Class: AGL::Mouse

Inherits:
Object
  • Object
show all
Defined in:
lib/minigl/global.rb

Class Method Summary collapse

Class Method Details

.button_down?(btn) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/minigl/global.rb', line 154

def self.button_down? btn
  @@down[btn]
end

.button_pressed?(btn) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/minigl/global.rb', line 150

def self.button_pressed? btn
  @@down[btn] and not @@prev_down[btn]
end

.button_released?(btn) ⇒ Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/minigl/global.rb', line 158

def self.button_released? btn
  @@prev_down[btn] and not @@down[btn]
end

.double_click?(btn) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/minigl/global.rb', line 162

def self.double_click? btn
  @@dbl_click[btn]
end

.initializeObject



114
115
116
117
118
119
# File 'lib/minigl/global.rb', line 114

def self.initialize
  @@down = {}
  @@prev_down = {}
  @@dbl_click = {}
  @@dbl_click_timer = {}
end

.over?(x, y, w, h) ⇒ Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/minigl/global.rb', line 166

def self.over? x, y, w, h
  @@x >= x and @@x < x + w and @@y >= y and @@y < y + h
end

.updateObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/minigl/global.rb', line 121

def self.update
  @@prev_down = @@down.clone
  @@down.clear
  @@dbl_click.clear
  
  @@dbl_click_timer.each do |k, v|
    if v < Game.double_click_delay; @@dbl_click_timer[k] += 1
    else; @@dbl_click_timer.delete k; end
  end
  
  k1 = [Gosu::MsLeft, Gosu::MsMiddle, Gosu::MsRight]
  k2 = [:left, :middle, :right]
  for i in 0..2
    if Game.window.button_down? k1[i]
      @@down[k2[i]] = true
      @@dbl_click[k2[i]] = true if @@dbl_click_timer[k2[i]]
      @@dbl_click_timer.delete k2[i]
    elsif @@prev_down[k2[i]]
      @@dbl_click_timer[k2[i]] = 0
    end
  end
  
  @@x = Game.window.mouse_x.round
  @@y = Game.window.mouse_y.round
end

.xObject



147
# File 'lib/minigl/global.rb', line 147

def self.x; @@x; end

.yObject



148
# File 'lib/minigl/global.rb', line 148

def self.y; @@y; end