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,57 +1,37 @@
1
1
  require 'sdl2'
2
2
 
3
-
3
+ ##
4
+ # ## SDL2 Mouse Support
5
+ #
4
6
  module SDL2
5
7
 
6
8
  class Cursor < Struct
7
-
9
+ layout :private, :pointer
8
10
  def self.release(pointer)
9
11
  SDL2.free_cursor(pointer)
10
12
  end
13
+
14
+ def self.create_color_cursor(surface, hot_x, hot_y)
15
+ SDL2.create_color_cursor!(surface, hot_x, hot_y)
16
+ end
11
17
  end
12
18
 
13
19
  enum :system_cursor, [:ARROW,:IBEAM,:WAIT,:CROSSHAIR,:WAITARROW,:SIZENWSE,:SIZENESW,:SIZEWE,
14
20
  :SIZENS,:SIZEALL,:NO,:HAND]
15
21
 
16
- ##
17
- #
18
- api :SDL_GetMouseFocus, [], Window.by_ref
19
- ##
20
- #
21
- api :SDL_GetMouseState, [IntStruct.by_ref, IntStruct.by_ref], :uint32
22
- ##
23
- #
24
- api :SDL_GetRelativeMouseState, [IntStruct.by_ref, IntStruct.by_ref], :uint32
25
- ##
26
- #
27
- api :SDL_WarpMouseInWindow, [Window.by_ref, :int, :int], :void
28
- ##
29
- #
30
- api :SDL_SetRelativeMouseMode, [:bool], :int
31
- ##
32
- #
33
- api :SDL_GetRelativeMouseMode, [], :bool
34
- ##
35
- #
36
- api :SDL_CreateCursor, [:pointer, :pointer, :int, :int, :int, :int], Cursor.auto_ptr
37
- ##
38
- #
39
- api :SDL_CreateColorCursor, [Surface.by_ref, :int, :int], Cursor.auto_ptr
40
- ##
41
- #
42
- api :SDL_CreateSystemCursor, [:system_cursor], Cursor.auto_ptr
43
- ##
44
- #
45
- api :SDL_GetCursor, [], Cursor.by_ref
46
- ##
47
- #
48
- api :SDL_GetDefaultCursor, [], Cursor.by_ref
49
- ##
50
- #
51
- api :SDL_FreeCursor, [Cursor.by_ref], :void
52
- ##
53
- #
54
- api :SDL_ShowCursor, [:int], :int
22
+ api :SDL_GetMouseFocus, [], Window.by_ref
23
+ api :SDL_GetMouseState, [TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :uint32
24
+ api :SDL_GetRelativeMouseState, [TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :uint32
25
+ api :SDL_WarpMouseInWindow, [Window.by_ref, :int, :int], :void
26
+ api :SDL_SetRelativeMouseMode, [:bool], :int
27
+ api :SDL_GetRelativeMouseMode, [], :bool
28
+ api :SDL_CreateCursor, [:pointer, :pointer, :int, :int, :int, :int], Cursor.ptr
29
+ api :SDL_CreateColorCursor, [Surface.by_ref, :int, :int], Cursor.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
30
+ api :SDL_CreateSystemCursor, [:system_cursor], Cursor.ptr
31
+ api :SDL_GetCursor, [], Cursor.by_ref
32
+ api :SDL_GetDefaultCursor, [], Cursor.by_ref
33
+ api :SDL_FreeCursor, [Cursor.by_ref], :void
34
+ api :SDL_ShowCursor, [:int], :int
55
35
 
56
36
  module Mouse
57
37
 
@@ -47,8 +47,8 @@ module SDL2
47
47
  # Convert enumerated pixel value format to bpp & RGBA mask values
48
48
  # TODO: Review why this is needed? Why not just read the Struct fields?
49
49
  def self.to_masks(format)
50
- p = Hash.new(){UInt32Struct.new}
51
- p[:bpp] = IntStruct.new
50
+ p = Hash.new(){TypedPointer::UInt32.new}
51
+ p[:bpp] = TypedPointer::Int.new
52
52
  SDL2.pixel_format_enum_to_masks(format, p[:bpp], p[:Rmask], p[:Bmask],p[:Amask])
53
53
  result = []
54
54
  p.each_value{|s|result << s[:value]}
@@ -101,7 +101,7 @@ module SDL2
101
101
 
102
102
  # Get the RGB components (array) from a pixel value
103
103
  def get_rgb(pixel)
104
- ptr = Hash.new(){UInt8Struct.new}
104
+ ptr = Hash.new(){TypedPointer::UInt8.new}
105
105
  SDL2.get_rgb(pixel, self, ptr[:r], ptr[:g], ptr[:b])
106
106
  result = []
107
107
  ptr.each_value{|s|result << s[:value]}
@@ -111,7 +111,7 @@ module SDL2
111
111
 
112
112
  # Get the RGBA components (array) from a pixel value
113
113
  def get_rgba(pixel)
114
- ptr = Hash.new(){UInt8Struct.new}
114
+ ptr = Hash.new(){TypedPointer::UInt8.new}
115
115
  SDL2.get_rgba(pixel, self, ptr[:r], ptr[:g], ptr[:b], ptr[:a])
116
116
  result = []
117
117
  ptr.each_value{|s|result << s[:value]}
@@ -1,36 +1,38 @@
1
1
  require 'sdl2/error'
2
2
  require 'sdl2/color'
3
- require 'sdl2/pixel_format'
3
+
4
4
 
5
5
  # SDL_pixels.h API
6
6
  module SDL2
7
7
  ALPHA_OPAQUE = 255
8
8
  ALPHA_TRANSPARENT = 0
9
9
 
10
+ ##
10
11
  # Predefined pixel types.
11
12
  module PIXELTYPE
12
13
  include EnumerableConstants
13
- UNKNOWN
14
- INDEX1
15
- INDEX4
16
- INDEX8
17
- PACKED8
18
- PACKED16
19
- PACKED32
20
- ARRAYU8
21
- ARRAYU16
22
- ARRAYU32
23
- ARRAYF16
24
- ARRAYF32
14
+ UNKNOWN = next_const_value
15
+ INDEX1 = next_const_value
16
+ INDEX4 = next_const_value
17
+ INDEX8 = next_const_value
18
+ PACKED8 = next_const_value
19
+ PACKED16 = next_const_value
20
+ PACKED32 = next_const_value
21
+ ARRAYU8 = next_const_value
22
+ ARRAYU16 = next_const_value
23
+ ARRAYU32 = next_const_value
24
+ ARRAYF16 = next_const_value
25
+ ARRAYF32 = next_const_value
25
26
  end
26
27
  enum :pixeltype, PIXELTYPE.flatten_consts
27
28
 
29
+ ##
28
30
  # Bitmap pixel order, high bit -> low bit
29
31
  module BITMAPORDER
30
32
  include EnumerableConstants
31
- NONE
32
- N4321
33
- N1234
33
+ NONE = next_const_value
34
+ N4321 = next_const_value
35
+ N1234 = next_const_value
34
36
  end
35
37
 
36
38
  enum :bitmaporder, BITMAPORDER.flatten_consts
@@ -38,29 +40,30 @@ module SDL2
38
40
  # Packed component order, high bit -> low bit
39
41
  module PACKEDORDER
40
42
  include EnumerableConstants
41
- NONE
42
- XRGB
43
- RGBX
44
- ARGB
45
- RGBA
46
- XBGR
47
- BGRX
48
- ABGR
49
- BGRA
43
+ NONE = next_const_value
44
+ XRGB = next_const_value
45
+ RGBX = next_const_value
46
+ ARGB = next_const_value
47
+ RGBA = next_const_value
48
+ XBGR = next_const_value
49
+ BGRX = next_const_value
50
+ ABGR = next_const_value
51
+ BGRA = next_const_value
50
52
  end
51
53
 
52
54
  enum :packedorder, PACKEDORDER.flatten_consts
53
55
 
56
+
54
57
  # Array component order, low byte -> hight byte
55
58
  module ARRAYORDER
56
59
  include EnumerableConstants
57
- NONE
58
- RGB
59
- RGBA
60
- ARGB
61
- BGR
62
- BGRA
63
- ABGR
60
+ NONE = next_const_value
61
+ RGB = next_const_value
62
+ RGBA = next_const_value
63
+ ARGB = next_const_value
64
+ BGR = next_const_value
65
+ BGRA = next_const_value
66
+ ABGR = next_const_value
64
67
  end
65
68
 
66
69
  enum :arrayorder, ARRAYORDER.flatten_consts
@@ -68,15 +71,15 @@ module SDL2
68
71
  # Packed component layout
69
72
  module PACKEDLAYOUT
70
73
  include EnumerableConstants
71
- NONE
72
- N332
73
- N4444
74
- N1555
75
- N5551
76
- N565
77
- N8888
78
- N2101010
79
- N1010102
74
+ NONE = next_const_value
75
+ N332 = next_const_value
76
+ N4444 = next_const_value
77
+ N1555 = next_const_value
78
+ N5551 = next_const_value
79
+ N565 = next_const_value
80
+ N8888 = next_const_value
81
+ N2101010 = next_const_value
82
+ N1010102 = next_const_value
80
83
  end
81
84
 
82
85
  enum :packedlayout, PACKEDLAYOUT.flatten_consts
@@ -193,25 +196,34 @@ module SDL2
193
196
  UYVY = SDL2.define_pixelfourcc('U', 'Y', 'V', 'Y')
194
197
  YVYU = SDL2.define_pixelfourcc('Y', 'V', 'Y', 'U')
195
198
  end
196
-
199
+
200
+ enum :pixel_format, PIXELFORMAT.flatten_consts
201
+
202
+ class TypedPointer
203
+ class PixelFormat < TypedPointer
204
+ type :pixel_format
205
+ end
206
+ end
207
+
208
+ require 'sdl2/pixel_format'
197
209
  ##
198
210
  #
199
211
  api :SDL_GetPixelFormatName, [:pixel_format], :string
200
212
  ##
201
213
  #
202
- api :SDL_PixelFormatEnumToMasks, [:pixel_format, IntStruct.by_ref, UInt32Struct.by_ref, UInt32Struct.by_ref,UInt32Struct.by_ref,UInt32Struct.by_ref,], :bool
214
+ api :SDL_PixelFormatEnumToMasks, [:pixel_format, TypedPointer::Int.by_ref, TypedPointer::UInt32.by_ref, TypedPointer::UInt32.by_ref,TypedPointer::UInt32.by_ref,TypedPointer::UInt32.by_ref,], :bool
203
215
  ##
204
216
  #
205
217
  api :SDL_MasksToPixelFormatEnum, [:int, :uint32, :uint32, :uint32, :uint32], :pixel_format
206
218
  ##
207
219
  #
208
- api :SDL_AllocFormat, [:pixel_format], PixelFormat.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
220
+ api :SDL_AllocFormat, [:pixel_format], PixelFormat.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
209
221
  ##
210
222
  #
211
223
  api :SDL_FreeFormat, [PixelFormat.by_ref], :void
212
224
  ##
213
225
  #
214
- api :SDL_AllocPalette, [:count], Palette.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
226
+ api :SDL_AllocPalette, [:count], Palette.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
215
227
  ##
216
228
  #
217
229
  api :SDL_SetPixelFormatPalette, [PixelFormat.by_ref, Palette.by_ref], :int
@@ -229,9 +241,9 @@ module SDL2
229
241
  api :SDL_MapRGBA, [PixelFormat.by_ref, :uint8, :uint8, :uint8, :uint8], :uint32
230
242
  ##
231
243
  #
232
- api :SDL_GetRGB, [:uint32, PixelFormat.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :void
244
+ api :SDL_GetRGB, [:uint32, PixelFormat.by_ref, TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref], :void
233
245
  ##
234
246
  #
235
- api :SDL_GetRGBA, [:uint32, PixelFormat.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :void
247
+ api :SDL_GetRGBA, [:uint32, PixelFormat.by_ref, TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref], :void
236
248
 
237
249
  end
@@ -15,6 +15,6 @@ module SDL2
15
15
 
16
16
  ##
17
17
  #
18
- api :SDL_GetPowerInfo, [IntStruct.by_ref, IntStruct.by_ref], :powerstate
18
+ api :SDL_GetPowerInfo, [TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :powerstate
19
19
 
20
20
  end
@@ -16,13 +16,12 @@ module SDL2
16
16
  def self.cast(something)
17
17
 
18
18
  if something.kind_of?(Array)
19
- something.map!(&:to_i)
20
19
  result = Rect.new
21
20
  case something.count
22
21
  when 4
23
- result.x, result.y, result.w, result.h = something
22
+ result.x, result.y, result.w, result.h = something.map(&:to_i)
24
23
  when 2
25
- result.x, result.y = something
24
+ result.x, result.y = something.map(&:to_i)
26
25
  else
27
26
  raise "#{self}#cast cannot convert array length #{something.count} of: #{something.inspect}"
28
27
  end
@@ -60,7 +59,7 @@ module SDL2
60
59
 
61
60
 
62
61
  # Determine whether two rectangles intersect.
63
- # @param Another rectangle to test against.
62
+ # * Another rectangle to test against.
64
63
  # @return True when they touch, false when they don't
65
64
  def has_intersection?(rect)
66
65
  rect = Rect.cast(rect)
@@ -68,7 +67,7 @@ module SDL2
68
67
  end
69
68
 
70
69
  # Calculate the intersection of two rectangles.
71
- # @param Another rectangle to find intersection with self.
70
+ # * Another rectangle to find intersection with self.
72
71
  # @return Rect or Nil if no intersection found.
73
72
  def intersection(rect)
74
73
  rect = Rect.cast(rect)
@@ -4,9 +4,20 @@ require 'sdl2/renderer'
4
4
  require 'sdl2/texture'
5
5
  require 'sdl2/point'
6
6
 
7
- module SDL2
7
+ ##
8
+ # == 2D Accelerated Rendering
9
+ # API Supports these primitives:
10
+ # * Single Pixel Points
11
+ # * Single Pixel Lines
12
+ # * Filled Rectangles
13
+ # * Texture Images
14
+ # Rendered in Opaque, Blended, or Additive modes.
15
+ # Textures have additional tint or alpha modulation,
16
+ # and the API supports stretching, rotation, or
17
+ # mirroring.
18
+ # NOTE: THIS API IS NOT THREAD SAFE
19
+ module SDL2
8
20
  enum :renderer_flags, RENDERER.flatten_consts
9
-
10
21
  # The access pattern allowed for a texture
11
22
  module TEXTUREACCESS
12
23
  include EnumerableConstants
@@ -14,184 +25,88 @@ module SDL2
14
25
  STREAMING
15
26
  TARGET
16
27
  end
17
- enum :texture_access, TEXTUREACCESS.flatten_consts
18
-
19
- # The texture channel modulation used in #render_copy
28
+ enum :texture_access, TEXTUREACCESS.flatten_consts
29
+
30
+ class TypedPointer
31
+ class TextureAccess < TypedPointer
32
+ type :texture_access
33
+ end
34
+ end
35
+
36
+ # The texture channel modulation used in #render_copy
20
37
  module TEXTUREMODULATE
21
38
  include EnumerableConstants
22
- NONE = 0x00000000
23
- COLOR = 0x00000001
24
- ALPHA = 0x00000002
25
- end
39
+ NONE = 0x00000000
40
+ COLOR = 0x00000001
41
+ ALPHA = 0x00000002
42
+ end
26
43
  enum :texture_modulate, TEXTUREMODULATE.flatten_consts
27
-
44
+
28
45
  # Constants for #render_copy_ex
29
46
  module FLIP
30
47
  include EnumerableConstants
31
48
  NONE = 0x00000000
32
49
  HORIZONTAL = 0x00000001
33
- VERTICAL = 0x00000002
50
+ VERTICAL = 0x00000002
51
+ BOTH = HORIZONTAL | VERTICAL
34
52
  end
35
53
  enum :renderer_flip, FLIP.flatten_consts
36
-
54
+
37
55
  typedef :int, :render_driver_index
38
-
39
- ##
40
- #
41
- api :SDL_GetNumRenderDrivers, [], :int
42
- ##
43
- #
44
- api :SDL_GetRenderDriverInfo, [:render_driver_index, RendererInfo.by_ref], :int
45
- ##
46
- #
47
- api :SDL_CreateWindowAndRenderer, [:int, :int, :window_flags, Window.by_ref, Renderer.by_ref], :int
48
- ##
49
- #
50
- api :SDL_CreateRenderer, [Window.by_ref, :render_driver_index, :renderer_flags], Renderer.auto_ptr
51
- ##
52
- #
53
- api :SDL_CreateSoftwareRenderer, [Surface.by_ref], Renderer.auto_ptr
54
- ##
55
- #
56
- api :SDL_GetRenderer, [Window.by_ref], Renderer.auto_ptr
57
- ##
58
- #
59
- api :SDL_GetRendererInfo, [Renderer.by_ref, RendererInfo.by_ref], :int
60
- ##
61
- #
62
- api :SDL_GetRendererOutputSize, [Renderer.by_ref, IntStruct.by_ref, IntStruct.by_ref], :int
63
- ##
64
- #
65
- api :SDL_CreateTexture, [Renderer.by_ref, :pixel_format, :texture_access, :int, :int], Texture.auto_ptr
66
- ##
67
- #
68
- api :SDL_CreateTextureFromSurface, [Renderer.by_ref, Surface.by_ref], Texture.auto_ptr
69
- ##
70
- #
71
- api :SDL_QueryTexture, [Texture.by_ref, UInt32Struct.by_ref, IntStruct.by_ref, IntStruct.by_ref, IntStruct.by_ref], :int
72
- ##
73
- #
74
- api :SDL_SetTextureColorMod, [Texture.by_ref, :uint8, :uint8, :uint8], :int
75
- ##
76
- #
77
- api :SDL_GetTextureColorMod, [Texture.by_ref, UInt8Struct.by_ref, UInt8Struct.by_ref, UInt8Struct.by_ref], :int
78
- ##
79
- #
80
- api :SDL_SetTextureAlphaMod, [Texture.by_ref, :uint8], :int
81
- ##
82
- #
83
- api :SDL_GetTextureAlphaMod, [Texture.by_ref, UInt8Struct.by_ref], :int
84
- ##
85
- #
86
- api :SDL_SetTextureBlendMode, [Texture.by_ref, :blend_mode], :int
87
- ##
88
- #
89
- api :SDL_GetTextureBlendMode, [Texture.by_ref, BlendModeStruct.by_ref], :int
90
- ##
91
- #
92
- api :SDL_UpdateTexture, [Texture.by_ref, Rect.by_ref, :pointer, :int], :int
93
- ##
94
- #
95
- api :SDL_LockTexture, [Texture.by_ref, Rect.by_ref, :pointer, IntStruct.by_ref], :int
96
- ##
97
- #
98
- api :SDL_UnlockTexture, [Texture.by_ref], :void
99
- ##
100
- #
101
- api :SDL_RenderTargetSupported, [Renderer.by_ref], :bool
102
- ##
103
- #
104
- api :SDL_GetRenderTarget, [Renderer.by_ref], Texture.by_ref
105
- ##
106
- #
107
- api :SDL_SetRenderTarget, [Renderer.by_ref, Texture.by_ref], :int
108
- ##
109
- #
110
- api :SDL_RenderSetLogicalSize, [Renderer.by_ref, :int, :int],:int
111
- ##
112
- #
113
- api :SDL_RenderGetLogicalSize, [Renderer.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
114
- ##
115
- #
116
- api :SDL_RenderSetViewport, [Renderer.by_ref, Rect.by_ref], :int
117
- ##
118
- #
119
- api :SDL_RenderGetViewport, [Renderer.by_ref, Rect.by_ref], :int
120
- ##
121
- #
122
- api :SDL_RenderSetClipRect, [Renderer.by_ref, Rect.by_ref], :int
123
- ##
124
- #
125
- api :SDL_RenderGetClipRect, [Renderer.by_ref, Rect.by_ref], :int
126
- ##
127
- #
128
- api :SDL_RenderSetScale, [Renderer.by_ref, :float, :float], :int
129
- ##
130
- #
131
- api :SDL_RenderGetScale, [Renderer.by_ref, FloatPointer.by_ref, FloatPointer.by_ref], :int
132
- ##
133
- #
134
- api :SDL_SetRenderDrawColor, [Renderer.by_ref, :uint8, :uint8, :uint8, :uint8], :int
135
- ##
136
- #
137
- api :SDL_GetRenderDrawColor, [Renderer.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :int
138
- ##
139
- #
140
- api :SDL_SetRenderDrawBlendMode, [Renderer.by_ref, :blend_mode], :int
141
- ##
142
- #
143
- api :SDL_GetRenderDrawBlendMode, [Renderer.by_ref, BlendModeStruct.by_ref], :int
144
- ##
145
- #
146
- api :SDL_RenderClear, [Renderer.by_ref], :int
147
- ##
148
- #
149
- api :SDL_RenderDrawPoint, [Renderer.by_ref, :int, :int], :int
150
- ##
151
- #
152
- api :SDL_RenderDrawPoints, [Renderer.by_ref, Point.by_ref, :count], :int
153
- ##
154
- #
155
- api :SDL_RenderDrawLine, [Renderer.by_ref, :int, :int, :int, :int], :int
156
- ##
157
- #
158
- api :SDL_RenderDrawLines, [Renderer.by_ref, Point.by_ref, :count], :int
159
- ##
160
- #
161
- api :SDL_RenderDrawRect, [Renderer.by_ref, Rect.by_ref], :int
162
- ##
163
- #
164
- api :SDL_RenderDrawRects, [Renderer.by_ref, Rect.by_ref, :count], :int
165
- ##
166
- #
167
- api :SDL_RenderFillRect, [Renderer.by_ref, Rect.by_ref], :int
168
- ##
169
- #
170
- api :SDL_RenderFillRects, [Renderer.by_ref, Rect.by_ref, :count], :int
171
- ##
172
- #
173
- api :SDL_RenderCopy, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref], :int
174
- ##
175
- #
176
- api :SDL_RenderCopyEx, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref, :double, Point.by_ref, :renderer_flip], :int
177
- ##
178
- #
179
- api :SDL_RenderReadPixels, [Renderer.by_ref, Rect.by_ref, :pixel_format, :pointer, :int], :int #TODO: Review linking.
180
- ##
181
- #
182
- api :SDL_RenderPresent, [Renderer.by_ref], :void
183
- ##
184
- #
185
- api :SDL_DestroyTexture, [Texture.by_ref], :void
186
- ##
187
- #
188
- api :SDL_DestroyRenderer, [Renderer.by_ref], :void
189
- ##
190
- #
191
- api :SDL_GL_BindTexture, [Texture.by_ref, FloatPointer.by_ref, FloatPointer.by_ref], :int
192
- ##
193
- #
194
- api :SDL_GL_UnbindTexture, [Texture.by_ref], :int
195
-
56
+
57
+ api :SDL_GetNumRenderDrivers, [], :int, {error: true, filter: OK_WHEN_GTE_ZERO}
58
+ api :SDL_GetRenderDriverInfo, [:render_driver_index, RendererInfo.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
59
+ api :SDL_CreateWindowAndRenderer, [:int, :int, :window_flags, Window.by_ref, Renderer.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
60
+ api :SDL_CreateRenderer, [Window.by_ref, :render_driver_index, :renderer_flags], Renderer.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
61
+ api :SDL_CreateSoftwareRenderer, [Surface.by_ref], Renderer.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
62
+ api :SDL_GetRenderer, [Window.by_ref], Renderer.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
63
+ api :SDL_GetRendererInfo, [Renderer.by_ref, RendererInfo.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
64
+ api :SDL_GetRendererOutputSize, [Renderer.by_ref, TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
65
+ api :SDL_CreateTexture, [Renderer.by_ref, :pixel_format, :texture_access, :int, :int], Texture.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
66
+ api :SDL_CreateTextureFromSurface, [Renderer.by_ref, Surface.by_ref], Texture.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
67
+ api :SDL_QueryTexture, [Texture.by_ref, TypedPointer::PixelFormat.by_ref, TypedPointer::TextureAccess.by_ref, TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
68
+ api :SDL_SetTextureColorMod, [Texture.by_ref, :uint8, :uint8, :uint8], :int,{error: true, filter: OK_WHEN_ZERO}
69
+ api :SDL_GetTextureColorMod, [Texture.by_ref, TypedPointer::UInt8.by_ref, TypedPointer::UInt8.by_ref, TypedPointer::UInt8.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
70
+ api :SDL_SetTextureAlphaMod, [Texture.by_ref, :uint8], :int,{error: true, filter: OK_WHEN_ZERO}
71
+ api :SDL_GetTextureAlphaMod, [Texture.by_ref, TypedPointer::UInt8.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
72
+ api :SDL_SetTextureBlendMode, [Texture.by_ref, :blend_mode], :int, {error: true, filter: OK_WHEN_ZERO}
73
+ api :SDL_GetTextureBlendMode, [Texture.by_ref, SDL2::TypedPointer::BlendMode.by_ref], :int,{error: true, filter: OK_WHEN_ZERO}
74
+ api :SDL_UpdateTexture, [Texture.by_ref, Rect.by_ref, :pointer, :int], :int, {error: true, filter: OK_WHEN_ZERO}
75
+ api :SDL_LockTexture, [Texture.by_ref, Rect.by_ref, TypedPointer::Pointer.by_ref, TypedPointer::Int.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
76
+ api :SDL_UnlockTexture, [Texture.by_ref], :void
77
+ api :SDL_RenderTargetSupported, [Renderer.by_ref], :bool
78
+ api :SDL_GetRenderTarget, [Renderer.by_ref], Texture.by_ref
79
+ api :SDL_SetRenderTarget, [Renderer.by_ref, Texture.by_ref], :int,{error: true, filter: OK_WHEN_ZERO}
80
+ api :SDL_RenderSetLogicalSize, [Renderer.by_ref, :int, :int],:int,{error: true, filter: OK_WHEN_ZERO}
81
+ api :SDL_RenderGetLogicalSize, [Renderer.by_ref, TypedPointer::Int.by_ref, TypedPointer::Int.by_ref], :void
82
+ api :SDL_RenderSetViewport, [Renderer.by_ref, Rect.by_ref], :int,{error: true, filter: OK_WHEN_ZERO}
83
+ api :SDL_RenderGetViewport, [Renderer.by_ref, Rect.by_ref], :int
84
+ api :SDL_RenderSetClipRect, [Renderer.by_ref, Rect.by_ref], :int,{error: true, filter: OK_WHEN_ZERO}
85
+ api :SDL_RenderGetClipRect, [Renderer.by_ref, Rect.by_ref], :void
86
+
87
+ api :SDL_RenderSetScale, [Renderer.by_ref, :float, :float], :int,{error: true, filter: OK_WHEN_ZERO}
88
+ api :SDL_RenderGetScale, [Renderer.by_ref, TypedPointer::Float.by_ref, TypedPointer::Float.by_ref], :int
89
+ api :SDL_SetRenderDrawColor, [Renderer.by_ref, :uint8, :uint8, :uint8, :uint8], :int,{error: true, filter: OK_WHEN_ZERO}
90
+ api :SDL_GetRenderDrawColor, [Renderer.by_ref, TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref,TypedPointer::UInt8.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
91
+ api :SDL_SetRenderDrawBlendMode, [Renderer.by_ref, :blend_mode], :int,{error: true, filter: OK_WHEN_ZERO}
92
+ api :SDL_GetRenderDrawBlendMode, [Renderer.by_ref, SDL2::TypedPointer::BlendMode.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
93
+ api :SDL_RenderClear, [Renderer.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
94
+ api :SDL_RenderDrawPoint, [Renderer.by_ref, :int, :int], :int, {error: true, filter: OK_WHEN_ZERO}
95
+ api :SDL_RenderDrawPoints, [Renderer.by_ref, Point.by_ref, :count], :int, {error: true, filter: OK_WHEN_ZERO}
96
+ api :SDL_RenderDrawLine, [Renderer.by_ref, :int, :int, :int, :int], :int, {error: true, filter: OK_WHEN_ZERO}
97
+ api :SDL_RenderDrawLines, [Renderer.by_ref, Point.by_ref, :count], :int, {error: true, filter: OK_WHEN_ZERO}
98
+ api :SDL_RenderDrawRect, [Renderer.by_ref, Rect.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
99
+ api :SDL_RenderDrawRects, [Renderer.by_ref, Rect.by_ref, :count], :int, {error: true, filter: OK_WHEN_ZERO}
100
+ api :SDL_RenderFillRect, [Renderer.by_ref, Rect.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
101
+ api :SDL_RenderFillRects, [Renderer.by_ref, Rect.by_ref, :count], :int, {error: true, filter: OK_WHEN_ZERO}
102
+ api :SDL_RenderCopy, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref], :int, {error: true, filter: OK_WHEN_ZERO}
103
+ api :SDL_RenderCopyEx, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref, :double, Point.by_ref, :renderer_flip], :int, {error: true, filter: OK_WHEN_ZERO}
104
+ api :SDL_RenderReadPixels, [Renderer.by_ref, Rect.by_ref, :pixel_format, :pointer, :int], :int,{error: true, filter: OK_WHEN_ZERO}
105
+ api :SDL_RenderPresent, [Renderer.by_ref], :void
106
+ api :SDL_DestroyTexture, [Texture.by_ref], :void
107
+ api :SDL_DestroyRenderer, [Renderer.by_ref], :void
108
+ api :SDL_GL_BindTexture, [Texture.by_ref, TypedPointer::Float.by_ref, TypedPointer::Float.by_ref], :int
109
+ api :SDL_GL_UnbindTexture, [Texture.by_ref], :int
110
+
196
111
 
197
112
  end