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.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +0 -6
  4. data/Guardfile +0 -45
  5. data/README.md +11 -21
  6. data/lib/bad_sdl.rb +4 -0
  7. data/lib/{sdl2 → bad_sdl}/application.rb +47 -35
  8. data/lib/{sdl2 → bad_sdl}/engine.rb +20 -3
  9. data/lib/{sdl2 → bad_sdl}/engine/block_engine.rb +2 -2
  10. data/lib/bad_sdl/engine/engines.rb +51 -0
  11. data/lib/enumerable_constants.rb +4 -2
  12. data/lib/sdl2.rb +26 -247
  13. data/lib/sdl2/blendmode.rb +18 -0
  14. data/lib/sdl2/color.rb +1 -3
  15. data/lib/sdl2/debug.rb +58 -0
  16. data/lib/sdl2/display.rb +30 -23
  17. data/lib/sdl2/error.rb +6 -4
  18. data/lib/sdl2/event.rb +229 -0
  19. data/lib/sdl2/event/abstract.rb +11 -0
  20. data/lib/sdl2/event/action.rb +19 -0
  21. data/lib/sdl2/event/common.rb +10 -0
  22. data/lib/sdl2/event/controller_axis.rb +20 -0
  23. data/lib/sdl2/event/controller_button.rb +17 -0
  24. data/lib/sdl2/event/controller_device.rb +14 -0
  25. data/lib/sdl2/event/dollar_gesture.rb +19 -0
  26. data/lib/sdl2/event/drop.rb +18 -0
  27. data/lib/sdl2/event/joy_axis.rb +20 -0
  28. data/lib/sdl2/event/joy_ball.rb +20 -0
  29. data/lib/sdl2/event/joy_button.rb +18 -0
  30. data/lib/sdl2/event/joy_device.rb +14 -0
  31. data/lib/sdl2/event/joy_hat.rb +18 -0
  32. data/lib/sdl2/event/keyboard.rb +18 -0
  33. data/lib/sdl2/event/mouse_button.rb +21 -0
  34. data/lib/sdl2/event/mouse_motion.rb +19 -0
  35. data/lib/sdl2/event/mouse_wheel.rb +17 -0
  36. data/lib/sdl2/event/multi_gesture.rb +20 -0
  37. data/lib/sdl2/event/os.rb +12 -0
  38. data/lib/sdl2/event/quit.rb +12 -0
  39. data/lib/sdl2/event/state.rb +13 -0
  40. data/lib/sdl2/event/sys_wm.rb +15 -0
  41. data/lib/sdl2/event/text_editing.rb +17 -0
  42. data/lib/sdl2/event/text_input.rb +15 -0
  43. data/lib/sdl2/event/touch_finger.rb +20 -0
  44. data/lib/sdl2/event/type.rb +62 -0
  45. data/lib/sdl2/event/user.rb +15 -0
  46. data/lib/sdl2/event/window.rb +19 -0
  47. data/lib/sdl2/events.rb +23 -538
  48. data/lib/sdl2/gem_version.rb +1 -1
  49. data/lib/sdl2/haptic.rb +3 -3
  50. data/lib/sdl2/hints.rb +3 -1
  51. data/lib/sdl2/image.rb +20 -20
  52. data/lib/sdl2/init.rb +5 -8
  53. data/lib/sdl2/joystick.rb +104 -78
  54. data/lib/sdl2/joystick/axes.rb +22 -0
  55. data/lib/sdl2/joystick/balls.rb +24 -0
  56. data/lib/sdl2/joystick/buttons.rb +22 -0
  57. data/lib/sdl2/joystick/components.rb +23 -0
  58. data/lib/sdl2/joystick/hats.rb +22 -0
  59. data/lib/sdl2/keyboard.rb +11 -10
  60. data/lib/sdl2/keycode.rb +70 -70
  61. data/lib/sdl2/library.rb +8 -7
  62. data/lib/sdl2/log.rb +6 -0
  63. data/lib/sdl2/managed_struct.rb +17 -0
  64. data/lib/sdl2/mixer.rb +16 -12
  65. data/lib/sdl2/mixer/chunk.rb +14 -3
  66. data/lib/sdl2/mouse.rb +21 -41
  67. data/lib/sdl2/pixel_format.rb +4 -4
  68. data/lib/sdl2/pixels.rb +59 -47
  69. data/lib/sdl2/power.rb +1 -1
  70. data/lib/sdl2/rect.rb +4 -5
  71. data/lib/sdl2/render.rb +85 -170
  72. data/lib/sdl2/renderer.rb +337 -20
  73. data/lib/sdl2/rwops.rb +89 -30
  74. data/lib/sdl2/stdinc.rb +18 -21
  75. data/lib/sdl2/struct.rb +184 -0
  76. data/lib/sdl2/struct_helper.rb +32 -0
  77. data/lib/sdl2/surface.rb +15 -14
  78. data/lib/sdl2/syswm.rb +26 -10
  79. data/lib/sdl2/syswm/msg.rb +22 -4
  80. data/lib/sdl2/texture.rb +106 -0
  81. data/lib/sdl2/touch.rb +16 -20
  82. data/lib/sdl2/ttf.rb +29 -29
  83. data/lib/sdl2/ttf/sdl_ttf_module.rb +1 -1
  84. data/lib/sdl2/typed_pointer.rb +45 -0
  85. data/lib/sdl2/union.rb +7 -0
  86. data/lib/sdl2/video.rb +97 -183
  87. data/lib/sdl2/window.rb +140 -90
  88. data/lib/struct_array.rb +42 -0
  89. data/sdl2_ffi.gemspec +3 -3
  90. data/spec/fixtures/approvals/lazyfoonet_lesson_03_advanced_timers/has_a_message.approved.png +0 -0
  91. data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
  92. data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_a_message.approved.png +0 -0
  93. data/spec/fixtures/approvals/lazyfoonet_lesson_14_advanced_timers/has_drawn_something.approved.png +0 -0
  94. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
  95. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
  96. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
  97. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
  98. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
  99. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
  100. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
  101. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
  102. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
  103. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
  104. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
  105. data/spec/fixtures/approvals/sdl2/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
  106. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_clear.approved.png +0 -0
  107. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_line_connecting_many_points.approved.png +0 -0
  108. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_point.approved.png +0 -0
  109. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_filled_rectangle.approved.png +0 -0
  110. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_pixel_line.approved.png +0 -0
  111. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_a_single_rectangle.approved.png +0 -0
  112. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_filled_rectangles.approved.png +0 -0
  113. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_many_rectangles_at_once.approved.png +0 -0
  114. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_draw_points.approved.png +0 -0
  115. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_render_textures.approved.png +0 -0
  116. data/spec/fixtures/approvals/sdl2_renderer/should_be_able_to_rotate_and_flip_while_rendering_textures.approved.png +0 -0
  117. data/spec/fixtures/approvals/sdl2_renderer/should_have_a_clip_rect.approved.png +0 -0
  118. data/spec/fixtures/images/finger.png +0 -0
  119. data/spec/fixtures/music/beat.wav +0 -0
  120. data/spec/fixtures/sounds/high.wav +0 -0
  121. data/spec/fixtures/sounds/low.wav +0 -0
  122. data/spec/fixtures/sounds/medium.wav +0 -0
  123. data/spec/fixtures/sounds/scratch.wav +0 -0
  124. data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +4 -6
  125. data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +3 -4
  126. data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +2 -2
  127. data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +3 -3
  128. data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
  129. data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +1 -1
  130. data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +3 -2
  131. data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +9 -7
  132. data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +11 -8
  133. data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +5 -4
  134. data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +17 -9
  135. data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +8 -7
  136. data/spec/functional/lazy_foo_tutorial/lazy_foo_13_advanced_timers_spec.rb +85 -0
  137. data/spec/functional/lazy_foo_tutorial/lazy_foo_14_regulating_frame_rate_spec.rb +67 -0
  138. data/spec/functional/lazy_foo_tutorial/lazy_foo_15_calculating_frame_rate_spec.rb +48 -0
  139. data/spec/functional/lazy_foo_tutorial/lazy_foo_16_motion_spec.rb +95 -0
  140. data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +3 -1
  141. data/spec/functional/lazy_foo_tutorial/timer.rb +55 -0
  142. data/spec/lib/bad_sdl/application_spec.rb +22 -0
  143. data/spec/{unit → lib}/sdl2/color_spec.rb +5 -1
  144. data/spec/lib/sdl2/display_spec.rb +6 -0
  145. data/spec/lib/sdl2/event_spec.rb +102 -0
  146. data/spec/lib/sdl2/events_spec.rb +12 -0
  147. data/spec/lib/sdl2/joystick_spec.rb +130 -0
  148. data/spec/lib/sdl2/keyboard_spec.rb +22 -0
  149. data/spec/lib/sdl2/mouse_spec.rb +21 -0
  150. data/spec/lib/sdl2/render_spec.rb +62 -0
  151. data/spec/lib/sdl2/renderer_spec.rb +224 -0
  152. data/spec/lib/sdl2/sdl2_helper.rb +5 -0
  153. data/spec/lib/sdl2/texture_spec.rb +65 -0
  154. data/{test/unit/sdl2/test_video.rb → spec/lib/sdl2/video_spec.rb} +82 -57
  155. data/spec/lib/sdl2/window_spec.rb +42 -0
  156. data/spec/{unit → lib}/unit_helper.rb +0 -0
  157. data/spec/png_writer.rb +9 -1
  158. data/spec/spec_helper.rb +5 -3
  159. metadata +201 -132
  160. data/lib/sdl2/engine/engines.rb +0 -46
  161. data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
  162. data/test/approvals/color_keying_example.approved.png +0 -0
  163. data/test/approvals/hello_world_example_hello.approved.png +0 -0
  164. data/test/approvals/hello_world_example_screen.approved.png +0 -0
  165. data/test/approvals/optimized_surface_loading.approved.png +0 -0
  166. data/test/fixtures/an_example.png +0 -0
  167. data/test/fixtures/background.bmp +0 -0
  168. data/test/fixtures/background.jpg +0 -0
  169. data/test/fixtures/color_bars.jpg +0 -0
  170. data/test/fixtures/foo.jpg +0 -0
  171. data/test/fixtures/hello.bmp +0 -0
  172. data/test/fixtures/sprites.jpg +0 -0
  173. data/test/fixtures/x.png +0 -0
  174. data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +0 -50
  175. data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +0 -42
  176. data/test/functional/examples/test_lazy_foo_examples.rb +0 -195
  177. data/test/functional/examples/test_readme_examples.rb +0 -15
  178. data/test/test_helper.rb +0 -13
  179. data/test/unit/sdl2/test_assert.rb +0 -10
  180. data/test/unit/sdl2/test_audio.rb +0 -9
  181. data/test/unit/sdl2/test_clipboard.rb +0 -13
  182. data/test/unit/sdl2/test_cpuinfo.rb +0 -11
  183. data/test/unit/sdl2/test_error.rb +0 -20
  184. data/test/unit/sdl2/test_events.rb +0 -31
  185. data/test/unit/sdl2/test_haptic.rb +0 -27
  186. data/test/unit/sdl2/test_hints.rb +0 -50
  187. data/test/unit/sdl2/test_image.rb +0 -9
  188. data/test/unit/sdl2/test_init.rb +0 -29
  189. data/test/unit/sdl2/test_keyboard.rb +0 -9
  190. data/test/unit/sdl2/test_log.rb +0 -80
  191. data/test/unit/sdl2/test_palette.rb +0 -26
  192. data/test/unit/sdl2/test_pixel_format.rb +0 -38
  193. data/test/unit/sdl2/test_pixels.rb +0 -24
  194. data/test/unit/sdl2/test_power.rb +0 -11
  195. data/test/unit/sdl2/test_rect.rb +0 -19
  196. data/test/unit/sdl2/test_render.rb +0 -58
  197. data/test/unit/sdl2/test_surface.rb +0 -88
  198. data/test/unit/sdl2/test_syswm.rb +0 -11
  199. data/test/unit/sdl2/test_timer.rb +0 -9
  200. data/test/unit/sdl2/test_ttf.rb +0 -11
  201. data/test/unit/sdl2/test_version.rb +0 -16
  202. data/test/unit/sdl2/test_window.rb +0 -155
  203. data/test/unit/test_scratch.rb +0 -19
  204. data/test/unit/test_sdl2.rb +0 -16
@@ -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
- layout :blank, :uint8 # Ignore Structure?
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
- def self.create(window, driver_idx, flags)
20
- create_render(window, driver_idx, flags)
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
- def self.get(window)
24
- get_renderer(window)
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
- def self.create_software(surface)
28
- create_software_renderer(surface)
29
- end
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
- def self.release(pointer)
32
- destroy_renderer(pointer)
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
- def clear
36
- render_clear(self)
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
- end
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
@@ -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
- #Forward Declaration for callbacks
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, UInt8Struct.by_ref,
44
- :here, UInt8Struct.by_ref,
45
- :stop, UInt8Struct.by_ref
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
- # CONSTANTS
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
- api :SDL_RWFromFile, [:string, :string], RWops.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
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
- api :SDL_RWFromFP, [:pointer, :bool], RWops.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
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
- api :SDL_RWFromMem, [:pointer, :count], RWops.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
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
- api :SDL_RWFromConstMem, [:pointer, :count], RWops.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
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.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
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