Class: RbSDL2::Mouse::MouseWheel

Inherits:
Object
  • Object
show all
Defined in:
lib/rb_sdl2/mouse/mouse_wheel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window = nil) ⇒ MouseWheel

Returns a new instance of MouseWheel.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 4

def initialize(window = nil)
  @wheel_x = @wheel_y = @x = @y = 0
  window_id = window&.window_id
  proc = -> (event) do
    if event.mouse_wheel? && window_id && event[:windowID] == window_id
      a = event[:direction] == ::SDL::MOUSEWHEEL_FLIPPED ? -1 : 1
      @x += event[:x] * a
      @y += event[:y] * a
    end
  end
  @watch = EventFilter.new(proc)
end

Instance Attribute Details

#wheel_xObject (readonly)

Returns the value of attribute wheel_x.



34
35
36
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 34

def wheel_x
  @wheel_x
end

#wheel_yObject (readonly)

Returns the value of attribute wheel_y.



34
35
36
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 34

def wheel_y
  @wheel_y
end

#window_idObject (readonly)

Returns the value of attribute window_id.



34
35
36
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 34

def window_id
  @window_id
end

Instance Method Details

#updateObject



17
18
19
20
21
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 17

def update
  @wheel_x, @wheel_y = @x, @y
  @x = @y = 0
  self
end

#wheel=(bool) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 23

def wheel=(bool)
  if bool
    EventFilter.define_watch(@watch)
  else
    EventFilter.undefine_watch(@watch)
  end
  @wheel_x = @wheel_y = @x = @y = 0
end

#wheel_positionObject



32
# File 'lib/rb_sdl2/mouse/mouse_wheel.rb', line 32

def wheel_position = [@wheel_x, @wheel_y]