rubygame 2.2.0-i586-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +201 -0
- data/README +139 -0
- data/ROADMAP +43 -0
- data/Rakefile +409 -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/MANIFEST +25 -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.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +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.o +0 -0
- data/ext/rubygame/rubygame_image.c +108 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +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.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +33 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +764 -0
- data/ext/rubygame/rubygame_mixer.h +62 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +209 -0
- data/ext/rubygame/rubygame_shared.h +60 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1147 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame/MANIFEST +12 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color/models/base.rb +106 -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/color.rb +79 -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/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/lib/rubygame.rb +41 -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 +313 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +75 -0
- data/samples/demo_rubygame.rb +284 -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 +152 -0
@@ -0,0 +1,62 @@
|
|
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_MIXER_H
|
22
|
+
#define _RUBYGAME_MIXER_H
|
23
|
+
|
24
|
+
#include "SDL_audio.h"
|
25
|
+
#include "SDL_mixer.h"
|
26
|
+
|
27
|
+
extern void Init_rubygame_mixer();
|
28
|
+
extern VALUE mMixer;
|
29
|
+
|
30
|
+
extern VALUE rbgm_mixer_openaudio(int, VALUE*, VALUE);
|
31
|
+
extern VALUE rbgm_mixer_closeaudio(VALUE);
|
32
|
+
extern VALUE rbgm_mixer_getmixchans();
|
33
|
+
extern VALUE rbgm_mixer_setmixchans(VALUE, VALUE);
|
34
|
+
extern VALUE rbgm_mixer_getdrivername(VALUE);
|
35
|
+
|
36
|
+
extern VALUE cSample;
|
37
|
+
extern VALUE rbgm_sample_new(VALUE, VALUE);
|
38
|
+
extern VALUE rbgm_mixchan_play( VALUE, VALUE, VALUE, VALUE );
|
39
|
+
extern VALUE rbgm_mixchan_stop( VALUE, VALUE );
|
40
|
+
extern VALUE rbgm_mixchan_pause( VALUE, VALUE );
|
41
|
+
extern VALUE rbgm_mixchan_resume( VALUE, VALUE );
|
42
|
+
|
43
|
+
extern VALUE cMusic;
|
44
|
+
extern VALUE rbgm_mixmusic_setcommand(VALUE, VALUE);
|
45
|
+
extern VALUE rbgm_mixmusic_new(VALUE, VALUE);
|
46
|
+
|
47
|
+
extern VALUE rbgm_mixmusic_play(int, VALUE*, VALUE);
|
48
|
+
extern VALUE rbgm_mixmusic_stop(VALUE);
|
49
|
+
extern VALUE rbgm_mixmusic_resume(VALUE);
|
50
|
+
extern VALUE rbgm_mixmusic_pause(VALUE);
|
51
|
+
extern VALUE rbgm_mixmusic_rewind(VALUE);
|
52
|
+
extern VALUE rbgm_mixmusic_jump(VALUE, VALUE);
|
53
|
+
extern VALUE rbgm_mixmusic_paused(VALUE);
|
54
|
+
extern VALUE rbgm_mixmusic_playing(VALUE);
|
55
|
+
|
56
|
+
extern VALUE rbgm_mixmusic_getvolume(VALUE);
|
57
|
+
extern VALUE rbgm_mixmusic_setvolume(VALUE, VALUE);
|
58
|
+
extern VALUE rbgm_mixmusic_fadein(int, VALUE*, VALUE);
|
59
|
+
extern VALUE rbgm_mixmusic_fadeout(VALUE, VALUE);
|
60
|
+
extern VALUE rbgm_mixmusic_fading(int, VALUE*, VALUE);
|
61
|
+
|
62
|
+
#endif
|
Binary file
|
Binary file
|
@@ -0,0 +1,448 @@
|
|
1
|
+
/*
|
2
|
+
* Screen -- Rubygame-bound SDL display window
|
3
|
+
*
|
4
|
+
* --
|
5
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
6
|
+
* Copyright (C) 2004-2007 John Croisant
|
7
|
+
*
|
8
|
+
* This library is free software; you can redistribute it and/or
|
9
|
+
* modify it under the terms of the GNU Lesser General Public
|
10
|
+
* License as published by the Free Software Foundation; either
|
11
|
+
* version 2.1 of the License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* This library is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
* Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
19
|
+
* License along with this library; if not, write to the Free Software
|
20
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
* ++
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include "rubygame_shared.h"
|
25
|
+
#include "rubygame_screen.h"
|
26
|
+
#include "rubygame_surface.h"
|
27
|
+
|
28
|
+
void Rubygame_Init_Screen();
|
29
|
+
|
30
|
+
VALUE cScreen;
|
31
|
+
|
32
|
+
VALUE rbgm_screen_setmode(int, VALUE*, VALUE);
|
33
|
+
VALUE rbgm_screen_getsurface(VALUE);
|
34
|
+
|
35
|
+
VALUE rbgm_screen_getcaption(VALUE);
|
36
|
+
VALUE rbgm_screen_setcaption(VALUE, VALUE);
|
37
|
+
|
38
|
+
VALUE rbgm_screen_seticon(VALUE, VALUE);
|
39
|
+
|
40
|
+
VALUE rbgm_screen_update(int, VALUE*, VALUE);
|
41
|
+
VALUE rbgm_screen_updaterects(VALUE, VALUE);
|
42
|
+
VALUE rbgm_screen_flip(VALUE);
|
43
|
+
|
44
|
+
VALUE rbgm_screen_getshowcursor(VALUE);
|
45
|
+
VALUE rbgm_screen_setshowcursor(VALUE, VALUE);
|
46
|
+
|
47
|
+
|
48
|
+
/* call-seq:
|
49
|
+
* new(size, depth=0, flags=[SWSURFACE]) -> Screen
|
50
|
+
* (aliases: set_mode, instance)
|
51
|
+
*
|
52
|
+
* Create a new Rubygame window if there is none, or modify the existing one.
|
53
|
+
* You cannot create more than one Screen; the existing one will be replaced.
|
54
|
+
* (This is a limitation of SDL.)
|
55
|
+
* Returns the resulting Screen.
|
56
|
+
*
|
57
|
+
* This method takes these arguments:
|
58
|
+
* size:: requested window size (in pixels), in the form [width,height]
|
59
|
+
* depth:: requested color depth (in bits per pixel). If 0 (default), the
|
60
|
+
* current system color depth.
|
61
|
+
* flags:: an Array of zero or more of the following flags (located under the
|
62
|
+
* Rubygame module).
|
63
|
+
*
|
64
|
+
* SWSURFACE:: Create the video surface in system memory.
|
65
|
+
* HWSURFACE:: Create the video surface in video memory.
|
66
|
+
* ASYNCBLIT:: Enables the use of asynchronous updates of the
|
67
|
+
* display surface. This will usually slow down
|
68
|
+
* blitting on single CPU machines, but may provide a
|
69
|
+
* speed increase on SMP systems.
|
70
|
+
* ANYFORMAT:: Normally, if a video surface of the requested
|
71
|
+
* bits-per-pixel (bpp) is not available, Rubygame
|
72
|
+
* will emulate one with a shadow surface. Passing
|
73
|
+
* +ANYFORMAT+ prevents this and causes Rubygame to
|
74
|
+
* use the video surface regardless of its depth.
|
75
|
+
* DOUBLEBUF:: Enable hardware double buffering; only valid with
|
76
|
+
* +HWSURFACE+. Calling #flip will flip the
|
77
|
+
* buffers and update the screen. All drawing will
|
78
|
+
* take place on the surface that is not displayed at
|
79
|
+
* the moment. If double buffering could not be
|
80
|
+
* enabled then #flip will just update the
|
81
|
+
* entire screen.
|
82
|
+
* FULLSCREEN:: Rubygame will attempt to use a fullscreen mode. If
|
83
|
+
* a hardware resolution change is not possible (for
|
84
|
+
* whatever reason), the next higher resolution will
|
85
|
+
* be used and the display window centered on a black
|
86
|
+
* background.
|
87
|
+
* OPENGL:: Create an OpenGL rendering context. You must set
|
88
|
+
* proper OpenGL video attributes with GL#set_attrib
|
89
|
+
* before calling this method with this flag. You can
|
90
|
+
* then use separate opengl libraries (for example rbogl)
|
91
|
+
* to do all OpenGL-related functions.
|
92
|
+
* Please note that you can't blit or draw regular SDL
|
93
|
+
* Surfaces onto an OpenGL-mode screen; you must use
|
94
|
+
* OpenGL functions.
|
95
|
+
* RESIZABLE:: Create a resizable window. When the window is
|
96
|
+
* resized by the user, a ResizeEvent is
|
97
|
+
* generated and #set_mode can be called again
|
98
|
+
* with the new size.
|
99
|
+
* NOFRAME:: If possible, create a window with no title bar or
|
100
|
+
* frame decoration.
|
101
|
+
* Fullscreen modes automatically have this flag set.
|
102
|
+
*/
|
103
|
+
VALUE rbgm_screen_setmode(int argc, VALUE *argv, VALUE module)
|
104
|
+
{
|
105
|
+
SDL_Surface *screen;
|
106
|
+
int w, h, depth;
|
107
|
+
Uint32 flags;
|
108
|
+
VALUE vsize, vdepth, vflags;
|
109
|
+
|
110
|
+
rb_scan_args(argc, argv, "12", &vsize, &vdepth, &vflags);
|
111
|
+
|
112
|
+
vsize = convert_to_array(vsize);
|
113
|
+
w = NUM2INT(rb_ary_entry(vsize,0));
|
114
|
+
h = NUM2INT(rb_ary_entry(vsize,1));
|
115
|
+
|
116
|
+
depth = 0;
|
117
|
+
if( RTEST(vdepth) )
|
118
|
+
{
|
119
|
+
depth = NUM2INT(vdepth);
|
120
|
+
}
|
121
|
+
|
122
|
+
flags = collapse_flags(vflags); /* in rubygame_shared */
|
123
|
+
|
124
|
+
screen = SDL_SetVideoMode( w,h,depth,flags );
|
125
|
+
|
126
|
+
if( screen==NULL )
|
127
|
+
{
|
128
|
+
rb_raise(eSDLError,"Couldn't set [%d x %d] %d bpp video mode: %s",
|
129
|
+
w, h, depth, SDL_GetError());
|
130
|
+
}
|
131
|
+
//format = screen->format;
|
132
|
+
//printf("New screen will be: %dx%d, %d bpp. Masks: %d, %d, %d, %d\n",w,h,depth,format->Rmask,format->Gmask,format->Bmask,format->Amask);
|
133
|
+
return Data_Wrap_Struct( cScreen,0,0,screen );
|
134
|
+
}
|
135
|
+
|
136
|
+
/* call-seq:
|
137
|
+
* get_surface
|
138
|
+
*
|
139
|
+
* Returns the current display window, or raises SDLError if it
|
140
|
+
* fails to get it (for example, if it doesn't exist yet).
|
141
|
+
*/
|
142
|
+
VALUE rbgm_screen_getsurface(VALUE module)
|
143
|
+
{
|
144
|
+
SDL_Surface *surface;
|
145
|
+
surface = SDL_GetVideoSurface();
|
146
|
+
if(surface==NULL)
|
147
|
+
{
|
148
|
+
rb_raise(eSDLError,"Couldn't get video surface: %s",SDL_GetError());
|
149
|
+
}
|
150
|
+
return Data_Wrap_Struct( cScreen,0,0,surface );
|
151
|
+
}
|
152
|
+
|
153
|
+
/* Screen methods: */
|
154
|
+
|
155
|
+
/* call-seq:
|
156
|
+
* title -> String
|
157
|
+
*
|
158
|
+
* Returns the current window title for the Screen.
|
159
|
+
* The default is an empty string.
|
160
|
+
*/
|
161
|
+
VALUE rbgm_screen_getcaption(VALUE self)
|
162
|
+
{
|
163
|
+
char *title,*icon;
|
164
|
+
|
165
|
+
SDL_WM_GetCaption( &title,&icon );
|
166
|
+
if (title == NULL)
|
167
|
+
title = "\0";
|
168
|
+
/* We don't really care about icon. */
|
169
|
+
return rb_str_new2(title);
|
170
|
+
}
|
171
|
+
|
172
|
+
/* call-seq:
|
173
|
+
* title = title
|
174
|
+
*
|
175
|
+
* Sets the window title for the Screen.
|
176
|
+
*
|
177
|
+
* title:: a String, (usually) displayed at the top of the Rubygame
|
178
|
+
* window (when not in fullscreen mode). If omitted or +nil+,
|
179
|
+
* +title+ will be an empty string.
|
180
|
+
* How this string is displayed (if at all) is system-dependent.
|
181
|
+
*/
|
182
|
+
VALUE rbgm_screen_setcaption(VALUE self, VALUE title)
|
183
|
+
{
|
184
|
+
char *title_str;
|
185
|
+
title_str = ""; /* default to blank */
|
186
|
+
|
187
|
+
if( RTEST(title) )
|
188
|
+
{
|
189
|
+
title_str = StringValuePtr(title);
|
190
|
+
}
|
191
|
+
SDL_WM_SetCaption(title_str,title_str);
|
192
|
+
return self;
|
193
|
+
}
|
194
|
+
|
195
|
+
/* call-seq:
|
196
|
+
* icon = icon
|
197
|
+
*
|
198
|
+
* Sets the window icon for the Screen.
|
199
|
+
*
|
200
|
+
* icon:: a Rubygame::Surface to be displayed at the top of the Rubygame
|
201
|
+
* window (when not in fullscreen mode), and in other OS-specific
|
202
|
+
* areas (like the taskbar entry). If omitted or +nil+, no icon
|
203
|
+
* will be shown at all.
|
204
|
+
*
|
205
|
+
* NOTE: The SDL docs state that icons on Win32 systems must be 32x32 pixels.
|
206
|
+
* That may or may not be true anymore, but you might want to consider it
|
207
|
+
* when creating games to run on Windows.
|
208
|
+
*
|
209
|
+
*/
|
210
|
+
VALUE rbgm_screen_seticon(VALUE self, VALUE data)
|
211
|
+
{
|
212
|
+
SDL_Surface *icon;
|
213
|
+
|
214
|
+
Data_Get_Struct(data, SDL_Surface, icon);
|
215
|
+
SDL_WM_SetIcon(icon, NULL);
|
216
|
+
|
217
|
+
return self;
|
218
|
+
}
|
219
|
+
|
220
|
+
/* call-seq:
|
221
|
+
* update()
|
222
|
+
* update(rect)
|
223
|
+
* update(x,y,w,h)
|
224
|
+
*
|
225
|
+
* Updates (refreshes) all or part of the Rubygame window, revealing to the
|
226
|
+
* user any changes that have been made since the last update. If you're using
|
227
|
+
* a double-buffered display (see Display.set_mode), you should use
|
228
|
+
* Screen#flip instead.
|
229
|
+
*
|
230
|
+
* This method takes these arguments:
|
231
|
+
* rect:: a Rubygame::Rect representing the area of the screen to update.
|
232
|
+
* Can also be an length-4 Array, or given as 4 separate arguments.
|
233
|
+
* If omitted or nil, the entire screen is updated.
|
234
|
+
*/
|
235
|
+
VALUE rbgm_screen_update(int argc, VALUE *argv, VALUE self)
|
236
|
+
{
|
237
|
+
int x,y,w,h;
|
238
|
+
SDL_Surface *screen;
|
239
|
+
Data_Get_Struct(self,SDL_Surface,screen);
|
240
|
+
VALUE vx, vy, vw, vh;
|
241
|
+
|
242
|
+
rb_scan_args(argc, argv, "04", &vx, &vy, &vw, &vh);
|
243
|
+
|
244
|
+
x = y = w = h = 0;
|
245
|
+
|
246
|
+
if( RTEST(vx) )
|
247
|
+
{
|
248
|
+
switch( TYPE(vx) ) {
|
249
|
+
case T_ARRAY: {
|
250
|
+
if( RARRAY(vx)->len < 4 )
|
251
|
+
{
|
252
|
+
rb_raise(rb_eArgError,"Array is too short to be a Rect (%s for 4)",
|
253
|
+
RARRAY(vx)->len);
|
254
|
+
}
|
255
|
+
x = NUM2INT(rb_ary_entry(vx,0));
|
256
|
+
y = NUM2INT(rb_ary_entry(vx,1));
|
257
|
+
w = NUM2INT(rb_ary_entry(vx,2));
|
258
|
+
h = NUM2INT(rb_ary_entry(vx,3));
|
259
|
+
break;
|
260
|
+
}
|
261
|
+
case T_FLOAT:
|
262
|
+
case T_BIGNUM:
|
263
|
+
case T_FIXNUM: {
|
264
|
+
x = NUM2INT(vx);
|
265
|
+
y = NUM2INT(vy);
|
266
|
+
w = NUM2INT(vw);
|
267
|
+
h = NUM2INT(vh);
|
268
|
+
break;
|
269
|
+
}
|
270
|
+
default: {
|
271
|
+
rb_raise(rb_eTypeError,"Unrecognized type for x (wanted Array or Numeric).");
|
272
|
+
break;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
Sint16 left,top,right,bottom;
|
278
|
+
|
279
|
+
left = min( max( 0, x ), screen->w );
|
280
|
+
top = min( max( 0, y ), screen->h );
|
281
|
+
right = min( max( left, x + w), screen->w );
|
282
|
+
bottom = min( max( top, y + h), screen->h );
|
283
|
+
|
284
|
+
x = left;
|
285
|
+
y = top;
|
286
|
+
w = right - left;
|
287
|
+
h = bottom - top;
|
288
|
+
|
289
|
+
SDL_UpdateRect(screen,x,y,w,h);
|
290
|
+
return self;
|
291
|
+
}
|
292
|
+
|
293
|
+
/* call-seq:
|
294
|
+
* update_rects(rects)
|
295
|
+
*
|
296
|
+
* Updates (as Screen#update does) several areas of the screen.
|
297
|
+
*
|
298
|
+
* This method takes these arguments:
|
299
|
+
* rects:: an Array containing any number of Rect objects, each
|
300
|
+
* rect representing a portion of the screen to update.
|
301
|
+
*/
|
302
|
+
VALUE rbgm_screen_updaterects(VALUE self, VALUE array_rects)
|
303
|
+
{
|
304
|
+
int i, num_rects;
|
305
|
+
VALUE each_rect;
|
306
|
+
SDL_Surface *screen;
|
307
|
+
SDL_Rect *rects;
|
308
|
+
|
309
|
+
/* unwrap the Screen instance from self (VALUE) */
|
310
|
+
Data_Get_Struct(self,SDL_Surface,screen);
|
311
|
+
|
312
|
+
/* prepare an (uninitialized) array of Rects */
|
313
|
+
array_rects = convert_to_array(array_rects);
|
314
|
+
num_rects = RARRAY(array_rects)->len;
|
315
|
+
rects = ALLOCA_N(SDL_Rect, num_rects);
|
316
|
+
|
317
|
+
/* initialize the array of Rects from array_rects */
|
318
|
+
for( i=0; i < num_rects; i++ )
|
319
|
+
{
|
320
|
+
each_rect = convert_to_array(rb_ary_entry(array_rects,i));
|
321
|
+
|
322
|
+
Sint16 x,y,left,top,right,bottom;
|
323
|
+
Uint16 w,h;
|
324
|
+
|
325
|
+
x = NUM2INT(rb_ary_entry(each_rect,0));
|
326
|
+
y = NUM2INT(rb_ary_entry(each_rect,1));
|
327
|
+
w = NUM2INT(rb_ary_entry(each_rect,2));
|
328
|
+
h = NUM2INT(rb_ary_entry(each_rect,3));
|
329
|
+
|
330
|
+
left = min( max( 0, x ), screen->w );
|
331
|
+
top = min( max( 0, y ), screen->h );
|
332
|
+
right = min( max( left, x + w), screen->w );
|
333
|
+
bottom = min( max( top, y + h), screen->h );
|
334
|
+
|
335
|
+
rects[i].x = left;
|
336
|
+
rects[i].y = top;
|
337
|
+
rects[i].w = right - left;
|
338
|
+
rects[i].h = bottom - top;
|
339
|
+
}
|
340
|
+
|
341
|
+
/* call the SDL method to update from all these rects */
|
342
|
+
SDL_UpdateRects( screen, num_rects, rects );
|
343
|
+
|
344
|
+
return self;
|
345
|
+
}
|
346
|
+
|
347
|
+
/* call-seq:
|
348
|
+
* flip()
|
349
|
+
*
|
350
|
+
* If the Rubygame display is double-buffered (see #set_mode), flips
|
351
|
+
* the buffers and updates the whole screen. Otherwise, just updates the
|
352
|
+
* whole screen.
|
353
|
+
*/
|
354
|
+
VALUE rbgm_screen_flip(VALUE self)
|
355
|
+
{
|
356
|
+
SDL_Surface *screen;
|
357
|
+
Data_Get_Struct(self, SDL_Surface, screen);
|
358
|
+
SDL_Flip(screen);
|
359
|
+
return self;
|
360
|
+
}
|
361
|
+
|
362
|
+
/* call-seq:
|
363
|
+
* show_cursor? -> true or false
|
364
|
+
*
|
365
|
+
* Returns true if the mouse cursor is shown, or false if hidden. See also
|
366
|
+
* #show_cursor=
|
367
|
+
*/
|
368
|
+
VALUE rbgm_screen_getshowcursor(VALUE self)
|
369
|
+
{
|
370
|
+
return SDL_ShowCursor(SDL_QUERY);
|
371
|
+
}
|
372
|
+
|
373
|
+
/* call-seq:
|
374
|
+
* show_cursor = value -> true or false or nil
|
375
|
+
*
|
376
|
+
* Set whether the mouse cursor is displayed or not. If +value+ is true,
|
377
|
+
* the cursor will be shown; if false, it will be hidden. See also
|
378
|
+
* #show_cursor?
|
379
|
+
*/
|
380
|
+
VALUE rbgm_screen_setshowcursor(VALUE self, VALUE val)
|
381
|
+
{
|
382
|
+
int state;
|
383
|
+
|
384
|
+
if(val == Qtrue) { state = SDL_ENABLE; }
|
385
|
+
else if(val == Qfalse || val == Qnil) { state = SDL_DISABLE; }
|
386
|
+
else { return Qnil; }
|
387
|
+
|
388
|
+
return SDL_ShowCursor(state);
|
389
|
+
}
|
390
|
+
|
391
|
+
/*
|
392
|
+
* Document-class: Rubygame::Screen
|
393
|
+
*
|
394
|
+
* Screen represents the display window for the game. The Screen is a
|
395
|
+
* special Surface that is displayed to the user. By changing and then
|
396
|
+
* updating the Screen many times per second, we can create the illusion
|
397
|
+
* of continous motion.
|
398
|
+
*
|
399
|
+
* Screen inherits most of the Surface methods, and can be passed to methods
|
400
|
+
* which expect a Surface, including Surface#blit and the Draw functions.
|
401
|
+
* However, the Screen cannot have a colorkey or an alpha channel, so
|
402
|
+
* Surface#set_colorkey and Surface#set_alpha are not inherited.
|
403
|
+
*
|
404
|
+
* Please note that only *one* Screen can exist, per application, at a time;
|
405
|
+
* this is a limitation of SDL. You *must* use Screen.set_mode to create the
|
406
|
+
* Screen or modify its properties.
|
407
|
+
*
|
408
|
+
* Also note that no changes to the Screen will be seen until it is refreshed.
|
409
|
+
* See #update, #update_rects, and #flip for ways to refresh all or part of
|
410
|
+
* the Screen.
|
411
|
+
*
|
412
|
+
*/
|
413
|
+
void Rubygame_Init_Screen()
|
414
|
+
{
|
415
|
+
#if 0
|
416
|
+
mRubygame = rb_define_module("Rubygame");
|
417
|
+
cSurface = rb_define_class_under(mRubygame,"Surface",rb_cObject);
|
418
|
+
#endif
|
419
|
+
|
420
|
+
/* Screen class */
|
421
|
+
cScreen = rb_define_class_under(mRubygame,"Screen",cSurface);
|
422
|
+
rb_define_singleton_method(cScreen,"new",rbgm_screen_setmode, -1);
|
423
|
+
rb_define_alias(rb_singleton_class(cScreen),"set_mode","new");
|
424
|
+
rb_define_alias(rb_singleton_class(cScreen),"instance","new");
|
425
|
+
rb_define_singleton_method(cScreen,"get_surface",rbgm_screen_getsurface, 0);
|
426
|
+
|
427
|
+
/* These are inherited from Surface, but should not be called on Screen */
|
428
|
+
rb_undef_method(cScreen,"set_alpha");
|
429
|
+
rb_undef_method(cScreen,"set_colorkey");
|
430
|
+
|
431
|
+
/* Screen methods */
|
432
|
+
rb_define_method(cScreen,"title",rbgm_screen_getcaption,0);
|
433
|
+
rb_define_method(cScreen,"title=",rbgm_screen_setcaption,1);
|
434
|
+
rb_define_method(cScreen,"icon=",rbgm_screen_seticon,1);
|
435
|
+
rb_define_method(cScreen,"update",rbgm_screen_update,-1);
|
436
|
+
rb_define_method(cScreen,"update_rects",rbgm_screen_updaterects,1);
|
437
|
+
rb_define_method(cScreen,"flip",rbgm_screen_flip,0);
|
438
|
+
rb_define_method(cScreen,"show_cursor?",rbgm_screen_getshowcursor,0);
|
439
|
+
rb_define_method(cScreen,"show_cursor=",rbgm_screen_setshowcursor,1);
|
440
|
+
|
441
|
+
/* Screen initialization flags */
|
442
|
+
rb_define_const(mRubygame,"DOUBLEBUF",UINT2NUM(SDL_DOUBLEBUF));
|
443
|
+
rb_define_const(mRubygame,"FULLSCREEN",UINT2NUM(SDL_FULLSCREEN));
|
444
|
+
rb_define_const(mRubygame,"OPENGL",UINT2NUM(SDL_OPENGL));
|
445
|
+
rb_define_const(mRubygame,"OPENGLBLIT",UINT2NUM(SDL_OPENGLBLIT));
|
446
|
+
rb_define_const(mRubygame,"RESIZABLE",UINT2NUM(SDL_RESIZABLE));
|
447
|
+
rb_define_const(mRubygame,"NOFRAME",UINT2NUM(SDL_NOFRAME));
|
448
|
+
}
|
@@ -0,0 +1,43 @@
|
|
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_SCREEN_H
|
22
|
+
#define _RUBYGAME_SCREEN_H
|
23
|
+
|
24
|
+
extern void Rubygame_Init_Screen();
|
25
|
+
|
26
|
+
extern VALUE cScreen;
|
27
|
+
|
28
|
+
extern VALUE rbgm_screen_setmode(int, VALUE*, VALUE);
|
29
|
+
extern VALUE rbgm_screen_getsurface(VALUE);
|
30
|
+
|
31
|
+
extern VALUE rbgm_screen_getcaption(VALUE);
|
32
|
+
extern VALUE rbgm_screen_setcaption(VALUE, VALUE);
|
33
|
+
|
34
|
+
extern VALUE rbgm_screen_seticon(VALUE, VALUE);
|
35
|
+
|
36
|
+
extern VALUE rbgm_screen_update(int, VALUE*, VALUE);
|
37
|
+
extern VALUE rbgm_screen_updaterects(VALUE, VALUE);
|
38
|
+
extern VALUE rbgm_screen_flip(VALUE);
|
39
|
+
|
40
|
+
extern VALUE rbgm_screen_getshowcursor(VALUE);
|
41
|
+
extern VALUE rbgm_screen_setshowcursor(VALUE, VALUE);
|
42
|
+
|
43
|
+
#endif
|
Binary file
|