sdl2_ffi 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +0 -6
- data/Guardfile +0 -45
- data/README.md +11 -21
- data/lib/bad_sdl.rb +4 -0
- data/lib/{sdl2 → bad_sdl}/application.rb +47 -35
- data/lib/{sdl2 → bad_sdl}/engine.rb +20 -3
- data/lib/{sdl2 → bad_sdl}/engine/block_engine.rb +2 -2
- data/lib/bad_sdl/engine/engines.rb +51 -0
- data/lib/enumerable_constants.rb +4 -2
- data/lib/sdl2.rb +26 -247
- data/lib/sdl2/blendmode.rb +18 -0
- data/lib/sdl2/color.rb +1 -3
- data/lib/sdl2/debug.rb +58 -0
- data/lib/sdl2/display.rb +30 -23
- data/lib/sdl2/error.rb +6 -4
- data/lib/sdl2/event.rb +229 -0
- data/lib/sdl2/event/abstract.rb +11 -0
- data/lib/sdl2/event/action.rb +19 -0
- data/lib/sdl2/event/common.rb +10 -0
- data/lib/sdl2/event/controller_axis.rb +20 -0
- data/lib/sdl2/event/controller_button.rb +17 -0
- data/lib/sdl2/event/controller_device.rb +14 -0
- data/lib/sdl2/event/dollar_gesture.rb +19 -0
- data/lib/sdl2/event/drop.rb +18 -0
- data/lib/sdl2/event/joy_axis.rb +20 -0
- data/lib/sdl2/event/joy_ball.rb +20 -0
- data/lib/sdl2/event/joy_button.rb +18 -0
- data/lib/sdl2/event/joy_device.rb +14 -0
- data/lib/sdl2/event/joy_hat.rb +18 -0
- data/lib/sdl2/event/keyboard.rb +18 -0
- data/lib/sdl2/event/mouse_button.rb +21 -0
- data/lib/sdl2/event/mouse_motion.rb +19 -0
- data/lib/sdl2/event/mouse_wheel.rb +17 -0
- data/lib/sdl2/event/multi_gesture.rb +20 -0
- data/lib/sdl2/event/os.rb +12 -0
- data/lib/sdl2/event/quit.rb +12 -0
- data/lib/sdl2/event/state.rb +13 -0
- data/lib/sdl2/event/sys_wm.rb +15 -0
- data/lib/sdl2/event/text_editing.rb +17 -0
- data/lib/sdl2/event/text_input.rb +15 -0
- data/lib/sdl2/event/touch_finger.rb +20 -0
- data/lib/sdl2/event/type.rb +62 -0
- data/lib/sdl2/event/user.rb +15 -0
- data/lib/sdl2/event/window.rb +19 -0
- data/lib/sdl2/events.rb +23 -538
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/haptic.rb +3 -3
- data/lib/sdl2/hints.rb +3 -1
- data/lib/sdl2/image.rb +20 -20
- data/lib/sdl2/init.rb +5 -8
- data/lib/sdl2/joystick.rb +104 -78
- data/lib/sdl2/joystick/axes.rb +22 -0
- data/lib/sdl2/joystick/balls.rb +24 -0
- data/lib/sdl2/joystick/buttons.rb +22 -0
- data/lib/sdl2/joystick/components.rb +23 -0
- data/lib/sdl2/joystick/hats.rb +22 -0
- data/lib/sdl2/keyboard.rb +11 -10
- data/lib/sdl2/keycode.rb +70 -70
- data/lib/sdl2/library.rb +8 -7
- data/lib/sdl2/log.rb +6 -0
- data/lib/sdl2/managed_struct.rb +17 -0
- data/lib/sdl2/mixer.rb +16 -12
- data/lib/sdl2/mixer/chunk.rb +14 -3
- data/lib/sdl2/mouse.rb +21 -41
- data/lib/sdl2/pixel_format.rb +4 -4
- data/lib/sdl2/pixels.rb +59 -47
- data/lib/sdl2/power.rb +1 -1
- data/lib/sdl2/rect.rb +4 -5
- data/lib/sdl2/render.rb +85 -170
- data/lib/sdl2/renderer.rb +337 -20
- data/lib/sdl2/rwops.rb +89 -30
- data/lib/sdl2/stdinc.rb +18 -21
- data/lib/sdl2/struct.rb +184 -0
- data/lib/sdl2/struct_helper.rb +32 -0
- data/lib/sdl2/surface.rb +15 -14
- data/lib/sdl2/syswm.rb +26 -10
- data/lib/sdl2/syswm/msg.rb +22 -4
- data/lib/sdl2/texture.rb +106 -0
- data/lib/sdl2/touch.rb +16 -20
- data/lib/sdl2/ttf.rb +29 -29
- data/lib/sdl2/ttf/sdl_ttf_module.rb +1 -1
- data/lib/sdl2/typed_pointer.rb +45 -0
- data/lib/sdl2/union.rb +7 -0
- data/lib/sdl2/video.rb +97 -183
- data/lib/sdl2/window.rb +140 -90
- data/lib/struct_array.rb +42 -0
- data/sdl2_ffi.gemspec +3 -3
- data/spec/fixtures/approvals/lazyfoonet_lesson_03_advanced_timers/has_a_message.approved.png +0 -0
- 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_14_advanced_timers/has_a_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_drawn_something.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
- data/spec/fixtures/images/finger.png +0 -0
- data/spec/fixtures/music/beat.wav +0 -0
- data/spec/fixtures/sounds/high.wav +0 -0
- data/spec/fixtures/sounds/low.wav +0 -0
- data/spec/fixtures/sounds/medium.wav +0 -0
- data/spec/fixtures/sounds/scratch.wav +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +4 -6
- data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +3 -4
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +2 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +3 -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 +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +3 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +9 -7
- data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +11 -8
- data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +5 -4
- data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +17 -9
- data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +8 -7
- data/spec/functional/lazy_foo_tutorial/lazy_foo_13_advanced_timers_spec.rb +85 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_14_regulating_frame_rate_spec.rb +67 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_15_calculating_frame_rate_spec.rb +48 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_16_motion_spec.rb +95 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +3 -1
- data/spec/functional/lazy_foo_tutorial/timer.rb +55 -0
- data/spec/lib/bad_sdl/application_spec.rb +22 -0
- data/spec/{unit → lib}/sdl2/color_spec.rb +5 -1
- data/spec/lib/sdl2/display_spec.rb +6 -0
- data/spec/lib/sdl2/event_spec.rb +102 -0
- data/spec/lib/sdl2/events_spec.rb +12 -0
- data/spec/lib/sdl2/joystick_spec.rb +130 -0
- data/spec/lib/sdl2/keyboard_spec.rb +22 -0
- data/spec/lib/sdl2/mouse_spec.rb +21 -0
- data/spec/lib/sdl2/render_spec.rb +62 -0
- data/spec/lib/sdl2/renderer_spec.rb +224 -0
- data/spec/lib/sdl2/sdl2_helper.rb +5 -0
- data/spec/lib/sdl2/texture_spec.rb +65 -0
- data/{test/unit/sdl2/test_video.rb → spec/lib/sdl2/video_spec.rb} +82 -57
- data/spec/lib/sdl2/window_spec.rb +42 -0
- data/spec/{unit → lib}/unit_helper.rb +0 -0
- data/spec/png_writer.rb +9 -1
- data/spec/spec_helper.rb +5 -3
- metadata +201 -132
- data/lib/sdl2/engine/engines.rb +0 -46
- data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
- data/test/approvals/color_keying_example.approved.png +0 -0
- data/test/approvals/hello_world_example_hello.approved.png +0 -0
- data/test/approvals/hello_world_example_screen.approved.png +0 -0
- data/test/approvals/optimized_surface_loading.approved.png +0 -0
- data/test/fixtures/an_example.png +0 -0
- data/test/fixtures/background.bmp +0 -0
- data/test/fixtures/background.jpg +0 -0
- data/test/fixtures/color_bars.jpg +0 -0
- data/test/fixtures/foo.jpg +0 -0
- data/test/fixtures/hello.bmp +0 -0
- data/test/fixtures/sprites.jpg +0 -0
- data/test/fixtures/x.png +0 -0
- data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +0 -50
- data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +0 -42
- data/test/functional/examples/test_lazy_foo_examples.rb +0 -195
- data/test/functional/examples/test_readme_examples.rb +0 -15
- data/test/test_helper.rb +0 -13
- data/test/unit/sdl2/test_assert.rb +0 -10
- data/test/unit/sdl2/test_audio.rb +0 -9
- data/test/unit/sdl2/test_clipboard.rb +0 -13
- data/test/unit/sdl2/test_cpuinfo.rb +0 -11
- data/test/unit/sdl2/test_error.rb +0 -20
- data/test/unit/sdl2/test_events.rb +0 -31
- data/test/unit/sdl2/test_haptic.rb +0 -27
- data/test/unit/sdl2/test_hints.rb +0 -50
- data/test/unit/sdl2/test_image.rb +0 -9
- data/test/unit/sdl2/test_init.rb +0 -29
- data/test/unit/sdl2/test_keyboard.rb +0 -9
- data/test/unit/sdl2/test_log.rb +0 -80
- data/test/unit/sdl2/test_palette.rb +0 -26
- data/test/unit/sdl2/test_pixel_format.rb +0 -38
- data/test/unit/sdl2/test_pixels.rb +0 -24
- data/test/unit/sdl2/test_power.rb +0 -11
- data/test/unit/sdl2/test_rect.rb +0 -19
- data/test/unit/sdl2/test_render.rb +0 -58
- data/test/unit/sdl2/test_surface.rb +0 -88
- data/test/unit/sdl2/test_syswm.rb +0 -11
- data/test/unit/sdl2/test_timer.rb +0 -9
- data/test/unit/sdl2/test_ttf.rb +0 -11
- data/test/unit/sdl2/test_version.rb +0 -16
- data/test/unit/sdl2/test_window.rb +0 -155
- data/test/unit/test_scratch.rb +0 -19
- data/test/unit/test_sdl2.rb +0 -16
data/lib/sdl2/window.rb
CHANGED
@@ -7,23 +7,6 @@ require 'sdl2/display/mode'
|
|
7
7
|
|
8
8
|
module SDL2
|
9
9
|
|
10
|
-
# Window Flags Constants
|
11
|
-
module WINDOW
|
12
|
-
include EnumerableConstants
|
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
|
-
end
|
27
10
|
|
28
11
|
# Used to indicate that you don't care what the window position is.
|
29
12
|
module WINDOWPOS
|
@@ -62,28 +45,45 @@ module SDL2
|
|
62
45
|
# Event subtype for window events
|
63
46
|
module WINDOWEVENT
|
64
47
|
include EnumerableConstants
|
65
|
-
NONE
|
66
|
-
SHOWN
|
67
|
-
HIDDEN
|
68
|
-
EXPOSED
|
69
|
-
MOVED
|
70
|
-
RESIZED
|
71
|
-
SIZE_CHANGED
|
72
|
-
MINIMIZED
|
73
|
-
MAXIMIZED
|
74
|
-
RESTORED
|
75
|
-
ENTER
|
76
|
-
LEAVE
|
77
|
-
FOCUS_GAINED
|
78
|
-
FOCUS_LOST
|
79
|
-
CLOSE
|
48
|
+
NONE = next_const_value
|
49
|
+
SHOWN = next_const_value
|
50
|
+
HIDDEN = next_const_value
|
51
|
+
EXPOSED = next_const_value
|
52
|
+
MOVED = next_const_value
|
53
|
+
RESIZED = next_const_value
|
54
|
+
SIZE_CHANGED = next_const_value
|
55
|
+
MINIMIZED = next_const_value
|
56
|
+
MAXIMIZED = next_const_value
|
57
|
+
RESTORED = next_const_value
|
58
|
+
ENTER = next_const_value
|
59
|
+
LEAVE = next_const_value
|
60
|
+
FOCUS_GAINED = next_const_value
|
61
|
+
FOCUS_LOST = next_const_value
|
62
|
+
CLOSE = next_const_value
|
80
63
|
end
|
81
64
|
|
82
65
|
# System Window
|
83
66
|
# A rectangular area you can blit into.
|
84
67
|
class Window < Struct
|
85
|
-
|
86
|
-
|
68
|
+
##
|
69
|
+
# Window Flags Constants
|
70
|
+
module FLAGS
|
71
|
+
include EnumerableConstants
|
72
|
+
FULLSCREEN = 0x00000001
|
73
|
+
OPENGL = 0x00000002
|
74
|
+
SHOWN = 0x00000004
|
75
|
+
HIDDEN = 0x00000008
|
76
|
+
BORDERLESS = 0x00000010
|
77
|
+
RESIZABLE = 0x00000020
|
78
|
+
MINIMIZED = 0x00000040
|
79
|
+
MAXIMIZED = 0x00000080
|
80
|
+
INPUT_GRABBED = 0x00000100
|
81
|
+
INPUT_FOCUS = 0x00000200
|
82
|
+
MOUSE_FOCUS = 0x00000400
|
83
|
+
FULLSCREEN_DESKTOP = ( FULLSCREEN | 0x00001000 )
|
84
|
+
FOREIGN = 0x00000800
|
85
|
+
end
|
86
|
+
|
87
87
|
layout :magic, :pointer,
|
88
88
|
:id, :uint32,
|
89
89
|
:title, :string,
|
@@ -109,68 +109,86 @@ module SDL2
|
|
109
109
|
:driverdata, :pointer,
|
110
110
|
:prev, :pointer,
|
111
111
|
:next, :pointer
|
112
|
-
|
112
|
+
##
|
113
113
|
# A simple wrapper for data objects associated with a window.
|
114
114
|
class Data
|
115
|
-
|
115
|
+
##
|
116
116
|
# Create a data object manager for a given window
|
117
117
|
def initialize(for_window)
|
118
118
|
@for_window = for_window
|
119
119
|
end
|
120
|
-
|
120
|
+
##
|
121
121
|
# Return the data named
|
122
122
|
def named(name)
|
123
123
|
SDL2.get_window_data(@for_window, name.to_s)
|
124
124
|
end
|
125
|
-
|
125
|
+
##
|
126
|
+
#
|
126
127
|
alias_method :[], :named
|
127
|
-
|
128
|
+
##
|
128
129
|
# Set the data named to value specified.
|
129
130
|
def named=(name, value)
|
130
131
|
SDL2.set_window_data(@for_window, name.to_s, value.to_s)
|
131
132
|
end
|
132
|
-
|
133
|
+
##
|
134
|
+
#
|
133
135
|
alias_method :[]=, :named=
|
134
136
|
end
|
135
|
-
|
137
|
+
##
|
136
138
|
# The Window's data manager.
|
137
|
-
|
138
|
-
|
139
|
+
def data
|
140
|
+
@data ||= Data.new(self)
|
141
|
+
end
|
142
|
+
##
|
139
143
|
# Construct a new window.
|
140
144
|
def initialize(*args, &block)
|
141
145
|
super(*args, &block)
|
142
|
-
@data = Data.new(self)
|
143
146
|
end
|
144
|
-
|
147
|
+
##
|
148
|
+
# These are the defaults a Window is created with unless overridden
|
149
|
+
DEFAULT = {
|
150
|
+
title: "SDL2::Window",
|
151
|
+
x: :CENTERED,
|
152
|
+
y: :CENTERED,
|
153
|
+
width: 320,
|
154
|
+
height: 240,
|
155
|
+
flags: 0
|
156
|
+
}
|
157
|
+
##
|
145
158
|
# Construct a new window with given:
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
def self.create(
|
153
|
-
|
154
|
-
|
155
|
-
|
159
|
+
# * title: The caption to use for the window
|
160
|
+
# * x: The x-position of the window
|
161
|
+
# * y: The y-position of the window
|
162
|
+
# * w: The width of the window
|
163
|
+
# * h: The height of the window
|
164
|
+
# * flags: Window Flags to use in construction
|
165
|
+
def self.create(options = {})
|
166
|
+
o = DEFAULT.merge(options)
|
167
|
+
Debug.log(self){"Creating with options: #{o.inspect}"}
|
168
|
+
# TODO: Log unused option keys
|
169
|
+
SDL2.create_window!(o[:title], o[:x], o[:y], o[:width], o[:height], o[:flags])
|
170
|
+
end
|
171
|
+
##
|
156
172
|
# Constructs a new window from arbitrary system-specific structure
|
157
|
-
#
|
173
|
+
# * data: Some system-specific pointer
|
158
174
|
# See SDL Documentation
|
159
175
|
def self.create_from(data)
|
176
|
+
Debug.log(self){"Creating from data: #{data.inspect}"}
|
160
177
|
create_window_from!(data)
|
161
178
|
end
|
162
|
-
|
179
|
+
##
|
163
180
|
# Returns the identified window already created
|
164
|
-
#
|
181
|
+
# * id: The window identifier to retrieve
|
165
182
|
def self.from_id(id)
|
166
183
|
get_window_from_id!(id)
|
167
184
|
end
|
168
|
-
|
185
|
+
##
|
169
186
|
# Constructs both a window and a renderer
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
187
|
+
# * w: The Width of the pair to create
|
188
|
+
# * h: The Height of the pair to create
|
189
|
+
# * flags: Window flags to utilize in creation
|
173
190
|
def self.create_with_renderer(w, h, flags)
|
191
|
+
|
174
192
|
window = Window.new
|
175
193
|
renderer = Renderer.new
|
176
194
|
if SDL2.create_window_and_renderer(w,h,flags,window,renderer) == 0
|
@@ -179,18 +197,24 @@ module SDL2
|
|
179
197
|
nil
|
180
198
|
end
|
181
199
|
end
|
182
|
-
|
200
|
+
##
|
183
201
|
# Release memory utilized by structure
|
184
202
|
def self.release(pointer)
|
185
|
-
|
203
|
+
fc = caller.first
|
204
|
+
Debug.log(self){"Release ignored from #{fc}"}
|
186
205
|
end
|
187
|
-
|
206
|
+
##
|
207
|
+
# Tell SDL we are done with the window. Any further use could result in a crash.
|
188
208
|
def destroy
|
189
|
-
|
209
|
+
unless self.null?
|
210
|
+
SDL2.destroy_window(self)
|
211
|
+
else
|
212
|
+
Debug.log(self){"Destruction of window null window requested."}
|
213
|
+
end
|
190
214
|
end
|
191
215
|
|
192
|
-
alias_method :destroy, :free
|
193
216
|
|
217
|
+
##
|
194
218
|
# Return the brightness level
|
195
219
|
def brightness
|
196
220
|
SDL2.get_window_brightness(self)
|
@@ -198,18 +222,15 @@ module SDL2
|
|
198
222
|
|
199
223
|
# Set the brightness level
|
200
224
|
def brightness=(level)
|
225
|
+
Debug.log(self){"Setting brightness to: #{level}"}
|
201
226
|
SDL2.set_window_brightness(self, level.to_f)
|
202
227
|
end
|
203
228
|
|
204
229
|
# Get a copy of the DisplayMode structure
|
205
230
|
def display_mode
|
206
231
|
dm = SDL2::Display::Mode.new
|
207
|
-
|
208
|
-
|
209
|
-
else
|
210
|
-
dm.pointer.free
|
211
|
-
return nil
|
212
|
-
end
|
232
|
+
SDL2.get_window_display_mode!(self, dm)
|
233
|
+
dm
|
213
234
|
end
|
214
235
|
|
215
236
|
# Get the display index associated with this window
|
@@ -300,14 +321,22 @@ module SDL2
|
|
300
321
|
# Get the window's current size
|
301
322
|
# @return Array => [<width>, <height>]
|
302
323
|
def current_size()
|
303
|
-
|
304
|
-
SDL2::get_window_size(self,
|
305
|
-
|
306
|
-
|
324
|
+
size = 2.times.map{TypedPointer::Int.new}
|
325
|
+
SDL2::get_window_size(self, *size)
|
326
|
+
size.map(&:value)
|
327
|
+
end
|
328
|
+
|
329
|
+
def width
|
330
|
+
current_size[0]
|
331
|
+
end
|
332
|
+
|
333
|
+
def height
|
334
|
+
current_size[1]
|
307
335
|
end
|
308
336
|
|
337
|
+
|
309
338
|
# Set the window's current size
|
310
|
-
#
|
339
|
+
# * size: A array containing the [width,height]
|
311
340
|
def current_size=(size)
|
312
341
|
SDL2.set_window_size(self, size[0], size[1])
|
313
342
|
end
|
@@ -315,14 +344,13 @@ module SDL2
|
|
315
344
|
# Get the window's maximum_size
|
316
345
|
# @return Array => [<width>, <height>]
|
317
346
|
def maximum_size
|
318
|
-
|
319
|
-
SDL2::get_window_maximum_size(self,
|
320
|
-
|
321
|
-
[w, h]
|
347
|
+
size = 2.times.map{TypedPointer::Int.new}
|
348
|
+
SDL2::get_window_maximum_size(self, *size)
|
349
|
+
size.map(&:value)
|
322
350
|
end
|
323
351
|
|
324
352
|
# Set the window's maximum size
|
325
|
-
#
|
353
|
+
# * size: A array containing the [width,height]
|
326
354
|
def maximum_size=(size)
|
327
355
|
SDL2.set_window_maximum_size(self, size[0], size[1])
|
328
356
|
end
|
@@ -330,14 +358,13 @@ module SDL2
|
|
330
358
|
# Get the window's minimum size
|
331
359
|
# @return Array => [<width>, <height>]
|
332
360
|
def minimum_size
|
333
|
-
|
334
|
-
SDL2::get_window_minimum_size(self,
|
335
|
-
|
336
|
-
[w, h]
|
361
|
+
size = 2.times.map{TypedPointer::Int.new}
|
362
|
+
SDL2::get_window_minimum_size(self, *size)
|
363
|
+
size.map(&:value)
|
337
364
|
end
|
338
365
|
|
339
366
|
# Set the window's minimum size
|
340
|
-
#
|
367
|
+
# * size: A array containing the [width,height]
|
341
368
|
def minimum_size=(size)
|
342
369
|
SDL2.set_window_minimum_size(self, size[0], size[1])
|
343
370
|
end
|
@@ -345,7 +372,7 @@ module SDL2
|
|
345
372
|
# Get the window's position
|
346
373
|
# @return Array => [<x>, <y>]
|
347
374
|
def position
|
348
|
-
position = [
|
375
|
+
position = [TypedPointer::Int.new, TypedPointer::Int.new]
|
349
376
|
SDL2::get_window_position(self, position[0], position[1])
|
350
377
|
x, y = position[0][:value], position[1][:value]
|
351
378
|
position.each(&:free)
|
@@ -353,7 +380,7 @@ module SDL2
|
|
353
380
|
end
|
354
381
|
|
355
382
|
# Set the window's position
|
356
|
-
#
|
383
|
+
# * size: A array containing the [x,y]
|
357
384
|
def position=(location)
|
358
385
|
SDL2::set_window_position(self, location[0],location[1])
|
359
386
|
end
|
@@ -367,6 +394,29 @@ module SDL2
|
|
367
394
|
def fullscreen=(flags)
|
368
395
|
SDL2.set_window_fullscreen(self, flags)
|
369
396
|
end
|
397
|
+
##
|
398
|
+
|
399
|
+
##
|
400
|
+
# Returns the renderer associated with this window
|
401
|
+
def renderer
|
402
|
+
SDL2.get_renderer(self)
|
403
|
+
end
|
404
|
+
# Utility function that returns an SDL2::Surface of a given render.
|
405
|
+
# Defaults to the renderer returned by SDL_GetRenderer(window=self)
|
406
|
+
# Added by BadQuanta originally for approval testing.
|
407
|
+
def renderer_to_surface(renderer = renderer)
|
408
|
+
w, h = renderer.output_size
|
409
|
+
fmt = surface.format
|
410
|
+
surface = SDL2::Surface.create_rgb(0,w,h,
|
411
|
+
fmt.bits_per_pixel,
|
412
|
+
fmt.r_mask,
|
413
|
+
fmt.g_mask,
|
414
|
+
fmt.b_mask,
|
415
|
+
fmt.a_mask
|
416
|
+
)
|
417
|
+
SDL2.render_read_pixels!(renderer, nil, fmt.format, surface.pixels, surface.pitch)
|
418
|
+
surface
|
419
|
+
end
|
370
420
|
end
|
371
421
|
|
372
422
|
end
|
data/lib/struct_array.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module SDL2
|
2
|
+
class StructArray
|
3
|
+
|
4
|
+
def self.clone_from(array, struct_class)
|
5
|
+
cloned_array = self.new(struct_class, array.count)
|
6
|
+
array.each_with_index do |item, idx|
|
7
|
+
cloned_array[idx].update_members(item)
|
8
|
+
end
|
9
|
+
cloned_array
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(struct_class, count)
|
14
|
+
@count = count
|
15
|
+
@struct_class = struct_class
|
16
|
+
# TODO: Make sure this will free the memory when this
|
17
|
+
# struct array is garbage collected.
|
18
|
+
@pointer = FFI::MemoryPointer.new(struct_class, @count)
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :pointer, :count
|
22
|
+
|
23
|
+
def [](idx)
|
24
|
+
raise "Invalid index #{idx}, count is #{@count}" unless (0 <= idx) and (idx < @count)
|
25
|
+
@struct_class.new(pointer + (idx*@struct_class.size))
|
26
|
+
end
|
27
|
+
|
28
|
+
def first(count = nil)
|
29
|
+
if count.nil?
|
30
|
+
self[0]
|
31
|
+
else
|
32
|
+
count.times.map do |idx|
|
33
|
+
self[idx]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def last
|
39
|
+
self[@count-1]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/sdl2_ffi.gemspec
CHANGED
@@ -20,15 +20,15 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'ffi'
|
22
22
|
spec.add_dependency 'activesupport'
|
23
|
-
|
23
|
+
|
24
|
+
spec.add_development_dependency 'approvals'
|
24
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
-
spec.add_development_dependency 'minitest', '~> 5.0.7' # TODO: Remove Minitest?
|
26
26
|
spec.add_development_dependency 'rspec', '~> 2.0'
|
27
27
|
spec.add_development_dependency 'rake'
|
28
28
|
spec.add_development_dependency 'pry'
|
29
29
|
spec.add_development_dependency 'guard'
|
30
|
-
#spec.add_development_dependency 'guard-minitest'
|
31
30
|
spec.add_development_dependency 'guard-rspec'
|
31
|
+
spec.add_development_dependency 'ruby-prof'
|
32
32
|
spec.add_development_dependency 'yard'
|
33
33
|
|
34
34
|
|
Binary file
|
Binary file
|
Binary file
|
data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_drawn_something.approved.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|