sdl2_ffi 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -59
- data/lib/sdl2.rb +52 -15
- data/lib/sdl2/application.rb +71 -0
- data/lib/sdl2/audio.rb +72 -24
- data/lib/sdl2/clipboard.rb +9 -3
- data/lib/sdl2/color.rb +8 -3
- data/lib/sdl2/cpuinfo.rb +30 -10
- data/lib/sdl2/engine.rb +52 -0
- data/lib/sdl2/engine/block_engine.rb +27 -0
- data/lib/sdl2/engine/engines.rb +46 -0
- data/lib/sdl2/error.rb +9 -3
- data/lib/sdl2/events.rb +68 -6
- data/lib/sdl2/gamecontroller.rb +60 -20
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/gesture.rb +12 -4
- data/lib/sdl2/haptic.rb +90 -30
- data/lib/sdl2/hints.rb +12 -4
- data/lib/sdl2/image.rb +85 -3
- data/lib/sdl2/init.rb +15 -5
- data/lib/sdl2/joystick.rb +63 -21
- data/lib/sdl2/keyboard.rb +101 -17
- data/lib/sdl2/keycode.rb +72 -72
- data/lib/sdl2/library.rb +7 -0
- data/lib/sdl2/log.rb +78 -21
- data/lib/sdl2/mixer.rb +651 -0
- data/lib/sdl2/mixer/chunk.rb +47 -0
- data/lib/sdl2/mixer/lib_paths.rb +8 -0
- data/lib/sdl2/mouse.rb +39 -13
- data/lib/sdl2/pixels.rb +39 -13
- data/lib/sdl2/point.rb +29 -0
- data/lib/sdl2/power.rb +3 -1
- data/lib/sdl2/rect.rb +94 -19
- data/lib/sdl2/render.rb +156 -52
- data/lib/sdl2/rwops.rb +60 -20
- data/lib/sdl2/surface.rb +85 -28
- data/lib/sdl2/syswm.rb +3 -1
- data/lib/sdl2/timer.rb +18 -6
- data/lib/sdl2/touch.rb +12 -4
- data/lib/sdl2/ttf.rb +153 -59
- data/lib/sdl2/ttf/font.rb +21 -5
- data/lib/sdl2/version.rb +9 -3
- data/lib/sdl2/video.rb +210 -70
- data/lib/sdl2/window.rb +9 -3
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/defaults_to_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/has_a_button_sheet.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_down.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_in.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_up.approved.png +0 -0
- data/spec/fixtures/images/button_sheet.png +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +9 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +1 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +4 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +10 -22
- data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +121 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +30 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +116 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +57 -0
- data/spec/spec_helper.rb +3 -1
- metadata +31 -2
data/lib/sdl2/ttf/font.rb
CHANGED
@@ -84,26 +84,42 @@ module SDL2
|
|
84
84
|
end
|
85
85
|
|
86
86
|
alias_method :free, :close
|
87
|
-
|
88
|
-
def
|
87
|
+
|
88
|
+
def self.default_fg=(color)
|
89
|
+
@@default_fg = Color.cast(color)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.default_fg
|
93
|
+
@@default_fg ||= Color.cast([255,255,255, ALPHA_OPAQUE])
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.default_bg=(color)
|
97
|
+
@@default_bg = Color.cast(color)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.default_bg
|
101
|
+
@@default_bg ||= Color.cast([0,0,0,ALPHA_OPAQUE])
|
102
|
+
end
|
103
|
+
|
104
|
+
def render_text_solid(text, color = Font::default_fg)
|
89
105
|
color = Color.cast(color)
|
90
106
|
TTF.render_text_solid!(self, text, color)
|
91
107
|
end
|
92
108
|
|
93
|
-
def render_text_shaded(text, fg =
|
109
|
+
def render_text_shaded(text, fg = Font::default_fg, bg = Font::default_bg )
|
94
110
|
fg = Color.cast(fg)
|
95
111
|
bg = Color.cast(bg)
|
96
112
|
TTF.render_text_shaded!(self, text, fg, bg)
|
97
113
|
end
|
98
114
|
|
99
|
-
def render_text_blended(text, fg =
|
115
|
+
def render_text_blended(text, fg = Font::default_fg)
|
100
116
|
#binding.pry
|
101
117
|
fg = Color.cast(fg)
|
102
118
|
#binding.pry
|
103
119
|
TTF.render_text_blended!(self, text, fg)
|
104
120
|
end
|
105
121
|
|
106
|
-
def render_text_blended_wrapped(text, width, fg =
|
122
|
+
def render_text_blended_wrapped(text, width, fg = default_fg)
|
107
123
|
fg = Color.cast(fg)
|
108
124
|
TTF.render_text_blended_wrapped!(self, text, fg, width)
|
109
125
|
end
|
data/lib/sdl2/version.rb
CHANGED
@@ -36,7 +36,13 @@ module SDL2
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
##
|
40
|
+
#
|
41
|
+
api :SDL_GetRevision, [], :string
|
42
|
+
##
|
43
|
+
#
|
44
|
+
api :SDL_GetRevisionNumber, [], :int
|
45
|
+
##
|
46
|
+
#
|
47
|
+
api :SDL_GetVersion, [Version.by_ref], :void
|
42
48
|
end
|
data/lib/sdl2/video.rb
CHANGED
@@ -72,74 +72,214 @@ module SDL2
|
|
72
72
|
|
73
73
|
# This interface represents SDL_video.h function prototypes, lines 208~
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
75
|
+
##
|
76
|
+
#
|
77
|
+
api :SDL_GetNumVideoDrivers, [], :int
|
78
|
+
##
|
79
|
+
#
|
80
|
+
api :SDL_GetVideoDriver, [:int], :string
|
81
|
+
##
|
82
|
+
#
|
83
|
+
api :SDL_VideoInit, [:string], :int
|
84
|
+
##
|
85
|
+
#
|
86
|
+
api :SDL_VideoQuit, [], :void
|
87
|
+
##
|
88
|
+
#
|
89
|
+
api :SDL_GetCurrentVideoDriver, [], :string
|
90
|
+
##
|
91
|
+
#
|
92
|
+
api :SDL_GetNumVideoDisplays, [], :int
|
93
|
+
##
|
94
|
+
#
|
95
|
+
api :SDL_GetDisplayName, [:display_index], :string
|
96
|
+
##
|
97
|
+
#
|
98
|
+
api :SDL_GetDisplayBounds, [:int, Rect.by_ref], :int
|
99
|
+
##
|
100
|
+
#
|
101
|
+
api :SDL_GetNumDisplayModes, [:int], :int
|
102
|
+
##
|
103
|
+
#
|
104
|
+
api :SDL_GetDisplayMode, [:int, :int, Display::Mode.by_ref], :int
|
105
|
+
##
|
106
|
+
#
|
107
|
+
api :SDL_GetDesktopDisplayMode, [:int, Display::Mode.by_ref], :int
|
108
|
+
##
|
109
|
+
#
|
110
|
+
api :SDL_GetCurrentDisplayMode, [:int, Display::Mode.by_ref], :int
|
111
|
+
##
|
112
|
+
#
|
113
|
+
api :SDL_GetClosestDisplayMode, [:display_index, Display::Mode.by_ref, Display::Mode.by_ref], Display::Mode.by_ref
|
114
|
+
##
|
115
|
+
#
|
116
|
+
api :SDL_GetWindowDisplayIndex, [Window.by_ref], :int
|
117
|
+
##
|
118
|
+
#
|
119
|
+
api :SDL_SetWindowDisplayMode, [Window.by_ref, :uint32], :int
|
120
|
+
##
|
121
|
+
#
|
122
|
+
api :SDL_GetWindowDisplayMode, [Window.by_ref, Display::Mode.by_ref], :int
|
123
|
+
##
|
124
|
+
#
|
125
|
+
api :SDL_GetWindowPixelFormat, [Window.by_ref], :uint32
|
126
|
+
##
|
127
|
+
#
|
128
|
+
api :SDL_CreateWindow, [:string, :int, :int, :int, :int, :window_flags], Window.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
129
|
+
##
|
130
|
+
#
|
131
|
+
api :SDL_CreateWindowFrom, [:pointer], Window.auto_ptr
|
132
|
+
##
|
133
|
+
#
|
134
|
+
api :SDL_GetWindowFromID, [:uint32], Window.by_ref
|
135
|
+
##
|
136
|
+
#
|
137
|
+
api :SDL_GetWindowID, [Window.by_ref], :uint32
|
138
|
+
##
|
139
|
+
#
|
140
|
+
api :SDL_GetWindowFlags, [Window.by_ref], :uint32
|
141
|
+
##
|
142
|
+
#
|
143
|
+
api :SDL_GetWindowTitle, [Window.by_ref], :string
|
144
|
+
##
|
145
|
+
#
|
146
|
+
api :SDL_SetWindowTitle, [Window.by_ref, :string], :void
|
147
|
+
##
|
148
|
+
#
|
149
|
+
api :SDL_SetWindowIcon, [Window.by_ref, Surface.by_ref], :void
|
150
|
+
##
|
151
|
+
#
|
152
|
+
api :SDL_SetWindowData, [Window.by_ref, :string, :pointer], :pointer
|
153
|
+
##
|
154
|
+
#
|
155
|
+
api :SDL_GetWindowData, [Window.by_ref, :string], :pointer
|
156
|
+
##
|
157
|
+
#
|
158
|
+
api :SDL_SetWindowPosition, [Window.by_ref, :int, :int], :void
|
159
|
+
##
|
160
|
+
#
|
161
|
+
api :SDL_GetWindowPosition, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
|
162
|
+
##
|
163
|
+
#
|
164
|
+
api :SDL_SetWindowSize, [Window.by_ref, :int, :int], :void
|
165
|
+
##
|
166
|
+
#
|
167
|
+
api :SDL_GetWindowSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
|
168
|
+
##
|
169
|
+
#
|
170
|
+
api :SDL_SetWindowMaximumSize, [Window.by_ref, :int, :int], :void
|
171
|
+
##
|
172
|
+
#
|
173
|
+
api :SDL_GetWindowMaximumSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
|
174
|
+
##
|
175
|
+
#
|
176
|
+
api :SDL_SetWindowMinimumSize, [Window.by_ref, :int, :int], :void
|
177
|
+
##
|
178
|
+
#
|
179
|
+
api :SDL_GetWindowMinimumSize, [Window.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
|
180
|
+
##
|
181
|
+
#
|
182
|
+
api :SDL_SetWindowBordered, [Window.by_ref, :bool], :void
|
183
|
+
##
|
184
|
+
#
|
185
|
+
api :SDL_ShowWindow, [Window.by_ref], :void
|
186
|
+
##
|
187
|
+
#
|
188
|
+
api :SDL_HideWindow, [Window.by_ref], :void
|
189
|
+
##
|
190
|
+
#
|
191
|
+
api :SDL_RaiseWindow, [Window.by_ref], :void
|
192
|
+
##
|
193
|
+
#
|
194
|
+
api :SDL_MaximizeWindow, [Window.by_ref], :void
|
195
|
+
##
|
196
|
+
#
|
197
|
+
api :SDL_MinimizeWindow, [Window.by_ref], :void
|
198
|
+
##
|
199
|
+
#
|
200
|
+
api :SDL_RestoreWindow, [Window.by_ref], :void
|
201
|
+
##
|
202
|
+
#
|
203
|
+
api :SDL_SetWindowFullscreen, [Window.by_ref, :uint32], :int
|
204
|
+
##
|
205
|
+
#
|
206
|
+
api :SDL_GetWindowSurface, [Window.by_ref], Surface.by_ref
|
207
|
+
##
|
208
|
+
#
|
209
|
+
api :SDL_UpdateWindowSurface, [Window.by_ref], :int, {error: true}
|
210
|
+
##
|
211
|
+
#
|
212
|
+
api :SDL_UpdateWindowSurfaceRects, [Window.by_ref, Rect.by_ref, :int], :int, {error: true}
|
213
|
+
##
|
214
|
+
#
|
215
|
+
api :SDL_GetWindowGrab, [Window.by_ref], :bool
|
216
|
+
##
|
217
|
+
#
|
218
|
+
api :SDL_SetWindowGrab, [Window.by_ref, :bool], :void
|
219
|
+
##
|
220
|
+
#
|
221
|
+
api :SDL_GetWindowBrightness, [Window.by_ref], :float
|
222
|
+
##
|
223
|
+
#
|
224
|
+
api :SDL_SetWindowBrightness, [Window.by_ref, :float], :int
|
225
|
+
##
|
226
|
+
#
|
227
|
+
api :SDL_GetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
|
228
|
+
##
|
229
|
+
#
|
230
|
+
api :SDL_SetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
|
231
|
+
##
|
232
|
+
#
|
233
|
+
api :SDL_DestroyWindow, [Window.by_ref], :void
|
234
|
+
##
|
235
|
+
#
|
236
|
+
api :SDL_IsScreenSaverEnabled, [], :bool
|
237
|
+
##
|
238
|
+
#
|
239
|
+
api :SDL_DisableScreenSaver, [], :void
|
240
|
+
##
|
241
|
+
#
|
242
|
+
api :SDL_EnableScreenSaver, [], :void
|
243
|
+
##
|
244
|
+
#
|
245
|
+
api :SDL_GL_LoadLibrary, [:string], :int
|
246
|
+
##
|
247
|
+
#
|
248
|
+
api :SDL_GL_GetProcAddress, [:string], :pointer
|
249
|
+
##
|
250
|
+
#
|
251
|
+
api :SDL_GL_UnloadLibrary, [], :void
|
252
|
+
##
|
253
|
+
#
|
254
|
+
api :SDL_GL_ExtensionSupported, [:string], :bool
|
255
|
+
##
|
256
|
+
#
|
257
|
+
api :SDL_GL_SetAttribute, [:gl_attr, IntStruct], :int
|
258
|
+
##
|
259
|
+
#
|
260
|
+
api :SDL_GL_GetAttribute, [:gl_attr, IntStruct.by_ref], :int
|
261
|
+
##
|
262
|
+
#
|
263
|
+
api :SDL_GL_CreateContext, [Window.by_ref], :gl_context
|
264
|
+
##
|
265
|
+
#
|
266
|
+
api :SDL_GL_MakeCurrent, [Window.by_ref, :gl_context], :int
|
267
|
+
##
|
268
|
+
#
|
269
|
+
api :SDL_GL_GetCurrentWindow, [], Window.by_ref
|
270
|
+
##
|
271
|
+
#
|
272
|
+
api :SDL_GL_GetCurrentContext, [], :gl_context
|
273
|
+
##
|
274
|
+
#
|
275
|
+
api :SDL_GL_SetSwapInterval, [:int], :int
|
276
|
+
##
|
277
|
+
#
|
278
|
+
api :SDL_GL_GetSwapInterval, [], :int
|
279
|
+
##
|
280
|
+
#
|
281
|
+
api :SDL_GL_DeleteContext, [:gl_context], :void
|
282
|
+
##
|
283
|
+
#
|
284
|
+
api :SDL_GL_SwapWindow, [Window.by_ref], :void
|
145
285
|
end
|
data/lib/sdl2/window.rb
CHANGED
@@ -182,8 +182,14 @@ module SDL2
|
|
182
182
|
|
183
183
|
# Release memory utilized by structure
|
184
184
|
def self.release(pointer)
|
185
|
-
destroy_window(pointer)
|
185
|
+
destroy_window(self.new pointer)
|
186
186
|
end
|
187
|
+
|
188
|
+
def destroy
|
189
|
+
destroy_window(self)
|
190
|
+
end
|
191
|
+
|
192
|
+
alias_method :destroy, :free
|
187
193
|
|
188
194
|
# Return the brightness level
|
189
195
|
def brightness
|
@@ -288,7 +294,7 @@ module SDL2
|
|
288
294
|
|
289
295
|
# Update the window's surface
|
290
296
|
def update_surface()
|
291
|
-
SDL2.update_window_surface!(self)
|
297
|
+
SDL2.update_window_surface!(self)
|
292
298
|
end
|
293
299
|
|
294
300
|
# Get the window's current size
|
@@ -342,7 +348,7 @@ module SDL2
|
|
342
348
|
position = [IntStruct.new, IntStruct.new]
|
343
349
|
SDL2::get_window_position(self, position[0], position[1])
|
344
350
|
x, y = position[0][:value], position[1][:value]
|
345
|
-
position.each
|
351
|
+
position.each(&:free)
|
346
352
|
[x, y]
|
347
353
|
end
|
348
354
|
|
Binary file
|
Binary file
|
data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/defaults_to_mouse_out.approved.png
ADDED
Binary file
|
data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/has_a_button_sheet.approved.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,25 +1,31 @@
|
|
1
1
|
require_relative 'lazy_foo_helper'
|
2
2
|
|
3
|
+
require 'sdl2/ttf'
|
4
|
+
|
5
|
+
|
3
6
|
# ORIGINAL: http://lazyfoo.net/SDL_tutorials/lesson01/index2.php
|
4
7
|
# Adapted for Ruby & SDL 2.0 as functional test by BadQuanta
|
5
8
|
describe "LazyFoo.net: Lesson 01: Hello World" do
|
6
9
|
|
7
10
|
before do
|
8
|
-
expect(init(:EVERYTHING)).to eq(0)
|
11
|
+
#expect(init(:EVERYTHING)).to eq(0)
|
9
12
|
|
10
13
|
@window = Window.create(subject, :CENTERED, :CENTERED, 640, 480, :SHOWN)
|
11
14
|
|
12
15
|
@screen = @window.surface
|
16
|
+
@screen.fill_rect(@screen.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
|
13
17
|
|
14
18
|
@hello = @screen.convert(SDL2.load_bmp!(img_path('hello.bmp')))
|
15
19
|
@screen.blit_in(@hello)
|
20
|
+
@hello.blit_out(@screen)
|
16
21
|
@window.update_surface
|
17
22
|
# If you want to see it, uncomment the following:
|
18
23
|
#delay(2000)
|
19
24
|
end
|
20
25
|
|
21
26
|
it 'loaded and optimizes hello bitmap' do
|
22
|
-
|
27
|
+
#binding.pry
|
28
|
+
verify(format: :png){@hello}
|
23
29
|
end
|
24
30
|
|
25
31
|
it 'created a window surface' do
|
@@ -28,6 +34,7 @@ describe "LazyFoo.net: Lesson 01: Hello World" do
|
|
28
34
|
end
|
29
35
|
|
30
36
|
it 'draws hello to the window surface' do
|
37
|
+
#binding.pry
|
31
38
|
verify(format: :png){@screen}
|
32
39
|
end
|
33
40
|
|
@@ -11,6 +11,7 @@ describe "LazyFoo.net: Lesson 03: Extension Libraries" do
|
|
11
11
|
@window = Window.create(subject, :CENTERED, :CENTERED, 640, 480)
|
12
12
|
|
13
13
|
@screen = @window.surface
|
14
|
+
@screen.fill_rect(@screen.rect, [0,0,0,SDL2::ALPHA_OPAQUE])
|
14
15
|
|
15
16
|
a_png = @screen.convert(Image.load!(img_path('an_example.png')))
|
16
17
|
|