Class: Charming::Events::MouseEvent

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

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

#altObject (readonly)

Returns the value of attribute alt

Returns:

  • (Object)

    the current value of alt



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def alt
  @alt
end

#buttonObject (readonly)

Returns the value of attribute button

Returns:

  • (Object)

    the current value of button



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def button
  @button
end

#ctrlObject (readonly)

Returns the value of attribute ctrl

Returns:

  • (Object)

    the current value of ctrl



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def ctrl
  @ctrl
end

#motionObject (readonly)

Returns the value of attribute motion

Returns:

  • (Object)

    the current value of motion



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def motion
  @motion
end

#releaseObject (readonly)

Returns the value of attribute release

Returns:

  • (Object)

    the current value of release



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def release
  @release
end

#shiftObject (readonly)

Returns the value of attribute shift

Returns:

  • (Object)

    the current value of shift



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def shift
  @shift
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



17
18
19
# File 'lib/charming/events/mouse_event.rb', line 17

def y
  @y
end

Instance Method Details

#button_nameObject

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 button_name
  MOUSE_BUTTON_MAP.fetch(button, :unknown)
end

#click?Boolean

Returns true for a button press (left, middle, or right) — not a release, drag, or hover.

Returns:

  • (Boolean)


28
29
30
# File 'lib/charming/events/mouse_event.rb', line 28

def click?
  !motion && !release? && %i[left middle right].include?(button_name)
end

#drag?Boolean

Returns true when the mouse moved with a button held down.

Returns:

  • (Boolean)


50
51
52
# File 'lib/charming/events/mouse_event.rb', line 50

def drag?
  motion && %i[left middle right].include?(button_name)
end

#motion?Boolean

Returns true for any mouse movement report (drag or hover).

Returns:

  • (Boolean)


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.)

Returns:

  • (Boolean)


40
41
42
# File 'lib/charming/events/mouse_event.rb', line 40

def release?
  release || (!motion && button_name == :release)
end

#scroll?Boolean

Returns true when the button name maps to either direction of scroll.

Returns:

  • (Boolean)


33
34
35
# File 'lib/charming/events/mouse_event.rb', line 33

def scroll?
  %i[scroll_up scroll_down].include?(button_name)
end