rubysdl 1.3.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/MANIFEST +22 -2
  2. data/NEWS.en +80 -0
  3. data/NEWS.ja +83 -0
  4. data/README.en +2 -1
  5. data/README.ja +2 -2
  6. data/doc-en/Makefile +18 -0
  7. data/doc-en/cdrom.rsd +417 -0
  8. data/doc-en/collision.rsd +174 -0
  9. data/doc-en/event.rsd +1476 -0
  10. data/doc-en/font.rsd +811 -0
  11. data/doc-en/general.rsd +43 -0
  12. data/doc-en/init.rsd +168 -0
  13. data/doc-en/joystick.rsd +401 -0
  14. data/doc-en/mixer.rsd +869 -0
  15. data/doc-en/mpeg.rsd +585 -0
  16. data/doc-en/opengl.rsd +155 -0
  17. data/doc-en/sdlskk.rsd +472 -0
  18. data/doc-en/time.rsd +46 -0
  19. data/doc-en/video.rsd +2806 -0
  20. data/doc-en/wm.rsd +112 -0
  21. data/doc/Makefile +1 -1
  22. data/doc/cdrom.rsd +3 -3
  23. data/doc/event.rsd +178 -179
  24. data/doc/general.rsd +10 -0
  25. data/doc/init.rsd +2 -2
  26. data/doc/joystick.rsd +29 -5
  27. data/doc/mixer.rsd +20 -0
  28. data/doc/rsd.rb +42 -9
  29. data/doc/sdlskk.rsd +7 -7
  30. data/doc/video.rsd +461 -168
  31. data/doc/wm.rsd +2 -2
  32. data/extconf.rb +1 -8
  33. data/lib/rubysdl_aliases.rb +52 -190
  34. data/lib/rubysdl_compatible_ver1.rb +243 -0
  35. data/lib/sdl.rb +58 -92
  36. data/rubysdl.h +59 -68
  37. data/rubysdl_cdrom.c +125 -102
  38. data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
  39. data/rubysdl_event.c +318 -255
  40. data/rubysdl_event_key.c +299 -287
  41. data/rubysdl_image.c +37 -13
  42. data/rubysdl_joystick.c +180 -67
  43. data/rubysdl_kanji.c +61 -75
  44. data/rubysdl_main.c +65 -138
  45. data/rubysdl_mixer.c +339 -214
  46. data/rubysdl_mouse.c +50 -43
  47. data/rubysdl_opengl.c +31 -28
  48. data/rubysdl_pixel.c +17 -28
  49. data/rubysdl_ref.en.html +5658 -0
  50. data/rubysdl_ref.en.rd +6337 -0
  51. data/rubysdl_ref.html +2253 -1964
  52. data/rubysdl_ref.rd +823 -469
  53. data/rubysdl_rwops.c +9 -6
  54. data/rubysdl_sdlskk.c +137 -165
  55. data/rubysdl_sge_video.c +355 -469
  56. data/rubysdl_smpeg.c +189 -190
  57. data/rubysdl_time.c +1 -1
  58. data/rubysdl_ttf.c +147 -215
  59. data/rubysdl_video.c +486 -405
  60. data/rubysdl_wm.c +30 -30
  61. data/sample/aadraw.rb +9 -9
  62. data/sample/alpha.rb +12 -13
  63. data/sample/alphadraw.rb +10 -10
  64. data/sample/bfont.rb +4 -4
  65. data/sample/cdrom.rb +11 -4
  66. data/sample/collision.rb +20 -20
  67. data/sample/cursor.rb +5 -5
  68. data/sample/ellipses.rb +20 -16
  69. data/sample/event2.rb +11 -9
  70. data/sample/font.rb +4 -4
  71. data/sample/fpstimer.rb +3 -3
  72. data/sample/icon.bmp.gz +0 -0
  73. data/sample/icon.png +0 -0
  74. data/sample/joy2.rb +14 -14
  75. data/sample/kanji.rb +7 -7
  76. data/sample/load_from_io.rb +44 -0
  77. data/sample/movesp.rb +13 -12
  78. data/sample/playmod.rb +2 -3
  79. data/sample/plaympeg.rb +8 -8
  80. data/sample/playwave.rb +5 -6
  81. data/sample/sdlskk.rb +11 -11
  82. data/sample/sgetest.rb +14 -12
  83. data/sample/stetris.rb +12 -13
  84. data/sample/testgl.rb +13 -14
  85. data/sample/testsprite.rb +12 -11
  86. data/sample/transformblit.rb +23 -22
  87. metadata +62 -35
  88. data/rubysdl_event2.c +0 -417
@@ -1572,10 +1572,10 @@ Object
1572
1572
  === class method
1573
1573
 
1574
1574
  --- SDL::Joystick.pall
1575
- Return whether Joystick.updateAll is called automatically.
1575
+ Return whether ((<SDL::Joystick.updateAll>)) is called automatically.
1576
1576
 
1577
1577
  --- SDL::JoyStick.pall=(polling)
1578
- Set whether Joystick.updateAll is called automatically and
1578
+ Set whether ((<SDL::Joystick.updateAll>)) is called automatically and
1579
1579
  whether joystick events are processed.
1580
1580
  Default is true, and you shouldn't change.
1581
1581
 
@@ -1599,6 +1599,7 @@ Object
1599
1599
 
1600
1600
  --- SDL::Joystick.updateAll
1601
1601
  --- SDL::Joystick.update_all
1602
+ --- SDL::Joystick.update
1602
1603
  Updates the state(position, buttons, etc.) of all open joysticks.
1603
1604
 
1604
1605
  === method
data/rubysdl_event.c CHANGED
@@ -17,330 +17,393 @@
17
17
  License along with this library; if not, write to the Free Software
18
18
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
  */
20
+
20
21
  #include "rubysdl.h"
21
22
 
22
- void eventCheck(int pred,char *msg)
23
+ static VALUE cEvent;
24
+ static VALUE cActiveEvent;
25
+ static VALUE cKeyDownEvent;
26
+ static VALUE cKeyUpEvent;
27
+ static VALUE cMouseMotionEvent;
28
+ static VALUE cMouseButtonDownEvent;
29
+ static VALUE cMouseButtonUpEvent;
30
+ static VALUE cJoyAxisEvent;
31
+ static VALUE cJoyBallEvent;
32
+ static VALUE cJoyHatEvent;
33
+ static VALUE cJoyButtonUpEvent;
34
+ static VALUE cJoyButtonDownEvent;
35
+ static VALUE cQuitEvent;
36
+ static VALUE cSysWMEvent;
37
+ static VALUE cVideoResizeEvent;
38
+
39
+ typedef VALUE (*event_creator)(SDL_Event *);
40
+ static event_creator event_creators[SDL_NUMEVENTS];
41
+
42
+ static VALUE createNoEvent(SDL_Event *event)
23
43
  {
24
- if(!pred)
25
- rb_raise(eSDLError,"this event is not %s event",msg) ;
44
+ return Qnil;
26
45
  }
27
-
28
- static VALUE createEventObject(VALUE class)
46
+
47
+ static VALUE createActiveEvent(SDL_Event *event)
29
48
  {
30
- SDL_Event *event;
31
-
32
- return Data_Make_Struct(class,SDL_Event,0,free,event);
49
+ VALUE obj = rb_obj_alloc(cActiveEvent);
50
+ rb_iv_set(obj, "@gain", INT2BOOL(event->active.gain));
51
+ rb_iv_set(obj, "@state", INT2FIX(event->active.state));
52
+ return obj;
33
53
  }
34
54
 
35
- static VALUE sdl_pollEvent(VALUE obj)
55
+ static VALUE createKeyEvent(VALUE obj, SDL_Event *event)
36
56
  {
37
- SDL_Event *event;
57
+ rb_iv_set(obj, "@press", INT2BOOL(event->key.state == SDL_PRESSED));
58
+ rb_iv_set(obj, "@sym", INT2FIX(event->key.keysym.sym));
59
+ rb_iv_set(obj, "@mod", UINT2NUM(event->key.keysym.mod));
60
+ rb_iv_set(obj, "@unicode", UINT2NUM(event->key.keysym.unicode));
61
+ return obj;
62
+ }
38
63
 
39
- Data_Get_Struct(obj,SDL_Event,event);
40
- return INT2NUM(SDL_PollEvent(event));
64
+ static VALUE createKeyDownEvent(SDL_Event *event)
65
+ {
66
+ VALUE obj = rb_obj_alloc(cKeyDownEvent);
67
+ return createKeyEvent(obj, event);
41
68
  }
42
- static VALUE sdl_waitEvent(VALUE obj)
69
+
70
+ static VALUE createKeyUpEvent(SDL_Event *event)
43
71
  {
44
- SDL_Event *event;
72
+ VALUE obj = rb_obj_alloc(cKeyUpEvent);
73
+ return createKeyEvent(obj, event);
74
+ }
45
75
 
46
- Data_Get_Struct(obj,SDL_Event,event);
47
- if( SDL_WaitEvent(event)==0 )
48
- rb_raise(eSDLError,"SDL_WaitEvent Failed :%s",SDL_GetError());
49
- return Qnil;
76
+ static VALUE createMouseMotionEvent(SDL_Event *event)
77
+ {
78
+ VALUE obj = rb_obj_alloc(cMouseMotionEvent);
79
+ rb_iv_set(obj, "@state", INT2FIX(event->motion.state));
80
+ rb_iv_set(obj, "@x", INT2FIX(event->motion.x));
81
+ rb_iv_set(obj, "@y", INT2FIX(event->motion.y));
82
+ rb_iv_set(obj, "@xrel", INT2FIX(event->motion.xrel));
83
+ rb_iv_set(obj, "@yrel", INT2FIX(event->motion.yrel));
84
+ return obj;
50
85
  }
51
86
 
52
- static VALUE sdl_eventType(VALUE obj)
87
+ static VALUE createMouseButtonEvent(VALUE obj, SDL_Event *event)
53
88
  {
54
- SDL_Event *event;
89
+ rb_iv_set(obj, "@button", INT2FIX(event->button.button));
90
+ rb_iv_set(obj, "@press", INT2BOOL(event->button.state == SDL_PRESSED));
91
+ rb_iv_set(obj, "@x", INT2FIX(event->button.x));
92
+ rb_iv_set(obj, "@y", INT2FIX(event->button.y));
93
+ return obj;
94
+ }
55
95
 
56
- Data_Get_Struct(obj,SDL_Event,event);
57
- return INT2FIX(event->type);
96
+ static VALUE createMouseButtonDownEvent(SDL_Event *event)
97
+ {
98
+ VALUE obj = rb_obj_alloc(cMouseButtonDownEvent);
99
+ return createMouseButtonEvent(obj, event);
58
100
  }
59
101
 
60
- /* --KeyboardEvent-- */
61
- static VALUE sdl_eventKeyPressed(VALUE obj)
102
+ static VALUE createMouseButtonUpEvent(SDL_Event *event)
62
103
  {
63
- SDL_Event *event;
64
-
65
- Data_Get_Struct(obj,SDL_Event,event);
66
- eventCheck((event->type == SDL_KEYDOWN)||(event->type == SDL_KEYUP),"key");
67
- if( event->key.state==SDL_PRESSED )
68
- return Qtrue;
69
- else
70
- return Qfalse;
104
+ VALUE obj = rb_obj_alloc(cMouseButtonUpEvent);
105
+ return createMouseButtonEvent(obj, event);
71
106
  }
72
- static VALUE sdl_eventKeyMod(VALUE obj)
107
+
108
+ static VALUE createJoyAxisEvent(SDL_Event *event)
73
109
  {
74
- SDL_Event *event;
75
-
76
- Data_Get_Struct(obj,SDL_Event,event);
77
- eventCheck((event->type == SDL_KEYDOWN)||(event->type == SDL_KEYUP),"key");
78
- return INT2NUM(event->key.keysym.mod);
110
+ VALUE obj = rb_obj_alloc(cJoyAxisEvent);
111
+ rb_iv_set(obj, "@which", INT2FIX(event->jaxis.which));
112
+ rb_iv_set(obj, "@axis", INT2FIX(event->jaxis.axis));
113
+ rb_iv_set(obj, "@value", INT2FIX(event->jaxis.value));
114
+ return obj;
79
115
  }
80
- static VALUE sdl_eventKeySym(VALUE obj)
116
+
117
+ static VALUE createJoyBallEvent(SDL_Event *event)
81
118
  {
82
- SDL_Event *event;
83
-
84
- Data_Get_Struct(obj,SDL_Event,event);
85
- eventCheck((event->type == SDL_KEYDOWN)||(event->type == SDL_KEYUP),"key");
86
- return INT2FIX(event->key.keysym.sym);
119
+ VALUE obj = rb_obj_alloc(cJoyBallEvent);
120
+ rb_iv_set(obj, "@which", INT2FIX(event->jball.which));
121
+ rb_iv_set(obj, "@ball", INT2FIX(event->jball.ball));
122
+ rb_iv_set(obj, "@xrel", INT2FIX(event->jball.xrel));
123
+ rb_iv_set(obj, "@yrel", INT2FIX(event->jball.yrel));
124
+ return obj;
87
125
  }
88
126
 
89
- /* --ActiveEvent-- */
90
- static VALUE sdl_eventActiveGained(VALUE obj)
127
+ static VALUE createJoyHatEvent(SDL_Event *event)
91
128
  {
92
- SDL_Event *event;
93
-
94
- Data_Get_Struct(obj,SDL_Event,event);
95
- eventCheck( event->type == SDL_ACTIVEEVENT , "active" );
96
- return (event->active.gain)?Qtrue:Qfalse;
129
+ VALUE obj = rb_obj_alloc(cJoyHatEvent);
130
+ rb_iv_set(obj, "@which", INT2FIX(event->jhat.which));
131
+ rb_iv_set(obj, "@hat", INT2FIX(event->jhat.hat));
132
+ rb_iv_set(obj, "@value", INT2FIX(event->jhat.value));
133
+ return obj;
97
134
  }
98
- static VALUE sdl_eventActiveState(VALUE obj)
135
+
136
+ static VALUE createJoyButtonEvent(VALUE obj, SDL_Event *event)
99
137
  {
100
- SDL_Event *event;
101
-
102
- Data_Get_Struct(obj,SDL_Event,event);
103
- eventCheck( event->type == SDL_ACTIVEEVENT , "active" );
104
- return INT2NUM(event->active.state);
138
+ rb_iv_set(obj, "@which", INT2FIX(event->jbutton.which));
139
+ rb_iv_set(obj, "@button", INT2FIX(event->jbutton.button));
140
+ rb_iv_set(obj, "@press", INT2BOOL(event->jbutton.state == SDL_PRESSED));
141
+ return obj;
142
+ }
143
+ static VALUE createJoyButtonUpEvent(SDL_Event *event)
144
+ {
145
+ VALUE obj = rb_obj_alloc(cJoyButtonUpEvent);
146
+ return createJoyButtonEvent(obj, event);
105
147
  }
106
148
 
107
- /* --MouseMotionEvent-- */
108
- static VALUE sdl_eventMouseX(VALUE obj)
149
+ static VALUE createJoyButtonDownEvent(SDL_Event *event)
109
150
  {
110
- SDL_Event *event;
111
-
112
- Data_Get_Struct(obj,SDL_Event,event);
113
- switch (event->type){
114
- case SDL_MOUSEMOTION:
115
- return INT2NUM(event->motion.x);
116
- case SDL_MOUSEBUTTONUP:
117
- case SDL_MOUSEBUTTONDOWN:
118
- return INT2NUM(event->button.x);
119
- default:
120
- eventCheck(0,"mouse"); /* raise exception */
121
- }
122
- return Qnil; /* never reach */
151
+ VALUE obj = rb_obj_alloc(cJoyButtonDownEvent);
152
+ return createJoyButtonEvent(obj, event);
123
153
  }
124
- static VALUE sdl_eventMouseY(VALUE obj)
154
+
155
+ static VALUE createQuitEvent(SDL_Event *event)
125
156
  {
126
- SDL_Event *event;
127
-
128
- Data_Get_Struct(obj,SDL_Event,event);
129
- switch (event->type){
130
- case SDL_MOUSEMOTION:
131
- return INT2NUM(event->motion.y);
132
- case SDL_MOUSEBUTTONUP:
133
- case SDL_MOUSEBUTTONDOWN:
134
- return INT2NUM(event->button.y);
135
- default:
136
- eventCheck(0,"mouse"); /* raise exception */
137
- }
138
- return Qnil; /* never reach */
157
+ VALUE obj = rb_obj_alloc(cQuitEvent);
158
+ return obj;
159
+ }
160
+
161
+ static VALUE createSysWMEvent(SDL_Event *event)
162
+ {
163
+ VALUE obj = rb_obj_alloc(cSysWMEvent);
164
+ return obj;
139
165
  }
140
- static VALUE sdl_eventMouseXrel(VALUE obj)
166
+
167
+ static VALUE createVideoResizeEvent(SDL_Event *event)
141
168
  {
142
- SDL_Event *event;
143
-
144
- Data_Get_Struct(obj,SDL_Event,event);
145
- eventCheck(event->type==SDL_MOUSEMOTION,"mouse motion");
146
- return INT2NUM(event->motion.xrel);
169
+ VALUE obj = rb_obj_alloc(cVideoResizeEvent);
170
+ rb_iv_set(obj, "@w", INT2FIX(event->resize.w));
171
+ rb_iv_set(obj, "@h", INT2FIX(event->resize.h));
172
+ return obj;
147
173
  }
148
- static VALUE sdl_eventMouseYrel(VALUE obj)
174
+
175
+ /* class method */
176
+ static VALUE Event_s_poll(VALUE class)
149
177
  {
150
- SDL_Event *event;
151
-
152
- Data_Get_Struct(obj,SDL_Event,event);
153
- eventCheck(event->type==SDL_MOUSEMOTION,"mouse motion");
154
- return INT2NUM(event->motion.yrel);
178
+ SDL_Event event;
179
+ rb_secure(4);
180
+ if( SDL_PollEvent(&event) == 1)
181
+ return event_creators[event.type](&event);
182
+ else
183
+ return Qnil;
184
+ }
185
+ static VALUE Event_s_wait(VALUE class)
186
+ {
187
+ SDL_Event event;
188
+ rb_secure(4);
189
+ if( SDL_WaitEvent(&event) == 1)
190
+ return event_creators[event.type](&event);
191
+ else
192
+ rb_raise(eSDLError, "Event handling error");
155
193
  }
156
194
 
157
- /* --SDL_MouseButtonEvent-- */
158
- static VALUE sdl_eventMouseButton(VALUE obj)
195
+ static VALUE Event_s_pump(VALUE class)
159
196
  {
160
- SDL_Event *event;
161
-
162
- Data_Get_Struct(obj,SDL_Event,event);
163
- eventCheck( (event->type==SDL_MOUSEBUTTONUP)||
164
- (event->type==SDL_MOUSEBUTTONDOWN) , "mouse button" );
165
- return INT2NUM( event->button.button );
197
+ SDL_PumpEvents();
198
+ return Qnil;
166
199
  }
167
- static VALUE sdl_eventMousePressed(VALUE obj)
200
+
201
+ static VALUE Event_s_new(VALUE class)
168
202
  {
169
- SDL_Event *event;
170
-
171
- Data_Get_Struct(obj,SDL_Event,event);
172
- eventCheck( (event->type==SDL_MOUSEBUTTONUP)||
173
- ( event->type==SDL_MOUSEBUTTONDOWN) , "mouse button" );
174
- return (event->button.state==SDL_PRESSED)?Qtrue:Qfalse;
203
+ return rb_obj_alloc(class);
175
204
  }
176
205
 
177
- static VALUE sdl_eventInfo(VALUE obj)
206
+ static VALUE Event_s_push(VALUE class, VALUE event)
178
207
  {
179
- SDL_Event *event;
180
-
181
- Data_Get_Struct(obj,SDL_Event,event);
182
- switch(event->type){
183
- case SDL_ACTIVEEVENT:
184
- return rb_ary_new3(3,INT2FIX(SDL_ACTIVEEVENT),BOOL(event->active.gain),
185
- INT2FIX(event->active.state));
186
- case SDL_KEYDOWN:
187
- case SDL_KEYUP:
188
- return rb_ary_new3( 4, INT2FIX(event->type),
189
- BOOL(event->key.state==SDL_PRESSED),
190
- INT2FIX(event->key.keysym.sym),
191
- UINT2NUM(event->key.keysym.mod)
192
- );
193
- case SDL_MOUSEMOTION:
194
- return rb_ary_new3( 6, INT2FIX(SDL_MOUSEMOTION),
195
- INT2FIX(event->motion.state),
196
- INT2FIX(event->motion.x),
197
- INT2FIX(event->motion.y),
198
- INT2FIX(event->motion.xrel),
199
- INT2FIX(event->motion.yrel)
200
- );
201
- case SDL_MOUSEBUTTONDOWN:
202
- case SDL_MOUSEBUTTONUP:
203
- return rb_ary_new3( 5, INT2FIX(event->type),
204
- INT2FIX(event->button.button),
205
- BOOL(event->button.state==SDL_PRESSED),
206
- INT2FIX(event->button.x),
207
- INT2FIX(event->button.y)
208
- );
209
- case SDL_JOYAXISMOTION:
210
- return rb_ary_new3( 4, INT2FIX(SDL_JOYAXISMOTION),
211
- INT2FIX(event->jaxis.which),
212
- INT2FIX(event->jaxis.axis),
213
- INT2FIX(event->jaxis.value)
214
- );
215
- case SDL_JOYBALLMOTION:
216
- return rb_ary_new3( 5, INT2FIX(SDL_JOYBALLMOTION),
217
- INT2FIX(event->jball.which),
218
- INT2FIX(event->jball.ball),
219
- INT2FIX(event->jball.xrel),
220
- INT2FIX(event->jball.yrel)
221
- );
222
- case SDL_JOYHATMOTION:
223
- return rb_ary_new3( 4, INT2FIX(SDL_JOYHATMOTION),
224
- INT2FIX(event->jhat.which),
225
- INT2FIX(event->jhat.hat),
226
- INT2FIX(event->jhat.value)
227
- );
228
- case SDL_JOYBUTTONDOWN:
229
- case SDL_JOYBUTTONUP:
230
- return rb_ary_new3( 4, INT2FIX(event->type),
231
- INT2FIX(event->jbutton.which),
232
- INT2FIX(event->jbutton.button),
233
- BOOL(event->jbutton.state==SDL_PRESSED)
234
- );
235
- case SDL_QUIT:
236
- return rb_ary_new3( 1, INT2FIX(SDL_QUIT));
237
- case SDL_SYSWMEVENT:
238
- return rb_ary_new3( 1, INT2FIX(SDL_SYSWMEVENT));
239
- case SDL_VIDEORESIZE:
240
- return rb_ary_new3( 3, INT2FIX(SDL_VIDEORESIZE),
241
- INT2FIX(event->resize.w),
242
- INT2FIX(event->resize.h)
243
- );
208
+ SDL_Event e;
209
+ VALUE eventClass;
210
+ rb_secure(4);
211
+ eventClass = CLASS_OF(event);
212
+ if(eventClass == cActiveEvent){
213
+ e.type = SDL_ACTIVEEVENT;
214
+ e.active.gain = rb_iv_get(event, "@gain");
215
+ e.active.state = NUM2INT(rb_iv_get(event, "@state"));
216
+ }else if(eventClass == cKeyDownEvent){
217
+ e.type=SDL_KEYDOWN;
218
+ e.key.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
219
+ e.key.keysym.sym = NUM2INT(rb_iv_get(event, "@sym"));
220
+ e.key.keysym.mod = NUM2UINT(rb_iv_get(event, "@mod"));
221
+ e.key.keysym.unicode = NUM2UINT( rb_iv_get(event, "@unicode") );
222
+ }else if(eventClass == cKeyUpEvent){
223
+ e.type = SDL_KEYUP;
224
+ e.key.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
225
+ e.key.keysym.sym = NUM2INT(rb_iv_get(event, "@sym"));
226
+ e.key.keysym.mod = NUM2UINT(rb_iv_get(event, "@mod"));
227
+ e.key.keysym.unicode = NUM2UINT( rb_iv_get(event, "@unicode") );
228
+ }else if(eventClass == cMouseMotionEvent){
229
+ e.type=SDL_MOUSEMOTION;
230
+ e.motion.state = NUM2INT(rb_iv_get(event, "@state"));
231
+ e.motion.x = NUM2INT(rb_iv_get(event, "@x"));
232
+ e.motion.y = NUM2INT(rb_iv_get(event, "@y"));
233
+ e.motion.xrel = NUM2INT(rb_iv_get(event, "@xrel"));
234
+ e.motion.yrel = NUM2INT(rb_iv_get(event, "@yrel"));
235
+ }else if(eventClass == cMouseButtonDownEvent){
236
+ e.type = SDL_MOUSEBUTTONDOWN;
237
+ e.button.button = NUM2INT(rb_iv_get(event, "@button"));
238
+ e.button.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
239
+ e.button.x = NUM2INT(rb_iv_get(event, "@x"));
240
+ e.button.y = NUM2INT(rb_iv_get(event, "@y"));
241
+ }else if(eventClass == cMouseButtonUpEvent){
242
+ e.type = SDL_MOUSEBUTTONUP;
243
+ e.button.button = NUM2INT(rb_iv_get(event, "@button"));
244
+ e.button.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
245
+ e.button.x = NUM2INT(rb_iv_get(event, "@x"));
246
+ e.button.y = NUM2INT(rb_iv_get(event, "@y"));\
247
+ }else if(eventClass == cJoyAxisEvent){
248
+ e.type = SDL_JOYAXISMOTION;
249
+ e.jaxis.which = NUM2INT(rb_iv_get(event, "@which"));
250
+ e.jaxis.axis = NUM2INT(rb_iv_get(event, "@axis"));
251
+ e.jaxis.value = NUM2INT(rb_iv_get(event, "@value"));
252
+ }else if(eventClass == cJoyBallEvent){
253
+ e.type = SDL_JOYBALLMOTION;
254
+ e.jball.which = NUM2INT(rb_iv_get(event, "@which"));
255
+ e.jball.ball = NUM2INT(rb_iv_get(event, "@ball"));
256
+ e.jball.xrel = NUM2INT(rb_iv_get(event, "@xrel"));
257
+ e.jball.yrel = NUM2INT(rb_iv_get(event, "@yrel"));
258
+ }else if(eventClass == cJoyHatEvent){
259
+ e.type = SDL_JOYHATMOTION;
260
+ e.jhat.which = NUM2INT(rb_iv_get(event, "@which"));
261
+ e.jhat.hat = NUM2INT(rb_iv_get(event, "@hat"));
262
+ e.jhat.value = NUM2INT(rb_iv_get(event, "@value"));
263
+ }else if(eventClass == cJoyButtonUpEvent){
264
+ e.type = SDL_JOYBUTTONUP;
265
+ e.jbutton.which = NUM2INT(rb_iv_get(event, "@which"));
266
+ e.jbutton.button = NUM2INT(rb_iv_get(event, "@button"));
267
+ e.jbutton.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
268
+ }else if(eventClass == cJoyButtonDownEvent){
269
+ e.type = SDL_JOYBUTTONDOWN;
270
+ e.jbutton.which = NUM2INT(rb_iv_get(event, "@which"));
271
+ e.jbutton.button = NUM2INT(rb_iv_get(event, "@button"));
272
+ e.jbutton.state = (rb_iv_get(event, "@press"))?SDL_PRESSED:SDL_RELEASED;
273
+ }else if(eventClass == cQuitEvent){
274
+ e.type = SDL_QUIT;
275
+ }else if(eventClass == cSysWMEvent){
276
+ e.type = SDL_SYSWMEVENT;
277
+ }else if(eventClass == cVideoResizeEvent){
278
+ e.type = SDL_VIDEORESIZE;
279
+ e.resize.w = NUM2INT(rb_iv_get(event, "@w"));
280
+ e.resize.h = NUM2INT(rb_iv_get(event, "@h"));
281
+ }else {
282
+ rb_raise(eSDLError, "This object couldn't be pushed");
244
283
  }
284
+ if(SDL_PushEvent(&e) == -1)
285
+ rb_raise(eSDLError, "the event couldn't be pushed");
245
286
  return Qnil;
246
287
  }
247
-
248
- static VALUE sdl_getAppState(VALUE class)
288
+ static VALUE Event_s_getAppState(VALUE class)
249
289
  {
250
290
  return INT2FIX(SDL_GetAppState());
251
291
  }
252
292
 
253
- static VALUE sdl_enableUNICODE(VALUE class)
293
+ static VALUE Event_s_enableUNICODE(VALUE class)
254
294
  {
295
+ rb_secure(4);
255
296
  SDL_EnableUNICODE(1);
256
297
  return Qnil;
257
298
  }
258
- static VALUE sdl_disableUNICODE(VALUE class)
299
+ static VALUE Event_s_disableUNICODE(VALUE class)
259
300
  {
301
+ rb_secure(4);
260
302
  SDL_EnableUNICODE(0);
261
303
  return Qnil;
262
304
  }
263
- static VALUE sdl_is_enableUNICODE(VALUE class)
305
+ static VALUE Event_s_is_enableUNICODE(VALUE class)
264
306
  {
265
- return BOOL(SDL_EnableUNICODE(-1));
307
+ return INT2BOOL(SDL_EnableUNICODE(-1));
266
308
  }
267
309
 
268
- static void defineConstForEvent()
310
+ void rubysdl_init_Event(VALUE mSDL)
269
311
  {
270
- rb_define_const(cEvent,"NOEVENT",INT2NUM(SDL_NOEVENT));
271
- rb_define_const(cEvent,"ACTIVEEVENT",INT2NUM(SDL_ACTIVEEVENT));
272
- rb_define_const(cEvent,"KEYDOWN",INT2NUM(SDL_KEYDOWN));
273
- rb_define_const(cEvent,"KEYUP",INT2NUM(SDL_KEYUP));
274
- rb_define_const(cEvent,"MOUSEMOTION",INT2NUM(SDL_MOUSEMOTION));
275
- rb_define_const(cEvent,"MOUSEBUTTONDOWN",INT2NUM(SDL_MOUSEBUTTONDOWN));
276
- rb_define_const(cEvent,"MOUSEBUTTONUP",INT2NUM(SDL_MOUSEBUTTONUP));
277
- rb_define_const(cEvent,"JOYAXISMOTION",INT2NUM(SDL_JOYAXISMOTION));
278
- rb_define_const(cEvent,"JOYBALLMOTION",INT2NUM(SDL_JOYBALLMOTION));
279
- rb_define_const(cEvent,"JOYHATMOTION",INT2NUM(SDL_JOYHATMOTION));
280
- rb_define_const(cEvent,"JOYBUTTONDOWN",INT2NUM(SDL_JOYBUTTONDOWN));
281
- rb_define_const(cEvent,"JOYBUTTONUP",INT2NUM(SDL_JOYBUTTONUP));
282
- rb_define_const(cEvent,"QUIT",INT2NUM(SDL_QUIT));
283
- rb_define_const(cEvent,"SYSWMEVENT",INT2NUM(SDL_SYSWMEVENT));
284
- rb_define_const(cEvent,"EVENT_RESERVEDA",INT2NUM(SDL_EVENT_RESERVEDA));
285
- rb_define_const(cEvent,"EVENT_RESERVEDB",INT2NUM(SDL_EVENT_RESERVEDB));
286
- rb_define_const(cEvent,"VIDEORESIZE",INT2NUM(SDL_VIDEORESIZE));
287
- #if SDL_VERSION_ATLEAST(1,2,0)
288
- rb_define_const(cEvent,"VIDEOEXPOSE",INT2NUM(SDL_VIDEOEXPOSE));
289
- #else
290
- rb_define_const(cEvent,"EVENT_RESERVED1",INT2NUM(SDL_EVENT_RESERVED1));
291
- #endif
292
- rb_define_const(cEvent,"EVENT_RESERVED2",INT2NUM(SDL_EVENT_RESERVED2));
293
- rb_define_const(cEvent,"EVENT_RESERVED3",INT2NUM(SDL_EVENT_RESERVED3));
294
- rb_define_const(cEvent,"EVENT_RESERVED4",INT2NUM(SDL_EVENT_RESERVED4));
295
- rb_define_const(cEvent,"EVENT_RESERVED5",INT2NUM(SDL_EVENT_RESERVED5));
296
- rb_define_const(cEvent,"EVENT_RESERVED6",INT2NUM(SDL_EVENT_RESERVED6));
297
- rb_define_const(cEvent,"EVENT_RESERVED7",INT2NUM(SDL_EVENT_RESERVED7));
298
- /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
299
- rb_define_const(cEvent,"USEREVENT",INT2NUM(SDL_USEREVENT));
300
- /* This last event is only for bounding internal arrays
301
- It is the number of bits in the event mask datatype -- Uint32
302
- */
303
- rb_define_const(cEvent,"NUMEVENTS",INT2NUM(SDL_NUMEVENTS));
304
-
305
- /* The available application states */
306
- rb_define_const(cEvent,"APPMOUSEFOCUS",UINT2NUM(SDL_APPMOUSEFOCUS));
307
- rb_define_const(cEvent,"APPINPUTFOCUS",UINT2NUM(SDL_APPINPUTFOCUS));
308
- rb_define_const(cEvent,"APPACTIVE",UINT2NUM(SDL_APPACTIVE));
309
-
310
- }
311
-
312
-
313
- void init_event()
314
- {
315
- cEvent = rb_define_class_under(mSDL,"Event",rb_cObject);
316
- rb_define_singleton_method(cEvent,"new",createEventObject,0);
312
+ int i;
317
313
 
318
- rb_define_singleton_method(cEvent,"appState",sdl_getAppState,0);
319
- rb_define_singleton_method(cEvent,"enableUNICODE",sdl_enableUNICODE,0);
320
- rb_define_singleton_method(cEvent,"disableUNICODE",sdl_disableUNICODE,0);
321
- rb_define_singleton_method(cEvent,"enableUNICODE?",sdl_is_enableUNICODE,0);
314
+ cEvent=rb_define_class_under(mSDL, "Event", rb_cObject);
315
+ rb_define_singleton_method(cEvent, "poll", Event_s_poll, 0);
316
+ rb_define_singleton_method(cEvent, "wait", Event_s_wait, 0);
317
+ rb_define_singleton_method(cEvent, "pump", Event_s_pump, 0);
318
+ rb_define_singleton_method(cEvent, "new", Event_s_new, 0);
319
+ rb_define_singleton_method(cEvent, "push", Event_s_push, 1);
320
+ rb_define_singleton_method(cEvent, "appState", Event_s_getAppState, 0);
321
+ rb_define_singleton_method(cEvent, "enableUNICODE", Event_s_enableUNICODE, 0);
322
+ rb_define_singleton_method(cEvent, "disableUNICODE", Event_s_disableUNICODE, 0);
323
+ rb_define_singleton_method(cEvent, "enableUNICODE?", Event_s_is_enableUNICODE, 0);
324
+ cActiveEvent=rb_define_class_under(cEvent, "Active", cEvent);
325
+ rb_define_attr(cActiveEvent, "gain", 1, 1);
326
+ rb_define_attr(cActiveEvent, "state", 1, 1);
322
327
 
323
- rb_define_method(cEvent,"poll",sdl_pollEvent,0);
324
- rb_define_method(cEvent,"wait",sdl_waitEvent,0);
328
+ cKeyDownEvent=rb_define_class_under(cEvent, "KeyDown", cEvent);
329
+ rb_define_attr(cKeyDownEvent, "press", 1, 1);
330
+ rb_define_attr(cKeyDownEvent, "sym", 1, 1);
331
+ rb_define_attr(cKeyDownEvent, "mod", 1, 1);
332
+ rb_define_attr(cKeyDownEvent, "unicode", 1, 1);
325
333
 
326
- rb_define_method(cEvent,"type",sdl_eventType,0);
334
+ cKeyUpEvent=rb_define_class_under(cEvent, "KeyUp", cEvent);
335
+ rb_define_attr(cKeyUpEvent, "press", 1, 1);
336
+ rb_define_attr(cKeyUpEvent, "sym", 1, 1);
337
+ rb_define_attr(cKeyUpEvent, "mod", 1, 1);
338
+ rb_define_attr(cKeyUpEvent, "unicode", 1, 1);
327
339
 
328
- rb_define_method(cEvent,"keyPress?",sdl_eventKeyPressed,0);
329
- rb_define_method(cEvent,"keySym",sdl_eventKeySym,0);
330
- rb_define_method(cEvent,"keyMod",sdl_eventKeyMod,0);
331
-
332
- rb_define_method(cEvent,"gain?",sdl_eventActiveGained,0);
333
- rb_define_method(cEvent,"appState",sdl_eventActiveState,0);
334
-
335
- rb_define_method(cEvent,"mouseX",sdl_eventMouseX,0);
336
- rb_define_method(cEvent,"mouseY",sdl_eventMouseY,0);
337
- rb_define_method(cEvent,"mouseXrel",sdl_eventMouseXrel,0);
338
- rb_define_method(cEvent,"mouseYrel",sdl_eventMouseYrel,0);
340
+ cMouseMotionEvent=rb_define_class_under(cEvent, "MouseMotion", cEvent);
341
+ rb_define_attr(cMouseMotionEvent, "state", 1, 1);
342
+ rb_define_attr(cMouseMotionEvent, "x", 1, 1);
343
+ rb_define_attr(cMouseMotionEvent, "y", 1, 1);
344
+ rb_define_attr(cMouseMotionEvent, "xrel", 1, 1);
345
+ rb_define_attr(cMouseMotionEvent, "yrel", 1, 1);
346
+
347
+ cMouseButtonDownEvent=rb_define_class_under(cEvent, "MouseButtonDown", cEvent);
348
+ rb_define_attr(cMouseButtonDownEvent, "button", 1, 1);
349
+ rb_define_attr(cMouseButtonDownEvent, "press", 1, 1);
350
+ rb_define_attr(cMouseButtonDownEvent, "x", 1, 1);
351
+ rb_define_attr(cMouseButtonDownEvent, "y", 1, 1);
339
352
 
340
- rb_define_method(cEvent,"mouseButton",sdl_eventMouseButton,0);
341
- rb_define_method(cEvent,"mousePress?",sdl_eventMousePressed,0);
353
+ cMouseButtonUpEvent=rb_define_class_under(cEvent, "MouseButtonUp", cEvent);
354
+ rb_define_attr(cMouseButtonUpEvent, "button", 1, 1);
355
+ rb_define_attr(cMouseButtonUpEvent, "press", 1, 1);
356
+ rb_define_attr(cMouseButtonUpEvent, "x", 1, 1);
357
+ rb_define_attr(cMouseButtonUpEvent, "y", 1, 1);
358
+
359
+ cJoyAxisEvent=rb_define_class_under(cEvent, "JoyAxis", cEvent);
360
+ rb_define_attr(cJoyAxisEvent, "which", 1, 1);
361
+ rb_define_attr(cJoyAxisEvent, "axis", 1, 1);
362
+ rb_define_attr(cJoyAxisEvent, "value", 1, 1);
363
+
364
+ cJoyBallEvent=rb_define_class_under(cEvent, "JoyBall", cEvent);
365
+ rb_define_attr(cJoyBallEvent, "which", 1, 1);
366
+ rb_define_attr(cJoyBallEvent, "ball", 1, 1);
367
+ rb_define_attr(cJoyBallEvent, "xrel", 1, 1);
368
+ rb_define_attr(cJoyBallEvent, "yrel", 1, 1);
369
+
370
+ cJoyHatEvent=rb_define_class_under(cEvent, "JoyHat", cEvent);
371
+ rb_define_attr(cJoyHatEvent, "which", 1, 1);
372
+ rb_define_attr(cJoyHatEvent, "hat", 1, 1);
373
+ rb_define_attr(cJoyHatEvent, "value", 1, 1);
374
+
375
+ cJoyButtonUpEvent=rb_define_class_under(cEvent, "JoyButtonUp", cEvent);
376
+ rb_define_attr(cJoyButtonUpEvent, "which", 1, 1);
377
+ rb_define_attr(cJoyButtonUpEvent, "button", 1, 1);
378
+ rb_define_attr(cJoyButtonUpEvent, "press", 1, 1);
342
379
 
343
- rb_define_method(cEvent,"info",sdl_eventInfo,0);
344
- defineConstForEvent();
380
+ cJoyButtonDownEvent=rb_define_class_under(cEvent, "JoyButtonDown", cEvent);
381
+ rb_define_attr(cJoyButtonDownEvent, "which", 1, 1);
382
+ rb_define_attr(cJoyButtonDownEvent, "button", 1, 1);
383
+ rb_define_attr(cJoyButtonDownEvent, "press", 1, 1);
345
384
 
385
+ cQuitEvent=rb_define_class_under(cEvent, "Quit", cEvent);
386
+
387
+ cSysWMEvent=rb_define_class_under(cEvent, "SysWM", cEvent);
388
+
389
+ cVideoResizeEvent=rb_define_class_under(cEvent, "VideoResize", cEvent);
390
+ rb_define_attr(cVideoResizeEvent, "w", 1, 1);
391
+ rb_define_attr(cVideoResizeEvent, "h", 1, 1);
392
+
393
+ for(i=0;i<SDL_NUMEVENTS;++i)
394
+ event_creators[i]=createNoEvent;
395
+ event_creators[SDL_ACTIVEEVENT] = createActiveEvent;
396
+ event_creators[SDL_KEYDOWN] = createKeyDownEvent;
397
+ event_creators[SDL_KEYUP] = createKeyUpEvent;
398
+ event_creators[SDL_MOUSEMOTION] = createMouseMotionEvent;
399
+ event_creators[SDL_MOUSEBUTTONDOWN] = createMouseButtonDownEvent;
400
+ event_creators[SDL_MOUSEBUTTONUP] = createMouseButtonUpEvent;
401
+ event_creators[SDL_JOYAXISMOTION] = createJoyAxisEvent;
402
+ event_creators[SDL_JOYBALLMOTION] = createJoyBallEvent;
403
+ event_creators[SDL_JOYHATMOTION] = createJoyHatEvent;
404
+ event_creators[SDL_JOYBUTTONDOWN] = createJoyButtonDownEvent;
405
+ event_creators[SDL_JOYBUTTONUP] = createJoyButtonUpEvent;
406
+ event_creators[SDL_QUIT] = createQuitEvent;
407
+ event_creators[SDL_SYSWMEVENT] = createSysWMEvent;
408
+ event_creators[SDL_VIDEORESIZE] = createVideoResizeEvent;
346
409
  }