rubysdl 1.3.1 → 2.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.
- data/MANIFEST +22 -2
- data/NEWS.en +80 -0
- data/NEWS.ja +83 -0
- data/README.en +2 -1
- data/README.ja +2 -2
- data/doc-en/Makefile +18 -0
- data/doc-en/cdrom.rsd +417 -0
- data/doc-en/collision.rsd +174 -0
- data/doc-en/event.rsd +1476 -0
- data/doc-en/font.rsd +811 -0
- data/doc-en/general.rsd +43 -0
- data/doc-en/init.rsd +168 -0
- data/doc-en/joystick.rsd +401 -0
- data/doc-en/mixer.rsd +869 -0
- data/doc-en/mpeg.rsd +585 -0
- data/doc-en/opengl.rsd +155 -0
- data/doc-en/sdlskk.rsd +472 -0
- data/doc-en/time.rsd +46 -0
- data/doc-en/video.rsd +2806 -0
- data/doc-en/wm.rsd +112 -0
- data/doc/Makefile +1 -1
- data/doc/cdrom.rsd +3 -3
- data/doc/event.rsd +178 -179
- data/doc/general.rsd +10 -0
- data/doc/init.rsd +2 -2
- data/doc/joystick.rsd +29 -5
- data/doc/mixer.rsd +20 -0
- data/doc/rsd.rb +42 -9
- data/doc/sdlskk.rsd +7 -7
- data/doc/video.rsd +461 -168
- data/doc/wm.rsd +2 -2
- data/extconf.rb +1 -8
- data/lib/rubysdl_aliases.rb +52 -190
- data/lib/rubysdl_compatible_ver1.rb +243 -0
- data/lib/sdl.rb +58 -92
- data/rubysdl.h +59 -68
- data/rubysdl_cdrom.c +125 -102
- data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
- data/rubysdl_event.c +318 -255
- data/rubysdl_event_key.c +299 -287
- data/rubysdl_image.c +37 -13
- data/rubysdl_joystick.c +180 -67
- data/rubysdl_kanji.c +61 -75
- data/rubysdl_main.c +65 -138
- data/rubysdl_mixer.c +339 -214
- data/rubysdl_mouse.c +50 -43
- data/rubysdl_opengl.c +31 -28
- data/rubysdl_pixel.c +17 -28
- data/rubysdl_ref.en.html +5658 -0
- data/rubysdl_ref.en.rd +6337 -0
- data/rubysdl_ref.html +2253 -1964
- data/rubysdl_ref.rd +823 -469
- data/rubysdl_rwops.c +9 -6
- data/rubysdl_sdlskk.c +137 -165
- data/rubysdl_sge_video.c +355 -469
- data/rubysdl_smpeg.c +189 -190
- data/rubysdl_time.c +1 -1
- data/rubysdl_ttf.c +147 -215
- data/rubysdl_video.c +486 -405
- data/rubysdl_wm.c +30 -30
- data/sample/aadraw.rb +9 -9
- data/sample/alpha.rb +12 -13
- data/sample/alphadraw.rb +10 -10
- data/sample/bfont.rb +4 -4
- data/sample/cdrom.rb +11 -4
- data/sample/collision.rb +20 -20
- data/sample/cursor.rb +5 -5
- data/sample/ellipses.rb +20 -16
- data/sample/event2.rb +11 -9
- data/sample/font.rb +4 -4
- data/sample/fpstimer.rb +3 -3
- data/sample/icon.bmp.gz +0 -0
- data/sample/icon.png +0 -0
- data/sample/joy2.rb +14 -14
- data/sample/kanji.rb +7 -7
- data/sample/load_from_io.rb +44 -0
- data/sample/movesp.rb +13 -12
- data/sample/playmod.rb +2 -3
- data/sample/plaympeg.rb +8 -8
- data/sample/playwave.rb +5 -6
- data/sample/sdlskk.rb +11 -11
- data/sample/sgetest.rb +14 -12
- data/sample/stetris.rb +12 -13
- data/sample/testgl.rb +13 -14
- data/sample/testsprite.rb +12 -11
- data/sample/transformblit.rb +23 -22
- metadata +62 -35
- 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
|
-
|
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
|
-
|
25
|
-
rb_raise(eSDLError,"this event is not %s event",msg) ;
|
44
|
+
return Qnil;
|
26
45
|
}
|
27
|
-
|
28
|
-
static VALUE
|
46
|
+
|
47
|
+
static VALUE createActiveEvent(SDL_Event *event)
|
29
48
|
{
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
55
|
+
static VALUE createKeyEvent(VALUE obj, SDL_Event *event)
|
36
56
|
{
|
37
|
-
|
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
|
-
|
40
|
-
|
64
|
+
static VALUE createKeyDownEvent(SDL_Event *event)
|
65
|
+
{
|
66
|
+
VALUE obj = rb_obj_alloc(cKeyDownEvent);
|
67
|
+
return createKeyEvent(obj, event);
|
41
68
|
}
|
42
|
-
|
69
|
+
|
70
|
+
static VALUE createKeyUpEvent(SDL_Event *event)
|
43
71
|
{
|
44
|
-
|
72
|
+
VALUE obj = rb_obj_alloc(cKeyUpEvent);
|
73
|
+
return createKeyEvent(obj, event);
|
74
|
+
}
|
45
75
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
87
|
+
static VALUE createMouseButtonEvent(VALUE obj, SDL_Event *event)
|
53
88
|
{
|
54
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
61
|
-
static VALUE sdl_eventKeyPressed(VALUE obj)
|
102
|
+
static VALUE createMouseButtonUpEvent(SDL_Event *event)
|
62
103
|
{
|
63
|
-
|
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
|
-
|
107
|
+
|
108
|
+
static VALUE createJoyAxisEvent(SDL_Event *event)
|
73
109
|
{
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
return
|
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
|
-
|
116
|
+
|
117
|
+
static VALUE createJoyBallEvent(SDL_Event *event)
|
81
118
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
90
|
-
static VALUE sdl_eventActiveGained(VALUE obj)
|
127
|
+
static VALUE createJoyHatEvent(SDL_Event *event)
|
91
128
|
{
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return
|
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
|
-
|
135
|
+
|
136
|
+
static VALUE createJoyButtonEvent(VALUE obj, SDL_Event *event)
|
99
137
|
{
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
108
|
-
static VALUE sdl_eventMouseX(VALUE obj)
|
149
|
+
static VALUE createJoyButtonDownEvent(SDL_Event *event)
|
109
150
|
{
|
110
|
-
|
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
|
-
|
154
|
+
|
155
|
+
static VALUE createQuitEvent(SDL_Event *event)
|
125
156
|
{
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
166
|
+
|
167
|
+
static VALUE createVideoResizeEvent(SDL_Event *event)
|
141
168
|
{
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
174
|
+
|
175
|
+
/* class method */
|
176
|
+
static VALUE Event_s_poll(VALUE class)
|
149
177
|
{
|
150
|
-
SDL_Event
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
158
|
-
static VALUE sdl_eventMouseButton(VALUE obj)
|
195
|
+
static VALUE Event_s_pump(VALUE class)
|
159
196
|
{
|
160
|
-
|
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
|
-
|
200
|
+
|
201
|
+
static VALUE Event_s_new(VALUE class)
|
168
202
|
{
|
169
|
-
|
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
|
206
|
+
static VALUE Event_s_push(VALUE class, VALUE event)
|
178
207
|
{
|
179
|
-
SDL_Event
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
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
|
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
|
305
|
+
static VALUE Event_s_is_enableUNICODE(VALUE class)
|
264
306
|
{
|
265
|
-
return
|
307
|
+
return INT2BOOL(SDL_EnableUNICODE(-1));
|
266
308
|
}
|
267
309
|
|
268
|
-
|
310
|
+
void rubysdl_init_Event(VALUE mSDL)
|
269
311
|
{
|
270
|
-
|
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
|
-
|
319
|
-
rb_define_singleton_method(cEvent,"
|
320
|
-
rb_define_singleton_method(cEvent,"
|
321
|
-
rb_define_singleton_method(cEvent,"
|
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
|
-
|
324
|
-
|
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
|
-
|
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
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
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
|
-
|
341
|
-
|
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
|
-
|
344
|
-
|
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
|
}
|