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

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

Parameters:

  • input (String)


23
24
25
# File 'lib/vedeu/input/mouse.rb', line 23

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputString (readonly, protected)

Returns:

  • (String)


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

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)


15
16
17
# File 'lib/vedeu/input/mouse.rb', line 15

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

Instance Method Details

#buttonFixnum (private)

Returns:

  • (Fixnum)


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

def button
  mouse[0]
end

#clickvoid

This method returns an undefined value.

Trigger an event depending on which button was pressed.



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

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)

Returns:



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

def left_click?
  button == 0
end

#mouseArray<Fixnum> (private)

Returns:

  • (Array<Fixnum>)


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

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

#wheel_down?Boolean (private)

Returns:



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

def wheel_down?
  button == 65
end

#wheel_up?Boolean (private)

Returns:



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

def wheel_up?
  button == 64
end

#xFixnum (private)

Returns:

  • (Fixnum)


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

def x
  mouse[1]
end

#yFixnum (private)

Returns:

  • (Fixnum)


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

def y
  mouse[2]
end