Class: Vedeu::Input::Mouse
- Inherits:
-
Object
- Object
- Vedeu::Input::Mouse
- Defined in:
- lib/vedeu/input/mouse.rb
Overview
Rudimentary support for mouse interactions.
Instance Attribute Summary collapse
- #input ⇒ String readonly protected
Class Method Summary collapse
-
.click(input) ⇒ void
Trigger an event depending on which button was pressed.
Instance Method Summary collapse
- #button ⇒ Fixnum private
-
#click ⇒ void
Trigger an event depending on which button was pressed.
-
#initialize(input) ⇒ Vedeu::Input::Mouse
constructor
Return an instance of Vedeu::Input::Mouse.
- #left_click? ⇒ Boolean private
- #mouse ⇒ Array<Fixnum> private
- #wheel_down? ⇒ Boolean private
- #wheel_up? ⇒ Boolean private
- #x ⇒ Fixnum private
- #y ⇒ Fixnum private
Constructor Details
#initialize(input) ⇒ Vedeu::Input::Mouse
Return an instance of Vedeu::Input::Mouse.
21 22 23 |
# File 'lib/vedeu/input/mouse.rb', line 21 def initialize(input) @input = input end |
Instance Attribute Details
#input ⇒ String (readonly, protected)
53 54 55 |
# File 'lib/vedeu/input/mouse.rb', line 53 def input @input end |
Class Method Details
.click(input) ⇒ void
This method returns an undefined value.
Trigger an event depending on which button was pressed.
13 14 15 |
# File 'lib/vedeu/input/mouse.rb', line 13 def self.click(input) new(input).click end |
Instance Method Details
#button ⇒ Fixnum (private)
58 59 60 |
# File 'lib/vedeu/input/mouse.rb', line 58 def mouse[0] end |
#click ⇒ void
This method returns an undefined value.
Trigger an event depending on which button was pressed.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vedeu/input/mouse.rb', line 28 def click Vedeu.log(type: :input, message: "Mouse pressed: '#{button}' (x: #{x}, y: #{y})") if left_click? Vedeu.trigger(:_cursor_reposition_, Vedeu.focus, y, x) elsif wheel_up? Vedeu.trigger(:_cursor_up_, Vedeu.focus) elsif wheel_down? Vedeu.trigger(:_cursor_down_, Vedeu.focus) else Vedeu.log(type: :input, message: 'Vedeu does not support mouse button ' \ "'#{button}' yet.") end end |
#left_click? ⇒ Boolean (private)
68 69 70 |
# File 'lib/vedeu/input/mouse.rb', line 68 def left_click? == 0 end |
#mouse ⇒ Array<Fixnum> (private)
63 64 65 |
# File 'lib/vedeu/input/mouse.rb', line 63 def mouse @_input ||= input.chars[3..-1].map { |character| character.ord - 32 } end |
#wheel_down? ⇒ Boolean (private)
78 79 80 |
# File 'lib/vedeu/input/mouse.rb', line 78 def wheel_down? == 65 end |
#wheel_up? ⇒ Boolean (private)
73 74 75 |
# File 'lib/vedeu/input/mouse.rb', line 73 def wheel_up? == 64 end |
#x ⇒ Fixnum (private)
83 84 85 |
# File 'lib/vedeu/input/mouse.rb', line 83 def x mouse[1] end |
#y ⇒ Fixnum (private)
88 89 90 |
# File 'lib/vedeu/input/mouse.rb', line 88 def y mouse[2] end |