Class: Charming::MouseEvent
- Inherits:
-
Data
- Object
- Data
- Charming::MouseEvent
- Defined in:
- lib/charming/mouse_event.rb
Overview
MouseEvent represents a mouse input event. button encodes which button or action was triggered (left, right, scroll), while x and y provide the cursor position. Modifier booleans (ctrl, alt, shift) capture key state at the time of the event.
Instance Attribute Summary collapse
-
#alt ⇒ Object
readonly
Returns the value of attribute alt.
-
#button ⇒ Object
readonly
Returns the value of attribute button.
-
#ctrl ⇒ Object
readonly
Returns the value of attribute ctrl.
-
#shift ⇒ Object
readonly
Returns the value of attribute shift.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#button_name ⇒ Object
Returns the semantic symbol for button — one of ‘left`, `right`, `scroll_up`, etc.
-
#click? ⇒ Boolean
Returns ‘true` when the current event is a click (left, middle, or right button).
-
#initialize(button:, x:, y:, ctrl: false, alt: false, shift: false) ⇒ MouseEvent
constructor
A new instance of MouseEvent.
-
#release? ⇒ Boolean
Returns ‘true` when the current event is a mouse release action.
-
#scroll? ⇒ Boolean
Returns ‘true` when the button name maps to either direction of scroll.
Constructor Details
#initialize(button:, x:, y:, ctrl: false, alt: false, shift: false) ⇒ MouseEvent
Returns a new instance of MouseEvent.
16 17 18 |
# File 'lib/charming/mouse_event.rb', line 16 def initialize(button:, x:, y:, ctrl: false, alt: false, shift: false) super end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def alt @alt end |
#button ⇒ Object (readonly)
Returns the value of attribute button
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def @button end |
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def ctrl @ctrl end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def shift @shift end |
#x ⇒ Object (readonly)
Returns the value of attribute x
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
15 16 17 |
# File 'lib/charming/mouse_event.rb', line 15 def y @y end |
Instance Method Details
#button_name ⇒ Object
Returns the semantic symbol for button — one of ‘left`, `right`, `scroll_up`, etc. or `:unknown`.
21 22 23 |
# File 'lib/charming/mouse_event.rb', line 21 def MOUSE_BUTTON_MAP.fetch(, :unknown) end |
#click? ⇒ Boolean
Returns ‘true` when the current event is a click (left, middle, or right button).
26 27 28 |
# File 'lib/charming/mouse_event.rb', line 26 def click? %i[left middle right].include?() end |
#release? ⇒ Boolean
Returns ‘true` when the current event is a mouse release action.
36 37 38 |
# File 'lib/charming/mouse_event.rb', line 36 def release? == :release end |
#scroll? ⇒ Boolean
Returns ‘true` when the button name maps to either direction of scroll.
31 32 33 |
# File 'lib/charming/mouse_event.rb', line 31 def scroll? %i[scroll_up scroll_down].include?() end |