gosu 1.3.0 → 1.4.3
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 +108 -14
- data/dependencies/SDL/include/SDL_assert.h +81 -50
- data/dependencies/SDL/include/SDL_atomic.h +135 -35
- data/dependencies/SDL/include/SDL_audio.h +960 -355
- data/dependencies/SDL/include/SDL_bits.h +11 -6
- data/dependencies/SDL/include/SDL_blendmode.h +91 -14
- data/dependencies/SDL/include/SDL_clipboard.h +30 -7
- data/dependencies/SDL/include/SDL_config.h +277 -27
- data/dependencies/SDL/include/SDL_config_android.h +13 -38
- data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
- data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
- data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
- data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
- data/dependencies/SDL/include/SDL_config_psp.h +16 -37
- data/dependencies/SDL/include/SDL_config_windows.h +28 -91
- data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
- data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
- data/dependencies/SDL/include/SDL_copying.h +1 -1
- data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
- data/dependencies/SDL/include/SDL_egl.h +906 -280
- data/dependencies/SDL/include/SDL_endian.h +101 -47
- data/dependencies/SDL/include/SDL_error.h +70 -19
- data/dependencies/SDL/include/SDL_events.h +387 -79
- data/dependencies/SDL/include/SDL_filesystem.h +73 -64
- data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
- data/dependencies/SDL/include/SDL_gesture.h +36 -6
- data/dependencies/SDL/include/SDL_haptic.h +304 -210
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +1286 -897
- data/dependencies/SDL/include/SDL_joystick.h +577 -130
- data/dependencies/SDL/include/SDL_keyboard.h +162 -63
- data/dependencies/SDL/include/SDL_keycode.h +7 -5
- data/dependencies/SDL/include/SDL_loadso.h +42 -8
- data/dependencies/SDL/include/SDL_locale.h +34 -32
- data/dependencies/SDL/include/SDL_log.h +212 -19
- data/dependencies/SDL/include/SDL_main.h +72 -17
- data/dependencies/SDL/include/SDL_messagebox.h +70 -23
- data/dependencies/SDL/include/SDL_metal.h +27 -32
- data/dependencies/SDL/include/SDL_misc.h +19 -15
- data/dependencies/SDL/include/SDL_mouse.h +262 -110
- data/dependencies/SDL/include/SDL_mutex.h +286 -66
- data/dependencies/SDL/include/SDL_name.h +1 -1
- data/dependencies/SDL/include/SDL_opengl.h +1 -1
- data/dependencies/SDL/include/SDL_opengles.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2.h +2 -2
- data/dependencies/SDL/include/SDL_pixels.h +199 -34
- data/dependencies/SDL/include/SDL_platform.h +39 -2
- data/dependencies/SDL/include/SDL_power.h +23 -10
- data/dependencies/SDL/include/SDL_quit.h +1 -1
- data/dependencies/SDL/include/SDL_rect.h +78 -28
- data/dependencies/SDL/include/SDL_render.h +1204 -472
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_rwops.h +605 -33
- data/dependencies/SDL/include/SDL_scancode.h +1 -1
- data/dependencies/SDL/include/SDL_sensor.h +76 -42
- data/dependencies/SDL/include/SDL_shape.h +38 -27
- data/dependencies/SDL/include/SDL_stdinc.h +96 -24
- data/dependencies/SDL/include/SDL_surface.h +571 -139
- data/dependencies/SDL/include/SDL_system.h +339 -101
- data/dependencies/SDL/include/SDL_syswm.h +50 -20
- data/dependencies/SDL/include/SDL_test.h +1 -1
- data/dependencies/SDL/include/SDL_test_assert.h +2 -2
- data/dependencies/SDL/include/SDL_test_common.h +23 -6
- data/dependencies/SDL/include/SDL_test_compare.h +1 -1
- data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
- data/dependencies/SDL/include/SDL_test_font.h +3 -3
- data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
- data/dependencies/SDL/include/SDL_test_harness.h +6 -6
- data/dependencies/SDL/include/SDL_test_images.h +1 -1
- data/dependencies/SDL/include/SDL_test_log.h +1 -1
- data/dependencies/SDL/include/SDL_test_md5.h +1 -1
- data/dependencies/SDL/include/SDL_test_memory.h +1 -1
- data/dependencies/SDL/include/SDL_test_random.h +2 -2
- data/dependencies/SDL/include/SDL_thread.h +226 -128
- data/dependencies/SDL/include/SDL_timer.h +129 -22
- data/dependencies/SDL/include/SDL_touch.h +48 -8
- data/dependencies/SDL/include/SDL_types.h +1 -1
- data/dependencies/SDL/include/SDL_version.h +72 -46
- data/dependencies/SDL/include/SDL_video.h +1266 -460
- data/dependencies/SDL/include/SDL_vulkan.h +100 -161
- data/dependencies/SDL/include/begin_code.h +22 -1
- data/dependencies/SDL/include/close_code.h +1 -1
- 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 +104 -70
- data/dependencies/SDL_sound/SDL_sound.h +6 -6
- data/dependencies/SDL_sound/SDL_sound_aiff.c +32 -32
- data/dependencies/SDL_sound/SDL_sound_au.c +14 -14
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +6 -7
- data/dependencies/SDL_sound/SDL_sound_flac.c +28 -30
- data/dependencies/SDL_sound/SDL_sound_internal.h +21 -14
- data/dependencies/SDL_sound/SDL_sound_modplug.c +26 -28
- data/dependencies/SDL_sound/SDL_sound_mp3.c +20 -36
- data/dependencies/SDL_sound/SDL_sound_raw.c +15 -16
- data/dependencies/SDL_sound/SDL_sound_shn.c +11 -10
- data/dependencies/SDL_sound/SDL_sound_voc.c +20 -18
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +11 -9
- data/dependencies/SDL_sound/SDL_sound_wav.c +49 -43
- data/dependencies/SDL_sound/dr_flac.h +10925 -4466
- data/dependencies/SDL_sound/dr_mp3.h +2802 -844
- data/dependencies/SDL_sound/libmodplug/fastmix.c +63 -64
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
- data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
- data/dependencies/SDL_sound/libmodplug/load_amf.c +12 -7
- data/dependencies/SDL_sound/libmodplug/load_ams.c +103 -44
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
- data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
- data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +61 -61
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +94 -58
- data/dependencies/SDL_sound/libmodplug/load_med.c +20 -11
- data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +50 -19
- data/dependencies/SDL_sound/libmodplug/load_okt.c +59 -28
- data/dependencies/SDL_sound/libmodplug/load_psm.c +104 -79
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
- data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
- data/dependencies/SDL_sound/libmodplug/load_ult.c +4 -3
- data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
- data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
- data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
- data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +32 -19
- data/dependencies/SDL_sound/libmodplug/sndfile.c +76 -160
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
- data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
- data/dependencies/SDL_sound/stb_vorbis.h +504 -329
- data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
- data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
- data/dependencies/mojoAL/mojoal.c +4848 -0
- data/dependencies/stb/stb_image.h +208 -73
- data/dependencies/stb/stb_image_write.h +57 -23
- data/dependencies/stb/stb_truetype.h +345 -279
- data/dependencies/utf8proc/utf8proc.c +37 -18
- data/dependencies/utf8proc/utf8proc.h +17 -5
- data/dependencies/utf8proc/utf8proc_data.h +12012 -10089
- data/ext/gosu/extconf.rb +29 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Buttons.hpp +103 -103
- data/include/Gosu/Color.hpp +19 -11
- data/include/Gosu/Directories.hpp +31 -24
- data/include/Gosu/Font.hpp +42 -44
- data/include/Gosu/Gosu.hpp +5 -8
- data/include/Gosu/Graphics.hpp +58 -71
- data/include/Gosu/GraphicsBase.hpp +26 -33
- data/include/Gosu/IO.hpp +0 -3
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/Math.hpp +0 -3
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Timing.hpp +2 -8
- data/include/Gosu/Version.hpp +2 -2
- data/include/Gosu/Window.hpp +71 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +24 -37
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/src/Audio.cpp +88 -86
- data/src/AudioFile.hpp +6 -6
- data/src/AudioFileAudioToolbox.cpp +1 -1
- data/src/AudioFileSDLSound.cpp +1 -1
- data/src/AudioImpl.cpp +0 -7
- data/src/AudioImpl.hpp +6 -8
- data/src/BitmapIO.cpp +23 -22
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +12 -9
- data/src/DirectoriesApple.cpp +25 -24
- data/src/DirectoriesUnix.cpp +14 -12
- data/src/DirectoriesWin.cpp +26 -30
- data/src/EmptyImageData.hpp +15 -17
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +59 -54
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +41 -47
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +108 -101
- data/src/LargeImageData.hpp +17 -15
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +35 -37
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/Resolution.cpp +12 -7
- data/src/RubyGosu.cxx +11 -39
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +37 -37
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TimingApple.cpp +1 -7
- data/src/TimingUnix.cpp +0 -6
- data/src/TimingWin.cpp +0 -6
- data/src/TrueTypeFont.cpp +107 -107
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +19 -22
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Window.cpp +97 -87
- data/src/WindowUIKit.cpp +46 -49
- metadata +7 -17
- data/dependencies/SDL/include/SDL_config_os2.h +0 -188
- data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
- data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
- data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
- data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
- data/dependencies/al_soft/AL/alext.h +0 -585
- data/dependencies/al_soft/AL/efx-creative.h +0 -3
- data/dependencies/al_soft/AL/efx-presets.h +0 -402
- data/dependencies/al_soft/AL/efx.h +0 -762
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib64/OpenAL32.dll +0 -0
data/src/Color.cpp
CHANGED
@@ -1,35 +1,38 @@
|
|
1
1
|
#include <Gosu/Color.hpp>
|
2
2
|
#include <Gosu/Math.hpp>
|
3
|
-
#include <cmath>
|
4
3
|
#include <algorithm>
|
4
|
+
#include <cmath>
|
5
5
|
|
6
6
|
namespace
|
7
7
|
{
|
8
|
-
struct HSV
|
9
|
-
|
8
|
+
struct HSV
|
9
|
+
{
|
10
|
+
double h, s, v;
|
11
|
+
};
|
12
|
+
|
10
13
|
HSV color_to_hsv(const Gosu::Color& c)
|
11
14
|
{
|
12
15
|
double r = c.red / 255.0;
|
13
16
|
double g = c.green / 255.0;
|
14
17
|
double b = c.blue / 255.0;
|
15
|
-
|
18
|
+
|
16
19
|
double min = std::min(std::min(r, g), b);
|
17
20
|
double max = std::max(std::max(r, g), b);
|
18
21
|
double delta = max - min;
|
19
22
|
|
20
23
|
if (max == 0) {
|
21
|
-
HSV hsv = {
|
24
|
+
HSV hsv = {0, 0, 0};
|
22
25
|
return hsv;
|
23
26
|
}
|
24
|
-
|
27
|
+
|
25
28
|
HSV hsv{};
|
26
29
|
|
27
30
|
// Value.
|
28
31
|
hsv.v = max;
|
29
|
-
|
32
|
+
|
30
33
|
// Saturation.
|
31
34
|
hsv.s = delta / max;
|
32
|
-
|
35
|
+
|
33
36
|
// Hue.
|
34
37
|
if (delta == 0) {
|
35
38
|
hsv.h = 0;
|
@@ -44,7 +47,7 @@ namespace
|
|
44
47
|
hsv.h = (r - g) / delta + 4;
|
45
48
|
}
|
46
49
|
hsv.h *= 60;
|
47
|
-
|
50
|
+
|
48
51
|
return hsv;
|
49
52
|
}
|
50
53
|
}
|
data/src/DirectoriesApple.cpp
CHANGED
@@ -4,65 +4,66 @@
|
|
4
4
|
#import <Gosu/Directories.hpp>
|
5
5
|
#import <Foundation/Foundation.h>
|
6
6
|
#import <unistd.h>
|
7
|
-
using namespace std;
|
8
7
|
|
9
8
|
void Gosu::use_resource_directory()
|
10
9
|
{
|
11
10
|
chdir(resource_prefix().c_str());
|
12
11
|
}
|
13
12
|
|
14
|
-
string Gosu::user_settings_prefix()
|
13
|
+
const std::string& Gosu::user_settings_prefix()
|
15
14
|
{
|
16
|
-
static string
|
15
|
+
static const std::string user_settings_prefix = [] {
|
17
16
|
@autoreleasepool {
|
18
17
|
NSString* library =
|
19
|
-
|
18
|
+
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)
|
19
|
+
.firstObject;
|
20
20
|
NSString* preferences = [library stringByAppendingPathComponent:@"Preferences"];
|
21
|
-
|
22
|
-
return string
|
21
|
+
|
22
|
+
return std::string{preferences.UTF8String ?: "."} + "/";
|
23
23
|
}
|
24
24
|
}();
|
25
|
-
return
|
25
|
+
return user_settings_prefix;
|
26
26
|
}
|
27
27
|
|
28
|
-
string Gosu::user_documents_prefix()
|
28
|
+
const std::string& Gosu::user_documents_prefix()
|
29
29
|
{
|
30
|
-
static string
|
30
|
+
static const std::string user_documents_prefix = [] {
|
31
31
|
@autoreleasepool {
|
32
32
|
NSString* documents =
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
|
34
|
+
.firstObject;
|
35
|
+
|
36
|
+
return std::string{documents.UTF8String ?: "."} + "/";
|
36
37
|
}
|
37
38
|
}();
|
38
|
-
return
|
39
|
+
return user_documents_prefix;
|
39
40
|
}
|
40
41
|
|
41
|
-
string Gosu::resource_prefix()
|
42
|
+
const std::string& Gosu::resource_prefix()
|
42
43
|
{
|
43
|
-
static string
|
44
|
+
static const std::string resource_prefix = [] {
|
44
45
|
@autoreleasepool {
|
45
46
|
NSString* resources = [NSBundle mainBundle].resourcePath;
|
46
|
-
return string
|
47
|
+
return std::string{resources.UTF8String ?: "."} + "/";
|
47
48
|
}
|
48
49
|
}();
|
49
|
-
return
|
50
|
+
return resource_prefix;
|
50
51
|
}
|
51
52
|
|
52
|
-
string Gosu::shared_resource_prefix()
|
53
|
+
const std::string& Gosu::shared_resource_prefix()
|
53
54
|
{
|
54
|
-
|
55
|
+
#ifdef GOSU_IS_IPHONE
|
55
56
|
return resource_prefix();
|
56
|
-
|
57
|
-
static string
|
57
|
+
#else
|
58
|
+
static const std::string shared_resource_prefix = [] {
|
58
59
|
@autoreleasepool {
|
59
60
|
NSString* bundle_path = [NSBundle mainBundle].bundlePath;
|
60
61
|
NSString* containing_path = [bundle_path stringByDeletingLastPathComponent];
|
61
|
-
return string
|
62
|
+
return std::string{containing_path.UTF8String ?: "."};
|
62
63
|
}
|
63
64
|
}();
|
64
|
-
return
|
65
|
-
|
65
|
+
return shared_resource_prefix;
|
66
|
+
#endif
|
66
67
|
}
|
67
68
|
|
68
69
|
#endif
|
data/src/DirectoriesUnix.cpp
CHANGED
@@ -7,13 +7,11 @@
|
|
7
7
|
#include <pwd.h>
|
8
8
|
#include <sys/types.h>
|
9
9
|
#include <unistd.h>
|
10
|
-
using namespace std;
|
11
10
|
|
12
|
-
static string home_dir()
|
11
|
+
static std::string home_dir()
|
13
12
|
{
|
14
13
|
passwd* pwd = getpwuid(geteuid());
|
15
|
-
|
16
|
-
return pwd->pw_dir;
|
14
|
+
return pwd && pwd->pw_dir ? pwd->pw_dir : ".";
|
17
15
|
}
|
18
16
|
|
19
17
|
void Gosu::use_resource_directory()
|
@@ -21,24 +19,28 @@ void Gosu::use_resource_directory()
|
|
21
19
|
// Do nothing, we expect the user to have the correct cwd on Linux.
|
22
20
|
}
|
23
21
|
|
24
|
-
string Gosu::resource_prefix()
|
22
|
+
const std::string& Gosu::resource_prefix()
|
25
23
|
{
|
26
|
-
|
24
|
+
static const std::string empty;
|
25
|
+
return empty;
|
27
26
|
}
|
28
27
|
|
29
|
-
string Gosu::shared_resource_prefix()
|
28
|
+
const std::string& Gosu::shared_resource_prefix()
|
30
29
|
{
|
31
|
-
|
30
|
+
static const std::string empty;
|
31
|
+
return empty;
|
32
32
|
}
|
33
33
|
|
34
|
-
string Gosu::user_settings_prefix()
|
34
|
+
const std::string& Gosu::user_settings_prefix()
|
35
35
|
{
|
36
|
-
|
36
|
+
static const std::string user_settings_prefix = home_dir() + "/.";
|
37
|
+
return user_settings_prefix;
|
37
38
|
}
|
38
39
|
|
39
|
-
string Gosu::user_documents_prefix()
|
40
|
+
const std::string& Gosu::user_documents_prefix()
|
40
41
|
{
|
41
|
-
|
42
|
+
static const std::string user_documents_prefix = home_dir() + "/";
|
43
|
+
return user_documents_prefix;
|
42
44
|
}
|
43
45
|
|
44
46
|
#endif
|
data/src/DirectoriesWin.cpp
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
#include <Gosu/Platform.hpp>
|
2
2
|
#if defined(GOSU_IS_WIN)
|
3
3
|
|
4
|
-
#include "WinUtility.hpp"
|
5
4
|
#include <Gosu/Directories.hpp>
|
6
5
|
#include <Gosu/Utility.hpp>
|
6
|
+
#include "WinUtility.hpp"
|
7
7
|
#include <cwchar>
|
8
|
-
#include <stdexcept>
|
9
8
|
#include <shlobj.h>
|
10
|
-
|
9
|
+
#include <stdexcept>
|
11
10
|
|
12
|
-
static string special_folder_path(int csidl)
|
11
|
+
static std::string special_folder_path(int csidl)
|
13
12
|
{
|
14
13
|
WCHAR buf[MAX_PATH + 2];
|
15
|
-
if (FAILED(SHGetFolderPathW(nullptr, csidl | CSIDL_FLAG_CREATE, nullptr, 0, buf)))
|
16
|
-
throw runtime_error
|
17
|
-
|
18
|
-
size_t len = wcslen(buf);
|
14
|
+
if (FAILED(SHGetFolderPathW(nullptr, csidl | CSIDL_FLAG_CREATE, nullptr, 0, buf)))
|
15
|
+
throw std::runtime_error{"Error getting special folder path"};
|
16
|
+
size_t len = std::wcslen(buf);
|
19
17
|
if (buf[len - 1] != L'\\') {
|
20
18
|
buf[len] = L'\\';
|
21
19
|
buf[len + 1] = 0;
|
@@ -23,16 +21,12 @@ static string special_folder_path(int csidl)
|
|
23
21
|
return Gosu::utf16_to_utf8(buf);
|
24
22
|
}
|
25
23
|
|
26
|
-
|
24
|
+
std::string exe_filename()
|
27
25
|
{
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"getting the module filename");
|
33
|
-
result = Gosu::utf16_to_utf8(buffer);
|
34
|
-
}
|
35
|
-
return result;
|
26
|
+
WCHAR buffer[MAX_PATH * 2];
|
27
|
+
Gosu::winapi_check(GetModuleFileNameW(nullptr, buffer, MAX_PATH * 2),
|
28
|
+
"getting the module filename");
|
29
|
+
return Gosu::utf16_to_utf8(buffer);
|
36
30
|
}
|
37
31
|
|
38
32
|
void Gosu::use_resource_directory()
|
@@ -40,30 +34,32 @@ void Gosu::use_resource_directory()
|
|
40
34
|
SetCurrentDirectory(utf8_to_utf16(resource_prefix()).c_str());
|
41
35
|
}
|
42
36
|
|
43
|
-
string Gosu::resource_prefix()
|
37
|
+
const std::string& Gosu::resource_prefix()
|
44
38
|
{
|
45
|
-
static string
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
result
|
50
|
-
}
|
51
|
-
return
|
39
|
+
static const std::string resource_prefix = [] {
|
40
|
+
std::string result = exe_filename();
|
41
|
+
const auto last_delim = result.find_last_of("\\/");
|
42
|
+
result.resize(last_delim == std::string::npos ? 0 : last_delim + 1);
|
43
|
+
return result;
|
44
|
+
}();
|
45
|
+
return resource_prefix;
|
52
46
|
}
|
53
47
|
|
54
|
-
string Gosu::shared_resource_prefix()
|
48
|
+
const std::string& Gosu::shared_resource_prefix()
|
55
49
|
{
|
56
50
|
return resource_prefix();
|
57
51
|
}
|
58
52
|
|
59
|
-
string Gosu::user_settings_prefix()
|
53
|
+
const std::string& Gosu::user_settings_prefix()
|
60
54
|
{
|
61
|
-
|
55
|
+
static const std::string user_settings_prefix = special_folder_path(CSIDL_APPDATA);
|
56
|
+
return user_settings_prefix;
|
62
57
|
}
|
63
58
|
|
64
|
-
string Gosu::user_documents_prefix()
|
59
|
+
const std::string& Gosu::user_documents_prefix()
|
65
60
|
{
|
66
|
-
|
61
|
+
static const std::string user_documents_prefix = special_folder_path(CSIDL_PERSONAL);
|
62
|
+
return user_documents_prefix;
|
67
63
|
}
|
68
64
|
|
69
65
|
#endif
|
data/src/EmptyImageData.hpp
CHANGED
@@ -8,43 +8,41 @@ namespace Gosu
|
|
8
8
|
class EmptyImageData : public ImageData
|
9
9
|
{
|
10
10
|
public:
|
11
|
-
int width() const override
|
11
|
+
int width() const override //
|
12
12
|
{
|
13
13
|
return 0;
|
14
14
|
}
|
15
|
-
|
16
|
-
int height() const override
|
15
|
+
|
16
|
+
int height() const override //
|
17
17
|
{
|
18
18
|
return 0;
|
19
19
|
}
|
20
|
-
|
21
|
-
void draw(double, double, Color,
|
22
|
-
double, double, Color,
|
23
|
-
double, double, Color,
|
24
|
-
double, double, Color,
|
20
|
+
|
21
|
+
void draw(double, double, Color, double, double, Color, //
|
22
|
+
double, double, Color, double, double, Color, //
|
25
23
|
ZPos, BlendMode) const override
|
26
24
|
{
|
27
25
|
}
|
28
|
-
|
29
|
-
GLTexInfo* gl_tex_info() const override
|
26
|
+
|
27
|
+
GLTexInfo* gl_tex_info() const override //
|
30
28
|
{
|
31
29
|
return nullptr;
|
32
30
|
}
|
33
|
-
|
34
|
-
Bitmap to_bitmap() const override
|
31
|
+
|
32
|
+
Bitmap to_bitmap() const override //
|
35
33
|
{
|
36
34
|
return Bitmap();
|
37
35
|
}
|
38
|
-
|
39
|
-
|
36
|
+
|
37
|
+
std::unique_ptr<ImageData> subimage(int, int, int, int) const override //
|
40
38
|
{
|
41
39
|
return nullptr;
|
42
40
|
}
|
43
|
-
|
44
|
-
|
41
|
+
|
42
|
+
void insert(const Bitmap&, int x, int y) override //
|
45
43
|
{
|
46
44
|
}
|
47
|
-
|
45
|
+
|
48
46
|
static const std::shared_ptr<EmptyImageData>& instance_ptr()
|
49
47
|
{
|
50
48
|
static std::shared_ptr<EmptyImageData> instance = std::make_shared<EmptyImageData>();
|
data/src/FileUnix.cpp
CHANGED
data/src/FileWin.cpp
CHANGED
data/src/Font.cpp
CHANGED
@@ -1,35 +1,32 @@
|
|
1
|
-
#include "MarkupParser.hpp"
|
2
|
-
#include "GraphicsImpl.hpp"
|
3
1
|
#include <Gosu/Font.hpp>
|
4
2
|
#include <Gosu/Graphics.hpp>
|
5
3
|
#include <Gosu/Image.hpp>
|
6
4
|
#include <Gosu/Math.hpp>
|
7
5
|
#include <Gosu/Text.hpp>
|
8
6
|
#include <Gosu/Utility.hpp>
|
9
|
-
|
10
|
-
#include
|
11
|
-
|
7
|
+
#include "GraphicsImpl.hpp"
|
8
|
+
#include "MarkupParser.hpp"
|
12
9
|
#include <array>
|
13
|
-
#include <cassert>
|
14
10
|
#include <map>
|
15
11
|
#include <stdexcept>
|
16
|
-
|
12
|
+
#include <utf8proc.h>
|
17
13
|
|
18
14
|
static const int FONT_RENDER_SCALE = 2;
|
19
15
|
|
20
|
-
struct Gosu::Font::Impl
|
16
|
+
struct Gosu::Font::Impl : Gosu::Noncopyable
|
21
17
|
{
|
22
|
-
string name;
|
18
|
+
std::string name;
|
23
19
|
int height;
|
24
20
|
unsigned base_flags;
|
21
|
+
unsigned image_flags;
|
25
22
|
|
26
23
|
// The most common characters are stored directly in an array for maximum performance.
|
27
24
|
// (This is the start of the Basic Multilingual Plane, up until the part where right-to-left
|
28
25
|
// languages begin, which don't really work with Gosu yet.)
|
29
|
-
array<array<Image, 0x58f>, FF_COMBINATIONS> fast_glyphs;
|
26
|
+
std::array<std::array<Image, 0x58f>, FF_COMBINATIONS> fast_glyphs;
|
30
27
|
// Everything else is looked up through a map...
|
31
|
-
array<map<utf8proc_int32_t, Image>, FF_COMBINATIONS> other_glyphs;
|
32
|
-
|
28
|
+
std::array<std::map<utf8proc_int32_t, Image>, FF_COMBINATIONS> other_glyphs;
|
29
|
+
|
33
30
|
Image& image(char32_t codepoint, unsigned font_flags)
|
34
31
|
{
|
35
32
|
Image* image;
|
@@ -39,98 +36,106 @@ struct Gosu::Font::Impl
|
|
39
36
|
else {
|
40
37
|
image = &other_glyphs[font_flags][codepoint];
|
41
38
|
}
|
42
|
-
|
39
|
+
|
43
40
|
// If this codepoint has not been rendered before, do it now.
|
44
41
|
if (image->width() == 0 && image->height() == 0) {
|
45
42
|
auto scaled_height = height * FONT_RENDER_SCALE;
|
46
|
-
|
47
|
-
|
43
|
+
// Optimization: Don't render higher-resolution versions if we use
|
44
|
+
// next neighbor interpolation anyway.
|
45
|
+
if (image_flags & IF_RETRO) scaled_height = height;
|
46
|
+
|
47
|
+
std::u32string string(1, codepoint);
|
48
48
|
Bitmap bitmap(scaled_height, scaled_height);
|
49
|
-
auto required_width = ceil(Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string,
|
50
|
-
|
49
|
+
auto required_width = ceil(Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name,
|
50
|
+
scaled_height, font_flags));
|
51
51
|
if (required_width > bitmap.width()) {
|
52
52
|
// If the character was wider than high, we need to render it again.
|
53
53
|
Bitmap(required_width, scaled_height).swap(bitmap);
|
54
|
-
Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string,
|
55
|
-
|
54
|
+
Gosu::draw_text(bitmap, 0, 0, Color::WHITE, string, name, scaled_height,
|
55
|
+
font_flags);
|
56
56
|
}
|
57
|
-
|
58
|
-
*image = Image(bitmap, 0, 0, required_width, scaled_height);
|
57
|
+
|
58
|
+
*image = Image(bitmap, 0, 0, required_width, scaled_height, image_flags);
|
59
59
|
}
|
60
|
-
|
60
|
+
|
61
61
|
return *image;
|
62
62
|
}
|
63
63
|
};
|
64
64
|
|
65
|
-
Gosu::Font::Font(int font_height, const string& font_name, unsigned font_flags)
|
66
|
-
:
|
65
|
+
Gosu::Font::Font(int font_height, const std::string& font_name, unsigned font_flags, unsigned image_flags)
|
66
|
+
: m_impl{new Impl}
|
67
67
|
{
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
m_impl->name = font_name;
|
69
|
+
m_impl->height = font_height;
|
70
|
+
m_impl->base_flags = font_flags;
|
71
|
+
m_impl->image_flags = image_flags;
|
71
72
|
}
|
72
73
|
|
73
|
-
const string& Gosu::Font::name() const
|
74
|
+
const std::string& Gosu::Font::name() const
|
74
75
|
{
|
75
|
-
return
|
76
|
+
return m_impl->name;
|
76
77
|
}
|
77
78
|
|
78
79
|
int Gosu::Font::height() const
|
79
80
|
{
|
80
|
-
return
|
81
|
+
return m_impl->height;
|
81
82
|
}
|
82
83
|
|
83
84
|
unsigned Gosu::Font::flags() const
|
84
85
|
{
|
85
|
-
return
|
86
|
+
return m_impl->base_flags;
|
87
|
+
}
|
88
|
+
|
89
|
+
unsigned Gosu::Font::image_flags() const
|
90
|
+
{
|
91
|
+
return m_impl->image_flags;
|
86
92
|
}
|
87
93
|
|
88
|
-
double Gosu::Font::text_width(const string& text) const
|
94
|
+
double Gosu::Font::text_width(const std::string& text) const
|
89
95
|
{
|
90
96
|
return markup_width(escape_markup(text));
|
91
97
|
}
|
92
98
|
|
93
|
-
double Gosu::Font::markup_width(const string& markup) const
|
99
|
+
double Gosu::Font::markup_width(const std::string& markup) const
|
94
100
|
{
|
95
101
|
double width = 0;
|
96
102
|
|
97
103
|
// Split the text into lines (split_words = false) because Font doesn't implement word-wrapping.
|
98
|
-
MarkupParser parser(
|
104
|
+
MarkupParser parser(m_impl->base_flags, false, [&](std::vector<FormattedString>&& line) {
|
99
105
|
double line_width = 0;
|
100
106
|
for (auto& part : line) {
|
101
107
|
for (auto codepoint : part.text) {
|
102
|
-
auto& image =
|
108
|
+
auto& image = m_impl->image(codepoint, part.flags);
|
103
109
|
double image_scale = 1.0 * height() / image.height();
|
104
110
|
line_width += image_scale * image.width();
|
105
111
|
}
|
106
112
|
}
|
107
|
-
width = max(width, line_width);
|
113
|
+
width = std::max(width, line_width);
|
108
114
|
});
|
109
115
|
parser.parse(markup);
|
110
|
-
|
116
|
+
|
111
117
|
return width;
|
112
118
|
}
|
113
119
|
|
114
|
-
void Gosu::Font::draw_text(const string& text, double x, double y, ZPos z,
|
120
|
+
void Gosu::Font::draw_text(const std::string& text, double x, double y, ZPos z, //
|
115
121
|
double scale_x, double scale_y, Color c, BlendMode mode) const
|
116
122
|
{
|
117
123
|
draw_markup(escape_markup(text), x, y, z, scale_x, scale_y, c, mode);
|
118
124
|
}
|
119
125
|
|
120
|
-
void Gosu::Font::draw_markup(const string& markup, double x, double y, ZPos z,
|
126
|
+
void Gosu::Font::draw_markup(const std::string& markup, double x, double y, ZPos z, //
|
121
127
|
double scale_x, double scale_y, Color c, BlendMode mode) const
|
122
128
|
{
|
123
129
|
double current_y = y;
|
124
|
-
|
130
|
+
|
125
131
|
// Split the text into lines (split_words = false) because Font doesn't implement word-wrapping.
|
126
|
-
MarkupParser parser(
|
132
|
+
MarkupParser parser(m_impl->base_flags, false, [&](std::vector<FormattedString>&& line) {
|
127
133
|
double current_x = x;
|
128
134
|
for (auto& part : line) {
|
129
135
|
for (auto codepoint : part.text) {
|
130
|
-
auto& image =
|
136
|
+
auto& image = m_impl->image(codepoint, part.flags);
|
131
137
|
double image_scale = 1.0 * height() / image.height();
|
132
|
-
image.draw(current_x, current_y, z,
|
133
|
-
image_scale * scale_x, image_scale * scale_y,
|
138
|
+
image.draw(current_x, current_y, z, image_scale * scale_x, image_scale * scale_y,
|
134
139
|
multiply(c, part.color), mode);
|
135
140
|
current_x += image_scale * scale_x * image.width();
|
136
141
|
}
|
@@ -140,23 +145,23 @@ void Gosu::Font::draw_markup(const string& markup, double x, double y, ZPos z,
|
|
140
145
|
parser.parse(markup);
|
141
146
|
}
|
142
147
|
|
143
|
-
void Gosu::Font::draw_text_rel(const string& text, double x, double y, ZPos z,
|
144
|
-
double rel_x, double rel_y, double scale_x, double scale_y,
|
148
|
+
void Gosu::Font::draw_text_rel(const std::string& text, double x, double y, ZPos z, //
|
149
|
+
double rel_x, double rel_y, double scale_x, double scale_y, //
|
145
150
|
Color c, BlendMode mode) const
|
146
151
|
{
|
147
152
|
if (rel_x) x -= text_width(text) * scale_x * rel_x;
|
148
153
|
if (rel_y) y -= height() * scale_y * rel_y;
|
149
|
-
|
154
|
+
|
150
155
|
draw_text(text, x, y, z, scale_x, scale_y, c, mode);
|
151
156
|
}
|
152
157
|
|
153
|
-
void Gosu::Font::draw_markup_rel(const string& markup, double x, double y, ZPos z,
|
158
|
+
void Gosu::Font::draw_markup_rel(const std::string& markup, double x, double y, ZPos z, //
|
154
159
|
double rel_x, double rel_y, double scale_x, double scale_y,
|
155
160
|
Color c, BlendMode mode) const
|
156
161
|
{
|
157
162
|
if (rel_x) x -= markup_width(markup) * scale_x * rel_x;
|
158
163
|
if (rel_y) y -= height() * scale_y * rel_y;
|
159
|
-
|
164
|
+
|
160
165
|
draw_markup(markup, x, y, z, scale_x, scale_y, c, mode);
|
161
166
|
}
|
162
167
|
|
@@ -164,14 +169,14 @@ void Gosu::Font::set_image(std::string codepoint, unsigned font_flags, const Gos
|
|
164
169
|
{
|
165
170
|
auto utc4 = utf8_to_composed_utc4(codepoint);
|
166
171
|
if (utc4.length() != 1) {
|
167
|
-
throw invalid_argument
|
172
|
+
throw std::invalid_argument{"Could not compose '" + codepoint + "' into single codepoint"};
|
168
173
|
}
|
169
|
-
|
170
|
-
if (utc4[0] <
|
171
|
-
|
174
|
+
|
175
|
+
if (utc4[0] < m_impl->fast_glyphs[font_flags].size()) {
|
176
|
+
m_impl->fast_glyphs[font_flags][utc4[0]] = image;
|
172
177
|
}
|
173
178
|
else {
|
174
|
-
|
179
|
+
m_impl->other_glyphs[font_flags][utc4[0]] = image;
|
175
180
|
}
|
176
181
|
}
|
177
182
|
|