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/renderer.rb
CHANGED
@@ -1,41 +1,358 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
require 'sdl2/renderer_info'
|
3
|
+
|
3
4
|
module SDL2
|
4
|
-
|
5
|
+
##
|
6
|
+
# Constants used to describe Renderer features (flags)
|
5
7
|
module RENDERER
|
6
8
|
include EnumerableConstants
|
7
|
-
|
8
|
-
SOFTWARE = 0x00000001
|
9
|
-
ACCELERATED = 0x00000002
|
10
|
-
PRESENTVSYNC = 0x00000004
|
9
|
+
|
10
|
+
SOFTWARE = 0x00000001
|
11
|
+
ACCELERATED = 0x00000002
|
12
|
+
PRESENTVSYNC = 0x00000004
|
11
13
|
TARGETTEXTURE = 0x00000008
|
12
14
|
end
|
13
|
-
|
15
|
+
|
16
|
+
##
|
17
|
+
# Render: Interface for 2D accelerated rendering.
|
18
|
+
# Supports the following:
|
19
|
+
# - pixel points
|
20
|
+
# - pixel lines
|
21
|
+
# - filled rectangles
|
22
|
+
# - texture images
|
23
|
+
#
|
24
|
+
# Also supports:
|
25
|
+
# - additive modes
|
26
|
+
# - blending/opaqueness
|
27
|
+
#
|
28
|
+
# Note: Does not support threading, single thread only.
|
29
|
+
#
|
30
|
+
# https://wiki.libsdl.org/CategoryRender
|
14
31
|
class Renderer < Struct
|
15
32
|
include RENDERER
|
33
|
+
##
|
34
|
+
# Enumerates the available Renderer Drivers
|
35
|
+
class Drivers
|
36
|
+
def self.count
|
37
|
+
SDL2.get_num_render_drivers!
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.[](idx)
|
41
|
+
info = SDL2::RendererInfo.create()
|
42
|
+
SDL2.get_render_driver_info!(idx, info)
|
43
|
+
info
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
layout :blank, :uint8 # Ignore Structure?
|
48
|
+
# layout :magic, :pointer,
|
49
|
+
# :window_event, :pointer,
|
50
|
+
# :get_output_size, :pointer,
|
51
|
+
# :create_texture, :pointer,
|
52
|
+
# :set_texture_color_mod, :pointer,
|
53
|
+
# :set_texture_alpha_mod, :pointer,
|
54
|
+
# :set_texture_blend_mode, :pointer,
|
55
|
+
# :update_texture, :pointer,
|
56
|
+
# #:update_texture_yuv, :pointer,
|
57
|
+
# :lock_texture, :pointer,
|
58
|
+
# :unlock_texture, :pointer,
|
59
|
+
# :set_render_target, :pointer,
|
60
|
+
# :update_viewport, :pointer,
|
61
|
+
# :update_clip_rect, :pointer,
|
62
|
+
# :render_clear, :pointer,
|
63
|
+
# :render_draw_points, :pointer,
|
64
|
+
# :render_draw_lines, :pointer,
|
65
|
+
# :render_fill_rects, :pointer,
|
66
|
+
# :render_copy, :pointer,
|
67
|
+
# :render_copy_ex, :pointer,
|
68
|
+
# :render_read_pixels, :pointer,
|
69
|
+
# :render_present, :pointer,
|
70
|
+
# :destroy_texture, :pointer,
|
71
|
+
# :destroy_renderer, :pointer,
|
72
|
+
# :gl_bind_texture, :pointer,
|
73
|
+
# :gl_unbind_texture, :pointer,
|
74
|
+
# :info, SDL2::RendererInfo.ptr,
|
75
|
+
# :window, SDL2::Window.ptr,
|
76
|
+
# :hidden, :bool,
|
77
|
+
# :logical_w, :int,
|
78
|
+
# :logical_h, :int,
|
79
|
+
# :logical_w_backup, :int,
|
80
|
+
# :logical_h_backup, :int,
|
81
|
+
# :viewport, SDL2::Rect.ptr,
|
82
|
+
# :viewport_backup, SDL2::Rect.ptr,
|
83
|
+
# :clip_rect, SDL2::Rect.ptr,
|
84
|
+
# :clip_rect_backup, SDL2::Rect.ptr,
|
85
|
+
# :scale, [:float, 2],
|
86
|
+
# :scale_backup, [:float, 2],
|
87
|
+
# :texture, :pointer,
|
88
|
+
# :target, :pointer,
|
89
|
+
# :r, :uint8,
|
90
|
+
# :g, :uint8,
|
91
|
+
# :b, :uint8,
|
92
|
+
# :a, :uint8,
|
93
|
+
# :blend_mode, :int,
|
94
|
+
# :driverdata, :pointer
|
95
|
+
|
96
|
+
##
|
97
|
+
# Constructs a Renderer for a window.
|
98
|
+
# @param flags: Combination of RENDERER flags requested
|
99
|
+
def self.create(window, flags = 0, driver_idx = -1)
|
100
|
+
SDL2.create_renderer!(window, driver_idx, flags)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Returns the rendering context for a window
|
105
|
+
def self.get(window)
|
106
|
+
SDL2.get_renderer!(window)
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Create a 2D software rendering context to be able
|
111
|
+
# to write directly to a surface (not a window).
|
112
|
+
def self.create_software(surface)
|
113
|
+
SDL2.create_software_renderer(surface)
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Release a render
|
118
|
+
def self.release(pointer)
|
119
|
+
SDL2.destroy_renderer(pointer)
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
#
|
124
|
+
def destroy
|
125
|
+
SDL2.destroy_renderer(self)
|
126
|
+
end
|
127
|
+
##
|
128
|
+
# Present the renderer (AKA: Draw/Flip/Update/Flush)
|
129
|
+
def present
|
130
|
+
SDL2.render_present(self)
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Return the Draw Blend Mode
|
135
|
+
def draw_blend_mode
|
136
|
+
blend_mode = SDL2::TypedPointer::BlendMode.new
|
137
|
+
SDL2.get_render_draw_blend_mode!(self, blend_mode)
|
138
|
+
blend_mode.value
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Change the Draw Blend Mode
|
143
|
+
def draw_blend_mode=(blend_mode)
|
144
|
+
SDL2.set_render_draw_blend_mode!(self, blend_mode)
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# Get the Draw Color
|
149
|
+
# Returns an SDL2::Color
|
150
|
+
def draw_color
|
151
|
+
colors = 4.times.map{SDL2::TypedPointer::UInt8.new}
|
152
|
+
SDL2.get_render_draw_color!(self, *colors)
|
153
|
+
colors = colors.map(&:value)
|
154
|
+
SDL2::Color.cast(colors)
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Set the Draw Color
|
159
|
+
def draw_color=(color)
|
160
|
+
color = SDL2::Color.cast(color)
|
161
|
+
SDL2.set_render_draw_color!(self, *color.to_a)
|
162
|
+
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# Get the target
|
166
|
+
# Returns nil if default when 'default' render target set
|
167
|
+
def target
|
168
|
+
target = SDL2.get_render_target(self)
|
169
|
+
target.null? ? nil : target
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Set the target
|
174
|
+
#
|
175
|
+
def target=(texture)
|
176
|
+
SDL2.set_render_target!(self, texture)
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Retrive the Render Driver Info for this Renderer
|
181
|
+
def info
|
182
|
+
render_info = SDL2::RendererInfo.new
|
183
|
+
SDL2.get_renderer_info!(self, render_info)
|
184
|
+
render_info
|
185
|
+
end
|
186
|
+
|
187
|
+
##
|
188
|
+
# Get the output size
|
189
|
+
# @returns the [width, height]
|
190
|
+
def output_size
|
191
|
+
wh = 2.times.map{SDL2::TypedPointer::Int.new}
|
192
|
+
SDL2.get_renderer_output_size!(self, *wh)
|
193
|
+
wh.map(&:value)
|
194
|
+
end
|
195
|
+
|
196
|
+
##
|
197
|
+
# This writes draw_color to entire rendering volume
|
198
|
+
def clear
|
199
|
+
SDL2.render_clear(self)
|
200
|
+
end
|
201
|
+
|
202
|
+
##
|
203
|
+
# Create a texture from a surface
|
204
|
+
def texture_from_surface(surface)
|
205
|
+
SDL2.create_texture_from_surface!(self, surface)
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# Render a Texture or a portion of a texture to the rendering target
|
210
|
+
def copy(texture, src_cords = nil, dst_cords = nil)
|
211
|
+
src_rect = SDL2::Rect.cast(src_cords)
|
212
|
+
dst_rect = SDL2::Rect.cast(dst_cords)
|
213
|
+
SDL2.render_copy!(self, texture, src_rect, dst_rect)
|
214
|
+
end
|
215
|
+
|
216
|
+
##
|
217
|
+
# Render a Texture or a portion of a texture to the rendering target
|
218
|
+
# optionally rotating it by an angle around the given center
|
219
|
+
# and also flipping it top-bottom and/or left-right
|
220
|
+
def copy_ex(texture, src_cords = nil, dst_cords = nil, angle = 0.0, center_cords = nil, flip = :NONE)
|
221
|
+
src_rect = SDL2::Rect.cast(src_cords)
|
222
|
+
dst_rect = SDL2::Rect.cast(dst_cords)
|
223
|
+
center_point = SDL2::Point.cast(center_cords)
|
224
|
+
SDL2.render_copy_ex(self, texture, src_rect, dst_rect, angle, center_point, flip)
|
225
|
+
end
|
226
|
+
|
227
|
+
##
|
228
|
+
# Draw a single pixel line
|
229
|
+
def draw_line(x1, y1, x2, y2)
|
230
|
+
SDL2.render_draw_line!(self, x1, y1, x2, y2)
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# Draw lines connecting all points specified.
|
235
|
+
# Each individual point should either be an SDL2::Point or
|
236
|
+
# something that can be cast into one.
|
237
|
+
def draw_lines(*cords)
|
238
|
+
points = SDL2::StructArray.clone_from(cords, SDL2::Point)
|
239
|
+
SDL2.render_draw_lines!(self, points.first, points.count)
|
240
|
+
end
|
241
|
+
|
242
|
+
##
|
243
|
+
# Draw a point
|
244
|
+
def draw_point(x,y)
|
245
|
+
SDL2.render_draw_point!(self, x, y)
|
246
|
+
end
|
247
|
+
|
248
|
+
##
|
249
|
+
# Draw each specified point. Each argument must be an X/Y point,
|
250
|
+
# either as an arrray [2,3], hash {x: 2, y: 3} or an SDL2::Point
|
251
|
+
def draw_points(*cords)
|
252
|
+
points = SDL2::StructArray.clone_from(cords, SDL2::Point)
|
253
|
+
SDL2.render_draw_points!(self, points.first, points.count)
|
254
|
+
end
|
255
|
+
|
256
|
+
##
|
257
|
+
# Draw a rectangle.
|
258
|
+
# Should be able to accept an: SDL2::Rect,
|
259
|
+
# A hash with :x, :y, :w, :h
|
260
|
+
# An array with 2 or 4 integer values.
|
261
|
+
def draw_rect(cords)
|
262
|
+
rect = SDL2::Rect.cast(cords)
|
263
|
+
SDL2.render_draw_rect(self, rect)
|
264
|
+
end
|
265
|
+
|
266
|
+
##
|
267
|
+
# Draw many rectangles at once.. each parameter should be something that
|
268
|
+
# SDL2::Renderer#draw_rect can take, however this routine sends all points
|
269
|
+
# to SDL directly.
|
270
|
+
def draw_rects(*cords)
|
271
|
+
rects = SDL2::StructArray.clone_from(cords, SDL2::Rect)
|
272
|
+
SDL2.render_draw_rects!(self, rects.first(), rects.count)
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Fill a rectangle
|
277
|
+
def fill_rect(cord)
|
278
|
+
rect = SDL2::Rect.cast(cord)
|
279
|
+
SDL2.render_fill_rect!(self, rect)
|
280
|
+
end
|
281
|
+
|
282
|
+
##
|
283
|
+
# Fill many rectangles at once
|
284
|
+
def fill_rects(*cords)
|
285
|
+
rects = SDL2::StructArray.clone_from(cords, SDL2::Rect)
|
286
|
+
SDL2.render_fill_rects!(self, rects.first(), rects.count)
|
287
|
+
end
|
16
288
|
|
17
|
-
|
289
|
+
##
|
290
|
+
# Get the clipping rectangle
|
291
|
+
def clip_rect
|
292
|
+
rect = SDL2::Rect.new
|
293
|
+
SDL2.render_get_clip_rect(self, rect)
|
294
|
+
rect
|
295
|
+
end
|
18
296
|
|
19
|
-
|
20
|
-
|
297
|
+
##
|
298
|
+
# Set the clipping rectangle
|
299
|
+
def clip_rect=(cords)
|
300
|
+
rect = SDL2::Rect.cast(cords)
|
301
|
+
SDL2.render_set_clip_rect!(self, rect)
|
302
|
+
rect
|
21
303
|
end
|
22
304
|
|
23
|
-
|
24
|
-
|
305
|
+
##
|
306
|
+
# Get the logical size of the renderer, returns [w, h]
|
307
|
+
def logical_size
|
308
|
+
size = 2.times.map{SDL2::TypedPointer::Int.new}
|
309
|
+
SDL2.render_get_logical_size(self, *size)
|
310
|
+
size.map(&:value)
|
25
311
|
end
|
26
312
|
|
27
|
-
|
28
|
-
|
29
|
-
|
313
|
+
##
|
314
|
+
# Set the logical size of the renderer, expects [w, h]
|
315
|
+
def logical_size=(wh)
|
316
|
+
SDL2.render_set_logical_size!(self, *wh)
|
317
|
+
wh
|
318
|
+
end
|
30
319
|
|
31
|
-
|
32
|
-
|
320
|
+
##
|
321
|
+
# Get the scale of the renderer, returns [x,y] floats
|
322
|
+
def scale
|
323
|
+
scale = 2.times.map{SDL2::TypedPointer::Float.new}
|
324
|
+
SDL2.render_get_scale(self, *scale)
|
325
|
+
scale.map(&:value)
|
33
326
|
end
|
34
327
|
|
35
|
-
|
36
|
-
|
328
|
+
##
|
329
|
+
# Set the scale of the renderer, expects [x,y] floats
|
330
|
+
def scale=(scale)
|
331
|
+
SDL2.render_set_scale!(self, *scale)
|
332
|
+
scale
|
333
|
+
end
|
334
|
+
|
335
|
+
##
|
336
|
+
# Get the viewport rect
|
337
|
+
def viewport
|
338
|
+
viewport = SDL2::Rect.new
|
339
|
+
SDL2.render_get_viewport(self, viewport)
|
340
|
+
viewport
|
37
341
|
end
|
38
342
|
|
39
|
-
|
40
|
-
|
343
|
+
##
|
344
|
+
# Set the viewport rect
|
345
|
+
def viewport=(cords)
|
346
|
+
viewport = SDL2::Rect.cast(cords)
|
347
|
+
SDL2.render_set_viewport!(self, viewport)
|
348
|
+
viewport
|
349
|
+
end
|
350
|
+
|
351
|
+
##
|
352
|
+
# Indicates if Targeted Rendering is supported.
|
353
|
+
def target_supported?
|
354
|
+
SDL2.render_target_supported?(self)
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|
41
358
|
end
|
data/lib/sdl2/rwops.rb
CHANGED
@@ -1,16 +1,36 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
|
3
|
+
##
|
4
|
+
# SDL_rwops.h => sdl2/rwops.rb
|
5
|
+
# - RWops Structs
|
3
6
|
module SDL2
|
4
|
-
#
|
7
|
+
#NOTE: This is just a forward declaration for the callbacks
|
5
8
|
class RWops < Struct
|
6
9
|
end
|
10
|
+
|
11
|
+
#NOTE: The aforementioned callbacks
|
7
12
|
callback :rwops_size, [RWops.by_ref], :int64
|
8
13
|
callback :rwops_seek, [RWops.by_ref, :int64, :int], :int64
|
9
14
|
callback :rwops_read, [RWops.by_ref, :pointer, :size_t, :size_t], :size_t
|
10
15
|
callback :rwops_write, [RWops.by_ref, :pointer, :size_t, :size_t], :size_t
|
11
16
|
callback :rwops_close, [RWops.by_ref], :int
|
12
17
|
|
18
|
+
##
|
19
|
+
# "This is the read/write operation structure -- very basic"
|
20
|
+
# size - " Return the size of the file in this rwops, or -1 if unkown
|
21
|
+
# seek - "Seek to \c offset relative to \c whence, one of stdio's whence values:
|
22
|
+
# RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
|
23
|
+
# return the final offset in the data stream, or -1 on error.
|
24
|
+
# read - "Read up to \c maxnum objects each of size \c size from the data
|
25
|
+
# stream to the area pointed at by \c ptr.
|
26
|
+
# Return the number of objects read, or 0 at error or end of file.
|
27
|
+
# write - "Write eactly \c num objects each of size \c size from the area
|
28
|
+
# pointed at by \c ptr to data stream.
|
29
|
+
# Return the number of objects written, or 0 at error or end of file.
|
30
|
+
# close - "Close and free an allocated SDL_RWops structure.
|
31
|
+
# Return 0 if successful or -1 on write error when flushing data.
|
13
32
|
class RWops < Struct
|
33
|
+
private
|
14
34
|
class AndroidIO < Struct
|
15
35
|
layout :fileNameRef, :pointer,
|
16
36
|
:inputSteramRef, :pointer,
|
@@ -40,9 +60,9 @@ module SDL2
|
|
40
60
|
end
|
41
61
|
|
42
62
|
class Mem <Struct
|
43
|
-
layout :base,
|
44
|
-
:here,
|
45
|
-
:stop,
|
63
|
+
layout :base, TypedPointer::UInt8.by_ref,
|
64
|
+
:here, TypedPointer::UInt8.by_ref,
|
65
|
+
:stop, TypedPointer::UInt8.by_ref
|
46
66
|
end
|
47
67
|
|
48
68
|
class Unkown < Struct
|
@@ -58,6 +78,7 @@ module SDL2
|
|
58
78
|
:unkown, Unkown
|
59
79
|
end
|
60
80
|
|
81
|
+
public
|
61
82
|
|
62
83
|
layout :size, :rwops_size,
|
63
84
|
:seek, :rwops_seek,
|
@@ -67,40 +88,70 @@ module SDL2
|
|
67
88
|
:type, :uint32,
|
68
89
|
:hidden, Hidden
|
69
90
|
|
91
|
+
##
|
92
|
+
# Release this structure using SDL_FreeRW
|
70
93
|
def self.release(pointer)
|
71
94
|
SDL2.free_rw(pointer)
|
72
95
|
end
|
73
96
|
|
74
|
-
|
97
|
+
##
|
98
|
+
# "Seek from the beginning of data"
|
75
99
|
SEEK_SET = 0
|
100
|
+
##
|
101
|
+
# "Seek relative to current read point"
|
76
102
|
SEEK_CUR = 1
|
103
|
+
##
|
104
|
+
# "Seek relative to the end of data"
|
77
105
|
SEEK_END = 2
|
78
106
|
|
107
|
+
##
|
108
|
+
# Create RWOps from file name
|
79
109
|
def self.from_file(file_name, mode)
|
80
110
|
SDL2.rw_from_file!(file_name, mode)
|
81
111
|
end
|
82
112
|
|
83
113
|
# Read/Write Macros re-implemented: Lines #184~189
|
114
|
+
|
115
|
+
##
|
116
|
+
# "Return the size of the file in this rwops, or -1 if unkown"
|
84
117
|
def size
|
85
118
|
self[:size].call
|
86
119
|
end
|
87
120
|
|
121
|
+
##
|
122
|
+
# "Seek to \c offset in the data stream, or -1 on error."
|
123
|
+
# "\return the number of objects read, or 0 at error or end of file"
|
88
124
|
def seek(offset, whence)
|
89
125
|
self[:seek].call(self, offset, whence)
|
90
126
|
end
|
91
127
|
|
128
|
+
##
|
129
|
+
# BadQuanta: "I suppose this returns the current position"
|
130
|
+
# SDL_rwops.h:186.
|
92
131
|
def tell
|
93
132
|
self[:seek].call(self, 0, SEEK_CUR)
|
94
133
|
end
|
95
134
|
|
135
|
+
##
|
136
|
+
# "Read up to \c maxnum objects each of size \c size from the data
|
137
|
+
# stream to the area pointed at by \c ptr."
|
138
|
+
# "\return the number of objects read, or 0 at error or end of file."
|
96
139
|
def read(pointer, size, n)
|
97
140
|
self[:read].call(self, pointer, size, n)
|
98
141
|
end
|
99
142
|
|
143
|
+
##
|
144
|
+
# "Write exactly \c num objects each of size \c size from the area
|
145
|
+
# pointed at by \c ptr to data stream."
|
146
|
+
#
|
147
|
+
# "\return the number of objects written, or 0 at error or end of file."
|
100
148
|
def write(pointer, size, n)
|
101
149
|
self[:write].call(self, pointer, size, n)
|
102
150
|
end
|
103
151
|
|
152
|
+
##
|
153
|
+
# "Close and free an allocated SDL_RWops structure."
|
154
|
+
# "\return 0 if successful or -1 on write error when flushing data."
|
104
155
|
def close
|
105
156
|
self[:close].call(self)
|
106
157
|
end
|
@@ -108,64 +159,72 @@ module SDL2
|
|
108
159
|
end
|
109
160
|
|
110
161
|
##
|
111
|
-
#
|
112
|
-
|
162
|
+
# Load from a file
|
163
|
+
# * file - filename string (existing)
|
164
|
+
# * mode - mode string
|
165
|
+
api :SDL_RWFromFile, [:string, :string], RWops.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
113
166
|
##
|
114
|
-
#
|
115
|
-
|
167
|
+
# Load from a file pointer
|
168
|
+
# * fp - a file pointer
|
169
|
+
# * autoclose - boolean
|
170
|
+
api :SDL_RWFromFP, [:pointer, :bool], RWops.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
116
171
|
##
|
117
|
-
#
|
118
|
-
|
172
|
+
# Load from any pointer in memory
|
173
|
+
# * mem - pointer
|
174
|
+
# * size - integer
|
175
|
+
api :SDL_RWFromMem, [:pointer, :count], RWops.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
119
176
|
##
|
120
|
-
#
|
121
|
-
|
177
|
+
# Load from "constant" memory
|
178
|
+
# * mem - constant pointer
|
179
|
+
# * size - integer
|
180
|
+
api :SDL_RWFromConstMem, [:pointer, :count], RWops.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
122
181
|
##
|
123
|
-
#
|
124
|
-
api :SDL_AllocRW, [], RWops.
|
182
|
+
# Allocate a RWops structure
|
183
|
+
api :SDL_AllocRW, [], RWops.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
|
125
184
|
##
|
126
|
-
#
|
185
|
+
# Release a RWops structure
|
127
186
|
api :SDL_FreeRW, [RWops.by_ref], :void
|
128
187
|
##
|
129
|
-
#
|
188
|
+
# Read 8 bytes
|
130
189
|
api :SDL_ReadU8, [RWops.by_ref], :uint8
|
131
190
|
##
|
132
|
-
#
|
191
|
+
# Read 16 bytes little endian
|
133
192
|
api :SDL_ReadLE16, [RWops.by_ref], :uint16
|
134
193
|
##
|
135
|
-
#
|
194
|
+
# Read 16 bytes big endian
|
136
195
|
api :SDL_ReadBE16, [RWops.by_ref], :uint16
|
137
196
|
##
|
138
|
-
#
|
197
|
+
# Read 32 bytes little endian
|
139
198
|
api :SDL_ReadLE32, [RWops.by_ref], :uint32
|
140
199
|
##
|
141
|
-
#
|
200
|
+
# Read 32 bytes big endian
|
142
201
|
api :SDL_ReadBE32, [RWops.by_ref], :uint32
|
143
202
|
##
|
144
|
-
#
|
203
|
+
# Read 64 bytes little endian
|
145
204
|
api :SDL_ReadLE64, [RWops.by_ref], :uint64
|
146
205
|
##
|
147
|
-
#
|
206
|
+
# Read 32 bytes big endian
|
148
207
|
api :SDL_ReadBE64, [RWops.by_ref], :uint64
|
149
208
|
|
150
209
|
##
|
151
|
-
#
|
210
|
+
# Write 8 bytes
|
152
211
|
api :SDL_WriteU8, [RWops.by_ref, :uint8], :size_t
|
153
212
|
##
|
154
|
-
#
|
213
|
+
# Write 16 bytes little endian
|
155
214
|
api :SDL_WriteLE16, [RWops.by_ref, :uint16], :size_t
|
156
215
|
##
|
157
|
-
#
|
216
|
+
# Write 16 bytes big endian
|
158
217
|
api :SDL_WriteBE16, [RWops.by_ref, :uint16], :size_t
|
159
218
|
##
|
160
|
-
#
|
219
|
+
# Write 32 bytes little endian
|
161
220
|
api :SDL_WriteLE32, [RWops.by_ref, :uint32], :size_t
|
162
221
|
##
|
163
|
-
#
|
222
|
+
# Write 32 bytes big endian
|
164
223
|
api :SDL_WriteBE32, [RWops.by_ref, :uint32], :size_t
|
165
224
|
##
|
166
|
-
#
|
225
|
+
# Write 64 bytes little endian
|
167
226
|
api :SDL_WriteLE64, [RWops.by_ref, :uint64], :size_t
|
168
227
|
##
|
169
|
-
#
|
228
|
+
# Write 64 bytes big endian
|
170
229
|
api :SDL_WriteBE64, [RWops.by_ref, :uint64], :size_t
|
171
230
|
end
|