gosu 0.7.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING.txt +29 -0
- data/Gosu/Async.hpp +48 -0
- data/Gosu/Audio.hpp +145 -0
- data/Gosu/AutoLink.hpp +16 -0
- data/Gosu/Bitmap.hpp +85 -0
- data/Gosu/ButtonsMac.hpp +114 -0
- data/Gosu/ButtonsWin.hpp +111 -0
- data/Gosu/ButtonsX.hpp +115 -0
- data/Gosu/Color.hpp +172 -0
- data/Gosu/Directories.hpp +36 -0
- data/Gosu/Font.hpp +59 -0
- data/Gosu/Fwd.hpp +31 -0
- data/Gosu/Gosu.hpp +26 -0
- data/Gosu/Graphics.hpp +86 -0
- data/Gosu/GraphicsBase.hpp +45 -0
- data/Gosu/IO.hpp +255 -0
- data/Gosu/Image.hpp +148 -0
- data/Gosu/ImageData.hpp +45 -0
- data/Gosu/Input.hpp +116 -0
- data/Gosu/Math.hpp +95 -0
- data/Gosu/Platform.hpp +61 -0
- data/Gosu/RotFlip.hpp +116 -0
- data/Gosu/Sockets.hpp +129 -0
- data/Gosu/Text.hpp +47 -0
- data/Gosu/TextInput.hpp +57 -0
- data/Gosu/Timing.hpp +16 -0
- data/Gosu/Utility.hpp +24 -0
- data/Gosu/WinUtility.hpp +76 -0
- data/Gosu/Window.hpp +84 -0
- data/GosuImpl/Async.cpp +37 -0
- data/GosuImpl/AudioFmod.cpp +417 -0
- data/GosuImpl/AudioSDL.cpp +255 -0
- data/GosuImpl/DirectoriesMac.mm +38 -0
- data/GosuImpl/DirectoriesUnix.cpp +48 -0
- data/GosuImpl/DirectoriesWin.cpp +42 -0
- data/GosuImpl/FileUnix.cpp +100 -0
- data/GosuImpl/FileWin.cpp +83 -0
- data/GosuImpl/Graphics/Bitmap.cpp +116 -0
- data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
- data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
- data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
- data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
- data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
- data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
- data/GosuImpl/Graphics/Color.cpp +126 -0
- data/GosuImpl/Graphics/Common.hpp +21 -0
- data/GosuImpl/Graphics/DrawOp.hpp +154 -0
- data/GosuImpl/Graphics/Font.cpp +110 -0
- data/GosuImpl/Graphics/Graphics.cpp +295 -0
- data/GosuImpl/Graphics/Image.cpp +159 -0
- data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
- data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
- data/GosuImpl/Graphics/RotFlip.cpp +184 -0
- data/GosuImpl/Graphics/TexChunk.cpp +77 -0
- data/GosuImpl/Graphics/TexChunk.hpp +40 -0
- data/GosuImpl/Graphics/Text.cpp +223 -0
- data/GosuImpl/Graphics/TextMac.cpp +242 -0
- data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
- data/GosuImpl/Graphics/TextWin.cpp +172 -0
- data/GosuImpl/Graphics/Texture.cpp +104 -0
- data/GosuImpl/Graphics/Texture.hpp +34 -0
- data/GosuImpl/IO.cpp +48 -0
- data/GosuImpl/InputMac.mm +677 -0
- data/GosuImpl/InputWin.cpp +444 -0
- data/GosuImpl/InputX.cpp +158 -0
- data/GosuImpl/MacUtility.hpp +48 -0
- data/GosuImpl/Math.cpp +49 -0
- data/GosuImpl/RubyGosu.swg +474 -0
- data/GosuImpl/RubyGosuStub.mm +17 -0
- data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
- data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
- data/GosuImpl/RubyGosu_wrap.h +31 -0
- data/GosuImpl/Sockets/CommSocket.cpp +304 -0
- data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
- data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
- data/GosuImpl/Sockets/Socket.cpp +145 -0
- data/GosuImpl/Sockets/Sockets.hpp +66 -0
- data/GosuImpl/TextInputMac.mm +207 -0
- data/GosuImpl/TextInputWin.cpp +197 -0
- data/GosuImpl/TextInputX.cpp +201 -0
- data/GosuImpl/TextTTFWin.cpp +247 -0
- data/GosuImpl/TimingUnix.cpp +17 -0
- data/GosuImpl/TimingWin.cpp +28 -0
- data/GosuImpl/Utility.cpp +140 -0
- data/GosuImpl/WinMain.cpp +69 -0
- data/GosuImpl/WinUtility.cpp +137 -0
- data/GosuImpl/WindowMac.mm +466 -0
- data/GosuImpl/WindowWin.cpp +447 -0
- data/GosuImpl/WindowX.cpp +392 -0
- data/GosuImpl/X11vroot.h +118 -0
- data/README.txt +13 -0
- data/Rakefile +178 -0
- data/examples/ChipmunkIntegration.rb +275 -0
- data/examples/CptnRuby.rb +231 -0
- data/examples/MoreChipmunkAndRMagick.rb +155 -0
- data/examples/OpenGLIntegration.rb +232 -0
- data/examples/RMagickIntegration.rb +449 -0
- data/examples/TextInput.cpp +170 -0
- data/examples/TextInput.rb +139 -0
- data/examples/Tutorial.cpp +215 -0
- data/examples/Tutorial.rb +137 -0
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +25 -0
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Sky.jpg +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
- data/linux/Makefile.in +98 -0
- data/linux/configure +5658 -0
- data/linux/configure.ac +126 -0
- data/linux/extconf.rb +11 -0
- data/mac/English.lproj/InfoPlist.strings +0 -0
- data/mac/Gosu-Info.plist +26 -0
- data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
- data/mac/RubyGosu Template-Info.plist +26 -0
- data/mac/libboost_thread_1_34_1_universal.a +0 -0
- data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
- data/mac/libfmod_universal.a +0 -0
- data/mac/libpng_universal.a +0 -0
- data/mac/libz_universal.a +0 -0
- data/reference/Async_8hpp-source.html +70 -0
- data/reference/Audio_8hpp-source.html +114 -0
- data/reference/Audio_8hpp.html +50 -0
- data/reference/AutoLink_8hpp-source.html +38 -0
- data/reference/AutoLink_8hpp.html +34 -0
- data/reference/Bitmap_8hpp-source.html +85 -0
- data/reference/Bitmap_8hpp.html +58 -0
- data/reference/ButtonsMac_8hpp-source.html +133 -0
- data/reference/ButtonsWin_8hpp-source.html +133 -0
- data/reference/ButtonsX_8hpp-source.html +134 -0
- data/reference/Color_8hpp-source.html +169 -0
- data/reference/Color_8hpp.html +85 -0
- data/reference/Directories_8hpp-source.html +42 -0
- data/reference/Directories_8hpp.html +46 -0
- data/reference/Font_8hpp-source.html +65 -0
- data/reference/Font_8hpp.html +41 -0
- data/reference/Fwd_8hpp-source.html +52 -0
- data/reference/Fwd_8hpp.html +37 -0
- data/reference/Gosu_8hpp-source.html +48 -0
- data/reference/Gosu_8hpp.html +34 -0
- data/reference/GraphicsBase_8hpp-source.html +57 -0
- data/reference/GraphicsBase_8hpp.html +56 -0
- data/reference/Graphics_8hpp-source.html +96 -0
- data/reference/Graphics_8hpp.html +53 -0
- data/reference/IO_8hpp-source.html +255 -0
- data/reference/IO_8hpp.html +74 -0
- data/reference/ImageData_8hpp-source.html +62 -0
- data/reference/ImageData_8hpp.html +43 -0
- data/reference/Image_8hpp-source.html +126 -0
- data/reference/Image_8hpp.html +48 -0
- data/reference/Input_8hpp-source.html +118 -0
- data/reference/Input_8hpp.html +50 -0
- data/reference/Math_8hpp-source.html +92 -0
- data/reference/Math_8hpp.html +74 -0
- data/reference/Platform_8hpp-source.html +83 -0
- data/reference/Platform_8hpp.html +73 -0
- data/reference/RotFlip_8hpp-source.html +138 -0
- data/reference/RotFlip_8hpp.html +77 -0
- data/reference/Sockets_8hpp-source.html +130 -0
- data/reference/Sockets_8hpp.html +66 -0
- data/reference/TextInput_8hpp-source.html +64 -0
- data/reference/TextInput_8hpp.html +41 -0
- data/reference/Text_8hpp-source.html +51 -0
- data/reference/Text_8hpp.html +46 -0
- data/reference/Timing_8hpp-source.html +36 -0
- data/reference/Timing_8hpp.html +42 -0
- data/reference/Utility_8hpp-source.html +44 -0
- data/reference/Utility_8hpp.html +48 -0
- data/reference/WinUtility_8hpp-source.html +79 -0
- data/reference/WinUtility_8hpp.html +64 -0
- data/reference/Window_8hpp-source.html +91 -0
- data/reference/Window_8hpp.html +41 -0
- data/reference/annotated.html +51 -0
- data/reference/classGosu_1_1Audio-members.html +34 -0
- data/reference/classGosu_1_1Audio.html +46 -0
- data/reference/classGosu_1_1Bitmap-members.html +44 -0
- data/reference/classGosu_1_1Bitmap.html +263 -0
- data/reference/classGosu_1_1Buffer-members.html +44 -0
- data/reference/classGosu_1_1Buffer.html +78 -0
- data/reference/classGosu_1_1Buffer.png +0 -0
- data/reference/classGosu_1_1Button-members.html +36 -0
- data/reference/classGosu_1_1Button.html +143 -0
- data/reference/classGosu_1_1Color-members.html +56 -0
- data/reference/classGosu_1_1Color.html +387 -0
- data/reference/classGosu_1_1File-members.html +41 -0
- data/reference/classGosu_1_1File.html +69 -0
- data/reference/classGosu_1_1File.png +0 -0
- data/reference/classGosu_1_1Font-members.html +39 -0
- data/reference/classGosu_1_1Font.html +309 -0
- data/reference/classGosu_1_1Graphics-members.html +50 -0
- data/reference/classGosu_1_1Graphics.html +234 -0
- data/reference/classGosu_1_1Image-members.html +45 -0
- data/reference/classGosu_1_1Image.html +518 -0
- data/reference/classGosu_1_1ImageData-members.html +37 -0
- data/reference/classGosu_1_1ImageData.html +60 -0
- data/reference/classGosu_1_1Input-members.html +44 -0
- data/reference/classGosu_1_1Input.html +223 -0
- data/reference/classGosu_1_1MessageSocket-members.html +40 -0
- data/reference/classGosu_1_1MessageSocket.html +233 -0
- data/reference/classGosu_1_1Resource-members.html +39 -0
- data/reference/classGosu_1_1Resource.html +116 -0
- data/reference/classGosu_1_1Resource.png +0 -0
- data/reference/classGosu_1_1Sample-members.html +37 -0
- data/reference/classGosu_1_1Sample.html +200 -0
- data/reference/classGosu_1_1SampleInstance-members.html +38 -0
- data/reference/classGosu_1_1SampleInstance.html +169 -0
- data/reference/classGosu_1_1Song-members.html +43 -0
- data/reference/classGosu_1_1Song.html +260 -0
- data/reference/classGosu_1_1TextInput-members.html +38 -0
- data/reference/classGosu_1_1TextInput.html +121 -0
- data/reference/classGosu_1_1Window-members.html +50 -0
- data/reference/classGosu_1_1Window.html +271 -0
- data/reference/doxyfile +233 -0
- data/reference/doxygen.css +433 -0
- data/reference/doxygen.png +0 -0
- data/reference/files.html +54 -0
- data/reference/functions.html +236 -0
- data/reference/functions_enum.html +45 -0
- data/reference/functions_func.html +227 -0
- data/reference/functions_vars.html +47 -0
- data/reference/hierarchy.html +53 -0
- data/reference/index.html +26 -0
- data/reference/namespaceGosu.html +2890 -0
- data/reference/namespaceGosu_1_1Colors.html +70 -0
- data/reference/namespaceGosu_1_1Win.html +275 -0
- data/reference/namespacemembers.html +216 -0
- data/reference/namespacemembers_enum.html +52 -0
- data/reference/namespacemembers_eval.html +54 -0
- data/reference/namespacemembers_func.html +185 -0
- data/reference/namespacemembers_type.html +46 -0
- data/reference/namespacemembers_vars.html +46 -0
- data/reference/namespaces.html +35 -0
- data/reference/tab_b.gif +0 -0
- data/reference/tab_l.gif +0 -0
- data/reference/tab_r.gif +0 -0
- data/reference/tabs.css +102 -0
- data/windows/Gosu.sln +29 -0
- data/windows/Gosu.vcproj +553 -0
- data/windows/RubyGosu.vcproj +138 -0
- metadata +305 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
#ifndef GOSUIMPL_BLOCKALLOCATOR_HPP
|
2
|
+
#define GOSUIMPL_BLOCKALLOCATOR_HPP
|
3
|
+
|
4
|
+
#include <boost/optional.hpp>
|
5
|
+
#include <boost/scoped_ptr.hpp>
|
6
|
+
|
7
|
+
namespace Gosu
|
8
|
+
{
|
9
|
+
class BlockAllocator
|
10
|
+
{
|
11
|
+
struct Impl;
|
12
|
+
boost::scoped_ptr<Impl> pimpl;
|
13
|
+
|
14
|
+
public:
|
15
|
+
struct Block
|
16
|
+
{
|
17
|
+
unsigned left, top, width, height;
|
18
|
+
Block() {}
|
19
|
+
Block(unsigned aLeft, unsigned aTop, unsigned aWidth, unsigned aHeight)
|
20
|
+
: left(aLeft), top(aTop), width(aWidth), height(aHeight) {}
|
21
|
+
};
|
22
|
+
|
23
|
+
BlockAllocator(unsigned width, unsigned height);
|
24
|
+
~BlockAllocator();
|
25
|
+
|
26
|
+
unsigned width() const;
|
27
|
+
unsigned height() const;
|
28
|
+
|
29
|
+
boost::optional<Block> alloc(unsigned width, unsigned height);
|
30
|
+
void free(unsigned left, unsigned top);
|
31
|
+
};
|
32
|
+
}
|
33
|
+
|
34
|
+
#endif
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#include <Gosu/Color.hpp>
|
2
|
+
#include <Gosu/Math.hpp>
|
3
|
+
#include <algorithm>
|
4
|
+
|
5
|
+
namespace
|
6
|
+
{
|
7
|
+
struct HSV { double h, s, v; };
|
8
|
+
|
9
|
+
HSV colorToHSV(const Gosu::Color& c)
|
10
|
+
{
|
11
|
+
double r = c.red() / 255.0;
|
12
|
+
double g = c.green() / 255.0;
|
13
|
+
double b = c.blue() / 255.0;
|
14
|
+
|
15
|
+
double min = std::min(std::min(r, g), b);
|
16
|
+
double max = std::max(std::max(r, g), b);
|
17
|
+
|
18
|
+
if (max == 0)
|
19
|
+
{
|
20
|
+
HSV hsv = { 0, 0, 0 };
|
21
|
+
return hsv;
|
22
|
+
}
|
23
|
+
|
24
|
+
// Value.
|
25
|
+
HSV hsv = { -1, -1, max };
|
26
|
+
|
27
|
+
// Saturation.
|
28
|
+
double delta = max - min;
|
29
|
+
hsv.s = delta / max;
|
30
|
+
|
31
|
+
// Hue.
|
32
|
+
if (r == max)
|
33
|
+
hsv.h = (g - b) / delta + (g < b ? 6 : 0);
|
34
|
+
else if (g == max)
|
35
|
+
hsv.h = (b - r) / delta + 2;
|
36
|
+
else
|
37
|
+
hsv.h = (r - g) / delta + 4;
|
38
|
+
hsv.h *= 60;
|
39
|
+
|
40
|
+
return hsv;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
Gosu::Color Gosu::Color::fromHSV(double h, double s, double v)
|
45
|
+
{
|
46
|
+
return fromAHSV(255, h, s, v);
|
47
|
+
}
|
48
|
+
|
49
|
+
Gosu::Color Gosu::Color::fromAHSV(Channel alpha, double h, double s, double v)
|
50
|
+
{
|
51
|
+
if (s == 0)
|
52
|
+
// Grey.
|
53
|
+
return Color(alpha, v * 255, v * 255, v * 255);
|
54
|
+
|
55
|
+
// Normalize hue
|
56
|
+
h = ((static_cast<int>(h) % 360) + 360) % 360;
|
57
|
+
|
58
|
+
int sector = h / 60;
|
59
|
+
double factorial = h / 60 - sector;
|
60
|
+
|
61
|
+
double p = v * (1 - s);
|
62
|
+
double q = v * (1 - s * factorial);
|
63
|
+
double t = v * (1 - s * (1 - factorial));
|
64
|
+
|
65
|
+
switch (sector)
|
66
|
+
{
|
67
|
+
case 0:
|
68
|
+
return Color(alpha, v * 255, t * 255, p * 255);
|
69
|
+
case 1:
|
70
|
+
return Color(alpha, q * 255, v * 255, p * 255);
|
71
|
+
case 2:
|
72
|
+
return Color(alpha, p * 255, v * 255, t * 255);
|
73
|
+
case 3:
|
74
|
+
return Color(alpha, p * 255, q * 255, v * 255);
|
75
|
+
case 4:
|
76
|
+
return Color(alpha, t * 255, p * 255, v * 255);
|
77
|
+
default: // sector 5
|
78
|
+
return Color(alpha, v * 255, p * 255, q * 255);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
double Gosu::Color::hue() const
|
83
|
+
{
|
84
|
+
return colorToHSV(*this).h;
|
85
|
+
}
|
86
|
+
|
87
|
+
void Gosu::Color::setHue(double h)
|
88
|
+
{
|
89
|
+
*this = fromAHSV(alpha(), h, saturation(), value());
|
90
|
+
}
|
91
|
+
|
92
|
+
double Gosu::Color::saturation() const
|
93
|
+
{
|
94
|
+
return colorToHSV(*this).s;
|
95
|
+
}
|
96
|
+
|
97
|
+
void Gosu::Color::setSaturation(double s)
|
98
|
+
{
|
99
|
+
*this = fromAHSV(alpha(), hue(), s, value());
|
100
|
+
}
|
101
|
+
|
102
|
+
double Gosu::Color::value() const
|
103
|
+
{
|
104
|
+
return colorToHSV(*this).v;
|
105
|
+
}
|
106
|
+
|
107
|
+
void Gosu::Color::setValue(double v)
|
108
|
+
{
|
109
|
+
*this = fromAHSV(alpha(), hue(), saturation(), v);
|
110
|
+
}
|
111
|
+
|
112
|
+
Gosu::Color Gosu::interpolate(Color a, Color b, double weight)
|
113
|
+
{
|
114
|
+
return Color(clamp<int>(round(Gosu::interpolate(a.alpha(), b.alpha(), weight)), 0, 255),
|
115
|
+
clamp<int>(round(Gosu::interpolate(a.red(), b.red(), weight)), 0, 255),
|
116
|
+
clamp<int>(round(Gosu::interpolate(a.green(), b.green(), weight)), 0, 255),
|
117
|
+
clamp<int>(round(Gosu::interpolate(a.blue(), b.blue(), weight)), 0, 255));
|
118
|
+
}
|
119
|
+
|
120
|
+
Gosu::Color Gosu::multiply(Color a, Color b)
|
121
|
+
{
|
122
|
+
return Color(round(a.alpha() * b.alpha() / 255.0),
|
123
|
+
round(a.red() * b.red() / 255.0),
|
124
|
+
round(a.green() * b.green() / 255.0),
|
125
|
+
round(a.blue() * b.blue() / 255.0));
|
126
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#ifndef GOSUIMPL_GRAPHICS_COMMON_HPP
|
2
|
+
#define GOSUIMPL_GRAPHICS_COMMON_HPP
|
3
|
+
|
4
|
+
#ifdef WIN32
|
5
|
+
#include <windows.h>
|
6
|
+
#endif
|
7
|
+
#ifdef __APPLE__
|
8
|
+
#include <OpenGL/gl.h>
|
9
|
+
#else
|
10
|
+
#include <GL/gl.h>
|
11
|
+
#endif
|
12
|
+
|
13
|
+
namespace Gosu
|
14
|
+
{
|
15
|
+
class Texture;
|
16
|
+
class TexChunk;
|
17
|
+
struct DrawOp;
|
18
|
+
class DrawOpQueue;
|
19
|
+
}
|
20
|
+
|
21
|
+
#endif
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#ifndef GOSUIMPL_DRAWOP_HPP
|
2
|
+
#define GOSUIMPL_DRAWOP_HPP
|
3
|
+
|
4
|
+
#include <Gosu/GraphicsBase.hpp>
|
5
|
+
#include <Gosu/Color.hpp>
|
6
|
+
#include <GosuImpl/Graphics/Common.hpp>
|
7
|
+
#include <GosuImpl/Graphics/TexChunk.hpp>
|
8
|
+
#include <set>
|
9
|
+
|
10
|
+
namespace Gosu
|
11
|
+
{
|
12
|
+
struct DrawOp
|
13
|
+
{
|
14
|
+
int clipX, clipY;
|
15
|
+
unsigned clipWidth, clipHeight;
|
16
|
+
|
17
|
+
struct Vertex
|
18
|
+
{
|
19
|
+
double x, y;
|
20
|
+
Color c;
|
21
|
+
Vertex() {}
|
22
|
+
Vertex(double x, double y, Color c) : x(x), y(y), c(c) {}
|
23
|
+
};
|
24
|
+
|
25
|
+
ZPos z;
|
26
|
+
Vertex vertices[4];
|
27
|
+
unsigned usedVertices;
|
28
|
+
const TexChunk* chunk;
|
29
|
+
AlphaMode mode;
|
30
|
+
|
31
|
+
DrawOp() { clipWidth = 0xffffffff; usedVertices = 0; chunk = 0; }
|
32
|
+
|
33
|
+
void perform() const
|
34
|
+
{
|
35
|
+
if (clipWidth != 0xffffffff)
|
36
|
+
{
|
37
|
+
glEnable(GL_SCISSOR_TEST);
|
38
|
+
glScissor(clipX, clipY, clipWidth, clipHeight);
|
39
|
+
}
|
40
|
+
|
41
|
+
if (mode == amAdditive)
|
42
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
43
|
+
else
|
44
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
45
|
+
|
46
|
+
if (chunk)
|
47
|
+
{
|
48
|
+
glEnable(GL_TEXTURE_2D);
|
49
|
+
glBindTexture(GL_TEXTURE_2D, chunk->texName());
|
50
|
+
}
|
51
|
+
|
52
|
+
if (usedVertices == 2)
|
53
|
+
glBegin(GL_LINES);
|
54
|
+
else if (usedVertices == 3)
|
55
|
+
glBegin(GL_TRIANGLES);
|
56
|
+
else if (usedVertices == 4)
|
57
|
+
glBegin(GL_QUADS);
|
58
|
+
|
59
|
+
double left, top, right, bottom;
|
60
|
+
if (chunk)
|
61
|
+
chunk->getCoords(left, top, right, bottom);
|
62
|
+
|
63
|
+
for (unsigned i = 0; i < usedVertices; i++)
|
64
|
+
{
|
65
|
+
glColor4f(vertices[i].c.red() / 255.0, vertices[i].c.green() / 255.0,
|
66
|
+
vertices[i].c.blue() / 255.0, vertices[i].c.alpha() / 255.0);
|
67
|
+
if (chunk)
|
68
|
+
switch (i)
|
69
|
+
{
|
70
|
+
case 0:
|
71
|
+
glTexCoord2d(left, top);
|
72
|
+
break;
|
73
|
+
case 1:
|
74
|
+
glTexCoord2d(right, top);
|
75
|
+
break;
|
76
|
+
case 2:
|
77
|
+
glTexCoord2d(right, bottom);
|
78
|
+
break;
|
79
|
+
case 3:
|
80
|
+
glTexCoord2d(left, bottom);
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
glVertex2d(vertices[i].x, vertices[i].y);
|
84
|
+
}
|
85
|
+
|
86
|
+
glEnd();
|
87
|
+
|
88
|
+
if (chunk)
|
89
|
+
glDisable(GL_TEXTURE_2D);
|
90
|
+
|
91
|
+
if (clipWidth != 0xffffffff)
|
92
|
+
glDisable(GL_SCISSOR_TEST);
|
93
|
+
}
|
94
|
+
|
95
|
+
bool operator<(const DrawOp& other) const
|
96
|
+
{
|
97
|
+
return z < other.z; // optimization starts TODAY
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
class DrawOpQueue
|
102
|
+
{
|
103
|
+
int clipX, clipY;
|
104
|
+
unsigned clipWidth, clipHeight;
|
105
|
+
std::multiset<DrawOp> set;
|
106
|
+
|
107
|
+
public:
|
108
|
+
DrawOpQueue()
|
109
|
+
: clipWidth(0xffffffff)
|
110
|
+
{
|
111
|
+
}
|
112
|
+
|
113
|
+
void addDrawOp(DrawOp op, ZPos z)
|
114
|
+
{
|
115
|
+
op.z = z;
|
116
|
+
if (clipWidth != 0xffffffff)
|
117
|
+
{
|
118
|
+
op.clipX = clipX;
|
119
|
+
op.clipY = clipY;
|
120
|
+
op.clipWidth = clipWidth;
|
121
|
+
op.clipHeight = clipHeight;
|
122
|
+
}
|
123
|
+
set.insert(op);
|
124
|
+
}
|
125
|
+
|
126
|
+
void beginClipping(int x, int y, unsigned width, unsigned height)
|
127
|
+
{
|
128
|
+
clipX = x;
|
129
|
+
clipY = y;
|
130
|
+
clipWidth = width;
|
131
|
+
clipHeight = height;
|
132
|
+
}
|
133
|
+
|
134
|
+
void endClipping()
|
135
|
+
{
|
136
|
+
clipWidth = 0xffffffff;
|
137
|
+
}
|
138
|
+
|
139
|
+
void performDrawOps()
|
140
|
+
{
|
141
|
+
std::multiset<DrawOp>::iterator cur = set.begin(), end = set.end();
|
142
|
+
while (cur != end)
|
143
|
+
{
|
144
|
+
cur->perform();
|
145
|
+
++cur;
|
146
|
+
}
|
147
|
+
set.clear();
|
148
|
+
}
|
149
|
+
};
|
150
|
+
}
|
151
|
+
|
152
|
+
#endif
|
153
|
+
|
154
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#include <Gosu/Font.hpp>
|
2
|
+
#include <Gosu/Graphics.hpp>
|
3
|
+
#include <Gosu/Image.hpp>
|
4
|
+
#include <Gosu/Math.hpp>
|
5
|
+
#include <Gosu/Text.hpp>
|
6
|
+
#include <boost/array.hpp>
|
7
|
+
using namespace std;
|
8
|
+
|
9
|
+
struct Gosu::Font::Impl
|
10
|
+
{
|
11
|
+
Graphics* graphics;
|
12
|
+
wstring fontName;
|
13
|
+
unsigned height;
|
14
|
+
|
15
|
+
// Chunk of 2^16 characters (on Windows, there'll only be one of them).
|
16
|
+
// IMPR: I couldn't find a way to determine the size of wchar_t at compile
|
17
|
+
// time, so I can't get rid of the magic numbers or even do some #ifdef
|
18
|
+
// magic.
|
19
|
+
typedef boost::array<boost::scoped_ptr<Image>, 65536> CharChunk;
|
20
|
+
boost::scoped_ptr<CharChunk> chunks[65536];
|
21
|
+
|
22
|
+
Image& getChar(wchar_t wc)
|
23
|
+
{
|
24
|
+
size_t chunkIndex = wc / 65536;
|
25
|
+
size_t charIndex = wc % 65536;
|
26
|
+
|
27
|
+
if (!chunks[chunkIndex])
|
28
|
+
chunks[chunkIndex].reset(new CharChunk);
|
29
|
+
|
30
|
+
boost::scoped_ptr<Image>& imgPtr = (*chunks[chunkIndex])[charIndex];
|
31
|
+
|
32
|
+
if (imgPtr)
|
33
|
+
return *imgPtr;
|
34
|
+
|
35
|
+
wstring charString(1, wc);
|
36
|
+
unsigned charWidth = Gosu::textWidth(charString, fontName, height, ffBold);
|
37
|
+
Bitmap bmp;
|
38
|
+
bmp.resize(charWidth, height);
|
39
|
+
|
40
|
+
drawText(bmp, charString, 0, 0, Colors::white, fontName, height, ffBold);
|
41
|
+
imgPtr.reset(new Image(*graphics, bmp));
|
42
|
+
return *imgPtr;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
Gosu::Font::Font(Graphics& graphics, const wstring& fontName, unsigned height)
|
47
|
+
: pimpl(new Impl)
|
48
|
+
{
|
49
|
+
pimpl->graphics = &graphics;
|
50
|
+
pimpl->fontName = fontName;
|
51
|
+
pimpl->height = height * 2; // Auto-AA!
|
52
|
+
}
|
53
|
+
|
54
|
+
Gosu::Font::~Font()
|
55
|
+
{
|
56
|
+
}
|
57
|
+
|
58
|
+
unsigned Gosu::Font::height() const
|
59
|
+
{
|
60
|
+
return pimpl->height / 2;
|
61
|
+
}
|
62
|
+
|
63
|
+
double Gosu::Font::textWidth(const std::wstring& text, double factorX) const
|
64
|
+
{
|
65
|
+
double result = 0;
|
66
|
+
for (unsigned i = 0; i < text.length(); ++i)
|
67
|
+
result += pimpl->getChar(text[i]).width();
|
68
|
+
return result * factorX / 2;
|
69
|
+
}
|
70
|
+
|
71
|
+
void Gosu::Font::draw(const wstring& text, double x, double y, ZPos z,
|
72
|
+
double factorX, double factorY, Color c, AlphaMode mode) const
|
73
|
+
{
|
74
|
+
factorX /= 2;
|
75
|
+
factorY /= 2;
|
76
|
+
|
77
|
+
for (unsigned i = 0; i < text.length(); ++i)
|
78
|
+
{
|
79
|
+
Image& curChar = pimpl->getChar(text[i]);
|
80
|
+
curChar.draw(x, y, z, factorX, factorY, c, mode);
|
81
|
+
x += curChar.width() * factorX;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
void Gosu::Font::drawRel(const wstring& text, double x, double y, ZPos z,
|
86
|
+
double relX, double relY, double factorX, double factorY, Color c,
|
87
|
+
AlphaMode mode) const
|
88
|
+
{
|
89
|
+
x -= textWidth(text) * factorX * relX;
|
90
|
+
y -= height() * factorY * relY;
|
91
|
+
|
92
|
+
draw(text, x, y, z, factorX, factorY, c, mode);
|
93
|
+
}
|
94
|
+
|
95
|
+
void Gosu::Font::drawRot(const wstring& text, double x, double y, ZPos z, double angle,
|
96
|
+
double factorX, double factorY, Color c, AlphaMode mode) const
|
97
|
+
{
|
98
|
+
factorX /= 2;
|
99
|
+
factorY /= 2;
|
100
|
+
|
101
|
+
double stepX = offsetX(angle + 90, 1.0), stepY = offsetY(angle + 90, 1.0);
|
102
|
+
|
103
|
+
for (unsigned i = 0; i < text.length(); ++i)
|
104
|
+
{
|
105
|
+
Image& curChar = pimpl->getChar(text[i]);
|
106
|
+
curChar.drawRot(x, y, z, angle, 0.0, 0.0, factorX, factorY, c, mode);
|
107
|
+
x += curChar.width() * factorX * stepX;
|
108
|
+
y += curChar.width() * factorX * stepY;
|
109
|
+
}
|
110
|
+
}
|