Class: Cura::Event::MouseButton

Inherits:
Mouse show all
Defined in:
lib/cura/event/mouse_button.rb

Overview

Dispatched when a mouse’s button state changes.

Constant Summary collapse

VALID_NAMES =
[:left, :middle, :right]
VALID_STATES =
[:up, :down, :click, :double_click]

Instance Attribute Summary

Attributes inherited from Mouse

#x, #y

Attributes inherited from Base

#created_at, #target

Instance Method Summary collapse

Methods inherited from Base

#==, #dispatch, inherited, name, #to_h

Methods included from Attributes::HasAttributes

included, #update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ MouseButton

Returns a new instance of MouseButton.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/cura/event/mouse_button.rb', line 14

def initialize(attributes={})
  super
  
  # raise ArgumentError, "name must be set" if @name.nil? # TODO: Termbox doesn't support which button was released yet
  raise ArgumentError, "state must be set" if @state.nil?
end

Instance Method Details

#click?Boolean

Get whether the mouse button state is double_click.

Returns:

  • (Boolean)


# File 'lib/cura/event/mouse_button.rb', line 78

#down?Boolean

Get whether the mouse button state is down.

Returns:

  • (Boolean)


# File 'lib/cura/event/mouse_button.rb', line 73

#left?Boolean

Get whether the mouse button state occurred the left button.

Returns:

  • (Boolean)


# File 'lib/cura/event/mouse_button.rb', line 49

#middle?Boolean

Get whether the mouse button state occurred the middle button.

Returns:

  • (Boolean)


# File 'lib/cura/event/mouse_button.rb', line 54

#nameSymbol

Get the mouse button name. Will return ‘:left`, `:middle`, or `:right`.

Returns:

  • (Symbol)


# File 'lib/cura/event/mouse_button.rb', line 35

#name=(value) ⇒ Symbol

Set the mouse button name.

Parameters:

  • value (#to_sym)

Returns:

  • (Symbol)


47
# File 'lib/cura/event/mouse_button.rb', line 47

attribute(:name) { |value| validate_list(value, VALID_NAMES) }

#right?Boolean

Get whether the mouse button state occurred the right button.

Returns:

  • (Boolean)


64
65
66
# File 'lib/cura/event/mouse_button.rb', line 64

VALID_NAMES.each do |name|
  define_method("#{name}?") { @name == name }
end

#stateSymbol

Get the mouse button state. Will return ‘:up`, `:down`, `:click`, or `:double_click`.

Returns:

  • (Symbol)


# File 'lib/cura/event/mouse_button.rb', line 21

#state=(value) ⇒ Symbol

Set the mouse button state.

Parameters:

  • value (#to_sym)

Returns:

  • (Symbol)


33
# File 'lib/cura/event/mouse_button.rb', line 33

attribute(:state) { |value| validate_list(value, VALID_STATES) }

#up?Boolean

Get whether the mouse button state is up.

Returns:

  • (Boolean)


# File 'lib/cura/event/mouse_button.rb', line 68