Class: Charming::Events::MouseEvent
- Inherits:
-
Data
- Object
- Data
- Charming::Events::MouseEvent
- Defined in:
- lib/charming/events/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.
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 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
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 def alt @alt end |
#button ⇒ Object (readonly)
Returns the value of attribute button
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 def @button end |
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 def ctrl @ctrl end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 def shift @shift end |
#x ⇒ Object (readonly)
Returns the value of attribute x
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
16 17 18 |
# File 'lib/charming/events/mouse_event.rb', line 16 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`.
22 23 24 |
# File 'lib/charming/events/mouse_event.rb', line 22 def MOUSE_BUTTON_MAP.fetch(, :unknown) end |
#click? ⇒ Boolean
Returns ‘true` when the current event is a click (left, middle, or right button).
27 28 29 |
# File 'lib/charming/events/mouse_event.rb', line 27 def click? %i[left middle right].include?() end |
#release? ⇒ Boolean
Returns ‘true` when the current event is a mouse release action.
37 38 39 |
# File 'lib/charming/events/mouse_event.rb', line 37 def release? == :release end |
#scroll? ⇒ Boolean
Returns ‘true` when the button name maps to either direction of scroll.
32 33 34 |
# File 'lib/charming/events/mouse_event.rb', line 32 def scroll? %i[scroll_up scroll_down].include?() end |