gosu 0.15.1 → 1.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) 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} +143 -78
  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 +330 -127
  155. data/{src → dependencies/stb}/stb_image_write.h +156 -85
  156. data/{src → dependencies/stb}/stb_truetype.h +192 -69
  157. data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
  158. data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
  159. data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
  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/{Gosu → include/Gosu}/Color.hpp +0 -0
  165. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  166. data/{Gosu → include/Gosu}/Font.hpp +1 -1
  167. data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
  168. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  169. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  170. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  171. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  172. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  173. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  174. data/{Gosu → include/Gosu}/Input.hpp +39 -51
  175. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  176. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  177. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  178. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  179. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  180. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Utility.hpp +15 -4
  182. data/{Gosu → include/Gosu}/Version.hpp +3 -3
  183. data/{Gosu → include/Gosu}/Window.hpp +46 -34
  184. data/lib/OpenAL32.dll +0 -0
  185. data/lib/SDL2.dll +0 -0
  186. data/lib/gosu.rb +0 -3
  187. data/lib/gosu/patches.rb +0 -23
  188. data/lib/gosu/preview.rb +1 -3
  189. data/lib/gosu/swig_patches.rb +6 -8
  190. data/lib64/OpenAL32.dll +0 -0
  191. data/lib64/SDL2.dll +0 -0
  192. data/rdoc/gosu.rb +112 -23
  193. data/src/Audio.cpp +50 -224
  194. data/src/AudioFile.hpp +20 -37
  195. data/src/AudioFileAudioToolbox.cpp +237 -0
  196. data/src/AudioFileSDLSound.cpp +147 -0
  197. data/src/AudioImpl.cpp +3 -12
  198. data/src/AudioImpl.hpp +3 -1
  199. data/src/Bitmap.cpp +85 -83
  200. data/src/BitmapIO.cpp +52 -58
  201. data/src/Font.cpp +4 -1
  202. data/src/Graphics.cpp +7 -4
  203. data/src/Image.cpp +13 -16
  204. data/src/Input.cpp +412 -164
  205. data/src/LargeImageData.cpp +2 -1
  206. data/src/MarkupParser.cpp +2 -1
  207. data/src/Resolution.cpp +8 -8
  208. data/src/RubyGosu.cxx +1184 -352
  209. data/src/RubyGosu.h +3 -2
  210. data/src/TexChunk.cpp +1 -1
  211. data/src/Text.cpp +1 -0
  212. data/src/TextBuilder.cpp +3 -1
  213. data/src/Texture.cpp +1 -1
  214. data/src/TrueTypeFont.cpp +2 -1
  215. data/src/TrueTypeFontWin.cpp +3 -3
  216. data/src/Utility.cpp +11 -7
  217. data/src/Window.cpp +90 -62
  218. data/src/WindowUIKit.cpp +21 -9
  219. metadata +195 -46
  220. data/Gosu/AutoLink.hpp +0 -14
  221. data/Gosu/Bitmap.hpp +0 -113
  222. data/lib/gosu/zen.rb +0 -89
  223. data/src/AudioToolboxFile.hpp +0 -210
  224. data/src/MPEGFile.hpp +0 -90
  225. data/src/OggFile.hpp +0 -92
  226. data/src/SndFile.hpp +0 -174
  227. data/src/WinMain.cpp +0 -64
@@ -1,41 +1,62 @@
1
- #!/usr/bin/env ruby
1
+ require "rbconfig"
2
2
 
3
- if RUBY_PLATFORM =~ /mswin$|mingw32|mingw64|win32\-|\-win32/
4
- platform = (RUBY_PLATFORM =~ /^x64-/ ? 'x64-mingw32' : 'i386-mingw32')
5
-
6
- puts "This gem is not meant to be installed on Windows. Instead, please use:"
7
- puts "gem install gosu --platform=#{platform}"
8
- exit 1
3
+ case RbConfig::CONFIG["host_os"]
4
+ when /^mingw/
5
+ windows = true
6
+ when /^darwin/
7
+ macos = true
9
8
  end
10
9
 
11
- puts 'The Gosu gem requires some libraries to be installed system-wide.'
12
- puts 'See the following site for a list:'
13
- if `uname`.chomp == 'Darwin'
14
- puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X'
15
- else
16
- puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux'
10
+ if not windows
11
+ puts 'The Gosu gem requires some libraries to be installed system-wide.'
12
+ puts 'See the following site for a list:'
13
+ if macos
14
+ puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X'
15
+ else
16
+ puts 'https://github.com/gosu/gosu/wiki/Getting-Started-on-Linux'
17
+ end
17
18
  end
18
19
 
19
20
  require 'mkmf'
20
21
  require 'fileutils'
21
22
 
22
- # Silence internal deprecation warnings in Gosu
23
+ # Silence internal deprecation warnings in Gosu.
23
24
  $CFLAGS << " -DGOSU_DEPRECATED="
24
25
 
26
+ # Disable assertions in C code.
27
+ $CFLAGS << " -DNDEBUG"
28
+
25
29
  $CXXFLAGS ||= ""
26
- $CXXFLAGS << " -std=gnu++11"
30
+ # Enable C++17, but at the same time make the compiler more permissive to avoid this error:
31
+ # https://stackoverflow.com/a/31899029 (triggered by ruby.h, which uses register variables)
32
+ # The "register" macro can be removed when support for Ruby 2.6 and older has been dropped.
33
+ $CXXFLAGS << " -std=gnu++17 -Dregister="
34
+
35
+ # Make Gosu's own header files and all of its dependencies available to C++ source files.
36
+ $INCFLAGS << " -I../../include -I../../dependencies/stb -I../../dependencies/utf8proc -I../../dependencies/SDL_sound"
27
37
 
28
- # For #include <Gosu/...>
29
- $INCFLAGS << " -I../.."
38
+ if windows
39
+ # We statically compile utf8proc into the Gosu binary.
40
+ # This macro is required to avoid errors about dllexport/dllimport mismatches.
41
+ $CFLAGS << " -DUTF8PROC_STATIC"
42
+ $CXXFLAGS << " -DUTF8PROC_STATIC"
30
43
 
31
- if `uname`.chomp == 'Darwin'
32
- # Disable assertions in C code.
33
- $CFLAGS << " -DNDEBUG"
44
+ # Define UNICODE to use the Unicode-aware variants of all Win32 API functions.
45
+ $CXXFLAGS << " -DUNICODE"
46
+
47
+ # Use the bundled versions of SDL 2 and open_al.
48
+ $INCFLAGS << " -I../../dependencies/al_soft -I../../dependencies/SDL/include"
49
+ if RbConfig::CONFIG['arch'] =~ /x64-/
50
+ $LDFLAGS << " -L../../dependencies/al_soft/x64 -L../../dependencies/SDL/lib/x64"
51
+ else
52
+ $LDFLAGS << " -L../../dependencies/al_soft/x86 -L../../dependencies/SDL/lib/x86"
53
+ end
54
+ $LDFLAGS << " -lgdi32 -lwinmm -lOpenGL32 -lOpenAL32 -lSDL2"
55
+ # Link libstdc++ statically to avoid having another DLL dependency when using Ocra.
56
+ $LDFLAGS << " -static-libstdc++"
57
+ elsif macos
34
58
  # Compile all C++ files as Objective C++ on macOS since mkmf does not support .mm files.
35
59
  $CXXFLAGS << " -x objective-c++ -fobjc-arc -DNDEBUG"
36
- # Prevents issues with Apple's pre-installed Ruby 2.3 on macOS 10.13.
37
- # https://github.com/gosu/gosu/issues/424
38
- $CXXFLAGS << " -Wno-reserved-user-defined-literal"
39
60
 
40
61
  # Explicitly specify libc++ as the standard library.
41
62
  # rvm will sometimes try to override this:
@@ -43,6 +64,7 @@ if `uname`.chomp == 'Darwin'
43
64
  $CXXFLAGS << " -stdlib=libc++"
44
65
 
45
66
  # Dependencies.
67
+ $CFLAGS << " #{`sdl2-config --cflags`.chomp}"
46
68
  $CXXFLAGS << " #{`sdl2-config --cflags`.chomp}"
47
69
  # Prefer statically linking SDL 2.
48
70
  $LDFLAGS << " #{`sdl2-config --static-libs`.chomp} -framework OpenGL -framework Metal -framework OpenAL"
@@ -76,24 +98,16 @@ else
76
98
  pkg_config 'libmpg123'
77
99
  pkg_config 'fontconfig'
78
100
 
79
- have_header 'AL/al.h' if have_library('openal')
101
+ have_header 'AL/al.h' if have_library('openal')
80
102
  end
81
103
 
82
- # Gem::Version#initialize is apparently broken in some versions of Ruby, so use a local helper.
83
- def ruby_newer_than?(want_version)
84
- have_parts = RUBY_VERSION.split('.').map { |part| part.to_i }
85
- want_parts = want_version.split('.').map { |part| part.to_i }
86
- have_parts << 0 while have_parts.size < want_parts.size
87
- want_parts << 0 while want_parts.size < have_parts.size
88
- (have_parts <=> want_parts) == 1
89
- end
90
-
91
- # In some versions of Ruby/mkmf, the $CXXFLAGS variable does not work.
92
- # We can modify CONFIG instead, and our changes will end up in the Makefile.
93
- # See: http://bugs.ruby-lang.org/issues/8315
94
- # The lower bound was reduced to 1.9.3 here: https://github.com/gosu/gosu/issues/321
95
- if ruby_newer_than?("1.9.2") and not ruby_newer_than?("2.2.0")
96
- CONFIG['CXXFLAGS'] = "#$CFLAGS #$CXXFLAGS"
104
+ # Because Ruby will only compile source file in the src/ folder, but our dependencies are
105
+ # stored in dependencies/, we need to create symlinks for all the .c files. This is terrible,
106
+ # but still seems better than putting everything into the same folder to begin with.
107
+ Dir.glob('../../dependencies/**/*.c').each do |dep|
108
+ File.open("../../src/#{File.basename dep}", "w") do |shim|
109
+ shim.puts "#include \"#{File.expand_path dep}\""
110
+ end
97
111
  end
98
112
 
99
113
  create_makefile "gosu", "../../src"
@@ -51,8 +51,8 @@ namespace Gosu
51
51
  //! parameters. Use samples for everything that's not music.
52
52
  class Sample
53
53
  {
54
- struct SampleData;
55
- std::shared_ptr<SampleData> data;
54
+ struct Impl;
55
+ std::shared_ptr<Impl> pimpl;
56
56
 
57
57
  public:
58
58
  //! Constructs an empty sample that is inaudible when played.
@@ -91,10 +91,8 @@ namespace Gosu
91
91
  //! and there is no way to control its pan (stereo position) or speed.
92
92
  class Song
93
93
  {
94
- class BaseData;
95
- class ModuleData;
96
- class StreamData;
97
- std::unique_ptr<BaseData> data;
94
+ struct Impl;
95
+ std::unique_ptr<Impl> pimpl;
98
96
 
99
97
  // Non-movable to avoid dangling internal references.
100
98
  Song(Song&&) = delete;
@@ -117,7 +115,7 @@ namespace Gosu
117
115
  //! no song has been played yet or the last song has finished
118
116
  //! playing.
119
117
  static Song* current_song();
120
-
118
+
121
119
  //! Starts or resumes playback of the song. This will stop all other
122
120
  //! songs and set the current song to this object.
123
121
  void play(bool looping = false);
@@ -137,7 +135,7 @@ namespace Gosu
137
135
  //! \param volume Can be anything from 0.0 (silence) to 1.0 (full volume).
138
136
  void set_volume(double volume);
139
137
 
140
- //! Called every tick by Window for management purposes.
138
+ //! Called every tick by Window to feed new audio data to OpenAL.
141
139
  static void update();
142
140
  };
143
141
  }
@@ -0,0 +1,100 @@
1
+ #pragma once
2
+
3
+ #include <Gosu/Color.hpp>
4
+ #include <Gosu/IO.hpp>
5
+ #include <string>
6
+ #include <vector>
7
+
8
+ namespace Gosu
9
+ {
10
+ /// A two-dimensional array area of pixels, each represented by a Color value.
11
+ /// Bitmaps are typically created only as an intermediate step between loading image files, and
12
+ /// creating Gosu::Image objects from them (i.e. transferring the image into video RAM).
13
+ /// Has (expensive) value semantics.
14
+ class Bitmap
15
+ {
16
+ int m_width = 0, m_height = 0;
17
+ std::vector<Color> m_pixels;
18
+
19
+ public:
20
+ Bitmap() = default;
21
+
22
+ Bitmap(int width, int height, Color c = Color::NONE);
23
+
24
+ int width() const
25
+ {
26
+ return m_width;
27
+ }
28
+
29
+ int height() const
30
+ {
31
+ return m_height;
32
+ }
33
+
34
+ void swap(Bitmap& other);
35
+
36
+ void resize(int width, int height, Color c = Color::NONE);
37
+
38
+ /// Returns the color at the specified position without any bounds checking.
39
+ Color get_pixel(int x, int y) const
40
+ {
41
+ return m_pixels[y * m_width + x];
42
+ }
43
+
44
+ /// Sets the pixel at the specified position without any bounds checking.
45
+ void set_pixel(int x, int y, Color c)
46
+ {
47
+ m_pixels[y * m_width + x] = c;
48
+ }
49
+
50
+ /// This updates a pixel using the "over" alpha compositing operator, see:
51
+ /// https://en.wikipedia.org/wiki/Alpha_compositing
52
+ void blend_pixel(int x, int y, Color c);
53
+
54
+ /// Inserts a bitmap at the given position. Parts of the inserted bitmap that would be
55
+ /// outside of the target bitmap will be clipped away.
56
+ void insert(int x, int y, const Bitmap& source);
57
+
58
+ /// Inserts a portion of a bitmap at the given position. Parts of the inserted bitmap that
59
+ /// would be outside of the target bitmap will be clipped away.
60
+ void insert(int x, int y, const Bitmap& source,
61
+ int src_x, int src_y, int src_width, int src_height);
62
+
63
+ /// Direct access to the array of color values.
64
+ /// The return value is undefined if this bitmap is empty.
65
+ const Color* data() const
66
+ {
67
+ return &m_pixels[0];
68
+ }
69
+
70
+ /// Direct access to the array of color values.
71
+ /// The return value is undefined if this bitmap is empty.
72
+ Color* data()
73
+ {
74
+ return &m_pixels[0];
75
+ }
76
+
77
+ #ifdef FRIEND_TEST
78
+ FRIEND_TEST(BitmapTests, MemoryManagement);
79
+ #endif
80
+ };
81
+
82
+ /// Loads any supported image into a Bitmap.
83
+ Bitmap load_image_file(const std::string& filename);
84
+ /// Loads any supported image into a Bitmap.
85
+ Bitmap load_image_file(Reader input);
86
+
87
+ /// Saves a Bitmap to a file.
88
+ void save_image_file(const Bitmap& bitmap, const std::string& filename);
89
+ /// Saves a Bitmap to an arbitrary resource.
90
+ void save_image_file(const Bitmap& bitmap, Writer writer,
91
+ const std::string_view& format_hint = "png");
92
+
93
+ /// Set the alpha value of all pixels which are equal to the color key to zero.
94
+ /// To reduce interpolation artefacts when stretching or rotating the resulting image, the color
95
+ /// value of these pixels will also be adjusted to the average of their surrounding pixels.
96
+ void apply_color_key(Bitmap& bitmap, Color key);
97
+
98
+ Bitmap apply_border_flags(unsigned image_flags, const Bitmap& source,
99
+ int src_x, int src_y, int src_width, int src_height);
100
+ }
@@ -1,15 +1,12 @@
1
1
  #pragma once
2
2
 
3
- #include <Gosu/Platform.hpp>
4
-
5
3
  namespace Gosu
6
4
  {
7
- //! List of button ids that can be used with Gosu::Input.
8
- //! This enumeration contains ids for keyboard keys (KB_*),
9
- //! mouse buttons and mouse wheel (MS_*) and gamepad buttons (GP_*).
10
- enum ButtonName
5
+ /// List of button IDs that can be used with Gosu::Input.
6
+ /// This enumeration contains IDs for keyboard keys (KB_*),
7
+ /// mouse buttons and mouse wheel (MS_*), as well as gamepad buttons (GP_*).
8
+ enum Button
11
9
  {
12
- KB_RANGE_BEGIN,
13
10
  KB_ESCAPE = 41,
14
11
  KB_F1 = 58,
15
12
  KB_F2 = 59,
@@ -51,6 +48,9 @@ namespace Gosu
51
48
  KB_DOWN = 81,
52
49
  KB_HOME = 74,
53
50
  KB_END = 77,
51
+ KB_PRINT_SCREEN = 70,
52
+ KB_SCROLL_LOCK = 71,
53
+ KB_PAUSE = 72,
54
54
  KB_INSERT = 73,
55
55
  KB_DELETE = 76,
56
56
  KB_PAGE_UP = 75,
@@ -67,6 +67,7 @@ namespace Gosu
67
67
  KB_COMMA = 54,
68
68
  KB_PERIOD = 55,
69
69
  KB_SLASH = 56,
70
+ KB_CAPS_LOCK = 57,
70
71
  KB_A = 4,
71
72
  KB_B = 5,
72
73
  KB_C = 6,
@@ -93,7 +94,8 @@ namespace Gosu
93
94
  KB_X = 27,
94
95
  KB_Y = 28,
95
96
  KB_Z = 29,
96
- KB_ISO = 100, // ` on US/UK macOS, < on EU macOS, \ on US/UK Windows
97
+ /// ` on US/UK macOS, < on EU macOS, \ on US/UK Windows
98
+ KB_ISO = 100,
97
99
  KB_NUMPAD_0 = 98,
98
100
  KB_NUMPAD_1 = 89,
99
101
  KB_NUMPAD_2 = 90,
@@ -125,13 +127,12 @@ namespace Gosu
125
127
  MS_OTHER_5,
126
128
  MS_OTHER_6,
127
129
  MS_OTHER_7,
128
- MS_RANGE_END = 0x110,
129
-
130
+
130
131
  GP_RANGE_BEGIN,
131
- GP_LEFT = GP_RANGE_BEGIN,
132
- GP_RIGHT,
133
- GP_UP,
134
- GP_DOWN,
132
+ GP_DPAD_LEFT = GP_RANGE_BEGIN,
133
+ GP_DPAD_RIGHT,
134
+ GP_DPAD_UP,
135
+ GP_DPAD_DOWN,
135
136
  GP_BUTTON_0,
136
137
  GP_BUTTON_1,
137
138
  GP_BUTTON_2,
@@ -149,10 +150,10 @@ namespace Gosu
149
150
  GP_BUTTON_14,
150
151
  GP_BUTTON_15,
151
152
 
152
- GP_0_LEFT,
153
- GP_0_RIGHT,
154
- GP_0_UP,
155
- GP_0_DOWN,
153
+ GP_0_DPAD_LEFT,
154
+ GP_0_DPAD_RIGHT,
155
+ GP_0_DPAD_UP,
156
+ GP_0_DPAD_DOWN,
156
157
  GP_0_BUTTON_0,
157
158
  GP_0_BUTTON_1,
158
159
  GP_0_BUTTON_2,
@@ -169,11 +170,11 @@ namespace Gosu
169
170
  GP_0_BUTTON_13,
170
171
  GP_0_BUTTON_14,
171
172
  GP_0_BUTTON_15,
172
-
173
- GP_1_LEFT,
174
- GP_1_RIGHT,
175
- GP_1_UP,
176
- GP_1_DOWN,
173
+
174
+ GP_1_DPAD_LEFT,
175
+ GP_1_DPAD_RIGHT,
176
+ GP_1_DPAD_UP,
177
+ GP_1_DPAD_DOWN,
177
178
  GP_1_BUTTON_0,
178
179
  GP_1_BUTTON_1,
179
180
  GP_1_BUTTON_2,
@@ -190,11 +191,11 @@ namespace Gosu
190
191
  GP_1_BUTTON_13,
191
192
  GP_1_BUTTON_14,
192
193
  GP_1_BUTTON_15,
193
-
194
- GP_2_LEFT,
195
- GP_2_RIGHT,
196
- GP_2_UP,
197
- GP_2_DOWN,
194
+
195
+ GP_2_DPAD_LEFT,
196
+ GP_2_DPAD_RIGHT,
197
+ GP_2_DPAD_UP,
198
+ GP_2_DPAD_DOWN,
198
199
  GP_2_BUTTON_0,
199
200
  GP_2_BUTTON_1,
200
201
  GP_2_BUTTON_2,
@@ -211,11 +212,11 @@ namespace Gosu
211
212
  GP_2_BUTTON_13,
212
213
  GP_2_BUTTON_14,
213
214
  GP_2_BUTTON_15,
214
-
215
- GP_3_LEFT,
216
- GP_3_RIGHT,
217
- GP_3_UP,
218
- GP_3_DOWN,
215
+
216
+ GP_3_DPAD_LEFT,
217
+ GP_3_DPAD_RIGHT,
218
+ GP_3_DPAD_UP,
219
+ GP_3_DPAD_DOWN,
219
220
  GP_3_BUTTON_0,
220
221
  GP_3_BUTTON_1,
221
222
  GP_3_BUTTON_2,
@@ -232,16 +233,75 @@ namespace Gosu
232
233
  GP_3_BUTTON_13,
233
234
  GP_3_BUTTON_14,
234
235
  GP_3_BUTTON_15,
235
-
236
- GP_RANGE_END = GP_3_BUTTON_15,
237
-
238
- NUM_BUTTONS = GP_RANGE_END + 1,
239
- NUM_GAMEPADS = 4,
240
- NO_BUTTON = 0xffffffff,
241
-
242
- KB_NUM = KB_RANGE_END - KB_RANGE_BEGIN + 1,
243
- MS_NUM = MS_RANGE_END - MS_RANGE_BEGIN + 1,
244
- GP_NUM = GP_RANGE_END - GP_RANGE_BEGIN + 1,
245
- GP_NUM_PER_GAMEPAD = GP_NUM / (NUM_GAMEPADS + 1)
236
+
237
+ GP_LEFT,
238
+ GP_RIGHT,
239
+ GP_UP,
240
+ GP_DOWN,
241
+
242
+ GP_0_LEFT,
243
+ GP_0_RIGHT,
244
+ GP_0_UP,
245
+ GP_0_DOWN,
246
+
247
+ GP_1_LEFT,
248
+ GP_1_RIGHT,
249
+ GP_1_UP,
250
+ GP_1_DOWN,
251
+
252
+ GP_2_LEFT,
253
+ GP_2_RIGHT,
254
+ GP_2_UP,
255
+ GP_2_DOWN,
256
+
257
+ GP_3_LEFT,
258
+ GP_3_RIGHT,
259
+ GP_3_UP,
260
+ GP_3_DOWN,
261
+ GP_RANGE_END = GP_3_DOWN,
262
+
263
+ NUM_GAMEPADS = 4,
264
+ NO_BUTTON = 0xffffffff,
265
+ };
266
+
267
+ /// List of axis IDs that can be used with Gosu::Input.
268
+ enum Axis
269
+ {
270
+ GP_LEFT_STICK_X_AXIS,
271
+ GP_LEFT_STICK_Y_AXIS,
272
+ GP_RIGHT_STICK_X_AXIS,
273
+ GP_RIGHT_STICK_Y_AXIS,
274
+ GP_LEFT_TRIGGER_AXIS,
275
+ GP_RIGHT_TRIGGER_AXIS,
276
+
277
+ GP_0_LEFT_STICK_X_AXIS,
278
+ GP_0_LEFT_STICK_Y_AXIS,
279
+ GP_0_RIGHT_STICK_X_AXIS,
280
+ GP_0_RIGHT_STICK_Y_AXIS,
281
+ GP_0_LEFT_TRIGGER_AXIS,
282
+ GP_0_RIGHT_TRIGGER_AXIS,
283
+
284
+ GP_1_LEFT_STICK_X_AXIS,
285
+ GP_1_LEFT_STICK_Y_AXIS,
286
+ GP_1_RIGHT_STICK_X_AXIS,
287
+ GP_1_RIGHT_STICK_Y_AXIS,
288
+ GP_1_LEFT_TRIGGER_AXIS,
289
+ GP_1_RIGHT_TRIGGER_AXIS,
290
+
291
+ GP_2_LEFT_STICK_X_AXIS,
292
+ GP_2_LEFT_STICK_Y_AXIS,
293
+ GP_2_RIGHT_STICK_X_AXIS,
294
+ GP_2_RIGHT_STICK_Y_AXIS,
295
+ GP_2_LEFT_TRIGGER_AXIS,
296
+ GP_2_RIGHT_TRIGGER_AXIS,
297
+
298
+ GP_3_LEFT_STICK_X_AXIS,
299
+ GP_3_LEFT_STICK_Y_AXIS,
300
+ GP_3_RIGHT_STICK_X_AXIS,
301
+ GP_3_RIGHT_STICK_Y_AXIS,
302
+ GP_3_LEFT_TRIGGER_AXIS,
303
+ GP_3_RIGHT_TRIGGER_AXIS,
304
+
305
+ NUM_AXES
246
306
  };
247
307
  }