gosu 0.9.2-x86-mingw32 → 0.10.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,114 +0,0 @@
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 <Gosu/Platform.hpp>
8
- #include <Gosu/TR1.hpp>
9
- #include <limits>
10
-
11
- namespace Gosu
12
- {
13
- //! Represents the Z position of something drawn with Gosu's graphics
14
- //! system. Draw calls with higher ZPos values will cover those with a
15
- //! lower ZPos value, that is, they are performed last.
16
- typedef double ZPos;
17
-
18
- //! Determines the way colors are combined when one is drawn onto
19
- //! another.
20
- #if defined(GOSU_CPP11_ENABLED)
21
- enum class AlphaMode
22
- {
23
- //! The color's channels will be interpolated. The alpha channel
24
- //! specifies the opacity of the new color, 255 is full opacity.
25
- DEFAULT,
26
- INTERPOLATE = DEFAULT,
27
- //! The colors' channels will be added. The alpha channel specifies
28
- //! the percentage of the new color's channels that will be added
29
- //! to the old color's channels.
30
- ADD,
31
- //! The color's channels will be multiplied with each other.
32
- MULTIPLY
33
- };
34
- constexpr AlphaMode amDefault = AlphaMode::DEFAULT;
35
- constexpr AlphaMode amInterpolate = AlphaMode::INTERPOLATE;
36
- constexpr AlphaMode amAdd = AlphaMode::ADD;
37
- constexpr AlphaMode amAdditive = AlphaMode::ADD;
38
- constexpr AlphaMode amMultiply = AlphaMode::MULTIPLY;
39
- #else
40
- enum AlphaMode
41
- {
42
- //! The color's channels will be interpolated. The alpha channel
43
- //! specifies the opacity of the new color, 255 is full opacity.
44
- amDefault,
45
- //! The colors' channels will be added. The alpha channel specifies
46
- //! the percentage of the new color's channels that will be added
47
- //! to the old color's channels.
48
- amAdd,
49
- amAdditive = amAdd,
50
- //! The color's channels will be multiplied with each other.
51
- amMultiply
52
- };
53
- #endif
54
-
55
- enum FontFlags
56
- {
57
- ffBold = 1,
58
- ffItalic = 2,
59
- ffUnderline = 4,
60
- ffCombinations = 8
61
- };
62
-
63
- enum TextAlign
64
- {
65
- taLeft,
66
- taRight,
67
- taCenter,
68
- taJustify
69
- };
70
-
71
- enum ImageFlags
72
- {
73
- //! Flags that affect the tileability of an image.
74
- ifSmooth = 0,
75
- // Note: No constant for '1', but Gosu treats '1' as ifTileable for
76
- // backward compatibility reasons (this used to be a bool).
77
- ifTileableLeft = 2,
78
- ifTileableTop = 4,
79
- ifTileableRight = 8,
80
- ifTileableBottom = 16,
81
- ifTileable = ifTileableLeft | ifTileableTop | ifTileableRight | ifTileableBottom
82
-
83
- // TODO - ifNearestNeighbor to replace undocumentedRetrofication.
84
- };
85
-
86
- #ifdef GOSU_IS_MAC
87
- // TODO: Without this gigantic hack, Gosu crashes in the "scale" function,
88
- // but _only_ when used from Ruby 1.9. It is unclear what might cause this -
89
- // maybe a compiler bug that tries to use SSE functions with the wrong
90
- // alignment. Adding __attribute__((aligned(16))) does not help, though.
91
- struct Transform
92
- {
93
- double value[16];
94
- bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
95
- const double &operator[](std::size_t idx) const { return value[idx]; }
96
- double &operator[](std::size_t idx) { return value[idx]; }
97
- };
98
- #else
99
- typedef std::tr1::array<double, 16> Transform;
100
- #endif
101
- Transform translate(double x, double y);
102
- Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
103
- Transform scale(double factor);
104
- Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
105
- Transform concat(const Transform& lhs, const Transform& rhs);
106
-
107
- #ifndef SWIG
108
- // A not so useful optimization - this was supposed to bypass the Z queue for immediate rendering.
109
- // In retrospect, the only useful optimization would be to work down the Z queue on a second thread.
110
- GOSU_DEPRECATED const double zImmediate = -std::numeric_limits<double>::infinity();
111
- #endif
112
- }
113
-
114
- #endif
data/Gosu/IO.hpp DELETED
@@ -1,269 +0,0 @@
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 <cstddef>
8
- #include <algorithm>
9
- #include <memory>
10
- #include <string>
11
- #include <vector>
12
- #include <Gosu/Platform.hpp>
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
- //! Utility class that points to a specific position in a resource
26
- //! and offers an interface for sequential reading.
27
- class Reader
28
- {
29
- const Resource* res;
30
- std::size_t pos;
31
-
32
- public:
33
- Reader(const Resource& resource, std::size_t position)
34
- : res(&resource), pos(position)
35
- {
36
- }
37
-
38
- const Resource& resource() const
39
- {
40
- return *res;
41
- }
42
-
43
- std::size_t position() const
44
- {
45
- return pos;
46
- }
47
-
48
- void setPosition(std::size_t value)
49
- {
50
- // TODO: Check?
51
- pos = value;
52
- }
53
-
54
- void seek(std::ptrdiff_t offset)
55
- {
56
- // TODO: Check?
57
- pos += offset;
58
- }
59
-
60
- void read(void* destBuffer, std::size_t length);
61
-
62
- //! Convenience function; equivalent to read(&t, sizeof t).
63
- template<typename T>
64
- void readPod(T& t, ByteOrder bo = boDontCare)
65
- {
66
- read(&t, sizeof t);
67
- if (bo == otherByteOrder)
68
- {
69
- char* begin = reinterpret_cast<char*>(&t);
70
- std::reverse(begin, begin + sizeof t);
71
- }
72
- }
73
-
74
- //! Similar to readPod(T&), but returns the read value instead.
75
- template<typename T>
76
- T getPod(ByteOrder bo = boDontCare)
77
- {
78
- T t;
79
- readPod<T>(t, bo);
80
- return t;
81
- }
82
- };
83
-
84
- //! Utility class that points to a specific position in a resource
85
- //! and offers an interface for sequential writing.
86
- class Writer
87
- {
88
- Resource* res;
89
- std::size_t pos;
90
-
91
- public:
92
- Writer(Resource& resource, std::size_t position)
93
- : res(&resource), pos(position)
94
- {
95
- }
96
-
97
- Resource& resource() const
98
- {
99
- return *res;
100
- }
101
-
102
- std::size_t position() const
103
- {
104
- return pos;
105
- }
106
-
107
- void setPosition(std::size_t value)
108
- {
109
- // TODO: Check?
110
- pos = value;
111
- }
112
-
113
- void seek(std::ptrdiff_t offset)
114
- {
115
- // TODO: Check?
116
- pos += offset;
117
- }
118
-
119
- void write(const void* sourceBuffer, std::size_t length);
120
-
121
- //! Convenience function; equivalent to write(&t, sizeof t).
122
- template<typename T>
123
- void writePod(const T& t, ByteOrder bo = boDontCare)
124
- {
125
- if (bo == otherByteOrder)
126
- {
127
- char buf[sizeof t];
128
- const char* begin = reinterpret_cast<const char*>(&t);
129
- std::reverse_copy(begin, begin + sizeof t, buf);
130
- write(buf, sizeof buf);
131
- }
132
- else
133
- write(&t, sizeof t);
134
- }
135
- };
136
-
137
- //! Base class for resources. A resource in Gosu is nothing more but a
138
- //! piece of binary data that can be read or written, for example files
139
- //! or simply areas of allocated memory.
140
- //! A resource always knows its size and can resize itself, thereby either
141
- //! truncating its content or allocating room for more data.
142
- class Resource
143
- {
144
- // Non-copyable
145
- #if defined(GOSU_CPP11_ENABLED)
146
- Resource(const Resource&) = delete;
147
- Resource& operator=(const Resource&) = delete;
148
- // and non-movable
149
- Resource(Resource&&) = delete;
150
- Resource& operator=(Resource&&) = delete;
151
- #else
152
- Resource(const Resource&);
153
- Resource& operator=(const Resource&);
154
- #endif
155
-
156
- public:
157
- Resource()
158
- {
159
- }
160
-
161
- virtual ~Resource()
162
- {
163
- }
164
-
165
- //! Convenience: Creates a new Reader that reads from the start of
166
- //! the resource.
167
- Reader frontReader() const
168
- {
169
- return Reader(*this, 0);
170
- }
171
-
172
- //! Convenience: Creates a new Writer that appends data at the
173
- //! end of the resource.
174
- Writer backWriter()
175
- {
176
- return Writer(*this, size());
177
- }
178
-
179
- virtual std::size_t size() const = 0;
180
-
181
- virtual void resize(std::size_t newSize) = 0;
182
-
183
- virtual void read(std::size_t offset, std::size_t length,
184
- void* destBuffer) const = 0;
185
-
186
- virtual void write(std::size_t offset, std::size_t length,
187
- const void* sourceBuffer) = 0;
188
- };
189
-
190
- //! Piece of memory with the Resource interface.
191
- class Buffer : public Resource
192
- {
193
- std::vector<char> buf;
194
-
195
- public:
196
- Buffer()
197
- {
198
- }
199
-
200
- Buffer(const Buffer& other)
201
- : Resource()
202
- , buf(other.buf)
203
- {
204
- }
205
-
206
- Buffer& operator=(const Buffer& other)
207
- {
208
- buf = other.buf;
209
- return *this;
210
- }
211
-
212
- std::size_t size() const;
213
- void resize(std::size_t newSize);
214
-
215
- void read(std::size_t offset, std::size_t length,
216
- void* destBuffer) const;
217
-
218
- void write(std::size_t offset, std::size_t length,
219
- const void* sourceBuffer);
220
-
221
- const void* data() const
222
- {
223
- return &buf[0];
224
- }
225
-
226
- void* data()
227
- {
228
- return &buf[0];
229
- }
230
- };
231
-
232
- enum FileMode
233
- {
234
- //! Opens an existing file for reading; throws an exception if the file
235
- //! cannot be found.
236
- fmRead,
237
- //! Writes data to a file. If the file already exists, is emptied on
238
- //! opening. If the file does not exist, it is created.
239
- fmReplace,
240
- //! Opens or creates a file with writing access, but does not clear
241
- //! existing contents.
242
- fmAlter
243
- };
244
-
245
- //! File with the Resource interface.
246
- class File : public Resource
247
- {
248
- struct Impl;
249
- const GOSU_UNIQUE_PTR<Impl> pimpl;
250
-
251
- public:
252
- explicit File(const std::wstring& filename, FileMode mode = fmRead);
253
- ~File();
254
-
255
- std::size_t size() const;
256
- void resize(std::size_t newSize);
257
- void read(std::size_t offset, std::size_t length,
258
- void* destBuffer) const;
259
- void write(std::size_t offset, std::size_t length,
260
- const void* sourceBuffer);
261
- };
262
-
263
- //! Loads a whole file into a buffer.
264
- void loadFile(Buffer& buffer, const std::wstring& filename);
265
- //! Creates or overwrites a file with the contents of a buffer.
266
- void saveFile(const Buffer& buffer, const std::wstring& filename);
267
- }
268
-
269
- #endif
data/Gosu/Image.hpp DELETED
@@ -1,131 +0,0 @@
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/Color.hpp>
9
- #include <Gosu/GraphicsBase.hpp>
10
- #include <Gosu/TR1.hpp>
11
- #include <memory>
12
- #include <vector>
13
-
14
- namespace Gosu
15
- {
16
- //! Provides functionality for drawing rectangular images.
17
- class Image
18
- {
19
- std::tr1::shared_ptr<ImageData> data;
20
-
21
- public:
22
- //! Loads an image from a given filename.
23
- //!
24
- //! A color key of #ff00ff is automatically applied to BMP image files.
25
- //! For more flexibility, use the corresponding constructor that uses a Bitmap object.
26
- explicit Image(const std::wstring& filename,
27
- unsigned imageFlags = ifSmooth);
28
-
29
- //! Loads a portion of the the image at the given filename..
30
- //!
31
- //! A color key of #ff00ff is automatically applied to BMP image files.
32
- //! For more flexibility, use the corresponding constructor that uses a Bitmap object.
33
- Image(const std::wstring& filename, unsigned srcX,
34
- unsigned srcY, unsigned srcWidth, unsigned srcHeight,
35
- unsigned imageFlags = ifSmooth);
36
-
37
- //! Converts the given bitmap into an image.
38
- explicit Image(const Bitmap& source,
39
- unsigned imageFlags = ifSmooth);
40
-
41
- //! Converts a portion of the given bitmap into an image.
42
- Image(const Bitmap& source, unsigned srcX,
43
- unsigned srcY, unsigned srcWidth, unsigned srcHeight,
44
- unsigned imageFlags = ifSmooth);
45
-
46
- //! Creates an Image from a user-supplied instance of the ImageData interface.
47
- explicit Image(GOSU_UNIQUE_PTR<ImageData> data);
48
-
49
- unsigned width() const;
50
- unsigned height() const;
51
-
52
- //! Draws the image so its upper left corner is at (x; y).
53
- void draw(double x, double y, ZPos z,
54
- double factorX = 1, double factorY = 1,
55
- Color c = Color::WHITE,
56
- AlphaMode mode = amDefault) const;
57
- //! Like draw(), but with modulation colors for all four corners.
58
- //! TODO: This can be an overload of draw() - in any case the name is terrible.
59
- void drawMod(double x, double y, ZPos z,
60
- double factorX, double factorY,
61
- Color c1, Color c2, Color c3, Color c4,
62
- AlphaMode mode = amDefault) const;
63
-
64
- //! Draws the image rotated by the given angle so that its rotation
65
- //! center is at (x; y). Note that this is different from how all the
66
- //! other drawing functions work!
67
- //! \param angle See Math.hpp for an explanation of how Gosu interprets
68
- //! angles.
69
- //! \param centerX Relative horizontal position of the rotation center
70
- //! on the image. 0 is the left border, 1 is the right border, 0.5 is
71
- //! the center (and default).
72
- //! \param centerY See centerX.
73
- void drawRot(double x, double y, ZPos z,
74
- double angle, double centerX = 0.5, double centerY = 0.5,
75
- double factorX = 1, double factorY = 1,
76
- Color c = Color::WHITE,
77
- AlphaMode mode = amDefault) const;
78
-
79
- #ifndef SWIG
80
- //! Provides access to the underlying image data object.
81
- ImageData& getData() const;
82
-
83
- GOSU_DEPRECATED Image(Graphics& graphics, const std::wstring& filename,
84
- bool tileable = false);
85
- GOSU_DEPRECATED Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
86
- unsigned srcY, unsigned srcWidth, unsigned srcHeight,
87
- bool tileable = false);
88
- GOSU_DEPRECATED Image(Graphics& graphics, const Bitmap& source,
89
- bool tileable = false);
90
- GOSU_DEPRECATED Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
91
- unsigned srcY, unsigned srcWidth, unsigned srcHeight,
92
- bool tileable = false);
93
- #endif
94
- };
95
-
96
- #ifndef SWIG
97
- //! Convenience function that slices an image file into a grid and creates images from them.
98
- //! \param tileWidth If positive, specifies the width of one tile in pixels.
99
- //! If negative, the bitmap is divided into -tileWidth rows.
100
- //! \param tileHeight See tileWidth.
101
- std::vector<Gosu::Image> loadTiles(const Bitmap& bmp,
102
- int tileWidth, int tileHeight, unsigned imageFlags = ifSmooth);
103
-
104
- //! Convenience function that slices a bitmap into a grid and creates images from them.
105
- //! \param tileWidth If positive, specifies the width of one tile in pixels.
106
- //! If negative, the bitmap is divided into -tileWidth rows.
107
- //! \param tileHeight See tileWidth.
108
- std::vector<Gosu::Image> loadTiles(const std::wstring& filename,
109
- int tileWidth, int tileHeight, unsigned imageFlags = ifSmooth);
110
-
111
- GOSU_DEPRECATED std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
112
- GOSU_DEPRECATED std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
113
- template<typename Container>
114
- GOSU_DEPRECATED void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
115
- {
116
- std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
117
- for (int i = 0, num = tiles.size(); i < num; ++i)
118
- appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
119
- }
120
- template<typename Container>
121
- GOSU_DEPRECATED void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
122
- int tileWidth, int tileHeight, bool tileable, Container& appendTo)
123
- {
124
- std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, tileWidth, tileHeight, tileable);
125
- for (int i = 0, num = tiles.size(); i < num; ++i)
126
- appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
127
- }
128
- #endif
129
- }
130
-
131
- #endif