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/stdinc.rb
CHANGED
@@ -26,28 +26,25 @@ module SDL2
|
|
26
26
|
# These are for internal use mostly, they test the return result
|
27
27
|
# of a function that can return an error. They are designed to
|
28
28
|
# return TRUE if there is NOT_AN_ERROR
|
29
|
-
|
30
|
-
#Filter Proc, True when arg equals zero
|
31
|
-
TRUE_WHEN_ZERO = Proc.new do |result|
|
32
|
-
# Handles both Negative and Positive error values.
|
33
|
-
result == 0
|
34
|
-
end
|
35
|
-
|
36
|
-
TRUE_WHEN_ONE = Proc.new{|result| result == 1}
|
37
|
-
|
38
|
-
TRUE_WHEN_NOT_ZERO = Proc.new do |result|
|
39
|
-
result != 0
|
40
|
-
end
|
41
|
-
|
42
|
-
# Filter Proc, True when arg not null?
|
43
|
-
TRUE_WHEN_NOT_NULL = Proc.new do |result|
|
44
|
-
# Anything but nil/null is considered valid.
|
45
|
-
(!result.null?)
|
46
|
-
end
|
47
29
|
|
48
|
-
|
49
|
-
|
50
|
-
|
30
|
+
##
|
31
|
+
# When the result is zero, everything is ok.
|
32
|
+
OK_WHEN_ZERO = Proc.new { |result| result == 0 }
|
33
|
+
##
|
34
|
+
# When the result is one, everything is ok
|
35
|
+
OK_WHEN_ONE = Proc.new{|result| result == 1}
|
36
|
+
##
|
37
|
+
# When the result must be positive
|
38
|
+
OK_WHEN_GTE_ZERO = Proc.new{|result| result >= 0}
|
39
|
+
##
|
40
|
+
# When result is anything but zero
|
41
|
+
OK_WHEN_NOT_ZERO = Proc.new { |result| result != 0 }
|
42
|
+
##
|
43
|
+
# When resultnot null?
|
44
|
+
OK_WHEN_NOT_NULL = Proc.new { |result| (!result.nil?) and (!result.null?) }
|
45
|
+
##
|
46
|
+
# When result is true
|
47
|
+
OK_WHEN_TRUE = Proc.new { |result| result == true }
|
51
48
|
|
52
49
|
# NOTE: None of the SDL Memory Macros/Externals
|
53
50
|
|
data/lib/sdl2/struct.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
module SDL2
|
2
|
+
##
|
3
|
+
# BadQuanta: sdl2_ffi messes with the FFI::Struct class for some useful additions.
|
4
|
+
class Struct < FFI::Struct
|
5
|
+
extend StructHelper
|
6
|
+
##
|
7
|
+
# Allows creation and use within block, automatically freeing pointer after block.
|
8
|
+
def initialize(*args, &block)
|
9
|
+
Debug.log(self){"Initializing with args: #{args.inspect}"}
|
10
|
+
super(*args)
|
11
|
+
if block_given?
|
12
|
+
Debug.log(self){'Block given, will be disposed of later'}
|
13
|
+
throw 'Release must be defined to use block' unless self.class.respond_to?(:release)
|
14
|
+
yield self
|
15
|
+
Debug.log(self){'Block returned, now disposing.'}
|
16
|
+
self.class.release(self.pointer)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Placeholder for Structs that need to initialize values.
|
22
|
+
def self.create(values = {})
|
23
|
+
Debug.log(self){"Constructing with values: #{values.inspect}"}
|
24
|
+
created = self.new
|
25
|
+
created.update_members(values)
|
26
|
+
created
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# A default release scheme is defined, but should be redefined where appropriate.
|
31
|
+
def self.release(pointer)
|
32
|
+
Debug.log(self){"Freeing pointer: #{pointer.inspect}"}
|
33
|
+
pointer.free
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# A default free operation, but should be redefined where appropriate.
|
38
|
+
# TODO: Is this wrong to do in conjuction with release?
|
39
|
+
def free()
|
40
|
+
if self.pointer.autorelease?
|
41
|
+
Debug.log(self){"Freeing autorelease pointer: #{pointer.inspect}"}
|
42
|
+
self.pointer.free
|
43
|
+
else
|
44
|
+
Debug.log(self){"Not freeing pointer"}
|
45
|
+
binding.pry
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# A human-readable representation of the struct and it's values.
|
50
|
+
#def inspect
|
51
|
+
# return 'nil' if self.null?
|
52
|
+
#
|
53
|
+
# #binding.pry
|
54
|
+
# #return self.to_s
|
55
|
+
#
|
56
|
+
# report = "struct #{self.class.to_s}{"
|
57
|
+
# report += self.class.members.collect do |field|
|
58
|
+
# "#{field}->#{self[field].inspect}"
|
59
|
+
# end.join(' ')
|
60
|
+
# report += "}"
|
61
|
+
# end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Compare two structures by class and values.
|
65
|
+
# This will return true when compared to a "partial hash" and
|
66
|
+
# all the key/value pairs the hash defines equal the
|
67
|
+
# corrisponding members in the structure.
|
68
|
+
# Otherwise all values must match between structures.
|
69
|
+
# TODO: CLEAN UP THIS COMPARISON CODE!!!
|
70
|
+
def ==(other)
|
71
|
+
Debug.log(self){
|
72
|
+
"COMPARING #{self} to #{other}"
|
73
|
+
}
|
74
|
+
|
75
|
+
result = catch(:result) do
|
76
|
+
unless self.class == other.class or other.kind_of? Hash
|
77
|
+
Debug.log(self){"Class Mismatch"}
|
78
|
+
throw :result, false
|
79
|
+
end
|
80
|
+
|
81
|
+
if (other.kind_of? Hash) and (other.keys - members).any?
|
82
|
+
Debug.log(self){"Extra Keys: #{other.keys-members}"}
|
83
|
+
thorw :result, false
|
84
|
+
end
|
85
|
+
|
86
|
+
if (other.respond_to?:null?) and (self.null? or other.null?)
|
87
|
+
unless self.null? and other.null?
|
88
|
+
Debug.log(self){"AHHHAOne is null and the other is not"}
|
89
|
+
throw :result, false
|
90
|
+
end
|
91
|
+
else
|
92
|
+
fields = other.kind_of?(Hash) ? members & other.keys : members
|
93
|
+
fields.each do |field|
|
94
|
+
Debug.log(self){"#{field}:#{self[field].class} = "}
|
95
|
+
|
96
|
+
unless self[field] == other[field]
|
97
|
+
|
98
|
+
Debug.log(self){"NO MATCH: #{self[field].to_s} #{other[field].to_s}"}
|
99
|
+
throw :result, false
|
100
|
+
end
|
101
|
+
Debug.log(self){"MATCH"}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Everything passed
|
106
|
+
throw :result, true
|
107
|
+
|
108
|
+
end
|
109
|
+
Debug.log(self){
|
110
|
+
"RESULT = #{result}"
|
111
|
+
}
|
112
|
+
return result
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Default cast handler.
|
117
|
+
#
|
118
|
+
#
|
119
|
+
# BadQuanta says:
|
120
|
+
# Casting means to take something and try to make it into a Structure
|
121
|
+
# - Other instances of the same class (simply returns that instance)
|
122
|
+
# - Any hash, this structure will be "created" with the has specifying members.
|
123
|
+
# - A nil object, which will return the same nil object assuming that is o.k.
|
124
|
+
def self.cast(something)
|
125
|
+
if something.kind_of? self
|
126
|
+
Debug.log(self){'No casting required.'}
|
127
|
+
return something
|
128
|
+
elsif something.kind_of? Hash
|
129
|
+
Debug.log(self){'Attempting to construct from hash.'}
|
130
|
+
return self.create(something)
|
131
|
+
elsif something.nil?
|
132
|
+
Debug.log(self){'Something is nil, returning nil.'}
|
133
|
+
return something #TODO: Assume NUL is ok?
|
134
|
+
else
|
135
|
+
# No need for a debug message, exception will act as one.
|
136
|
+
raise "#{self} can't cast #{something.insepct}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Set members to values contained within hash.
|
142
|
+
def update_members(values)
|
143
|
+
Debug.log(self){"Updating members from values: #{values.inspect}"}
|
144
|
+
if values.kind_of? Array
|
145
|
+
raise "#{self} has less fields then #{values.inspect}" if values.count > members.count
|
146
|
+
Debug.log(self){"Field to value map: #{Hash.new(members.first(values.count).zip(values)).inspect}"}
|
147
|
+
members.first(values.count).each_with_index do |field, idx|
|
148
|
+
self[field] = values[idx]
|
149
|
+
end
|
150
|
+
elsif values.kind_of? Hash
|
151
|
+
common = (self.members & values.keys)
|
152
|
+
Debug.log(self){
|
153
|
+
ignored_keys = values.keys - common
|
154
|
+
ignored_keys.empty? ? "All hash keys mapped to struct members." : "Ignored these value keys: #{ignored_keys.inspect}"
|
155
|
+
}
|
156
|
+
common.each do |field|
|
157
|
+
unless self[field].kind_of?(Struct)
|
158
|
+
self[field] = values[field]
|
159
|
+
else
|
160
|
+
self[field] = self[field].class.cast(values[field])
|
161
|
+
end
|
162
|
+
end
|
163
|
+
elsif values.kind_of? self.class
|
164
|
+
Debug.log(self){'Coping values from another instance.'}
|
165
|
+
members.each do |member|
|
166
|
+
self[member] = values[member]
|
167
|
+
end
|
168
|
+
else
|
169
|
+
raise "#{self}#update_members unable to update from #{values.inspect}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# Human readable translation of a structure
|
175
|
+
def to_s
|
176
|
+
null = self.to_ptr.null?
|
177
|
+
values = members.map do |member|
|
178
|
+
"#{member}=#{null ? 'null' : self[member]}"
|
179
|
+
end unless null
|
180
|
+
"<#{self.class.to_s} #{null ? 'NULL' : values.join(' ')}>"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
module SDL2
|
3
|
+
##
|
4
|
+
# A struct helper provides member_reader/member_writer helpers for quickly accessing those damn members.
|
5
|
+
# This is extended into sdl2_ffi's usage of Structs, ManagedStructs, and Unions. Do I know exatcly what I'm
|
6
|
+
# doing, no... but teach me what I'm doing wrong.
|
7
|
+
module StructHelper
|
8
|
+
# Define a set of member readers
|
9
|
+
# Ex1: `member_readers [:one, :two, :three]`
|
10
|
+
# Ex2: `member_readers *members`
|
11
|
+
def member_readers(*members_to_define)
|
12
|
+
members_to_define.each do |member|
|
13
|
+
define_method member do
|
14
|
+
self[member]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
# Define a set of member writers
|
21
|
+
# Ex1: `member_writers [:one, :two, :three]`
|
22
|
+
# Ex2: `member_writers *members`
|
23
|
+
def member_writers(*members_to_define)
|
24
|
+
members_to_define.each do |member|
|
25
|
+
define_method "#{member}=".to_sym do |value|
|
26
|
+
self[member]= value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/sdl2/surface.rb
CHANGED
@@ -21,6 +21,7 @@ module SDL2
|
|
21
21
|
:format, PixelFormat.by_ref,
|
22
22
|
:w, :int,
|
23
23
|
:h, :int,
|
24
|
+
:pitch, :int,
|
24
25
|
:pixels, :pointer,
|
25
26
|
:userdata, :pointer,
|
26
27
|
:locked, :int,
|
@@ -128,7 +129,7 @@ module SDL2
|
|
128
129
|
alias_method :rle=, :set_rle
|
129
130
|
|
130
131
|
# Sets the color key for this surface.
|
131
|
-
#
|
132
|
+
# * key may be 1) A pixel value encoded for this surface's format
|
132
133
|
# 2) Anything that Color::cast can handle.
|
133
134
|
# 3) Nil, which will disable the color key for this surface.
|
134
135
|
def set_color_key(key)
|
@@ -149,7 +150,7 @@ module SDL2
|
|
149
150
|
# Gets the color key for this surface.
|
150
151
|
# @returns Nil, indicating no color keying, or the encoded pixel value used.
|
151
152
|
def get_color_key()
|
152
|
-
key_s =
|
153
|
+
key_s = TypedPointer::UInt32.new
|
153
154
|
if SDL2.get_color_key?(self, key_s)
|
154
155
|
result = key_s[:value]
|
155
156
|
else
|
@@ -190,7 +191,7 @@ module SDL2
|
|
190
191
|
|
191
192
|
##
|
192
193
|
#
|
193
|
-
api :SDL_CreateRGBSurface, [:surface_flags, :int, :int, :int, :uint32, :uint32, :uint32, :uint32], Surface.
|
194
|
+
api :SDL_CreateRGBSurface, [:surface_flags, :int, :int, :int, :uint32, :uint32, :uint32, :uint32], Surface.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
194
195
|
##
|
195
196
|
#
|
196
197
|
api :SDL_FreeSurface, [Surface.by_ref], :void
|
@@ -205,14 +206,14 @@ module SDL2
|
|
205
206
|
api :SDL_UnlockSurface, [Surface.by_ref], :void
|
206
207
|
##
|
207
208
|
#
|
208
|
-
api :SDL_LoadBMP_RW, [RWops.by_ref, :int], Surface.
|
209
|
+
api :SDL_LoadBMP_RW, [RWops.by_ref, :int], Surface.ptr
|
209
210
|
|
210
211
|
# Redefine SDL_LoadBMP macro:
|
211
212
|
def self.load_bmp(file)
|
212
213
|
SDL2.load_bmp_rw(RWops.from_file(file, 'rb'), 1)
|
213
214
|
end
|
214
215
|
|
215
|
-
returns_error(:load_bmp,
|
216
|
+
returns_error(:load_bmp,OK_WHEN_NOT_NULL)
|
216
217
|
|
217
218
|
##
|
218
219
|
#
|
@@ -230,27 +231,27 @@ module SDL2
|
|
230
231
|
api :SDL_SetColorKey, [Surface.by_ref, :bool, :uint32], :int, {error: true}
|
231
232
|
##
|
232
233
|
#
|
233
|
-
api :SDL_GetColorKey, [Surface.by_ref,
|
234
|
+
api :SDL_GetColorKey, [Surface.by_ref, TypedPointer::UInt32.by_ref], :uint32, {error: true}
|
234
235
|
# Could mean an SDL error... or maybe not?
|
235
|
-
boolean? :get_color_key,
|
236
|
+
boolean? :get_color_key, OK_WHEN_ZERO
|
236
237
|
##
|
237
238
|
#
|
238
239
|
api :SDL_SetSurfaceColorMod, [Surface.by_ref, :uint8, :uint8, :uint8], :int
|
239
240
|
##
|
240
241
|
#
|
241
|
-
api :SDL_GetSurfaceColorMod, [Surface.by_ref,
|
242
|
+
api :SDL_GetSurfaceColorMod, [Surface.by_ref, TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref], :int
|
242
243
|
##
|
243
244
|
#
|
244
245
|
api :SDL_SetSurfaceAlphaMod, [Surface.by_ref, :uint8], :int, {error: true}
|
245
246
|
##
|
246
247
|
#
|
247
|
-
api :SDL_GetSurfaceAlphaMod, [Surface.by_ref,
|
248
|
+
api :SDL_GetSurfaceAlphaMod, [Surface.by_ref,TypedPointer::UInt8.by_ref], :int, {error: true}
|
248
249
|
##
|
249
250
|
#
|
250
251
|
api :SDL_SetSurfaceBlendMode, [Surface.by_ref, :blend_mode], :int, {error: true}
|
251
252
|
##
|
252
253
|
#
|
253
|
-
api :SDL_GetSurfaceBlendMode, [Surface.by_ref,
|
254
|
+
api :SDL_GetSurfaceBlendMode, [Surface.by_ref, SDL2::TypedPointer::BlendMode.by_ref], :int, {error: true}
|
254
255
|
##
|
255
256
|
#
|
256
257
|
api :SDL_SetClipRect, [Surface.by_ref, Rect.by_ref], :int, {error: true}
|
@@ -259,10 +260,10 @@ module SDL2
|
|
259
260
|
api :SDL_GetClipRect, [Surface.by_ref, Rect.by_ref], :int, {error: true}
|
260
261
|
##
|
261
262
|
#
|
262
|
-
api :SDL_ConvertSurface, [Surface.by_ref, PixelFormat.by_ref, :surface_flags], Surface.
|
263
|
+
api :SDL_ConvertSurface, [Surface.by_ref, PixelFormat.by_ref, :surface_flags], Surface.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
263
264
|
##
|
264
265
|
#
|
265
|
-
api :SDL_ConvertSurfaceFormat, [Surface.by_ref, :pixel_format, :surface_flags], Surface.
|
266
|
+
api :SDL_ConvertSurfaceFormat, [Surface.by_ref, :pixel_format, :surface_flags], Surface.ptr
|
266
267
|
##
|
267
268
|
#
|
268
269
|
api :SDL_ConvertPixels, [:int, :int, :pixel_format, :pointer, :int, :pixel_format, :pointer, :int], :int, {error: true}
|
@@ -282,7 +283,7 @@ module SDL2
|
|
282
283
|
upper_blit(src, srcrect, dst, dstrect)
|
283
284
|
end
|
284
285
|
|
285
|
-
returns_error(:blit_surface,
|
286
|
+
returns_error(:blit_surface, OK_WHEN_ZERO)
|
286
287
|
|
287
288
|
##
|
288
289
|
#
|
@@ -299,7 +300,7 @@ module SDL2
|
|
299
300
|
upper_blit_scaled(src, srcrect, dst, dstrect)
|
300
301
|
end
|
301
302
|
|
302
|
-
returns_error(:blit_scaled,
|
303
|
+
returns_error(:blit_scaled, OK_WHEN_ZERO)
|
303
304
|
|
304
305
|
##
|
305
306
|
#
|
data/lib/sdl2/syswm.rb
CHANGED
@@ -4,19 +4,35 @@ require 'sdl2/video'
|
|
4
4
|
require 'sdl2/syswm/info'
|
5
5
|
require 'sdl2/syswm/msg'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
##
|
8
|
+
# SDL_syswm.h - "Include file for SDL custom system window manager hooks."
|
9
|
+
#
|
10
|
+
# Your application has access to a special type of event ::SDL_SYSWMEVENT,
|
11
|
+
# which contains window-manager specific information and arrives whenever
|
12
|
+
# an unhandled window event occurs. This event is ignored by default, but
|
13
|
+
# you can enable it with SDL_EventState().
|
14
|
+
module SDL2
|
9
15
|
module SysWM
|
10
|
-
|
16
|
+
module TYPE
|
17
|
+
extend EnumerableConstants
|
18
|
+
UNKOWN
|
19
|
+
WINDOWS
|
20
|
+
X11
|
21
|
+
DIRECTFB
|
22
|
+
COCOA
|
23
|
+
UIKIT
|
24
|
+
WAYLAND
|
25
|
+
WINRT
|
26
|
+
end
|
11
27
|
end
|
12
|
-
|
28
|
+
|
13
29
|
SYSWM = SysWM # Because I don't care about case.
|
14
|
-
|
30
|
+
|
15
31
|
# Line 99~107
|
16
|
-
enum :syswm_type,
|
17
|
-
|
32
|
+
enum :syswm_type, SysWM::TYPE.flatten_constants
|
33
|
+
|
18
34
|
##
|
19
|
-
|
20
|
-
|
21
|
-
|
35
|
+
#
|
36
|
+
api :SDL_GetWindowWMInfo, [Window.by_ref, SYSWM::Info.by_ref], :bool
|
37
|
+
|
22
38
|
end
|
data/lib/sdl2/syswm/msg.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
|
3
3
|
module SDL2 # SDL_syswm.h
|
4
|
-
|
4
|
+
|
5
5
|
module SysWM
|
6
|
+
##
|
7
|
+
# "The custom event structure."
|
6
8
|
class Msg < Struct
|
7
9
|
|
10
|
+
private
|
11
|
+
|
12
|
+
##
|
13
|
+
#
|
8
14
|
class Win < Struct
|
9
15
|
layout :hwnd, :pointer,
|
10
16
|
:msg, :uint,
|
@@ -12,23 +18,33 @@ module SDL2 # SDL_syswm.h
|
|
12
18
|
:lparam, :int32
|
13
19
|
end
|
14
20
|
|
15
|
-
|
21
|
+
##
|
22
|
+
#
|
16
23
|
class X11 < Struct
|
17
24
|
layout :dummy, :uint32 # TODO: FIXME: NOT YET SUPPORTED!
|
18
25
|
end
|
19
26
|
|
27
|
+
##
|
28
|
+
#
|
20
29
|
class DirectFB < Struct
|
21
30
|
layout :event, :uint32 # TODO: FIXME: NOT YET SUPPORTED!
|
22
31
|
end
|
23
32
|
|
33
|
+
##
|
34
|
+
#
|
24
35
|
class Cocoa < Struct
|
25
|
-
layout :dummy, :long # SDL2 says 'No Cocoa window events yet'
|
36
|
+
layout :dummy, :long # TODO: REVIEW: SDL2 says 'No Cocoa window events yet'
|
26
37
|
end
|
27
38
|
|
39
|
+
|
40
|
+
##
|
41
|
+
#
|
28
42
|
class UIKit < Struct
|
29
|
-
layout :dummy, :long # SDL2 says 'No UIKit window events yet'
|
43
|
+
layout :dummy, :long # TODO: REVIEW: SDL2 says 'No UIKit window events yet'
|
30
44
|
end
|
31
45
|
|
46
|
+
##
|
47
|
+
#
|
32
48
|
class MsgUnion < FFI::Union
|
33
49
|
layout :win, Win,
|
34
50
|
:x11, X11,
|
@@ -38,6 +54,8 @@ module SDL2 # SDL_syswm.h
|
|
38
54
|
:dummy, :int
|
39
55
|
end
|
40
56
|
|
57
|
+
public
|
58
|
+
|
41
59
|
layout :version, Version,
|
42
60
|
:subsystem, :int,
|
43
61
|
:msg, MsgUnion
|