ruby-sdl-ffi 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,206 @@
1
+ ------------------------------------------------------------
2
+ Author: John Croisant <jacius@gmail.com>
3
+ Date: Sun Aug 8 00:03:34 2010 -0500
4
+
5
+ Ruby-SDL-FFI 0.3 released.
6
+
7
+ ------------------------------------------------------------
8
+ Author: John Croisant <jacius@gmail.com>
9
+ Date: Sat Aug 7 23:49:19 2010 -0500
10
+
11
+ Updated copyright on files modified in 2010.
12
+
13
+ M README.rdoc
14
+ M lib/ruby-sdl-ffi.rb
15
+ M lib/ruby-sdl-ffi/sdl.rb
16
+ M lib/ruby-sdl-ffi/sdl/video.rb
17
+
18
+ ------------------------------------------------------------
19
+ Author: John Croisant <jacius@gmail.com>
20
+ Date: Sat Aug 7 23:19:44 2010 -0500
21
+
22
+ Fixed examples to use '#!/usr/bin/env ruby'.
23
+
24
+ '#!/bin/env ruby' doesn't work on Mac.
25
+
26
+ Also fixed a NameError in load_music.rb, due to FFI API changes.
27
+
28
+ M examples/load_image.rb
29
+ M examples/load_music.rb
30
+
31
+ ------------------------------------------------------------
32
+ Author: John Croisant <jacius@gmail.com>
33
+ Date: Sat Aug 7 23:13:40 2010 -0500
34
+
35
+ Updated NEWS.rdoc, README.rdoc, and ruby-sdl-ffi.gemspec for version 0.3.
36
+
37
+ M NEWS.rdoc
38
+ M README.rdoc
39
+ M ruby-sdl-ffi.gemspec
40
+
41
+ ------------------------------------------------------------
42
+ Author: John Croisant <jacius@gmail.com>
43
+ Date: Sat Aug 7 23:11:40 2010 -0500
44
+
45
+ Improved how RUBYSDLFFI_PATH and SDL_PATHS are processed.
46
+
47
+ M lib/ruby-sdl-ffi/sdl.rb
48
+
49
+ ------------------------------------------------------------
50
+ Author: John Croisant <jacius@gmail.com>
51
+ Date: Fri Aug 6 04:07:07 2010 -0500
52
+
53
+ Added SDL.set_app_name (and SDL::Mac.set_app_name).
54
+
55
+ M lib/ruby-sdl-ffi/sdl/mac.rb
56
+ M lib/ruby-sdl-ffi/sdl/video.rb
57
+
58
+ ------------------------------------------------------------
59
+ Author: John Croisant <jacius@gmail.com>
60
+ Date: Fri Aug 6 01:35:14 2010 -0500
61
+
62
+ Removed unused Mac code and nibs.
63
+
64
+ D lib/ruby-sdl-ffi/sdl/EmptyMacMenu.nib/designable.nib
65
+ D lib/ruby-sdl-ffi/sdl/EmptyMacMenu.nib/keyedobjects.nib
66
+ D lib/ruby-sdl-ffi/sdl/MacMenu.nib/designable.nib
67
+ D lib/ruby-sdl-ffi/sdl/MacMenu.nib/keyedobjects.nib
68
+ D lib/ruby-sdl-ffi/sdl/SparseMacMenu.nib/designable.nib
69
+ D lib/ruby-sdl-ffi/sdl/SparseMacMenu.nib/keyedobjects.nib
70
+ M lib/ruby-sdl-ffi/sdl/mac.rb
71
+ M lib/ruby-sdl-ffi/sdl/video.rb
72
+
73
+ ------------------------------------------------------------
74
+ Author: John Croisant <jacius@gmail.com>
75
+ Date: Tue Aug 3 22:53:14 2010 -0500
76
+
77
+ Extract paths from ENV["RUBYSDLFFI_PATH"] if present.
78
+
79
+ RUBYSDLFFI_PATH should be a colon (on *nix/Mac) or semicolon
80
+ (Windows) separated list of paths to search for SDL libraries.
81
+
82
+ (Alternative to setting the SDL_PATHS constant in Ruby.)
83
+
84
+ M lib/ruby-sdl-ffi/sdl.rb
85
+
86
+ ------------------------------------------------------------
87
+ Author: John Croisant <jacius@gmail.com>
88
+ Date: Sat Jul 10 22:53:30 2010 -0500
89
+
90
+ More progress on Mac support.
91
+
92
+ M lib/ruby-sdl-ffi/sdl/mac.rb
93
+ M lib/ruby-sdl-ffi/sdl/video.rb
94
+
95
+ ------------------------------------------------------------
96
+ Author: John Croisant <jacius@gmail.com>
97
+ Date: Fri Jul 9 03:16:12 2010 -0500
98
+
99
+ More object-oriented style for Mac ObjC/Cocoa bindings.
100
+
101
+ M lib/ruby-sdl-ffi/sdl/mac.rb
102
+
103
+ ------------------------------------------------------------
104
+ Author: John Croisant <jacius@gmail.com>
105
+ Date: Thu Jul 8 05:03:35 2010 -0500
106
+
107
+ WIP experimental mac menu support
108
+
109
+ A lib/ruby-sdl-ffi/sdl/EmptyMacMenu.nib/designable.nib
110
+ A lib/ruby-sdl-ffi/sdl/EmptyMacMenu.nib/keyedobjects.nib
111
+ A lib/ruby-sdl-ffi/sdl/MacMenu.nib/designable.nib
112
+ A lib/ruby-sdl-ffi/sdl/MacMenu.nib/keyedobjects.nib
113
+ A lib/ruby-sdl-ffi/sdl/SparseMacMenu.nib/designable.nib
114
+ A lib/ruby-sdl-ffi/sdl/SparseMacMenu.nib/keyedobjects.nib
115
+ M lib/ruby-sdl-ffi/sdl/mac.rb
116
+ M lib/ruby-sdl-ffi/sdl/video.rb
117
+
118
+ ------------------------------------------------------------
119
+ Author: John Croisant <jacius@gmail.com>
120
+ Date: Fri Jul 2 23:10:58 2010 -0500
121
+
122
+ Disable Mac magic if using rsdl or ENV["RUBYSDLFFI_NOCOCOA"] is true.
123
+
124
+ M lib/ruby-sdl-ffi/sdl/mac.rb
125
+ M lib/ruby-sdl-ffi/sdl/video.rb
126
+
127
+ ------------------------------------------------------------
128
+ Author: John Croisant <jacius@gmail.com>
129
+ Date: Wed Jun 30 18:39:16 2010 -0500
130
+
131
+ Improved integration with the Mac window manager.
132
+
133
+ The app now gets an application menu and dock icon, and the
134
+ SDL window can gain focus and have a title.
135
+
136
+ M lib/ruby-sdl-ffi/sdl/mac.rb
137
+ M lib/ruby-sdl-ffi/sdl/video.rb
138
+
139
+ ------------------------------------------------------------
140
+ Author: John Croisant <jacius@gmail.com>
141
+ Date: Tue Jun 29 03:45:58 2010 -0500
142
+
143
+ Preliminary support for Mac without rsdl.
144
+
145
+ This allows the normal ruby interpreter to create a window on
146
+ Mac OS X. No special interpreter (i.e. rsdl) is needed.
147
+ However, some SDL functions have memory leaks, so we should wrap
148
+ those functions in NS{Push,Pop}AutoreleasePool.
149
+
150
+ Eternal thanks to erisdiscord for pointing the way!
151
+
152
+ M lib/ruby-sdl-ffi/sdl.rb
153
+ A lib/ruby-sdl-ffi/sdl/mac.rb
154
+
155
+ ------------------------------------------------------------
156
+ Author: John Croisant <jacius@gmail.com>
157
+ Date: Fri Jun 4 18:17:54 2010 -0500
158
+
159
+ Fixed SDL.GL_GetAttribute returning FFI::Buffer instead of integer.
160
+
161
+ M lib/ruby-sdl-ffi/sdl/video.rb
162
+
163
+ ------------------------------------------------------------
164
+ Author: John Croisant <jacius@gmail.com>
165
+ Date: Sun Apr 11 05:13:04 2010 -0500
166
+
167
+ Made SDL::Palette enumerable, defined #each and #at.
168
+
169
+ M lib/ruby-sdl-ffi/sdl/video.rb
170
+
171
+ ------------------------------------------------------------
172
+ Author: John Croisant <jacius@gmail.com>
173
+ Date: Thu Dec 10 14:20:10 2009 -0600
174
+
175
+ Made a nice wrapper around SDL::GetKeyRepeat().
176
+
177
+ M lib/ruby-sdl-ffi/sdl/keyboard.rb
178
+
179
+ ------------------------------------------------------------
180
+ Author: John Croisant <jacius@gmail.com>
181
+ Date: Thu Dec 10 13:53:53 2009 -0600
182
+
183
+ Use Buffer instad of MemoryPointer in many places.
184
+
185
+ There may be other places where Buffer should be used,
186
+ but these are the obvious ones.
187
+
188
+ M lib/ruby-sdl-ffi/gfx/rotozoom.rb
189
+ M lib/ruby-sdl-ffi/sdl/audio.rb
190
+ M lib/ruby-sdl-ffi/sdl/event.rb
191
+ M lib/ruby-sdl-ffi/sdl/keyboard.rb
192
+ M lib/ruby-sdl-ffi/sdl/mouse.rb
193
+ M lib/ruby-sdl-ffi/sdl/video.rb
194
+ M lib/ruby-sdl-ffi/ttf.rb
195
+
196
+ ------------------------------------------------------------
197
+ Author: John Croisant <jacius@gmail.com>
198
+ Date: Thu Dec 10 02:53:55 2009 -0600
199
+
200
+ Fixed a mistake in SDL::WaitEvent().
201
+
202
+ M lib/ruby-sdl-ffi/sdl/event.rb
203
+
1
204
  ------------------------------------------------------------
2
205
  Author: John Croisant <jacius@gmail.com>
3
206
  Date: Fri Oct 30 18:29:33 2009 -0500
data/NEWS.rdoc CHANGED
@@ -1,5 +1,42 @@
1
1
  = NEWS
2
2
 
3
+
4
+ == Ruby-SDL-FFI 0.3
5
+
6
+ * Ruby-SDL-FFI can now work on Mac OS X without the need for a special
7
+ interpreter (i.e. rsdl). If this causes issues for you, you can
8
+ disable it by setting the RUBYSDLFFI_NOCOCOA environment variable to
9
+ "true".
10
+
11
+ * Added the SDL::set_app_name() method. This sets the application name
12
+ in a platform-appropriate way, or does nothing if the platform is
13
+ not supported. On Mac OS X, it changes the text in the menu bar.
14
+ Support for other platforms may be added in the future.
15
+
16
+ * Ruby-SDL-FFI now reads the RUBYSDLFFI_PATH environment variable for
17
+ additional library load paths. It should be a colon-separated
18
+ (Linux/Mac) or semicolon-separated (Windows) list of directories to
19
+ search for libraries.
20
+
21
+ * The SDL::Palette class is now Enumerable. You can iterate over it
22
+ with #each, #collect, etc. You can also read a specific index using
23
+ #at (but not #[], which is reserved for struct access).
24
+
25
+ * SDL.GL_GetAttribute() now returns an integer, like it should.
26
+ Before, it would return an FFI::Buffer.
27
+
28
+ * SDL.GetKeyRepeat() is now easier to use. It returns an Array of two
29
+ integers: [delay, interval]. Before, you had to pass two output
30
+ buffers, then extract the integers afterwards.
31
+
32
+ * Fixed a NoMethodError in SDL.WaitEvent().
33
+
34
+ * Ruby-SDL-FFI now uses FFI::Buffer instead of FFI::MemoryPointer in
35
+ many places. This should give a slight performance boost on JRuby,
36
+ and potentially other platforms.
37
+
38
+
39
+
3
40
  == Ruby-SDL-FFI 0.2
4
41
 
5
42
  * The values of SDL::AUDIO_U16SYS and SDL::AUDIO_S16SYS are now
@@ -18,7 +55,6 @@
18
55
 
19
56
 
20
57
 
21
-
22
58
  == Ruby-SDL-FFI 0.1
23
59
 
24
60
  * Initial release of Ruby-SDL-FFI. Bindings are provided for these
@@ -1,12 +1,12 @@
1
1
 
2
2
  = Ruby-SDL-FFI
3
3
 
4
- Version:: 0.2
5
- Date:: 2009-10-30
4
+ Version:: 0.3
5
+ Date:: 2010-08-08
6
6
 
7
7
  Homepage:: http://github.com/jacius/ruby-sdl-ffi/
8
8
  Author:: John Croisant <jacius@gmail.com>
9
- Copyright:: 2009 John Croisant
9
+ Copyright:: 2009, 2010 John Croisant
10
10
 
11
11
 
12
12
  == Description
@@ -31,7 +31,7 @@ libraries (Rubygame [4], Gosu [5], etc.).
31
31
 
32
32
  == Caveats
33
33
 
34
- Ruby-SDL-FFI is still in VERY EARLY DEVELOPMENT STAGES. That means:
34
+ Ruby-SDL-FFI is still in EARLY DEVELOPMENT STAGES. That means:
35
35
 
36
36
  * It may not work correctly (or at all).
37
37
  * It may not be complete.
@@ -62,7 +62,7 @@ Ruby-SDL-FFI may work with older versions, but hasn't been tried on them.
62
62
 
63
63
  Ruby-SDL-FFI is licensed under the following terms (the "MIT License"):
64
64
 
65
- Copyright (c) 2009 John Croisant
65
+ Copyright (c) 2009, 2010 John Croisant
66
66
 
67
67
  Permission is hereby granted, free of charge, to any person obtaining
68
68
  a copy of this software and associated documentation files (the
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Ruby-SDL-FFI - Ruby-FFI bindings to SDL
6
6
  #
7
- # Copyright (c) 2009 John Croisant
7
+ # Copyright (c) 2009, 2010 John Croisant
8
8
  #
9
9
  # Permission is hereby granted, free of charge, to any person obtaining
10
10
  # a copy of this software and associated documentation files (the
@@ -54,11 +54,11 @@ module SDL
54
54
  SDL::Surface.typed_pointer
55
55
 
56
56
  func :__rotozoomSurfaceSize, :rotozoomSurfaceSize,
57
- [ :int, :int, :double, :double, :pointer, :pointer ], :void
57
+ [ :int, :int, :double, :double, :buffer_out, :buffer_out ], :void
58
58
 
59
59
  def self.rotozoomSurfaceSize( width, height, angle, zoom )
60
- w = FFI::MemoryPointer.new( :int )
61
- h = FFI::MemoryPointer.new( :int )
60
+ w = FFI::Buffer.new( :int )
61
+ h = FFI::Buffer.new( :int )
62
62
  __rotozoomSurfaceSize( width, height, angle, zoom, w, h )
63
63
  return [w.get_int(0), h.get_int(0)]
64
64
  end
@@ -70,11 +70,11 @@ module SDL
70
70
 
71
71
  func :__rotozoomSurfaceSizeXY, :rotozoomSurfaceSizeXY,
72
72
  [ :int, :int, :double, :double, :double,
73
- :pointer, :pointer ], :void
73
+ :buffer_out, :buffer_out ], :void
74
74
 
75
75
  def self.rotozoomSurfaceSizeXY( width, height, angle, zoomx, zoomy )
76
- w = FFI::MemoryPointer.new( :int )
77
- h = FFI::MemoryPointer.new( :int )
76
+ w = FFI::Buffer.new( :int )
77
+ h = FFI::Buffer.new( :int )
78
78
  __rotozoomSurfaceSizeXY( width, height, angle, zoomx, zoomy, w, h )
79
79
  return [w.get_int(0), h.get_int(0)]
80
80
  end
@@ -86,11 +86,11 @@ module SDL
86
86
 
87
87
 
88
88
  func :__zoomSurfaceSize, :zoomSurfaceSize,
89
- [ :int, :int, :double, :double, :pointer, :pointer ], :void
89
+ [ :int, :int, :double, :double, :buffer_out, :buffer_out ], :void
90
90
 
91
91
  def self.zoomSurfaceSize( width, height, zoomx, zoomy )
92
- w = FFI::MemoryPointer.new( :int )
93
- h = FFI::MemoryPointer.new( :int )
92
+ w = FFI::Buffer.new( :int )
93
+ h = FFI::Buffer.new( :int )
94
94
  __zoomSurfaceSize( width, height, zoomx, zoomy, w, h )
95
95
  return [w.get_int(0), h.get_int(0)]
96
96
  end
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Ruby-SDL-FFI - Ruby-FFI bindings to SDL
6
6
  #
7
- # Copyright (c) 2009 John Croisant
7
+ # Copyright (c) 2009, 2010 John Croisant
8
8
  #
9
9
  # Permission is hereby granted, free of charge, to any person obtaining
10
10
  # a copy of this software and associated documentation files (the
@@ -35,13 +35,17 @@ module SDL
35
35
  extend NiceFFI::Library
36
36
 
37
37
  unless defined? SDL::LOAD_PATHS
38
- # Check if the application has defined SDL_PATHS with some
39
- # paths to check first for SDL libraries.
40
- SDL::LOAD_PATHS = if defined? ::SDL_PATHS
41
- NiceFFI::PathSet::DEFAULT.prepend( ::SDL_PATHS )
42
- else
43
- NiceFFI::PathSet::DEFAULT
44
- end
38
+ SDL::LOAD_PATHS = NiceFFI::PathSet::DEFAULT.dup
39
+
40
+ rubysdlffi_path = ENV["RUBYSDLFFI_PATH"]
41
+ if rubysdlffi_path and not rubysdlffi_path.empty?
42
+ paths = rubysdlffi_path.split( File::PATH_SEPARATOR ).compact
43
+ SDL::LOAD_PATHS.prepend!(paths)
44
+ end
45
+
46
+ if defined? ::SDL_PATHS
47
+ SDL::LOAD_PATHS.prepend!(::SDL_PATHS)
48
+ end
45
49
  end
46
50
 
47
51
  load_library "SDL", SDL::LOAD_PATHS
@@ -59,6 +63,7 @@ this_dir = File.expand_path( File.dirname(__FILE__) )
59
63
  # because event and mouse depend on them, respectively.
60
64
 
61
65
  %w{
66
+ mac
62
67
  core
63
68
  keyboard
64
69
  video
@@ -91,12 +91,13 @@ module SDL
91
91
  # end
92
92
 
93
93
 
94
- sdl_func :AudioInit, [ :string ], :int
95
- sdl_func :AudioQuit, [ ], :void
96
- sdl_func :OpenAudio, [ :pointer, :pointer ], :int
94
+ sdl_func :AudioInit, [ :string ], :int
95
+ sdl_func :AudioQuit, [ ], :void
96
+ sdl_func :OpenAudio, [ :buffer_in, :buffer_out ], :int
97
97
 
98
98
 
99
- func :__AudioDriverName, "SDL_AudioDriverName", [:pointer, :int], :pointer
99
+ func :__AudioDriverName, "SDL_AudioDriverName",
100
+ [:buffer_out, :int], :pointer
100
101
 
101
102
  def self.AudioDriverName
102
103
  b = FFI::Buffer.new(:char, 1024)
@@ -310,10 +310,10 @@ module SDL
310
310
  end
311
311
 
312
312
 
313
- func :__SDL_PollEvent, "SDL_PollEvent", [ :pointer ], :int
313
+ func :__SDL_PollEvent, "SDL_PollEvent", [ :buffer_out ], :int
314
314
 
315
315
  def self.PollEvent()
316
- mp = FFI::MemoryPointer.new( SDL::Event, 1 )
316
+ mp = FFI::Buffer.new( SDL::Event, 1 )
317
317
  n = __SDL_PollEvent( mp )
318
318
  if n == 0
319
319
  nil
@@ -323,24 +323,24 @@ module SDL
323
323
  end
324
324
 
325
325
 
326
- func :__SDL_WaitEvent, "SDL_WaitEvent", [ :pointer ], :int
326
+ func :__SDL_WaitEvent, "SDL_WaitEvent", [ :buffer_out ], :int
327
327
 
328
328
  def self.WaitEvent()
329
- mp = FFI::MemoryPointer.new( SDL::Event, 1 )
329
+ mp = FFI::Buffer.new( SDL::Event, 1 )
330
330
  n = __SDL_WaitEvent( mp )
331
331
  if n == 0
332
332
  nil
333
333
  else
334
- _extract_event( Event.new(mp) )
334
+ Event.new(mp).unwrap
335
335
  end
336
336
  end
337
337
 
338
338
 
339
- sdl_func :PushEvent, [ :pointer ], :int
339
+ sdl_func :PushEvent, [ :buffer_in ], :int
340
340
 
341
341
 
342
342
 
343
- callback(:eventfilter_cb, [ :pointer ], :int)
343
+ callback(:eventfilter_cb, [ :buffer_out ], :int)
344
344
 
345
345
  func :__SDL_SetEventFilter, "SDL_SetEventFilter",
346
346
  [ :eventfilter_cb ], :void
@@ -47,13 +47,23 @@ module SDL
47
47
  DEFAULT_REPEAT_INTERVAL = 30
48
48
 
49
49
  sdl_func :EnableKeyRepeat, [ :int, :int ], :int
50
- sdl_func :GetKeyRepeat, [ :pointer, :pointer ], :void
51
50
 
52
51
 
53
- func :__SDL_GetKeyState, "SDL_GetKeyState", [ :pointer ], :pointer
52
+ func :__SDL_GetKeyRepeat, "SDL_GetKeyRepeat",
53
+ [ :buffer_out, :buffer_out ], :void
54
+
55
+ def self.GetKeyRepeat()
56
+ delay = FFI::Buffer.new( :int )
57
+ interval = FFI::Buffer.new( :int )
58
+ __SDL_GetKeyRepeat( delay, interval )
59
+ return [delay.get_int(0), interval.get_int(0)]
60
+ end
61
+
62
+
63
+ func :__SDL_GetKeyState, "SDL_GetKeyState", [ :buffer_out ], :pointer
54
64
 
55
65
  def self.GetKeyState()
56
- numkeys = FFI::MemoryPointer.new( :int )
66
+ numkeys = FFI::Buffer.new( :int )
57
67
  keys = __SDL_GetKeyState( numkeys )
58
68
  return keys.get_array_of_uint8( 0, numkeys.get_int(0) )
59
69
  end
@@ -0,0 +1,437 @@
1
+ #--
2
+ #
3
+ # This file is one part of:
4
+ #
5
+ # Ruby-SDL-FFI - Ruby-FFI bindings to SDL
6
+ #
7
+ # Copyright (c) 2010 John Croisant
8
+ #
9
+ # Permission is hereby granted, free of charge, to any person obtaining
10
+ # a copy of this software and associated documentation files (the
11
+ # "Software"), to deal in the Software without restriction, including
12
+ # without limitation the rights to use, copy, modify, merge, publish,
13
+ # distribute, sublicense, and/or sell copies of the Software, and to
14
+ # permit persons to whom the Software is furnished to do so, subject to
15
+ # the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be
18
+ # included in all copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+ #++
29
+
30
+ #--
31
+ # Some bindings to Mac OS X system framework to allow Ruby-SDL-FFI
32
+ # to create a window on Mac without a special Ruby interpreter (rsdl).
33
+ # These are for internal use only. They are NOT part of the API.
34
+ #
35
+ # Eternal thanks to erisdiscord and jlnr for pointing the way!
36
+
37
+
38
+ # Only define this stuff if running on a Mac and not using rsdl and
39
+ # the RUBYSDLFFI_NOCOCOA environment variable is not true-ish.
40
+ if FFI::Platform.mac? and ($0 != "rsdl") and \
41
+ not (/^(1|t|true|y|yes)$/i =~ ENV["RUBYSDLFFI_NOCOCOA"])
42
+
43
+ module SDL::Mac
44
+
45
+ class << self
46
+
47
+ def make_menus( app_name )
48
+ ptr = FFI.find_type(:pointer)
49
+
50
+ nsapp = Cocoa.NSApp
51
+ menubar = Cocoa::NSMenu.new.initWithTitle("AMainMenu")
52
+ nsapp.msg( "setMainMenu:", ptr, menubar )
53
+
54
+ remove_bold_menu( nsapp, menubar )
55
+ make_app_menu( menubar, app_name )
56
+ make_window_menu( nsapp, menubar )
57
+
58
+ nil
59
+ end
60
+
61
+
62
+ def set_app_name( app_name )
63
+ ptr = FFI.find_type(:pointer)
64
+
65
+ if @appmenuitem
66
+ @appmenuitem.title = app_name
67
+ @hideitem.title = "Hide #{app_name}" if @hideitem
68
+ @quititem.title = "Quit #{app_name}" if @quititem
69
+ else
70
+ make_menus( app_name )
71
+ end
72
+
73
+ nil
74
+ end
75
+
76
+
77
+ private
78
+
79
+ # Hack to remove the bold "ruby" menu (aka the "Apple" menu).
80
+ # It's a ghost menu, it haunts us but can't be modified.
81
+ def remove_bold_menu( nsapp, menubar )
82
+ item = Cocoa::NSMenuItem.new.initWithTitle("AppleMenu")
83
+ menu = Cocoa::NSMenu.new.initWithTitle("AppleMenu")
84
+ item.submenu = menu
85
+
86
+ nsapp.msg("setAppleMenu:", FFI.find_type(:pointer), menu)
87
+ menubar.addItem(item)
88
+ menubar.removeItem(item)
89
+
90
+ item.release
91
+ menu.release
92
+ end
93
+
94
+
95
+ # Create the main menu with the app's name (Hide, Quit, etc.)
96
+ def make_app_menu( menubar, app_name )
97
+ item = Cocoa::NSMenuItem.new.initWithTitle( app_name )
98
+ menu = Cocoa::NSMenu.new.initWithTitle( app_name )
99
+ item.submenu = menu
100
+ menubar.addItem(item)
101
+
102
+ @hideitem = menu.addItemWithTitle("Hide #{app_name}", "hide:")
103
+ menu.addItemWithTitle("Hide Others", "hideOtherApplications:")
104
+ menu.addItemWithTitle("Show All", "unhideAllApplications:")
105
+
106
+ # Can't get the Quit menu item to work right yet.
107
+ # menu.addItem( Cocoa::NSMenuItem.separatorItem )
108
+ # @quititem = menu.addItemWithTitle("Quit #{app_name}", "terminate:")
109
+
110
+ @appmenuitem = item
111
+ menu.release
112
+ end
113
+
114
+
115
+ # Create the "Window" menu (Minimize, etc.)
116
+ def make_window_menu( nsapp, menubar )
117
+ ptr = FFI.find_type(:pointer)
118
+
119
+ item = Cocoa::NSMenuItem.new.initWithTitle("Window")
120
+ menu = Cocoa::NSMenu.new.initWithTitle("Window")
121
+ item.submenu = menu
122
+ menubar.addItem(item)
123
+ nsapp.msg("setWindowsMenu:", ptr, menu)
124
+
125
+ menu.addItemWithTitle("Minimize", "performMiniaturize:")
126
+
127
+ item.release
128
+ menu.release
129
+ end
130
+
131
+
132
+ def inspect_menu( menu, indent="" )
133
+ puts "%s-%s (%s \"%s\", %d items)"%[indent, menu, menu.classname,
134
+ menu.title, menu.length]
135
+ menu.each do |ob|
136
+ if ob.hasSubmenu?
137
+ inspect_menu( ob.submenu, indent+" " )
138
+ else
139
+ puts "%s -%s (%s \"%s\")"%[indent, ob, ob.classname, ob.title]
140
+ end
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+
147
+ module ObjC
148
+ extend NiceFFI::Library
149
+ load_library 'objc'
150
+
151
+ typedef :pointer, :id
152
+ typedef :pointer, :sel
153
+ typedef :pointer, :ivar
154
+ typedef :pointer, :nsclass
155
+ callback :imp, [:id, :sel, :varargs], :id
156
+
157
+
158
+ class NSObject < NiceFFI::OpaqueStruct
159
+ def self.nsclassname; name.split("::")[-1]; end
160
+
161
+ # define msg, msg_ptr, msg_str, msg_int, msg_bool (and class methods)
162
+ ["", "_ptr", "_str", "_int", "_bool"].each do |suffix|
163
+ module_eval("
164
+ def msg#{suffix}( message, *args )
165
+ ObjC.msgSend#{suffix}( @pointer, message, *args )
166
+ end
167
+
168
+ def self.msg#{suffix}( message, *args )
169
+ ObjC.msgSend#{suffix}( ObjC.NSClass(self.nsclassname),
170
+ message, *args )
171
+ end")
172
+ end
173
+
174
+ def inspect; msg_str("description").to_s; end
175
+ def nsclassname; ObjC.object_getClassName(@pointer); end
176
+ def release; msg("release"); end
177
+ end
178
+
179
+ def self.NSObject( *args )
180
+ NSObject.new( *args )
181
+ end
182
+
183
+
184
+ class NSClass < NSObject
185
+ def initialize( str_or_ptr )
186
+ if str_or_ptr.is_a? String
187
+ super( ObjC.getClass(str_or_ptr) )
188
+ else
189
+ super
190
+ end
191
+ end
192
+ end
193
+
194
+ def self.NSClass( *args )
195
+ NSClass.new( *args )
196
+ end
197
+
198
+
199
+ class NSString < NSObject
200
+ def initialize( str_or_ptr )
201
+ if str_or_ptr.is_a? String
202
+ super( ObjC::NSClass("NSString").\
203
+ msg_ptr("stringWithUTF8String:",
204
+ FFI.find_type(:string), str_or_ptr) )
205
+ else
206
+ super
207
+ end
208
+ end
209
+
210
+ def to_s
211
+ str = msg_ptr( "UTF8String" )
212
+ (str.null?) ? "(NULL)" : str.read_string()
213
+ end
214
+ end
215
+
216
+ def self.NSString( *args )
217
+ NSString.new( *args )
218
+ end
219
+
220
+
221
+ func :__msgSend, :objc_msgSend, [:id, :sel, :varargs], :id
222
+ func :__msgSend_int, :objc_msgSend, [:id, :sel, :varargs], :long
223
+
224
+ def self.msgSend( id, selector, *args )
225
+ selector = self.sel(selector) if selector.is_a? String
226
+ NSObject.new( __msgSend( id, selector, *args ) )
227
+ end
228
+ def self.msgSend_ptr( id, selector, *args )
229
+ selector = self.sel(selector) if selector.is_a? String
230
+ __msgSend( id, selector, *args )
231
+ end
232
+ def self.msgSend_str( id, selector, *args )
233
+ selector = self.sel(selector) if selector.is_a? String
234
+ NSString.new( __msgSend( id, selector, *args ) )
235
+ end
236
+ def self.msgSend_int( id, selector, *args )
237
+ selector = self.sel(selector) if selector.is_a? String
238
+ __msgSend_int( id, selector, *args )
239
+ end
240
+ def self.msgSend_bool( id, selector, *args )
241
+ selector = self.sel(selector) if selector.is_a? String
242
+ ( __msgSend_int( id, selector, *args ) == 0 ) ? false : true
243
+ end
244
+
245
+ func :getClass, :objc_getClass, [:string], :id
246
+ func :class_replaceMethod, [:nsclass, :sel, :imp, :string], :imp
247
+
248
+ func :object_getClassName, [:id], :string
249
+ func :object_getInstanceVariable, [:id, :string, :pointer], :ivar
250
+ func :object_setInstanceVariable, [:id, :string, :pointer], :ivar
251
+
252
+ func :sel_registerName, [:string], :sel
253
+ func :sel_getName, [:sel], :string
254
+
255
+ def self.sel( name )
256
+ sel_registerName( name.to_s )
257
+ end
258
+
259
+ end
260
+
261
+
262
+ module Cocoa
263
+ extend NiceFFI::Library
264
+ load_library '/System/Library/Frameworks/Cocoa.framework/Cocoa'
265
+
266
+ func :NSApplicationLoad, [], :bool
267
+
268
+ func :NSPushAutoreleasePool, [], :void
269
+ func :NSPopAutoreleasePool, [], :void
270
+
271
+ NSApplicationLoad()
272
+ NSPushAutoreleasePool()
273
+
274
+ def self.NSApp
275
+ @nsapp ||= ObjC::NSClass("NSApplication").msg("sharedApplication")
276
+ end
277
+
278
+ class NSMenu < ObjC::NSObject
279
+ include Enumerable
280
+
281
+ def initialize( *args )
282
+ if args.empty?
283
+ super( ObjC::NSClass("NSMenu").msg_ptr("alloc") )
284
+ else
285
+ super( args[0] )
286
+ end
287
+ end
288
+
289
+ def initWithTitle( title )
290
+ msg( "initWithTitle:", FFI.find_type(:pointer), ObjC::NSString(title) )
291
+ self
292
+ end
293
+
294
+ def title
295
+ msg_str("title")
296
+ end
297
+
298
+ def title=( t )
299
+ msg("setTitle:", FFI.find_type(:pointer), ObjC::NSString(t))
300
+ end
301
+
302
+ def addItem( item )
303
+ msg("addItem:", FFI.find_type(:pointer), item)
304
+ self
305
+ end
306
+
307
+ def addItemWithTitle( title, action=nil, keyEquivalent="" )
308
+ ptr = FFI.find_type(:pointer)
309
+ action = ObjC.sel(action) if action.is_a? String
310
+ item = msg_ptr( "addItemWithTitle:action:keyEquivalent:",
311
+ ptr, ObjC::NSString(title),
312
+ ptr, action,
313
+ ptr, ObjC::NSString(keyEquivalent))
314
+ NSMenuItem.new(item)
315
+ end
316
+
317
+ def removeItem( item )
318
+ msg("removeItem:", FFI.find_type(:pointer), item)
319
+ self
320
+ end
321
+
322
+ def removeItemAtIndex( index )
323
+ msg("removeItemAtIndex:", FFI.find_type(:long), index)
324
+ self
325
+ end
326
+
327
+ def length
328
+ msg_int( "numberOfItems" )
329
+ end
330
+
331
+ def [](index)
332
+ Cocoa::NSMenuItem( msg_ptr("itemAtIndex:", FFI.find_type(:long), index) )
333
+ end
334
+
335
+ def each
336
+ length.times{ |i| yield self[i] }
337
+ end
338
+ end
339
+
340
+ def self.NSMenu( *args )
341
+ NSMenu.new( *args )
342
+ end
343
+
344
+
345
+ class NSMenuItem < ObjC::NSObject
346
+ def self.separatorItem
347
+ new( msg_ptr("separatorItem") )
348
+ end
349
+
350
+ def initialize( *args )
351
+ if args.empty?
352
+ super( ObjC::NSClass("NSMenuItem").msg_ptr("alloc") )
353
+ else
354
+ super( args[0] )
355
+ end
356
+ end
357
+
358
+ def initWithTitle( title, action=nil, keyEquivalent="" )
359
+ ptr = FFI.find_type(:pointer)
360
+ action = ObjC.sel(action) if action.is_a? String
361
+ msg( "initWithTitle:action:keyEquivalent:",
362
+ ptr, ObjC::NSString(title),
363
+ ptr, action,
364
+ ptr, ObjC::NSString(keyEquivalent))
365
+ self
366
+ end
367
+
368
+ def title
369
+ msg_str("title")
370
+ end
371
+
372
+ def title=( t )
373
+ msg("setTitle:", FFI.find_type(:pointer), ObjC::NSString(t))
374
+ end
375
+
376
+ def hasSubmenu?
377
+ msg_bool("hasSubmenu")
378
+ end
379
+
380
+ def submenu
381
+ Cocoa::NSMenu( msg_ptr("submenu") ) if hasSubmenu?
382
+ end
383
+
384
+ def submenu=( menu )
385
+ msg("setSubmenu:", FFI.find_type(:pointer), menu)
386
+ end
387
+ end
388
+
389
+ def self.NSMenuItem( *args )
390
+ NSMenuItem.new( *args )
391
+ end
392
+
393
+
394
+ attach_variable "vNSNibOwner", "NSNibOwner", :pointer
395
+ NSNibOwner =
396
+ ObjC::NSString( ObjC::NSString(self.vNSNibOwner).to_s )
397
+
398
+ attach_variable "vNSNibTopLevelObjects", "NSNibTopLevelObjects", :pointer
399
+ NSNibTopLevelObjects =
400
+ ObjC::NSString( ObjC::NSString(self.vNSNibTopLevelObjects).to_s )
401
+
402
+ NSAlphaShiftKeyMask = 1 << 16
403
+ NSShiftKeyMask = 1 << 17
404
+ NSControlKeyMask = 1 << 18
405
+ NSAlternateKeyMask = 1 << 19
406
+ NSCommandKeyMask = 1 << 20
407
+ NSNumericPadKeyMask = 1 << 21
408
+ NSHelpKeyMask = 1 << 22
409
+ NSFunctionKeyMask = 1 << 23
410
+ end
411
+
412
+
413
+ module HIServices
414
+ extend NiceFFI::Library
415
+ load_library '/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/HIServices'
416
+
417
+ class ProcessSerialNumber < NiceFFI::Struct
418
+ layout :highLongOfPSN, :ulong, :lowLongOfPSN, :ulong
419
+ end
420
+
421
+ # Some relevant constants (but not part of the same enum)
422
+ KCurrentProcess = 2
423
+ KProcessTransformToForegroundApplication = 1
424
+
425
+ func :TransformProcessType, [:pointer, :long], :long
426
+ func :SetFrontProcess, [:pointer], :long
427
+
428
+ # Does the magic to make the current process a front process.
429
+ def self.make_current_front
430
+ current = ProcessSerialNumber.new( [0, KCurrentProcess] )
431
+ TransformProcessType(current,KProcessTransformToForegroundApplication)
432
+ SetFrontProcess( current )
433
+ end
434
+ end
435
+
436
+ end
437
+ end
@@ -49,29 +49,29 @@ module SDL
49
49
  end
50
50
 
51
51
  func :__SDL_GetMouseState, "SDL_GetMouseState",
52
- [ :pointer, :pointer ], :uint8
52
+ [ :buffer_out, :buffer_out ], :uint8
53
53
 
54
54
  # Returns [buttons, x, y].
55
55
  # buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants).
56
56
  # x, y: current position of the mouse cursor.
57
57
  def self.GetMouseState()
58
- xmp = FFI::MemoryPointer.new( :int )
59
- ymp = FFI::MemoryPointer.new( :int )
58
+ xmp = FFI::Buffer.new( :int )
59
+ ymp = FFI::Buffer.new( :int )
60
60
  buttons = __SDL_GetMouseState( xmp, ymp )
61
61
  return [buttons, xmp.get_int(0), ymp.get_int(0)]
62
62
  end
63
63
 
64
64
 
65
65
  func :__SDL_GetRelativeMouseState, "SDL_GetRelativeMouseState",
66
- [ :pointer, :pointer ], :uint8
66
+ [ :buffer_out, :buffer_out ], :uint8
67
67
 
68
68
  # Returns [buttons, x, y].
69
69
  # buttons: buttons currently pressed (bitmask of BUTTON_*MASK constants).
70
70
  # x, y: movement of the mouse cursor since last call of this method.
71
71
  #
72
72
  def self.GetRelativeMouseState()
73
- xmp = FFI::MemoryPointer.new( :int )
74
- ymp = FFI::MemoryPointer.new( :int )
73
+ xmp = FFI::Buffer.new( :int )
74
+ ymp = FFI::Buffer.new( :int )
75
75
  buttons = __SDL_GetRelativeMouseState( xmp, ymp )
76
76
  return [buttons, xmp.get_int(0), ymp.get_int(0)]
77
77
  end
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Ruby-SDL-FFI - Ruby-FFI bindings to SDL
6
6
  #
7
- # Copyright (c) 2009 John Croisant
7
+ # Copyright (c) 2009, 2010 John Croisant
8
8
  #
9
9
  # Permission is hereby granted, free of charge, to any person obtaining
10
10
  # a copy of this software and associated documentation files (the
@@ -50,11 +50,30 @@ module SDL
50
50
 
51
51
  end
52
52
 
53
+
53
54
  class Palette < NiceFFI::Struct
54
55
  layout( :ncolors, :int,
55
56
  :colors, :pointer )
57
+
58
+ include Enumerable
59
+
60
+ # Returns the color at the given index in the palette, as an
61
+ # SDL::Color instance.
62
+ def at( index )
63
+ index = (0...ncolors).to_a.at(index)
64
+ if index
65
+ SDL::Color.new( self[:colors] + index * SDL::Color.size )
66
+ end
67
+ end
68
+
69
+ # Yields an SDL::Color for each color in the palette.
70
+ def each
71
+ ncolors.times{ |i| yield at(i) }
72
+ end
73
+
56
74
  end
57
75
 
76
+
58
77
  class PixelFormat < NiceFFI::Struct
59
78
  layout( :palette, Palette.typed_pointer,
60
79
  :BitsPerPixel, :uint8,
@@ -252,9 +271,40 @@ module SDL
252
271
  ## Don't know how to implement this one. :-\
253
272
  # sdl_func :ListModes, [ :pointer, :uint32 ], :pointer
254
273
 
255
- sdl_func :SetVideoMode, [ :int, :int, :int, :uint32 ],
256
- SDL::Surface.typed_pointer( :autorelease => false )
257
274
 
275
+ func :__SetVideoMode, "SDL_SetVideoMode", [ :int, :int, :int, :uint32 ],
276
+ SDL::Surface.typed_pointer( :autorelease => false )
277
+
278
+ def self.SetVideoMode( *args )
279
+ result = __SetVideoMode(*args)
280
+ if defined? SDL::Mac
281
+ SDL::Mac::HIServices.make_current_front
282
+ SDL::Mac.make_menus("ruby")
283
+ end
284
+ return result
285
+ end
286
+
287
+
288
+ # Sets the application name, if the platform supports it. This
289
+ # method is safe to call even on platforms which do not support it
290
+ # (but does nothing). Currently this method only has an effect on
291
+ # Mac OS X.
292
+ #
293
+ # The effect of this method depends on the platform. On Mac OS X, it
294
+ # sets the text used in the main application menu.
295
+ #
296
+ # (Note: this method does not correspond to any part of the SDL API.
297
+ # It communicates with the platform directly.)
298
+ #
299
+ # Example:
300
+ # SDL.set_app_name("SpaceQuest 4000")
301
+ #
302
+ def self.set_app_name( app_name )
303
+ if defined? SDL::Mac
304
+ SDL::Mac.set_app_name( app_name )
305
+ end
306
+ nil
307
+ end
258
308
 
259
309
 
260
310
  func :__UpdateRects, "SDL_UpdateRects", [ :pointer, :int, :pointer ], :void
@@ -280,7 +330,7 @@ module SDL
280
330
 
281
331
 
282
332
  func :__SDL_GetGammaRamp, "SDL_GetGammaRamp",
283
- [ :pointer, :pointer, :pointer ], :int
333
+ [ :buffer_out, :buffer_out, :buffer_out ], :int
284
334
 
285
335
  def self.GetGammaRamp()
286
336
  rtable = FFI::Buffer.new( :uint16, 256 )
@@ -306,12 +356,12 @@ module SDL
306
356
 
307
357
 
308
358
  func :__SDL_GetRGB, "SDL_GetRGB",
309
- [ :uint32, :pointer, :pointer, :pointer, :pointer ], :void
359
+ [ :uint32, :pointer, :buffer_out, :buffer_out, :buffer_out ], :void
310
360
 
311
361
  def self.GetRGB( uint32, format )
312
- r = FFI::MemoryPointer.new( :uint8 )
313
- g = FFI::MemoryPointer.new( :uint8 )
314
- b = FFI::MemoryPointer.new( :uint8 )
362
+ r = FFI::Buffer.new( :uint8 )
363
+ g = FFI::Buffer.new( :uint8 )
364
+ b = FFI::Buffer.new( :uint8 )
315
365
  __SDL_GetRGB( uint32, format, r, g, b )
316
366
  return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0)]
317
367
  end
@@ -319,13 +369,14 @@ module SDL
319
369
 
320
370
 
321
371
  func :__SDL_GetRGBA, "SDL_GetRGBA",
322
- [ :uint32, :pointer, :pointer, :pointer, :pointer, :pointer ], :void
372
+ [ :uint32, :pointer, :buffer_out,
373
+ :buffer_out, :buffer_out, :buffer_out ], :void
323
374
 
324
375
  def self.GetRGBA( uint32, format )
325
- r = FFI::MemoryPointer.new( :uint8 )
326
- g = FFI::MemoryPointer.new( :uint8 )
327
- b = FFI::MemoryPointer.new( :uint8 )
328
- a = FFI::MemoryPointer.new( :uint8 )
376
+ r = FFI::Buffer.new( :uint8 )
377
+ g = FFI::Buffer.new( :uint8 )
378
+ b = FFI::Buffer.new( :uint8 )
379
+ a = FFI::Buffer.new( :uint8 )
329
380
  __SDL_GetRGBA( uint32, format, r, g, b, a )
330
381
  return [r.get_uint8(0), g.get_uint8(0), b.get_uint8(0), a.get_uint8(0)]
331
382
  end
@@ -358,10 +409,10 @@ module SDL
358
409
 
359
410
  sdl_func :SetClipRect, [ :pointer, :pointer ], SDL::BOOL
360
411
 
361
- func :__SDL_GetClipRect, "SDL_GetClipRect", [ :pointer, :pointer ], :void
412
+ func :__SDL_GetClipRect, "SDL_GetClipRect", [ :pointer, :buffer_out ], :void
362
413
 
363
414
  def self.GetClipRect( surface )
364
- mp = FFI::MemoryPointer.new( Rect )
415
+ mp = FFI::Buffer.new( Rect )
365
416
  __SDL_GetClipRect( surface, mp )
366
417
  return Rect.new( mp )
367
418
  end
@@ -397,15 +448,15 @@ module SDL
397
448
 
398
449
 
399
450
  func :__GL_GetAttribute, "SDL_GL_GetAttribute",
400
- [ SDL::GLATTR, :pointer ], :int
451
+ [ SDL::GLATTR, :buffer_out ], :int
401
452
 
402
453
  def self.GL_GetAttribute( attrib )
403
- value = FFI::Buffer.new( :int )
404
- result = __GL_GetAttribute( attrib, value )
454
+ buffer = FFI::Buffer.new( :int )
455
+ result = __GL_GetAttribute( attrib, buffer )
405
456
  if( result == -1 )
406
457
  return nil
407
458
  else
408
- return value
459
+ return buffer.get_int(0)
409
460
  end
410
461
  end
411
462
 
@@ -420,11 +471,11 @@ module SDL
420
471
  sdl_func :WM_SetCaption, [ :string, :string ], :void
421
472
 
422
473
  func :__SDL_WM_GetCaption, "SDL_WM_GetCaption",
423
- [ :pointer, :pointer ], :void
474
+ [ :buffer_out, :buffer_out ], :void
424
475
 
425
476
  def self.WM_GetCaption()
426
- title = FFI::MemoryPointer.new( :pointer )
427
- icont = FFI::MemoryPointer.new( :pointer )
477
+ title = FFI::Buffer.new( :pointer )
478
+ icont = FFI::Buffer.new( :pointer )
428
479
  __SDL_WM_GetCaption( title, icont )
429
480
  return [ title.get_pointer(0).get_string(0),
430
481
  icont.get_pointer(0).get_string(0) ]
@@ -103,15 +103,15 @@ module SDL
103
103
 
104
104
 
105
105
  func :__GlyphMetrics, "TTF_GlyphMetrics",
106
- [ :pointer, :uint16, :pointer, :pointer,
107
- :pointer, :pointer, :pointer ], :int
106
+ [ :pointer, :uint16, :buffer_out, :buffer_out,
107
+ :buffer_out, :buffer_out, :buffer_out ], :int
108
108
 
109
109
  # Returns:: [minx, maxx, miny, maxy, advance], or nil on failure.
110
110
  #
111
111
  def self.GlyphMetrics( font, char )
112
- minx, maxx = FFI::MemoryPointer.new(:int), FFI::MemoryPointer.new(:int)
113
- miny, maxy = FFI::MemoryPointer.new(:int), FFI::MemoryPointer.new(:int)
114
- advance = FFI::MemoryPointer.new(:int)
112
+ minx, maxx = FFI::Buffer.new(:int), FFI::Buffer.new(:int)
113
+ miny, maxy = FFI::Buffer.new(:int), FFI::Buffer.new(:int)
114
+ advance = FFI::Buffer.new(:int)
115
115
  result = __GlyphMetrics( font, char, minx, maxx, miny, maxy, advance )
116
116
  if( result == 0 )
117
117
  return [minx.get_int(0), maxx.get_int(0),
@@ -124,11 +124,11 @@ module SDL
124
124
 
125
125
 
126
126
  func :__SizeText, "TTF_SizeText",
127
- [ :pointer, :string, :pointer, :pointer ], :int
127
+ [ :pointer, :string, :buffer_out, :buffer_out ], :int
128
128
 
129
129
  def self.SizeText( font, text )
130
- w = FFI::MemoryPointer.new( :int )
131
- h = FFI::MemoryPointer.new( :int )
130
+ w = FFI::Buffer.new( :int )
131
+ h = FFI::Buffer.new( :int )
132
132
  __SizeText( font, text, w, h )
133
133
  return [w.get_int(0),h.get_int(0)]
134
134
  end
@@ -136,11 +136,11 @@ module SDL
136
136
 
137
137
 
138
138
  func :__SizeUTF8, "TTF_SizeUTF8",
139
- [ :pointer, :string, :pointer, :pointer ], :int
139
+ [ :pointer, :string, :buffer_out, :buffer_out ], :int
140
140
 
141
141
  def self.SizeUTF( font, text )
142
- w = FFI::MemoryPointer.new( :int )
143
- h = FFI::MemoryPointer.new( :int )
142
+ w = FFI::Buffer.new( :int )
143
+ h = FFI::Buffer.new( :int )
144
144
  __SizeUTF( font, text, w, h )
145
145
  return [w.get_int(0),h.get_int(0)]
146
146
  end
@@ -148,11 +148,11 @@ module SDL
148
148
 
149
149
 
150
150
  func :__SizeUNICODE, "TTF_SizeUNICODE",
151
- [ :pointer, :pointer, :pointer, :pointer ], :int
151
+ [ :pointer, :pointer, :buffer_out, :buffer_out ], :int
152
152
 
153
153
  def self.SizeUNICODE( font, text )
154
- w = FFI::MemoryPointer.new( :int )
155
- h = FFI::MemoryPointer.new( :int )
154
+ w = FFI::Buffer.new( :int )
155
+ h = FFI::Buffer.new( :int )
156
156
  __SizeUNICODE( font, text, w, h )
157
157
  return [w.get_int(0),h.get_int(0)]
158
158
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-sdl-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ hash: 13
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ version: "0.3"
5
10
  platform: ruby
6
11
  authors:
7
12
  - John Croisant
@@ -9,19 +14,24 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-30 00:00:00 -05:00
17
+ date: 2010-08-08 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: nice-ffi
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 0
31
+ - 2
23
32
  version: "0.2"
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  description: |
26
36
  Ruby-SDL-FFI is a low-level binding to SDL and related libraries
27
37
  using Ruby-FFI. It provides very basic access to SDL from
@@ -48,6 +58,7 @@ files:
48
58
  - lib/ruby-sdl-ffi/sdl/cdrom.rb
49
59
  - lib/ruby-sdl-ffi/sdl/video.rb
50
60
  - lib/ruby-sdl-ffi/sdl/core.rb
61
+ - lib/ruby-sdl-ffi/sdl/mac.rb
51
62
  - lib/ruby-sdl-ffi/sdl/keysyms.rb
52
63
  - lib/ruby-sdl-ffi/sdl/timer.rb
53
64
  - lib/ruby-sdl-ffi/sdl/audio.rb
@@ -72,17 +83,24 @@ rdoc_options: []
72
83
  require_paths:
73
84
  - lib
74
85
  required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
75
87
  requirements:
76
88
  - - ">="
77
89
  - !ruby/object:Gem::Version
90
+ hash: 31
91
+ segments:
92
+ - 1
93
+ - 8
78
94
  version: "1.8"
79
- version:
80
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
81
97
  requirements:
82
98
  - - ">="
83
99
  - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
84
103
  version: "0"
85
- version:
86
104
  requirements:
87
105
  - SDL >= 1.2.13
88
106
  - SDL_image >= 1.2.7 (optional)
@@ -90,7 +108,7 @@ requirements:
90
108
  - SDL_mixer >= 1.2.8 (optional)
91
109
  - SDL_ttf >= 2.0.9 (optional)
92
110
  rubyforge_project: ruby-sdl-ffi
93
- rubygems_version: 1.3.5
111
+ rubygems_version: 1.3.7
94
112
  signing_key:
95
113
  specification_version: 3
96
114
  summary: Ruby-FFI bindings to SDL