gosu 0.15.2 → 1.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- 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 +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +330 -127
- data/{src → dependencies/stb}/stb_image_write.h +156 -85
- data/{src → dependencies/stb}/stb_truetype.h +192 -69
- data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
- data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
- data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
- data/ext/gosu/extconf.rb +53 -39
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/{Gosu → include/Gosu}/Font.hpp +1 -1
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +39 -51
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +15 -4
- data/{Gosu → include/Gosu}/Version.hpp +3 -3
- data/{Gosu → include/Gosu}/Window.hpp +46 -34
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/patches.rb +0 -23
- data/lib/gosu/preview.rb +1 -3
- data/lib/gosu/swig_patches.rb +14 -12
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +112 -23
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +20 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/Font.cpp +3 -1
- data/src/Graphics.cpp +7 -4
- data/src/Image.cpp +13 -16
- data/src/Input.cpp +412 -164
- data/src/LargeImageData.cpp +1 -1
- data/src/MarkupParser.cpp +2 -1
- data/src/Resolution.cpp +8 -8
- data/src/RubyGosu.cxx +1017 -196
- data/src/RubyGosu.h +4 -2
- data/src/TexChunk.cpp +1 -1
- data/src/TextBuilder.cpp +3 -1
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +1 -1
- data/src/TrueTypeFontWin.cpp +3 -3
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +90 -62
- data/src/WindowUIKit.cpp +21 -9
- metadata +194 -65
- data/Gosu/AutoLink.hpp +0 -14
- data/Gosu/Bitmap.hpp +0 -113
- data/Gosu/Channel.h +0 -25
- data/Gosu/Color.h +0 -38
- data/Gosu/Font.h +0 -36
- data/Gosu/Gosu.h +0 -79
- data/Gosu/Image.h +0 -54
- data/Gosu/Sample.h +0 -19
- data/Gosu/Song.h +0 -24
- data/Gosu/TextInput.h +0 -30
- data/Gosu/Window.h +0 -61
- data/lib/gosu/zen.rb +0 -89
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/ChannelWrapper.cpp +0 -50
- data/src/ColorWrapper.cpp +0 -126
- data/src/Constants.cpp +0 -287
- data/src/FontWrapper.cpp +0 -74
- data/src/GosuWrapper.cpp +0 -232
- data/src/ImageWrapper.cpp +0 -168
- data/src/MPEGFile.hpp +0 -90
- data/src/OggFile.hpp +0 -92
- data/src/SampleWrapper.cpp +0 -30
- data/src/SndFile.hpp +0 -174
- data/src/SongWrapper.cpp +0 -52
- data/src/TextInputWrapper.cpp +0 -101
- data/src/WinMain.cpp +0 -64
- data/src/WindowWrapper.cpp +0 -289
data/src/RubyGosu.h
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* ----------------------------------------------------------------------------
|
2
2
|
* This file was automatically generated by SWIG (http://www.swig.org).
|
3
|
-
* Version 4.0
|
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,
|
31
|
+
SwigDirector_Window(VALUE self,int width,int height,unsigned int window_flags=Gosu::WF_WINDOWED,double update_interval=16.666666);
|
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
|
|
data/src/TexChunk.cpp
CHANGED
@@ -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(
|
123
|
+
clipped_bitmap.insert(-clip_left, -clip_top, original_bitmap);
|
124
124
|
bitmap = &clipped_bitmap;
|
125
125
|
}
|
126
126
|
|
data/src/TextBuilder.cpp
CHANGED
@@ -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)
|
data/src/Texture.cpp
CHANGED
@@ -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(
|
127
|
+
bitmap.insert(-int(x), -int(y), full_texture);
|
128
128
|
|
129
129
|
return bitmap;
|
130
130
|
#endif
|
data/src/TrueTypeFont.cpp
CHANGED
data/src/TrueTypeFontWin.cpp
CHANGED
@@ -32,9 +32,9 @@ const unsigned char* Gosu::ttf_data_by_name(const string& font_name, unsigned fo
|
|
32
32
|
LOGFONT logfont = {
|
33
33
|
0, 0, 0, 0,
|
34
34
|
(font_flags & Gosu::FF_BOLD) ? FW_BOLD : FW_NORMAL,
|
35
|
-
(font_flags & Gosu::FF_ITALIC) ? TRUE : FALSE,
|
36
|
-
(font_flags & Gosu::FF_UNDERLINE) ? TRUE : FALSE,
|
37
|
-
|
35
|
+
static_cast<BYTE>((font_flags & Gosu::FF_ITALIC) ? TRUE : FALSE),
|
36
|
+
static_cast<BYTE>((font_flags & Gosu::FF_UNDERLINE) ? TRUE : FALSE),
|
37
|
+
0 /* no strikethrough */,
|
38
38
|
ANSI_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
|
39
39
|
DEFAULT_PITCH
|
40
40
|
};
|
data/src/Utility.cpp
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#include <Gosu/Utility.hpp>
|
2
2
|
#include <Gosu/Platform.hpp>
|
3
3
|
|
4
|
-
#include
|
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(
|
48
|
+
bool Gosu::has_extension(string_view filename, string_view extension)
|
49
49
|
{
|
50
|
-
size_t ext_len =
|
50
|
+
size_t ext_len = extension.length();
|
51
51
|
if (ext_len > filename.length()) {
|
52
52
|
return false;
|
53
53
|
}
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
string_view::iterator filename_iter = filename.end();
|
56
|
+
string_view::iterator ext_iter = extension.end();
|
57
57
|
while (ext_len--) {
|
58
|
-
|
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
|
-
|
72
|
+
const char* env = getenv("LANG");
|
73
|
+
return env ? env : "en_US";
|
70
74
|
}
|
71
75
|
#endif
|
data/src/Window.cpp
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#include <Gosu/Platform.hpp>
|
2
2
|
#if !defined(GOSU_IS_IPHONE)
|
3
3
|
|
4
|
+
#if defined(GOSU_IS_WIN)
|
5
|
+
#include <windows.h>
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#include <Gosu/Gosu.hpp>
|
5
9
|
#include "GraphicsImpl.hpp"
|
6
10
|
#include <SDL.h>
|
@@ -22,8 +26,6 @@ namespace Gosu
|
|
22
26
|
throw runtime_error(operation + ": " + (error ? error : "(unknown error)"));
|
23
27
|
}
|
24
28
|
|
25
|
-
static void cleanup();
|
26
|
-
|
27
29
|
SDL_Window* shared_window()
|
28
30
|
{
|
29
31
|
static SDL_Window* window = nullptr;
|
@@ -32,14 +34,12 @@ namespace Gosu
|
|
32
34
|
throw_sdl_error("Could not initialize SDL Video");
|
33
35
|
}
|
34
36
|
|
35
|
-
atexit(cleanup);
|
36
|
-
|
37
37
|
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
|
38
|
-
|
38
|
+
|
39
39
|
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
40
40
|
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
41
41
|
#endif
|
42
|
-
|
42
|
+
|
43
43
|
window =
|
44
44
|
SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 64, 64, flags);
|
45
45
|
if (window == nullptr) {
|
@@ -58,27 +58,20 @@ namespace Gosu
|
|
58
58
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
59
59
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
60
60
|
#endif
|
61
|
-
|
61
|
+
|
62
62
|
context = SDL_GL_CreateContext(shared_window());
|
63
|
-
|
63
|
+
|
64
64
|
if (context == nullptr) {
|
65
65
|
throw_sdl_error("Could not create OpenGL context");
|
66
66
|
}
|
67
67
|
}
|
68
68
|
return context;
|
69
69
|
}
|
70
|
-
|
70
|
+
|
71
71
|
void ensure_current_context()
|
72
72
|
{
|
73
73
|
SDL_GL_MakeCurrent(shared_window(), shared_gl_context());
|
74
74
|
}
|
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
75
|
}
|
83
76
|
|
84
77
|
struct Gosu::Window::Impl
|
@@ -98,13 +91,11 @@ struct Gosu::Window::Impl
|
|
98
91
|
unique_ptr<Input> input;
|
99
92
|
};
|
100
93
|
|
101
|
-
Gosu::Window::Window(
|
102
|
-
bool resizable)
|
94
|
+
Gosu::Window::Window(int width, int height, unsigned window_flags, double update_interval)
|
103
95
|
: pimpl(new Impl)
|
104
96
|
{
|
105
|
-
|
106
|
-
|
107
|
-
#endif
|
97
|
+
set_borderless(window_flags & WF_BORDERLESS);
|
98
|
+
set_resizable(window_flags & WF_RESIZABLE);
|
108
99
|
|
109
100
|
// Even in fullscreen mode, temporarily show the window in windowed mode to centre it.
|
110
101
|
// This ensures that the window will be centered correctly when exiting fullscreen mode.
|
@@ -114,15 +105,16 @@ Gosu::Window::Window(unsigned width, unsigned height, bool fullscreen, double up
|
|
114
105
|
SDL_SetWindowPosition(shared_window(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
115
106
|
|
116
107
|
// Really enable fullscreen if desired.
|
117
|
-
resize(width, height,
|
108
|
+
resize(width, height, (window_flags & WF_FULLSCREEN));
|
118
109
|
|
119
110
|
SDL_GL_SetSwapInterval(1);
|
120
111
|
|
121
112
|
pimpl->update_interval = update_interval;
|
122
|
-
pimpl->resizable = resizable;
|
123
113
|
|
124
114
|
input().on_button_down = [this](Button button) { button_down(button); };
|
125
115
|
input().on_button_up = [this](Button button) { button_up(button); };
|
116
|
+
input().on_gamepad_connected = [this](int index) { gamepad_connected(index); };
|
117
|
+
input().on_gamepad_disconnected = [this](int index) { gamepad_disconnected(index); };
|
126
118
|
}
|
127
119
|
|
128
120
|
Gosu::Window::~Window()
|
@@ -130,12 +122,12 @@ Gosu::Window::~Window()
|
|
130
122
|
SDL_HideWindow(shared_window());
|
131
123
|
}
|
132
124
|
|
133
|
-
|
125
|
+
int Gosu::Window::width() const
|
134
126
|
{
|
135
127
|
return graphics().width();
|
136
128
|
}
|
137
129
|
|
138
|
-
|
130
|
+
int Gosu::Window::height() const
|
139
131
|
{
|
140
132
|
return graphics().height();
|
141
133
|
}
|
@@ -145,25 +137,20 @@ bool Gosu::Window::fullscreen() const
|
|
145
137
|
return pimpl->fullscreen;
|
146
138
|
}
|
147
139
|
|
148
|
-
|
149
|
-
{
|
150
|
-
return pimpl->resizable;
|
151
|
-
}
|
152
|
-
|
153
|
-
void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
140
|
+
void Gosu::Window::resize(int width, int height, bool fullscreen)
|
154
141
|
{
|
155
142
|
pimpl->fullscreen = fullscreen;
|
156
|
-
|
143
|
+
|
157
144
|
int actual_width = width;
|
158
145
|
int actual_height = height;
|
159
146
|
double scale_factor = 1.0;
|
160
147
|
double black_bar_width = 0;
|
161
148
|
double black_bar_height = 0;
|
162
|
-
|
149
|
+
|
163
150
|
if (fullscreen) {
|
164
151
|
actual_width = Gosu::screen_width(this);
|
165
152
|
actual_height = Gosu::screen_height(this);
|
166
|
-
|
153
|
+
|
167
154
|
if (resizable()) {
|
168
155
|
// Resizable fullscreen windows stubbornly follow the desktop resolution.
|
169
156
|
width = actual_width;
|
@@ -184,9 +171,9 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
184
171
|
}
|
185
172
|
}
|
186
173
|
else {
|
187
|
-
|
188
|
-
|
189
|
-
|
174
|
+
int max_width = Gosu::available_width(this);
|
175
|
+
int max_height = Gosu::available_height(this);
|
176
|
+
|
190
177
|
if (resizable()) {
|
191
178
|
// If the window is resizable, limit its size, without preserving the aspect ratio.
|
192
179
|
width = actual_width = min(width, max_width);
|
@@ -199,18 +186,18 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
199
186
|
actual_height = height * scale_factor;
|
200
187
|
}
|
201
188
|
}
|
202
|
-
|
189
|
+
|
203
190
|
SDL_SetWindowFullscreen(shared_window(), fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
204
191
|
if (!pimpl->resizing) {
|
205
192
|
SDL_SetWindowSize(shared_window(), actual_width, actual_height);
|
206
193
|
}
|
207
|
-
|
194
|
+
|
208
195
|
#if SDL_VERSION_ATLEAST(2, 0, 1)
|
209
196
|
SDL_GL_GetDrawableSize(shared_window(), &actual_width, &actual_height);
|
210
197
|
#endif
|
211
|
-
|
198
|
+
|
212
199
|
ensure_current_context();
|
213
|
-
|
200
|
+
|
214
201
|
if (!pimpl->graphics) {
|
215
202
|
pimpl->graphics.reset(new Graphics(actual_width, actual_height));
|
216
203
|
}
|
@@ -218,7 +205,7 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
218
205
|
pimpl->graphics->set_physical_resolution(actual_width, actual_height);
|
219
206
|
}
|
220
207
|
pimpl->graphics->set_resolution(width, height, black_bar_width, black_bar_height);
|
221
|
-
|
208
|
+
|
222
209
|
if (!pimpl->input) {
|
223
210
|
pimpl->input.reset(new Input(shared_window()));
|
224
211
|
}
|
@@ -226,6 +213,29 @@ void Gosu::Window::resize(unsigned width, unsigned height, bool fullscreen)
|
|
226
213
|
black_bar_width, black_bar_height);
|
227
214
|
}
|
228
215
|
|
216
|
+
bool Gosu::Window::resizable() const
|
217
|
+
{
|
218
|
+
return pimpl->resizable;
|
219
|
+
}
|
220
|
+
|
221
|
+
void Gosu::Window::set_resizable(bool resizable)
|
222
|
+
{
|
223
|
+
pimpl->resizable = resizable;
|
224
|
+
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
225
|
+
SDL_SetWindowResizable(shared_window(), resizable ? SDL_TRUE : SDL_FALSE);
|
226
|
+
#endif
|
227
|
+
}
|
228
|
+
|
229
|
+
bool Gosu::Window::borderless() const
|
230
|
+
{
|
231
|
+
return SDL_GetWindowFlags(shared_window()) & SDL_WINDOW_BORDERLESS;
|
232
|
+
}
|
233
|
+
|
234
|
+
void Gosu::Window::set_borderless(bool borderless)
|
235
|
+
{
|
236
|
+
SDL_SetWindowBordered(shared_window(), borderless ? SDL_FALSE : SDL_TRUE);
|
237
|
+
}
|
238
|
+
|
229
239
|
double Gosu::Window::update_interval() const
|
230
240
|
{
|
231
241
|
return pimpl->update_interval;
|
@@ -250,17 +260,35 @@ void Gosu::Window::set_caption(const string& caption)
|
|
250
260
|
void Gosu::Window::show()
|
251
261
|
{
|
252
262
|
unsigned long time_before_tick = milliseconds();
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
263
|
+
|
264
|
+
#ifdef GOSU_IS_WIN
|
265
|
+
// Try to convince Windows to only run this thread on the first core, to avoid timing glitches.
|
266
|
+
// (If we ever run into a situation where the first core is not available, we should start to
|
267
|
+
// use GetProcessAffinityMask to retrieve the allowed cores as a bitmask.)
|
268
|
+
DWORD_PTR previous_affinity = SetThreadAffinityMask(GetCurrentThread(), 1);
|
269
|
+
#endif
|
270
|
+
|
271
|
+
try {
|
272
|
+
while (tick()) {
|
273
|
+
// Sleep to keep this loop from eating 100% CPU.
|
274
|
+
unsigned long tick_time = milliseconds() - time_before_tick;
|
275
|
+
if (tick_time < update_interval()) {
|
276
|
+
sleep(update_interval() - tick_time);
|
277
|
+
}
|
278
|
+
|
279
|
+
time_before_tick = milliseconds();
|
259
280
|
}
|
260
|
-
|
261
|
-
|
281
|
+
} catch (...) {
|
282
|
+
#ifdef GOSU_IS_WIN
|
283
|
+
if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
|
284
|
+
#endif
|
285
|
+
throw;
|
262
286
|
}
|
263
|
-
|
287
|
+
|
288
|
+
#ifdef GOSU_IS_WIN
|
289
|
+
if (previous_affinity) SetThreadAffinityMask(GetCurrentThread(), previous_affinity);
|
290
|
+
#endif
|
291
|
+
|
264
292
|
pimpl->state = Impl::CLOSED;
|
265
293
|
}
|
266
294
|
|
@@ -270,7 +298,7 @@ bool Gosu::Window::tick()
|
|
270
298
|
pimpl->state = Impl::CLOSED;
|
271
299
|
return false;
|
272
300
|
}
|
273
|
-
|
301
|
+
|
274
302
|
if (pimpl->state == Impl::CLOSED) {
|
275
303
|
SDL_ShowWindow(shared_window());
|
276
304
|
pimpl->state = Impl::OPEN;
|
@@ -282,7 +310,7 @@ bool Gosu::Window::tick()
|
|
282
310
|
SDL_GL_GetDrawableSize(shared_window(), &width, &height);
|
283
311
|
graphics().set_physical_resolution(width, height);
|
284
312
|
}
|
285
|
-
|
313
|
+
|
286
314
|
SDL_Event e;
|
287
315
|
while (SDL_PollEvent(&e)) {
|
288
316
|
|
@@ -320,29 +348,29 @@ bool Gosu::Window::tick()
|
|
320
348
|
}
|
321
349
|
}
|
322
350
|
}
|
323
|
-
|
351
|
+
|
324
352
|
Song::update();
|
325
|
-
|
353
|
+
|
326
354
|
input().update();
|
327
|
-
|
355
|
+
|
328
356
|
update();
|
329
|
-
|
357
|
+
|
330
358
|
SDL_ShowCursor(needs_cursor());
|
331
|
-
|
359
|
+
|
332
360
|
if (needs_redraw()) {
|
333
361
|
ensure_current_context();
|
334
362
|
graphics().frame([&] {
|
335
363
|
draw();
|
336
364
|
FPS::register_frame();
|
337
365
|
});
|
338
|
-
|
366
|
+
|
339
367
|
SDL_GL_SwapWindow(shared_window());
|
340
368
|
}
|
341
|
-
|
369
|
+
|
342
370
|
if (pimpl->state == Impl::CLOSING) {
|
343
371
|
pimpl->state = Impl::CLOSED;
|
344
372
|
}
|
345
|
-
|
373
|
+
|
346
374
|
return pimpl->state == Impl::OPEN;
|
347
375
|
}
|
348
376
|
|
@@ -357,7 +385,7 @@ void Gosu::Window::button_down(Button button)
|
|
357
385
|
bool toggle_fullscreen;
|
358
386
|
|
359
387
|
// Default shortcuts for toggling fullscreen mode, see: https://github.com/gosu/gosu/issues/361
|
360
|
-
|
388
|
+
|
361
389
|
#ifdef GOSU_IS_MAC
|
362
390
|
// cmd+F and cmd+ctrl+F are both common shortcuts for toggling fullscreen mode on macOS.
|
363
391
|
toggle_fullscreen = button == KB_F &&
|