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,101 @@
|
|
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
|
+
#ifndef _RUBYGAME_GFX_H
|
23
|
+
#define _RUBYGAME_GFX_H
|
24
|
+
|
25
|
+
#include <SDL_gfxPrimitives.h>
|
26
|
+
#include <SDL_rotozoom.h>
|
27
|
+
|
28
|
+
#ifndef SDL_GFXPRIMITIVES_MAJOR
|
29
|
+
#define SDL_GFXPRIMITIVES_MAJOR 0
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifndef SDL_GFXPRIMITIVES_MINOR
|
33
|
+
#define SDL_GFXPRIMITIVES_MINOR 0
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifndef SDL_GFXPRIMITIVES_MICRO
|
37
|
+
#define SDL_GFXPRIMITIVES_MICRO 0
|
38
|
+
#endif
|
39
|
+
|
40
|
+
|
41
|
+
/* If we have at least version 2.0.12 of SDL_gfxPrimitives, draw_pie calls
|
42
|
+
filledPieRGBA, otherwise it calls filledpieRGBA (lowercase pie)*/
|
43
|
+
#ifndef HAVE_UPPERCASEPIE
|
44
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 12))
|
45
|
+
#define HAVE_UPPERCASEPIE
|
46
|
+
#endif
|
47
|
+
#endif
|
48
|
+
|
49
|
+
/* Separate X/Y rotozoom scaling was not supported prior to 2.0.13. */
|
50
|
+
/* Check if we have at least version 2.0.13 of SDL_gfxPrimitives */
|
51
|
+
#ifndef HAVE_ROTOZOOMXY
|
52
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 13))
|
53
|
+
#define HAVE_ROTOZOOMXY
|
54
|
+
#endif
|
55
|
+
#endif
|
56
|
+
|
57
|
+
/* Non-filled pie shapes (arcs) were not supported prior to 2.0.11. */
|
58
|
+
/* Check if we have at least version 2.0.11 of SDL_gfxPrimitives */
|
59
|
+
#ifndef HAVE_NONFILLEDPIE
|
60
|
+
#if ((SDL_GFXPRIMITIVES_MAJOR > 2) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR > 0) || (SDL_GFXPRIMITIVES_MAJOR == 2 && SDL_GFXPRIMITIVES_MINOR == 0 && SDL_GFXPRIMITIVES_MICRO >= 11))
|
61
|
+
#define HAVE_NONFILLEDPIE
|
62
|
+
#endif
|
63
|
+
#endif
|
64
|
+
|
65
|
+
extern void Init_rubygame_gfx();
|
66
|
+
extern void extract_xy(VALUE, Sint16*, Sint16*);
|
67
|
+
|
68
|
+
extern void draw_line(VALUE, VALUE, VALUE, VALUE, int);
|
69
|
+
extern VALUE rbgm_draw_line(VALUE, VALUE, VALUE, VALUE);
|
70
|
+
extern VALUE rbgm_draw_aaline(VALUE, VALUE, VALUE, VALUE);
|
71
|
+
|
72
|
+
extern void draw_rect(VALUE, VALUE, VALUE, VALUE, int);
|
73
|
+
extern VALUE rbgm_draw_rect(VALUE, VALUE, VALUE, VALUE);
|
74
|
+
extern VALUE rbgm_draw_fillrect(VALUE, VALUE, VALUE, VALUE);
|
75
|
+
|
76
|
+
extern void draw_circle(VALUE, VALUE, VALUE, VALUE, int, int);
|
77
|
+
extern VALUE rbgm_draw_circle(VALUE, VALUE, VALUE, VALUE);
|
78
|
+
extern VALUE rbgm_draw_aacircle(VALUE, VALUE, VALUE, VALUE);
|
79
|
+
extern VALUE rbgm_draw_fillcircle(VALUE, VALUE, VALUE, VALUE);
|
80
|
+
|
81
|
+
extern void draw_ellipse(VALUE, VALUE, VALUE, VALUE, int, int);
|
82
|
+
extern VALUE rbgm_draw_ellipse(VALUE, VALUE, VALUE, VALUE);
|
83
|
+
extern VALUE rbgm_draw_aaellipse(VALUE, VALUE, VALUE, VALUE);
|
84
|
+
extern VALUE rbgm_draw_fillellipse(VALUE, VALUE, VALUE, VALUE);
|
85
|
+
|
86
|
+
extern void draw_pie(VALUE, VALUE, VALUE, VALUE, VALUE, int);
|
87
|
+
extern VALUE rbgm_draw_pie(VALUE, VALUE, VALUE, VALUE, VALUE);
|
88
|
+
extern VALUE rbgm_draw_fillpie(VALUE, VALUE, VALUE, VALUE, VALUE);
|
89
|
+
|
90
|
+
extern void draw_polygon(VALUE, VALUE, VALUE, int, int);
|
91
|
+
extern VALUE rbgm_draw_polygon(VALUE, VALUE, VALUE);
|
92
|
+
extern VALUE rbgm_draw_aapolygon(VALUE, VALUE, VALUE);
|
93
|
+
extern VALUE rbgm_draw_fillpolygon(VALUE, VALUE, VALUE);
|
94
|
+
|
95
|
+
extern VALUE rbgm_transform_rotozoom(int, VALUE*, VALUE);
|
96
|
+
extern VALUE rbgm_transform_rotozoomsize(int, VALUE*, VALUE);
|
97
|
+
|
98
|
+
extern VALUE rbgm_transform_zoom(int, VALUE*, VALUE);
|
99
|
+
extern VALUE rbgm_transform_zoomsize(int, VALUE*, VALUE);
|
100
|
+
|
101
|
+
#endif
|
Binary file
|
Binary file
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
* OpenGL attribute methods.
|
3
|
+
* --
|
4
|
+
* Rubygame -- Ruby classes and bindings to SDL to facilitate game creation
|
5
|
+
* Copyright (C) 2004-2007 John Croisant
|
6
|
+
*
|
7
|
+
* This library is free software; you can redistribute it and/or
|
8
|
+
* modify it under the terms of the GNU Lesser General Public
|
9
|
+
* License as published by the Free Software Foundation; either
|
10
|
+
* version 2.1 of the License, or (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This library is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
* Lesser General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public
|
18
|
+
* License along with this library; if not, write to the Free Software
|
19
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
* ++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_gl.h"
|
25
|
+
|
26
|
+
/* --
|
27
|
+
* Most code is directly from Ruby/SDL's rubysdl_opengl.c file.
|
28
|
+
*
|
29
|
+
* Many thanks for saving me some time. :)
|
30
|
+
* ++
|
31
|
+
*/
|
32
|
+
|
33
|
+
VALUE mGL;
|
34
|
+
void Rubygame_Init_GL();
|
35
|
+
void Define_GL_Constants();
|
36
|
+
|
37
|
+
#ifdef HAVE_OPENGL
|
38
|
+
|
39
|
+
VALUE rbgm_gl_getattrib(VALUE, VALUE);
|
40
|
+
VALUE rbgm_gl_setattrib(VALUE,VALUE,VALUE);
|
41
|
+
VALUE rbgm_gl_swapbuffers(VALUE);
|
42
|
+
|
43
|
+
/* call-seq:
|
44
|
+
* get_attrib( attrib ) -> Integer
|
45
|
+
*
|
46
|
+
* Return the value of the the SDL/OpenGL attribute identified by +attrib+,
|
47
|
+
* which should be one of the constants defined in the Rubygame::GL module.
|
48
|
+
* See #set_attrib for a list of attribute constants.
|
49
|
+
*
|
50
|
+
* This method is useful after using #set_attrib and calling Screen#set_mode,
|
51
|
+
* to make sure the attribute is the expected value.
|
52
|
+
*/
|
53
|
+
VALUE rbgm_gl_getattrib(VALUE module, VALUE attr)
|
54
|
+
{
|
55
|
+
int val;
|
56
|
+
if(SDL_GL_GetAttribute(NUM2INT(attr),&val)==-1)
|
57
|
+
rb_raise(eSDLError,"GL get attribute failed: %s",SDL_GetError());
|
58
|
+
return INT2NUM(val);
|
59
|
+
}
|
60
|
+
|
61
|
+
/* call-seq:
|
62
|
+
* set_attrib( attrib, value ) -> nil
|
63
|
+
*
|
64
|
+
* Set the SDL/OpenGL attribute +attrib+ to +value+. This should be called
|
65
|
+
* *before* you call Screen#set_mode with the OPENGL flag. You may wish to
|
66
|
+
* use #get_attrib after calling Screen#set_mode to confirm that the attribute
|
67
|
+
* is set to the desired value.
|
68
|
+
*
|
69
|
+
* The full list of SDL/OpenGL attribute identifier constants (located under
|
70
|
+
* the Rubygame::GL module) is as follows:
|
71
|
+
*
|
72
|
+
* RED_SIZE:: Size of framebuffer red component, in bits.
|
73
|
+
* GREEN_SIZE:: Size of framebuffer green component, in bits.
|
74
|
+
* BLUE_SIZE:: Size of framebuffer blue component, in bits.
|
75
|
+
* ALPHA_SIZE:: Size of framebuffer alpha (opacity) component, in bits.
|
76
|
+
* BUFFER_SIZE:: Size of framebuffer, in bits.
|
77
|
+
* DOUBLEBUFFER:: Enable or disable double-buffering.
|
78
|
+
* DEPTH_SIZE:: Size of depth buffer, in bits.
|
79
|
+
* STENCIL_SIZE:: Size of stencil buffer, in bits.
|
80
|
+
* ACCUM_RED_SIZE:: Size of accumulation buffer red component, in bits.
|
81
|
+
* ACCUM_GREEN_SIZE:: Size of accumulation buffer green component, in bits.
|
82
|
+
* ACCUM_BLUE_SIZE:: Size of accumulation buffer blue component, in bits.
|
83
|
+
* ACCUM_ALPHA_SIZE:: Size of accumulation buffer alpha component, in bits.
|
84
|
+
*
|
85
|
+
*/
|
86
|
+
VALUE rbgm_gl_setattrib(VALUE module,VALUE attr,VALUE val)
|
87
|
+
{
|
88
|
+
if(SDL_GL_SetAttribute(NUM2INT(attr),NUM2INT(val))==-1)
|
89
|
+
rb_raise(eSDLError,"GL set attribute failed: %s",SDL_GetError());
|
90
|
+
return Qnil;
|
91
|
+
}
|
92
|
+
|
93
|
+
/* call-seq:
|
94
|
+
* swap_buffers( ) -> nil
|
95
|
+
*
|
96
|
+
* Swap the back and front buffers, for double-buffered OpenGL displays.
|
97
|
+
* Should be safe to use (albeit with no effect) on single-buffered OpenGL
|
98
|
+
* displays.
|
99
|
+
*/
|
100
|
+
VALUE rbgm_gl_swapbuffers(VALUE module)
|
101
|
+
{
|
102
|
+
SDL_GL_SwapBuffers();
|
103
|
+
return Qnil;
|
104
|
+
}
|
105
|
+
|
106
|
+
#endif
|
107
|
+
|
108
|
+
/* Document-module: Rubygame::GL
|
109
|
+
*
|
110
|
+
* The GL module provides an interface to SDL's OpenGL-related functions,
|
111
|
+
* allowing a Rubygame application to create hardware-accelerated 3D graphics
|
112
|
+
* with OpenGL.
|
113
|
+
*
|
114
|
+
* Please note that Rubygame itself does not provide an interface to OpenGL
|
115
|
+
* functions -- only functions which allow Rubygame to work together with
|
116
|
+
* OpenGL. You will need to use another library, for example
|
117
|
+
* ruby-opengl[http://ruby-opengl.rubyforge.org/],
|
118
|
+
* to actually create graphics with OpenGL.
|
119
|
+
*
|
120
|
+
* Users who wish to use Rubygame Surfaces as textures in OpenGL should
|
121
|
+
* see also the Surface#pixels method.
|
122
|
+
*/
|
123
|
+
void Rubygame_Init_GL()
|
124
|
+
{
|
125
|
+
#if 0
|
126
|
+
mRubygame = rb_define_module("Rubygame");
|
127
|
+
#endif
|
128
|
+
|
129
|
+
mGL = rb_define_module_under(mRubygame,"GL");
|
130
|
+
Define_GL_Constants();
|
131
|
+
|
132
|
+
#ifdef HAVE_OPENGL
|
133
|
+
rb_define_module_function(mGL,"get_attrib", rbgm_gl_getattrib, 1);
|
134
|
+
rb_define_module_function(mGL,"set_attrib", rbgm_gl_setattrib, 2);
|
135
|
+
rb_define_module_function(mGL,"swap_buffers", rbgm_gl_swapbuffers, 0);
|
136
|
+
#endif
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
void Define_GL_Constants()
|
141
|
+
{
|
142
|
+
rb_define_const(mGL,"RED_SIZE",INT2NUM(SDL_GL_RED_SIZE));
|
143
|
+
rb_define_const(mGL,"GREEN_SIZE",INT2NUM(SDL_GL_GREEN_SIZE));
|
144
|
+
rb_define_const(mGL,"BLUE_SIZE",INT2NUM(SDL_GL_BLUE_SIZE));
|
145
|
+
rb_define_const(mGL,"ALPHA_SIZE",INT2NUM(SDL_GL_ALPHA_SIZE));
|
146
|
+
rb_define_const(mGL,"BUFFER_SIZE",INT2NUM(SDL_GL_BUFFER_SIZE));
|
147
|
+
rb_define_const(mGL,"DOUBLEBUFFER",INT2NUM(SDL_GL_DOUBLEBUFFER));
|
148
|
+
rb_define_const(mGL,"DEPTH_SIZE",INT2NUM(SDL_GL_DEPTH_SIZE));
|
149
|
+
rb_define_const(mGL,"STENCIL_SIZE",INT2NUM(SDL_GL_STENCIL_SIZE));
|
150
|
+
rb_define_const(mGL,"ACCUM_RED_SIZE",INT2NUM(SDL_GL_ACCUM_RED_SIZE));
|
151
|
+
rb_define_const(mGL,"ACCUM_GREEN_SIZE",INT2NUM(SDL_GL_ACCUM_GREEN_SIZE));
|
152
|
+
rb_define_const(mGL,"ACCUM_BLUE_SIZE",INT2NUM(SDL_GL_ACCUM_BLUE_SIZE));
|
153
|
+
rb_define_const(mGL,"ACCUM_ALPHA_SIZE",INT2NUM(SDL_GL_ACCUM_ALPHA_SIZE));
|
154
|
+
}
|
@@ -0,0 +1,32 @@
|
|
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_GL_H
|
22
|
+
#define _RUBYGAME_GL_H
|
23
|
+
|
24
|
+
extern VALUE mGL;
|
25
|
+
extern void Rubygame_Init_GL();
|
26
|
+
extern void Define_GL_Constants();
|
27
|
+
|
28
|
+
extern VALUE rbgm_gl_getattrib(VALUE, VALUE);
|
29
|
+
extern VALUE rbgm_gl_setattrib(VALUE,VALUE,VALUE);
|
30
|
+
extern VALUE rbgm_gl_swapbuffers(VALUE);
|
31
|
+
|
32
|
+
#endif
|
Binary file
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/*
|
2
|
+
* Interface to SDL_image library, for loading image files to Surfaces.
|
3
|
+
*--
|
4
|
+
* Rubygame -- Ruby code and bindings to SDL to facilitate game creation
|
5
|
+
* Copyright (C) 2004-2007 John Croisant
|
6
|
+
*
|
7
|
+
* This library is free software; you can redistribute it and/or
|
8
|
+
* modify it under the terms of the GNU Lesser General Public
|
9
|
+
* License as published by the Free Software Foundation; either
|
10
|
+
* version 2.1 of the License, or (at your option) any later version.
|
11
|
+
*
|
12
|
+
* This library is distributed in the hope that it will be useful,
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
+
* Lesser General Public License for more details.
|
16
|
+
*
|
17
|
+
* You should have received a copy of the GNU Lesser General Public
|
18
|
+
* License along with this library; if not, write to the Free Software
|
19
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
*++
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "rubygame_shared.h"
|
24
|
+
#include "rubygame_surface.h"
|
25
|
+
#include "rubygame_image.h"
|
26
|
+
|
27
|
+
void Rubygame_Init_Image();
|
28
|
+
VALUE rbgm_image_load(VALUE, VALUE);
|
29
|
+
|
30
|
+
/*
|
31
|
+
* call-seq:
|
32
|
+
* Surface.load_image( filename ) -> Surface
|
33
|
+
*
|
34
|
+
* Load an image file from the disk to a Surface. If the image has an alpha
|
35
|
+
* channel (e.g. PNG with transparency), the Surface will as well. If the
|
36
|
+
* image cannot be loaded (for example if the image format is unsupported),
|
37
|
+
* will raise SDLError.
|
38
|
+
*
|
39
|
+
* This method is only usable if Rubygame was compiled with the SDL_image
|
40
|
+
* library; you can check Rubygame::VERSIONS[:sdl_image] to see if it was.
|
41
|
+
*
|
42
|
+
* This method takes this argument:
|
43
|
+
* filename:: a string containing the relative or absolute path to the
|
44
|
+
* image file. The file must have the proper file extension,
|
45
|
+
* as it is used to determine image format.
|
46
|
+
*
|
47
|
+
* These formats may be supported, but some may not be available on a
|
48
|
+
* particular system.
|
49
|
+
* BMP:: "Windows Bitmap" format.
|
50
|
+
* GIF:: "Graphics Interchange Format."
|
51
|
+
* JPG:: "Independent JPEG Group" format.
|
52
|
+
* LBM:: "Linear Bitmap" format (?)
|
53
|
+
* PCX:: "PC Paintbrush" format
|
54
|
+
* PNG:: "Portable Network Graphics" format.
|
55
|
+
* PNM:: "Portable Any Map" format. (i.e., PPM, PGM, or PBM)
|
56
|
+
* TGA:: "Truevision TARGA" format.
|
57
|
+
* TIF:: "Tagged Image File Format"
|
58
|
+
* XCF:: "eXperimental Computing Facility" (GIMP native format).
|
59
|
+
* XPM:: "XPixMap" format.
|
60
|
+
*/
|
61
|
+
VALUE rbgm_image_load( VALUE class, VALUE filename )
|
62
|
+
{
|
63
|
+
char *name;
|
64
|
+
SDL_Surface *surf;
|
65
|
+
|
66
|
+
name = StringValuePtr(filename);
|
67
|
+
surf = IMG_Load( name );
|
68
|
+
if(surf == NULL)
|
69
|
+
{
|
70
|
+
rb_raise(eSDLError,"Couldn't load image `%s': %s", name, IMG_GetError());
|
71
|
+
}
|
72
|
+
return Data_Wrap_Struct( cSurface,0,SDL_FreeSurface,surf );
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
* Document-class: Rubygame::Surface
|
77
|
+
*
|
78
|
+
* Surface represents an image, a block of colored pixels arranged in a 2D grid.
|
79
|
+
* You can load image files to a new Surface with #load_image, or create
|
80
|
+
* an empty one with Surface.new and draw shapes on it with #draw_line,
|
81
|
+
* #draw_circle, and all the rest.
|
82
|
+
*
|
83
|
+
* One of the most important Surface concepts is #blit, copying image
|
84
|
+
* data from one Surface onto another. By blitting Surfaces onto the
|
85
|
+
* Screen (which is a special type of Surface) and then using Screen#update,
|
86
|
+
* you can make images appear for the player to see.
|
87
|
+
*
|
88
|
+
*/
|
89
|
+
void Init_rubygame_image()
|
90
|
+
{
|
91
|
+
|
92
|
+
#if 0
|
93
|
+
mRubygame = rb_define_module("Rubygame");
|
94
|
+
cSurface = rb_define_class_under(mRubygame,"Surface",rb_cObject);
|
95
|
+
#endif
|
96
|
+
|
97
|
+
Init_rubygame_shared();
|
98
|
+
|
99
|
+
rb_hash_aset(rb_ivar_get(mRubygame,rb_intern("VERSIONS")),
|
100
|
+
ID2SYM(rb_intern("sdl_image")),
|
101
|
+
rb_ary_new3(3,
|
102
|
+
INT2NUM(SDL_IMAGE_MAJOR_VERSION),
|
103
|
+
INT2NUM(SDL_IMAGE_MINOR_VERSION),
|
104
|
+
INT2NUM(SDL_IMAGE_PATCHLEVEL)));
|
105
|
+
|
106
|
+
/* Image methods */
|
107
|
+
rb_define_singleton_method(cSurface,"load_image",rbgm_image_load,1);
|
108
|
+
}
|
@@ -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
|
+
}
|