gosu 0.15.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/COPYING +1 -1
  4. data/dependencies/SDL/include/SDL.h +138 -0
  5. data/dependencies/SDL/include/SDL_assert.h +293 -0
  6. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  7. data/dependencies/SDL/include/SDL_audio.h +859 -0
  8. data/dependencies/SDL/include/SDL_bits.h +121 -0
  9. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  10. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  11. data/dependencies/SDL/include/SDL_config.h +55 -0
  12. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  13. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  14. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  15. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  16. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  17. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  18. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  19. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  20. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  21. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  22. data/dependencies/SDL/include/SDL_copying.h +20 -0
  23. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  24. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  25. data/dependencies/SDL/include/SDL_endian.h +263 -0
  26. data/dependencies/SDL/include/SDL_error.h +112 -0
  27. data/dependencies/SDL/include/SDL_events.h +827 -0
  28. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  29. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  30. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  31. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  32. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  33. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  34. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  35. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  36. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  37. data/dependencies/SDL/include/SDL_locale.h +101 -0
  38. data/dependencies/SDL/include/SDL_log.h +211 -0
  39. data/dependencies/SDL/include/SDL_main.h +180 -0
  40. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  41. data/dependencies/SDL/include/SDL_metal.h +117 -0
  42. data/dependencies/SDL/include/SDL_misc.h +75 -0
  43. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  44. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  45. data/dependencies/SDL/include/SDL_name.h +33 -0
  46. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  47. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  48. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  49. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  51. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  52. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  53. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  54. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  55. data/dependencies/SDL/include/SDL_platform.h +198 -0
  56. data/dependencies/SDL/include/SDL_power.h +75 -0
  57. data/dependencies/SDL/include/SDL_quit.h +58 -0
  58. data/dependencies/SDL/include/SDL_rect.h +174 -0
  59. data/dependencies/SDL/include/SDL_render.h +1158 -0
  60. data/dependencies/SDL/include/SDL_revision.h +2 -0
  61. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  62. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  63. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  64. data/dependencies/SDL/include/SDL_shape.h +144 -0
  65. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  66. data/dependencies/SDL/include/SDL_surface.h +563 -0
  67. data/dependencies/SDL/include/SDL_system.h +325 -0
  68. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  69. data/dependencies/SDL/include/SDL_test.h +69 -0
  70. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  71. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  72. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  73. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  74. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  75. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  76. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  77. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  78. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  79. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  80. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  81. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  82. data/dependencies/SDL/include/SDL_thread.h +366 -0
  83. data/dependencies/SDL/include/SDL_timer.h +115 -0
  84. data/dependencies/SDL/include/SDL_touch.h +102 -0
  85. data/dependencies/SDL/include/SDL_types.h +29 -0
  86. data/dependencies/SDL/include/SDL_version.h +162 -0
  87. data/dependencies/SDL/include/SDL_video.h +1282 -0
  88. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  89. data/dependencies/SDL/include/begin_code.h +166 -0
  90. data/dependencies/SDL/include/close_code.h +40 -0
  91. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  92. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  93. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  94. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  95. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  96. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  97. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  98. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  99. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  100. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  101. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  102. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  103. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  104. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  105. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  106. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  107. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  108. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  109. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  110. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  111. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  112. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  113. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  114. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  116. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  117. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  118. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  119. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  121. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  124. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  125. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  126. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  127. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  128. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  129. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  130. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  131. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  132. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  133. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  134. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  135. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  136. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  137. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  138. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  140. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  141. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  142. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  143. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  144. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  145. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +128 -23
  146. data/dependencies/al_soft/AL/al.h +655 -0
  147. data/dependencies/al_soft/AL/alc.h +270 -0
  148. data/dependencies/al_soft/AL/alext.h +585 -0
  149. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  150. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  151. data/dependencies/al_soft/AL/efx.h +762 -0
  152. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  153. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  154. data/{src → dependencies/stb}/stb_image.h +476 -176
  155. data/{src → dependencies/stb}/stb_image_write.h +253 -131
  156. data/{src → dependencies/stb}/stb_truetype.h +262 -104
  157. data/{src → dependencies/utf8proc}/utf8proc.c +47 -29
  158. data/{src → dependencies/utf8proc}/utf8proc.h +46 -24
  159. data/{src → dependencies/utf8proc}/utf8proc_data.h +10043 -9609
  160. data/ext/gosu/extconf.rb +53 -39
  161. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  162. data/include/Gosu/Bitmap.hpp +100 -0
  163. data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
  164. data/include/Gosu/Channel.h +25 -0
  165. data/include/Gosu/Color.h +38 -0
  166. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  167. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  168. data/include/Gosu/Font.h +36 -0
  169. data/{Gosu → include/Gosu}/Font.hpp +1 -1
  170. data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
  171. data/include/Gosu/Gosu.h +82 -0
  172. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  173. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  174. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  175. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  176. data/include/Gosu/Image.h +54 -0
  177. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  178. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  179. data/{Gosu → include/Gosu}/Input.hpp +39 -51
  180. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  182. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  183. data/include/Gosu/Sample.h +19 -0
  184. data/include/Gosu/Song.h +24 -0
  185. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  186. data/include/Gosu/TextInput.h +30 -0
  187. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  188. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  189. data/{Gosu → include/Gosu}/Utility.hpp +15 -4
  190. data/{Gosu → include/Gosu}/Version.hpp +2 -2
  191. data/include/Gosu/Window.h +63 -0
  192. data/{Gosu → include/Gosu}/Window.hpp +23 -25
  193. data/lib/OpenAL32.dll +0 -0
  194. data/lib/SDL2.dll +0 -0
  195. data/lib/gosu.rb +0 -3
  196. data/lib/gosu/patches.rb +0 -23
  197. data/lib/gosu/preview.rb +1 -3
  198. data/lib/gosu/swig_patches.rb +3 -2
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/rdoc/gosu.rb +98 -22
  202. data/src/Audio.cpp +50 -224
  203. data/src/AudioFile.hpp +20 -37
  204. data/src/AudioFileAudioToolbox.cpp +237 -0
  205. data/src/AudioFileSDLSound.cpp +147 -0
  206. data/src/AudioImpl.cpp +3 -12
  207. data/src/AudioImpl.hpp +3 -1
  208. data/src/Bitmap.cpp +85 -83
  209. data/src/BitmapIO.cpp +52 -58
  210. data/src/ChannelWrapper.cpp +50 -0
  211. data/src/ColorWrapper.cpp +126 -0
  212. data/src/Constants.cpp +338 -0
  213. data/src/Font.cpp +4 -1
  214. data/src/FontWrapper.cpp +74 -0
  215. data/src/GosuWrapper.cpp +251 -0
  216. data/src/Graphics.cpp +7 -4
  217. data/src/Image.cpp +13 -16
  218. data/src/ImageWrapper.cpp +168 -0
  219. data/src/Input.cpp +412 -164
  220. data/src/LargeImageData.cpp +2 -1
  221. data/src/MarkupParser.cpp +2 -1
  222. data/src/RubyGosu.cxx +912 -172
  223. data/src/RubyGosu.h +4 -2
  224. data/src/SampleWrapper.cpp +30 -0
  225. data/src/SongWrapper.cpp +52 -0
  226. data/src/TexChunk.cpp +1 -1
  227. data/src/Text.cpp +1 -0
  228. data/src/TextBuilder.cpp +3 -1
  229. data/src/TextInputWrapper.cpp +101 -0
  230. data/src/Texture.cpp +1 -1
  231. data/src/TrueTypeFont.cpp +2 -1
  232. data/src/Utility.cpp +11 -7
  233. data/src/Window.cpp +30 -39
  234. data/src/WindowWrapper.cpp +317 -0
  235. metadata +212 -43
  236. data/Gosu/AutoLink.hpp +0 -14
  237. data/Gosu/Bitmap.hpp +0 -113
  238. data/lib/gosu/zen.rb +0 -89
  239. data/src/AudioToolboxFile.hpp +0 -210
  240. data/src/OggFile.hpp +0 -92
  241. data/src/SndFile.hpp +0 -174
  242. data/src/WinMain.cpp +0 -64
@@ -1,6 +1,6 @@
1
1
  /* ----------------------------------------------------------------------------
2
2
  * This file was automatically generated by SWIG (http://www.swig.org).
3
- * Version 4.0.1
3
+ * Version 4.1.0
4
4
  *
5
5
  * This file is not intended to be easily readable and contains a number of
6
6
  * coding conventions designed to improve portability and efficiency. Do not make
@@ -28,7 +28,7 @@ public:
28
28
  class SwigDirector_Window : public Gosu::Window, public Swig::Director {
29
29
 
30
30
  public:
31
- SwigDirector_Window(VALUE self, unsigned int width, unsigned int height, bool fullscreen = false, double update_interval = 16.666666, bool resizable = false);
31
+ SwigDirector_Window(VALUE self,unsigned int width,unsigned int height,bool fullscreen=false,double update_interval=16.666666,bool resizable=false);
32
32
  virtual ~SwigDirector_Window();
33
33
  virtual void show();
34
34
  virtual bool tick();
@@ -41,6 +41,8 @@ public:
41
41
  virtual void release_memory();
42
42
  virtual void button_down(Gosu::Button arg0);
43
43
  virtual void button_up(Gosu::Button arg0);
44
+ virtual void gamepad_connected(int index);
45
+ virtual void gamepad_disconnected(int index);
44
46
  virtual void drop(std::string const &filename);
45
47
  };
46
48
 
@@ -0,0 +1,30 @@
1
+ #include <Gosu/Audio.hpp>
2
+ #include <Gosu/Sample.h>
3
+
4
+ extern "C" {
5
+
6
+ Gosu_Sample *Gosu_Sample_create(const char *filename)
7
+ {
8
+ return reinterpret_cast<Gosu_Sample *>( new Gosu::Sample(filename) );
9
+ }
10
+
11
+ void Gosu_Sample_destroy(Gosu_Sample *sample)
12
+ {
13
+ delete( reinterpret_cast<Gosu::Sample *>( sample ) );
14
+ }
15
+
16
+ Gosu_Channel *Gosu_Sample_play(Gosu_Sample *sample, double volume, double speed, bool looping)
17
+ {
18
+ Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play(volume, speed, looping);
19
+
20
+ return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
21
+ }
22
+
23
+ Gosu_Channel *Gosu_Sample_play_pan(Gosu_Sample *sample, double pan, double volume, double speed, bool looping)
24
+ {
25
+ Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play_pan(pan, volume, speed, looping);
26
+
27
+ return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
28
+ }
29
+
30
+ }
@@ -0,0 +1,52 @@
1
+ #include <Gosu/Audio.hpp>
2
+ #include <Gosu/Song.h>
3
+
4
+ extern "C" {
5
+ Gosu_Song* Gosu_Song_create(const char* filename)
6
+ {
7
+ return reinterpret_cast<Gosu_Song*>( new Gosu::Song(filename) );
8
+ }
9
+
10
+ void Gosu_Song_destroy(Gosu_Song* song)
11
+ {
12
+ delete( reinterpret_cast<Gosu::Song*>( song ));
13
+ }
14
+
15
+ void Gosu_Song_play(Gosu_Song* song, bool looping)
16
+ {
17
+ reinterpret_cast<Gosu::Song*>( song )->play(looping);
18
+ }
19
+
20
+ bool Gosu_Song_playing(Gosu_Song* song)
21
+ {
22
+ return reinterpret_cast<Gosu::Song*>( song )->playing();
23
+ }
24
+
25
+ void Gosu_Song_pause(Gosu_Song* song)
26
+ {
27
+ reinterpret_cast<Gosu::Song*>( song )->pause();
28
+ }
29
+
30
+ bool Gosu_Song_paused(Gosu_Song* song)
31
+ {
32
+ return reinterpret_cast<Gosu::Song*>( song )->paused();
33
+ }
34
+
35
+ void Gosu_Song_stop(Gosu_Song* song)
36
+ {
37
+ reinterpret_cast<Gosu::Song*>( song )->stop();
38
+ }
39
+
40
+ double Gosu_Song_volume(Gosu_Song* song){
41
+ return reinterpret_cast<Gosu::Song*>( song )->volume();
42
+ }
43
+
44
+ void Gosu_Song_set_volume(Gosu_Song* song, double volume){
45
+ return reinterpret_cast<Gosu::Song*>( song )->set_volume(volume);
46
+ }
47
+
48
+ Gosu_Song* Gosu_Song_current_song()
49
+ {
50
+ return reinterpret_cast<Gosu_Song*>(Gosu::Song::current_song());
51
+ }
52
+ }
@@ -120,7 +120,7 @@ void Gosu::TexChunk::insert(const Bitmap& original_bitmap, int x, int y)
120
120
  if (clipped_width <= 0 || clipped_height <= 0) return;
121
121
 
122
122
  clipped_bitmap.resize(clipped_width, clipped_height);
123
- clipped_bitmap.insert(original_bitmap, -clip_left, -clip_top);
123
+ clipped_bitmap.insert(-clip_left, -clip_top, original_bitmap);
124
124
  bitmap = &clipped_bitmap;
125
125
  }
126
126
 
@@ -7,6 +7,7 @@
7
7
  #include <cmath>
8
8
  #include <algorithm>
9
9
  #include <vector>
10
+ #include <stdexcept>
10
11
  using namespace std;
11
12
 
12
13
  double Gosu::text_width(const u32string& text,
@@ -1,8 +1,10 @@
1
1
  #include "TextBuilder.hpp"
2
2
  #include <Gosu/Text.hpp>
3
+
4
+ #include <utf8proc.h>
5
+
3
6
  #include <cassert>
4
7
  #include <cmath>
5
- #include "utf8proc.h"
6
8
  using namespace std;
7
9
 
8
10
  Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<FormattedString> parts)
@@ -0,0 +1,101 @@
1
+ #include <Gosu/Gosu.hpp>
2
+
3
+ namespace Gosu
4
+ {
5
+ class TextInputForWrapper : public Gosu::TextInput
6
+ {
7
+ public:
8
+ TextInputForWrapper();
9
+ std::string filter(std::string text) const override;
10
+ std::function<void (const char *text)> filter_callback;
11
+ std::string filter_result = "";
12
+ };
13
+ } // namespace Gosu
14
+
15
+ Gosu::TextInputForWrapper::TextInputForWrapper() : Gosu::TextInput()
16
+ {
17
+ }
18
+
19
+ std::string Gosu::TextInputForWrapper::filter(std::string text) const
20
+ {
21
+ if (filter_callback != nullptr) {
22
+ filter_callback(text.c_str());
23
+ return filter_result;
24
+ }
25
+ else {
26
+ return text;
27
+ }
28
+ }
29
+
30
+ extern "C" {
31
+ #include <Gosu/TextInput.h>
32
+
33
+ Gosu_TextInput *Gosu_TextInput_create()
34
+ {
35
+ return reinterpret_cast<Gosu_TextInput *>(new Gosu::TextInputForWrapper());
36
+ }
37
+
38
+ const char *Gosu_TextInput_text(Gosu_TextInput *text_input)
39
+ {
40
+ thread_local std::string string;
41
+ string = reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->text();
42
+
43
+ return string.c_str();
44
+ }
45
+
46
+ void Gosu_TextInput_set_text(Gosu_TextInput *text_input, const char *text)
47
+ {
48
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_text(text);
49
+ }
50
+
51
+ unsigned Gosu_TextInput_caret_pos(Gosu_TextInput *text_input)
52
+ {
53
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->caret_pos();
54
+ }
55
+
56
+ void Gosu_TextInput_set_caret_pos(Gosu_TextInput *text_input, unsigned pos)
57
+ {
58
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_caret_pos(pos);
59
+ }
60
+
61
+ unsigned Gosu_TextInput_selection_start(Gosu_TextInput *text_input)
62
+ {
63
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->selection_start();
64
+ }
65
+
66
+ void Gosu_TextInput_set_selection_start(Gosu_TextInput *text_input, unsigned pos)
67
+ {
68
+ return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_selection_start(pos);
69
+ }
70
+
71
+ void Gosu_TextInput_set_filter(Gosu_TextInput *text_input, void function(void *data, const char *text), void *data)
72
+ {
73
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_callback = [=](const char *text) { function(data, text); };
74
+ }
75
+
76
+ void Gosu_TextInput_set_filter_result(Gosu_TextInput *text_input, const char *result)
77
+ {
78
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_result = result;
79
+ }
80
+
81
+ void Gosu_TextInput_insert_text(Gosu_TextInput *text_input, const char *text)
82
+ {
83
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->insert_text(text);
84
+ }
85
+
86
+ void Gosu_TextInput_delete_backward(Gosu_TextInput *text_input)
87
+ {
88
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_backward();
89
+ }
90
+
91
+ void Gosu_TextInput_delete_forward(Gosu_TextInput *text_input)
92
+ {
93
+ reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_forward();
94
+ }
95
+
96
+ void Gosu_TextInput_destroy(Gosu_TextInput *text_input)
97
+ {
98
+ delete (reinterpret_cast<Gosu::TextInputForWrapper *>(text_input));
99
+ }
100
+
101
+ }
@@ -124,7 +124,7 @@ Gosu::Bitmap Gosu::Texture::to_bitmap(unsigned x, unsigned y, unsigned width, un
124
124
  // TODO: There are ways to retrieve only part of a texture, which we should use sooner or later.
125
125
  glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, full_texture.data());
126
126
  Bitmap bitmap(width, height);
127
- bitmap.insert(full_texture, -int(x), -int(y));
127
+ bitmap.insert(-int(x), -int(y), full_texture);
128
128
 
129
129
  return bitmap;
130
130
  #endif
@@ -1,6 +1,7 @@
1
1
  #include "TrueTypeFont.hpp"
2
2
  #include <Gosu/IO.hpp>
3
3
  #include <Gosu/Text.hpp>
4
+ #include <stdexcept>
4
5
 
5
6
  // Disable comma warnings in stb headers.
6
7
  #ifdef __GNUC__
@@ -9,7 +10,7 @@
9
10
  #endif
10
11
 
11
12
  #define STB_TRUETYPE_IMPLEMENTATION
12
- #include "stb_truetype.h"
13
+ #include <stb_truetype.h>
13
14
 
14
15
  #ifdef __GNUC__
15
16
  #pragma GCC diagnostic pop
@@ -1,7 +1,7 @@
1
1
  #include <Gosu/Utility.hpp>
2
2
  #include <Gosu/Platform.hpp>
3
3
 
4
- #include "utf8proc.h"
4
+ #include <utf8proc.h>
5
5
 
6
6
  #include <cstring>
7
7
  #include <stdexcept>
@@ -45,17 +45,20 @@ u32string Gosu::utf8_to_composed_utc4(const string& utf8)
45
45
  return utc4;
46
46
  }
47
47
 
48
- bool Gosu::has_extension(const string& filename, const char* extension)
48
+ bool Gosu::has_extension(string_view filename, string_view extension)
49
49
  {
50
- size_t ext_len = strlen(extension);
50
+ size_t ext_len = extension.length();
51
51
  if (ext_len > filename.length()) {
52
52
  return false;
53
53
  }
54
54
 
55
- const char* str = filename.c_str() + filename.length();
56
- const char* ext = extension + ext_len;
55
+ string_view::iterator filename_iter = filename.end();
56
+ string_view::iterator ext_iter = extension.end();
57
57
  while (ext_len--) {
58
- if (tolower((int) *--str) != *--ext) {
58
+ --filename_iter;
59
+ --ext_iter;
60
+
61
+ if (tolower((int) *filename_iter) != tolower((int) *ext_iter)) {
59
62
  return false;
60
63
  }
61
64
  }
@@ -66,6 +69,7 @@ bool Gosu::has_extension(const string& filename, const char* extension)
66
69
  #if defined(GOSU_IS_UNIX) && !defined(GOSU_IS_MAC)
67
70
  string Gosu::language()
68
71
  {
69
- return getenv("LANG");
72
+ const char* env = getenv("LANG");
73
+ return env ? env : "en_US";
70
74
  }
71
75
  #endif
@@ -22,8 +22,6 @@ namespace Gosu
22
22
  throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
23
23
  }
24
24
 
25
- static void cleanup();
26
-
27
25
  SDL_Window* shared_window()
28
26
  {
29
27
  static SDL_Window* window = nullptr;
@@ -32,14 +30,12 @@ namespace Gosu
32
30
  throw_sdl_error("Could not initialize SDL Video");
33
31
  }
34
32
 
35
- atexit(cleanup);
36
-
37
33
  Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
38
-
34
+
39
35
  #if SDL_VERSION_ATLEAST(2, 0, 1)
40
36
  flags |= SDL_WINDOW_ALLOW_HIGHDPI;
41
37
  #endif
42
-
38
+
43
39
  window =
44
40
  SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
45
41
  if (window == nullptr) {
@@ -58,27 +54,20 @@ namespace Gosu
58
54
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
59
55
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
60
56
  #endif
61
-
57
+
62
58
  context = SDL_GL_CreateContext(shared_window());
63
-
59
+
64
60
  if (context == nullptr) {
65
61
  throw_sdl_error("Could not create OpenGL context");
66
62
  }
67
63
  }
68
64
  return context;
69
65
  }
70
-
66
+
71
67
  void ensure_current_context()
72
68
  {
73
69
  SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
74
70
  }
75
-
76
- static void cleanup()
77
- {
78
- SDL_GL_DeleteContext(shared_gl_context());
79
- SDL_DestroyWindow(shared_window());
80
- SDL_QuitSubSystem(SDL_INIT_VIDEO);
81
- }
82
71
  }
83
72
 
84
73
  struct Gosu::Window::Impl
@@ -123,6 +112,8 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
123
112
 
124
113
  input().on_button_down = [this](Button button) { button_down(button); };
125
114
  input().on_button_up = [this](Button button) { button_up(button); };
115
+ input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
116
+ input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
126
117
  }
127
118
 
128
119
  Gosu::Window::~Window()
@@ -153,17 +144,17 @@ bool Gosu::Window::resizable() const
153
144
  void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
154
145
  {
155
146
  pimpl->fullscreen = fullscreen;
156
-
147
+
157
148
  int actual_width = width;
158
149
  int actual_height = height;
159
150
  double scale_factor = 1.0;
160
151
  double black_bar_width = 0;
161
152
  double black_bar_height = 0;
162
-
153
+
163
154
  if (fullscreen) {
164
155
  actual_width = Gosu::screen_width(this);
165
156
  actual_height = Gosu::screen_height(this);
166
-
157
+
167
158
  if (resizable()) {
168
159
  // Resizable fullscreen windows stubbornly follow the desktop resolution.
169
160
  width = actual_width;
@@ -186,7 +177,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
186
177
  else {
187
178
  unsigned max_width = Gosu::available_width(this);
188
179
  unsigned max_height = Gosu::available_height(this);
189
-
180
+
190
181
  if (resizable()) {
191
182
  // If the window is resizable, limit its size, without preserving the aspect ratio.
192
183
  width = actual_width = min(width, max_width);
@@ -199,18 +190,18 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
199
190
  actual_height = height * scale_factor;
200
191
  }
201
192
  }
202
-
193
+
203
194
  SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
204
195
  if (!pimpl->resizing) {
205
196
  SDL_SetWindowSize(shared_window(), actual_width, actual_height);
206
197
  }
207
-
198
+
208
199
  #if SDL_VERSION_ATLEAST(2, 0, 1)
209
200
  SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
210
201
  #endif
211
-
202
+
212
203
  ensure_current_context();
213
-
204
+
214
205
  if (!pimpl->graphics) {
215
206
  pimpl->graphics.reset(new Graphics(actual_width, actual_height));
216
207
  }
@@ -218,7 +209,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
218
209
  pimpl->graphics->set_physical_resolution(actual_width, actual_height);
219
210
  }
220
211
  pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
221
-
212
+
222
213
  if (!pimpl->input) {
223
214
  pimpl->input.reset(new Input(shared_window()));
224
215
  }
@@ -250,17 +241,17 @@ void Gosu::Window::set_caption(const string& caption)
250
241
  void Gosu::Window::show()
251
242
  {
252
243
  unsigned long time_before_tick = milliseconds();
253
-
244
+
254
245
  while (tick()) {
255
246
  // Sleep to keep this loop from eating 100% CPU.
256
247
  unsigned long tick_time = milliseconds() - time_before_tick;
257
248
  if (tick_time < update_interval()) {
258
249
  sleep(update_interval() - tick_time);
259
250
  }
260
-
251
+
261
252
  time_before_tick = milliseconds();
262
253
  }
263
-
254
+
264
255
  pimpl->state = Impl::CLOSED;
265
256
  }
266
257
 
@@ -270,7 +261,7 @@ bool Gosu::Window::tick()
270
261
  pimpl->state = Impl::CLOSED;
271
262
  return false;
272
263
  }
273
-
264
+
274
265
  if (pimpl->state == Impl::CLOSED) {
275
266
  SDL_ShowWindow(shared_window());
276
267
  pimpl->state = Impl::OPEN;
@@ -282,7 +273,7 @@ bool Gosu::Window::tick()
282
273
  SDL_GL_GetDrawableSize(shared_window(), &width, &height);
283
274
  graphics().set_physical_resolution(width, height);
284
275
  }
285
-
276
+
286
277
  SDL_Event e;
287
278
  while (SDL_PollEvent(&e)) {
288
279
 
@@ -320,29 +311,29 @@ bool Gosu::Window::tick()
320
311
  }
321
312
  }
322
313
  }
323
-
314
+
324
315
  Song::update();
325
-
316
+
326
317
  input().update();
327
-
318
+
328
319
  update();
329
-
320
+
330
321
  SDL_ShowCursor(needs_cursor());
331
-
322
+
332
323
  if (needs_redraw()) {
333
324
  ensure_current_context();
334
325
  graphics().frame([&] {
335
326
  draw();
336
327
  FPS::register_frame();
337
328
  });
338
-
329
+
339
330
  SDL_GL_SwapWindow(shared_window());
340
331
  }
341
-
332
+
342
333
  if (pimpl->state == Impl::CLOSING) {
343
334
  pimpl->state = Impl::CLOSED;
344
335
  }
345
-
336
+
346
337
  return pimpl->state == Impl::OPEN;
347
338
  }
348
339
 
@@ -357,7 +348,7 @@ void Gosu::Window::button_down(Button button)
357
348
  bool toggle_fullscreen;
358
349
 
359
350
  // Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
360
-
351
+
361
352
  #ifdef GOSU_IS_MAC
362
353
  // cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
363
354
  toggle_fullscreen = button == KB_F &&