gosu 0.7.20 → 0.7.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gosu/Audio.hpp +1 -0
- data/Gosu/Color.hpp +5 -0
- data/Gosu/Font.hpp +5 -0
- data/Gosu/Graphics.hpp +12 -0
- data/Gosu/GraphicsBase.hpp +4 -3
- data/Gosu/ImageData.hpp +1 -0
- data/Gosu/Input.hpp +1 -0
- data/Gosu/Platform.hpp +8 -0
- data/Gosu/Text.hpp +17 -7
- data/Gosu/Version.hpp +2 -2
- data/Gosu/Window.hpp +4 -4
- data/GosuImpl/Audio/AudioSDL.cpp +4 -0
- data/GosuImpl/Graphics/BitmapPNG.cpp +7 -6
- data/GosuImpl/Graphics/Common.hpp +28 -0
- data/GosuImpl/Graphics/DrawOp.hpp +31 -6
- data/GosuImpl/Graphics/Font.cpp +63 -34
- data/GosuImpl/Graphics/FormattedString.hpp +248 -0
- data/GosuImpl/Graphics/Graphics.cpp +39 -7
- data/GosuImpl/Graphics/LargeImageData.cpp +10 -0
- data/GosuImpl/Graphics/LargeImageData.hpp +2 -0
- data/GosuImpl/Graphics/Macro.hpp +5 -0
- data/GosuImpl/Graphics/TexChunk.cpp +10 -5
- data/GosuImpl/Graphics/TexChunk.hpp +4 -2
- data/GosuImpl/Graphics/Text.cpp +118 -57
- data/GosuImpl/Graphics/TextTouch.mm +49 -17
- data/GosuImpl/Graphics/TextUnix.cpp +1 -2
- data/GosuImpl/Graphics/TextWin.cpp +2 -3
- data/GosuImpl/Graphics/Texture.cpp +33 -2
- data/GosuImpl/Graphics/Texture.hpp +3 -1
- data/GosuImpl/Graphics/Transform.cpp +59 -0
- data/GosuImpl/RubyGosu.swg +46 -4
- data/GosuImpl/RubyGosu_wrap.cxx +822 -157
- data/GosuImpl/Utility.cpp +1 -0
- data/GosuImpl/WindowWin.cpp +8 -8
- data/examples/CptnRuby.rb +27 -28
- data/lib/gosu.rb +1 -1
- data/linux/extconf.rb +2 -2
- metadata +21 -6
- data/GosuImpl/RubyGosu_wrap.cxx.rej +0 -187
data/Gosu/Audio.hpp
CHANGED
data/Gosu/Color.hpp
CHANGED
@@ -146,6 +146,11 @@ namespace Gosu
|
|
146
146
|
// require 'gosu'; include Gosu
|
147
147
|
// works from within Ruby, the #ifndef guard can be removed.
|
148
148
|
#ifndef SWIG
|
149
|
+
inline bool operator<(Color a, Color b)
|
150
|
+
{
|
151
|
+
return a.argb() < b.argb();
|
152
|
+
}
|
153
|
+
|
149
154
|
inline bool operator==(Color a, Color b)
|
150
155
|
{
|
151
156
|
return a.argb() == b.argb();
|
data/Gosu/Font.hpp
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <Gosu/Fwd.hpp>
|
8
8
|
#include <Gosu/Color.hpp>
|
9
9
|
#include <Gosu/GraphicsBase.hpp>
|
10
|
+
#include <Gosu/Platform.hpp>
|
10
11
|
#include <boost/scoped_ptr.hpp>
|
11
12
|
#include <string>
|
12
13
|
|
@@ -45,6 +46,7 @@ namespace Gosu
|
|
45
46
|
double textWidth(const std::wstring& text, double factorX = 1) const;
|
46
47
|
|
47
48
|
//! Draws text so the top left corner of the text is at (x; y).
|
49
|
+
//! \param text Formatted text without line-breaks.
|
48
50
|
void draw(const std::wstring& text, double x, double y, ZPos z,
|
49
51
|
double factorX = 1, double factorY = 1,
|
50
52
|
Color c = Color::WHITE, AlphaMode mode = amDefault) const;
|
@@ -59,6 +61,9 @@ namespace Gosu
|
|
59
61
|
double relX, double relY, double factorX = 1, double factorY = 1,
|
60
62
|
Color c = Color::WHITE, AlphaMode mode = amDefault) const;
|
61
63
|
|
64
|
+
#ifndef SWIG
|
65
|
+
GOSU_DEPRECATED
|
66
|
+
#endif
|
62
67
|
//! Analogous to draw, but rotates the text by a given angle.
|
63
68
|
void drawRot(const std::wstring& text, double x, double y, ZPos z, double angle,
|
64
69
|
double factorX = 1, double factorY = 1,
|
data/Gosu/Graphics.hpp
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <Gosu/Fwd.hpp>
|
8
8
|
#include <Gosu/Color.hpp>
|
9
9
|
#include <Gosu/GraphicsBase.hpp>
|
10
|
+
#include <boost/array.hpp>
|
10
11
|
#include <boost/scoped_ptr.hpp>
|
11
12
|
#include <memory>
|
12
13
|
|
@@ -24,6 +25,12 @@ namespace Gosu
|
|
24
25
|
// (Held back until it will not cause a stock Ubuntu to crash. Don't ask me!)
|
25
26
|
//extern unsigned const MAX_TEXTURE_SIZE;
|
26
27
|
|
28
|
+
typedef boost::array<double, 16> Transform;
|
29
|
+
Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
|
30
|
+
Transform translate(double x, double y);
|
31
|
+
Transform scale(double factor);
|
32
|
+
Transform scale(double factorX, double factorY);
|
33
|
+
|
27
34
|
//! Serves as the target of all drawing and provides basic drawing
|
28
35
|
//! functionality.
|
29
36
|
//! Usually created by Gosu::Window.
|
@@ -66,6 +73,11 @@ namespace Gosu
|
|
66
73
|
//! Finishes building the macro and returns it as a drawable object.
|
67
74
|
//! Most usually, the return value is passed to Image::Image().
|
68
75
|
std::auto_ptr<Gosu::ImageData> endRecording();
|
76
|
+
|
77
|
+
//! Pushes one transformation onto the transformation stack.
|
78
|
+
void pushTransform(const Transform& transform);
|
79
|
+
//! Pops one transformation from the transformation stack.
|
80
|
+
void popTransform();
|
69
81
|
|
70
82
|
//! Draws a line from one point to another (last pixel exclusive).
|
71
83
|
void drawLine(double x1, double y1, Color c1,
|
data/Gosu/GraphicsBase.hpp
CHANGED
data/Gosu/ImageData.hpp
CHANGED
data/Gosu/Input.hpp
CHANGED
data/Gosu/Platform.hpp
CHANGED
@@ -62,4 +62,12 @@ namespace Gosu
|
|
62
62
|
# endif
|
63
63
|
#endif
|
64
64
|
|
65
|
+
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
66
|
+
# define GOSU_DEPRECATED __attribute__((__deprecated__))
|
67
|
+
#elif defined(GOSU_IS_WIN)
|
68
|
+
# define GOSU_DEPRECATED __declspec(deprecated)
|
69
|
+
#else
|
70
|
+
# define GOSU_DEPRECATED
|
71
|
+
#endif
|
72
|
+
|
65
73
|
#endif
|
data/Gosu/Text.hpp
CHANGED
@@ -15,14 +15,18 @@ namespace Gosu
|
|
15
15
|
//! platform.
|
16
16
|
std::wstring defaultFontName();
|
17
17
|
|
18
|
-
//! Returns the width
|
19
|
-
//!
|
18
|
+
//! Returns the width an unformatted line of text would span on a bitmap if it were drawn using
|
19
|
+
//! drawText with the same arguments. This is a very low-level function that does not understand
|
20
|
+
//! any of Gosu's HTML-like markup.
|
21
|
+
//! \param text Unformatted text.
|
20
22
|
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
|
21
23
|
unsigned textWidth(const std::wstring& text,
|
22
24
|
const std::wstring& fontName, unsigned fontHeight,
|
23
25
|
unsigned fontFlags = 0);
|
24
26
|
|
25
|
-
//! Draws a line of text on a bitmap.
|
27
|
+
//! Draws a line of unformatted text on a bitmap. This is a very low-level function that does not understand
|
28
|
+
//! any of Gosu's HTML-like markup.
|
29
|
+
//! \param text Unformatted text.
|
26
30
|
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
|
27
31
|
//! \param fontHeight Height, in pixels, of the text.
|
28
32
|
//! \param fontFlags Binary combination of members of the FontFlags
|
@@ -31,8 +35,9 @@ namespace Gosu
|
|
31
35
|
Color c, const std::wstring& fontName, unsigned fontHeight,
|
32
36
|
unsigned fontFlags = 0);
|
33
37
|
|
34
|
-
//! Creates a bitmap that is filled with a line of text given to the function.
|
35
|
-
//! The line
|
38
|
+
//! Creates a bitmap that is filled with a line of formatted text given to the function.
|
39
|
+
//! The line can contain line breaks and HTML-like markup.
|
40
|
+
//! \param text Formatted text.
|
36
41
|
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
|
37
42
|
//! \param fontHeight Height of the font in pixels.
|
38
43
|
//! \param fontFlags Binary combination of members of the FontFlags
|
@@ -41,8 +46,9 @@ namespace Gosu
|
|
41
46
|
const std::wstring& fontName, unsigned fontHeight,
|
42
47
|
unsigned fontFlags = 0);
|
43
48
|
|
44
|
-
//! Creates a bitmap that is filled with the text given to the function.
|
45
|
-
//! The
|
49
|
+
//! Creates a bitmap that is filled with the formatted text given to the function.
|
50
|
+
//! The line can contain line breaks and HTML-like markup.
|
51
|
+
//! \param text Formatted text.
|
46
52
|
//! \param fontName Name of a system font, or a filename to a TTF file (must contain '/', does not work on Linux).
|
47
53
|
//! \param fontHeight Height of the font in pixels.
|
48
54
|
//! \param lineSpacing Spacing between two lines of text in pixels.
|
@@ -55,6 +61,10 @@ namespace Gosu
|
|
55
61
|
const std::wstring& fontName, unsigned fontHeight,
|
56
62
|
unsigned lineSpacing, unsigned maxWidth, TextAlign align,
|
57
63
|
unsigned fontFlags = 0);
|
64
|
+
|
65
|
+
//! Registers a new HTML-style entity that can subsequently be used
|
66
|
+
//! with Gosu::Font and Gosu::createText. The name is given without & and ;.
|
67
|
+
void registerEntity(const std::wstring& name, const Bitmap& replacement);
|
58
68
|
}
|
59
69
|
|
60
70
|
#endif
|
data/Gosu/Version.hpp
CHANGED
data/Gosu/Window.hpp
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
#include <string>
|
14
14
|
|
15
15
|
#ifdef GOSU_IS_WIN
|
16
|
+
#define NOMINMAX
|
16
17
|
#include <windows.h>
|
17
18
|
#endif
|
18
19
|
|
@@ -100,11 +101,10 @@ namespace Gosu
|
|
100
101
|
const Touches& currentTouches() const;
|
101
102
|
#endif
|
102
103
|
|
104
|
+
GOSU_DEPRECATED const Audio& audio() const;
|
105
|
+
GOSU_DEPRECATED Audio& audio();
|
106
|
+
|
103
107
|
#endif
|
104
|
-
|
105
|
-
// Deprecated.
|
106
|
-
const Audio& audio() const;
|
107
|
-
Audio& audio();
|
108
108
|
};
|
109
109
|
}
|
110
110
|
|
data/GosuImpl/Audio/AudioSDL.cpp
CHANGED
@@ -293,6 +293,10 @@ void Gosu::Song::changeVolume(double volume) {
|
|
293
293
|
Mix_VolumeMusic(trunc(data->volume * MIX_MAX_VOLUME));
|
294
294
|
}
|
295
295
|
|
296
|
+
void Gosu::Song::update()
|
297
|
+
{
|
298
|
+
}
|
299
|
+
|
296
300
|
// Deprecated constructors.
|
297
301
|
|
298
302
|
Gosu::Sample::Sample(Audio& audio, const std::wstring& filename)
|
@@ -241,7 +241,7 @@ Gosu::Writer Gosu::saveToPNG(const Bitmap& bmp, Writer writer)
|
|
241
241
|
tmpWriteStream = &writer; // No more experimental.
|
242
242
|
png_set_write_fn(pngPtr, png_get_io_ptr(pngPtr), writePNGdata, flushPNGdata);
|
243
243
|
|
244
|
-
png_set_IHDR(pngPtr, infoPtr, bmp.width(), bmp.height(), 8,
|
244
|
+
png_set_IHDR(pngPtr, infoPtr, bmp.width(), bmp.height(), 8, PNG_COLOR_TYPE_RGBA,
|
245
245
|
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
246
246
|
|
247
247
|
png_write_info(pngPtr, infoPtr);
|
@@ -250,12 +250,13 @@ Gosu::Writer Gosu::saveToPNG(const Bitmap& bmp, Writer writer)
|
|
250
250
|
rows = new png_bytep[bmp.height()];
|
251
251
|
for(unsigned int y = 0; y < bmp.height(); y++)
|
252
252
|
{
|
253
|
-
rows[y] = new png_byte[bmp.width() *
|
254
|
-
for(unsigned int x = 0; x < bmp.width()*
|
253
|
+
rows[y] = new png_byte[bmp.width() * 4];
|
254
|
+
for(unsigned int x = 0; x < bmp.width()*4; x += 4)
|
255
255
|
{
|
256
|
-
rows[y][x] = bmp.getPixel(x/
|
257
|
-
rows[y][x+1] = bmp.getPixel(x/
|
258
|
-
rows[y][x+2] = bmp.getPixel(x/
|
256
|
+
rows[y][x] = bmp.getPixel(x/4, y).red();
|
257
|
+
rows[y][x+1] = bmp.getPixel(x/4, y).green();
|
258
|
+
rows[y][x+2] = bmp.getPixel(x/4, y).blue();
|
259
|
+
rows[y][x+3] = bmp.getPixel(x/4, y).alpha();
|
259
260
|
}
|
260
261
|
}
|
261
262
|
|
@@ -1,9 +1,12 @@
|
|
1
1
|
#ifndef GOSUIMPL_GRAPHICS_COMMON_HPP
|
2
2
|
#define GOSUIMPL_GRAPHICS_COMMON_HPP
|
3
3
|
|
4
|
+
#include <Gosu/Bitmap.hpp>
|
5
|
+
#include <Gosu/Graphics.hpp>
|
4
6
|
#include <Gosu/Platform.hpp>
|
5
7
|
|
6
8
|
#if defined(GOSU_IS_WIN)
|
9
|
+
#define NOMINMAX
|
7
10
|
#include <windows.h>
|
8
11
|
#include <GL/gl.h>
|
9
12
|
#elif defined(GOSU_IS_IPHONE)
|
@@ -16,6 +19,7 @@
|
|
16
19
|
#endif
|
17
20
|
|
18
21
|
#include <algorithm>
|
22
|
+
#include <list>
|
19
23
|
#include <vector>
|
20
24
|
|
21
25
|
namespace Gosu
|
@@ -24,6 +28,7 @@ namespace Gosu
|
|
24
28
|
class TexChunk;
|
25
29
|
struct DrawOp;
|
26
30
|
class DrawOpQueue;
|
31
|
+
typedef std::list<Transform> Transforms;
|
27
32
|
typedef std::vector<DrawOpQueue> DrawOpQueueStack;
|
28
33
|
class Macro;
|
29
34
|
|
@@ -46,6 +51,29 @@ namespace Gosu
|
|
46
51
|
std::swap(c3, c4);
|
47
52
|
}
|
48
53
|
}
|
54
|
+
|
55
|
+
inline Transform multiply(const Transform& left, const Transform& right)
|
56
|
+
{
|
57
|
+
Gosu::Transform result;
|
58
|
+
result.assign(0);
|
59
|
+
for (int i = 0; i < 16; ++i)
|
60
|
+
for (int j = 0; j < 4; ++j)
|
61
|
+
result[i] += left[i / 4 * 4 + j] * right[i % 4 + j * 4];
|
62
|
+
return result;
|
63
|
+
}
|
64
|
+
|
65
|
+
inline void multiplyBitmapAlpha(Bitmap& bmp, Color::Channel alpha)
|
66
|
+
{
|
67
|
+
for (int y = 0; y < bmp.height(); ++y)
|
68
|
+
for (int x = 0; x < bmp.width(); ++x)
|
69
|
+
{
|
70
|
+
Color c = bmp.getPixel(x, y);
|
71
|
+
c.setAlpha(c.alpha() * alpha / 255);
|
72
|
+
bmp.setPixel(x, y, c);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
const Bitmap& entityBitmap(const std::wstring& name);
|
49
77
|
}
|
50
78
|
|
51
79
|
#endif
|
@@ -24,6 +24,7 @@ namespace Gosu
|
|
24
24
|
|
25
25
|
struct DrawOp
|
26
26
|
{
|
27
|
+
Gosu::Transform* transform;
|
27
28
|
int clipX, clipY;
|
28
29
|
unsigned clipWidth, clipHeight;
|
29
30
|
|
@@ -41,17 +42,24 @@ namespace Gosu
|
|
41
42
|
const TexChunk* chunk;
|
42
43
|
AlphaMode mode;
|
43
44
|
|
44
|
-
DrawOp() { clipWidth = 0xffffffff; usedVertices = 0; chunk = 0; }
|
45
|
+
DrawOp(Gosu::Transform& transform) : transform(&transform) { clipWidth = 0xffffffff; usedVertices = 0; chunk = 0; }
|
45
46
|
|
46
47
|
#ifndef GOSU_IS_IPHONE
|
47
|
-
void perform(GLuint& currentTexName, const void*) const
|
48
|
+
void perform(GLuint& currentTexName, Transform*& currentTransform, const void*) const
|
48
49
|
{
|
49
50
|
if (clipWidth != 0xffffffff)
|
50
51
|
{
|
51
52
|
glEnable(GL_SCISSOR_TEST);
|
52
53
|
glScissor(clipX, clipY, clipWidth, clipHeight);
|
53
54
|
}
|
54
|
-
|
55
|
+
|
56
|
+
if (transform != currentTransform) {
|
57
|
+
glPopMatrix();
|
58
|
+
glPushMatrix();
|
59
|
+
glMultMatrixd(transform->data());
|
60
|
+
currentTransform = transform;
|
61
|
+
}
|
62
|
+
|
55
63
|
if (mode == amAdditive)
|
56
64
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
57
65
|
else if (mode == amMultiply)
|
@@ -113,7 +121,7 @@ namespace Gosu
|
|
113
121
|
glDisable(GL_SCISSOR_TEST);
|
114
122
|
}
|
115
123
|
#else
|
116
|
-
void perform(unsigned& currentTexName, const DrawOp* next) const
|
124
|
+
void perform(unsigned& currentTexName, Transform*& currentTransform, const DrawOp* next) const
|
117
125
|
{
|
118
126
|
if (usedVertices != 4)
|
119
127
|
return; // No triangles, no lines on iPhone
|
@@ -140,6 +148,13 @@ namespace Gosu
|
|
140
148
|
isSetup = true;
|
141
149
|
}
|
142
150
|
|
151
|
+
if (transform != currentTransform) {
|
152
|
+
glPopMatrix();
|
153
|
+
glPushMatrix();
|
154
|
+
glMultMatrixd(transform->data());
|
155
|
+
currentTransform = transform;
|
156
|
+
}
|
157
|
+
|
143
158
|
if (clipWidth != 0xffffffff)
|
144
159
|
{
|
145
160
|
glEnable(GL_SCISSOR_TEST);
|
@@ -283,7 +298,11 @@ namespace Gosu
|
|
283
298
|
if (z == zImmediate)
|
284
299
|
{
|
285
300
|
GLuint currentTexName = NO_TEXTURE;
|
286
|
-
|
301
|
+
Transform* currentTransform = 0;
|
302
|
+
glMatrixMode(GL_MODELVIEW);
|
303
|
+
glPushMatrix();
|
304
|
+
op.perform(currentTexName, currentTransform, 0);
|
305
|
+
glPopMatrix();
|
287
306
|
if (currentTexName != NO_TEXTURE)
|
288
307
|
glDisable(GL_TEXTURE_2D);
|
289
308
|
}
|
@@ -308,15 +327,21 @@ namespace Gosu
|
|
308
327
|
void performDrawOps() const
|
309
328
|
{
|
310
329
|
GLuint currentTexName = NO_TEXTURE;
|
330
|
+
Transform* currentTransform = 0;
|
331
|
+
|
332
|
+
glMatrixMode(GL_MODELVIEW);
|
333
|
+
glPushMatrix();
|
311
334
|
|
312
335
|
std::multiset<DrawOp>::const_iterator last, cur = set.begin(), end = set.end();
|
313
336
|
while (cur != end)
|
314
337
|
{
|
315
338
|
last = cur;
|
316
339
|
++cur;
|
317
|
-
last->perform(currentTexName, cur == end ? 0 : &*cur);
|
340
|
+
last->perform(currentTexName, currentTransform, cur == end ? 0 : &*cur);
|
318
341
|
}
|
319
342
|
|
343
|
+
glPopMatrix();
|
344
|
+
|
320
345
|
if (currentTexName != NO_TEXTURE)
|
321
346
|
glDisable(GL_TEXTURE_2D);
|
322
347
|
}
|
data/GosuImpl/Graphics/Font.cpp
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
#include <Gosu/Image.hpp>
|
4
4
|
#include <Gosu/Math.hpp>
|
5
5
|
#include <Gosu/Text.hpp>
|
6
|
+
#include <GosuImpl/Graphics/Common.hpp>
|
7
|
+
#include <GosuImpl/Graphics/FormattedString.hpp>
|
6
8
|
#include <boost/array.hpp>
|
9
|
+
#include <boost/shared_ptr.hpp>
|
10
|
+
#include <map>
|
7
11
|
using namespace std;
|
8
12
|
|
9
13
|
namespace
|
@@ -28,25 +32,39 @@ struct Gosu::Font::Impl
|
|
28
32
|
{
|
29
33
|
Graphics* graphics;
|
30
34
|
wstring name;
|
31
|
-
unsigned height;
|
32
|
-
unsigned flags;
|
35
|
+
unsigned height, flags;
|
33
36
|
|
34
37
|
// Chunk of 2^16 characters (on Windows, there'll only be one of them).
|
35
38
|
// IMPR: I couldn't find a way to determine the size of wchar_t at compile
|
36
39
|
// time, so I can't get rid of the magic numbers or even do some #ifdef
|
37
40
|
// magic.
|
38
41
|
typedef boost::array<boost::scoped_ptr<Image>, 65536> CharChunk;
|
39
|
-
boost::scoped_ptr<CharChunk> chunks[65536];
|
42
|
+
boost::scoped_ptr<CharChunk> chunks[65536][ffCombinations];
|
43
|
+
|
44
|
+
std::map<std::wstring, boost::shared_ptr<Image> > entityCache;
|
40
45
|
|
41
|
-
Image&
|
46
|
+
const Image& imageAt(const FormattedString& fs, unsigned i)
|
42
47
|
{
|
48
|
+
if (fs.entityAt(i))
|
49
|
+
{
|
50
|
+
boost::shared_ptr<Image>& ptr = entityCache[fs.entityAt(i)];
|
51
|
+
if (!ptr)
|
52
|
+
ptr.reset(new Image(*graphics, entityBitmap(fs.entityAt(i)), false));
|
53
|
+
return *ptr;
|
54
|
+
}
|
55
|
+
|
56
|
+
wchar_t wc = fs.charAt(i);
|
57
|
+
unsigned flags = fs.flagsAt(i);
|
58
|
+
|
59
|
+
assert(flags < ffCombinations);
|
60
|
+
|
43
61
|
size_t chunkIndex = wc / 65536;
|
44
62
|
size_t charIndex = wc % 65536;
|
45
63
|
|
46
|
-
if (!chunks[chunkIndex])
|
47
|
-
chunks[chunkIndex].reset(new CharChunk);
|
64
|
+
if (!chunks[chunkIndex][flags])
|
65
|
+
chunks[chunkIndex][flags].reset(new CharChunk);
|
48
66
|
|
49
|
-
boost::scoped_ptr<Image>& imgPtr = (*chunks[chunkIndex])[charIndex];
|
67
|
+
boost::scoped_ptr<Image>& imgPtr = (*chunks[chunkIndex][flags])[charIndex];
|
50
68
|
|
51
69
|
if (imgPtr)
|
52
70
|
return *imgPtr;
|
@@ -62,6 +80,14 @@ struct Gosu::Font::Impl
|
|
62
80
|
imgPtr.reset(new Image(*graphics, bmp));
|
63
81
|
return *imgPtr;
|
64
82
|
}
|
83
|
+
|
84
|
+
double factorAt(const FormattedString& fs, unsigned index) const
|
85
|
+
{
|
86
|
+
if (fs.entityAt(index))
|
87
|
+
return 1;
|
88
|
+
else
|
89
|
+
return 0.5;
|
90
|
+
}
|
65
91
|
};
|
66
92
|
|
67
93
|
Gosu::Font::Font(Graphics& graphics, const wstring& fontName, unsigned fontHeight,
|
@@ -70,7 +96,7 @@ Gosu::Font::Font(Graphics& graphics, const wstring& fontName, unsigned fontHeigh
|
|
70
96
|
{
|
71
97
|
pimpl->graphics = &graphics;
|
72
98
|
pimpl->name = fontName;
|
73
|
-
pimpl->height = fontHeight * 2;
|
99
|
+
pimpl->height = fontHeight * 2;
|
74
100
|
pimpl->flags = fontFlags;
|
75
101
|
}
|
76
102
|
|
@@ -95,24 +121,29 @@ unsigned Gosu::Font::flags() const
|
|
95
121
|
|
96
122
|
double Gosu::Font::textWidth(const std::wstring& text, double factorX) const
|
97
123
|
{
|
124
|
+
FormattedString fs(text, flags());
|
98
125
|
double result = 0;
|
99
|
-
for (unsigned i = 0; i <
|
100
|
-
result += pimpl->
|
101
|
-
return result * factorX
|
126
|
+
for (unsigned i = 0; i < fs.length(); ++i)
|
127
|
+
result += pimpl->imageAt(fs, i).width() * pimpl->factorAt(fs, i);
|
128
|
+
return result * factorX;
|
102
129
|
}
|
103
130
|
|
104
131
|
void Gosu::Font::draw(const wstring& text, double x, double y, ZPos z,
|
105
132
|
double factorX, double factorY, Color c, AlphaMode mode) const
|
106
133
|
{
|
107
|
-
|
108
|
-
|
134
|
+
FormattedString fs(text, flags());
|
135
|
+
|
109
136
|
enum {
|
110
137
|
LTR = 1,
|
111
138
|
RTL = -1
|
112
139
|
} dir = LTR;
|
113
140
|
|
114
|
-
for (unsigned i = 0; i <
|
141
|
+
for (unsigned i = 0; i < fs.length(); ++i)
|
115
142
|
{
|
143
|
+
/*
|
144
|
+
|
145
|
+
Sorry, LTR/RTL support taken out until somebody uses it
|
146
|
+
|
116
147
|
if (isLtrChar(text[i]))
|
117
148
|
{
|
118
149
|
if (dir == RTL)
|
@@ -124,18 +155,25 @@ void Gosu::Font::draw(const wstring& text, double x, double y, ZPos z,
|
|
124
155
|
if (dir == LTR)
|
125
156
|
x += 2 * textWidth(text.substr(i + 1, wstring::npos)) * factorX, dir = RTL;
|
126
157
|
continue;
|
127
|
-
}
|
128
|
-
|
129
|
-
Image& curChar = pimpl->
|
130
|
-
|
131
|
-
|
158
|
+
}*/
|
159
|
+
|
160
|
+
const Image& curChar = pimpl->imageAt(fs, i);
|
161
|
+
double curFactor;
|
162
|
+
Gosu::Color color;
|
163
|
+
if (fs.entityAt(i))
|
164
|
+
curFactor = 1.0, color = Gosu::Color(fs.colorAt(i).alpha() * c.alpha() / 255, 255, 255, 255);
|
132
165
|
else
|
133
|
-
|
166
|
+
curFactor = 0.5, color = Gosu::multiply(fs.colorAt(i), c);
|
167
|
+
|
168
|
+
//if (dir == LTR)
|
169
|
+
curChar.draw(x, y, z, factorX * curFactor, factorY * curFactor, color, mode);
|
170
|
+
//else
|
171
|
+
// curChar.draw(x - curChar.width() * factorX, y, z, factorX, factorY, c, mode);
|
134
172
|
|
135
|
-
x += curChar.width() * factorX * dir;
|
173
|
+
x += curChar.width() * factorX * curFactor * dir;
|
136
174
|
}
|
137
175
|
}
|
138
|
-
|
176
|
+
|
139
177
|
void Gosu::Font::drawRel(const wstring& text, double x, double y, ZPos z,
|
140
178
|
double relX, double relY, double factorX, double factorY, Color c,
|
141
179
|
AlphaMode mode) const
|
@@ -149,16 +187,7 @@ void Gosu::Font::drawRel(const wstring& text, double x, double y, ZPos z,
|
|
149
187
|
void Gosu::Font::drawRot(const wstring& text, double x, double y, ZPos z, double angle,
|
150
188
|
double factorX, double factorY, Color c, AlphaMode mode) const
|
151
189
|
{
|
152
|
-
|
153
|
-
factorY
|
154
|
-
|
155
|
-
double stepX = offsetX(angle + 90, 1.0), stepY = offsetY(angle + 90, 1.0);
|
156
|
-
|
157
|
-
for (unsigned i = 0; i < text.length(); ++i)
|
158
|
-
{
|
159
|
-
Image& curChar = pimpl->getChar(text[i]);
|
160
|
-
curChar.drawRot(x, y, z, angle, 0.0, 0.0, factorX, factorY, c, mode);
|
161
|
-
x += curChar.width() * factorX * stepX;
|
162
|
-
y += curChar.width() * factorX * stepY;
|
163
|
-
}
|
190
|
+
pimpl->graphics->pushTransform(rotate(angle, x, y));
|
191
|
+
draw(text, x, y, z, factorX, factorY, c, mode);
|
192
|
+
pimpl->graphics->popTransform();
|
164
193
|
}
|