gosu 1.1.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +1 -1
- 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 +83 -7
- data/dependencies/SDL_sound/SDL_sound.h +4 -4
- data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
- data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
- data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
- data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
- data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
- data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
- data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
- data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
- data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
- data/dependencies/SDL_sound/dr_flac.h +618 -220
- data/dependencies/SDL_sound/dr_mp3.h +263 -94
- data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -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 +11 -7
- data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
- 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 +45 -49
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
- data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
- data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
- data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
- data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
- 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 +2 -2
- 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 +24 -18
- data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
- 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 +508 -325
- 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 +4594 -0
- data/ext/gosu/extconf.rb +33 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Color.hpp +63 -107
- data/include/Gosu/Font.hpp +44 -50
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Graphics.hpp +64 -75
- data/include/Gosu/GraphicsBase.hpp +32 -39
- 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 +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Utility.hpp +10 -8
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +73 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +28 -37
- data/lib/gosu/swig_patches.rb +31 -3
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +9 -1
- data/src/Audio.cpp +86 -86
- data/src/AudioFile.hpp +6 -6
- data/src/AudioFileAudioToolbox.cpp +1 -1
- data/src/AudioFileSDLSound.cpp +1 -1
- data/src/AudioImpl.hpp +5 -5
- data/src/Bitmap.cpp +13 -13
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +62 -55
- data/src/EmptyImageData.hpp +16 -18
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +52 -57
- data/src/GosuViewController.cpp +2 -0
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +42 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +120 -113
- data/src/LargeImageData.hpp +18 -16
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +124 -169
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/RenderState.hpp +5 -5
- data/src/Resolution.cpp +114 -61
- data/src/RubyGosu.cxx +470 -501
- data/src/RubyGosu.h +3 -2
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +58 -59
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +108 -108
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +27 -23
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +82 -23
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +103 -86
- data/src/WindowUIKit.cpp +48 -51
- metadata +8 -20
- 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/UtilityApple.cpp +0 -16
- data/src/UtilityWin.cpp +0 -17
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.
|
3
|
+
* Version 4.0.2
|
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,int width,int height,unsigned int window_flags=Gosu::WF_WINDOWED,double update_interval=16.666666);
|
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();
|
@@ -37,6 +37,7 @@ public:
|
|
37
37
|
virtual void draw();
|
38
38
|
virtual bool needs_redraw() const;
|
39
39
|
virtual bool needs_cursor() const;
|
40
|
+
virtual void gain_focus();
|
40
41
|
virtual void lose_focus();
|
41
42
|
virtual void release_memory();
|
42
43
|
virtual void button_down(Gosu::Button arg0);
|
data/src/TexChunk.cpp
CHANGED
@@ -1,57 +1,66 @@
|
|
1
1
|
#include "TexChunk.hpp"
|
2
|
-
#include "DrawOpQueue.hpp"
|
3
|
-
#include "Texture.hpp"
|
4
2
|
#include <Gosu/Bitmap.hpp>
|
5
3
|
#include <Gosu/Graphics.hpp>
|
4
|
+
#include "DrawOpQueue.hpp"
|
5
|
+
#include "Texture.hpp"
|
6
6
|
#include <stdexcept>
|
7
7
|
|
8
|
-
using namespace std;
|
9
|
-
|
10
8
|
void Gosu::TexChunk::set_tex_info()
|
11
9
|
{
|
12
|
-
double width =
|
10
|
+
double width = m_texture->width(), height = m_texture->height();
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
m_info.tex_name = m_texture->tex_name();
|
13
|
+
m_info.left = m_x / width;
|
14
|
+
m_info.top = m_y / height;
|
15
|
+
m_info.right = (m_x + m_w) / width;
|
16
|
+
m_info.bottom = (m_y + m_h) / height;
|
19
17
|
}
|
20
18
|
|
21
|
-
Gosu::TexChunk::TexChunk(shared_ptr<Texture> texture, int x, int y, int w, int h, int padding)
|
22
|
-
:
|
19
|
+
Gosu::TexChunk::TexChunk(std::shared_ptr<Texture> texture, int x, int y, int w, int h, int padding)
|
20
|
+
: m_texture{move(texture)},
|
21
|
+
m_x{x},
|
22
|
+
m_y{y},
|
23
|
+
m_w{w},
|
24
|
+
m_h{h},
|
25
|
+
m_padding{padding}
|
23
26
|
{
|
24
27
|
set_tex_info();
|
25
28
|
}
|
26
29
|
|
27
30
|
Gosu::TexChunk::TexChunk(const TexChunk& parent, int x, int y, int w, int h)
|
28
|
-
:
|
31
|
+
: m_texture{parent.m_texture},
|
32
|
+
m_x{parent.m_x + x},
|
33
|
+
m_y{parent.m_y + y},
|
34
|
+
m_w{w},
|
35
|
+
m_h{h},
|
36
|
+
m_padding{0}
|
29
37
|
{
|
30
|
-
if (x < 0 || y < 0 || x + w > parent.
|
31
|
-
throw invalid_argument
|
38
|
+
if (x < 0 || y < 0 || x + w > parent.m_w || y + h > parent.m_h) {
|
39
|
+
throw std::invalid_argument{"subimage bounds exceed those of its parent"};
|
32
40
|
}
|
33
41
|
if (w <= 0 || h <= 0) {
|
34
|
-
throw invalid_argument
|
42
|
+
throw std::invalid_argument{"cannot create empty image"};
|
35
43
|
}
|
36
|
-
|
44
|
+
|
37
45
|
set_tex_info();
|
38
|
-
|
46
|
+
m_texture->block(m_x, m_y, m_w, m_h);
|
39
47
|
}
|
40
48
|
|
41
49
|
Gosu::TexChunk::~TexChunk()
|
42
50
|
{
|
43
|
-
|
51
|
+
m_texture->free(m_x - m_padding, m_y - m_padding, m_w + 2 * m_padding, m_h + 2 * m_padding);
|
44
52
|
}
|
45
53
|
|
46
|
-
void Gosu::TexChunk::draw(double x1, double y1, Color c1, double x2, double y2, Color c2,
|
47
|
-
|
54
|
+
void Gosu::TexChunk::draw(double x1, double y1, Color c1, double x2, double y2, Color c2, //
|
55
|
+
double x3, double y3, Color c3, double x4, double y4, Color c4, //
|
56
|
+
ZPos z, BlendMode mode) const
|
48
57
|
{
|
49
58
|
DrawOp op;
|
50
|
-
op.render_state.texture =
|
59
|
+
op.render_state.texture = m_texture;
|
51
60
|
op.render_state.mode = mode;
|
52
|
-
|
61
|
+
|
53
62
|
normalize_coordinates(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
54
|
-
|
63
|
+
|
55
64
|
op.vertices_or_block_index = 4;
|
56
65
|
op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
57
66
|
op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
@@ -63,34 +72,34 @@ void Gosu::TexChunk::draw(double x1, double y1, Color c1, double x2, double y2,
|
|
63
72
|
op.vertices[3] = DrawOp::Vertex(x3, y3, c3);
|
64
73
|
op.vertices[2] = DrawOp::Vertex(x4, y4, c4);
|
65
74
|
#endif
|
66
|
-
op.left =
|
67
|
-
op.top =
|
68
|
-
op.right =
|
69
|
-
op.bottom =
|
70
|
-
|
75
|
+
op.left = m_info.left;
|
76
|
+
op.top = m_info.top;
|
77
|
+
op.right = m_info.right;
|
78
|
+
op.bottom = m_info.bottom;
|
79
|
+
|
71
80
|
op.z = z;
|
72
81
|
Graphics::schedule_draw_op(op);
|
73
82
|
}
|
74
83
|
|
75
|
-
unique_ptr<Gosu::ImageData> Gosu::TexChunk::subimage(int x, int y, int width, int height) const
|
84
|
+
std::unique_ptr<Gosu::ImageData> Gosu::TexChunk::subimage(int x, int y, int width, int height) const
|
76
85
|
{
|
77
|
-
return unique_ptr<Gosu::ImageData>(new TexChunk(*this, x, y, width, height));
|
86
|
+
return std::unique_ptr<Gosu::ImageData>(new TexChunk(*this, x, y, width, height));
|
78
87
|
}
|
79
88
|
|
80
89
|
Gosu::Bitmap Gosu::TexChunk::to_bitmap() const
|
81
90
|
{
|
82
|
-
return
|
91
|
+
return m_texture->to_bitmap(m_x, m_y, m_w, m_h);
|
83
92
|
}
|
84
93
|
|
85
94
|
void Gosu::TexChunk::insert(const Bitmap& original_bitmap, int x, int y)
|
86
95
|
{
|
87
96
|
Bitmap clipped_bitmap;
|
88
97
|
const Bitmap* bitmap = &original_bitmap;
|
89
|
-
|
98
|
+
|
90
99
|
// If inserting the bitmap at the given position exceeds the boundaries of the space allocated
|
91
100
|
// for this image on the texture, we need to clip the bitmap and insert the clipped version
|
92
101
|
// instead.
|
93
|
-
if (x < 0 || y < 0 || x + original_bitmap.width() >
|
102
|
+
if (x < 0 || y < 0 || x + original_bitmap.width() > m_w || y + original_bitmap.height() > m_h) {
|
94
103
|
// How many pixels to remove at the top and left sides.
|
95
104
|
int clip_left = 0, clip_top = 0;
|
96
105
|
// How large the clipped version needs to be.
|
@@ -109,22 +118,22 @@ void Gosu::TexChunk::insert(const Bitmap& original_bitmap, int x, int y)
|
|
109
118
|
y = 0;
|
110
119
|
}
|
111
120
|
// Clip away pixels on the right side, if necessary.
|
112
|
-
if (x + clipped_width >
|
113
|
-
clipped_width = (
|
121
|
+
if (x + clipped_width > m_w) {
|
122
|
+
clipped_width = (m_w - x);
|
114
123
|
}
|
115
124
|
// Clip away pixels on the bottom, if necessary.
|
116
|
-
if (y + clipped_height >
|
117
|
-
clipped_height = (
|
125
|
+
if (y + clipped_height > m_h) {
|
126
|
+
clipped_height = (m_h - y);
|
118
127
|
}
|
119
128
|
|
120
129
|
if (clipped_width <= 0 || clipped_height <= 0) return;
|
121
|
-
|
130
|
+
|
122
131
|
clipped_bitmap.resize(clipped_width, clipped_height);
|
123
132
|
clipped_bitmap.insert(-clip_left, -clip_top, original_bitmap);
|
124
133
|
bitmap = &clipped_bitmap;
|
125
134
|
}
|
126
|
-
|
135
|
+
|
127
136
|
glBindTexture(GL_TEXTURE_2D, tex_name());
|
128
|
-
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
137
|
+
glTexSubImage2D(GL_TEXTURE_2D, 0, m_x + x, m_y + y, bitmap->width(), bitmap->height(),
|
129
138
|
Color::GL_FORMAT, GL_UNSIGNED_BYTE, bitmap->data());
|
130
139
|
}
|
data/src/TexChunk.hpp
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
#pragma once
|
2
2
|
|
3
|
-
#include "GraphicsImpl.hpp"
|
4
3
|
#include <Gosu/Fwd.hpp>
|
5
4
|
#include <Gosu/ImageData.hpp>
|
5
|
+
#include "GraphicsImpl.hpp"
|
6
6
|
#include <memory>
|
7
7
|
#include <stdexcept>
|
8
8
|
|
9
9
|
class Gosu::TexChunk : public Gosu::ImageData
|
10
10
|
{
|
11
|
-
std::shared_ptr<Texture>
|
12
|
-
int
|
13
|
-
|
14
|
-
GLTexInfo
|
15
|
-
|
11
|
+
std::shared_ptr<Texture> m_texture;
|
12
|
+
int m_x, m_y, m_w, m_h, m_padding;
|
13
|
+
|
14
|
+
GLTexInfo m_info;
|
15
|
+
|
16
16
|
void set_tex_info();
|
17
|
-
|
17
|
+
|
18
18
|
public:
|
19
19
|
TexChunk(std::shared_ptr<Texture> texture, int x, int y, int w, int h, int padding);
|
20
20
|
TexChunk(const TexChunk& parent, int x, int y, int w, int h);
|
21
21
|
~TexChunk() override;
|
22
22
|
|
23
|
-
int width() const override
|
24
|
-
int height() const override { return
|
25
|
-
|
26
|
-
GLuint tex_name() const { return
|
27
|
-
|
28
|
-
void draw(double x1, double y1, Color c1,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
const GLTexInfo* gl_tex_info() const override { return &
|
35
|
-
|
23
|
+
int width() const override { return m_w; }
|
24
|
+
int height() const override { return m_h; }
|
25
|
+
|
26
|
+
GLuint tex_name() const { return m_info.tex_name; }
|
27
|
+
|
28
|
+
void draw(double x1, double y1, Color c1, //
|
29
|
+
double x2, double y2, Color c2, //
|
30
|
+
double x3, double y3, Color c3, //
|
31
|
+
double x4, double y4, Color c4, //
|
32
|
+
ZPos z, BlendMode mode) const override;
|
33
|
+
|
34
|
+
const GLTexInfo* gl_tex_info() const override { return &m_info; }
|
35
|
+
|
36
36
|
std::unique_ptr<ImageData> subimage(int x, int y, int width, int height) const override;
|
37
|
-
|
37
|
+
|
38
38
|
Gosu::Bitmap to_bitmap() const override;
|
39
|
-
|
39
|
+
|
40
40
|
void insert(const Bitmap& bitmap, int x, int y) override;
|
41
41
|
};
|
data/src/Text.cpp
CHANGED
@@ -1,95 +1,94 @@
|
|
1
|
+
#include <Gosu/Text.hpp>
|
2
|
+
#include "GraphicsImpl.hpp"
|
1
3
|
#include "MarkupParser.hpp"
|
2
4
|
#include "TextBuilder.hpp"
|
3
|
-
#include "GraphicsImpl.hpp"
|
4
5
|
#include "TrueTypeFont.hpp"
|
5
|
-
#include <Gosu/Text.hpp>
|
6
|
-
#include <cassert>
|
7
|
-
#include <cmath>
|
8
6
|
#include <algorithm>
|
9
|
-
#include <
|
7
|
+
#include <cmath>
|
10
8
|
#include <stdexcept>
|
11
|
-
|
9
|
+
#include <vector>
|
12
10
|
|
13
|
-
double Gosu::text_width(const u32string& text,
|
14
|
-
const string& font_name, double font_height, unsigned font_flags)
|
11
|
+
double Gosu::text_width(const std::u32string& text, //
|
12
|
+
const std::string& font_name, double font_height, unsigned font_flags)
|
15
13
|
{
|
16
|
-
if (font_height <= 0)
|
17
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument
|
18
|
-
|
19
|
-
|
14
|
+
if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
|
15
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
|
16
|
+
|
17
|
+
TrueTypeFont& font = font_by_name(font_name, font_flags);
|
20
18
|
return font.draw_text(text, font_height, nullptr, 0, 0, Gosu::Color::NONE);
|
21
19
|
}
|
22
20
|
|
23
|
-
double Gosu::draw_text(Bitmap& bitmap, double x, double y, Color c, const u32string& text,
|
24
|
-
const string& font_name, double font_height, unsigned font_flags)
|
21
|
+
double Gosu::draw_text(Bitmap& bitmap, double x, double y, Color c, const std::u32string& text,
|
22
|
+
const std::string& font_name, double font_height, unsigned font_flags)
|
25
23
|
{
|
26
|
-
if (font_height <= 0)
|
27
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument("Invalid font_flags");
|
24
|
+
if (font_height <= 0) throw std::invalid_argument("font_height must be > 0");
|
25
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument("Invalid font_flags");
|
28
26
|
|
29
|
-
|
27
|
+
TrueTypeFont& font = font_by_name(font_name, font_flags);
|
30
28
|
return font.draw_text(text, font_height, &bitmap, x, y, c);
|
31
29
|
}
|
32
30
|
|
33
|
-
Gosu::Bitmap Gosu::layout_text(const string& text, const string& font_name,
|
34
|
-
double font_height, double line_spacing,
|
35
|
-
|
31
|
+
Gosu::Bitmap Gosu::layout_text(const std::string& text, const std::string& font_name, //
|
32
|
+
double font_height, double line_spacing, int width, //
|
33
|
+
Alignment align, unsigned font_flags)
|
36
34
|
{
|
37
35
|
// Escape all markup and delegate to layout_markup.
|
38
|
-
return layout_markup(escape_markup(text), font_name,
|
39
|
-
|
40
|
-
width, align, font_flags);
|
36
|
+
return layout_markup(escape_markup(text), font_name, font_height, line_spacing, width, align,
|
37
|
+
font_flags);
|
41
38
|
}
|
42
39
|
|
43
|
-
Gosu::Bitmap Gosu::layout_markup(const string& markup, const string& font_name,
|
44
|
-
double font_height, double line_spacing,
|
45
|
-
|
40
|
+
Gosu::Bitmap Gosu::layout_markup(const std::string& markup, const std::string& font_name, //
|
41
|
+
double font_height, double line_spacing, int width, //
|
42
|
+
Alignment align, unsigned font_flags)
|
46
43
|
{
|
47
|
-
if (font_height <= 0)
|
48
|
-
if (line_spacing < -font_height)
|
49
|
-
if (font_flags >= FF_COMBINATIONS) throw invalid_argument
|
50
|
-
|
44
|
+
if (font_height <= 0) throw std::invalid_argument{"font_height must be > 0"};
|
45
|
+
if (line_spacing < -font_height) throw std::invalid_argument{"line_spacing < -font_height"};
|
46
|
+
if (font_flags >= FF_COMBINATIONS) throw std::invalid_argument{"Invalid font_flags"};
|
47
|
+
|
51
48
|
if (width >= 0) {
|
52
|
-
TextBuilder text_builder
|
53
|
-
|
49
|
+
TextBuilder text_builder{font_name, static_cast<int>(font_height),
|
50
|
+
static_cast<int>(line_spacing), width, align};
|
51
|
+
|
54
52
|
// Feed all formatted substrings to the TextBuilder, which will construct the result.
|
55
53
|
// Split the input string into words, because this method implements word-wrapping.
|
56
|
-
MarkupParser parser
|
57
|
-
|
58
|
-
|
54
|
+
MarkupParser parser{font_flags, true, [&text_builder](std::vector<FormattedString> word) {
|
55
|
+
text_builder.feed_word(move(word));
|
56
|
+
}};
|
59
57
|
parser.parse(markup);
|
60
|
-
|
61
|
-
return text_builder.move_into_bitmap();
|
58
|
+
|
59
|
+
return std::move(text_builder).move_into_bitmap();
|
62
60
|
}
|
63
61
|
else {
|
64
|
-
vector<vector<FormattedString>> lines;
|
65
|
-
|
62
|
+
std::vector<std::vector<FormattedString>> lines;
|
63
|
+
|
66
64
|
// Split the text into lines (split_words = false) since this method does not wrap lines.
|
67
|
-
MarkupParser parser
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
65
|
+
MarkupParser parser{font_flags, false, [&lines](std::vector<FormattedString>&& line) {
|
66
|
+
// Remove trailing \n characters from each line to avoid errors from
|
67
|
+
// Gosu::text_width().
|
68
|
+
if (!line.back().text.empty() && line.back().text.back() == '\n') {
|
69
|
+
line.back().text.pop_back();
|
70
|
+
}
|
71
|
+
|
72
|
+
lines.emplace_back(line);
|
73
|
+
}};
|
75
74
|
parser.parse(markup);
|
76
|
-
|
75
|
+
|
77
76
|
if (lines.empty()) return Bitmap();
|
78
|
-
|
77
|
+
|
79
78
|
// Measure every part of every line.
|
80
|
-
vector<double> line_widths;
|
79
|
+
std::vector<double> line_widths;
|
81
80
|
double max_width = 0;
|
82
81
|
for (auto& line : lines) {
|
83
82
|
line_widths.push_back(0);
|
84
83
|
for (auto& part : line) {
|
85
84
|
line_widths.back() += text_width(part.text, font_name, font_height, part.flags);
|
86
85
|
}
|
87
|
-
max_width = max(max_width, line_widths.back());
|
86
|
+
max_width = std::max(max_width, line_widths.back());
|
88
87
|
}
|
89
|
-
|
90
|
-
double height = lines.size() * font_height + (lines.size() - 1) * line_spacing;
|
91
|
-
Bitmap result(ceil(max_width), ceil(height));
|
92
|
-
|
88
|
+
|
89
|
+
double height = lines.size() * font_height + (lines.size() - 1.0) * line_spacing;
|
90
|
+
Bitmap result{static_cast<int>(std::ceil(max_width)), static_cast<int>(std::ceil(height))};
|
91
|
+
|
93
92
|
// Render every part of every line.
|
94
93
|
double y = 0;
|
95
94
|
for (int i = 0; i < lines.size(); ++i) {
|
@@ -100,14 +99,14 @@ Gosu::Bitmap Gosu::layout_markup(const string& markup, const string& font_name,
|
|
100
99
|
else if (align == AL_RIGHT) {
|
101
100
|
x = result.width() - line_widths[i];
|
102
101
|
}
|
103
|
-
|
102
|
+
|
104
103
|
for (auto& part : lines[i]) {
|
105
|
-
x = draw_text(result, x, y, part.color, part.text,
|
106
|
-
|
104
|
+
x = draw_text(result, x, y, part.color, part.text, font_name, font_height,
|
105
|
+
part.flags);
|
107
106
|
}
|
108
107
|
y += (font_height + line_spacing);
|
109
108
|
}
|
110
|
-
|
109
|
+
|
111
110
|
return result;
|
112
111
|
}
|
113
112
|
}
|
data/src/TextBuilder.cpp
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
#include "TextBuilder.hpp"
|
2
2
|
#include <Gosu/Text.hpp>
|
3
|
-
|
4
|
-
#include <utf8proc.h>
|
5
|
-
|
6
3
|
#include <cassert>
|
7
4
|
#include <cmath>
|
8
|
-
|
5
|
+
#include <utf8proc.h>
|
9
6
|
|
10
|
-
Gosu::WordInfo::WordInfo(const string& font_name, double font_height,
|
7
|
+
Gosu::WordInfo::WordInfo(const std::string& font_name, double font_height,
|
8
|
+
std::vector<FormattedString> parts)
|
11
9
|
{
|
12
|
-
assert
|
13
|
-
|
14
|
-
auto* properties = utf8proc_get_property(parts.front().text.front());
|
10
|
+
assert(!parts.empty());
|
11
|
+
|
12
|
+
const auto* properties = utf8proc_get_property(parts.front().text.front());
|
15
13
|
|
16
14
|
// Also check the BiDi class to filter out non-breaking spaces.
|
17
15
|
is_whitespace = properties->category == UTF8PROC_CATEGORY_ZS &&
|
@@ -20,119 +18,124 @@ Gosu::WordInfo::WordInfo(const string& font_name, double font_height, vector<For
|
|
20
18
|
is_end_of_line = parts.back().text.back() == '\n';
|
21
19
|
// Remove the trailing backspace character to avoid errors from Gosu::text_width().
|
22
20
|
if (is_end_of_line) parts.back().text.pop_back();
|
23
|
-
|
21
|
+
|
24
22
|
width = 0;
|
25
23
|
for (const auto& part : parts) {
|
26
|
-
assert
|
27
|
-
|
24
|
+
assert(is_end_of_line || !part.text.empty());
|
25
|
+
|
28
26
|
width += text_width(part.text, font_name, font_height, part.flags);
|
29
27
|
}
|
30
|
-
|
28
|
+
|
31
29
|
this->parts = move(parts);
|
32
30
|
}
|
33
31
|
|
34
32
|
void Gosu::TextBuilder::flush_current_line(EndOfLineReason reason)
|
35
33
|
{
|
36
|
-
if (
|
34
|
+
if (m_current_line.empty()) {
|
37
35
|
if (reason == END_OF_PARAGRAPH) allocate_next_line();
|
38
36
|
return;
|
39
37
|
}
|
40
|
-
|
38
|
+
|
41
39
|
allocate_next_line();
|
42
|
-
|
40
|
+
|
43
41
|
// Remove trailing whitespace so that justifying the text across the line works.
|
44
|
-
if (
|
45
|
-
|
42
|
+
if (m_current_line.back().is_whitespace) m_current_line.pop_back();
|
43
|
+
|
46
44
|
// Shouldn't happen because the first word on a line should never be whitespace.
|
47
|
-
assert
|
48
|
-
|
45
|
+
assert(!m_current_line.empty());
|
46
|
+
|
49
47
|
double words_width = 0, whitespace_width = 0;
|
50
|
-
for (const auto& word :
|
48
|
+
for (const auto& word : m_current_line) {
|
51
49
|
(word.is_whitespace ? whitespace_width : words_width) += word.width;
|
52
50
|
}
|
53
|
-
|
51
|
+
|
54
52
|
double x = 0;
|
55
|
-
if (
|
56
|
-
x =
|
53
|
+
if (m_align == AL_RIGHT) {
|
54
|
+
x = m_result.width() - words_width - whitespace_width;
|
57
55
|
}
|
58
|
-
else if (
|
59
|
-
x = (
|
56
|
+
else if (m_align == AL_CENTER) {
|
57
|
+
x = (m_result.width() - words_width - whitespace_width) / 2.0;
|
60
58
|
}
|
61
|
-
|
59
|
+
|
62
60
|
double whitespace_factor = 1.0;
|
63
|
-
if (
|
64
|
-
whitespace_factor = (
|
61
|
+
if (m_align == AL_JUSTIFY && whitespace_width != 0 && reason == LINE_TOO_LONG) {
|
62
|
+
whitespace_factor = (m_result.width() - words_width) / whitespace_width;
|
65
63
|
}
|
66
|
-
|
67
|
-
double y = (
|
68
|
-
|
69
|
-
for (const auto& word :
|
64
|
+
|
65
|
+
double y = (m_used_lines - 1) * (m_font_height + m_line_spacing);
|
66
|
+
|
67
|
+
for (const auto& word : m_current_line) {
|
70
68
|
if (word.is_whitespace) {
|
71
69
|
x += word.width * whitespace_factor;
|
72
70
|
}
|
73
71
|
else {
|
74
72
|
for (const auto& part : word.parts) {
|
75
|
-
draw_text(
|
73
|
+
draw_text(m_result, x, y, part.color, part.text, m_font_name, m_font_height,
|
74
|
+
part.flags);
|
76
75
|
}
|
77
76
|
x += word.width;
|
78
77
|
}
|
79
78
|
}
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
|
80
|
+
m_current_line.clear();
|
81
|
+
m_current_line_width = 0;
|
83
82
|
}
|
84
83
|
|
85
84
|
void Gosu::TextBuilder::allocate_next_line()
|
86
85
|
{
|
87
|
-
if (
|
88
|
-
|
86
|
+
if (m_used_lines == m_allocated_lines) {
|
87
|
+
m_allocated_lines += 10;
|
89
88
|
resize_to_allocated_lines();
|
90
89
|
}
|
91
|
-
|
92
|
-
++
|
90
|
+
|
91
|
+
++m_used_lines;
|
93
92
|
}
|
94
93
|
|
95
94
|
void Gosu::TextBuilder::resize_to_allocated_lines()
|
96
95
|
{
|
97
|
-
double new_height =
|
98
|
-
|
96
|
+
double new_height =
|
97
|
+
m_font_height * m_allocated_lines + m_line_spacing * std::max(0, m_allocated_lines - 1);
|
98
|
+
m_result.resize(m_result.width(), ceil(new_height));
|
99
99
|
}
|
100
100
|
|
101
|
-
Gosu::TextBuilder::TextBuilder(const string& font_name, int font_height, int line_spacing,
|
101
|
+
Gosu::TextBuilder::TextBuilder(const std::string& font_name, int font_height, int line_spacing,
|
102
102
|
int width, Alignment align)
|
103
|
-
: font_name
|
103
|
+
: m_font_name{font_name},
|
104
|
+
m_font_height{font_height * 1.0},
|
105
|
+
m_line_spacing{line_spacing * 1.0},
|
106
|
+
m_align{align}
|
104
107
|
{
|
105
108
|
// This class uses result.width() to remember its destination width, so store it in there.
|
106
|
-
|
109
|
+
m_result.resize(width, 0);
|
107
110
|
}
|
108
111
|
|
109
|
-
Gosu::Bitmap Gosu::TextBuilder::move_into_bitmap()
|
112
|
+
Gosu::Bitmap Gosu::TextBuilder::move_into_bitmap() &&
|
110
113
|
{
|
111
114
|
flush_current_line(END_OF_TEXT);
|
112
|
-
|
115
|
+
|
113
116
|
// Shrink to fit the currently used height.
|
114
|
-
|
117
|
+
m_allocated_lines = m_used_lines;
|
115
118
|
resize_to_allocated_lines();
|
116
|
-
return move(
|
119
|
+
return std::move(m_result);
|
117
120
|
}
|
118
121
|
|
119
|
-
void Gosu::TextBuilder::feed_word(vector<FormattedString>&& word)
|
122
|
+
void Gosu::TextBuilder::feed_word(std::vector<FormattedString>&& word)
|
120
123
|
{
|
121
|
-
WordInfo new_word(
|
122
|
-
|
123
|
-
if (
|
124
|
+
WordInfo new_word(m_font_name, m_font_height, word);
|
125
|
+
|
126
|
+
if (m_current_line_width + new_word.width > m_result.width()) {
|
124
127
|
// Can't fit it on the same line as before, so flush the last line before adding the word to
|
125
128
|
// the next line.
|
126
129
|
flush_current_line(LINE_TOO_LONG);
|
127
|
-
|
130
|
+
|
128
131
|
if (new_word.is_whitespace) {
|
129
132
|
// Do not wrap trailing whitespace onto the start of the next line - discard this word.
|
130
133
|
return;
|
131
134
|
}
|
132
135
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
+
|
137
|
+
m_current_line.emplace_back(new_word);
|
138
|
+
m_current_line_width += new_word.width * 1.0;
|
136
139
|
|
137
140
|
if (new_word.is_end_of_line) {
|
138
141
|
flush_current_line(END_OF_PARAGRAPH);
|