Module: Tea::Mouse

Defined in:
lib/tea/m_event_app.rb,
lib/tea/m_event_mouse.rb

Defined Under Namespace

Classes: Down, Gained, Lost, Move, Scroll, Up

Constant Summary collapse

LEFT =

Mouse button constants for mouse events.

:LEFT
MIDDLE =
:MIDDLE
RIGHT =
:RIGHT

Class Method Summary collapse

Class Method Details

.in_app?Boolean

Returns true if the mouse is in the screen window

Returns:

  • (Boolean)


124
125
126
# File 'lib/tea/m_event_mouse.rb', line 124

def Mouse.in_app?
  @in_app
end

.left?Boolean

Returns true if the left mouse button is down. Updated when Event.get is called.

Returns:

  • (Boolean)


107
108
109
# File 'lib/tea/m_event_mouse.rb', line 107

def Mouse.left?
  @left
end

.middle?Boolean

Returns true if the middle mouse button is down. Updated when Event.get is called.

Returns:

  • (Boolean)


113
114
115
# File 'lib/tea/m_event_mouse.rb', line 113

def Mouse.middle?
  @middle
end

.right?Boolean

Returns true if the right mouse button is down. Updated when Event.get is called.

Returns:

  • (Boolean)


119
120
121
# File 'lib/tea/m_event_mouse.rb', line 119

def Mouse.right?
  @right
end

.update_state(tea_event) ⇒ Object

Update the mouse state, so that Mouse.x, Mouse.y, Mouse.left?, Mouse.middle? and Mouse.right? return recent data.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/tea/m_event_mouse.rb', line 130

def Mouse.update_state(tea_event)
  case tea_event
  when Move
    @x = tea_event.x
    @y = tea_event.y
  when Down
    case tea_event.button
    when LEFT   then @left = true
    when MIDDLE then @middle = true
    when RIGHT  then @right = true
    end
  when Up
    case tea_event.button
    when LEFT   then @left = false
    when MIDDLE then @middle = false
    when RIGHT  then @right = false
    end
  when Lost
    @in_app = false
  when Gained
    @in_app = true
  end
end

.xObject

Report the x position of the mouse in the screen window. Updated when Event.get is called.



95
96
97
# File 'lib/tea/m_event_mouse.rb', line 95

def Mouse.x
  @x
end

.yObject

Report the y position of the mouse in the screen window. Updated when Event.get is called.



101
102
103
# File 'lib/tea/m_event_mouse.rb', line 101

def Mouse.y
  @y
end