Class: Three::Browser::Element
- Inherits:
-
Object
- Object
- Three::Browser::Element
- Defined in:
- lib/three/browser.rb
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event_listener(name, &block) ⇒ Object (also: #on)
- #bounding_client_rect ⇒ Object
- #client_height ⇒ Object
- #client_width ⇒ Object
-
#initialize(handle) ⇒ Element
constructor
A new instance of Element.
- #pointer_ndc(event) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(handle) ⇒ Element
Returns a new instance of Element.
10 11 12 |
# File 'lib/three/browser.rb', line 10 def initialize(handle) @handle = handle end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
8 9 10 |
# File 'lib/three/browser.rb', line 8 def handle @handle end |
Class Method Details
.wrap(value) ⇒ Object
14 15 16 |
# File 'lib/three/browser.rb', line 14 def self.wrap(value) value.is_a?(self) ? value : new(value) end |
Instance Method Details
#add_event_listener(name, &block) ⇒ Object Also known as: on
30 31 32 33 |
# File 'lib/three/browser.rb', line 30 def add_event_listener(name, &block) @handle.call(:addEventListener, name.to_s, block) self end |
#bounding_client_rect ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/three/browser.rb', line 37 def bounding_client_rect rect = @handle.call(:getBoundingClientRect) { left: rect[:left].to_f, top: rect[:top].to_f, width: rect[:width].to_f, height: rect[:height].to_f } end |
#client_height ⇒ Object
22 23 24 |
# File 'lib/three/browser.rb', line 22 def client_height [@handle[:clientHeight].to_i, 1].max end |
#client_width ⇒ Object
18 19 20 |
# File 'lib/three/browser.rb', line 18 def client_width [@handle[:clientWidth].to_i, 1].max end |
#pointer_ndc(event) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/three/browser.rb', line 47 def pointer_ndc(event) rect = bounding_client_rect x = ((event[:clientX].to_f - rect[:left]) / rect[:width]) * 2 - 1 y = -(((event[:clientY].to_f - rect[:top]) / rect[:height]) * 2 - 1) [x, y] end |
#size ⇒ Object
26 27 28 |
# File 'lib/three/browser.rb', line 26 def size [client_width, client_height] end |