sdl2_ffi 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +33 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +83 -0
  9. data/Rakefile +7 -0
  10. data/bin/coderay +16 -0
  11. data/bin/guard +16 -0
  12. data/bin/pry +16 -0
  13. data/bin/rake +16 -0
  14. data/bin/thor +16 -0
  15. data/lib/sdl2/assert.rb +7 -0
  16. data/lib/sdl2/audio.rb +139 -0
  17. data/lib/sdl2/clipboard.rb +27 -0
  18. data/lib/sdl2/color.rb +12 -0
  19. data/lib/sdl2/cpuinfo.rb +18 -0
  20. data/lib/sdl2/display/mode.rb +53 -0
  21. data/lib/sdl2/display/modes.rb +36 -0
  22. data/lib/sdl2/display.rb +74 -0
  23. data/lib/sdl2/error.rb +9 -0
  24. data/lib/sdl2/events.rb +358 -0
  25. data/lib/sdl2/gamecontroller.rb +62 -0
  26. data/lib/sdl2/gem_version.rb +4 -0
  27. data/lib/sdl2/gesture.rb +15 -0
  28. data/lib/sdl2/haptic.rb +159 -0
  29. data/lib/sdl2/hints.rb +47 -0
  30. data/lib/sdl2/init.rb +54 -0
  31. data/lib/sdl2/joystick.rb +58 -0
  32. data/lib/sdl2/keyboard.rb +34 -0
  33. data/lib/sdl2/keycode.rb +294 -0
  34. data/lib/sdl2/log.rb +70 -0
  35. data/lib/sdl2/mouse.rb +54 -0
  36. data/lib/sdl2/palette.rb +15 -0
  37. data/lib/sdl2/pixel_format.rb +28 -0
  38. data/lib/sdl2/pixels.rb +35 -0
  39. data/lib/sdl2/point.rb +7 -0
  40. data/lib/sdl2/power.rb +9 -0
  41. data/lib/sdl2/rect.rb +38 -0
  42. data/lib/sdl2/render.rb +77 -0
  43. data/lib/sdl2/renderer.rb +34 -0
  44. data/lib/sdl2/renderer_info.rb +13 -0
  45. data/lib/sdl2/rwops.rb +127 -0
  46. data/lib/sdl2/scancode.rb +275 -0
  47. data/lib/sdl2/sdl_module.rb +8 -0
  48. data/lib/sdl2/surface.rb +83 -0
  49. data/lib/sdl2/syswm/info.rb +49 -0
  50. data/lib/sdl2/syswm/msg.rb +46 -0
  51. data/lib/sdl2/syswm.rb +20 -0
  52. data/lib/sdl2/texture.rb +9 -0
  53. data/lib/sdl2/timer.rb +17 -0
  54. data/lib/sdl2/touch.rb +24 -0
  55. data/lib/sdl2/version.rb +30 -0
  56. data/lib/sdl2/video.rb +154 -0
  57. data/lib/sdl2/window.rb +259 -0
  58. data/lib/sdl2.rb +99 -0
  59. data/lib/sdl2_ffi.rb +6 -0
  60. data/sdl2_ffi.gemspec +31 -0
  61. data/test/test_helper.rb +2 -0
  62. data/test/unit/sdl2/test_assert.rb +10 -0
  63. data/test/unit/sdl2/test_audio.rb +9 -0
  64. data/test/unit/sdl2/test_clipboard.rb +13 -0
  65. data/test/unit/sdl2/test_cpuinfo.rb +11 -0
  66. data/test/unit/sdl2/test_error.rb +20 -0
  67. data/test/unit/sdl2/test_events.rb +31 -0
  68. data/test/unit/sdl2/test_haptic.rb +10 -0
  69. data/test/unit/sdl2/test_hints.rb +50 -0
  70. data/test/unit/sdl2/test_init.rb +29 -0
  71. data/test/unit/sdl2/test_keyboard.rb +9 -0
  72. data/test/unit/sdl2/test_log.rb +80 -0
  73. data/test/unit/sdl2/test_pixels.rb +24 -0
  74. data/test/unit/sdl2/test_power.rb +11 -0
  75. data/test/unit/sdl2/test_rect.rb +19 -0
  76. data/test/unit/sdl2/test_render.rb +58 -0
  77. data/test/unit/sdl2/test_surface.rb +45 -0
  78. data/test/unit/sdl2/test_syswm.rb +11 -0
  79. data/test/unit/sdl2/test_timer.rb +9 -0
  80. data/test/unit/sdl2/test_version.rb +16 -0
  81. data/test/unit/sdl2/test_video.rb +170 -0
  82. data/test/unit/sdl2/test_window.rb +158 -0
  83. data/test/unit/test_sdl2.rb +16 -0
  84. metadata +280 -0
@@ -0,0 +1,46 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2 # SDL_syswm.h
4
+
5
+ module SysWM
6
+ class Msg < Struct
7
+
8
+ class Win < Struct
9
+ layout :hwnd, :pointer,
10
+ :msg, :uint,
11
+ :wparam, :int16,
12
+ :lparam, :int32
13
+ end
14
+
15
+
16
+ class X11 < Struct
17
+ layout :dummy, :uint32 # TODO: FIXME: NOT YET SUPPORTED!
18
+ end
19
+
20
+ class DirectFB < Struct
21
+ layout :event, :uint32 # TODO: FIXME: NOT YET SUPPORTED!
22
+ end
23
+
24
+ class Cocoa < Struct
25
+ layout :dummy, :long # SDL2 says 'No Cocoa window events yet'
26
+ end
27
+
28
+ class UIKit < Struct
29
+ layout :dummy, :long # SDL2 says 'No UIKit window events yet'
30
+ end
31
+
32
+ class MsgUnion < FFI::Union
33
+ layout :win, Win,
34
+ :x11, X11,
35
+ :dfb, DirectFB,
36
+ :cocoa, Cocoa,
37
+ :uikit, UIKit,
38
+ :dummy, :int
39
+ end
40
+
41
+ layout :version, Version,
42
+ :subsystem, :int,
43
+ :msg, MsgUnion
44
+ end
45
+ end
46
+ end
data/lib/sdl2/syswm.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'sdl2'
2
+ require 'sdl2/version'
3
+ require 'sdl2/video'
4
+ require 'sdl2/syswm/info'
5
+ require 'sdl2/syswm/msg'
6
+
7
+ module SDL2 # SDL_syswm.h
8
+
9
+ module SysWM
10
+
11
+ end
12
+
13
+ SYSWM = SysWM # Because I don't care about case.
14
+
15
+ # Line 99~107
16
+ enum :syswm_type, [:unkown, :window, :x11, :directfb, :cocoa, :uikit]
17
+
18
+ api :SDL_GetWindowWMInfo, [Window.by_ref, SYSWM::Info.by_ref], :bool
19
+
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'sdl2'
2
+ # Stub for now.. need to implement!!!
3
+ module SDL2
4
+ class Texture < FFI::Struct
5
+ def self.release(pointer)
6
+ SDL2.destroy_texture(pointer)
7
+ end
8
+ end
9
+ end
data/lib/sdl2/timer.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ api :SDL_GetTicks, [], :uint32
6
+ api :SDL_GetPerformanceCounter, [], :uint64
7
+ api :SDL_GetPerformanceFrequency, [], :uint64
8
+ api :SDL_Delay, [:uint32], :void
9
+
10
+ callback :timer_callback, [:uint32, :pointer], :uint32
11
+
12
+ typedef :int, :timer_id
13
+
14
+ api :SDL_AddTimer, [:uint32, :timer_callback, :pointer], :timer_id
15
+ api :SDL_RemoveTimer, [:timer_id], :bool
16
+
17
+ end
data/lib/sdl2/touch.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'sdl2'
2
+ require 'sdl2/video'
3
+
4
+ module SDL2
5
+
6
+ typedef :int64, :touch_id
7
+ typedef :int64, :finger_id
8
+
9
+ class Finger < Struct
10
+ layout :id, :finger_id,
11
+ :x, :float,
12
+ :y, :float,
13
+ :pressure, :float
14
+ end
15
+
16
+ TOUCH_MOUSEID = -1
17
+
18
+ api :SDL_GetNumTouchDevices, [], :int
19
+ api :SDL_GetTouchDevice, [:int], :touch_id
20
+ api :SDL_GetNumTouchFingers, [:touch_id], :int
21
+ api :SDL_GetTouchFinger, [:touch_id, :int], Finger.by_ref
22
+
23
+
24
+ end
@@ -0,0 +1,30 @@
1
+ require 'sdl2'
2
+
3
+ module SDL2
4
+
5
+ class Version < FFI::Struct
6
+ layout :major, :uint8,
7
+ :minor, :uint8,
8
+ :patch, :uint8
9
+
10
+ def major
11
+ self[:major]
12
+ end
13
+
14
+ def minor
15
+ self[:minor]
16
+ end
17
+
18
+ def patch
19
+ self[:patch]
20
+ end
21
+
22
+ def to_s
23
+ "SDL v#{major}.#{minor}.#{patch}"
24
+ end
25
+ end
26
+
27
+ api :SDL_GetRevision, [], :string
28
+ api :SDL_GetRevisionNumber, [], :int
29
+ api :SDL_GetVersion, [Version.by_ref], :void
30
+ end
data/lib/sdl2/video.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'sdl2'
2
+ require 'sdl2/rect'
3
+ require 'sdl2/window'
4
+ require 'sdl2/display'
5
+ require 'sdl2/surface'
6
+
7
+ #require 'sdl2/renderer'
8
+ #require 'sdl2/texture'
9
+ require 'sdl2/syswm/info'
10
+
11
+ #
12
+ module SDL2
13
+ typedef :int, :display_index
14
+
15
+
16
+ enum :window_flags, [
17
+ :fullscreen, Window::FULLSCREEN,
18
+ :opengl, Window::OPENGL,
19
+ :shown, Window::SHOWN,
20
+ :hidden, Window::HIDDEN,
21
+ :borderless, Window::BORDERLESS,
22
+ :minimized, Window::MINIMIZED,
23
+ :maximized, Window::MAXIMIZED,
24
+ :input_grabbed, Window::INPUT_GRABBED,
25
+ :input_focus, Window::INPUT_FOCUS,
26
+ :mouse_focus, Window::MOUSE_FOCUS,
27
+ :fullscreen_desktop, Window::FULLSCREEN_DESKTOP,
28
+ :foreign, Window::FOREIGN
29
+ ]
30
+ # TODO: SDL_video.h lines 113~129
31
+
32
+ # line: 134~155
33
+ enum :window_event_id, [
34
+ :none,
35
+ :shown,
36
+ :hidden,
37
+ :exposed,
38
+ :moved,
39
+ :resized,
40
+ :size_changed,
41
+ :minimized,
42
+ :maximized,
43
+ :restored,
44
+ :enter,
45
+ :leave,
46
+ :focus_gained,
47
+ :focus_lost,
48
+ :close
49
+ ]
50
+ # line 160
51
+ typedef :pointer, :gl_context
52
+ # lines 165~190
53
+ enum :gl_attr, [
54
+ :red_size,
55
+ :green_size,
56
+ :blue_size,
57
+ :alpha_size,
58
+ :buffer_size,
59
+ :doublebuffer,
60
+ :depth_size,
61
+ :stencil_size,
62
+ :accum_red_size,
63
+ :accum_green_size,
64
+ :accum_blue_size,
65
+ :accum_alpha_size,
66
+ :stereo,
67
+ :multisamplebuffers,
68
+ :multisamplesamples,
69
+ :accelerated_visual,
70
+ :retained_backing,
71
+ :context_major_version,
72
+ :context_minor_version,
73
+ :context_egl,
74
+ :context_flags,
75
+ :context_profile_mask,
76
+ :share_with_current_context
77
+ ]
78
+ # lines 192~197
79
+ enum :gl_profile, [:core, 0x0001, :compatibility, 0x0002, :es, 0x0004]
80
+ # lines 199~205
81
+ enum :gl_context_flag, [:debug, 0x0001, :forward_compatible, 0x0002, :robust_access, 0x0004, :reset_isolation, 0x0008]
82
+
83
+ # This interface represents SDL_video.h function prototypes, lines 208~
84
+ api :SDL_GetNumVideoDrivers, [], :int
85
+ api :SDL_GetVideoDriver, [:int], :string
86
+ api :SDL_VideoInit, [:string], :int
87
+ api :SDL_VideoQuit, [], :void
88
+ api :SDL_GetCurrentVideoDriver, [], :string
89
+ api :SDL_GetNumVideoDisplays, [], :int
90
+ api :SDL_GetDisplayName, [:display_index], :string
91
+ api :SDL_GetDisplayBounds, [:int, Rect.by_ref], :int
92
+ api :SDL_GetNumDisplayModes, [:int], :int
93
+ api :SDL_GetDisplayMode, [:int, :int, Display::Mode.by_ref], :int
94
+ api :SDL_GetDesktopDisplayMode, [:int, Display::Mode.by_ref], :int
95
+ api :SDL_GetCurrentDisplayMode, [:int, Display::Mode.by_ref], :int
96
+ api :SDL_GetClosestDisplayMode, [:display_index, Display::Mode.by_ref, Display::Mode.by_ref], Display::Mode.by_ref
97
+ api :SDL_GetWindowDisplayIndex, [Window.by_ref], :int
98
+ api :SDL_SetWindowDisplayMode, [Window.by_ref, :uint32], :int
99
+ api :SDL_GetWindowDisplayMode, [Window.by_ref, Display::Mode.by_ref], :int
100
+ api :SDL_GetWindowPixelFormat, [Window.by_ref], :uint32
101
+ api :SDL_CreateWindow, [:string, :int, :int, :int, :int, :uint32], Window.auto_ptr
102
+ api :SDL_CreateWindowFrom, [:pointer], Window.auto_ptr
103
+ api :SDL_GetWindowFromID, [:uint32], Window.by_ref
104
+ api :SDL_GetWindowID, [Window.by_ref], :uint32
105
+ api :SDL_GetWindowFlags, [Window.by_ref], :uint32
106
+ api :SDL_GetWindowTitle, [Window.by_ref], :string
107
+ api :SDL_SetWindowTitle, [Window.by_ref, :string], :void
108
+ api :SDL_SetWindowIcon, [Window.by_ref, Surface.by_ref], :void
109
+ api :SDL_SetWindowData, [Window.by_ref, :string, :pointer], :pointer
110
+ api :SDL_GetWindowData, [Window.by_ref, :string], :pointer
111
+ api :SDL_SetWindowPosition, [Window.by_ref, :int, :int], :void
112
+ api :SDL_GetWindowPosition, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
113
+ api :SDL_SetWindowSize, [Window.by_ref, :int, :int], :void
114
+ api :SDL_GetWindowSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
115
+ api :SDL_SetWindowMaximumSize, [Window.by_ref, :int, :int], :void
116
+ api :SDL_GetWindowMaximumSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
117
+ api :SDL_SetWindowMinimumSize, [Window.by_ref, :int, :int], :void
118
+ api :SDL_GetWindowMinimumSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
119
+ api :SDL_SetWindowBordered, [Window.by_ref, :bool], :void
120
+ api :SDL_ShowWindow, [Window.by_ref], :void
121
+ api :SDL_HideWindow, [Window.by_ref], :void
122
+ api :SDL_RaiseWindow, [Window.by_ref], :void
123
+ api :SDL_MaximizeWindow, [Window.by_ref], :void
124
+ api :SDL_MinimizeWindow, [Window.by_ref], :void
125
+ api :SDL_RestoreWindow, [Window.by_ref], :void
126
+ api :SDL_SetWindowFullscreen, [Window.by_ref, :uint32], :int
127
+ api :SDL_GetWindowSurface, [Window.by_ref], Surface.by_ref
128
+ api :SDL_UpdateWindowSurface, [Window.by_ref], :int
129
+ api :SDL_UpdateWindowSurfaceRects, [Window.by_ref, Rect.by_ref, :int], :int
130
+ api :SDL_GetWindowGrab, [Window.by_ref], :bool
131
+ api :SDL_SetWindowGrab, [Window.by_ref, :bool], :void
132
+ api :SDL_GetWindowBrightness, [Window.by_ref], :float
133
+ api :SDL_SetWindowBrightness, [Window.by_ref, :float], :int
134
+ api :SDL_GetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
135
+ api :SDL_SetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
136
+ api :SDL_DestroyWindow, [Window.by_ref], :void
137
+ api :SDL_IsScreenSaverEnabled, [], :bool
138
+ api :SDL_DisableScreenSaver, [], :void
139
+ api :SDL_EnableScreenSaver, [], :void
140
+ api :SDL_GL_LoadLibrary, [:string], :int
141
+ api :SDL_GL_GetProcAddress, [:string], :pointer
142
+ api :SDL_GL_UnloadLibrary, [], :void
143
+ api :SDL_GL_ExtensionSupported, [:string], :bool
144
+ api :SDL_GL_SetAttribute, [:gl_attr, IntStruct], :int
145
+ api :SDL_GL_GetAttribute, [:gl_attr, IntStruct.by_ref], :int
146
+ api :SDL_GL_CreateContext, [Window.by_ref], :gl_context
147
+ api :SDL_GL_MakeCurrent, [Window.by_ref, :gl_context], :int
148
+ api :SDL_GL_GetCurrentWindow, [], Window.by_ref
149
+ api :SDL_GL_GetCurrentContext, [], :gl_context
150
+ api :SDL_GL_SetSwapInterval, [:int], :int
151
+ api :SDL_GL_GetSwapInterval, [], :int
152
+ api :SDL_GL_DeleteContext, [:gl_context], :void
153
+ api :SDL_GL_SwapWindow, [Window.by_ref], :void
154
+ end
@@ -0,0 +1,259 @@
1
+ require 'sdl2'
2
+ require 'sdl2/error'
3
+
4
+ #require 'sdl2/video'
5
+ require 'sdl2/surface'
6
+ require 'sdl2/display/mode'
7
+
8
+ module SDL2
9
+
10
+ # System Window
11
+ # A rectangular area you can blit into.
12
+ class Window < Struct
13
+ FULLSCREEN = 0x00000001
14
+ OPENGL = 0x00000002
15
+ SHOWN = 0x00000004
16
+ HIDDEN = 0x00000008
17
+ BORDERLESS = 0x00000010
18
+ RESIZABLE = 0x00000020
19
+ MINIMIZED = 0x00000040
20
+ MAXIMIZED = 0x00000080
21
+ INPUT_GRABBED = 0x00000100
22
+ INPUT_FOCUS = 0x00000200
23
+ MOUSE_FOCUS = 0x00000400
24
+ FULLSCREEN_DESKTOP = ( FULLSCREEN | 0x00001000 )
25
+ FOREIGN = 0x00000800
26
+
27
+ layout :magic, :pointer,
28
+ :id, :uint32,
29
+ :title, :string,
30
+ :icon, Surface.by_ref,
31
+ :x, :int,
32
+ :y, :int,
33
+ :w, :int,
34
+ :h, :int,
35
+ :min_w, :int,
36
+ :min_h, :int,
37
+ :max_w, :int,
38
+ :max_h, :int,
39
+ :flags, :uint32,
40
+ :windowed, Rect,
41
+ :fullscreen_mode, Display::Mode,
42
+ :brightness, :float,
43
+ :gamma, :pointer,
44
+ :saved_gamma, :pointer,
45
+ :surface, Surface.by_ref,
46
+ :surface_valid, :bool,
47
+ :shaper, :pointer, # TODO: WindowShaper.by_ref,
48
+ :data, :pointer,
49
+ :driverdata, :pointer,
50
+ :prev, Window.by_ref,
51
+ :next, Window.by_ref
52
+
53
+ class Data
54
+
55
+ def initialize(for_window)
56
+ @for_window = for_window
57
+ end
58
+
59
+ def [](name)
60
+ named(name)
61
+ end
62
+
63
+ def named(name)
64
+ SDL2.get_window_data(@for_window, name.to_s)
65
+ end
66
+
67
+ def named=(name, value)
68
+ SDL2.set_window_data(@for_window, name.to_s, value.to_s)
69
+ end
70
+ end
71
+
72
+ attr_reader :data
73
+
74
+ def initialize(*args, &block)
75
+ super(*args, &block)
76
+ @data = Data.new(self)
77
+ end
78
+
79
+ def self.create(title ='', x = 0, y = 0, w = 100, h = 100, flags = 0)
80
+ SDL2.create_window(title, x, y, w, h, flags)
81
+ end
82
+
83
+ def self.create_from(data)
84
+ create_window_from(data)
85
+ end
86
+
87
+ def self.from_id(id)
88
+ get_window_from_id(id)
89
+ end
90
+
91
+ def self.create!(*args)
92
+ creation = create(*args)
93
+ get_error() if creation.null?
94
+ return creation
95
+ end
96
+
97
+ def self.create_with_renderer(w, h, flags)
98
+ window = Window.new
99
+ renderer = Renderer.new
100
+ if SDL2.create_window_and_renderer(w,h,flags,window,renderer) == 0
101
+ [window, renderer]
102
+ else
103
+ nil
104
+ end
105
+ end
106
+
107
+ def self.release(pointer)
108
+ destroy_window(pointer)
109
+ end
110
+
111
+ def brightness
112
+ SDL2.get_window_brightness(self)
113
+ end
114
+
115
+ def brightness=(level)
116
+ SDL2.set_window_brightness(self, level.to_f)
117
+ end
118
+
119
+ def display_mode
120
+ dm = SDL2::Display::Mode.new
121
+ if SDL2.get_window_display_mode(self, dm) == 0
122
+ return dm
123
+ else
124
+ dm.pointer.free
125
+ return nil
126
+ end
127
+ end
128
+
129
+ def display_index
130
+ SDL2.get_window_display_index(self)
131
+ end
132
+
133
+ def display
134
+ Display[display_index]
135
+ end
136
+
137
+ def flags
138
+ SDL2.get_window_flags(self)
139
+ end
140
+
141
+ def grab?
142
+ get_window_grab(self) == :true
143
+ end
144
+
145
+ def grab=(value)
146
+ unless value == :true or value == :false
147
+ value = value ? :true : :false
148
+ end
149
+ set_window_grab(self, value)
150
+ end
151
+
152
+ def id
153
+ SDL2.get_window_id(self)
154
+ end
155
+
156
+ def pixel_format
157
+ SDL2.get_window_pixel_format(self)
158
+ end
159
+
160
+ def title
161
+ SDL2.get_window_title(self)
162
+ end
163
+
164
+ def title=(value)
165
+ SDL2.set_window_title(self, value)
166
+ end
167
+
168
+ def hide
169
+ SDL2.hide_window(self)
170
+ end
171
+
172
+ def maximize
173
+ SDL2.maximize_window(self)
174
+ end
175
+
176
+ def minimize
177
+ SDL2.minimize_window(self)
178
+ end
179
+
180
+ def raise_above
181
+ SDL2.raise_window(self)
182
+ end
183
+
184
+ def restore
185
+ SDL2.restore_window(self)
186
+ end
187
+
188
+ def show
189
+ SDL2.show_window(self)
190
+ end
191
+
192
+ def icon=(surface)
193
+ set_window_icon(self, surface)
194
+ end
195
+
196
+ def update_surface()
197
+ SDL2.update_window_surface(self)
198
+ end
199
+
200
+ def update_surface!()
201
+ SDL2.throw_error_unless update_surface == 0
202
+ return 0
203
+ end
204
+
205
+ def current_size()
206
+ w_struct, h_struct = IntStruct.new, IntStruct.new
207
+ SDL2::get_window_size(self, w_struct, h_struct)
208
+ w, h = w_struct[:value], h_struct[:value]
209
+ [w, h]
210
+ end
211
+
212
+ def current_size=(size)
213
+ SDL2.set_window_size(self, size[0], size[1])
214
+ end
215
+
216
+ def maximum_size
217
+ w_struct, h_struct = IntStruct.new, IntStruct.new
218
+ SDL2::get_window_maximum_size(self, w_struct, h_struct)
219
+ w, h = w_struct[:value], h_struct[:value]
220
+ [w, h]
221
+ end
222
+
223
+ def maximum_size=(size)
224
+ SDL2.set_window_maximum_size(self, size[0], size[1])
225
+ end
226
+
227
+ def minimum_size
228
+ w_struct, h_struct = IntStruct.new, IntStruct.new
229
+ SDL2::get_window_minimum_size(self, w_struct, h_struct)
230
+ w, h = w_struct[:value], h_struct[:value]
231
+ [w, h]
232
+ end
233
+
234
+ def minimum_size=(size)
235
+ SDL2.set_window_minimum_size(self, size[0], size[1])
236
+ end
237
+
238
+ def position
239
+ position = [IntStruct.new, IntStruct.new]
240
+ SDL2::get_window_position(self, position[0], position[1])
241
+ x, y = position[0][:value], position[1][:value]
242
+ position.each{|struct|struct.pointer.free}
243
+ [x, y]
244
+ end
245
+
246
+ def position=(location)
247
+ SDL2::set_window_position(self, location[0],location[1])
248
+ end
249
+
250
+ def surface
251
+ SDL2.get_window_surface(self)
252
+ end
253
+
254
+ def fullscreen=(flags)
255
+ SDL2.set_window_fullscreen(self, flags)
256
+ end
257
+ end
258
+
259
+ end
data/lib/sdl2.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'ffi'
2
+ require 'sdl2/sdl_module'
3
+ require 'active_support/inflector'
4
+
5
+ module SDL2
6
+ extend FFI::Library
7
+
8
+
9
+ # This converts the SDL Function Prototype name "SDL_XxxYyyyyZzz" to ruby's
10
+ # "xxx_yyyy_zzz" convetion
11
+ def self.api(func_name, args, type)
12
+ camelCaseName = func_name.to_s.gsub('SDL_','')
13
+ methodName = ActiveSupport::Inflector.underscore(camelCaseName).to_sym
14
+ print "Linking #{func_name} -> #{methodName}...."
15
+ self.attach_function methodName, func_name, args, type
16
+ puts "OK!"
17
+ return methodName
18
+ end
19
+
20
+ class Struct < FFI::Struct
21
+
22
+ def initialize(*args, &block)
23
+ super(*args)
24
+ if block_given?
25
+ throw 'Release must be defined to use block' unless self.class.respond_to?(:release)
26
+ yield self
27
+ self.class.release(self.pointer)
28
+ end
29
+ end
30
+ end
31
+
32
+ class ManagedStruct < FFI::ManagedStruct
33
+
34
+ def initialize(*args, &block)
35
+ super(*args)
36
+ if block_given?
37
+ throw 'Release must be defined to use block' unless self.class.respond_to?(:release)
38
+ yield self
39
+ self.class.release(self.pointer)
40
+ end
41
+ end
42
+ end
43
+
44
+ # TODO: Review default/hard-coded load paths?
45
+ ffi_lib SDL_MODULE
46
+
47
+ # SDL_Bool
48
+ enum :bool, [:false, 0, :true, 1]
49
+
50
+ def self.throw_error_unless(condition)
51
+ throw get_error() unless condition
52
+ end
53
+
54
+ def self.throw_error_if(condition)
55
+ throw get_error() if condition
56
+ end
57
+
58
+ # Simple Type Structures to interface 'typed-pointers'
59
+ # TODO: Research if this is the best way to handle 'typed-pointers'
60
+ class FloatStruct < FFI::Struct
61
+ layout :value, :float
62
+ end
63
+
64
+ class IntStruct < FFI::Struct
65
+ layout :value, :int
66
+ end
67
+
68
+ class UInt16Struct < FFI::Struct
69
+ layout :value, :uint16
70
+ end
71
+
72
+ class UInt32Struct < FFI::Struct
73
+ layout :value, :uint32
74
+ end
75
+
76
+ class UInt8Struct < FFI::Struct
77
+ layout :value, :uint8
78
+ end
79
+
80
+ # TODO: Review if this is the best place to put it.
81
+ # BlendMode is defined in a header file that is always included, so I'm
82
+ # defineing again here.
83
+ enum :blend_mode, [
84
+ :none, 0x00000000,
85
+ :blend, 0x00000001,
86
+ :add, 0x00000002,
87
+ :mod, 0x00000004
88
+ ]
89
+
90
+ class BlendModeStruct < FFI::Struct
91
+ layout :value, :blend_mode
92
+ end
93
+
94
+ typedef :uint32, :pixel_format
95
+
96
+ # Simple typedef to represent array sizes.
97
+ typedef :int, :count
98
+
99
+ end
data/lib/sdl2_ffi.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'sdl2'
2
+ require 'ffi'
3
+
4
+ # Alias the module, in case of confusion?
5
+ SDL2_FFI = SDL2
6
+ Sdl2_Ffi = SDL2
data/sdl2_ffi.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sdl2/gem_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sdl2_ffi'
8
+ spec.version = SDL2::GEM_VERSION
9
+ spec.authors = ['BadQuanta']
10
+ spec.email = ['BadQuanta@Gmail.com']
11
+ spec.description = %q{Foreign Function Interface to SDL2 in Ruby }
12
+ spec.summary = %q{Object Oriented wrapper for SDL2. Help me test & debug my interface.}
13
+ spec.homepage = 'https://github.com/BadQuanta/sdl2_ffi'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'ffi'
22
+ spec.add_dependency 'yinum'
23
+ spec.add_dependency 'activesupport'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'minitest', '~> 5.0.7'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'guard'
30
+ spec.add_development_dependency 'guard-minitest'
31
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+