Class: Charming::MouseEvent

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

Instance Method Summary collapse

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

#altObject (readonly)

Returns the value of attribute alt

Returns:

  • (Object)

    the current value of alt



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def alt
  @alt
end

#buttonObject (readonly)

Returns the value of attribute button

Returns:

  • (Object)

    the current value of button



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def button
  @button
end

#ctrlObject (readonly)

Returns the value of attribute ctrl

Returns:

  • (Object)

    the current value of ctrl



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def ctrl
  @ctrl
end

#shiftObject (readonly)

Returns the value of attribute shift

Returns:

  • (Object)

    the current value of shift



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def shift
  @shift
end

#xObject (readonly)

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



15
16
17
# File 'lib/charming/mouse_event.rb', line 15

def y
  @y
end

Instance Method Details

#button_nameObject

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

#click?Boolean

Returns ‘true` when the current event is a click (left, middle, or right button).

Returns:

  • (Boolean)


26
27
28
# File 'lib/charming/mouse_event.rb', line 26

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

#release?Boolean

Returns ‘true` when the current event is a mouse release action.

Returns:

  • (Boolean)


36
37
38
# File 'lib/charming/mouse_event.rb', line 36

def release?
  button_name == :release
end

#scroll?Boolean

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/charming/mouse_event.rb', line 31

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