gosu 1.5.0 → 2.0.0.pre6
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.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +233 -0
- data/dependencies/SDL/include/SDL_assert.h +320 -0
- data/dependencies/SDL/include/SDL_atomic.h +414 -0
- data/dependencies/SDL/include/SDL_audio.h +1500 -0
- data/dependencies/SDL/include/{SDL3/SDL_bits.h → SDL_bits.h} +27 -47
- data/dependencies/SDL/include/{SDL3/SDL_blendmode.h → SDL_blendmode.h} +55 -59
- data/dependencies/SDL/include/SDL_clipboard.h +141 -0
- data/dependencies/SDL/include/SDL_config.h +331 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +594 -0
- data/dependencies/SDL/include/{SDL3/SDL_egl.h → SDL_egl.h} +8 -11
- data/dependencies/SDL/include/SDL_endian.h +348 -0
- data/dependencies/SDL/include/SDL_error.h +163 -0
- data/dependencies/SDL/include/SDL_events.h +1166 -0
- data/dependencies/SDL/include/SDL_filesystem.h +149 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +1074 -0
- data/dependencies/SDL/include/SDL_gesture.h +117 -0
- data/dependencies/SDL/include/SDL_guid.h +100 -0
- data/dependencies/SDL/include/SDL_haptic.h +1341 -0
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +2613 -0
- data/dependencies/SDL/include/SDL_joystick.h +1069 -0
- data/dependencies/SDL/include/SDL_keyboard.h +353 -0
- data/dependencies/SDL/include/SDL_keycode.h +358 -0
- data/dependencies/SDL/include/SDL_loadso.h +115 -0
- data/dependencies/SDL/include/{SDL3/SDL_locale.h → SDL_locale.h} +24 -40
- data/dependencies/SDL/include/SDL_log.h +404 -0
- data/dependencies/SDL/include/SDL_main.h +282 -0
- data/dependencies/SDL/include/{SDL3/SDL_messagebox.h → SDL_messagebox.h} +48 -85
- data/dependencies/SDL/include/{SDL3/SDL_metal.h → SDL_metal.h} +29 -29
- data/dependencies/SDL/include/{SDL3/SDL_misc.h → SDL_misc.h} +12 -13
- data/dependencies/SDL/include/SDL_mouse.h +464 -0
- data/dependencies/SDL/include/SDL_mutex.h +545 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/{SDL3/SDL_opengl.h → SDL_opengl.h} +252 -1221
- data/dependencies/SDL/include/{SDL3/SDL_opengles.h → SDL_opengles.h} +7 -6
- data/dependencies/SDL/include/{SDL3/SDL_opengles2.h → SDL_opengles2.h} +11 -10
- data/dependencies/SDL/include/SDL_pixels.h +644 -0
- data/dependencies/SDL/include/SDL_platform.h +261 -0
- data/dependencies/SDL/include/{SDL3/SDL_power.h → SDL_power.h} +19 -40
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +376 -0
- data/dependencies/SDL/include/SDL_render.h +1924 -0
- data/dependencies/SDL/include/SDL_revision.h +7 -0
- data/dependencies/SDL/include/SDL_rwops.h +841 -0
- data/dependencies/SDL/include/{SDL3/SDL_scancode.h → SDL_scancode.h} +68 -60
- data/dependencies/SDL/include/SDL_sensor.h +322 -0
- data/dependencies/SDL/include/SDL_shape.h +155 -0
- data/dependencies/SDL/include/SDL_stdinc.h +838 -0
- data/dependencies/SDL/include/SDL_surface.h +997 -0
- data/dependencies/SDL/include/SDL_system.h +623 -0
- data/dependencies/SDL/include/SDL_syswm.h +386 -0
- data/dependencies/SDL/include/{SDL3/SDL_test.h → SDL_test.h} +22 -16
- data/dependencies/SDL/include/{SDL3/SDL_test_assert.h → SDL_test_assert.h} +34 -27
- data/dependencies/SDL/include/{SDL3/SDL_test_common.h → SDL_test_common.h} +52 -109
- data/dependencies/SDL/include/{SDL3/SDL_test_compare.h → SDL_test_compare.h} +14 -22
- data/dependencies/SDL/include/{SDL3/SDL_test_crc32.h → SDL_test_crc32.h} +30 -27
- data/dependencies/SDL/include/{SDL3/SDL_test_font.h → SDL_test_font.h} +49 -50
- data/dependencies/SDL/include/{SDL3/SDL_test_fuzzer.h → SDL_test_fuzzer.h} +79 -64
- data/dependencies/SDL/include/{SDL3/SDL_test_harness.h → SDL_test_harness.h} +30 -47
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/{SDL3/SDL_platform.h → SDL_test_log.h} +26 -25
- data/dependencies/SDL/include/{SDL3/SDL_test_md5.h → SDL_test_md5.h} +28 -21
- data/dependencies/SDL/include/{SDL3/SDL_test_memory.h → SDL_test_memory.h} +16 -19
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +464 -0
- data/dependencies/SDL/include/SDL_timer.h +222 -0
- data/dependencies/SDL/include/SDL_touch.h +150 -0
- data/dependencies/SDL/include/{SDL3/SDL_copying.h → SDL_types.h} +9 -2
- data/dependencies/SDL/include/SDL_version.h +204 -0
- data/dependencies/SDL/include/SDL_video.h +2178 -0
- data/dependencies/SDL/include/SDL_vulkan.h +215 -0
- data/dependencies/SDL/include/begin_code.h +187 -0
- data/dependencies/SDL/include/{SDL3/SDL_close_code.h → close_code.h} +6 -7
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +215 -136
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +54 -55
- data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +41 -24
- data/dependencies/SDL_sound/SDL_sound_flac.c +12 -32
- data/dependencies/SDL_sound/SDL_sound_internal.h +48 -33
- data/dependencies/SDL_sound/SDL_sound_modplug.c +29 -21
- data/dependencies/SDL_sound/SDL_sound_mp3.c +13 -35
- data/dependencies/SDL_sound/SDL_sound_raw.c +15 -14
- data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
- data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +25 -34
- data/dependencies/SDL_sound/SDL_sound_wav.c +82 -86
- data/dependencies/SDL_sound/dr_flac.h +1281 -1845
- data/dependencies/SDL_sound/dr_mp3.h +617 -1035
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +4 -5
- data/dependencies/SDL_sound/libmodplug/load_ams.c +3 -6
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +1 -2
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
- data/dependencies/SDL_sound/libmodplug/modplug.h +1 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
- data/dependencies/SDL_sound/libmodplug/sndfile.c +0 -3
- data/dependencies/SDL_sound/libmodplug/sndmix.c +3 -7
- data/dependencies/SDL_sound/stb_vorbis.h +343 -397
- data/dependencies/mojoAL/AL/alc.h +2 -2
- data/dependencies/mojoAL/mojoal.c +1878 -2113
- data/dependencies/stb/stb_image.h +1381 -1192
- data/dependencies/stb/stb_image_write.h +129 -329
- data/dependencies/stb/stb_truetype.h +60 -304
- data/dependencies/utf8proc/utf8proc.c +75 -133
- data/dependencies/utf8proc/utf8proc.h +50 -131
- data/dependencies/utf8proc/utf8proc_data.h +15658 -16213
- data/ext/gosu-ffi/extconf.rb +28 -11
- data/ext/gosu-ffi/gosu-ffi.def +0 -3
- data/ffi/Gosu.cpp +29 -52
- data/ffi/Gosu.h +4 -4
- data/ffi/Gosu_Color.cpp +36 -80
- data/ffi/Gosu_FFI_internal.h +13 -12
- data/ffi/Gosu_Font.cpp +11 -16
- data/ffi/Gosu_Font.h +4 -4
- data/ffi/Gosu_Image.cpp +36 -69
- data/ffi/Gosu_Image.h +5 -16
- data/include/Gosu/Bitmap.hpp +1 -1
- data/include/Gosu/Color.hpp +4 -5
- data/include/Gosu/Graphics.hpp +0 -2
- data/include/Gosu/Image.hpp +1 -1
- data/include/Gosu/Math.hpp +5 -5
- data/include/Gosu/Utility.hpp +1 -27
- data/include/Gosu/Version.hpp +2 -2
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/channel.rb +0 -1
- data/lib/gosu/color.rb +13 -36
- data/lib/gosu/compat.rb +14 -106
- data/lib/gosu/constants.rb +24 -24
- data/lib/gosu/ffi.rb +13 -24
- data/lib/gosu/font.rb +13 -19
- data/lib/gosu/gosu.rb +61 -101
- data/lib/gosu/image.rb +34 -72
- data/lib/gosu/sample.rb +0 -1
- data/lib/gosu/song.rb +0 -1
- data/lib/gosu/text_input.rb +1 -15
- data/lib/gosu/window.rb +10 -31
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +0 -2
- data/src/Audio.cpp +16 -22
- data/src/AudioFileSDLSound.cpp +5 -5
- data/src/BinPacker.cpp +4 -5
- data/src/Bitmap.cpp +9 -16
- data/src/Buffer.cpp +14 -5
- data/src/ClipRectStack.hpp +83 -17
- data/src/Directories.cpp +1 -1
- data/src/DrawOp.hpp +17 -14
- data/src/DrawOpQueue.hpp +31 -25
- data/src/Font.cpp +1 -1
- data/src/GosuGLView.cpp +7 -1
- data/src/Graphics.cpp +25 -32
- data/src/GraphicsImpl.hpp +24 -0
- data/src/Image.cpp +2 -2
- data/src/Input.cpp +70 -66
- data/src/Macro.cpp +26 -43
- data/src/Macro.hpp +16 -22
- data/src/Math.cpp +7 -20
- data/src/OffScreenTarget.cpp +10 -3
- data/src/OpenGLContext.cpp +8 -7
- data/src/OpenGLContext.hpp +2 -2
- data/src/RenderState.hpp +54 -30
- data/src/Resolution.cpp +38 -48
- data/src/TexChunk.cpp +2 -2
- data/src/TextInput.cpp +9 -9
- data/src/Texture.cpp +1 -1
- data/src/TiledDrawable.cpp +7 -6
- data/src/TrueTypeFontUnix.cpp +9 -12
- data/src/Utility.cpp +26 -39
- data/src/UtilityWin.cpp +2 -6
- data/src/Window.cpp +34 -54
- metadata +93 -99
- data/dependencies/SDL/include/SDL3/SDL.h +0 -91
- data/dependencies/SDL/include/SDL3/SDL_assert.h +0 -710
- data/dependencies/SDL/include/SDL3/SDL_asyncio.h +0 -550
- data/dependencies/SDL/include/SDL3/SDL_atomic.h +0 -692
- data/dependencies/SDL/include/SDL3/SDL_audio.h +0 -2382
- data/dependencies/SDL/include/SDL3/SDL_begin_code.h +0 -553
- data/dependencies/SDL/include/SDL3/SDL_camera.h +0 -535
- data/dependencies/SDL/include/SDL3/SDL_clipboard.h +0 -331
- data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +0 -374
- data/dependencies/SDL/include/SDL3/SDL_dialog.h +0 -343
- data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +0 -234
- data/dependencies/SDL/include/SDL3/SDL_endian.h +0 -645
- data/dependencies/SDL/include/SDL3/SDL_error.h +0 -226
- data/dependencies/SDL/include/SDL3/SDL_events.h +0 -1651
- data/dependencies/SDL/include/SDL3/SDL_filesystem.h +0 -537
- data/dependencies/SDL/include/SDL3/SDL_gamepad.h +0 -1657
- data/dependencies/SDL/include/SDL3/SDL_gpu.h +0 -4637
- data/dependencies/SDL/include/SDL3/SDL_guid.h +0 -106
- data/dependencies/SDL/include/SDL3/SDL_haptic.h +0 -1461
- data/dependencies/SDL/include/SDL3/SDL_hidapi.h +0 -571
- data/dependencies/SDL/include/SDL3/SDL_hints.h +0 -5041
- data/dependencies/SDL/include/SDL3/SDL_init.h +0 -508
- data/dependencies/SDL/include/SDL3/SDL_intrin.h +0 -410
- data/dependencies/SDL/include/SDL3/SDL_iostream.h +0 -1379
- data/dependencies/SDL/include/SDL3/SDL_joystick.h +0 -1385
- data/dependencies/SDL/include/SDL3/SDL_keyboard.h +0 -615
- data/dependencies/SDL/include/SDL3/SDL_keycode.h +0 -348
- data/dependencies/SDL/include/SDL3/SDL_loadso.h +0 -145
- data/dependencies/SDL/include/SDL3/SDL_log.h +0 -541
- data/dependencies/SDL/include/SDL3/SDL_main.h +0 -704
- data/dependencies/SDL/include/SDL3/SDL_main_impl.h +0 -149
- data/dependencies/SDL/include/SDL3/SDL_mouse.h +0 -813
- data/dependencies/SDL/include/SDL3/SDL_mutex.h +0 -1117
- data/dependencies/SDL/include/SDL3/SDL_oldnames.h +0 -1339
- data/dependencies/SDL/include/SDL3/SDL_pen.h +0 -198
- data/dependencies/SDL/include/SDL3/SDL_pixels.h +0 -1441
- data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +0 -497
- data/dependencies/SDL/include/SDL3/SDL_process.h +0 -441
- data/dependencies/SDL/include/SDL3/SDL_properties.h +0 -572
- data/dependencies/SDL/include/SDL3/SDL_rect.h +0 -528
- data/dependencies/SDL/include/SDL3/SDL_render.h +0 -3034
- data/dependencies/SDL/include/SDL3/SDL_revision.h +0 -56
- data/dependencies/SDL/include/SDL3/SDL_sensor.h +0 -321
- data/dependencies/SDL/include/SDL3/SDL_stdinc.h +0 -6186
- data/dependencies/SDL/include/SDL3/SDL_storage.h +0 -686
- data/dependencies/SDL/include/SDL3/SDL_surface.h +0 -1769
- data/dependencies/SDL/include/SDL3/SDL_system.h +0 -840
- data/dependencies/SDL/include/SDL3/SDL_test_log.h +0 -83
- data/dependencies/SDL/include/SDL3/SDL_thread.h +0 -602
- data/dependencies/SDL/include/SDL3/SDL_time.h +0 -249
- data/dependencies/SDL/include/SDL3/SDL_timer.h +0 -454
- data/dependencies/SDL/include/SDL3/SDL_touch.h +0 -184
- data/dependencies/SDL/include/SDL3/SDL_tray.h +0 -544
- data/dependencies/SDL/include/SDL3/SDL_version.h +0 -198
- data/dependencies/SDL/include/SDL3/SDL_video.h +0 -3497
- data/dependencies/SDL/include/SDL3/SDL_vulkan.h +0 -287
- data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
- data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +0 -755
- data/lib/SDL3.dll +0 -0
- data/lib64/SDL3.dll +0 -0
- data/src/ClipRectStack.cpp +0 -38
- /data/dependencies/SDL/include/{SDL3/SDL_opengl_glext.h → SDL_opengl_glext.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2.h → SDL_opengles2_gl2.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2ext.h → SDL_opengles2_gl2ext.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2platform.h → SDL_opengles2_gl2platform.h} +0 -0
- /data/dependencies/SDL/include/{SDL3/SDL_opengles2_khrplatform.h → SDL_opengles2_khrplatform.h} +0 -0
data/src/Graphics.cpp
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#include <Gosu/Bitmap.hpp>
|
|
1
2
|
#include <Gosu/Graphics.hpp>
|
|
2
3
|
#include <Gosu/Image.hpp>
|
|
3
4
|
#include <Gosu/Utility.hpp>
|
|
@@ -7,6 +8,7 @@
|
|
|
7
8
|
#include "Macro.hpp"
|
|
8
9
|
#include "OffScreenTarget.hpp"
|
|
9
10
|
#include "OpenGLContext.hpp"
|
|
11
|
+
#include <algorithm>
|
|
10
12
|
#include <memory>
|
|
11
13
|
|
|
12
14
|
namespace Gosu
|
|
@@ -105,6 +107,9 @@ Gosu::Viewport::Viewport(int phys_width, int phys_height)
|
|
|
105
107
|
|
|
106
108
|
Gosu::Viewport::~Viewport()
|
|
107
109
|
{
|
|
110
|
+
if (current_viewport_pointer == this) {
|
|
111
|
+
current_viewport_pointer = nullptr;
|
|
112
|
+
}
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
int Gosu::Viewport::width() const
|
|
@@ -133,15 +138,6 @@ void Gosu::Viewport::set_resolution(int virtual_width, int virtual_height,
|
|
|
133
138
|
m_impl->update_base_transform();
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
Gosu::Cleanup Gosu::Viewport::make_current()
|
|
137
|
-
{
|
|
138
|
-
auto result = finally([previous = current_viewport_pointer] {
|
|
139
|
-
current_viewport_pointer = previous;
|
|
140
|
-
});
|
|
141
|
-
current_viewport_pointer = this;
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
141
|
void Gosu::Viewport::frame(const std::function<void()>& f)
|
|
146
142
|
{
|
|
147
143
|
if (current_viewport_pointer != nullptr) {
|
|
@@ -170,7 +166,7 @@ void Gosu::Viewport::frame(const std::function<void()>& f)
|
|
|
170
166
|
glClearColor(0, 0, 0, 1);
|
|
171
167
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
172
168
|
|
|
173
|
-
|
|
169
|
+
current_viewport_pointer = this;
|
|
174
170
|
|
|
175
171
|
f();
|
|
176
172
|
|
|
@@ -197,7 +193,7 @@ void Gosu::Viewport::frame(const std::function<void()>& f)
|
|
|
197
193
|
flush();
|
|
198
194
|
}
|
|
199
195
|
|
|
200
|
-
|
|
196
|
+
current_viewport_pointer = nullptr;
|
|
201
197
|
|
|
202
198
|
// Clear leftover transforms, clip rects etc.
|
|
203
199
|
if (queues.size() == 1) {
|
|
@@ -225,10 +221,14 @@ void Gosu::gl(const std::function<void()>& f)
|
|
|
225
221
|
throw std::logic_error("Custom OpenGL ES is not supported yet");
|
|
226
222
|
#else
|
|
227
223
|
Viewport& cg = current_viewport();
|
|
224
|
+
|
|
228
225
|
flush();
|
|
226
|
+
|
|
229
227
|
cg.m_impl->begin_gl();
|
|
230
|
-
|
|
228
|
+
|
|
231
229
|
f();
|
|
230
|
+
|
|
231
|
+
cg.m_impl->end_gl();
|
|
232
232
|
#endif
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -240,28 +240,24 @@ void Gosu::gl(Gosu::ZPos z, const std::function<void()>& f)
|
|
|
240
240
|
const auto wrapped_f = [f] {
|
|
241
241
|
Viewport& cg = current_viewport();
|
|
242
242
|
cg.m_impl->begin_gl();
|
|
243
|
-
const auto cleanup_gl = finally([&cg] { cg.m_impl->end_gl(); });
|
|
244
243
|
f();
|
|
244
|
+
cg.m_impl->end_gl();
|
|
245
245
|
};
|
|
246
246
|
current_queue().gl(wrapped_f, z);
|
|
247
247
|
#endif
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
void Gosu::clip_to(double x, double y, double width, double height,
|
|
250
|
+
void Gosu::clip_to(double x, double y, double width, double height,
|
|
251
|
+
const std::function<void()>& f)
|
|
251
252
|
{
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
viewport_height = current_viewport_pointer->m_impl->phys_height;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
current_queue().begin_clipping(x, y, width, height, viewport_height);
|
|
258
|
-
const auto cleanup_cliprect = finally([] { current_queue().end_clipping(); });
|
|
259
|
-
|
|
253
|
+
double screen_height = current_viewport().m_impl->phys_height;
|
|
254
|
+
current_queue().begin_clipping(x, y, width, height, screen_height);
|
|
260
255
|
f();
|
|
256
|
+
current_queue().end_clipping();
|
|
261
257
|
}
|
|
262
258
|
|
|
263
259
|
Gosu::Image Gosu::render(int width, int height, const std::function<void()>& f,
|
|
264
|
-
|
|
260
|
+
unsigned image_flags)
|
|
265
261
|
{
|
|
266
262
|
const OpenGLContext current_context;
|
|
267
263
|
|
|
@@ -284,15 +280,17 @@ Gosu::Image Gosu::render(int width, int height, const std::function<void()>& f,
|
|
|
284
280
|
Image result = OffScreenTarget(width, height, image_flags).render([&] {
|
|
285
281
|
#ifndef GOSU_IS_OPENGLES
|
|
286
282
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
287
|
-
const auto pop_attributes = finally([] { glPopAttrib(); });
|
|
288
283
|
#endif
|
|
289
284
|
glClearColor(0, 0, 0, 0);
|
|
290
285
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
291
286
|
glEnable(GL_BLEND);
|
|
292
287
|
queues.emplace_back(QM_RENDER_TO_TEXTURE);
|
|
293
|
-
const auto pop_queue = finally([&] { queues.pop_back(); });
|
|
294
288
|
f();
|
|
295
289
|
queues.back().perform_draw_ops_and_code();
|
|
290
|
+
queues.pop_back();
|
|
291
|
+
#ifndef GOSU_IS_OPENGLES
|
|
292
|
+
glPopAttrib();
|
|
293
|
+
#endif
|
|
296
294
|
});
|
|
297
295
|
|
|
298
296
|
// Restore previous matrix and glViewport.
|
|
@@ -306,29 +304,24 @@ Gosu::Image Gosu::render(int width, int height, const std::function<void()>& f,
|
|
|
306
304
|
Gosu::Image Gosu::record(int width, int height, const std::function<void()>& f)
|
|
307
305
|
{
|
|
308
306
|
queues.emplace_back(QM_RECORD_MACRO);
|
|
309
|
-
const auto pop_queue = finally([&] { queues.pop_back(); });
|
|
310
307
|
|
|
311
308
|
f();
|
|
312
309
|
|
|
313
310
|
std::unique_ptr<Drawable> result(new Macro(current_queue(), width, height));
|
|
311
|
+
queues.pop_back();
|
|
314
312
|
return Image(std::move(result));
|
|
315
313
|
}
|
|
316
314
|
|
|
317
315
|
void Gosu::transform(const Gosu::Transform& transform, const std::function<void()>& f)
|
|
318
316
|
{
|
|
319
317
|
current_queue().push_transform(transform);
|
|
320
|
-
const auto pop_transform = finally([&] { current_queue().pop_transform(); });
|
|
321
|
-
|
|
322
318
|
f();
|
|
319
|
+
current_queue().pop_transform();
|
|
323
320
|
}
|
|
324
321
|
|
|
325
322
|
void Gosu::draw_line(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
|
326
323
|
ZPos z, BlendMode mode)
|
|
327
324
|
{
|
|
328
|
-
if (current_queue().mode() == QM_RECORD_MACRO) {
|
|
329
|
-
throw std::logic_error("Drawing lines is not allowed while recording a macro");
|
|
330
|
-
}
|
|
331
|
-
|
|
332
325
|
DrawOp op;
|
|
333
326
|
op.render_state.mode = mode;
|
|
334
327
|
op.vertices_or_block_index = 2;
|
data/src/GraphicsImpl.hpp
CHANGED
|
@@ -13,6 +13,23 @@ namespace Gosu
|
|
|
13
13
|
struct RenderState;
|
|
14
14
|
class RenderStateManager;
|
|
15
15
|
|
|
16
|
+
const unsigned NO_CLIPPING = 0xffffffff;
|
|
17
|
+
|
|
18
|
+
// In various places in Gosu, width==NO_CLIPPING by convention means
|
|
19
|
+
// that no clipping should happen.
|
|
20
|
+
struct ClipRect
|
|
21
|
+
{
|
|
22
|
+
double x, y, width, height;
|
|
23
|
+
|
|
24
|
+
bool operator==(const ClipRect& other) const
|
|
25
|
+
{
|
|
26
|
+
// No clipping
|
|
27
|
+
return (width == NO_CLIPPING && other.width == NO_CLIPPING) ||
|
|
28
|
+
// Clipping, but same
|
|
29
|
+
(x == other.x && y == other.y && width == other.width && height == other.height);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
16
33
|
enum QueueMode
|
|
17
34
|
{
|
|
18
35
|
QM_RENDER_TO_SCREEN,
|
|
@@ -27,6 +44,7 @@ namespace Gosu
|
|
|
27
44
|
class DrawOpQueue;
|
|
28
45
|
typedef std::list<Transform> Transforms;
|
|
29
46
|
typedef std::list<DrawOpQueue> DrawOpQueueStack;
|
|
47
|
+
class Macro;
|
|
30
48
|
struct ArrayVertex
|
|
31
49
|
{
|
|
32
50
|
float tex_coords[2];
|
|
@@ -53,6 +71,12 @@ namespace Gosu
|
|
|
53
71
|
|
|
54
72
|
void schedule_draw_op(const DrawOp& op);
|
|
55
73
|
|
|
74
|
+
#ifdef GOSU_IS_IPHONE
|
|
75
|
+
int clip_rect_base_factor();
|
|
76
|
+
#else
|
|
77
|
+
inline int clip_rect_base_factor() { return 1; }
|
|
78
|
+
#endif
|
|
79
|
+
|
|
56
80
|
void register_frame();
|
|
57
81
|
|
|
58
82
|
inline std::string escape_markup(const std::string& text) {
|
data/src/Image.cpp
CHANGED
|
@@ -129,8 +129,8 @@ std::vector<Gosu::Image> Gosu::load_tiles(const Bitmap& bitmap, //
|
|
|
129
129
|
|
|
130
130
|
for (int y = 0; y < tiles_y; ++y) {
|
|
131
131
|
for (int x = 0; x < tiles_x; ++x) {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
images.emplace_back(
|
|
133
|
+
bitmap, Rect { x * tile_width, y * tile_height, tile_width, tile_height }, flags);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
data/src/Input.cpp
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
#include <Gosu/TextInput.hpp>
|
|
6
6
|
#include <Gosu/Utility.hpp>
|
|
7
7
|
|
|
8
|
-
#include <
|
|
8
|
+
#include <SDL.h>
|
|
9
9
|
#include <utf8proc.h>
|
|
10
10
|
|
|
11
11
|
#include <cstdlib>
|
|
@@ -32,7 +32,7 @@ static const unsigned NUM_BUTTONS = Gosu::GP_RANGE_END + 1;
|
|
|
32
32
|
static array<bool, NUM_BUTTONS> button_states = {false};
|
|
33
33
|
static array<double, NUM_AXES_PER_GAMEPAD * (Gosu::NUM_GAMEPADS + 1)> axis_states = {0.0};
|
|
34
34
|
static vector<shared_ptr<SDL_Joystick>> open_joysticks;
|
|
35
|
-
static vector<shared_ptr<
|
|
35
|
+
static vector<shared_ptr<SDL_GameController>> open_game_controllers;
|
|
36
36
|
// Stores joystick instance id or -1 if empty
|
|
37
37
|
static array<int, Gosu::NUM_GAMEPADS> gamepad_slots = {-1, -1, -1, -1};
|
|
38
38
|
|
|
@@ -65,7 +65,7 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
65
65
|
{
|
|
66
66
|
require_sdl_video();
|
|
67
67
|
|
|
68
|
-
SDL_InitSubSystem(
|
|
68
|
+
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
~Impl()
|
|
@@ -73,13 +73,12 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
73
73
|
open_joysticks.clear();
|
|
74
74
|
open_game_controllers.clear();
|
|
75
75
|
|
|
76
|
-
SDL_QuitSubSystem(
|
|
76
|
+
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
void update_mouse_position()
|
|
80
80
|
{
|
|
81
|
-
|
|
82
|
-
int window_x, window_y;
|
|
81
|
+
int x, y, window_x, window_y;
|
|
83
82
|
SDL_GetWindowPosition(window, &window_x, &window_y);
|
|
84
83
|
SDL_GetGlobalMouseState(&x, &y);
|
|
85
84
|
mouse_x = x - window_x;
|
|
@@ -88,9 +87,9 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
88
87
|
|
|
89
88
|
void set_mouse_position(double x, double y)
|
|
90
89
|
{
|
|
91
|
-
SDL_WarpMouseInWindow(window,
|
|
92
|
-
(x - mouse_offset_x) / mouse_scale_x,
|
|
93
|
-
(y - mouse_offset_y) / mouse_scale_y);
|
|
90
|
+
SDL_WarpMouseInWindow(window,
|
|
91
|
+
static_cast<int>((x - mouse_offset_x) / mouse_scale_x),
|
|
92
|
+
static_cast<int>((y - mouse_offset_y) / mouse_scale_y));
|
|
94
93
|
|
|
95
94
|
#if !defined(GOSU_IS_X)
|
|
96
95
|
// On systems where we have a working GetGlobalMouseState, we can warp the mouse and
|
|
@@ -106,23 +105,23 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
106
105
|
bool feed_sdl_event(const SDL_Event* e)
|
|
107
106
|
{
|
|
108
107
|
switch (e->type) {
|
|
109
|
-
case
|
|
110
|
-
case
|
|
111
|
-
if (e->key.repeat == 0 && e->key.scancode <= static_cast<int>(KB_RANGE_END)) {
|
|
112
|
-
enqueue_event(e->key.scancode, e->type ==
|
|
108
|
+
case SDL_KEYDOWN:
|
|
109
|
+
case SDL_KEYUP: {
|
|
110
|
+
if (e->key.repeat == 0 && e->key.keysym.scancode <= static_cast<int>(KB_RANGE_END)) {
|
|
111
|
+
enqueue_event(e->key.keysym.scancode, e->type == SDL_KEYDOWN);
|
|
113
112
|
return true;
|
|
114
113
|
}
|
|
115
114
|
break;
|
|
116
115
|
}
|
|
117
|
-
case
|
|
118
|
-
case
|
|
116
|
+
case SDL_MOUSEBUTTONDOWN:
|
|
117
|
+
case SDL_MOUSEBUTTONUP: {
|
|
119
118
|
if (e->button.button >= 1 && e->button.button <= 3) {
|
|
120
|
-
enqueue_event(MS_LEFT + e->button.button - 1, e->type ==
|
|
119
|
+
enqueue_event(MS_LEFT + e->button.button - 1, e->type == SDL_MOUSEBUTTONDOWN);
|
|
121
120
|
return true;
|
|
122
121
|
}
|
|
123
122
|
break;
|
|
124
123
|
}
|
|
125
|
-
case
|
|
124
|
+
case SDL_MOUSEWHEEL: {
|
|
126
125
|
if (e->wheel.y > 0) {
|
|
127
126
|
enqueue_event(MS_WHEEL_UP, true);
|
|
128
127
|
enqueue_event(MS_WHEEL_UP, false);
|
|
@@ -135,37 +134,41 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
135
134
|
}
|
|
136
135
|
break;
|
|
137
136
|
}
|
|
138
|
-
case
|
|
137
|
+
case SDL_JOYDEVICEADDED: {
|
|
139
138
|
if (available_gamepad_slot_index() == -1) {
|
|
140
139
|
break;
|
|
141
140
|
}
|
|
142
141
|
int gamepad_slot = -1;
|
|
143
142
|
int joystick_instance_id = -1;
|
|
144
|
-
int i = e->jdevice.which; //
|
|
143
|
+
int i = e->jdevice.which; // SDL2 device_index
|
|
145
144
|
|
|
146
|
-
if (
|
|
147
|
-
if (
|
|
145
|
+
if (SDL_IsGameController(i)) {
|
|
146
|
+
if (SDL_GameController *game_controller = SDL_GameControllerOpen(i)) {
|
|
148
147
|
gamepad_slot = available_gamepad_slot_index();
|
|
149
|
-
joystick_instance_id =
|
|
148
|
+
joystick_instance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(game_controller));
|
|
150
149
|
if (gamepad_instance_id_is_known(joystick_instance_id)) {
|
|
151
150
|
return true;
|
|
152
151
|
}
|
|
153
|
-
|
|
152
|
+
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
|
153
|
+
SDL_GameControllerSetPlayerIndex(game_controller, gamepad_slot);
|
|
154
|
+
#endif
|
|
154
155
|
open_game_controllers.emplace_back(
|
|
155
|
-
shared_ptr<
|
|
156
|
+
shared_ptr<SDL_GameController>(game_controller, SDL_GameControllerClose)
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
// ...but fall back on the good, old SDL_Joystick API.
|
|
160
|
-
else if (SDL_Joystick* joystick =
|
|
161
|
+
else if (SDL_Joystick* joystick = SDL_JoystickOpen(i)) {
|
|
161
162
|
gamepad_slot = available_gamepad_slot_index();
|
|
162
|
-
joystick_instance_id =
|
|
163
|
+
joystick_instance_id = SDL_JoystickInstanceID(joystick);
|
|
163
164
|
if (gamepad_instance_id_is_known(joystick_instance_id)) {
|
|
164
165
|
return true;
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
#if SDL_VERSION_ATLEAST(2, 0, 12)
|
|
168
|
+
SDL_JoystickSetPlayerIndex(joystick, gamepad_slot);
|
|
169
|
+
#endif
|
|
167
170
|
open_joysticks.emplace_back(
|
|
168
|
-
shared_ptr<SDL_Joystick>(joystick,
|
|
171
|
+
shared_ptr<SDL_Joystick>(joystick, SDL_JoystickClose)
|
|
169
172
|
);
|
|
170
173
|
}
|
|
171
174
|
|
|
@@ -176,7 +179,7 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
176
179
|
}
|
|
177
180
|
break;
|
|
178
181
|
}
|
|
179
|
-
case
|
|
182
|
+
case SDL_JOYDEVICEREMOVED: {
|
|
180
183
|
int gamepad_slot = gamepad_slot_index(e->jdevice.which);
|
|
181
184
|
if (gamepad_slot >= 0) {
|
|
182
185
|
enqueue_gamepad_connection_event(gamepad_slot, false, e->jdevice.which);
|
|
@@ -235,8 +238,8 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
235
238
|
int index = gamepad_slot_index(instance_id);
|
|
236
239
|
|
|
237
240
|
for (int i = 0; i < open_game_controllers.size(); i++) {
|
|
238
|
-
SDL_Joystick* joystick =
|
|
239
|
-
if (
|
|
241
|
+
SDL_Joystick* joystick = SDL_GameControllerGetJoystick(open_game_controllers[i].get());
|
|
242
|
+
if (SDL_JoystickInstanceID(joystick) == instance_id) {
|
|
240
243
|
open_game_controllers.erase(open_game_controllers.begin() + i);
|
|
241
244
|
gamepad_slots[index] = -1;
|
|
242
245
|
return;
|
|
@@ -244,7 +247,7 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
244
247
|
}
|
|
245
248
|
|
|
246
249
|
for (int i = 0; i < open_joysticks.size(); i++) {
|
|
247
|
-
if (
|
|
250
|
+
if (SDL_JoystickInstanceID(open_joysticks[i].get()) == instance_id) {
|
|
248
251
|
open_joysticks.erase(open_joysticks.begin() + i);
|
|
249
252
|
gamepad_slots[index] = -1;
|
|
250
253
|
return;
|
|
@@ -276,11 +279,11 @@ struct Gosu::Input::Impl : private Gosu::Noncopyable
|
|
|
276
279
|
|
|
277
280
|
// Poll data from SDL, using either of two API interfaces.
|
|
278
281
|
GamepadBuffer current_gamepad;
|
|
279
|
-
if (
|
|
280
|
-
current_gamepad = poll_game_controller(
|
|
282
|
+
if (SDL_GameController* game_controller = SDL_GameControllerFromInstanceID(gamepad_slots[i])) {
|
|
283
|
+
current_gamepad = poll_game_controller(game_controller);
|
|
281
284
|
}
|
|
282
285
|
else {
|
|
283
|
-
current_gamepad = poll_joystick(
|
|
286
|
+
current_gamepad = poll_joystick(SDL_JoystickFromInstanceID(gamepad_slots[i]));
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
int axis_offset = NUM_AXES_PER_GAMEPAD * (i + 1);
|
|
@@ -401,37 +404,37 @@ private:
|
|
|
401
404
|
event_queue.push_back(event);
|
|
402
405
|
}
|
|
403
406
|
|
|
404
|
-
GamepadBuffer poll_game_controller(
|
|
407
|
+
GamepadBuffer poll_game_controller(SDL_GameController* controller)
|
|
405
408
|
{
|
|
406
409
|
GamepadBuffer gamepad;
|
|
407
410
|
|
|
408
411
|
// Poll axes first.
|
|
409
412
|
gamepad.axes[GP_LEFT_STICK_X_AXIS] =
|
|
410
|
-
scale_axis(
|
|
413
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTX));
|
|
411
414
|
gamepad.axes[GP_LEFT_STICK_Y_AXIS] =
|
|
412
|
-
scale_axis(
|
|
415
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTY));
|
|
413
416
|
gamepad.axes[GP_RIGHT_STICK_X_AXIS] =
|
|
414
|
-
scale_axis(
|
|
417
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX));
|
|
415
418
|
gamepad.axes[GP_RIGHT_STICK_Y_AXIS] =
|
|
416
|
-
scale_axis(
|
|
419
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY));
|
|
417
420
|
gamepad.axes[GP_LEFT_TRIGGER_AXIS] =
|
|
418
|
-
scale_axis(
|
|
421
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERLEFT));
|
|
419
422
|
gamepad.axes[GP_RIGHT_TRIGGER_AXIS] =
|
|
420
|
-
scale_axis(
|
|
423
|
+
scale_axis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
|
|
421
424
|
|
|
422
425
|
gamepad.buttons[GP_DPAD_LEFT - GP_RANGE_BEGIN] =
|
|
423
|
-
|
|
426
|
+
SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
|
424
427
|
gamepad.buttons[GP_DPAD_RIGHT - GP_RANGE_BEGIN] =
|
|
425
|
-
|
|
428
|
+
SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
|
426
429
|
gamepad.buttons[GP_DPAD_UP - GP_RANGE_BEGIN] =
|
|
427
|
-
|
|
430
|
+
SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
|
428
431
|
gamepad.buttons[GP_DPAD_DOWN - GP_RANGE_BEGIN] =
|
|
429
|
-
|
|
432
|
+
SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
|
430
433
|
|
|
431
434
|
int button = 0;
|
|
432
|
-
for (; button <
|
|
435
|
+
for (; button < SDL_CONTROLLER_BUTTON_DPAD_UP; ++button) {
|
|
433
436
|
gamepad.buttons[GP_BUTTON_0 + button - GP_RANGE_BEGIN] =
|
|
434
|
-
|
|
437
|
+
SDL_GameControllerGetButton(controller, (SDL_GameControllerButton) button);
|
|
435
438
|
}
|
|
436
439
|
// Represent the triggers as buttons in addition to them being axes.
|
|
437
440
|
gamepad.buttons[GP_BUTTON_0 + button++ - GP_RANGE_BEGIN] =
|
|
@@ -448,37 +451,37 @@ private:
|
|
|
448
451
|
GamepadBuffer gamepad;
|
|
449
452
|
|
|
450
453
|
// Just guess that the first four axes are equivalent to two analog sticks.
|
|
451
|
-
int axes =
|
|
454
|
+
int axes = SDL_JoystickNumAxes(joystick);
|
|
452
455
|
if (axes > 0) {
|
|
453
456
|
gamepad.axes[GP_LEFT_STICK_X_AXIS] =
|
|
454
|
-
scale_axis(
|
|
457
|
+
scale_axis(SDL_JoystickGetAxis(joystick, 0));
|
|
455
458
|
}
|
|
456
459
|
if (axes > 1) {
|
|
457
460
|
gamepad.axes[GP_LEFT_STICK_Y_AXIS] =
|
|
458
|
-
scale_axis(
|
|
461
|
+
scale_axis(SDL_JoystickGetAxis(joystick, 1));
|
|
459
462
|
}
|
|
460
463
|
if (axes > 2) {
|
|
461
464
|
gamepad.axes[GP_RIGHT_STICK_X_AXIS] =
|
|
462
|
-
scale_axis(
|
|
465
|
+
scale_axis(SDL_JoystickGetAxis(joystick, 2));
|
|
463
466
|
}
|
|
464
467
|
if (axes > 3) {
|
|
465
468
|
gamepad.axes[GP_RIGHT_STICK_Y_AXIS] =
|
|
466
|
-
scale_axis(
|
|
469
|
+
scale_axis(SDL_JoystickGetAxis(joystick, 3));
|
|
467
470
|
}
|
|
468
471
|
|
|
469
472
|
// All hats are merged into the DPad.
|
|
470
|
-
int hats =
|
|
473
|
+
int hats = SDL_JoystickNumHats(joystick);
|
|
471
474
|
for (int hat = 0; hat < hats; ++hat) {
|
|
472
|
-
Uint8 value =
|
|
475
|
+
Uint8 value = SDL_JoystickGetHat(joystick, hat);
|
|
473
476
|
if (value & SDL_HAT_LEFT) gamepad.buttons[GP_DPAD_LEFT - GP_RANGE_BEGIN] = true;
|
|
474
477
|
if (value & SDL_HAT_RIGHT) gamepad.buttons[GP_DPAD_RIGHT - GP_RANGE_BEGIN] = true;
|
|
475
478
|
if (value & SDL_HAT_UP) gamepad.buttons[GP_DPAD_UP - GP_RANGE_BEGIN] = true;
|
|
476
479
|
if (value & SDL_HAT_DOWN) gamepad.buttons[GP_DPAD_DOWN - GP_RANGE_BEGIN] = true;
|
|
477
480
|
}
|
|
478
481
|
|
|
479
|
-
int buttons = min<int>(NUM_BUTTONS_PER_GAMEPAD - 4,
|
|
482
|
+
int buttons = min<int>(NUM_BUTTONS_PER_GAMEPAD - 4, SDL_JoystickNumButtons(joystick));
|
|
480
483
|
for (int button = 0; button < buttons; ++button) {
|
|
481
|
-
if (
|
|
484
|
+
if (SDL_JoystickGetButton(joystick, button)) {
|
|
482
485
|
gamepad.buttons[GP_BUTTON_0 + button - GP_RANGE_BEGIN] = true;
|
|
483
486
|
}
|
|
484
487
|
}
|
|
@@ -531,7 +534,8 @@ string Gosu::Input::id_to_char(Button btn)
|
|
|
531
534
|
|
|
532
535
|
// SDL_GetKeyName returns "Space" for this value, but we want the character value.
|
|
533
536
|
if (btn == KB_SPACE) return " ";
|
|
534
|
-
|
|
537
|
+
|
|
538
|
+
SDL_Keycode keycode = SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(btn));
|
|
535
539
|
if (keycode == SDLK_UNKNOWN) return "";
|
|
536
540
|
|
|
537
541
|
const char* name = SDL_GetKeyName(keycode);
|
|
@@ -555,14 +559,14 @@ Gosu::Button Gosu::Input::char_to_id(string ch)
|
|
|
555
559
|
require_sdl_video();
|
|
556
560
|
|
|
557
561
|
SDL_Keycode keycode = SDL_GetKeyFromName(ch.c_str());
|
|
558
|
-
return keycode == SDLK_UNKNOWN ? NO_BUTTON : Button(SDL_GetScancodeFromKey(keycode
|
|
562
|
+
return keycode == SDLK_UNKNOWN ? NO_BUTTON : Button(SDL_GetScancodeFromKey(keycode));
|
|
559
563
|
}
|
|
560
564
|
|
|
561
565
|
std::string Gosu::Input::button_name(Button btn)
|
|
562
566
|
{
|
|
563
567
|
require_sdl_video();
|
|
564
568
|
|
|
565
|
-
SDL_Keycode keycode = SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(btn)
|
|
569
|
+
SDL_Keycode keycode = SDL_GetKeyFromScancode(static_cast<SDL_Scancode>(btn));
|
|
566
570
|
return SDL_GetKeyName(keycode);
|
|
567
571
|
}
|
|
568
572
|
|
|
@@ -578,11 +582,11 @@ std::string Gosu::Input::gamepad_name(int index)
|
|
|
578
582
|
return "";
|
|
579
583
|
}
|
|
580
584
|
|
|
581
|
-
if (
|
|
582
|
-
return
|
|
585
|
+
if (SDL_GameController* game_controller = SDL_GameControllerFromInstanceID(instance_id)) {
|
|
586
|
+
return SDL_GameControllerName(game_controller);
|
|
583
587
|
}
|
|
584
|
-
else if (SDL_Joystick* joystick =
|
|
585
|
-
return
|
|
588
|
+
else if (SDL_Joystick* joystick = SDL_JoystickFromInstanceID(instance_id)) {
|
|
589
|
+
return SDL_JoystickName(joystick);
|
|
586
590
|
}
|
|
587
591
|
|
|
588
592
|
return "";
|
|
@@ -668,10 +672,10 @@ Gosu::TextInput* Gosu::Input::text_input() const
|
|
|
668
672
|
void Gosu::Input::set_text_input(TextInput* text_input)
|
|
669
673
|
{
|
|
670
674
|
if (pimpl->text_input && text_input == nullptr) {
|
|
671
|
-
SDL_StopTextInput(
|
|
675
|
+
SDL_StopTextInput();
|
|
672
676
|
}
|
|
673
677
|
else if (pimpl->text_input == nullptr && text_input) {
|
|
674
|
-
SDL_StartTextInput(
|
|
678
|
+
SDL_StartTextInput();
|
|
675
679
|
}
|
|
676
680
|
|
|
677
681
|
pimpl->text_input = text_input;
|