Module: DXRubySDL::Input

Defined in:
lib/dxruby_sdl/input.rb

Class Method Summary collapse

Class Method Details

.key_down?(key_code) ⇒ Boolean Also known as: keyDown?

Returns:

  • (Boolean)


71
72
73
# File 'lib/dxruby_sdl/input.rb', line 71

def key_down?(key_code)
  return sdl_key_press?(to_sdl_key(key_code))
end

.key_push?(key_code) ⇒ Boolean Also known as: keyPush?

Returns:

  • (Boolean)


75
76
77
# File 'lib/dxruby_sdl/input.rb', line 75

def key_push?(key_code)
  return sdl_key_push?(to_sdl_key(key_code))
end

.keysObject



103
104
105
# File 'lib/dxruby_sdl/input.rb', line 103

def keys
  return @keys
end

.mouse_down?(button) ⇒ Boolean Also known as: mouseDown?

Returns:

  • (Boolean)


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dxruby_sdl/input.rb', line 79

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_xObject Also known as: mousePosX



63
64
65
# File 'lib/dxruby_sdl/input.rb', line 63

def mouse_pos_x
  return SDL::Mouse.state[0]
end

.mouse_pos_yObject Also known as: mousePosY



67
68
69
# File 'lib/dxruby_sdl/input.rb', line 67

def mouse_pos_y
  return SDL::Mouse.state[1]
end

.mouse_push?(button) ⇒ Boolean Also known as: mousePush?

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dxruby_sdl/input.rb', line 91

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) ⇒ Boolean Also known as: padDown?

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dxruby_sdl/input.rb', line 35

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) ⇒ Boolean Also known as: padPush?

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dxruby_sdl/input.rb', line 49

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) ⇒ Object Also known as: setRepeat



9
10
11
# File 'lib/dxruby_sdl/input.rb', line 9

def set_repeat(wait, interval)
  SDL::Key.enable_key_repeat(wait, interval)
end

.x(pad_number = 0) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/dxruby_sdl/input.rb', line 13

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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/dxruby_sdl/input.rb', line 24

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