rubygame 2.5.3 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/CREDITS +6 -4
  2. data/NEWS +79 -0
  3. data/README +55 -72
  4. data/ROADMAP +20 -13
  5. data/doc/custom_sdl_load_paths.rdoc +79 -0
  6. data/doc/getting_started.rdoc +65 -36
  7. data/doc/keyboard_symbols.rdoc +243 -0
  8. data/doc/macosx_install.rdoc +49 -35
  9. data/doc/windows_install.rdoc +36 -108
  10. data/lib/rubygame.rb +62 -24
  11. data/lib/rubygame/audio.rb +147 -0
  12. data/lib/rubygame/clock.rb +164 -1
  13. data/lib/rubygame/color.rb +40 -7
  14. data/lib/rubygame/color/models/hsl.rb +1 -1
  15. data/lib/rubygame/color/models/hsv.rb +1 -1
  16. data/lib/rubygame/color/models/rgb.rb +1 -1
  17. data/lib/rubygame/color/palettes/css.rb +1 -3
  18. data/lib/rubygame/color/palettes/x11.rb +1 -2
  19. data/lib/rubygame/constants.rb +297 -0
  20. data/lib/rubygame/deprecated_mixer.rb +555 -0
  21. data/lib/rubygame/event.rb +122 -6
  22. data/lib/rubygame/event_handler.rb +3 -1
  23. data/lib/rubygame/event_hook.rb +6 -2
  24. data/lib/rubygame/event_triggers.rb +1 -1
  25. data/lib/rubygame/events.rb +416 -1
  26. data/lib/rubygame/ftor.rb +1 -7
  27. data/lib/rubygame/gfx.rb +583 -0
  28. data/lib/rubygame/gl.rb +107 -0
  29. data/lib/rubygame/image.rb +140 -0
  30. data/lib/rubygame/joystick.rb +184 -0
  31. data/lib/rubygame/main.rb +82 -0
  32. data/lib/rubygame/mediabag.rb +1 -1
  33. data/lib/rubygame/mixer.rb +30 -0
  34. data/lib/rubygame/music.rb +493 -0
  35. data/lib/rubygame/queue.rb +3 -1
  36. data/lib/rubygame/rect.rb +9 -9
  37. data/lib/rubygame/screen.rb +357 -0
  38. data/lib/rubygame/shared.rb +40 -4
  39. data/lib/rubygame/sound.rb +428 -0
  40. data/lib/rubygame/surface.rb +626 -0
  41. data/lib/rubygame/ttf.rb +311 -0
  42. data/samples/FreeSans.ttf +0 -0
  43. data/samples/README +6 -5
  44. data/samples/demo_draw.rb +1 -1
  45. data/samples/demo_gl.rb +3 -1
  46. data/samples/demo_gl_tex.rb +4 -2
  47. data/samples/demo_rubygame.rb +114 -105
  48. data/samples/demo_sfont.rb +1 -1
  49. data/samples/demo_ttf.rb +3 -1
  50. data/samples/demo_utf8.rb +1 -1
  51. data/samples/image_viewer.rb +118 -0
  52. data/samples/load_and_blit.rb +1 -1
  53. data/samples/rubygame.png +0 -0
  54. metadata +34 -40
  55. data/Rakefile +0 -537
  56. data/doc/extended_readme.rdoc +0 -49
  57. data/ext/body/rubygame_body.so +0 -0
  58. data/ext/rubygame/rubygame_clock.c +0 -301
  59. data/ext/rubygame/rubygame_clock.h +0 -32
  60. data/ext/rubygame/rubygame_event.c +0 -760
  61. data/ext/rubygame/rubygame_event.h +0 -48
  62. data/ext/rubygame/rubygame_event2.c +0 -661
  63. data/ext/rubygame/rubygame_event2.h +0 -29
  64. data/ext/rubygame/rubygame_gfx.c +0 -942
  65. data/ext/rubygame/rubygame_gfx.h +0 -101
  66. data/ext/rubygame/rubygame_gl.c +0 -154
  67. data/ext/rubygame/rubygame_gl.h +0 -32
  68. data/ext/rubygame/rubygame_image.c +0 -252
  69. data/ext/rubygame/rubygame_image.h +0 -41
  70. data/ext/rubygame/rubygame_joystick.c +0 -336
  71. data/ext/rubygame/rubygame_joystick.h +0 -41
  72. data/ext/rubygame/rubygame_main.c +0 -158
  73. data/ext/rubygame/rubygame_main.h +0 -36
  74. data/ext/rubygame/rubygame_mixer.c +0 -1024
  75. data/ext/rubygame/rubygame_mixer.h +0 -36
  76. data/ext/rubygame/rubygame_music.c +0 -1017
  77. data/ext/rubygame/rubygame_music.h +0 -29
  78. data/ext/rubygame/rubygame_screen.c +0 -572
  79. data/ext/rubygame/rubygame_screen.h +0 -45
  80. data/ext/rubygame/rubygame_shared.c +0 -269
  81. data/ext/rubygame/rubygame_shared.h +0 -69
  82. data/ext/rubygame/rubygame_sound.c +0 -863
  83. data/ext/rubygame/rubygame_sound.h +0 -29
  84. data/ext/rubygame/rubygame_surface.c +0 -1153
  85. data/ext/rubygame/rubygame_surface.h +0 -62
  86. data/ext/rubygame/rubygame_ttf.c +0 -599
  87. data/ext/rubygame/rubygame_ttf.h +0 -69
  88. data/samples/keys.rb +0 -52
@@ -19,12 +19,120 @@
19
19
 
20
20
  module Rubygame
21
21
 
22
- # List of all Rubygame hardware event classes. *Do not modify!*
23
- SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\
24
- MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\
25
- JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\
26
- ResizeEvent, QuitEvent]
27
-
22
+ class << self
23
+
24
+ # Retrieves all pending events from SDL's event stack and converts them
25
+ # into Rubygame Event objects. Returns an Array of all the events, in
26
+ # the order they were read.
27
+ #
28
+ # This method is used by the EventQueue class, so don't call it if you are
29
+ # using EventQueue for event management! If you do, the EventQueue will not
30
+ # receive all the events, because they will have been removed from SDL's
31
+ # event stack by this method.
32
+ #
33
+ # However, if you aren't using EventQueue, you can safely use this method
34
+ # to make your own event management system.
35
+ #
36
+ def fetch_sdl_events
37
+ deprecated("Rubygame.fetch_sdl_events", "3.0")
38
+ events = []
39
+ until( ( event = SDL::PollEvent() ).nil? )
40
+ events << _convert_sdlevent(event)
41
+ end
42
+ return events
43
+ end
44
+
45
+
46
+ private
47
+
48
+
49
+ def _convert_active( state ) # :nodoc:
50
+ states = []
51
+ states << "mouse" if (state & SDL::APPMOUSEFOCUS)
52
+ states << "keyboard" if (state & SDL::APPINPUTFOCUS)
53
+ states << "active" if (state & SDL::APPACTIVE)
54
+ return states
55
+ end
56
+
57
+
58
+ def _convert_keymod( mods ) # :nodoc:
59
+ array = []
60
+ array << SDL::K_LSHIFT if( mods & SDL::KMOD_LSHIFT )
61
+ array << SDL::K_RSHIFT if( mods & SDL::KMOD_RSHIFT )
62
+ array << SDL::K_LCTRL if( mods & SDL::KMOD_LCTRL )
63
+ array << SDL::K_RCTRL if( mods & SDL::KMOD_RCTRL )
64
+ array << SDL::K_LALT if( mods & SDL::KMOD_LALT )
65
+ array << SDL::K_RALT if( mods & SDL::KMOD_RALT )
66
+ array << SDL::K_LMETA if( mods & SDL::KMOD_LMETA )
67
+ array << SDL::K_RMETA if( mods & SDL::KMOD_RMETA )
68
+ array << SDL::K_NUMLOCK if( mods & SDL::KMOD_NUM )
69
+ array << SDL::K_CAPSLOCK if( mods & SDL::KMOD_CAPS )
70
+ array << SDL::K_MODE if( mods & SDL::KMOD_MODE )
71
+ return array
72
+ end
73
+
74
+
75
+ def _convert_mousebuttons( state ) # :nodoc:
76
+ states = []
77
+ states << SDL::BUTTON_LEFT if (state & SDL::BUTTON_LMASK)
78
+ states << SDL::BUTTON_MIDDLE if (state & SDL::BUTTON_MMASK)
79
+ states << SDL::BUTTON_RIGHT if (state & SDL::BUTTON_RMASK)
80
+ return states
81
+ end
82
+
83
+
84
+ def _convert_sdlevent( ev ) # :nodoc:
85
+ case ev.type
86
+
87
+ when SDL::ACTIVEEVENT
88
+ return ActiveEvent.new( (ev.gain == 1), _convert_active(ev.state) )
89
+
90
+ when SDL::VIDEOEXPOSE
91
+ return ExposeEvent.new()
92
+
93
+ when SDL::JOYAXISMOTION
94
+ return JoyAxisEvent.new( ev.which, ev.axis, ev.value )
95
+
96
+ when SDL::JOYBALLMOTION
97
+ return JoyBallEvent.new( ev.which, ev.ball, [ev.xrel, ev.yrel] )
98
+
99
+ when SDL::JOYBUTTONDOWN
100
+ return JoyDownEvent.new( ev.which, ev.button )
101
+
102
+ when SDL::JOYBUTTONUP
103
+ return JoyUpEvent.new( ev.which, ev.button )
104
+
105
+ when SDL::JOYHATMOTION
106
+ return JoyHatEvent.new( ev.which, ev.hat, ev.value )
107
+
108
+ when SDL::KEYDOWN
109
+ return KeyDownEvent.new(ev.keysym.sym, _convert_keymod(ev.keysym.mod))
110
+
111
+ when SDL::KEYUP
112
+ return KeyUpEvent.new(ev.keysym.sym, _convert_keymod(ev.keysym.mod))
113
+
114
+ when SDL::MOUSEBUTTONDOWN
115
+ return MouseDownEvent.new( [ev.x, ev.y], ev.button )
116
+
117
+ when SDL::MOUSEBUTTONUP
118
+ return MouseUpEvent.new( [ev.x, ev.y], ev.button )
119
+
120
+ when SDL::MOUSEMOTION
121
+ return MouseMotionEvent.new( [ev.x, ev.y], [ev.xrel, ev.yrel],
122
+ _convert_mousebuttons(ev.state) )
123
+
124
+ when SDL::VIDEORESIZE
125
+ return ResizeEvent.new( [ev.w, ev.h] )
126
+
127
+ when SDL::QUIT
128
+ return QuitEvent.new()
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+
28
136
  # Converts a keyboard symbol (keysym) into a human-readable text string.
29
137
  # If either Shift key was being pressed, alphanumeric or punctuation keys
30
138
  # will be made uppercase or alternate, based on U.S. keyboard layout.
@@ -310,4 +418,12 @@ module Rubygame
310
418
  # pressed the close button.)
311
419
  class QuitEvent < Event
312
420
  end
421
+
422
+
423
+ # List of all Rubygame hardware event classes. *Do not modify!*
424
+ SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\
425
+ MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\
426
+ JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\
427
+ ResizeEvent, QuitEvent]
428
+
313
429
  end # module Rubygame
@@ -19,7 +19,9 @@
19
19
  #
20
20
  #++
21
21
 
22
- require 'rubygame/event_hook'
22
+
23
+
24
+ require( File.join( File.dirname(__FILE__), "event_hook" ) )
23
25
 
24
26
 
25
27
  # EventHandler provides a simple, extensible system for
@@ -17,8 +17,12 @@
17
17
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
  #++
19
19
 
20
- require 'rubygame/event_triggers'
21
- require 'rubygame/event_actions'
20
+
21
+
22
+ %w{ event_triggers event_actions }.each do |f|
23
+ require( File.join( File.dirname(__FILE__), f ) )
24
+ end
25
+
22
26
 
23
27
  module Rubygame
24
28
 
@@ -17,7 +17,7 @@
17
17
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
  #++
19
19
 
20
- require 'rubygame'
20
+
21
21
 
22
22
  # This module contains all the event trigger classes that
23
23
  # come with Rubygame.
@@ -2,7 +2,7 @@
2
2
  # This file is one part of:
3
3
  # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
4
4
  #
5
- # Copyright (C) 2008 John Croisant
5
+ # Copyright (C) 2008-2009 John Croisant
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
8
8
  # modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,68 @@
22
22
 
23
23
  module Rubygame
24
24
 
25
+
26
+ # Enable key repeat, so that additional keyboard release and press
27
+ # events are automatically generated for as long as the key is held
28
+ # down. See also #disable_key_repeat.
29
+ #
30
+ # delay:: how many seconds to wait before starting to repeat.
31
+ # Default is 0.5 seconds. (Numeric or :default, optional)
32
+ #
33
+ # interval:: how many seconds to wait in between repetitions after
34
+ # the first one. Default is 0.03 seconds.
35
+ # (Numeric or :default, optional)
36
+ #
37
+ def self.enable_key_repeat( delay=:default, interval=:default )
38
+
39
+ delay = if delay == :default
40
+ SDL::DEFAULT_REPEAT_DELAY
41
+ else
42
+ delay.to_f
43
+ end
44
+
45
+ interval = if interval == :default
46
+ SDL::DEFAULT_REPEAT_INTERVAL
47
+ else
48
+ interval.to_f
49
+ end
50
+
51
+ if delay < 0.001
52
+ raise( ArgumentError,
53
+ "delay must be at least 0.001 sec (got #{delay})" )
54
+ end
55
+
56
+ if interval < 0.001
57
+ raise( ArgumentError,
58
+ "interval must be at least 0.001 sec (got #{interval})" )
59
+ end
60
+
61
+ result = SDL.EnableKeyRepeat( (delay * 1000).to_i, (interval * 1000).to_i )
62
+
63
+ if result != 0
64
+ raise( Rubygame::SDLError,
65
+ "Could not enable key repeat: #{SDL.GetError()}" )
66
+ end
67
+
68
+ return nil
69
+ end
70
+
71
+
72
+ # Disable key repeat, undoing the effect of #enable_key_repeat.
73
+ #
74
+ def self.disable_key_repeat
75
+ result = SDL.EnableKeyRepeat( 0, 0 )
76
+
77
+ if result != 0
78
+ raise( Rubygame::SDLError,
79
+ "Could not disable key repeat: #{SDL.GetError()}" )
80
+ end
81
+
82
+ return nil
83
+ end
84
+
85
+
86
+
25
87
  # The Events module contains classes representing various
26
88
  # hardware events (e.g. keyboard presses, mouse clicks)
27
89
  # and software events (e.g. clock tick, window becomes active)
@@ -32,6 +94,359 @@ module Rubygame
32
94
  # deprecated and should not be used anymore.
33
95
  #
34
96
  module Events
97
+
98
+
99
+
100
+ # NOTE: This method converts the SDL events into the new-style event
101
+ # classes, located in the Rubygame::Events module. For converting to
102
+ # the older (deprecated) events, see Rubygame.fetch_sdl_events.
103
+ #
104
+ # Retrieves all pending events from SDL's event stack and converts them
105
+ # into Rubygame event objects. Returns an Array of all the events, in
106
+ # the order they were read.
107
+ #
108
+ # This method is used by the EventQueue class (among others), so
109
+ # don't call it if you are using any of Rubygame's event management
110
+ # classes (e.g. EventQueue)! If you do, they will not receive all
111
+ # the events, because some events will have been removed from SDL's
112
+ # event stack by this method.
113
+ #
114
+ # However, if you aren't using EventQueue, you can safely use this
115
+ # method to make your own event management system.
116
+ #
117
+ def self.fetch_sdl_events
118
+ events = []
119
+ until( ( event = SDL::PollEvent() ).nil? )
120
+ case ( event = _convert_sdlevent(event) )
121
+ when Array; events += event
122
+ else; events << event
123
+ end
124
+ end
125
+ return events
126
+ end
127
+
128
+
129
+
130
+ private
131
+
132
+
133
+ # Convert SDL's ACTIVEEVENT into zero or more of:
134
+ #
135
+ # InputFocusGained or InputFocusLost
136
+ # MouseFocusGained or MouseFocusLost
137
+ # WindowUnminimized or WindowMinimized
138
+ #
139
+ # Returns a ruby Array of the events it generated.
140
+ #
141
+ def self._convert_activeevent( ev )
142
+
143
+ state = ev.state
144
+ gain = ev.gain
145
+
146
+ # any_state = SDL::APPACTIVE | SDL::APPINPUTFOCUS | SDL::APPMOUSEFOCUS
147
+ # if( state & any_state == 0 )
148
+ # raise( Rubygame::SDLError, "Unknown ACTIVEEVENT state #{state}. "+
149
+ # "This is a bug in Rubygame." )
150
+ # end
151
+
152
+ events = []
153
+
154
+ if( SDL::APPACTIVE & state )
155
+ if( gain == 1 )
156
+ events << WindowUnminimized.new
157
+ else
158
+ events << WindowMinimized.new
159
+ end
160
+ end
161
+
162
+ if( SDL::APPINPUTFOCUS & state )
163
+ if( gain == 1 )
164
+ events << InputFocusGained.new
165
+ else
166
+ events << InputFocusLost.new
167
+ end
168
+ end
169
+
170
+ if( SDL::APPMOUSEFOCUS & state )
171
+ if( gain == 1 )
172
+ events << MouseFocusGained.new
173
+ else
174
+ events << MouseFocusLost.new
175
+ end
176
+ end
177
+
178
+ return events
179
+
180
+ end
181
+
182
+
183
+
184
+ # Convert SDL's joystick axis events into JoystickAxisMoved.
185
+ #
186
+ def self._convert_joyaxisevent( ev )
187
+ joy_id = ev.which
188
+ axis = ev.axis
189
+ value = ev.value
190
+
191
+ # Convert value to the -1.0 .. 1.0 range
192
+ value = if( value > 0 )
193
+ value / 32767.0
194
+ else
195
+ value / 32768.0
196
+ end
197
+
198
+ return JoystickAxisMoved.new( joy_id, axis, value )
199
+ end
200
+
201
+
202
+
203
+ # Convert SDL's joystick ball events into JoystickBallMoved.
204
+ #
205
+ def self._convert_joyballevent( ev )
206
+ return JoystickBallMoved.new( ev.which, ev.ball, [ev.xrel, ev.xrel] )
207
+ end
208
+
209
+
210
+
211
+ # Convert SDL's joystick button events into JoystickButtonPressed or
212
+ # JoystickButtonReleased.
213
+ #
214
+ def self._convert_joybuttonevent( ev )
215
+ case ev.state
216
+ when SDL::PRESSED
217
+ JoystickButtonPressed.new( ev.which, ev.button )
218
+ when SDL::RELEASED
219
+ JoystickButtonReleased.new( ev.which, ev.button )
220
+ else
221
+ raise( Rubygame::SDLError, "Unknown joystick button state "+
222
+ "#{ev.jbutton.state}. This is a bug in Rubygame." )
223
+ end
224
+ end
225
+
226
+
227
+
228
+ # Convert SDL's joystick hat events into JoystickHatMoved.
229
+ #
230
+ def self._convert_joyhatevent( ev )
231
+ dir = case ev.value
232
+ when SDL::HAT_RIGHTUP; :up_right
233
+ when SDL::HAT_RIGHTDOWN; :down_right
234
+ when SDL::HAT_LEFTUP; :up_left
235
+ when SDL::HAT_LEFTDOWN; :down_left
236
+ when SDL::HAT_UP; :up
237
+ when SDL::HAT_RIGHT; :right
238
+ when SDL::HAT_DOWN; :down
239
+ when SDL::HAT_LEFT; :left
240
+ else; nil
241
+ end
242
+
243
+ return JoystickHatMoved.new( ev.which, ev.hat, dir )
244
+ end
245
+
246
+
247
+
248
+ # Returns a sanitized symbol for the given key.
249
+ #
250
+ def self._convert_key_symbol( key )
251
+ Rubygame.init_video_system
252
+
253
+ name = case key
254
+ when SDL::K_1; "number 1"
255
+ when SDL::K_2; "number 2"
256
+ when SDL::K_3; "number 3"
257
+ when SDL::K_4; "number 4"
258
+ when SDL::K_5; "number 5"
259
+ when SDL::K_6; "number 6"
260
+ when SDL::K_7; "number 7"
261
+ when SDL::K_8; "number 8"
262
+ when SDL::K_9; "number 9"
263
+ when SDL::K_0; "number 0"
264
+ when SDL::K_EXCLAIM; "exclamation mark"
265
+ when SDL::K_QUOTEDBL; "double quote"
266
+ when SDL::K_HASH; "hash"
267
+ when SDL::K_DOLLAR; "dollar"
268
+ when SDL::K_AMPERSAND; "ampersand"
269
+ when SDL::K_QUOTE; "quote"
270
+ when SDL::K_LEFTPAREN; "left parenthesis"
271
+ when SDL::K_RIGHTPAREN; "right parenthesis"
272
+ when SDL::K_ASTERISK; "asterisk"
273
+ when SDL::K_PLUS; "plus"
274
+ when SDL::K_MINUS; "minus"
275
+ when SDL::K_PERIOD; "period"
276
+ when SDL::K_COMMA; "comma"
277
+ when SDL::K_SLASH; "slash"
278
+ when SDL::K_SEMICOLON; "semicolon"
279
+ when SDL::K_LESS; "less than"
280
+ when SDL::K_EQUALS; "equals"
281
+ when SDL::K_GREATER; "greater than"
282
+ when SDL::K_QUESTION; "question mark"
283
+ when SDL::K_AT; "at"
284
+ when SDL::K_LEFTBRACKET; "left bracket"
285
+ when SDL::K_BACKSLASH; "backslash"
286
+ when SDL::K_RIGHTBRACKET; "right bracket"
287
+ when SDL::K_CARET; "caret"
288
+ when SDL::K_UNDERSCORE; "underscore"
289
+ when SDL::K_BACKQUOTE; "backquote"
290
+ when SDL::K_KP1; "keypad 1"
291
+ when SDL::K_KP2; "keypad 2"
292
+ when SDL::K_KP3; "keypad 3"
293
+ when SDL::K_KP4; "keypad 4"
294
+ when SDL::K_KP5; "keypad 5"
295
+ when SDL::K_KP6; "keypad 6"
296
+ when SDL::K_KP7; "keypad 7"
297
+ when SDL::K_KP8; "keypad 8"
298
+ when SDL::K_KP9; "keypad 9"
299
+ when SDL::K_KP0; "keypad 0"
300
+ when SDL::K_KP_PERIOD; "keypad period"
301
+ when SDL::K_KP_DIVIDE; "keypad divide"
302
+ when SDL::K_KP_MULTIPLY; "keypad multiply"
303
+ when SDL::K_KP_MINUS; "keypad minus"
304
+ when SDL::K_KP_PLUS; "keypad plus"
305
+ when SDL::K_KP_EQUALS; "keypad equals"
306
+ when SDL::K_KP_ENTER; "keypad enter"
307
+ else; SDL::GetKeyName( key )
308
+ end
309
+
310
+ name.downcase!
311
+ name.gsub!(/[- ]/, "_")
312
+ return name.to_sym
313
+ end
314
+
315
+
316
+
317
+ # Convert an OR'd list of KMODs into an Array of symbols.
318
+ #
319
+ def self._convert_keymods( mods )
320
+ return [] if mods == 0
321
+
322
+ array = []
323
+ array << :left_shift if( mods & SDL::KMOD_LSHIFT )
324
+ array << :right_shift if( mods & SDL::KMOD_RSHIFT )
325
+ array << :left_ctrl if( mods & SDL::KMOD_LCTRL )
326
+ array << :right_ctrl if( mods & SDL::KMOD_RCTRL )
327
+ array << :left_alt if( mods & SDL::KMOD_LALT )
328
+ array << :right_alt if( mods & SDL::KMOD_RALT )
329
+ array << :left_meta if( mods & SDL::KMOD_LMETA )
330
+ array << :right_meta if( mods & SDL::KMOD_RMETA )
331
+ array << :numlock if( mods & SDL::KMOD_NUM )
332
+ array << :capslock if( mods & SDL::KMOD_CAPS )
333
+ array << :mode if( mods & SDL::KMOD_MODE )
334
+
335
+ return array
336
+ end
337
+
338
+
339
+
340
+ # Convert a Unicode char into a UTF8 ruby byte-string.
341
+ #
342
+ def self._convert_unicode( int )
343
+ if( int > 0 )
344
+ [int].pack('U')
345
+ else
346
+ ""
347
+ end
348
+ end
349
+
350
+
351
+
352
+ # Convert SDL's keyboard events into KeyPressed / KeyReleased.
353
+ #
354
+ def self._convert_keyboardevent( ev )
355
+ key = _convert_key_symbol( ev.keysym.sym );
356
+ mods = _convert_keymods( ev.keysym.mod );
357
+
358
+ case ev.state
359
+ when SDL::PRESSED
360
+ unicode = _convert_unicode( ev.keysym.unicode )
361
+ KeyPressed.new( key, mods, unicode )
362
+ when SDL::RELEASED
363
+ KeyReleased.new( key, mods )
364
+ else
365
+ raise( Rubygame::SDLError, "Unknown keyboard event state "+
366
+ "#{ev.key.state}. This is a bug in Rubygame." )
367
+ end
368
+ end
369
+
370
+
371
+
372
+ # Convert SDL's mouse click events into MousePressed / MouseReleased.
373
+ #
374
+ def self._convert_mouseclickevent( ev )
375
+ button = case ev.button
376
+ when SDL::BUTTON_LEFT; :mouse_left
377
+ when SDL::BUTTON_MIDDLE; :mouse_middle
378
+ when SDL::BUTTON_RIGHT; :mouse_right
379
+ when SDL::BUTTON_WHEELUP; :mouse_wheel_up
380
+ when SDL::BUTTON_WHEELDOWN; :mouse_wheel_down
381
+ else; ("mouse_%d"%button).to_sym
382
+ end
383
+
384
+ pos = [ev.x, ev.y]
385
+
386
+ case ev.state
387
+ when SDL::PRESSED
388
+ MousePressed.new( pos, button )
389
+ when SDL::RELEASED
390
+ MouseReleased.new( pos, button )
391
+ else
392
+ raise( Rubygame::SDLError, "Unknown mouse event state "+
393
+ "#{ev.button.state}. This is a bug in Rubygame." )
394
+ end
395
+ end
396
+
397
+
398
+
399
+ # Convert SDL's mouse motion events into MouseMoved
400
+ #
401
+ def self._convert_mousemotionevent( ev )
402
+ mods = ev.state
403
+
404
+ btns = []
405
+ btns << :mouse_left if( mods & SDL::BUTTON_LMASK )
406
+ btns << :mouse_middle if( mods & SDL::BUTTON_MMASK )
407
+ btns << :mouse_right if( mods & SDL::BUTTON_RMASK )
408
+ btns << :mouse_wheel_up if( mods & (1<<(SDL::BUTTON_WHEELUP - 1)) )
409
+ btns << :mouse_wheel_down if( mods & (1<<(SDL::BUTTON_WHEELDOWN - 1)) )
410
+
411
+ pos = [ev.x, ev.y]
412
+ rel = [ev.xrel, ev.yrel]
413
+
414
+ return MouseMoved.new( pos, rel, btns )
415
+ end
416
+
417
+
418
+
419
+ # Converts an SDL_Event (C type) into a Rubygame event of the
420
+ # corresponding class.
421
+ #
422
+ def self._convert_sdlevent( ev )
423
+ case ev
424
+ when SDL::ActiveEvent
425
+ return _convert_activeevent(ev)
426
+ when SDL::ExposeEvent
427
+ return WindowExposed.new()
428
+ when SDL::JoyAxisEvent
429
+ return _convert_joyaxisevent(ev)
430
+ when SDL::JoyBallEvent
431
+ return _convert_joyballevent(ev)
432
+ when SDL::JoyButtonEvent
433
+ return _convert_joybuttonevent(ev)
434
+ when SDL::JoyHatEvent
435
+ return _convert_joyhatevent(ev)
436
+ when SDL::KeyboardEvent
437
+ return _convert_keyboardevent(ev)
438
+ when SDL::MouseButtonEvent
439
+ return _convert_mouseclickevent(ev)
440
+ when SDL::MouseMotionEvent
441
+ return _convert_mousemotionevent(ev)
442
+ when SDL::ResizeEvent
443
+ return WindowResized.new( [ev.w, ev.h] )
444
+ when SDL::QuitEvent
445
+ return QuitRequested.new()
446
+ end
447
+ end
448
+
449
+
35
450
  end
36
451
 
37
452
  end