rubysdl 1.3.1 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/MANIFEST +22 -2
  2. data/NEWS.en +80 -0
  3. data/NEWS.ja +83 -0
  4. data/README.en +2 -1
  5. data/README.ja +2 -2
  6. data/doc-en/Makefile +18 -0
  7. data/doc-en/cdrom.rsd +417 -0
  8. data/doc-en/collision.rsd +174 -0
  9. data/doc-en/event.rsd +1476 -0
  10. data/doc-en/font.rsd +811 -0
  11. data/doc-en/general.rsd +43 -0
  12. data/doc-en/init.rsd +168 -0
  13. data/doc-en/joystick.rsd +401 -0
  14. data/doc-en/mixer.rsd +869 -0
  15. data/doc-en/mpeg.rsd +585 -0
  16. data/doc-en/opengl.rsd +155 -0
  17. data/doc-en/sdlskk.rsd +472 -0
  18. data/doc-en/time.rsd +46 -0
  19. data/doc-en/video.rsd +2806 -0
  20. data/doc-en/wm.rsd +112 -0
  21. data/doc/Makefile +1 -1
  22. data/doc/cdrom.rsd +3 -3
  23. data/doc/event.rsd +178 -179
  24. data/doc/general.rsd +10 -0
  25. data/doc/init.rsd +2 -2
  26. data/doc/joystick.rsd +29 -5
  27. data/doc/mixer.rsd +20 -0
  28. data/doc/rsd.rb +42 -9
  29. data/doc/sdlskk.rsd +7 -7
  30. data/doc/video.rsd +461 -168
  31. data/doc/wm.rsd +2 -2
  32. data/extconf.rb +1 -8
  33. data/lib/rubysdl_aliases.rb +52 -190
  34. data/lib/rubysdl_compatible_ver1.rb +243 -0
  35. data/lib/sdl.rb +58 -92
  36. data/rubysdl.h +59 -68
  37. data/rubysdl_cdrom.c +125 -102
  38. data/{rubysdl_doc.en.rd → rubysdl_doc_old.en.rd} +3 -2
  39. data/rubysdl_event.c +318 -255
  40. data/rubysdl_event_key.c +299 -287
  41. data/rubysdl_image.c +37 -13
  42. data/rubysdl_joystick.c +180 -67
  43. data/rubysdl_kanji.c +61 -75
  44. data/rubysdl_main.c +65 -138
  45. data/rubysdl_mixer.c +339 -214
  46. data/rubysdl_mouse.c +50 -43
  47. data/rubysdl_opengl.c +31 -28
  48. data/rubysdl_pixel.c +17 -28
  49. data/rubysdl_ref.en.html +5658 -0
  50. data/rubysdl_ref.en.rd +6337 -0
  51. data/rubysdl_ref.html +2253 -1964
  52. data/rubysdl_ref.rd +823 -469
  53. data/rubysdl_rwops.c +9 -6
  54. data/rubysdl_sdlskk.c +137 -165
  55. data/rubysdl_sge_video.c +355 -469
  56. data/rubysdl_smpeg.c +189 -190
  57. data/rubysdl_time.c +1 -1
  58. data/rubysdl_ttf.c +147 -215
  59. data/rubysdl_video.c +486 -405
  60. data/rubysdl_wm.c +30 -30
  61. data/sample/aadraw.rb +9 -9
  62. data/sample/alpha.rb +12 -13
  63. data/sample/alphadraw.rb +10 -10
  64. data/sample/bfont.rb +4 -4
  65. data/sample/cdrom.rb +11 -4
  66. data/sample/collision.rb +20 -20
  67. data/sample/cursor.rb +5 -5
  68. data/sample/ellipses.rb +20 -16
  69. data/sample/event2.rb +11 -9
  70. data/sample/font.rb +4 -4
  71. data/sample/fpstimer.rb +3 -3
  72. data/sample/icon.bmp.gz +0 -0
  73. data/sample/icon.png +0 -0
  74. data/sample/joy2.rb +14 -14
  75. data/sample/kanji.rb +7 -7
  76. data/sample/load_from_io.rb +44 -0
  77. data/sample/movesp.rb +13 -12
  78. data/sample/playmod.rb +2 -3
  79. data/sample/plaympeg.rb +8 -8
  80. data/sample/playwave.rb +5 -6
  81. data/sample/sdlskk.rb +11 -11
  82. data/sample/sgetest.rb +14 -12
  83. data/sample/stetris.rb +12 -13
  84. data/sample/testgl.rb +13 -14
  85. data/sample/testsprite.rb +12 -11
  86. data/sample/transformblit.rb +23 -22
  87. metadata +62 -35
  88. data/rubysdl_event2.c +0 -417
data/sample/stetris.rb CHANGED
@@ -117,9 +117,9 @@ end
117
117
 
118
118
  class Level
119
119
  def load_render_data
120
- @image = SDL::Surface.loadBMP("icon.bmp")
121
- @image.setColorKey( SDL::SRCCOLORKEY ,0)
122
- @image = @image.displayFormat
120
+ @image = SDL::Surface.load_bmp("icon.bmp")
121
+ @image.set_color_key( SDL::SRCCOLORKEY ,0)
122
+ @image = @image.display_format
123
123
  @step_x = 32 # todo: image width
124
124
  @step_y = 32 # todo: image height
125
125
  # todo: raise exception is level does not fit to screen!
@@ -139,14 +139,14 @@ class Level
139
139
  x = @offset_x
140
140
  cells.each do |cell|
141
141
  i = (cell == 0) ? 63 : 255
142
- @image.setAlpha(SDL::SRCALPHA,i)
142
+ @image.set_alpha(SDL::SRCALPHA,i)
143
143
  $screen.put(@image,x,y)
144
144
  x += @step_x
145
145
  end
146
146
  end
147
147
  FILL = (20 * 256*256) + (0 * 256) + 10
148
148
  def render_removal(rows)
149
- $screen.fillRect(0,0,640,512,0)
149
+ $screen.fill_rect(0,0,640,512,0)
150
150
  render
151
151
  rows.reverse_each do |row|
152
152
  y = (row * @step_y) + @offset_y
@@ -155,7 +155,7 @@ class Level
155
155
  i = 0
156
156
  x = @offset_x
157
157
  while i < @width
158
- $screen.fillRect(x,y,@step_x,@step_y,FILL)
158
+ $screen.fill_rect(x,y,@step_x,@step_y,FILL)
159
159
  $screen.flip
160
160
  i += 1
161
161
  x += @step_x
@@ -165,7 +165,7 @@ class Level
165
165
  i = 0
166
166
  x = @offset_x + ((@width-1)*@step_x)
167
167
  while i < @width
168
- $screen.fillRect(x,y,@step_x,@step_y,FILL)
168
+ $screen.fill_rect(x,y,@step_x,@step_y,FILL)
169
169
  $screen.flip
170
170
  i += 1
171
171
  x -= @step_x
@@ -177,7 +177,7 @@ class Level
177
177
  end
178
178
 
179
179
  SDL.init( SDL::INIT_VIDEO )
180
- $screen = SDL::setVideoMode(640,512,24,SDL::SWSURFACE)
180
+ $screen = SDL::Screen.open(640,512,24,SDL::SWSURFACE)
181
181
  level = Level.new
182
182
  level.test
183
183
  level.load_render_data
@@ -231,10 +231,10 @@ loop do
231
231
  rotate = false
232
232
 
233
233
  # handle keystrokes
234
- while event = SDL::Event2.poll
234
+ while event = SDL::Event.poll
235
235
  case event
236
- when SDL::Event2::Quit then exit
237
- when SDL::Event2::KeyDown
236
+ when SDL::Event::Quit then exit
237
+ when SDL::Event::KeyDown
238
238
  case event.sym
239
239
  when SDL::Key::ESCAPE then exit
240
240
  when SDL::Key::UP then rotate = true
@@ -268,8 +268,7 @@ loop do
268
268
  end
269
269
 
270
270
  # repaint screen
271
- $screen.fillRect(0,0,640,512,0)
271
+ $screen.fill_rect(0,0,640,512,0)
272
272
  level.render
273
- GC.start # release memory.. otherwise it would grow steady
274
273
  $screen.flip
275
274
  end
data/sample/testgl.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require 'sdl'
2
2
  require 'opengl'
3
3
 
4
+ # initialize SDL and opengl
4
5
  SDL.init SDL::INIT_VIDEO
5
- SDL.setGLAttr SDL::GL_RED_SIZE,5
6
- SDL.setGLAttr SDL::GL_GREEN_SIZE,5
7
- SDL.setGLAttr SDL::GL_BLUE_SIZE,5
8
- SDL.setGLAttr SDL::GL_DEPTH_SIZE,16
9
- SDL.setGLAttr SDL::GL_DOUBLEBUFFER,1
10
- SDL.setVideoMode 640,400,16,SDL::OPENGL
6
+ SDL::GL.set_attr SDL::GL_RED_SIZE,5
7
+ SDL::GL.set_attr SDL::GL_GREEN_SIZE,5
8
+ SDL::GL.set_attr SDL::GL_BLUE_SIZE,5
9
+ SDL::GL.set_attr SDL::GL_DEPTH_SIZE,16
10
+ SDL::GL.set_attr SDL::GL_DOUBLEBUFFER,1
11
+ SDL::Screen.open 640,400,16,SDL::OPENGL
12
+
11
13
  GL::Viewport( 0, 0, 640, 400 );
12
14
  GL::MatrixMode( GL::PROJECTION );
13
15
  GL::LoadIdentity( );
@@ -21,7 +23,6 @@ GL::DepthFunc(GL::LESS);
21
23
 
22
24
  GL::ShadeModel(GL::SMOOTH);
23
25
 
24
- event=SDL::Event.new
25
26
  shadedCube=true
26
27
 
27
28
  color =
@@ -47,16 +48,14 @@ cube =
47
48
 
48
49
  loop do
49
50
 
50
- if event.poll != 0 then
51
- if event.type==SDL::Event::QUIT then
52
- break
53
- end
54
- if event.type==SDL::Event::KEYDOWN then
51
+ while event = SDL::Event2.poll
52
+ case event
53
+ when SDL::Event2::Quit, SDL::Event2::KeyDown
55
54
  exit
56
55
  end
57
56
  end
58
57
 
59
- GL.ClearColor(0.0, 0.0, 0.0, 1.0);
58
+ GL.ClearColor(0.0, 0.0, 0.0, 1.0);
60
59
  GL.Clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
61
60
 
62
61
 
@@ -161,6 +160,6 @@ loop do
161
160
  GL::MatrixMode(GL::MODELVIEW);
162
161
  GL::Rotate(5.0, 1.0, 1.0, 1.0);
163
162
 
164
- SDL.GLSwapBuffers
163
+ SDL::GL.swap_buffers
165
164
 
166
165
  end
data/sample/testsprite.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'sdl'
2
2
 
3
- SDL.init( SDL::INIT_VIDEO )
4
- screen = SDL::setVideoMode(640,480,16,SDL::SWSURFACE)
5
- SDL::WM::setCaption('testsprite.rb','testsprite.rb icon')
6
- image = SDL::Surface.loadBMP("icon.bmp")
7
- image.setColorKey( SDL::SRCCOLORKEY ,0)
8
- $image = image.displayFormat
3
+ SDL.init(SDL::INIT_VIDEO)
4
+ screen = SDL::Screen.open(640, 480, 16, SDL::SWSURFACE)
5
+ SDL::WM::set_caption('testsprite.rb','testsprite.rb icon')
6
+ image = SDL::Surface.load_bmp("icon.bmp")
7
+ image.set_color_key(SDL::SRCCOLORKEY ,0)
8
+ $image = image.display_format
9
9
 
10
10
  class Sprite
11
11
  def initialize
@@ -38,7 +38,7 @@ class Sprite
38
38
  end
39
39
 
40
40
  def draw(screen)
41
- SDL.blitSurface($image,0,0,32,32,screen,@x,@y)
41
+ SDL::Surface.blit($image, 0, 0, 32, 32, screen, @x, @y)
42
42
  end
43
43
 
44
44
  end
@@ -50,19 +50,20 @@ end
50
50
 
51
51
 
52
52
  while true
53
- while event = SDL::Event2.poll
53
+ while event = SDL::Event.poll
54
54
  case event
55
- when SDL::Event2::KeyDown, SDL::Event2::Quit
55
+ when SDL::Event::KeyDown, SDL::Event::Quit
56
56
  exit
57
57
  end
58
58
  end
59
- screen.fillRect(0,0,640,480,0)
59
+ screen.fill_rect(0, 0, 640, 480, 0)
60
60
 
61
61
  sprites.each {|i|
62
62
  i.move
63
63
  i.draw(screen)
64
64
  }
65
- screen.updateRect(0,0,0,0)
65
+
66
+ screen.update_rect(0, 0, 0, 0)
66
67
  end
67
68
 
68
69
 
@@ -1,41 +1,42 @@
1
1
  require 'sdl'
2
2
 
3
3
  SDL.init( SDL::INIT_VIDEO )
4
- screen = SDL::setVideoMode(640,480,16,SDL::SWSURFACE)
4
+ screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
5
5
 
6
- image = SDL::Surface.loadBMP("icon.bmp")
7
- image.setColorKey( SDL::SRCCOLORKEY , image[0,0])
8
- image = image.displayFormat
6
+ image = SDL::Surface.load_bmp("icon.bmp")
7
+ image.set_color_key( SDL::SRCCOLORKEY , image[0,0])
8
+ image = image.display_format
9
9
 
10
- aimage = SDL::Surface.loadBMP("icon.bmp")
11
- aimage.setColorKey( SDL::SRCCOLORKEY, aimage[0,0] )
12
- aimage.setAlpha(SDL::SRCALPHA, 128 )
13
- aimage = aimage.displayFormat
10
+ aimage = SDL::Surface.load_bmp("icon.bmp")
11
+ aimage.set_color_key( SDL::SRCCOLORKEY, aimage[0,0] )
12
+ aimage.set_alpha(SDL::SRCALPHA, 128 )
13
+ aimage = aimage.display_format
14
14
 
15
15
  angle = 0
16
16
 
17
- while true
17
+ loop do
18
18
 
19
- event = SDL::Event2.poll
20
- case event
21
- when SDL::Event2::Quit
22
- exit
23
- when SDL::Event2::KeyDown
24
- exit if event.sym == SDL::Key::ESCAPE
19
+ while event = SDL::Event.poll
20
+ case event
21
+ when SDL::Event::Quit
22
+ exit
23
+ when SDL::Event::KeyDown
24
+ exit if event.sym == SDL::Key::ESCAPE
25
+ end
25
26
  end
26
27
 
27
28
  angle += 2
28
29
 
29
- screen.fillRect(0,0,640,480,[100,100,100])
30
+ screen.fill_rect(0,0,640,480,[100,100,100])
30
31
 
31
- SDL.transform(image,screen,angle,1,1,image.w/2,image.h/2,100,100,0 )
32
- SDL.transformBlit(image,screen,angle,1,1,image.w/2,image.h/2,200,200,0 )
32
+ SDL::Surface.transform_draw(image,screen,angle,1,1,image.w/2,image.h/2,100,100,0 )
33
+ SDL::Surface.transform_blit(image,screen,angle,1,1,image.w/2,image.h/2,200,200,0 )
33
34
 
34
- SDL.transform(image,screen,angle,1,1,0,0,300,300,0 )
35
- SDL.transformBlit(image,screen,angle,1,1,0,0,400,200,0 )
35
+ SDL::Surface.transform_draw(image,screen,angle,1,1,0,0,300,300,0 )
36
+ SDL::Surface.transform_blit(image,screen,angle,1,1,0,0,400,200,0 )
36
37
 
37
- SDL.transformBlit(aimage,screen,angle,1,1,0,0,100,400,0 )
38
+ SDL::Surface.transform_blit(aimage,screen,angle,1,1,0,0,100,400,0 )
38
39
 
39
- screen.updateRect(0,0,0,0)
40
+ screen.update_rect(0,0,0,0)
40
41
 
41
42
  end
metadata CHANGED
@@ -1,33 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rubysdl
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.3.1
7
- date: 2007-08-27 00:00:00 +09:00
8
- summary: The simple ruby extension library to use SDL
9
- require_paths:
10
- - lib
11
- email: ohai@kmc.gr.jp
12
- homepage: http://www.kmc.gr.jp/~ohai/
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "2.0"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ohbayashi Ippei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-20 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ohai@kmc.gr.jp
18
+ executables: []
19
+
20
+ extensions:
21
+ - extconf.rb
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - MANIFEST
33
26
  - README.ja
@@ -39,12 +32,15 @@ files:
39
32
  - extconf.rb
40
33
  - lib/rubysdl_aliases.rb
41
34
  - lib/sdl.rb
35
+ - lib/rubysdl_compatible_ver1.rb
42
36
  - rubysdl.h
43
37
  - rubysdl_const_list.txt
44
38
  - rubysdl_doc_old.rd
45
39
  - rubysdl_ref.rd
46
40
  - rubysdl_ref.html
47
- - rubysdl_doc.en.rd
41
+ - rubysdl_ref.en.rd
42
+ - rubysdl_ref.en.html
43
+ - rubysdl_doc_old.en.rd
48
44
  - rubysdl_event.c
49
45
  - rubysdl_event_key.c
50
46
  - rubysdl_main.c
@@ -60,7 +56,6 @@ files:
60
56
  - rubysdl_image.c
61
57
  - rubysdl_opengl.c
62
58
  - rubysdl_pixel.c
63
- - rubysdl_event2.c
64
59
  - rubysdl_smpeg.c
65
60
  - rubysdl_sdlskk.c
66
61
  - rubysdl_kanji.c
@@ -95,6 +90,9 @@ files:
95
90
  - sample/font.bmp
96
91
  - sample/kanji.rb
97
92
  - sample/sample.ttf
93
+ - sample/load_from_io.rb
94
+ - sample/icon.png
95
+ - sample/icon.bmp.gz
98
96
  - doc/Makefile
99
97
  - doc/rsd.rb
100
98
  - doc/cdrom.rsd
@@ -110,17 +108,46 @@ files:
110
108
  - doc/time.rsd
111
109
  - doc/video.rsd
112
110
  - doc/wm.rsd
113
- test_files: []
114
-
111
+ - doc-en/Makefile
112
+ - doc-en/cdrom.rsd
113
+ - doc-en/collision.rsd
114
+ - doc-en/event.rsd
115
+ - doc-en/font.rsd
116
+ - doc-en/general.rsd
117
+ - doc-en/init.rsd
118
+ - doc-en/joystick.rsd
119
+ - doc-en/mixer.rsd
120
+ - doc-en/mpeg.rsd
121
+ - doc-en/opengl.rsd
122
+ - doc-en/sdlskk.rsd
123
+ - doc-en/time.rsd
124
+ - doc-en/video.rsd
125
+ - doc-en/wm.rsd
126
+ has_rdoc: false
127
+ homepage: http://www.kmc.gr.jp/~ohai/
128
+ post_install_message:
115
129
  rdoc_options: []
116
130
 
117
- extra_rdoc_files: []
118
-
119
- executables: []
120
-
121
- extensions:
122
- - extconf.rb
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: "0"
138
+ version:
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: "0"
144
+ version:
123
145
  requirements: []
124
146
 
125
- dependencies: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.0.1
149
+ signing_key:
150
+ specification_version: 2
151
+ summary: The simple ruby extension library to use SDL
152
+ test_files: []
126
153
 
data/rubysdl_event2.c DELETED
@@ -1,417 +0,0 @@
1
- /*
2
- Ruby/SDL Ruby extension library for SDL
3
-
4
- Copyright (C) 2001-2007 Ohbayashi Ippei
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
- #ifdef DEF_EVENT2
22
-
23
- #include "rubysdl.h"
24
-
25
- typedef VALUE (*createEventObjFunc)(SDL_Event *);
26
- static createEventObjFunc createEventObj[SDL_NUMEVENTS];
27
-
28
- static VALUE createNoEvent(SDL_Event *event)
29
- {
30
- return Qnil;
31
- }
32
-
33
- static VALUE createActiveEvent(SDL_Event *event)
34
- {
35
- VALUE obj=rb_obj_alloc(cActiveEvent);
36
- rb_iv_set(obj,"@gain",BOOL(event->active.gain));
37
- rb_iv_set(obj,"@state",INT2FIX(event->active.state));
38
- return obj;
39
- }
40
-
41
- static VALUE createKeyEvent(VALUE obj,SDL_Event *event)
42
- {
43
- rb_iv_set(obj,"@press",BOOL(event->key.state==SDL_PRESSED));
44
- rb_iv_set(obj,"@sym",INT2FIX(event->key.keysym.sym));
45
- rb_iv_set(obj,"@mod",UINT2NUM(event->key.keysym.mod));
46
- rb_iv_set(obj,"@unicode",UINT2NUM(event->key.keysym.unicode));
47
- return obj;
48
- }
49
-
50
- static VALUE createKeyDownEvent(SDL_Event *event)
51
- {
52
- VALUE obj=rb_obj_alloc(cKeyDownEvent);
53
- return createKeyEvent(obj,event);
54
- }
55
-
56
- static VALUE createKeyUpEvent(SDL_Event *event)
57
- {
58
- VALUE obj=rb_obj_alloc(cKeyUpEvent);
59
- return createKeyEvent(obj,event);
60
- }
61
-
62
- static VALUE createMouseMotionEvent(SDL_Event *event)
63
- {
64
- VALUE obj=rb_obj_alloc(cMouseMotionEvent);
65
- rb_iv_set(obj,"@state",INT2FIX(event->motion.state));
66
- rb_iv_set(obj,"@x",INT2FIX(event->motion.x));
67
- rb_iv_set(obj,"@y",INT2FIX(event->motion.y));
68
- rb_iv_set(obj,"@xrel",INT2FIX(event->motion.xrel));
69
- rb_iv_set(obj,"@yrel",INT2FIX(event->motion.yrel));
70
- return obj;
71
- }
72
-
73
- static VALUE createMouseButtonEvent(VALUE obj,SDL_Event *event)
74
- {
75
- rb_iv_set(obj,"@button",INT2FIX(event->button.button));
76
- rb_iv_set(obj,"@press",BOOL(event->button.state==SDL_PRESSED));
77
- rb_iv_set(obj,"@x",INT2FIX(event->button.x));
78
- rb_iv_set(obj,"@y",INT2FIX(event->button.y));
79
- return obj;
80
- }
81
-
82
- static VALUE createMouseButtonDownEvent(SDL_Event *event)
83
- {
84
- VALUE obj=rb_obj_alloc(cMouseButtonDownEvent);
85
- return createMouseButtonEvent(obj,event);
86
- }
87
-
88
- static VALUE createMouseButtonUpEvent(SDL_Event *event)
89
- {
90
- VALUE obj=rb_obj_alloc(cMouseButtonUpEvent);
91
- return createMouseButtonEvent(obj,event);
92
- }
93
-
94
- static VALUE createJoyAxisEvent(SDL_Event *event)
95
- {
96
- VALUE obj=rb_obj_alloc(cJoyAxisEvent);
97
- rb_iv_set(obj,"@which",INT2FIX(event->jaxis.which));
98
- rb_iv_set(obj,"@axis",INT2FIX(event->jaxis.axis));
99
- rb_iv_set(obj,"@value",INT2FIX(event->jaxis.value));
100
- return obj;
101
- }
102
-
103
- static VALUE createJoyBallEvent(SDL_Event *event)
104
- {
105
- VALUE obj=rb_obj_alloc(cJoyBallEvent);
106
- rb_iv_set(obj,"@which",INT2FIX(event->jball.which));
107
- rb_iv_set(obj,"@ball",INT2FIX(event->jball.ball));
108
- rb_iv_set(obj,"@xrel",INT2FIX(event->jball.xrel));
109
- rb_iv_set(obj,"@yrel",INT2FIX(event->jball.yrel));
110
- return obj;
111
- }
112
-
113
- static VALUE createJoyHatEvent(SDL_Event *event)
114
- {
115
- VALUE obj=rb_obj_alloc(cJoyHatEvent);
116
- rb_iv_set(obj,"@which",INT2FIX(event->jhat.which));
117
- rb_iv_set(obj,"@hat",INT2FIX(event->jhat.hat));
118
- rb_iv_set(obj,"@value",INT2FIX(event->jhat.value));
119
- return obj;
120
- }
121
-
122
- static VALUE createJoyButtonEvent(VALUE obj,SDL_Event *event)
123
- {
124
- rb_iv_set(obj,"@which",INT2FIX(event->jbutton.which));
125
- rb_iv_set(obj,"@button",INT2FIX(event->jbutton.button));
126
- rb_iv_set(obj,"@press",BOOL(event->jbutton.state==SDL_PRESSED));
127
- return obj;
128
- }
129
- static VALUE createJoyButtonUpEvent(SDL_Event *event)
130
- {
131
- VALUE obj=rb_obj_alloc(cJoyButtonUpEvent);
132
- return createJoyButtonEvent(obj,event);
133
- }
134
-
135
- static VALUE createJoyButtonDownEvent(SDL_Event *event)
136
- {
137
- VALUE obj=rb_obj_alloc(cJoyButtonDownEvent);
138
- return createJoyButtonEvent(obj,event);
139
- }
140
-
141
- static VALUE createQuitEvent(SDL_Event *event)
142
- {
143
- VALUE obj=rb_obj_alloc(cQuitEvent);
144
- return obj;
145
- }
146
-
147
- static VALUE createSysWMEvent(SDL_Event *event)
148
- {
149
- VALUE obj=rb_obj_alloc(cSysWMEvent);
150
- return obj;
151
- }
152
-
153
- static VALUE createVideoResizeEvent(SDL_Event *event)
154
- {
155
- VALUE obj=rb_obj_alloc(cVideoResizeEvent);
156
- rb_iv_set(obj,"@w",INT2FIX(event->resize.w));
157
- rb_iv_set(obj,"@h",INT2FIX(event->resize.h));
158
- return obj;
159
- }
160
-
161
- static VALUE createVideoExposeEvent(SDL_Event *event)
162
- {
163
- return rb_obj_alloc(cVideoExposeEvent);
164
- }
165
-
166
- static VALUE sdl_event2_poll(VALUE class)
167
- {
168
- SDL_Event event;
169
- if( SDL_PollEvent(&event)==1)
170
- return createEventObj[event.type](&event);
171
- else
172
- return Qnil;
173
- }
174
- static VALUE sdl_event2_wait(VALUE class)
175
- {
176
- SDL_Event event;
177
- if( SDL_WaitEvent(&event)==1)
178
- return createEventObj[event.type](&event);
179
- else
180
- rb_raise(eSDLError,"Event handling error");
181
- }
182
- static VALUE sdl_event2_pump(VALUE class)
183
- {
184
- SDL_PumpEvents();
185
- return Qnil;
186
- }
187
-
188
- static VALUE sdl_event2_new(VALUE class)
189
- {
190
- return rb_obj_alloc(class);
191
- }
192
-
193
- static VALUE sdl_event2_push(VALUE class,VALUE event)
194
- {
195
- SDL_Event e;
196
- VALUE eventClass=CLASS_OF(event);
197
- if(eventClass==cActiveEvent){
198
- e.type=SDL_ACTIVEEVENT;
199
- e.active.gain=rb_iv_get(event,"@gain");
200
- e.active.state=NUM2INT(rb_iv_get(event,"@state"));
201
- }else if(eventClass==cKeyDownEvent){
202
- e.type=SDL_KEYDOWN;
203
- e.key.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
204
- e.key.keysym.sym=NUM2INT(rb_iv_get(event,"@sym"));
205
- e.key.keysym.mod=NUM2UINT(rb_iv_get(event,"@mod"));
206
- e.key.keysym.unicode = NUM2UINT( rb_iv_get(event,"@unicode") );
207
- }else if(eventClass==cKeyUpEvent){
208
- e.type=SDL_KEYUP;
209
- e.key.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
210
- e.key.keysym.sym=NUM2INT(rb_iv_get(event,"@sym"));
211
- e.key.keysym.mod=NUM2UINT(rb_iv_get(event,"@mod"));
212
- e.key.keysym.unicode = NUM2UINT( rb_iv_get(event,"@unicode") );
213
- }else if(eventClass==cMouseMotionEvent){
214
- e.type=SDL_MOUSEMOTION;
215
- e.motion.state=NUM2INT(rb_iv_get(event,"@state"));
216
- e.motion.x=NUM2INT(rb_iv_get(event,"@x"));
217
- e.motion.y=NUM2INT(rb_iv_get(event,"@y"));
218
- e.motion.xrel=NUM2INT(rb_iv_get(event,"@xrel"));
219
- e.motion.yrel=NUM2INT(rb_iv_get(event,"@yrel"));
220
- }else if(eventClass==cMouseButtonDownEvent){
221
- e.type=SDL_MOUSEBUTTONDOWN;
222
- e.button.button=NUM2INT(rb_iv_get(event,"@button"));
223
- e.button.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
224
- e.button.x=NUM2INT(rb_iv_get(event,"@x"));
225
- e.button.y=NUM2INT(rb_iv_get(event,"@y"));
226
- }else if(eventClass==cMouseButtonUpEvent){
227
- e.type=SDL_MOUSEBUTTONUP;
228
- e.button.button=NUM2INT(rb_iv_get(event,"@button"));
229
- e.button.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
230
- e.button.x=NUM2INT(rb_iv_get(event,"@x"));
231
- e.button.y=NUM2INT(rb_iv_get(event,"@y"));\
232
- }else if(eventClass==cJoyAxisEvent){
233
- e.type=SDL_JOYAXISMOTION;
234
- e.jaxis.which=NUM2INT(rb_iv_get(event,"@which"));
235
- e.jaxis.axis=NUM2INT(rb_iv_get(event,"@axis"));
236
- e.jaxis.value=NUM2INT(rb_iv_get(event,"@value"));
237
- }else if(eventClass==cJoyBallEvent){
238
- e.type=SDL_JOYBALLMOTION;
239
- e.jball.which=NUM2INT(rb_iv_get(event,"@which"));
240
- e.jball.ball=NUM2INT(rb_iv_get(event,"@ball"));
241
- e.jball.xrel=NUM2INT(rb_iv_get(event,"@xrel"));
242
- e.jball.yrel=NUM2INT(rb_iv_get(event,"@yrel"));
243
- }else if(eventClass==cJoyHatEvent){
244
- e.type=SDL_JOYHATMOTION;
245
- e.jhat.which=NUM2INT(rb_iv_get(event,"@which"));
246
- e.jhat.hat=NUM2INT(rb_iv_get(event,"@hat"));
247
- e.jhat.value=NUM2INT(rb_iv_get(event,"@value"));
248
- }else if(eventClass==cJoyButtonUpEvent){
249
- e.type=SDL_JOYBUTTONUP;
250
- e.jbutton.which=NUM2INT(rb_iv_get(event,"@which"));
251
- e.jbutton.button=NUM2INT(rb_iv_get(event,"@button"));
252
- e.jbutton.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
253
- }else if(eventClass==cJoyButtonDownEvent){
254
- e.type=SDL_JOYBUTTONDOWN;
255
- e.jbutton.which=NUM2INT(rb_iv_get(event,"@which"));
256
- e.jbutton.button=NUM2INT(rb_iv_get(event,"@button"));
257
- e.jbutton.state=(rb_iv_get(event,"@press"))?SDL_PRESSED:SDL_RELEASED;
258
- }else if(eventClass==cQuitEvent){
259
- e.type=SDL_QUIT;
260
- }else if(eventClass==cSysWMEvent){
261
- e.type=SDL_SYSWMEVENT;
262
- }else if(eventClass==cVideoResizeEvent){
263
- e.type=SDL_VIDEORESIZE;
264
- e.resize.w=NUM2INT(rb_iv_get(event,"@w"));
265
- e.resize.h=NUM2INT(rb_iv_get(event,"@h"));
266
- }else if(eventClass==cVideoExposeEvent){
267
- e.type=SDL_VIDEOEXPOSE;
268
- }else {
269
- rb_raise(eSDLError,"This object couldn't be pushed");
270
- }
271
- if(SDL_PushEvent(&e)==-1)
272
- rb_raise(eSDLError,"the event couldn't be pushed");
273
- return Qnil;
274
- }
275
- static VALUE sdl_event2_getAppState(VALUE class)
276
- {
277
- return INT2FIX(SDL_GetAppState());
278
- }
279
-
280
- static VALUE sdl_event2_enableUNICODE(VALUE class)
281
- {
282
- SDL_EnableUNICODE(1);
283
- return Qnil;
284
- }
285
- static VALUE sdl_event2_disableUNICODE(VALUE class)
286
- {
287
- SDL_EnableUNICODE(0);
288
- return Qnil;
289
- }
290
- static VALUE sdl_event2_is_enableUNICODE(VALUE class)
291
- {
292
- return BOOL(SDL_EnableUNICODE(-1));
293
- }
294
-
295
- void init_event2(void)
296
- {
297
- int i;
298
-
299
- cEvent2=rb_define_class_under(mSDL,"Event2",rb_cObject);
300
- rb_define_singleton_method(cEvent2,"poll",sdl_event2_poll,0);
301
- rb_define_singleton_method(cEvent2,"wait",sdl_event2_wait,0);
302
- rb_define_singleton_method(cEvent2, "pump",sdl_event2_pump, 0);
303
- /*rb_define_attr(cEvent2,"type",1,0);*/
304
- rb_define_singleton_method(cEvent2,"new",sdl_event2_new,0);
305
- rb_define_singleton_method(cEvent2,"push",sdl_event2_push,1);
306
- rb_define_singleton_method(cEvent2,"appState",sdl_event2_getAppState,0);
307
- rb_define_singleton_method(cEvent2,"enableUNICODE",sdl_event2_enableUNICODE,0);
308
- rb_define_singleton_method(cEvent2,"disableUNICODE",sdl_event2_disableUNICODE,0);
309
- rb_define_singleton_method(cEvent2,"enableUNICODE?",sdl_event2_is_enableUNICODE,0);
310
- cActiveEvent=rb_define_class_under(cEvent2,"Active",cEvent2);
311
- rb_define_attr(cActiveEvent,"gain",1,1);
312
- rb_define_attr(cActiveEvent,"state",1,1);
313
-
314
- cKeyDownEvent=rb_define_class_under(cEvent2,"KeyDown",cEvent2);
315
- rb_define_attr(cKeyDownEvent,"press",1,1);
316
- rb_define_attr(cKeyDownEvent,"sym",1,1);
317
- rb_define_attr(cKeyDownEvent,"mod",1,1);
318
- rb_define_attr(cKeyDownEvent,"unicode",1,1);
319
-
320
- cKeyUpEvent=rb_define_class_under(cEvent2,"KeyUp",cEvent2);
321
- rb_define_attr(cKeyUpEvent,"press",1,1);
322
- rb_define_attr(cKeyUpEvent,"sym",1,1);
323
- rb_define_attr(cKeyUpEvent,"mod",1,1);
324
- rb_define_attr(cKeyUpEvent,"unicode",1,1);
325
-
326
- cMouseMotionEvent=rb_define_class_under(cEvent2,"MouseMotion",cEvent2);
327
- rb_define_attr(cMouseMotionEvent,"state",1,1);
328
- rb_define_attr(cMouseMotionEvent,"x",1,1);
329
- rb_define_attr(cMouseMotionEvent,"y",1,1);
330
- rb_define_attr(cMouseMotionEvent,"xrel",1,1);
331
- rb_define_attr(cMouseMotionEvent,"yrel",1,1);
332
-
333
- cMouseButtonDownEvent=rb_define_class_under(cEvent2,"MouseButtonDown",cEvent2);
334
- rb_define_attr(cMouseButtonDownEvent,"button",1,1);
335
- rb_define_attr(cMouseButtonDownEvent,"press",1,1);
336
- rb_define_attr(cMouseButtonDownEvent,"x",1,1);
337
- rb_define_attr(cMouseButtonDownEvent,"y",1,1);
338
-
339
- cMouseButtonUpEvent=rb_define_class_under(cEvent2,"MouseButtonUp",cEvent2);
340
- rb_define_attr(cMouseButtonUpEvent,"button",1,1);
341
- rb_define_attr(cMouseButtonUpEvent,"press",1,1);
342
- rb_define_attr(cMouseButtonUpEvent,"x",1,1);
343
- rb_define_attr(cMouseButtonUpEvent,"y",1,1);
344
-
345
- cJoyAxisEvent=rb_define_class_under(cEvent2,"JoyAxis",cEvent2);
346
- rb_define_attr(cJoyAxisEvent,"which",1,1);
347
- rb_define_attr(cJoyAxisEvent,"axis",1,1);
348
- rb_define_attr(cJoyAxisEvent,"value",1,1);
349
-
350
- cJoyBallEvent=rb_define_class_under(cEvent2,"JoyBall",cEvent2);
351
- rb_define_attr(cJoyBallEvent,"which",1,1);
352
- rb_define_attr(cJoyBallEvent,"ball",1,1);
353
- rb_define_attr(cJoyBallEvent,"xrel",1,1);
354
- rb_define_attr(cJoyBallEvent,"yrel",1,1);
355
-
356
- cJoyHatEvent=rb_define_class_under(cEvent2,"JoyHat",cEvent2);
357
- rb_define_attr(cJoyHatEvent,"which",1,1);
358
- rb_define_attr(cJoyHatEvent,"hat",1,1);
359
- rb_define_attr(cJoyHatEvent,"value",1,1);
360
-
361
- cJoyButtonUpEvent=rb_define_class_under(cEvent2,"JoyButtonUp",cEvent2);
362
- rb_define_attr(cJoyButtonUpEvent,"which",1,1);
363
- rb_define_attr(cJoyButtonUpEvent,"button",1,1);
364
- rb_define_attr(cJoyButtonUpEvent,"press",1,1);
365
-
366
- cJoyButtonDownEvent=rb_define_class_under(cEvent2,"JoyButtonDown",cEvent2);
367
- rb_define_attr(cJoyButtonDownEvent,"which",1,1);
368
- rb_define_attr(cJoyButtonDownEvent,"button",1,1);
369
- rb_define_attr(cJoyButtonDownEvent,"press",1,1);
370
-
371
- cQuitEvent=rb_define_class_under(cEvent2,"Quit",cEvent2);
372
-
373
- cSysWMEvent=rb_define_class_under(cEvent2,"SysWM",cEvent2);
374
-
375
- cVideoResizeEvent=rb_define_class_under(cEvent2,"VideoResize",cEvent2);
376
- rb_define_attr(cVideoResizeEvent,"w",1,1);
377
- rb_define_attr(cVideoResizeEvent,"h",1,1);
378
-
379
- cVideoExposeEvent=rb_define_class_under(cEvent2,"VideoExpose",cEvent2);
380
-
381
- for(i=0;i<SDL_NUMEVENTS;++i)
382
- createEventObj[i]=createNoEvent;
383
- createEventObj[SDL_ACTIVEEVENT]=createActiveEvent;
384
- createEventObj[SDL_KEYDOWN]=createKeyDownEvent;
385
- createEventObj[SDL_KEYUP]=createKeyUpEvent;
386
- createEventObj[SDL_MOUSEMOTION]=createMouseMotionEvent;
387
- createEventObj[SDL_MOUSEBUTTONDOWN]=createMouseButtonDownEvent;
388
- createEventObj[SDL_MOUSEBUTTONUP]=createMouseButtonUpEvent;
389
- createEventObj[SDL_JOYAXISMOTION]=createJoyAxisEvent;
390
- createEventObj[SDL_JOYBALLMOTION]=createJoyBallEvent;
391
- createEventObj[SDL_JOYHATMOTION]=createJoyHatEvent;
392
- createEventObj[SDL_JOYBUTTONDOWN]=createJoyButtonDownEvent;
393
- createEventObj[SDL_JOYBUTTONUP]=createJoyButtonUpEvent;
394
- createEventObj[SDL_QUIT]=createQuitEvent;
395
- createEventObj[SDL_SYSWMEVENT]=createSysWMEvent;
396
- createEventObj[SDL_VIDEORESIZE]=createVideoResizeEvent;
397
- createEventObj[SDL_VIDEOEXPOSE]=createVideoExposeEvent;
398
-
399
- }
400
- /*
401
- Active;
402
- KeyDown;
403
- KeyUp;
404
- MouseMotion;
405
- MouseButtonDown;
406
- MouseButtonUp;
407
- JoyAxis;
408
- JoyBall;
409
- JoyHat;
410
- JoyButtonUp;
411
- JoyButtonDown;
412
- Quit;
413
- SysWM;
414
- VideoResize;
415
- */
416
-
417
- #endif /* DEF_EVENT2 */