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,45 @@
|
|
1
|
+
//! \file GraphicsBase.hpp
|
2
|
+
//! Contains general typedefs and enums related to graphics.
|
3
|
+
|
4
|
+
#ifndef GOSU_GRAPHICSBASE_HPP
|
5
|
+
#define GOSU_GRAPHICSBASE_HPP
|
6
|
+
|
7
|
+
#include <boost/cstdint.hpp>
|
8
|
+
|
9
|
+
namespace Gosu
|
10
|
+
{
|
11
|
+
//! Represents the Z position of something drawn with Gosu's graphics
|
12
|
+
//! system. Draw calls with higher ZPos values will cover those with a
|
13
|
+
//! lower ZPos value, that is, they are performed last.
|
14
|
+
typedef double ZPos;
|
15
|
+
|
16
|
+
//! Determines the way colors are combined when one is drawn onto
|
17
|
+
//! another.
|
18
|
+
enum AlphaMode
|
19
|
+
{
|
20
|
+
//! The color's channels will be interpolated. The alpha channel
|
21
|
+
//! specifies the opacity of the new color, 255 is full opacity.
|
22
|
+
amDefault,
|
23
|
+
//! The colors' channels will be added. The alpha channel specifies
|
24
|
+
//! the percentage of the new color's channels that will be added
|
25
|
+
//! to the old color's channels.
|
26
|
+
amAdditive
|
27
|
+
};
|
28
|
+
|
29
|
+
enum FontFlags
|
30
|
+
{
|
31
|
+
ffBold = 1,
|
32
|
+
ffItalic = 2,
|
33
|
+
ffUnderline = 4
|
34
|
+
};
|
35
|
+
|
36
|
+
enum TextAlign
|
37
|
+
{
|
38
|
+
taLeft,
|
39
|
+
taRight,
|
40
|
+
taCenter,
|
41
|
+
taJustify
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
#endif
|
data/Gosu/IO.hpp
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
//! \file IO.hpp
|
2
|
+
//! Contains everything related to input and output.
|
3
|
+
|
4
|
+
#ifndef GOSU_IO_HPP
|
5
|
+
#define GOSU_IO_HPP
|
6
|
+
|
7
|
+
#include <boost/utility.hpp>
|
8
|
+
#include <boost/scoped_ptr.hpp>
|
9
|
+
#include <cstddef>
|
10
|
+
#include <algorithm>
|
11
|
+
#include <string>
|
12
|
+
#include <vector>
|
13
|
+
|
14
|
+
namespace Gosu
|
15
|
+
{
|
16
|
+
class Resource;
|
17
|
+
|
18
|
+
enum ByteOrder { boLittle, boBig, boDontCare };
|
19
|
+
#ifdef __BIG_ENDIAN__
|
20
|
+
const ByteOrder nativeByteOrder = boBig, otherByteOrder = boLittle;
|
21
|
+
#else
|
22
|
+
const ByteOrder nativeByteOrder = boLittle, otherByteOrder = boBig;
|
23
|
+
#endif
|
24
|
+
|
25
|
+
class Reader
|
26
|
+
{
|
27
|
+
const Resource* res;
|
28
|
+
std::size_t pos;
|
29
|
+
|
30
|
+
public:
|
31
|
+
Reader(const Resource& resource, std::size_t position)
|
32
|
+
: res(&resource), pos(position)
|
33
|
+
{
|
34
|
+
}
|
35
|
+
|
36
|
+
const Resource& resource() const
|
37
|
+
{
|
38
|
+
return *res;
|
39
|
+
}
|
40
|
+
|
41
|
+
std::size_t position() const
|
42
|
+
{
|
43
|
+
return pos;
|
44
|
+
}
|
45
|
+
|
46
|
+
void setPosition(std::size_t value)
|
47
|
+
{
|
48
|
+
// TODO: Check?
|
49
|
+
pos = value;
|
50
|
+
}
|
51
|
+
|
52
|
+
void seek(std::ptrdiff_t offset)
|
53
|
+
{
|
54
|
+
// TODO: Check?
|
55
|
+
pos += offset;
|
56
|
+
}
|
57
|
+
|
58
|
+
void read(void* destBuffer, std::size_t length);
|
59
|
+
|
60
|
+
//! Convenience function; equivalent to read(&t, sizeof t).
|
61
|
+
template<typename T>
|
62
|
+
void readPod(T& t, ByteOrder bo = boDontCare)
|
63
|
+
{
|
64
|
+
read(&t, sizeof t);
|
65
|
+
if (bo == otherByteOrder)
|
66
|
+
{
|
67
|
+
char* begin = reinterpret_cast<char*>(&t);
|
68
|
+
std::reverse(begin, begin + sizeof t);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
//! Similar to readPod(T&), but returns the read value instead.
|
73
|
+
template<typename T>
|
74
|
+
T getPod(ByteOrder bo = boDontCare)
|
75
|
+
{
|
76
|
+
T t;
|
77
|
+
readPod<T>(t, bo);
|
78
|
+
return t;
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
class Writer
|
83
|
+
{
|
84
|
+
Resource* res;
|
85
|
+
std::size_t pos;
|
86
|
+
|
87
|
+
public:
|
88
|
+
Writer(Resource& resource, std::size_t position)
|
89
|
+
: res(&resource), pos(position)
|
90
|
+
{
|
91
|
+
}
|
92
|
+
|
93
|
+
Resource& resource() const
|
94
|
+
{
|
95
|
+
return *res;
|
96
|
+
}
|
97
|
+
|
98
|
+
std::size_t position() const
|
99
|
+
{
|
100
|
+
return pos;
|
101
|
+
}
|
102
|
+
|
103
|
+
void setPosition(std::size_t value)
|
104
|
+
{
|
105
|
+
// TODO: Check?
|
106
|
+
pos = value;
|
107
|
+
}
|
108
|
+
|
109
|
+
void seek(std::ptrdiff_t offset)
|
110
|
+
{
|
111
|
+
// TODO: Check?
|
112
|
+
pos += offset;
|
113
|
+
}
|
114
|
+
|
115
|
+
void write(const void* sourceBuffer, std::size_t length);
|
116
|
+
|
117
|
+
//! Convenience function; equivalent to write(&t, sizeof t).
|
118
|
+
template<typename T>
|
119
|
+
void writePod(const T& t, ByteOrder bo = boDontCare)
|
120
|
+
{
|
121
|
+
if (bo == otherByteOrder)
|
122
|
+
{
|
123
|
+
char buf[sizeof t];
|
124
|
+
const char* begin = reinterpret_cast<const char*>(&t);
|
125
|
+
std::reverse_copy(begin, begin + sizeof t, buf);
|
126
|
+
write(buf, sizeof buf);
|
127
|
+
}
|
128
|
+
else
|
129
|
+
write(&t, sizeof t);
|
130
|
+
}
|
131
|
+
};
|
132
|
+
|
133
|
+
//! Base class for resources. A resource in Gosu is nothing more but a
|
134
|
+
//! piece of binary data that can be read or written, for example files
|
135
|
+
//! or simply areas of allocated memory.
|
136
|
+
//! A resource always knows its size and can resize itself, thereby either
|
137
|
+
//! truncating its content or allocating room for more data.
|
138
|
+
class Resource : boost::noncopyable
|
139
|
+
{
|
140
|
+
public:
|
141
|
+
virtual ~Resource()
|
142
|
+
{
|
143
|
+
}
|
144
|
+
|
145
|
+
//! Convenience: Creates a new Reader that reads from the start of
|
146
|
+
//! the resource.
|
147
|
+
Reader frontReader() const
|
148
|
+
{
|
149
|
+
return Reader(*this, 0);
|
150
|
+
}
|
151
|
+
|
152
|
+
//! Convenience: Creates a new Writer that appends data at the
|
153
|
+
//! end of the resource.
|
154
|
+
Writer backWriter()
|
155
|
+
{
|
156
|
+
return Writer(*this, size());
|
157
|
+
}
|
158
|
+
|
159
|
+
virtual std::size_t size() const = 0;
|
160
|
+
|
161
|
+
virtual void resize(std::size_t newSize) = 0;
|
162
|
+
|
163
|
+
virtual void read(std::size_t offset, std::size_t length,
|
164
|
+
void* destBuffer) const = 0;
|
165
|
+
|
166
|
+
virtual void write(std::size_t offset, std::size_t length,
|
167
|
+
const void* sourceBuffer) = 0;
|
168
|
+
};
|
169
|
+
|
170
|
+
//! Piece of memory with the Resource interface.
|
171
|
+
class Buffer : public Resource
|
172
|
+
{
|
173
|
+
std::vector<char> buf;
|
174
|
+
|
175
|
+
public:
|
176
|
+
Buffer()
|
177
|
+
{
|
178
|
+
}
|
179
|
+
|
180
|
+
Buffer(const Buffer& other)
|
181
|
+
: buf(other.buf)
|
182
|
+
{
|
183
|
+
}
|
184
|
+
|
185
|
+
Buffer& operator=(const Buffer& other)
|
186
|
+
{
|
187
|
+
buf = other.buf;
|
188
|
+
return *this;
|
189
|
+
}
|
190
|
+
|
191
|
+
std::size_t size() const
|
192
|
+
{
|
193
|
+
return buf.size();
|
194
|
+
}
|
195
|
+
|
196
|
+
void resize(std::size_t newSize)
|
197
|
+
{
|
198
|
+
buf.resize(newSize);
|
199
|
+
}
|
200
|
+
|
201
|
+
void read(std::size_t offset, std::size_t length,
|
202
|
+
void* destBuffer) const;
|
203
|
+
|
204
|
+
void write(std::size_t offset, std::size_t length,
|
205
|
+
const void* sourceBuffer);
|
206
|
+
|
207
|
+
const void* data() const
|
208
|
+
{
|
209
|
+
return &buf[0];
|
210
|
+
}
|
211
|
+
|
212
|
+
void* data()
|
213
|
+
{
|
214
|
+
return &buf[0];
|
215
|
+
}
|
216
|
+
};
|
217
|
+
|
218
|
+
enum FileMode
|
219
|
+
{
|
220
|
+
//! Opens an existing file for reading; throws an exception if the file
|
221
|
+
//! cannot be found.
|
222
|
+
fmRead,
|
223
|
+
//! Writes data to a file. If the file already exists, is emptied on
|
224
|
+
//! opening. If the file does not exist, it is created.
|
225
|
+
fmReplace,
|
226
|
+
//! Opens or creates a file with writing access, but does not clear
|
227
|
+
//! existing contents.
|
228
|
+
fmAlter
|
229
|
+
};
|
230
|
+
|
231
|
+
//! File with the Resource interface.
|
232
|
+
class File : public Resource
|
233
|
+
{
|
234
|
+
struct Impl;
|
235
|
+
boost::scoped_ptr<Impl> pimpl;
|
236
|
+
|
237
|
+
public:
|
238
|
+
explicit File(const std::wstring& filename, FileMode mode = fmRead);
|
239
|
+
~File();
|
240
|
+
|
241
|
+
std::size_t size() const;
|
242
|
+
void resize(std::size_t newSize);
|
243
|
+
void read(std::size_t offset, std::size_t length,
|
244
|
+
void* destBuffer) const;
|
245
|
+
void write(std::size_t offset, std::size_t length,
|
246
|
+
const void* sourceBuffer);
|
247
|
+
};
|
248
|
+
|
249
|
+
//! Loads a whole file into a buffer.
|
250
|
+
void loadFile(Buffer& buffer, const std::wstring& filename);
|
251
|
+
//! Creates or overwrites a file with the contents of a buffer.
|
252
|
+
void saveFile(const Buffer& buffer, const std::wstring& filename);
|
253
|
+
}
|
254
|
+
|
255
|
+
#endif
|
data/Gosu/Image.hpp
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
//! \file Image.hpp
|
2
|
+
//! Interface of the Image class and helper functions.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGE_HPP
|
5
|
+
#define GOSU_IMAGE_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Bitmap.hpp>
|
9
|
+
#include <Gosu/RotFlip.hpp>
|
10
|
+
#include <boost/scoped_ptr.hpp>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! Provides functionality for drawing rectangular images.
|
15
|
+
class Image
|
16
|
+
{
|
17
|
+
boost::scoped_ptr<ImageData> data;
|
18
|
+
|
19
|
+
public:
|
20
|
+
//! Loads an image from a given filename that can be drawn onto
|
21
|
+
//! graphics.
|
22
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
23
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
24
|
+
//! corresponding constructor that uses a Bitmap object.
|
25
|
+
Image(Graphics& graphics, const std::wstring& filename,
|
26
|
+
bool hardBorders = false);
|
27
|
+
//! Loads a portion of the the image at the given filename that can be
|
28
|
+
//! drawn onto graphics.
|
29
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
30
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
31
|
+
//! corresponding constructor that uses a Bitmap object.
|
32
|
+
Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
|
33
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
34
|
+
bool hardBorders = false);
|
35
|
+
|
36
|
+
//! Converts the given bitmap into an image that can be drawn onto
|
37
|
+
//! graphics.
|
38
|
+
Image(Graphics& graphics, const Bitmap& source,
|
39
|
+
bool hardBorders = false);
|
40
|
+
//! Converts a portion of the given bitmap into an image that can be
|
41
|
+
//! drawn onto graphics.
|
42
|
+
Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
|
43
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
44
|
+
bool hardBorders = false);
|
45
|
+
|
46
|
+
~Image();
|
47
|
+
|
48
|
+
unsigned width() const;
|
49
|
+
unsigned height() const;
|
50
|
+
|
51
|
+
//! Draws the image so its upper left corner is at (x; y).
|
52
|
+
void draw(double x, double y, ZPos z,
|
53
|
+
double factorX = 1, double factorY = 1,
|
54
|
+
Color c = Colors::white,
|
55
|
+
AlphaMode mode = amDefault) const;
|
56
|
+
//! Like draw(), but allows to give modulation colors for all four
|
57
|
+
//! corners.
|
58
|
+
void drawMod(double x, double y, ZPos z,
|
59
|
+
double factorX, double factorY,
|
60
|
+
Color c1, Color c2, Color c3, Color c4,
|
61
|
+
AlphaMode mode = amDefault) const;
|
62
|
+
|
63
|
+
//! Draws the image rotated by the given angle so that its rotation
|
64
|
+
//! center is at (x; y). Note that this is different from how all the
|
65
|
+
//! other drawing functions work!
|
66
|
+
//! \param angle See Math.hpp for an explanation of how Gosu interprets
|
67
|
+
//! angles.
|
68
|
+
//! \param centerX Relative horizontal position of the rotation center
|
69
|
+
//! on the image. 0 is the left border, 1 is the right border, 0.5 is
|
70
|
+
//! the center (and default).
|
71
|
+
//! \param centerY See centerX.
|
72
|
+
void drawRot(double x, double y, ZPos z,
|
73
|
+
double angle, double centerX = 0.5, double centerY = 0.5,
|
74
|
+
double factorX = 1, double factorY = 1,
|
75
|
+
Color c = Colors::white,
|
76
|
+
AlphaMode mode = amDefault) const;
|
77
|
+
|
78
|
+
#ifndef SWIG
|
79
|
+
void drawRotFlip(double x, double y, ZPos z,
|
80
|
+
RotFlip rf,
|
81
|
+
double factorX = 1, double factorY = 1,
|
82
|
+
Color c = Colors::white,
|
83
|
+
AlphaMode mode = amDefault) const;
|
84
|
+
void drawRotFlipMod(double x, double y, ZPos z,
|
85
|
+
RotFlip rf,
|
86
|
+
double factorX, double factorY,
|
87
|
+
Color c1, Color c2, Color c3, Color c4,
|
88
|
+
AlphaMode mode = amDefault) const;
|
89
|
+
|
90
|
+
//! Provides access to the underlying image data object.
|
91
|
+
const ImageData& getData() const;
|
92
|
+
#endif
|
93
|
+
};
|
94
|
+
|
95
|
+
//! Convenience function that splits a BMP or PNG file into an area
|
96
|
+
//! of small rectangles and creates images from them.
|
97
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
98
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
99
|
+
//! \param tileHeight See tileWidth.
|
100
|
+
//! \param appendTo STL container to which the images will be appended.
|
101
|
+
//! Must provide a push_back member function; std::vector<boost::shared_ptr<Image>>
|
102
|
+
//! is usually the most reasonable container.
|
103
|
+
template<typename Container>
|
104
|
+
void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
|
105
|
+
int tileWidth, int tileHeight, bool hardBorders, Container& appendTo)
|
106
|
+
{
|
107
|
+
imagesFromTiledBitmap(graphics, quickLoadBitmap(filename), tileWidth, tileHeight, hardBorders, appendTo);
|
108
|
+
}
|
109
|
+
|
110
|
+
//! Convenience function that splits a bitmap into an area of small
|
111
|
+
//! rectangles and creates images from them.
|
112
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
113
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
114
|
+
//! \param tileHeight See tileWidth.
|
115
|
+
//! \param appendTo STL container to which the images will be appended.
|
116
|
+
//! Must provide a push_back member function; std::vector<boost::shared_ptr<Image>>
|
117
|
+
//! is usually the most reasonable container.
|
118
|
+
template<typename Container>
|
119
|
+
void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
|
120
|
+
int tileWidth, int tileHeight, bool hardBorders, Container& appendTo)
|
121
|
+
{
|
122
|
+
int tilesX, tilesY;
|
123
|
+
|
124
|
+
if (tileWidth > 0)
|
125
|
+
tilesX = bmp.width() / tileWidth;
|
126
|
+
else
|
127
|
+
{
|
128
|
+
tilesX = -tileWidth;
|
129
|
+
tileWidth = bmp.width() / tilesX;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (tileHeight > 0)
|
133
|
+
tilesY = bmp.height() / tileHeight;
|
134
|
+
else
|
135
|
+
{
|
136
|
+
tilesY = -tileHeight;
|
137
|
+
tileHeight = bmp.height() / tilesY;
|
138
|
+
}
|
139
|
+
|
140
|
+
for (int y = 0; y < tilesY; ++y)
|
141
|
+
for (int x = 0; x < tilesX; ++x)
|
142
|
+
appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
|
143
|
+
x * tileWidth, y * tileHeight, tileWidth, tileHeight,
|
144
|
+
hardBorders)));
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
#endif
|
data/Gosu/ImageData.hpp
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
//! \file ImageData.hpp
|
2
|
+
//! Interface of the ImageData class.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGEDATA_HPP
|
5
|
+
#define GOSU_IMAGEDATA_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Color.hpp>
|
8
|
+
#include <Gosu/GraphicsBase.hpp>
|
9
|
+
#include <boost/optional.hpp>
|
10
|
+
#include <boost/utility.hpp>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
struct GLTexInfo
|
15
|
+
{
|
16
|
+
int texName;
|
17
|
+
double left, right, top, bottom;
|
18
|
+
};
|
19
|
+
|
20
|
+
//! The ImageData class is an abstract base class for drawable images.
|
21
|
+
//! Instances of classes derived by ImageData are usually returned by
|
22
|
+
//! Graphics::createImage and usually only used to implement drawing
|
23
|
+
//! primitives like Image, which then provide a more specialized and
|
24
|
+
//! intuitive drawing interface.
|
25
|
+
class ImageData : boost::noncopyable
|
26
|
+
{
|
27
|
+
public:
|
28
|
+
virtual ~ImageData()
|
29
|
+
{
|
30
|
+
}
|
31
|
+
|
32
|
+
virtual unsigned width() const = 0;
|
33
|
+
virtual unsigned height() const = 0;
|
34
|
+
|
35
|
+
virtual void draw(double x1, double y1, Color c1,
|
36
|
+
double x2, double y2, Color c2,
|
37
|
+
double x3, double y3, Color c3,
|
38
|
+
double x4, double y4, Color c4,
|
39
|
+
ZPos z, AlphaMode mode) const = 0;
|
40
|
+
|
41
|
+
virtual boost::optional<GLTexInfo> glTexInfo() const = 0;
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
#endif
|