Class: Vedeu::Input::Mouse

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

Overview

Rudimentary support for mouse interactions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Return an instance of Vedeu::Input::Mouse.

Parameters:

  • input (String)


21
22
23
# File 'lib/vedeu/input/mouse.rb', line 21

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputString (readonly, protected)

Returns:

  • (String)


53
54
55
# File 'lib/vedeu/input/mouse.rb', line 53

def input
  @input
end

Class Method Details

.click(input) ⇒ void

This method returns an undefined value.

Trigger an event depending on which button was pressed.

Parameters:

  • input (String)


13
14
15
# File 'lib/vedeu/input/mouse.rb', line 13

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

Instance Method Details

#buttonFixnum (private)

Returns:

  • (Fixnum)


58
59
60
# File 'lib/vedeu/input/mouse.rb', line 58

def button
  mouse[0]
end

#clickvoid

This method returns an undefined value.

Trigger an event depending on which button was pressed.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vedeu/input/mouse.rb', line 28

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

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

  end
end

#left_click?Boolean (private)

Returns:

  • (Boolean)


68
69
70
# File 'lib/vedeu/input/mouse.rb', line 68

def left_click?
  button == 0
end

#mouseArray<Fixnum> (private)

Returns:

  • (Array<Fixnum>)


63
64
65
# File 'lib/vedeu/input/mouse.rb', line 63

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

#wheel_down?Boolean (private)

Returns:

  • (Boolean)


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

def wheel_down?
  button == 65
end

#wheel_up?Boolean (private)

Returns:

  • (Boolean)


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

def wheel_up?
  button == 64
end

#xFixnum (private)

Returns:

  • (Fixnum)


83
84
85
# File 'lib/vedeu/input/mouse.rb', line 83

def x
  mouse[1]
end

#yFixnum (private)

Returns:

  • (Fixnum)


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

def y
  mouse[2]
end