gosu 1.4.6 → 2.0.0.pre6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL_atomic.h +2 -3
  4. data/dependencies/SDL/include/SDL_audio.h +7 -7
  5. data/dependencies/SDL/include/SDL_blendmode.h +1 -1
  6. data/dependencies/SDL/include/SDL_endian.h +3 -3
  7. data/dependencies/SDL/include/SDL_gamecontroller.h +4 -4
  8. data/dependencies/SDL/include/SDL_hints.h +72 -28
  9. data/dependencies/SDL/include/SDL_joystick.h +8 -5
  10. data/dependencies/SDL/include/SDL_keycode.h +1 -1
  11. data/dependencies/SDL/include/SDL_main.h +7 -0
  12. data/dependencies/SDL/include/SDL_mouse.h +6 -7
  13. data/dependencies/SDL/include/SDL_mutex.h +79 -5
  14. data/dependencies/SDL/include/SDL_opengl_glext.h +5 -1
  15. data/dependencies/SDL/include/SDL_power.h +7 -8
  16. data/dependencies/SDL/include/SDL_render.h +5 -0
  17. data/dependencies/SDL/include/SDL_revision.h +2 -2
  18. data/dependencies/SDL/include/SDL_sensor.h +1 -1
  19. data/dependencies/SDL/include/SDL_stdinc.h +19 -11
  20. data/dependencies/SDL/include/SDL_thread.h +2 -2
  21. data/dependencies/SDL/include/SDL_version.h +2 -2
  22. data/dependencies/SDL/include/SDL_video.h +30 -2
  23. data/dependencies/SDL/include/begin_code.h +7 -7
  24. data/dependencies/SDL/include/close_code.h +2 -2
  25. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  26. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  27. data/dependencies/SDL_sound/SDL_sound.h +1 -1
  28. data/dependencies/SDL_sound/dr_flac.h +48 -23
  29. data/dependencies/SDL_sound/dr_mp3.h +34 -14
  30. data/dependencies/SDL_sound/stb_vorbis.h +3 -2
  31. data/dependencies/mojoAL/mojoal.c +1 -1
  32. data/ext/{gosu → gosu-ffi}/extconf.rb +34 -33
  33. data/ext/gosu-ffi/gosu-ffi.def +464 -0
  34. data/ffi/Gosu.cpp +307 -0
  35. data/ffi/Gosu.h +84 -0
  36. data/ffi/Gosu_Channel.cpp +62 -0
  37. data/ffi/Gosu_Channel.h +17 -0
  38. data/ffi/Gosu_Color.cpp +132 -0
  39. data/ffi/Gosu_Color.h +31 -0
  40. data/ffi/Gosu_Constants.cpp +334 -0
  41. data/ffi/Gosu_FFI.h +34 -0
  42. data/ffi/Gosu_FFI_internal.h +161 -0
  43. data/ffi/Gosu_Font.cpp +92 -0
  44. data/ffi/Gosu_Font.h +32 -0
  45. data/ffi/Gosu_Image.cpp +206 -0
  46. data/ffi/Gosu_Image.h +60 -0
  47. data/ffi/Gosu_Sample.cpp +29 -0
  48. data/ffi/Gosu_Sample.h +14 -0
  49. data/ffi/Gosu_Song.cpp +69 -0
  50. data/ffi/Gosu_Song.h +18 -0
  51. data/ffi/Gosu_TextInput.cpp +94 -0
  52. data/ffi/Gosu_TextInput.h +25 -0
  53. data/ffi/Gosu_Window.cpp +314 -0
  54. data/ffi/Gosu_Window.h +78 -0
  55. data/include/Gosu/Audio.hpp +6 -11
  56. data/include/Gosu/Bitmap.hpp +38 -53
  57. data/include/Gosu/Buffer.hpp +54 -0
  58. data/include/Gosu/Color.hpp +27 -35
  59. data/include/Gosu/Directories.hpp +25 -28
  60. data/include/Gosu/Drawable.hpp +58 -0
  61. data/include/Gosu/Font.hpp +6 -5
  62. data/include/Gosu/Fwd.hpp +4 -6
  63. data/include/Gosu/Gosu.hpp +5 -5
  64. data/include/Gosu/Graphics.hpp +51 -61
  65. data/include/Gosu/GraphicsBase.hpp +1 -11
  66. data/include/Gosu/Image.hpp +11 -14
  67. data/include/Gosu/Math.hpp +50 -72
  68. data/include/Gosu/Transform.hpp +32 -0
  69. data/include/Gosu/Utility.hpp +51 -1
  70. data/include/Gosu/Version.hpp +3 -3
  71. data/include/Gosu/Window.hpp +15 -9
  72. data/lib/SDL2.dll +0 -0
  73. data/lib/gosu/channel.rb +49 -0
  74. data/lib/gosu/color.rb +150 -0
  75. data/lib/gosu/compat.rb +29 -8
  76. data/lib/gosu/constants.rb +386 -0
  77. data/lib/gosu/ffi.rb +258 -0
  78. data/lib/gosu/font.rb +56 -0
  79. data/lib/gosu/gl_tex_info.rb +33 -0
  80. data/lib/gosu/gosu.rb +210 -0
  81. data/lib/gosu/image.rb +141 -0
  82. data/lib/gosu/numeric.rb +17 -0
  83. data/lib/gosu/preview.rb +6 -6
  84. data/lib/gosu/sample.rb +24 -0
  85. data/lib/gosu/song.rb +56 -0
  86. data/lib/gosu/text_input.rb +69 -0
  87. data/lib/gosu/window.rb +228 -0
  88. data/lib/gosu.rb +29 -8
  89. data/lib64/SDL2.dll +0 -0
  90. data/rdoc/gosu.rb +0 -2
  91. data/src/Audio.cpp +12 -12
  92. data/src/AudioFile.hpp +5 -4
  93. data/src/AudioFileAudioToolbox.cpp +8 -8
  94. data/src/AudioFileSDLSound.cpp +7 -10
  95. data/src/BinPacker.cpp +187 -0
  96. data/src/BinPacker.hpp +55 -0
  97. data/src/Bitmap.cpp +166 -144
  98. data/src/BitmapIO.cpp +60 -86
  99. data/src/Buffer.cpp +159 -0
  100. data/src/Color.cpp +75 -80
  101. data/src/Directories.cpp +47 -0
  102. data/src/DirectoriesUIKit.cpp +50 -0
  103. data/src/DrawOp.hpp +9 -4
  104. data/src/DrawOpQueue.hpp +2 -2
  105. data/src/Drawable.cpp +95 -0
  106. data/src/EmptyDrawable.hpp +38 -0
  107. data/src/FPS.cpp +31 -0
  108. data/src/Font.cpp +104 -74
  109. data/src/GosuGLView.cpp +14 -6
  110. data/src/GosuViewController.cpp +2 -10
  111. data/src/Graphics.cpp +60 -126
  112. data/src/GraphicsImpl.hpp +17 -47
  113. data/src/Image.cpp +41 -35
  114. data/src/Input.cpp +7 -8
  115. data/src/Macro.cpp +6 -6
  116. data/src/Macro.hpp +4 -4
  117. data/src/MarkupParser.cpp +5 -5
  118. data/src/Math.cpp +35 -22
  119. data/src/OffScreenTarget.cpp +53 -49
  120. data/src/OffScreenTarget.hpp +13 -11
  121. data/src/OpenGLContext.cpp +117 -0
  122. data/src/OpenGLContext.hpp +41 -0
  123. data/src/RenderState.hpp +21 -19
  124. data/src/Resolution.cpp +23 -21
  125. data/src/TexChunk.cpp +35 -80
  126. data/src/TexChunk.hpp +44 -35
  127. data/src/Text.cpp +1 -1
  128. data/src/TextBuilder.cpp +35 -21
  129. data/src/TextBuilder.hpp +6 -9
  130. data/src/Texture.cpp +62 -80
  131. data/src/Texture.hpp +25 -23
  132. data/src/TiledDrawable.cpp +150 -0
  133. data/src/TiledDrawable.hpp +47 -0
  134. data/src/TimingApple.cpp +1 -1
  135. data/src/Transform.cpp +45 -50
  136. data/src/TransformStack.hpp +16 -16
  137. data/src/TrueTypeFont.cpp +59 -51
  138. data/src/TrueTypeFont.hpp +6 -7
  139. data/src/TrueTypeFontApple.cpp +28 -19
  140. data/src/TrueTypeFontUnix.cpp +27 -23
  141. data/src/TrueTypeFontWin.cpp +30 -30
  142. data/src/Utility.cpp +84 -21
  143. data/src/UtilityWin.cpp +45 -0
  144. data/src/Window.cpp +92 -142
  145. data/src/WindowUIKit.cpp +14 -14
  146. metadata +72 -31
  147. data/include/Gosu/IO.hpp +0 -254
  148. data/include/Gosu/ImageData.hpp +0 -53
  149. data/include/Gosu/Inspection.hpp +0 -7
  150. data/lib/gosu/patches.rb +0 -66
  151. data/lib/gosu/run.rb +0 -20
  152. data/lib/gosu/swig_patches.rb +0 -110
  153. data/src/BlockAllocator.cpp +0 -131
  154. data/src/BlockAllocator.hpp +0 -32
  155. data/src/DirectoriesApple.cpp +0 -69
  156. data/src/DirectoriesUnix.cpp +0 -46
  157. data/src/DirectoriesWin.cpp +0 -65
  158. data/src/EmptyImageData.hpp +0 -52
  159. data/src/FileUnix.cpp +0 -99
  160. data/src/FileWin.cpp +0 -88
  161. data/src/IO.cpp +0 -60
  162. data/src/Iconv.hpp +0 -51
  163. data/src/Inspection.cpp +0 -27
  164. data/src/LargeImageData.cpp +0 -215
  165. data/src/LargeImageData.hpp +0 -39
  166. data/src/Log.hpp +0 -19
  167. data/src/RubyGosu.cxx +0 -13100
  168. data/src/RubyGosu.h +0 -49
  169. data/src/WinUtility.cpp +0 -61
  170. data/src/WinUtility.hpp +0 -27
@@ -0,0 +1,206 @@
1
+ #include "Gosu_FFI_internal.h"
2
+ #include <cstring> // for std::memcpy
3
+
4
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create(const char* filename, unsigned image_flags)
5
+ {
6
+ return Gosu_translate_exceptions([=] {
7
+ return new Gosu_Image{Gosu::Image{filename, image_flags}};
8
+ });
9
+ }
10
+
11
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_markup(const char* markup, const char* font,
12
+ double font_height, int width,
13
+ double spacing, unsigned align,
14
+ unsigned font_flags, unsigned image_flags)
15
+ {
16
+ return Gosu_translate_exceptions([=] {
17
+ Gosu::Bitmap bitmap = Gosu::layout_markup(markup, font, font_height, spacing, width,
18
+ static_cast<Gosu::Alignment>(align), font_flags);
19
+ return new Gosu_Image{Gosu::Image{bitmap, image_flags}};
20
+ });
21
+ }
22
+
23
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_text(const char* text, const char* font,
24
+ double font_height, int width, double spacing,
25
+ unsigned align, unsigned font_flags,
26
+ unsigned image_flags)
27
+ {
28
+ return Gosu_translate_exceptions([=] {
29
+ Gosu::Bitmap bitmap = Gosu::layout_text(text, font, font_height, spacing, width,
30
+ static_cast<Gosu::Alignment>(align), font_flags);
31
+ return new Gosu_Image{Gosu::Image{bitmap, image_flags}};
32
+ });
33
+ }
34
+
35
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_blob(void* blob, int byte_count, int columns,
36
+ int rows, unsigned image_flags)
37
+ {
38
+ return Gosu_translate_exceptions([=] {
39
+ std::size_t size = columns * rows * 4;
40
+ Gosu::Bitmap bitmap{columns, rows};
41
+
42
+ if (byte_count == size) {
43
+ // 32 bit per pixel, assume R8G8B8A8
44
+ std::memcpy(bitmap.data(), blob, size);
45
+ }
46
+ else if (byte_count == size * sizeof(float)) {
47
+ // 128 bit per channel, assume float/float/float/float - for Texplay compatibility.
48
+ const float* in = static_cast<const float*>(blob);
49
+ Gosu::Color::Channel* out = reinterpret_cast<Gosu::Color::Channel*>(bitmap.data());
50
+ for (std::size_t i = 0; i < size; ++i) {
51
+ out[i] = static_cast<Gosu::Color::Channel>(in[i] * 255);
52
+ }
53
+ }
54
+ else {
55
+ throw std::invalid_argument{"Invalid byte_count " + std::to_string(byte_count) +
56
+ "for image of size " + std::to_string(columns) + "x" +
57
+ std::to_string(rows)};
58
+ }
59
+
60
+ return new Gosu_Image{Gosu::Image{bitmap, image_flags}};
61
+ });
62
+ }
63
+
64
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_subimage(Gosu_Image* image, int left, int top,
65
+ int width, int height)
66
+ {
67
+ return Gosu_translate_exceptions([=]() -> Gosu_Image* {
68
+ std::unique_ptr<Gosu::Drawable> drawable
69
+ = image->image.drawable().subimage(Gosu::Rect { left, top, width, height });
70
+
71
+ if (! drawable) return nullptr;
72
+
73
+ return new Gosu_Image{Gosu::Image{std::move(drawable)}};
74
+ });
75
+ }
76
+
77
+ GOSU_FFI_API void Gosu_Image_create_from_tiles(const char* source, int tile_width, int tile_height,
78
+ void function(void*, Gosu_Image*), void* data,
79
+ unsigned image_flags)
80
+ {
81
+ Gosu_translate_exceptions([=] {
82
+ std::vector<Gosu::Image> gosu_images =
83
+ Gosu::load_tiles(source, tile_width, tile_height, image_flags);
84
+
85
+ for (Gosu::Image& img : gosu_images) {
86
+ function(data, new Gosu_Image{img});
87
+ }
88
+ });
89
+ }
90
+
91
+ GOSU_FFI_API void Gosu_Image_create_tiles_from_image(Gosu_Image* image, int tile_width,
92
+ int tile_height,
93
+ void function(void*, Gosu_Image*), void* data,
94
+ unsigned image_flags)
95
+ {
96
+ Gosu_translate_exceptions([=] {
97
+ std::vector<Gosu::Image> gosu_images = Gosu::load_tiles(
98
+ image->image.drawable().to_bitmap(), tile_width, tile_height, image_flags);
99
+
100
+ for (Gosu::Image& img : gosu_images) {
101
+ function(data, new Gosu_Image{img});
102
+ }
103
+ });
104
+ }
105
+
106
+ GOSU_FFI_API void Gosu_Image_destroy(Gosu_Image* image)
107
+ {
108
+ delete image;
109
+ }
110
+
111
+ // Properties
112
+
113
+ GOSU_FFI_API unsigned Gosu_Image_width(Gosu_Image* image)
114
+ {
115
+ return Gosu_translate_exceptions([=] {
116
+ return image->image.width();
117
+ });
118
+ }
119
+
120
+ GOSU_FFI_API unsigned Gosu_Image_height(Gosu_Image* image)
121
+ {
122
+ return Gosu_translate_exceptions([=] {
123
+ return image->image.height();
124
+ });
125
+ }
126
+
127
+ GOSU_FFI_API Gosu_GLTexInfo* Gosu_Image_gl_tex_info_create(Gosu_Image* image)
128
+ {
129
+ return Gosu_translate_exceptions([=]() -> Gosu_GLTexInfo* {
130
+ const Gosu::GLTexInfo* info = image->image.drawable().gl_tex_info();
131
+ if (!info) {
132
+ return nullptr;
133
+ }
134
+ return new Gosu_GLTexInfo {
135
+ .tex_name = info->tex_name,
136
+ .left = info->left,
137
+ .right = info->right,
138
+ .top = info->top,
139
+ .bottom = info->bottom,
140
+ };
141
+ });
142
+ }
143
+
144
+ GOSU_FFI_API void Gosu_Image_gl_tex_info_destroy(Gosu_GLTexInfo* gl_tex_info)
145
+ {
146
+ Gosu_translate_exceptions([=] {
147
+ delete reinterpret_cast<Gosu::GLTexInfo*>(gl_tex_info);
148
+ });
149
+ }
150
+
151
+ // Rendering
152
+
153
+ GOSU_FFI_API void Gosu_Image_draw(Gosu_Image* image, double x, double y, double z, double scale_x,
154
+ double scale_y, unsigned color, unsigned mode)
155
+ {
156
+ Gosu_translate_exceptions([=] {
157
+ image->image.draw(x, y, z, scale_x, scale_y, color, static_cast<Gosu::BlendMode>(mode));
158
+ });
159
+ }
160
+
161
+ GOSU_FFI_API void Gosu_Image_draw_rot(Gosu_Image* image, double x, double y, double z, double angle,
162
+ double center_x, double center_y, double scale_x,
163
+ double scale_y, unsigned color, unsigned mode)
164
+ {
165
+ Gosu_translate_exceptions([=] {
166
+ image->image.draw_rot(x, y, z, angle, center_x, center_y, scale_x, scale_y, color,
167
+ static_cast<Gosu::BlendMode>(mode));
168
+ });
169
+ }
170
+
171
+ GOSU_FFI_API void Gosu_Image_draw_as_quad(Gosu_Image* image, double x1, double y1, unsigned color1,
172
+ double x2, double y2, unsigned color2, double x3,
173
+ double y3, unsigned color3, double x4, double y4,
174
+ unsigned color4, double z, unsigned mode)
175
+ {
176
+ Gosu_translate_exceptions([=] {
177
+ image->image.drawable().draw(x1, y1, color1, x2, y2, color2, x3, y3, color3, x4, y4, color4, z,
178
+ static_cast<Gosu::BlendMode>(mode));
179
+ });
180
+ }
181
+
182
+ // Image operations
183
+
184
+ GOSU_FFI_API void Gosu_Image_insert(Gosu_Image* image, Gosu_Image* source, int x, int y)
185
+ {
186
+ Gosu_translate_exceptions([=] {
187
+ Gosu::Bitmap bitmap = source->image.drawable().to_bitmap();
188
+ image->image.drawable().insert(bitmap, x, y);
189
+ });
190
+ }
191
+
192
+ GOSU_FFI_API uint8_t* Gosu_Image_to_blob(Gosu_Image* image)
193
+ {
194
+ static thread_local Gosu::Bitmap bitmap;
195
+ return Gosu_translate_exceptions([=] {
196
+ bitmap = image->image.drawable().to_bitmap();
197
+ return reinterpret_cast<uint8_t*>(bitmap.data());
198
+ });
199
+ }
200
+
201
+ GOSU_FFI_API void Gosu_Image_save(Gosu_Image* image, const char* filename)
202
+ {
203
+ Gosu_translate_exceptions([=] {
204
+ Gosu::save_image_file(image->image.drawable().to_bitmap(), filename);
205
+ });
206
+ }
data/ffi/Gosu_Image.h ADDED
@@ -0,0 +1,60 @@
1
+ #pragma once
2
+
3
+ #include "Gosu_FFI.h"
4
+ #include <stdint.h>
5
+
6
+ typedef struct Gosu_Image Gosu_Image;
7
+
8
+ typedef struct Gosu_GLTexInfo
9
+ {
10
+ uint32_t tex_name;
11
+ double left, right, top, bottom;
12
+ } Gosu_GLTexInfo;
13
+
14
+ // Constructor
15
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create(const char* filename, unsigned image_flags);
16
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_blob(void* blob, int byte_count, int width,
17
+ int height, unsigned image_flags);
18
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_markup(const char* markup, const char* font,
19
+ double font_height, int width,
20
+ double spacing, unsigned align,
21
+ unsigned font_flags, unsigned image_flags);
22
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_text(const char* text, const char* font,
23
+ double font_height, int width, double spacing,
24
+ unsigned align, unsigned font_flags,
25
+ unsigned image_flags);
26
+ GOSU_FFI_API Gosu_Image* Gosu_Image_create_from_subimage(Gosu_Image* source, int left, int top,
27
+ int width, int height);
28
+
29
+ GOSU_FFI_API void Gosu_Image_create_from_tiles(const char* source, int tile_width, int tile_height,
30
+ void function(void* data, Gosu_Image* image),
31
+ void* data, unsigned image_flags);
32
+ GOSU_FFI_API void Gosu_Image_create_tiles_from_image(Gosu_Image* image, int tile_width,
33
+ int tile_height,
34
+ void function(void* data, Gosu_Image* image),
35
+ void* data, unsigned image_flags);
36
+
37
+ // Destructor
38
+ GOSU_FFI_API void Gosu_Image_destroy(Gosu_Image* image);
39
+
40
+ // Image properties
41
+ GOSU_FFI_API unsigned Gosu_Image_width(Gosu_Image* image);
42
+ GOSU_FFI_API unsigned Gosu_Image_height(Gosu_Image* image);
43
+
44
+ // Rendering
45
+ GOSU_FFI_API void Gosu_Image_draw(Gosu_Image* image, double x, double y, double z, double scale_x,
46
+ double scale_y, unsigned color, unsigned mode);
47
+ GOSU_FFI_API void Gosu_Image_draw_rot(Gosu_Image* image, double x, double y, double z, double angle,
48
+ double center_x, double center_y, double scale_x,
49
+ double scale_y, unsigned color, unsigned mode);
50
+ GOSU_FFI_API void Gosu_Image_draw_as_quad(Gosu_Image* image, double x1, double y1, unsigned color1,
51
+ double x2, double y2, unsigned color2, double x3,
52
+ double y3, unsigned color3, double x4, double y4,
53
+ unsigned color4, double z, unsigned mode);
54
+
55
+ // Operations
56
+ GOSU_FFI_API void Gosu_Image_insert(Gosu_Image* image, Gosu_Image* source, int x, int y);
57
+ GOSU_FFI_API void Gosu_Image_save(Gosu_Image* image, const char* filename);
58
+ GOSU_FFI_API uint8_t* Gosu_Image_to_blob(Gosu_Image* image);
59
+ GOSU_FFI_API Gosu_GLTexInfo* Gosu_Image_gl_tex_info_create(Gosu_Image* image);
60
+ GOSU_FFI_API void Gosu_Image_gl_tex_info_destroy(Gosu_GLTexInfo* tex_info);
@@ -0,0 +1,29 @@
1
+ #include "Gosu_FFI_internal.h"
2
+
3
+ GOSU_FFI_API Gosu_Sample* Gosu_Sample_create(const char* filename)
4
+ {
5
+ return Gosu_translate_exceptions([=] {
6
+ return new Gosu_Sample{Gosu::Sample{filename}};
7
+ });
8
+ }
9
+
10
+ GOSU_FFI_API void Gosu_Sample_destroy(Gosu_Sample* sample)
11
+ {
12
+ delete sample;
13
+ }
14
+
15
+ GOSU_FFI_API Gosu_Channel* Gosu_Sample_play(Gosu_Sample* sample, double volume, double speed,
16
+ bool looping)
17
+ {
18
+ return Gosu_translate_exceptions([=] {
19
+ return new Gosu_Channel{sample->sample.play(volume, speed, looping)};
20
+ });
21
+ }
22
+
23
+ GOSU_FFI_API Gosu_Channel* Gosu_Sample_play_pan(Gosu_Sample* sample, double pan, double volume,
24
+ double speed, bool looping)
25
+ {
26
+ return Gosu_translate_exceptions([=] {
27
+ return new Gosu_Channel{sample->sample.play_pan(pan, volume, speed, looping)};
28
+ });
29
+ }
data/ffi/Gosu_Sample.h ADDED
@@ -0,0 +1,14 @@
1
+ #pragma once
2
+
3
+ #include "Gosu_Channel.h"
4
+ #include "Gosu_FFI.h"
5
+
6
+ typedef struct Gosu_Sample Gosu_Sample;
7
+
8
+ GOSU_FFI_API Gosu_Sample* Gosu_Sample_create(const char* filename);
9
+ GOSU_FFI_API void Gosu_Sample_destroy(Gosu_Sample* sample);
10
+
11
+ GOSU_FFI_API Gosu_Channel* Gosu_Sample_play(Gosu_Sample* sample, double volume, double speed,
12
+ bool looping);
13
+ GOSU_FFI_API Gosu_Channel* Gosu_Sample_play_pan(Gosu_Sample* sample, double pan, double volume,
14
+ double speed, bool looping);
data/ffi/Gosu_Song.cpp ADDED
@@ -0,0 +1,69 @@
1
+ #include "Gosu_FFI_internal.h"
2
+
3
+ GOSU_FFI_API Gosu_Song* Gosu_Song_create(const char* filename)
4
+ {
5
+ return Gosu_translate_exceptions([=] {
6
+ return new Gosu_Song{filename};
7
+ });
8
+ }
9
+
10
+ GOSU_FFI_API void Gosu_Song_destroy(Gosu_Song* song)
11
+ {
12
+ delete song;
13
+ }
14
+
15
+ GOSU_FFI_API void Gosu_Song_play(Gosu_Song* song, bool looping)
16
+ {
17
+ Gosu_translate_exceptions([=] {
18
+ song->play(looping);
19
+ });
20
+ }
21
+
22
+ GOSU_FFI_API bool Gosu_Song_playing(Gosu_Song* song)
23
+ {
24
+ return Gosu_translate_exceptions([=] {
25
+ return song->playing();
26
+ });
27
+ }
28
+
29
+ GOSU_FFI_API void Gosu_Song_pause(Gosu_Song* song)
30
+ {
31
+ Gosu_translate_exceptions([=] {
32
+ song->pause();
33
+ });
34
+ }
35
+
36
+ GOSU_FFI_API bool Gosu_Song_paused(Gosu_Song* song)
37
+ {
38
+ return Gosu_translate_exceptions([=] {
39
+ return song->paused();
40
+ });
41
+ }
42
+
43
+ GOSU_FFI_API void Gosu_Song_stop(Gosu_Song* song)
44
+ {
45
+ Gosu_translate_exceptions([=] {
46
+ song->stop();
47
+ });
48
+ }
49
+
50
+ GOSU_FFI_API double Gosu_Song_volume(Gosu_Song* song)
51
+ {
52
+ return Gosu_translate_exceptions([=] {
53
+ return song->volume();
54
+ });
55
+ }
56
+
57
+ GOSU_FFI_API void Gosu_Song_set_volume(Gosu_Song* song, double volume)
58
+ {
59
+ Gosu_translate_exceptions([=] {
60
+ return song->set_volume(volume);
61
+ });
62
+ }
63
+
64
+ GOSU_FFI_API Gosu_Song* Gosu_Song_current_song(void)
65
+ {
66
+ return Gosu_translate_exceptions([=] {
67
+ return reinterpret_cast<Gosu_Song*>(Gosu::Song::current_song());
68
+ });
69
+ }
data/ffi/Gosu_Song.h ADDED
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "Gosu_FFI.h"
4
+
5
+ typedef struct Gosu_Song Gosu_Song;
6
+
7
+ GOSU_FFI_API Gosu_Song* Gosu_Song_create(const char* filename);
8
+ GOSU_FFI_API void Gosu_Song_destroy(Gosu_Song* song);
9
+
10
+ GOSU_FFI_API void Gosu_Song_pause(Gosu_Song* song);
11
+ GOSU_FFI_API bool Gosu_Song_paused(Gosu_Song* song);
12
+ GOSU_FFI_API void Gosu_Song_play(Gosu_Song* song, bool looping);
13
+ GOSU_FFI_API bool Gosu_Song_playing(Gosu_Song* song);
14
+ GOSU_FFI_API void Gosu_Song_stop(Gosu_Song* song);
15
+ GOSU_FFI_API double Gosu_Song_volume(Gosu_Song* song);
16
+ GOSU_FFI_API void Gosu_Song_set_volume(Gosu_Song* song, double volume);
17
+
18
+ GOSU_FFI_API Gosu_Song* Gosu_Song_current_song(void);
@@ -0,0 +1,94 @@
1
+ #include "Gosu_FFI_internal.h"
2
+
3
+ GOSU_FFI_API Gosu_TextInput* Gosu_TextInput_create()
4
+ {
5
+ return Gosu_translate_exceptions([=] {
6
+ return new Gosu_TextInput{};
7
+ });
8
+ }
9
+
10
+ GOSU_FFI_API void Gosu_TextInput_destroy(Gosu_TextInput* text_input)
11
+ {
12
+ delete text_input;
13
+ }
14
+
15
+ GOSU_FFI_API const char* Gosu_TextInput_text(Gosu_TextInput* text_input)
16
+ {
17
+ static thread_local std::string text;
18
+
19
+ return Gosu_translate_exceptions([=] {
20
+ text = text_input->text();
21
+ return text.c_str();
22
+ });
23
+ }
24
+
25
+ GOSU_FFI_API void Gosu_TextInput_set_text(Gosu_TextInput* text_input, const char* text)
26
+ {
27
+ Gosu_translate_exceptions([=] {
28
+ text_input->set_text(text);
29
+ });
30
+ }
31
+
32
+ GOSU_FFI_API int Gosu_TextInput_caret_pos(Gosu_TextInput* text_input)
33
+ {
34
+ return Gosu_translate_exceptions([=] {
35
+ return text_input->caret_pos();
36
+ });
37
+ }
38
+
39
+ GOSU_FFI_API void Gosu_TextInput_set_caret_pos(Gosu_TextInput* text_input, int pos)
40
+ {
41
+ Gosu_translate_exceptions([=] {
42
+ text_input->set_caret_pos(pos);
43
+ });
44
+ }
45
+
46
+ GOSU_FFI_API int Gosu_TextInput_selection_start(Gosu_TextInput* text_input)
47
+ {
48
+ return Gosu_translate_exceptions([=] {
49
+ return text_input->selection_start();
50
+ });
51
+ }
52
+
53
+ GOSU_FFI_API void Gosu_TextInput_set_selection_start(Gosu_TextInput* text_input, int pos)
54
+ {
55
+ Gosu_translate_exceptions([=] {
56
+ text_input->set_selection_start(pos);
57
+ });
58
+ }
59
+
60
+ GOSU_FFI_API void Gosu_TextInput_set_filter(Gosu_TextInput* text_input,
61
+ void function(void*, const char*), void* data)
62
+ {
63
+ Gosu_translate_exceptions([=] {
64
+ text_input->filter_callback = [=](const char* text) { function(data, text); };
65
+ });
66
+ }
67
+
68
+ GOSU_FFI_API void Gosu_TextInput_set_filter_result(Gosu_TextInput* text_input, const char* result)
69
+ {
70
+ Gosu_translate_exceptions([=] {
71
+ text_input->filter_result = result;
72
+ });
73
+ }
74
+
75
+ GOSU_FFI_API void Gosu_TextInput_insert_text(Gosu_TextInput* text_input, const char* text)
76
+ {
77
+ Gosu_translate_exceptions([=] {
78
+ text_input->insert_text(text);
79
+ });
80
+ }
81
+
82
+ GOSU_FFI_API void Gosu_TextInput_delete_backward(Gosu_TextInput* text_input)
83
+ {
84
+ Gosu_translate_exceptions([=] {
85
+ text_input->delete_backward();
86
+ });
87
+ }
88
+
89
+ GOSU_FFI_API void Gosu_TextInput_delete_forward(Gosu_TextInput* text_input)
90
+ {
91
+ Gosu_translate_exceptions([=] {
92
+ text_input->delete_forward();
93
+ });
94
+ }
@@ -0,0 +1,25 @@
1
+ #pragma once
2
+
3
+ #include "Gosu_FFI.h"
4
+
5
+ typedef struct Gosu_TextInput Gosu_TextInput;
6
+
7
+ GOSU_FFI_API Gosu_TextInput* Gosu_TextInput_create(void);
8
+ GOSU_FFI_API void Gosu_TextInput_destroy(Gosu_TextInput* text_input);
9
+
10
+ GOSU_FFI_API const char* Gosu_TextInput_text(Gosu_TextInput* text_input);
11
+ GOSU_FFI_API void Gosu_TextInput_set_text(Gosu_TextInput* text_input, const char* text);
12
+
13
+ GOSU_FFI_API int Gosu_TextInput_caret_pos(Gosu_TextInput* text_input);
14
+ GOSU_FFI_API void Gosu_TextInput_set_caret_pos(Gosu_TextInput* text_input, int pos);
15
+
16
+ GOSU_FFI_API int Gosu_TextInput_selection_start(Gosu_TextInput* text_input);
17
+ GOSU_FFI_API void Gosu_TextInput_set_selection_start(Gosu_TextInput* text_input, int pos);
18
+
19
+ GOSU_FFI_API void Gosu_TextInput_set_filter(Gosu_TextInput* text_input,
20
+ void function(void* data, const char* text),
21
+ void* data);
22
+ GOSU_FFI_API void Gosu_TextInput_set_filter_result(Gosu_TextInput* text_input, const char* result);
23
+ GOSU_FFI_API void Gosu_TextInput_insert_text(Gosu_TextInput* text_input, const char* text);
24
+ GOSU_FFI_API void Gosu_TextInput_delete_backward(Gosu_TextInput* text_input);
25
+ GOSU_FFI_API void Gosu_TextInput_delete_forward(Gosu_TextInput* text_input);