rubygame 2.3.0-x86-mswin32-60
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/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +252 -0
- data/README +123 -0
- data/ROADMAP +109 -0
- data/Rakefile +440 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.obj +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.obj +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.obj +0 -0
- data/ext/rubygame/rubygame_image.c +252 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.obj +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.obj +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +36 -0
- data/ext/rubygame/rubygame_main.obj +0 -0
- data/ext/rubygame/rubygame_mixer.c +1024 -0
- data/ext/rubygame/rubygame_mixer.h +36 -0
- data/ext/rubygame/rubygame_mixer.obj +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_music.c +1017 -0
- data/ext/rubygame/rubygame_music.h +29 -0
- data/ext/rubygame/rubygame_music.obj +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.obj +0 -0
- data/ext/rubygame/rubygame_shared.c +272 -0
- data/ext/rubygame/rubygame_shared.h +68 -0
- data/ext/rubygame/rubygame_shared.obj +0 -0
- data/ext/rubygame/rubygame_sound.c +863 -0
- data/ext/rubygame/rubygame_sound.h +29 -0
- data/ext/rubygame/rubygame_sound.obj +0 -0
- data/ext/rubygame/rubygame_surface.c +1151 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.obj +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.obj +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.obj +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame.rb +41 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/color/models/base.rb +111 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/named_resource.rb +254 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +302 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +77 -0
- data/samples/demo_rubygame.rb +296 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- metadata +164 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
/*
|
2
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
* Copyright (C) 2004-2007 John Croisant
|
4
|
+
*
|
5
|
+
* This library is free software; you can redistribute it and/or
|
6
|
+
* modify it under the terms of the GNU Lesser General Public
|
7
|
+
* License as published by the Free Software Foundation; either
|
8
|
+
* version 2.1 of the License, or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This library is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
* Lesser General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public
|
16
|
+
* License along with this library; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
#ifndef _RUBYGAME_IMAGE_H
|
22
|
+
#define _RUBYGAME_IMAGE_H
|
23
|
+
|
24
|
+
#include "SDL_image.h"
|
25
|
+
|
26
|
+
#ifndef SDL_IMAGE_MAJOR_VERSION
|
27
|
+
#define SDL_IMAGE_MAJOR_VERSION 0
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#ifndef SDL_IMAGE_MINOR_VERSION
|
31
|
+
#define SDL_IMAGE_MINOR_VERSION 0
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifndef SDL_IMAGE_PATCHLEVEL
|
35
|
+
#define SDL_IMAGE_PATCHLEVEL 0
|
36
|
+
#endif
|
37
|
+
|
38
|
+
extern void Init_rubygame_image();
|
39
|
+
extern VALUE rbgm_image_load(VALUE, VALUE);
|
40
|
+
|
41
|
+
#endif
|
Binary file
|
Binary file
|
@@ -0,0 +1,247 @@
|
|
1
|
+
/*--
|
2
|
+
*
|
3
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
4
|
+
* Copyright (C) 2004-2007 John Croisant
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*
|
20
|
+
*++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_joystick.h"
|
25
|
+
|
26
|
+
void Rubygame_Init_Joystick();
|
27
|
+
VALUE cJoy;
|
28
|
+
|
29
|
+
VALUE rbgm_joy_numjoysticks(VALUE);
|
30
|
+
VALUE rbgm_joy_getname(VALUE, VALUE);
|
31
|
+
|
32
|
+
VALUE rbgm_joystick_new(VALUE, VALUE);
|
33
|
+
|
34
|
+
VALUE rbgm_joystick_index(VALUE);
|
35
|
+
VALUE rbgm_joystick_name(VALUE);
|
36
|
+
VALUE rbgm_joystick_numaxes(VALUE);
|
37
|
+
VALUE rbgm_joystick_numballs(VALUE);
|
38
|
+
VALUE rbgm_joystick_numhats(VALUE);
|
39
|
+
VALUE rbgm_joystick_numbuttons(VALUE);
|
40
|
+
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* num_joysticks -> Integer
|
45
|
+
*
|
46
|
+
* Returns the total number of joysticks detected on the system.
|
47
|
+
*/
|
48
|
+
VALUE rbgm_joy_numjoysticks( VALUE module )
|
49
|
+
{
|
50
|
+
return INT2FIX(SDL_NumJoysticks());
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* call-seq:
|
55
|
+
* get_name( n ) -> String
|
56
|
+
*
|
57
|
+
* Returns the name of nth joystick on the system, up to 1024
|
58
|
+
* characters long. The name is implementation-dependent.
|
59
|
+
* See also #name().
|
60
|
+
*/
|
61
|
+
VALUE rbgm_joy_getname( VALUE module, VALUE joynum )
|
62
|
+
{
|
63
|
+
return rb_str_new2(SDL_JoystickName(NUM2INT(joynum)));
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
/*
|
68
|
+
* Internal function to safely deallocate the joystick, that is,
|
69
|
+
* only if SDL Joystick module is still initialised.
|
70
|
+
*/
|
71
|
+
static void RBGM_JoystickClose(SDL_Joystick *joy)
|
72
|
+
{
|
73
|
+
if(SDL_WasInit(SDL_INIT_JOYSTICK))
|
74
|
+
{
|
75
|
+
SDL_JoystickClose(joy);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
/*
|
81
|
+
* call-seq:
|
82
|
+
* new( n ) -> Joystick
|
83
|
+
*
|
84
|
+
* Create and initialize an interface to the nth joystick on the
|
85
|
+
* system. Raises SDLError if the joystick could not be opened.
|
86
|
+
*/
|
87
|
+
VALUE rbgm_joystick_new( VALUE module, VALUE vindex )
|
88
|
+
{
|
89
|
+
VALUE self;
|
90
|
+
SDL_Joystick *joy;
|
91
|
+
int index;
|
92
|
+
|
93
|
+
index = NUM2INT(vindex);
|
94
|
+
|
95
|
+
joy = SDL_JoystickOpen(index);
|
96
|
+
if(joy == NULL)
|
97
|
+
{
|
98
|
+
rb_raise(eSDLError,"Could not open joystick %d: %s",\
|
99
|
+
index,SDL_GetError());
|
100
|
+
}
|
101
|
+
self = Data_Wrap_Struct(cJoy, 0, RBGM_JoystickClose, joy);
|
102
|
+
return self;
|
103
|
+
}
|
104
|
+
|
105
|
+
/*
|
106
|
+
* call-seq:
|
107
|
+
* index -> Integer
|
108
|
+
*
|
109
|
+
* Returns the index number of the Joystick, i.e. the identifier number of the
|
110
|
+
* joystick that this interface controls. This is the same number that was
|
111
|
+
* given to #new().
|
112
|
+
*/
|
113
|
+
VALUE rbgm_joystick_index( VALUE self )
|
114
|
+
{
|
115
|
+
SDL_Joystick *joy;
|
116
|
+
|
117
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
118
|
+
return INT2FIX(SDL_JoystickIndex(joy));
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* call-seq:
|
123
|
+
* name -> String
|
124
|
+
*
|
125
|
+
* Returns a String containing the name of the Joystick, up to 1024
|
126
|
+
* characters long. The name is implementation-dependent. See also
|
127
|
+
* #get_name().
|
128
|
+
*/
|
129
|
+
VALUE rbgm_joystick_name( VALUE self )
|
130
|
+
{
|
131
|
+
char *name;
|
132
|
+
SDL_Joystick *joy;
|
133
|
+
Uint8 index;
|
134
|
+
int n;
|
135
|
+
int size = 1024;
|
136
|
+
|
137
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
138
|
+
index = SDL_JoystickIndex(joy);
|
139
|
+
name = (char *)malloc(size);
|
140
|
+
n = snprintf(name,size,"%s",SDL_JoystickName(index));
|
141
|
+
return rb_str_new(name,n);
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
* call-seq:
|
146
|
+
* axes -> Integer
|
147
|
+
*
|
148
|
+
* Returns the number of axes (singular: axis) featured on the Joystick. Each
|
149
|
+
* control stick generally has two axes (X and Y), although there are other
|
150
|
+
* types of controls which are represented as one or more axes. See also
|
151
|
+
* #axis_state().
|
152
|
+
*/
|
153
|
+
VALUE rbgm_joystick_numaxes( VALUE self )
|
154
|
+
{
|
155
|
+
SDL_Joystick *joy;
|
156
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
157
|
+
return INT2FIX(SDL_JoystickNumAxes(joy));
|
158
|
+
}
|
159
|
+
|
160
|
+
/*
|
161
|
+
* call-seq:
|
162
|
+
* balls -> Integer
|
163
|
+
*
|
164
|
+
* Returns the number of trackballs featured on the Joystick. A trackball is
|
165
|
+
* usually a small sphere which can be rotated in-place in any direction,
|
166
|
+
* registering relative movement along two axes. See alse #ball_state().
|
167
|
+
*/
|
168
|
+
VALUE rbgm_joystick_numballs( VALUE self )
|
169
|
+
{
|
170
|
+
SDL_Joystick *joy;
|
171
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
172
|
+
return INT2FIX(SDL_JoystickNumBalls(joy));
|
173
|
+
}
|
174
|
+
|
175
|
+
/*
|
176
|
+
* call-seq:
|
177
|
+
* hats -> Integer
|
178
|
+
*
|
179
|
+
* Returns the number of hats featured on the Joystick. A hat is a switch
|
180
|
+
* which can be pushed in one of several directions, or centered. See also
|
181
|
+
* #hat_state().
|
182
|
+
*/
|
183
|
+
VALUE rbgm_joystick_numhats( VALUE self )
|
184
|
+
{
|
185
|
+
SDL_Joystick *joy;
|
186
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
187
|
+
return INT2FIX(SDL_JoystickNumHats(joy));
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* call-seq:
|
192
|
+
* buttons -> Integer
|
193
|
+
*
|
194
|
+
* Returns the number of buttons featured on the Joystick. A button can
|
195
|
+
* be in one of two states: neutral, or pushed. See also #button_state()
|
196
|
+
*/
|
197
|
+
VALUE rbgm_joystick_numbuttons( VALUE self )
|
198
|
+
{
|
199
|
+
SDL_Joystick *joy;
|
200
|
+
Data_Get_Struct(self,SDL_Joystick,joy);
|
201
|
+
SDL_JoystickUpdate();
|
202
|
+
return INT2FIX(SDL_JoystickNumButtons(joy));
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
/* Document-class: Rubygame::Joystick
|
207
|
+
*
|
208
|
+
* The Joystick class interfaces with joysticks, gamepads, and other
|
209
|
+
* similar hardware devices, commonly used to play games. Each joystick can
|
210
|
+
* offer 0 or more #axes, #balls, #hats, and/or #buttons.
|
211
|
+
*
|
212
|
+
* After a Joystick object is successfully created, events for that
|
213
|
+
* Joystick will begin appearing on the Queue, reporting any state change
|
214
|
+
* that occurs. Some examples of state changes are a button being pressed
|
215
|
+
* or released, or a control stick being moved (resulting in one or more axes
|
216
|
+
* being changed).
|
217
|
+
*
|
218
|
+
* The full list of Joystick-related events is as follows:
|
219
|
+
* - JoyAxisEvent
|
220
|
+
* - JoyBallEvent
|
221
|
+
* - JoyHatEvent
|
222
|
+
* - JoyDownEvent
|
223
|
+
* - JoyUpEvent
|
224
|
+
*
|
225
|
+
* In future versions of Rubygame, it will be possible to directly query
|
226
|
+
* the state each joystick. However, it is recommended that you use the
|
227
|
+
* event system for most cases, so you might as well get used to it!
|
228
|
+
*
|
229
|
+
*/
|
230
|
+
void Rubygame_Init_Joystick()
|
231
|
+
{
|
232
|
+
#if 0
|
233
|
+
mRubygame = rb_define_module("Rubygame");
|
234
|
+
#endif
|
235
|
+
|
236
|
+
cJoy = rb_define_class_under(mRubygame,"Joystick",rb_cObject);
|
237
|
+
rb_define_singleton_method(cJoy,"num_joysticks",rbgm_joy_numjoysticks,0);
|
238
|
+
rb_define_singleton_method(cJoy,"get_name",rbgm_joy_getname,1);
|
239
|
+
|
240
|
+
rb_define_singleton_method(cJoy,"new",rbgm_joystick_new,1);
|
241
|
+
rb_define_method(cJoy,"index",rbgm_joystick_index,0);
|
242
|
+
rb_define_method(cJoy,"name",rbgm_joystick_name,0);
|
243
|
+
rb_define_method(cJoy,"axes",rbgm_joystick_numaxes,0);
|
244
|
+
rb_define_method(cJoy,"balls",rbgm_joystick_numballs,0);
|
245
|
+
rb_define_method(cJoy,"hats",rbgm_joystick_numhats,0);
|
246
|
+
rb_define_method(cJoy,"buttons",rbgm_joystick_numbuttons,0);
|
247
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/*
|
2
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
3
|
+
* Copyright (C) 2004-2007 John Croisant
|
4
|
+
*
|
5
|
+
* This library is free software; you can redistribute it and/or
|
6
|
+
* modify it under the terms of the GNU Lesser General Public
|
7
|
+
* License as published by the Free Software Foundation; either
|
8
|
+
* version 2.1 of the License, or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This library is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
* Lesser General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public
|
16
|
+
* License along with this library; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
|
21
|
+
|
22
|
+
#ifndef _RUBYGAME_JOYSTICK_H
|
23
|
+
#define _RUBYGAME_JOYSTICK_H
|
24
|
+
|
25
|
+
extern void Rubygame_Init_Joystick();
|
26
|
+
|
27
|
+
extern VALUE cJoy;
|
28
|
+
|
29
|
+
extern VALUE rbgm_joy_numjoysticks(VALUE);
|
30
|
+
extern VALUE rbgm_joy_getname(VALUE, VALUE);
|
31
|
+
|
32
|
+
extern VALUE rbgm_joystick_new(VALUE, VALUE);
|
33
|
+
|
34
|
+
extern VALUE rbgm_joystick_index(VALUE);
|
35
|
+
extern VALUE rbgm_joystick_name(VALUE);
|
36
|
+
extern VALUE rbgm_joystick_numaxes(VALUE);
|
37
|
+
extern VALUE rbgm_joystick_numballs(VALUE);
|
38
|
+
extern VALUE rbgm_joystick_numhats(VALUE);
|
39
|
+
extern VALUE rbgm_joystick_numbuttons(VALUE);
|
40
|
+
|
41
|
+
#endif
|
Binary file
|
@@ -0,0 +1,155 @@
|
|
1
|
+
/*
|
2
|
+
*--
|
3
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
4
|
+
* Copyright (C) 2004-2007 John Croisant
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*++
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "rubygame_shared.h"
|
23
|
+
#include "rubygame_main.h"
|
24
|
+
#include "rubygame_event.h"
|
25
|
+
#include "rubygame_gl.h"
|
26
|
+
#include "rubygame_joystick.h"
|
27
|
+
#include "rubygame_screen.h"
|
28
|
+
#include "rubygame_surface.h"
|
29
|
+
#include "rubygame_time.h"
|
30
|
+
|
31
|
+
VALUE rbgm_init(VALUE);
|
32
|
+
VALUE rbgm_quit(VALUE);
|
33
|
+
void Define_Rubygame_Constants();
|
34
|
+
|
35
|
+
/*
|
36
|
+
* call-seq:
|
37
|
+
* key_name(sym) -> string
|
38
|
+
*
|
39
|
+
* Given the sym of a key, returns a printable representation. This
|
40
|
+
* differs from key2str in that this will return a printable string
|
41
|
+
* for any key, even non-printable keys such as the arrow keys.
|
42
|
+
*
|
43
|
+
* This method may raise SDLError if the SDL video subsystem could
|
44
|
+
* not be initialized for some reason.
|
45
|
+
*
|
46
|
+
* Example:
|
47
|
+
* Rubygame.key_name( Rubygame::K_A ) # => "a"
|
48
|
+
* Rubygame.key_name( Rubygame::K_RETURN ) # => "return"
|
49
|
+
* Rubygame.key_name( Rubygame::K_LEFT ) # => "left"
|
50
|
+
*/
|
51
|
+
VALUE rbgm_keyname(VALUE self, VALUE sym)
|
52
|
+
{
|
53
|
+
/* SDL_GetKeyName only works when video system has been initialized. */
|
54
|
+
if( init_video_system() == 0 )
|
55
|
+
{
|
56
|
+
SDLKey key = NUM2INT(sym);
|
57
|
+
char *result = SDL_GetKeyName(key);
|
58
|
+
return rb_str_new2(result);
|
59
|
+
}
|
60
|
+
else
|
61
|
+
{
|
62
|
+
rb_raise(eSDLError,"Could not initialize SDL video subsystem.");
|
63
|
+
return Qnil;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
/*
|
69
|
+
* call-seq:
|
70
|
+
* init -> nil
|
71
|
+
*
|
72
|
+
* Initialize Rubygame. This should be called soon after you +require+
|
73
|
+
* Rubygame, so that everything will work properly.
|
74
|
+
*/
|
75
|
+
VALUE rbgm_init(VALUE module)
|
76
|
+
{
|
77
|
+
if(SDL_Init(SDL_INIT_EVERYTHING)==0)
|
78
|
+
{
|
79
|
+
return Qnil;
|
80
|
+
}
|
81
|
+
else
|
82
|
+
{
|
83
|
+
rb_raise(eSDLError,"Could not initialize SDL.");
|
84
|
+
return Qnil; /* should never get here */
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* call-seq:
|
90
|
+
* quit -> nil
|
91
|
+
*
|
92
|
+
* Quit Rubygame. This should be used before your program terminates,
|
93
|
+
* especially if you have been using a fullscreen Screen! (Otherwise,
|
94
|
+
* the desktop resolution might not revert to its previous setting on
|
95
|
+
* some platforms, and your users will be frustrated and confused!)
|
96
|
+
*/
|
97
|
+
VALUE rbgm_quit(VALUE module)
|
98
|
+
{
|
99
|
+
SDL_Quit();
|
100
|
+
return Qnil;
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
void Init_rubygame_core()
|
105
|
+
{
|
106
|
+
Init_rubygame_shared();
|
107
|
+
|
108
|
+
mRubygame = rb_define_module("Rubygame");
|
109
|
+
|
110
|
+
rb_define_module_function(mRubygame,"init",rbgm_init,0);
|
111
|
+
rb_define_module_function(mRubygame,"quit",rbgm_quit,0);
|
112
|
+
rb_define_singleton_method(mRubygame,"key_name",rbgm_keyname, 1);
|
113
|
+
cRect = rb_define_class_under(mRubygame,"Rect",rb_cArray);
|
114
|
+
|
115
|
+
rb_hash_aset(rb_ivar_get(mRubygame,rb_intern("VERSIONS")),
|
116
|
+
ID2SYM(rb_intern("rubygame")),
|
117
|
+
rb_ary_new3(3,
|
118
|
+
INT2NUM(RUBYGAME_MAJOR_VERSION),
|
119
|
+
INT2NUM(RUBYGAME_MINOR_VERSION),
|
120
|
+
INT2NUM(RUBYGAME_PATCHLEVEL)));
|
121
|
+
rb_hash_aset(rb_ivar_get(mRubygame,rb_intern("VERSIONS")),
|
122
|
+
ID2SYM(rb_intern("sdl")),
|
123
|
+
rb_ary_new3(3,
|
124
|
+
INT2NUM(SDL_MAJOR_VERSION),
|
125
|
+
INT2NUM(SDL_MINOR_VERSION),
|
126
|
+
INT2NUM(SDL_PATCHLEVEL)));
|
127
|
+
|
128
|
+
Rubygame_Init_Time();
|
129
|
+
Rubygame_Init_Surface();
|
130
|
+
Rubygame_Init_Screen();
|
131
|
+
Rubygame_Init_Event();
|
132
|
+
Rubygame_Init_Joystick();
|
133
|
+
Rubygame_Init_GL();
|
134
|
+
|
135
|
+
/* Flags for subsystem initialization */
|
136
|
+
rb_define_const(mRubygame,"INIT_TIMER",INT2NUM(SDL_INIT_TIMER));
|
137
|
+
rb_define_const(mRubygame,"INIT_AUDIO",INT2NUM(SDL_INIT_AUDIO));
|
138
|
+
rb_define_const(mRubygame,"INIT_VIDEO",INT2NUM(SDL_INIT_VIDEO));
|
139
|
+
rb_define_const(mRubygame,"INIT_CDROM",INT2NUM(SDL_INIT_CDROM));
|
140
|
+
rb_define_const(mRubygame,"INIT_JOYSTICK",INT2NUM(SDL_INIT_JOYSTICK));
|
141
|
+
rb_define_const(mRubygame,"INIT_NOPARACHUTE",INT2NUM(SDL_INIT_NOPARACHUTE));
|
142
|
+
rb_define_const(mRubygame,"INIT_EVENTTHREAD",UINT2NUM(SDL_INIT_EVENTTHREAD));
|
143
|
+
rb_define_const(mRubygame,"INIT_EVERYTHING",UINT2NUM(SDL_INIT_EVERYTHING));
|
144
|
+
|
145
|
+
|
146
|
+
/* Define fully opaque and full transparent (0 and 255) */
|
147
|
+
rb_define_const(mRubygame,"ALPHA_OPAQUE",UINT2NUM(SDL_ALPHA_OPAQUE));
|
148
|
+
rb_define_const(mRubygame,"ALPHA_TRANSPARENT",
|
149
|
+
UINT2NUM(SDL_ALPHA_TRANSPARENT));
|
150
|
+
|
151
|
+
|
152
|
+
/* Flags for palettes (?) */
|
153
|
+
rb_define_const(mRubygame,"LOGPAL",UINT2NUM(SDL_LOGPAL));
|
154
|
+
rb_define_const(mRubygame,"PHYSPAL",UINT2NUM(SDL_PHYSPAL));
|
155
|
+
}
|