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. motion marks drag/hover movement and release marks an SGR button release.
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.
-
#motion ⇒ Object
readonly
Returns the value of attribute motion.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#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
truefor a button press (left, middle, or right) — not a release, drag, or hover. -
#drag? ⇒ Boolean
Returns
truewhen the mouse moved with a button held down. -
#initialize(button:, x:, y:, ctrl: false, alt: false, shift: false, motion: false, release: false) ⇒ MouseEvent
constructor
A new instance of MouseEvent.
-
#motion? ⇒ Boolean
Returns
truefor any mouse movement report (drag or hover). -
#release? ⇒ Boolean
Returns
truefor a button release: the SGR release marker, or the legacy button-3 release code on a non-motion event. -
#scroll? ⇒ Boolean
Returns
truewhen the button name maps to either direction of scroll.
Constructor Details
#initialize(button:, x:, y:, ctrl: false, alt: false, shift: false, motion: false, release: false) ⇒ MouseEvent
Returns a new instance of MouseEvent.
18 19 20 |
# File 'lib/charming/events/mouse_event.rb', line 18 def initialize(button:, x:, y:, ctrl: false, alt: false, shift: false, motion: false, release: false) super end |
Instance Attribute Details
#alt ⇒ Object (readonly)
Returns the value of attribute alt
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def alt @alt end |
#button ⇒ Object (readonly)
Returns the value of attribute button
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def @button end |
#ctrl ⇒ Object (readonly)
Returns the value of attribute ctrl
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def ctrl @ctrl end |
#motion ⇒ Object (readonly)
Returns the value of attribute motion
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def motion @motion end |
#release ⇒ Object (readonly)
Returns the value of attribute release
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def release @release end |
#shift ⇒ Object (readonly)
Returns the value of attribute shift
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def shift @shift end |
#x ⇒ Object (readonly)
Returns the value of attribute x
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y
17 18 19 |
# File 'lib/charming/events/mouse_event.rb', line 17 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.
23 24 25 |
# File 'lib/charming/events/mouse_event.rb', line 23 def MOUSE_BUTTON_MAP.fetch(, :unknown) end |
#click? ⇒ Boolean
Returns true for a button press (left, middle, or right) — not a release, drag, or hover.
28 29 30 |
# File 'lib/charming/events/mouse_event.rb', line 28 def click? !motion && !release? && %i[left middle right].include?() end |
#drag? ⇒ Boolean
Returns true when the mouse moved with a button held down.
50 51 52 |
# File 'lib/charming/events/mouse_event.rb', line 50 def drag? motion && %i[left middle right].include?() end |
#motion? ⇒ Boolean
Returns true for any mouse movement report (drag or hover).
45 46 47 |
# File 'lib/charming/events/mouse_event.rb', line 45 def motion? motion end |
#release? ⇒ Boolean
Returns true for a button release: the SGR release marker, or the legacy
button-3 release code on a non-motion event. (During motion, button 3
means "no button held", not a release.)
40 41 42 |
# File 'lib/charming/events/mouse_event.rb', line 40 def release? release || (!motion && == :release) end |
#scroll? ⇒ Boolean
Returns true when the button name maps to either direction of scroll.
33 34 35 |
# File 'lib/charming/events/mouse_event.rb', line 33 def scroll? %i[scroll_up scroll_down].include?() end |