Class: Vedeu::Input::Mouse Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/input/mouse.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Rudimentary support for mouse interactions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Vedeu::Input::Mouse

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Vedeu::Input::Mouse.

Parameters:

  • input (String)


25
26
27
# File 'lib/vedeu/input/mouse.rb', line 25

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputString (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


61
62
63
# File 'lib/vedeu/input/mouse.rb', line 61

def input
  @input
end

Class Method Details

.click(input) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Trigger an event depending on which button was pressed.

Parameters:

  • input (String)


17
18
19
# File 'lib/vedeu/input/mouse.rb', line 17

def self.click(input)
  new(input).click
end

Instance Method Details

#buttonFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


66
67
68
# File 'lib/vedeu/input/mouse.rb', line 66

def button
  mouse[0]
end

#clickvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Trigger an event depending on which button was pressed.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vedeu/input/mouse.rb', line 32

def click
  Vedeu.log(type:    :input,
            message: "Mouse pressed: '#{button}' " \
                     "(x: #{x}, y: #{y})")

  Vedeu.trigger(:_mouse_event_, input)

  if left_click?
    Vedeu.trigger(:_cursor_reposition_, Vedeu.focus, y, x)

  elsif wheel_up?
    Vedeu.trigger(:_cursor_up_, Vedeu.focus)

  elsif wheel_down?
    Vedeu.trigger(:_cursor_down_, Vedeu.focus)

  else
    Vedeu.log(type:    :input,
              message: 'Vedeu does not support mouse button ' \
                       "'#{button}' yet.")

    false
  end
end

#left_click?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the mouse interaction was recognised as a left click.

Returns:



74
75
76
# File 'lib/vedeu/input/mouse.rb', line 74

def left_click?
  button == 0
end

#mouseArray<Fixnum> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Fixnum>)


79
80
81
# File 'lib/vedeu/input/mouse.rb', line 79

def mouse
  @_input ||= input.chars[3..-1].map { |character| character.ord - 32 }
end

#wheel_down?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the mouse interaction was recognised as the scroll wheel moving down.

Returns:



95
96
97
# File 'lib/vedeu/input/mouse.rb', line 95

def wheel_down?
  button == 65
end

#wheel_up?Boolean (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean indicating the mouse interaction was recognised as the scroll wheel moving up.

Returns:



87
88
89
# File 'lib/vedeu/input/mouse.rb', line 87

def wheel_up?
  button == 64
end

#xFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


100
101
102
# File 'lib/vedeu/input/mouse.rb', line 100

def x
  mouse[1]
end

#yFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


105
106
107
# File 'lib/vedeu/input/mouse.rb', line 105

def y
  mouse[2]
end