rubysdl 1.3.1 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/rubysdl_wm.c
CHANGED
@@ -19,53 +19,53 @@
|
|
19
19
|
*/
|
20
20
|
#include "rubysdl.h"
|
21
21
|
|
22
|
-
static VALUE
|
22
|
+
static VALUE WM_s_caption(VALUE mod)
|
23
23
|
{
|
24
|
-
char *title
|
25
|
-
|
26
|
-
|
24
|
+
char *title, *icon;
|
25
|
+
|
26
|
+
rb_secure(4);
|
27
|
+
SDL_WM_GetCaption(&title, &icon);
|
28
|
+
return rb_ary_new3(2, rb_str_new2(title), rb_str_new2(icon));
|
27
29
|
}
|
28
|
-
static VALUE
|
30
|
+
static VALUE WM_s_setCaption(VALUE mod, VALUE title, VALUE icon)
|
29
31
|
{
|
30
|
-
|
32
|
+
rb_secure(4);
|
33
|
+
SafeStringValue(title);
|
34
|
+
SafeStringValue(icon);
|
35
|
+
|
36
|
+
SDL_WM_SetCaption(RSTRING_PTR(title), RSTRING_PTR(icon));
|
31
37
|
return Qnil;
|
32
38
|
}
|
33
|
-
static VALUE
|
39
|
+
static VALUE WM_s_set_icon(VALUE mod, VALUE icon)
|
34
40
|
{
|
35
|
-
|
36
|
-
|
37
|
-
rb_raise(rb_eArgError,"type mismatch (expected Surface)");
|
38
|
-
Data_Get_Struct(icon,SDL_Surface,surface);
|
39
|
-
SDL_WM_SetIcon(surface,NULL);
|
41
|
+
rb_secure(4);
|
42
|
+
SDL_WM_SetIcon(Get_SDL_Surface(icon), NULL);
|
40
43
|
return Qnil;
|
41
44
|
}
|
42
|
-
static VALUE
|
45
|
+
static VALUE WM_s_iconify(VALUE mod)
|
43
46
|
{
|
47
|
+
rb_secure(4);
|
44
48
|
if( ! SDL_WM_IconifyWindow() )
|
45
49
|
rb_raise( eSDLError,"iconify failed: %s",SDL_GetError() );
|
46
50
|
return Qnil;
|
47
51
|
}
|
48
52
|
|
49
|
-
static
|
50
|
-
{
|
51
|
-
rb_define_const(mWM,"GRAB_QUERY",INT2NUM(SDL_GRAB_QUERY));
|
52
|
-
rb_define_const(mWM,"GRAB_OFF",INT2NUM(SDL_GRAB_OFF));
|
53
|
-
rb_define_const(mWM,"GRAB_ON",INT2NUM(SDL_GRAB_ON));
|
54
|
-
}
|
55
|
-
|
56
|
-
static VALUE sdl_wm_grabInput(VALUE mod, VALUE flag)
|
53
|
+
static VALUE WM_s_grabInput(VALUE mod, VALUE flag)
|
57
54
|
{
|
58
|
-
|
55
|
+
rb_secure(4);
|
56
|
+
return INT2FIX(SDL_WM_GrabInput(flag));
|
59
57
|
}
|
60
58
|
|
61
|
-
void
|
59
|
+
void rubysdl_init_WM(VALUE mSDL)
|
62
60
|
{
|
63
|
-
mWM=rb_define_module_under(mSDL,"WM");
|
64
|
-
rb_define_module_function(mWM,"caption",
|
65
|
-
rb_define_module_function(mWM,"setCaption",
|
66
|
-
rb_define_module_function(mWM,"icon=",
|
67
|
-
rb_define_module_function(mWM,"iconify",
|
68
|
-
rb_define_module_function(mWM,"grabInput",
|
61
|
+
VALUE mWM=rb_define_module_under(mSDL, "WM");
|
62
|
+
rb_define_module_function(mWM, "caption", WM_s_caption, 0);
|
63
|
+
rb_define_module_function(mWM, "setCaption", WM_s_setCaption, 2);
|
64
|
+
rb_define_module_function(mWM, "icon=", WM_s_set_icon, 1);
|
65
|
+
rb_define_module_function(mWM, "iconify", WM_s_iconify, 0);
|
66
|
+
rb_define_module_function(mWM, "grabInput", WM_s_grabInput, 1);
|
69
67
|
|
70
|
-
|
68
|
+
rb_define_const(mWM, "GRAB_QUERY", INT2NUM(SDL_GRAB_QUERY));
|
69
|
+
rb_define_const(mWM, "GRAB_OFF", INT2NUM(SDL_GRAB_OFF));
|
70
|
+
rb_define_const(mWM, "GRAB_ON", INT2NUM(SDL_GRAB_ON));
|
71
71
|
}
|
data/sample/aadraw.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
5
|
-
SDL::WM::
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
SDL::WM::set_caption $0, $0
|
6
6
|
|
7
|
-
Red=screen.format.
|
8
|
-
screen.
|
9
|
-
screen.
|
10
|
-
screen.
|
11
|
-
screen.
|
7
|
+
Red=screen.format.map_rgb(255,0,0)
|
8
|
+
screen.draw_line(20,20,300,200,Red, true)
|
9
|
+
screen.draw_circle(100,100,50,[87,87,87], false, true)
|
10
|
+
screen.draw_circle(300,300,30,Red, true, true)
|
11
|
+
screen.draw_ellipse(320,240,100,200,[200,255,0], false, true)
|
12
12
|
|
13
13
|
screen.flip
|
14
14
|
|
15
15
|
while true
|
16
|
-
while event = SDL::
|
16
|
+
while event = SDL::Event.poll
|
17
17
|
case event
|
18
|
-
when SDL::
|
18
|
+
when SDL::Event::KeyDown, SDL::Event::Quit
|
19
19
|
exit
|
20
20
|
end
|
21
21
|
end
|
data/sample/alpha.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
|
6
|
+
image = SDL::Surface.load_bmp("icon.bmp")
|
7
|
+
image.set_color_key( SDL::SRCCOLORKEY ,0)
|
8
|
+
image = image.display_format
|
5
9
|
|
6
|
-
image = SDL::Surface.loadBMP("icon.bmp")
|
7
|
-
image.setColorKey( SDL::SRCCOLORKEY ,0)
|
8
|
-
image = image.displayFormat
|
9
10
|
|
10
|
-
event=SDL::Event.new
|
11
11
|
i=0;
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if event.type==SDL::Event::KEYDOWN then
|
12
|
+
black = screen.format.map_rgb(0,0,0)
|
13
|
+
while true
|
14
|
+
while event = SDL::Event.poll
|
15
|
+
case event
|
16
|
+
when SDL::Event::Quit, SDL::Event::KeyDown
|
18
17
|
exit
|
19
18
|
end
|
20
19
|
end
|
21
|
-
screen.fillRect(0,0,640,480,
|
20
|
+
screen.fillRect(0,0,640,480,black)
|
22
21
|
|
23
|
-
image.
|
22
|
+
image.set_alpha(SDL::SRCALPHA,i%256)
|
24
23
|
screen.put(image,310,195)
|
25
24
|
i+=1
|
26
25
|
screen.flip
|
data/sample/alphadraw.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
5
|
-
SDL::WM::
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
SDL::WM::set_caption $0, $0
|
6
6
|
|
7
|
-
Red=screen.format.
|
8
|
-
screen.
|
9
|
-
screen.
|
10
|
-
screen.
|
11
|
-
screen.
|
12
|
-
screen.
|
7
|
+
Red=screen.format.map_rgb(255,0,0)
|
8
|
+
screen.draw_circle(320,240,220,[140,180,0], true, true)
|
9
|
+
screen.draw_line(20,20,300,200,Red,true, rand(64)+128)
|
10
|
+
screen.draw_circle(100,100,50,[87,87,87],false,true,rand(64)+128)
|
11
|
+
screen.draw_circle(300,170,50,[87,80,0],true, false, rand(64)+128)
|
12
|
+
screen.draw_ellipse(320,240,100,200,[200,255,0],false, false, rand(64)+128)
|
13
13
|
|
14
14
|
screen.flip
|
15
15
|
|
16
16
|
while true
|
17
|
-
while event = SDL::
|
17
|
+
while event = SDL::Event.poll
|
18
18
|
case event
|
19
|
-
when SDL::
|
19
|
+
when SDL::Event::KeyDown, SDL::Event::Quit
|
20
20
|
exit
|
21
21
|
end
|
22
22
|
end
|
data/sample/bfont.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
5
|
|
6
6
|
font = SDL::BMFont.open("font.bmp",SDL::BMFont::TRANSPARENT)
|
7
7
|
|
8
8
|
y = 0
|
9
9
|
|
10
10
|
while true
|
11
|
-
while event = SDL::
|
11
|
+
while event = SDL::Event.poll
|
12
12
|
case event
|
13
|
-
when SDL::
|
13
|
+
when SDL::Event::KeyDown, SDL::Event::Quit
|
14
14
|
exit
|
15
15
|
end
|
16
16
|
end
|
17
|
-
screen.
|
17
|
+
screen.fill_rect(0,0,640,480,0)
|
18
18
|
|
19
19
|
y = (y + 1) % 480
|
20
20
|
font.textout(screen,"BitMapFont Testing..",40,y)
|
data/sample/cdrom.rb
CHANGED
@@ -2,14 +2,21 @@ require 'sdl'
|
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_CDROM )
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
num_drive = SDL::CD.num_drive
|
6
|
+
if num_drive == 0
|
7
|
+
print "No cdrom drive is detected\n"
|
8
|
+
exit
|
9
|
+
else
|
10
|
+
print "#{num_drive} cdrom drives are detected\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
print SDL::CD.index_name(0),"\n"
|
7
14
|
cd=SDL::CD.open(0)
|
8
15
|
cd.status
|
9
|
-
print cd.
|
16
|
+
print cd.num_tracks," ",cd.status, "\n"
|
10
17
|
|
11
18
|
begin
|
12
|
-
cd.
|
19
|
+
cd.play_tracks 1,0,1,0
|
13
20
|
sleep 100
|
14
21
|
ensure
|
15
22
|
cd.stop
|
data/sample/collision.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
5
|
-
SDL::WM::
|
6
|
-
$image = SDL::Surface.
|
7
|
-
$image.
|
8
|
-
$image = $image.
|
9
|
-
$cMap = $image.
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
SDL::WM::set_caption('collision.rb','collision.rb icon')
|
6
|
+
$image = SDL::Surface.load_bmp("icon.bmp")
|
7
|
+
$image.set_color_key( SDL::SRCCOLORKEY ,0)
|
8
|
+
$image = $image.display_format
|
9
|
+
$cMap = $image.make_collision_map
|
10
10
|
|
11
11
|
class Sprite
|
12
12
|
|
@@ -21,8 +21,8 @@ class Sprite
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def move
|
24
|
-
@x, @dx =
|
25
|
-
@y, @dy =
|
24
|
+
@x, @dx = move_coord(@x, @dx, xMax)
|
25
|
+
@y, @dy = move_coord(@y, @dy, yMax)
|
26
26
|
end
|
27
27
|
|
28
28
|
def bounce
|
@@ -32,16 +32,16 @@ class Sprite
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def draw
|
35
|
-
SDL.
|
35
|
+
SDL::Surface.blit($image,0,0,$image.w,$image.h,@screen,@x,@y)
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
$cMap.
|
38
|
+
def collide_with?(sprite)
|
39
|
+
$cMap.collision_check(@x, @y, $cMap, sprite.x, sprite.y) != nil
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
def
|
44
|
+
def move_coord(coord, delta, max)
|
45
45
|
coord += delta
|
46
46
|
if coord >= max then
|
47
47
|
delta *= -1
|
@@ -64,11 +64,11 @@ class Sprite
|
|
64
64
|
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
67
|
+
def detect_collisions(sprites)
|
68
68
|
collisions = []
|
69
69
|
for i in (0 ... sprites.size - 1) do
|
70
70
|
for j in (i + 1 ... sprites.size) do
|
71
|
-
if sprites[i].
|
71
|
+
if sprites[i].collide_with?(sprites[j])
|
72
72
|
collisions << sprites[i]
|
73
73
|
collisions << sprites[j]
|
74
74
|
end
|
@@ -79,19 +79,19 @@ end
|
|
79
79
|
|
80
80
|
sprites = (1..8).collect {Sprite.new(screen)}
|
81
81
|
|
82
|
-
|
82
|
+
background = screen.format.map_rgb(64, 64, 64)
|
83
83
|
while true
|
84
|
-
while event = SDL::
|
84
|
+
while event = SDL::Event.poll
|
85
85
|
case event
|
86
|
-
when SDL::
|
86
|
+
when SDL::Event::KeyDown, SDL::Event::Quit
|
87
87
|
exit
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
screen.
|
91
|
+
screen.fill_rect(0,0,640,480,background)
|
92
92
|
sprites.each {|i| i.move}
|
93
|
-
|
93
|
+
detect_collisions(sprites).each {|i| i.bounce}
|
94
94
|
sprites.each {|i| i.draw}
|
95
|
-
screen.
|
95
|
+
screen.update_rect(0,0,0,0)
|
96
96
|
end
|
97
97
|
|
data/sample/cursor.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
5
|
-
screen.
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
screen.fill_rect 0,0,640,480,[32,240,100]
|
6
6
|
screen.flip
|
7
|
-
SDL::WM::
|
7
|
+
SDL::WM::set_caption $0,$0
|
8
8
|
|
9
|
-
image=SDL::Surface.
|
10
|
-
SDL::Mouse.
|
9
|
+
image=SDL::Surface.load_bmp 'cursor.bmp'
|
10
|
+
SDL::Mouse.set_cursor image,image[0,0],image[1,1],image[7,0],543
|
11
11
|
|
12
12
|
|
13
13
|
while true
|
data/sample/ellipses.rb
CHANGED
@@ -3,33 +3,37 @@
|
|
3
3
|
|
4
4
|
require 'sdl'
|
5
5
|
|
6
|
-
def show(
|
7
|
-
|
8
|
-
|
6
|
+
def show(fill)
|
7
|
+
screen = SDL::Screen.open(640, 480, 16, SDL::SWSURFACE)
|
8
|
+
format = screen.format
|
9
9
|
loop do
|
10
|
-
color =
|
10
|
+
color = format.map_rgb(rand(256),rand(256),rand(256))
|
11
11
|
x = rand(screen.w)
|
12
12
|
y = rand(screen.h)
|
13
13
|
xr = rand(80)
|
14
14
|
yr = rand(80)
|
15
|
-
|
16
|
-
|
17
|
-
case event
|
18
|
-
when SDL::Event::
|
15
|
+
screen.draw_ellipse(x, y, xr, yr, color, fill)
|
16
|
+
while event = SDL::Event.poll
|
17
|
+
case event
|
18
|
+
when SDL::Event::Quit
|
19
19
|
exit
|
20
|
-
when SDL::Event::
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
when SDL::Event::KeyDown
|
21
|
+
if event.sym == SDL::Key::ESCAPE
|
22
|
+
exit
|
23
|
+
else
|
24
|
+
return
|
25
|
+
end
|
26
|
+
when SDL::Event::MouseButtonDown
|
27
|
+
return
|
25
28
|
end
|
26
29
|
end
|
27
|
-
SDL::Key.scan
|
28
30
|
screen.updateRect(0, 0, 0, 0)
|
31
|
+
sleep 0.05
|
29
32
|
end
|
33
|
+
screen.destroy
|
30
34
|
end
|
31
35
|
|
32
36
|
srand
|
33
37
|
SDL.init SDL::INIT_VIDEO
|
34
|
-
show(
|
35
|
-
show(
|
38
|
+
show(false)
|
39
|
+
show(true)
|
data/sample/event2.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'sdl'
|
2
2
|
|
3
3
|
SDL.init( SDL::INIT_VIDEO )
|
4
|
-
screen = SDL::
|
5
|
-
SDL::WM::
|
4
|
+
screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
|
5
|
+
SDL::WM::set_caption $0,$0
|
6
6
|
|
7
7
|
loop do
|
8
|
-
|
8
|
+
while event=SDL::Event.poll
|
9
9
|
case event
|
10
|
-
when SDL::
|
10
|
+
when SDL::Event::Active
|
11
11
|
print "Active ", (event.gain)?"gain":"lost","\n"
|
12
|
-
when SDL::
|
12
|
+
when SDL::Event::KeyDown
|
13
13
|
print "KeyDown sym:#{event.sym} mod:#{event.mod}","\n"
|
14
14
|
if event.sym==SDL::Key::A then
|
15
|
-
e=SDL::
|
15
|
+
e=SDL::Event::KeyDown.new
|
16
16
|
e.sym=3333
|
17
17
|
e.mod=3333
|
18
18
|
e.press=true
|
19
19
|
e.unicode=200
|
20
|
-
SDL::
|
20
|
+
SDL::Event.push(e)
|
21
21
|
end
|
22
|
-
when SDL::
|
22
|
+
when SDL::Event::KeyUp
|
23
23
|
print "KeyUp sym:#{event.sym} mod:#{event.mod}","\n"
|
24
24
|
|
25
|
-
when SDL::
|
25
|
+
when SDL::Event::Quit
|
26
26
|
exit
|
27
27
|
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
sleep 0.05
|
30
32
|
end
|
31
33
|
|
32
34
|
|