module DXRubySDL::Input
Constants
- DXRUBY_KEY_TABLE
- SDL_KEY_TABLE
Private Class Methods
handle_key_event(event)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 212 def handle_key_event(event) dkey = to_dxruby_key(event.sym) case event when SDL::Event::KeyDown @keys.add(dkey) when SDL::Event::KeyUp @keys.delete(dkey) @checked_keys.delete(dkey) @down_keys.delete(dkey) end end
joystick(pad_number)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 194 def joystick(pad_number) if pad_number >= SDL::Joystick.num return nil end if !@joysticks[pad_number] @joysticks[pad_number] = SDL::Joystick.open(pad_number) end return @joysticks[pad_number] end
sdl_key_press?(key)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 179 def sdl_key_press?(key) dkey = to_dxruby_key(key) if @keys.include?(dkey) @checked_keys.add(dkey) return true else return false end end
sdl_key_push?(key)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 189 def sdl_key_push?(key) dkey = to_dxruby_key(key) return sdl_key_press?(key) && !@down_keys.include?(dkey) end
store_last_state()
click to toggle source
# File lib/dxruby_sdl/input.rb, line 173 def store_last_state @down_keys.merge(@checked_keys) @checked_keys.clear @last_mouse_state = SDL::Mouse.state end
to_dxruby_key(key_code)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 208 def to_dxruby_key(key_code) return DXRUBY_KEY_TABLE[key_code] end
to_sdl_key(key_code)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 204 def to_sdl_key(key_code) return SDL_KEY_TABLE[key_code] end
Public Instance Methods
key_down?(key_code)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 70 def key_down?(key_code) return sdl_key_press?(to_sdl_key(key_code)) end
key_push?(key_code)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 74 def key_push?(key_code) return sdl_key_push?(to_sdl_key(key_code)) end
keys()
click to toggle source
# File lib/dxruby_sdl/input.rb, line 102 def keys return @keys end
mouse_down?(button)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 78 def mouse_down?(button) case button when M_LBUTTON index = 2 when M_MBUTTON index = 3 when M_RBUTTON index = 4 end return SDL::Mouse.state[index] end
mouse_pos_x()
click to toggle source
# File lib/dxruby_sdl/input.rb, line 62 def mouse_pos_x return SDL::Mouse.state[0] end
mouse_pos_y()
click to toggle source
# File lib/dxruby_sdl/input.rb, line 66 def mouse_pos_y return SDL::Mouse.state[1] end
mouse_push?(button)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 90 def mouse_push?(button) case button when M_LBUTTON index = 2 when M_MBUTTON index = 3 when M_RBUTTON index = 4 end return SDL::Mouse.state[index] && !@last_mouse_state[index] end
pad_down?(button_code, pad_number = 0)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 34 def pad_down?(button_code, pad_number = 0) if button_code == P_BUTTON0 && sdl_key_press?(SDL::Key::Z) || button_code == P_BUTTON1 && sdl_key_press?(SDL::Key::X) || button_code == P_BUTTON2 && sdl_key_press?(SDL::Key::C) || button_code == P_LEFT && sdl_key_press?(SDL::Key::LEFT) || button_code == P_RIGHT && sdl_key_press?(SDL::Key::RIGHT) || button_code == P_UP && sdl_key_press?(SDL::Key::UP) || button_code == P_DOWN && sdl_key_press?(SDL::Key::DOWN) || ((j = joystick(pad_number)) && j.button(button_code)) return true end return false end
pad_push?(button_code, pad_number = 0)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 48 def pad_push?(button_code, pad_number = 0) if button_code == P_BUTTON0 && sdl_key_push?(SDL::Key::Z) || button_code == P_BUTTON1 && sdl_key_push?(SDL::Key::X) || button_code == P_BUTTON2 && sdl_key_push?(SDL::Key::C) || button_code == P_LEFT && sdl_key_push?(SDL::Key::LEFT) || button_code == P_RIGHT && sdl_key_push?(SDL::Key::RIGHT) || button_code == P_UP && sdl_key_push?(SDL::Key::UP) || button_code == P_DOWN && sdl_key_push?(SDL::Key::DOWN) || ((j = joystick(pad_number)) && j.button(button_code)) return true end return false end
set_repeat(wait, interval)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 8 def set_repeat(wait, interval) SDL::Key.enable_key_repeat(wait, interval) end
x(pad_number = 0)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 12 def x(pad_number = 0) res = 0 if sdl_key_press?(SDL::Key::LEFT) res -= 1 end if sdl_key_press?(SDL::Key::RIGHT) res += 1 end return res end
y(pad_number = 0)
click to toggle source
# File lib/dxruby_sdl/input.rb, line 23 def y(pad_number = 0) res = 0 if sdl_key_press?(SDL::Key::UP) res -= 1 end if sdl_key_press?(SDL::Key::DOWN) res += 1 end return res end