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
@@ -0,0 +1,23 @@
1
+ module SDL2
2
+ ##
3
+ # A Joystick has all kinds of components, such as
4
+ class Joystick
5
+ ##
6
+ # Abstract component enumerator
7
+ # Requires :count and :[] to be defined
8
+ class Components
9
+ ##
10
+ # Initialize an enumeration
11
+ def initialize(for_joystick)
12
+ @joystick = for_joystick
13
+ raise "Must be an SDL2::Joystick, not a #{@joystick.class.to_s}" unless @joystick.kind_of?(SDL2::Joystick)
14
+ end
15
+
16
+ ##
17
+ # Generate enumerator, captures all at call time
18
+ def each(&block)
19
+ count.times.map{|idx|self[idx]}.each(&block)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'sdl2/joystick/components'
2
+ module SDL2
3
+ ##
4
+ # A Joystick may have many hats.
5
+ class Joystick
6
+ ##
7
+ # Enumerates hats on a joystick.
8
+ class Hats < Components
9
+ ##
10
+ # How many hats are there?
11
+ def count
12
+ SDL2::joystick_num_hats(@joystick)
13
+ end
14
+ ##
15
+ # Hat accessor via index
16
+ # @returns Integer (See: SDL2::HAT constants)
17
+ def [](idx)
18
+ SDL2::joystick_get_hat(@joystick,idx)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -27,10 +27,12 @@ module SDL2
27
27
  # get_keyboard_focus!
28
28
  api :SDL_GetKeyboardFocus, [], Window.by_ref
29
29
 
30
+
31
+
30
32
  ##
31
33
  # brief Get a snapshot of the current state of the keyboard.
32
34
  #
33
- # @param numkeys if non-NULL, receives the length of the returned array.
35
+ # * numkeys if non-NULL, receives the length of the returned array.
34
36
  #
35
37
  # @return An array of key states.
36
38
  # Indexes into this array are obtained by using ::SDL_Scancode values.
@@ -43,9 +45,8 @@ module SDL2
43
45
  # if state[SDL2::SCANCODE::RETURN]
44
46
  # puts("<RETURN> is pressed.\n");
45
47
  # end
46
- api :SDL_GetKeyboardState, [:pointer], :pointer
47
-
48
-
48
+ api :SDL_GetKeyboardState, [TypedPointer::Int.by_ref], :pointer
49
+
49
50
  ##
50
51
  #
51
52
  api :SDL_GetModState, [], :keymod
@@ -97,9 +98,11 @@ module SDL2
97
98
 
98
99
  # Get a snapshot of the current state of the keyboard.
99
100
  def self.get_state()
100
- count = FFI::MemoryPointer.new :int, 1
101
- state = FFI::Pointer.new :uint8, SDL2::get_keyboard_state(count)
102
- result = state.get_array_of_int(0, count.get_int(0))
101
+ count = SDL2::TypedPointer::Int.new
102
+
103
+ state = SDL2::get_keyboard_state(count)
104
+ #binding.pry
105
+ result = state.get_array_of_uint8(:uint8, :get_uint8, count.value)
103
106
  count.free
104
107
  state.free
105
108
  return result
@@ -114,8 +117,6 @@ module SDL2
114
117
  # @note This does not change the keyboard state, only the key modifier flags.
115
118
  def self.set_mod(modstate)
116
119
  SDL2::set_mod_state(modstate)
117
- end
118
-
119
-
120
+ end
120
121
  end
121
122
  end
@@ -17,76 +17,76 @@ module SDL2
17
17
  include EnumerableConstants
18
18
  UNKNOWN = 0
19
19
 
20
- RETURN = '\r'.codepoints()[0]
21
- ESCAPE = '\033'.codepoints()[0]
22
- BACKSPACE = '\b'.codepoints()[0]
23
- TAB = '\t'.codepoints()[0]
24
- SPACE = ' '.codepoints()[0]
25
- EXCLAIM = '!'.codepoints()[0]
26
- QUOTEDBL = '"'.codepoints()[0]
27
- HASH = '#'.codepoints()[0]
28
- PERCENT = '%'.codepoints()[0]
29
- DOLLAR = '$'.codepoints()[0]
30
- AMPERSAND = '&'.codepoints()[0]
31
- QUOTE = '\''.codepoints()[0]
32
- LEFTPAREN = '('.codepoints()[0]
33
- RIGHTPAREN = ')'.codepoints()[0]
34
- ASTERISK = '*'.codepoints()[0]
35
- PLUS = '+'.codepoints()[0]
36
- COMMA = ','.codepoints()[0]
37
- MINUS = '-'.codepoints()[0]
38
- PERIOD = '.'.codepoints()[0]
39
- SLASH = '/'.codepoints()[0]
40
- N0 = '0'.codepoints()[0]
41
- N1 = '1'.codepoints()[0]
42
- N2 = '2'.codepoints()[0]
43
- N3 = '3'.codepoints()[0]
44
- N4 = '4'.codepoints()[0]
45
- N5 = '5'.codepoints()[0]
46
- N6 = '6'.codepoints()[0]
47
- N7 = '7'.codepoints()[0]
48
- N8 = '8'.codepoints()[0]
49
- N9 = '9'.codepoints()[0]
50
- COLON = ':'.codepoints()[0]
51
- SEMICOLON = ';'.codepoints()[0]
52
- LESS = '<'.codepoints()[0]
53
- EQUALS = '='.codepoints()[0]
54
- GREATER = '>'.codepoints()[0]
55
- QUESTION = '?'.codepoints()[0]
56
- AT = '@'.codepoints()[0]
20
+ RETURN = "\r".bytes[0]
21
+ ESCAPE = "\033".bytes[0]
22
+ BACKSPACE = "\b".bytes[0]
23
+ TAB = "\t".bytes[0]
24
+ SPACE = ' '.bytes[0]
25
+ EXCLAIM = '!'.bytes[0]
26
+ QUOTEDBL = '"'.bytes[0]
27
+ HASH = '#'.bytes[0]
28
+ PERCENT = '%'.bytes[0]
29
+ DOLLAR = '$'.bytes[0]
30
+ AMPERSAND = '&'.bytes[0]
31
+ QUOTE = '\''.bytes[0]
32
+ LEFTPAREN = '('.bytes[0]
33
+ RIGHTPAREN = ')'.bytes[0]
34
+ ASTERISK = '*'.bytes[0]
35
+ PLUS = '+'.bytes[0]
36
+ COMMA = ','.bytes[0]
37
+ MINUS = '-'.bytes[0]
38
+ PERIOD = '.'.bytes[0]
39
+ SLASH = '/'.bytes[0]
40
+ N0 = '0'.bytes[0]
41
+ N1 = '1'.bytes[0]
42
+ N2 = '2'.bytes[0]
43
+ N3 = '3'.bytes[0]
44
+ N4 = '4'.bytes[0]
45
+ N5 = '5'.bytes[0]
46
+ N6 = '6'.bytes[0]
47
+ N7 = '7'.bytes[0]
48
+ N8 = '8'.bytes[0]
49
+ N9 = '9'.bytes[0]
50
+ COLON = ':'.bytes[0]
51
+ SEMICOLON = ';'.bytes[0]
52
+ LESS = '<'.bytes[0]
53
+ EQUALS = '='.bytes[0]
54
+ GREATER = '>'.bytes[0]
55
+ QUESTION = '?'.bytes[0]
56
+ AT = '@'.bytes[0]
57
57
 
58
- LEFTBRACKET = '['.codepoints()[0]
59
- BACKSLASH = '\\'.codepoints()[0]
60
- RIGHTBRACKET = ']'.codepoints()[0]
61
- CARET = '^'.codepoints()[0]
62
- UNDERSCORE = '_'.codepoints()[0]
63
- BACKQUOTE = '`'.codepoints()[0]
64
- A = 'a'.codepoints()[0]
65
- B = 'b'.codepoints()[0]
66
- C = 'c'.codepoints()[0]
67
- D = 'd'.codepoints()[0]
68
- E = 'e'.codepoints()[0]
69
- F = 'f'.codepoints()[0]
70
- G = 'g'.codepoints()[0]
71
- H = 'h'.codepoints()[0]
72
- I = 'i'.codepoints()[0]
73
- J = 'j'.codepoints()[0]
74
- K = 'k'.codepoints()[0]
75
- L = 'l'.codepoints()[0]
76
- M = 'm'.codepoints()[0]
77
- N = 'n'.codepoints()[0]
78
- O = 'o'.codepoints()[0]
79
- P = 'p'.codepoints()[0]
80
- Q = 'q'.codepoints()[0]
81
- R = 'r'.codepoints()[0]
82
- S = 's'.codepoints()[0]
83
- T = 't'.codepoints()[0]
84
- U = 'u'.codepoints()[0]
85
- V = 'v'.codepoints()[0]
86
- W = 'w'.codepoints()[0]
87
- X = 'x'.codepoints()[0]
88
- Y = 'y'.codepoints()[0]
89
- Z = 'z'.codepoints()[0]
58
+ LEFTBRACKET = '['.bytes[0]
59
+ BACKSLASH = "\\".bytes[0]
60
+ RIGHTBRACKET = ']'.bytes[0]
61
+ CARET = '^'.bytes[0]
62
+ UNDERSCORE = '_'.bytes[0]
63
+ BACKQUOTE = '`'.bytes[0]
64
+ A = 'a'.bytes[0]
65
+ B = 'b'.bytes[0]
66
+ C = 'c'.bytes[0]
67
+ D = 'd'.bytes[0]
68
+ E = 'e'.bytes[0]
69
+ F = 'f'.bytes[0]
70
+ G = 'g'.bytes[0]
71
+ H = 'h'.bytes[0]
72
+ I = 'i'.bytes[0]
73
+ J = 'j'.bytes[0]
74
+ K = 'k'.bytes[0]
75
+ L = 'l'.bytes[0]
76
+ M = 'm'.bytes[0]
77
+ N = 'n'.bytes[0]
78
+ O = 'o'.bytes[0]
79
+ P = 'p'.bytes[0]
80
+ Q = 'q'.bytes[0]
81
+ R = 'r'.bytes[0]
82
+ S = 's'.bytes[0]
83
+ T = 't'.bytes[0]
84
+ U = 'u'.bytes[0]
85
+ V = 'v'.bytes[0]
86
+ W = 'w'.bytes[0]
87
+ X = 'x'.bytes[0]
88
+ Y = 'y'.bytes[0]
89
+ Z = 'z'.bytes[0]
90
90
 
91
91
  CAPSLOCK = SDL2.scancode_to_keycode(SCANCODE::CAPSLOCK)
92
92
 
@@ -109,7 +109,7 @@ module SDL2
109
109
  INSERT = SDL2.scancode_to_keycode(SCANCODE::INSERT)
110
110
  HOME = SDL2.scancode_to_keycode(SCANCODE::HOME)
111
111
  PAGEUP = SDL2.scancode_to_keycode(SCANCODE::PAGEUP)
112
- DELETE = '\177'.codepoints()[0]
112
+ DELETE = "\177".bytes[0]
113
113
  END_ = SDL2.scancode_to_keycode(SCANCODE::END_)
114
114
  PAGEDOWN = SDL2.scancode_to_keycode(SCANCODE::PAGEDOWN)
115
115
  RIGHT = SDL2.scancode_to_keycode(SCANCODE::RIGHT)
@@ -9,11 +9,7 @@ module SDL2
9
9
  # "xxx_yyyy_zzz" convetion
10
10
  def api(func_name, args, type, options = {})
11
11
 
12
- options = {
13
- :error => false,
14
- :filter => type == :bool ? TRUE_WHEN_TRUE : TRUE_WHEN_ZERO
15
- }.merge(options)
16
-
12
+
17
13
  # TODO: Review ugly hack:
18
14
  remove_part = case self.to_s
19
15
  when "SDL2"
@@ -29,8 +25,13 @@ module SDL2
29
25
  /[A-Z][A-Z|0-9]*_/
30
26
  end
31
27
 
32
- camelCaseName = func_name.to_s.gsub(remove_part,'')
33
- methodName = ActiveSupport::Inflector.underscore(camelCaseName).to_sym
28
+ options = {
29
+ :error => false,
30
+ :filter => type == :bool ? OK_WHEN_TRUE : OK_WHEN_ZERO,
31
+ :method_name => ActiveSupport::Inflector.underscore(func_name.to_s.gsub(remove_part,'')).to_sym,
32
+ }.merge(options)
33
+
34
+ methodName = options[:method_name]
34
35
 
35
36
  attach_function methodName, func_name, args, type
36
37
 
@@ -39,6 +39,7 @@ module SDL2
39
39
  RESERVED10 = next_const_value
40
40
  CUSTOM = next_const_value
41
41
  end
42
+
42
43
  def self.<<(msg, *args)
43
44
  SDL2.log(msg, *args)
44
45
  end
@@ -70,6 +71,11 @@ module SDL2
70
71
  def self.get_priority(category)
71
72
  SDL2.log_get_priority(category)
72
73
  end
74
+
75
+ def self.with_temp_priority(level)
76
+ raise "Block required" unless block_given?
77
+ old_cat = self.get_priority(category)
78
+ end
73
79
  end
74
80
 
75
81
  enum :log_priority, Log::PRIORITY.flatten_consts
@@ -0,0 +1,17 @@
1
+ module SDL2
2
+ ##
3
+ # FFI::ManagedStruct possibly with useful additions.
4
+ class ManagedStruct < FFI::ManagedStruct
5
+ extend StructHelper
6
+ # Allows create and use the struct within a block.
7
+ def initialize(*args, &block)
8
+ SDL2::Debug.log(self){"Initializing with: #{args.inspect}"}
9
+ super(*args)
10
+ if block_given?
11
+ yield self
12
+ end
13
+ end
14
+
15
+
16
+ end
17
+ end
@@ -35,7 +35,7 @@ module SDL2
35
35
  ##
36
36
  # This function gets the version of the dynamically linked SDL_mixer library.
37
37
  # :method: linked_version
38
- api :Mix_Linked_Version, [], Version.auto_ptr
38
+ api :Mix_Linked_Version, [], Version.ptr
39
39
 
40
40
  enum :init_flags, INIT.flatten_consts
41
41
 
@@ -47,7 +47,7 @@ module SDL2
47
47
  # Mix_Init(flags)
48
48
  # init(flags)
49
49
  # init!(flags)
50
- api :Mix_Init, [:init_flags], :int, {error: true, filter: TRUE_WHEN_NOT_ZERO}
50
+ api :Mix_Init, [:init_flags], :int, {error: true, filter: OK_WHEN_NOT_ZERO}
51
51
 
52
52
  ##
53
53
  # Unloads libraries loaded with Mix_Init
@@ -110,6 +110,10 @@ module SDL2
110
110
  def self.pause
111
111
  Mixer::pause_music
112
112
  end
113
+
114
+ def self.release(pointer)
115
+ Mixer::free_music(pointer)
116
+ end
113
117
  end
114
118
 
115
119
  ##
@@ -140,7 +144,7 @@ module SDL2
140
144
  # Load a wave file
141
145
  # :call-seq:
142
146
  # load_wav_rw(src_rwops, freesrc)
143
- api :Mix_LoadWAV_RW, [RWops.by_ref, :int], Chunk.auto_ptr
147
+ api :Mix_LoadWAV_RW, [RWops.by_ref, :int], Chunk.ptr
144
148
 
145
149
  ##
146
150
  # Load a wave file or a music (.mod .s3m .it .xm) file
@@ -148,30 +152,30 @@ module SDL2
148
152
  Mixer::load_wav_rw(RWops.from_file(filename, "rb"), 1)
149
153
  end
150
154
 
151
- returns_error :load_wav, TRUE_WHEN_NOT_NULL
155
+ returns_error :load_wav, OK_WHEN_NOT_NULL
152
156
 
153
157
  ##
154
158
  # Load a wave file or a music (.mod .s3m .it .xm) file
155
159
  # :call-seq:
156
160
  # load_mus(filepath)
157
- api :Mix_LoadMUS, [:string], Music.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
161
+ api :Mix_LoadMUS, [:string], Music.ptr, {error: true, filter: OK_WHEN_NOT_NULL}
158
162
 
159
163
  ##
160
164
  # Load a music file from an SDL_RWop object (Ogg and MikMod specific currently)
161
165
  # Matt Campbell (matt@campbellhome.dhs.org) April 2000
162
- api :Mix_LoadMUS_RW, [RWops.by_ref, :int], Music.auto_ptr
166
+ api :Mix_LoadMUS_RW, [RWops.by_ref, :int], Music.ptr
163
167
 
164
168
  ##
165
169
  # Load a music file from an SDL_RWop object assuming a specific format
166
- api :Mix_LoadMUSType_RW, [RWops.by_ref, :music_type, :int], Music.auto_ptr
170
+ api :Mix_LoadMUSType_RW, [RWops.by_ref, :music_type, :int], Music.ptr
167
171
 
168
172
  ##
169
173
  # Load a wave file of the mixer format from a memory buffer
170
- api :Mix_QuickLoad_WAV, [:pointer], Chunk.auto_ptr
174
+ api :Mix_QuickLoad_WAV, [:pointer], Chunk.ptr
171
175
 
172
176
  ##
173
177
  # Load raw audio data of the mixer format from a memory buffer
174
- api :Mix_QuickLoad_RAW, [:pointer, :uint32], Chunk.auto_ptr
178
+ api :Mix_QuickLoad_RAW, [:pointer, :uint32], Chunk.ptr
175
179
 
176
180
  ##
177
181
  # Free an audio chunk previously loaded
@@ -597,7 +601,7 @@ module SDL2
597
601
  api :Mix_ResumeMusic, [], :void
598
602
  api :Mix_RewindMusic, [], :void
599
603
  api :Mix_PausedMusic, [], :int
600
- boolean? :paused_music, TRUE_WHEN_NOT_ZERO
604
+ boolean? :paused_music, OK_WHEN_NOT_ZERO
601
605
 
602
606
 
603
607
  ##
@@ -612,10 +616,10 @@ module SDL2
612
616
  # Check the status of a specific channel.
613
617
  # If the specified channel is -1, check all channels.
614
618
  api :Mix_Playing, [:int], :int
615
- boolean? :playing, TRUE_WHEN_ONE
619
+ boolean? :playing, OK_WHEN_ONE
616
620
 
617
621
  api :Mix_PlayingMusic, [], :int
618
- boolean? :playing_music, TRUE_WHEN_ONE
622
+ boolean? :playing_music, OK_WHEN_ONE
619
623
 
620
624
  ##
621
625
  # Stop music and set external music playback command
@@ -4,6 +4,7 @@ module SDL2
4
4
 
5
5
  module Mixer
6
6
 
7
+ ##
7
8
  # The internal format for an audio chunk
8
9
  #
9
10
  # * allocated - :int
@@ -20,14 +21,17 @@ module SDL2
20
21
  member_readers *members
21
22
  member_writers *members
22
23
 
24
+ ##
25
+ # Load a chunk from a wave file path (string)
23
26
  def self.load_wav(filepath)
24
27
  Mixer.load_wav!(filepath)
25
28
  end
26
29
 
30
+ ##
27
31
  # Plays chunk
28
- # @param opts[:channel]: defaults to -1
29
- # @param opts[:loop]: defaults to 0
30
- # @param opts[:ms]: defaults to -1
32
+ # opts[:channel]: defaults to -1
33
+ # opts[:loop]: defaults to 0
34
+ # opts[:ms]: defaults to -1
31
35
  def play(opts = {})
32
36
  channel = opts[:channel] || -1
33
37
  loop = opts[:loop] || 0
@@ -35,11 +39,18 @@ module SDL2
35
39
  Mixer::play_channel_timed(channel, self, loop, ms)
36
40
  end
37
41
 
42
+ ##
38
43
  # Check if anything is playing?
39
44
  def self.playing?
40
45
  Mixer::playing?(-1)
41
46
  end
42
47
 
48
+ ##
49
+ # Release this structure with Mixer::free_chunk
50
+ def self.release(pointer)
51
+ Mixer::free_chunk(pointer)
52
+ end
53
+
43
54
  end
44
55
 
45
56
  end