gosu 0.7.25-i386-mingw32 → 0.7.26-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ //! \file Directories.hpp
2
+ //! Access to a small set of system paths.
3
+
4
+ #ifndef GOSU_DIRECTORIES_HPP
5
+ #define GOSU_DIRECTORIES_HPP
6
+
7
+ #include <string>
8
+
9
+ namespace Gosu
10
+ {
11
+ //! Prefix for a program's own resources.
12
+ //! On Windows, the executable's containing directory.
13
+ //! On OS X, the application's Resources subdirectory.
14
+ //! On Linux, the current directory.
15
+ std::wstring resourcePrefix();
16
+
17
+ //! Prefix for resources of a group of programs.
18
+ //! On Windows, the executable's containing directory.
19
+ //! On OS X, the application's containing subdirectory.
20
+ //! On Linux, the current directory.
21
+ std::wstring sharedResourcePrefix();
22
+
23
+ //! Prefix for user settings.
24
+ //! On Windows, the same as %APPDATA%.
25
+ //! On OS X, the user's Library/Preferences folder.
26
+ //! On Linux, the home directory plus a trailing dot for hidden files.
27
+ std::wstring userSettingsPrefix();
28
+
29
+ //! Prefix for user documents, e.g. save games.
30
+ //! On Windows, the My Documents folder.
31
+ //! On OS X, the user's Documents folder.
32
+ //! On Linux, the home directory.
33
+ std::wstring userDocsPrefix();
34
+ }
35
+
36
+ #endif
@@ -0,0 +1,74 @@
1
+ //! \file Font.hpp
2
+ //! Interface of the Font class.
3
+
4
+ #ifndef GOSU_FONT_HPP
5
+ #define GOSU_FONT_HPP
6
+
7
+ #include <Gosu/Fwd.hpp>
8
+ #include <Gosu/Color.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
10
+ #include <Gosu/Platform.hpp>
11
+ #include <boost/shared_ptr.hpp>
12
+ #include <string>
13
+
14
+ namespace Gosu
15
+ {
16
+ //! A font can be used to draw text on a Graphics object very flexibly.
17
+ //! Fonts are ideal for small texts that change regularly. For large,
18
+ //! static texts you should use createBitmap and turn the result into
19
+ //! an image.
20
+ class Font
21
+ {
22
+ struct Impl;
23
+ boost::shared_ptr<Impl> pimpl;
24
+
25
+ public:
26
+ //! Constructs a font that can be drawn onto the graphics object.
27
+ //! \param fontName Name of a system font, or a filename to a TTF
28
+ //! file (must contain '/', does not work on Linux).
29
+ //! \param fontHeight Height of the font, in pixels.
30
+ //! \param fontFlags Flags used to render individual characters of
31
+ //! the font.
32
+ Font(Graphics& graphics, const std::wstring& fontName,
33
+ unsigned fontHeight, unsigned fontFlags = ffBold);
34
+
35
+ //! Returns the name of the font that was used to create it.
36
+ std::wstring name() const;
37
+
38
+ //! Returns the height of the font, in pixels.
39
+ unsigned height() const;
40
+
41
+ //! Returns the flags used to create the font characters.
42
+ unsigned flags() const;
43
+
44
+ //! Returns the width, in pixels, the given text would occupy if drawn.
45
+ double textWidth(const std::wstring& text, double factorX = 1) const;
46
+
47
+ //! Draws text so the top left corner of the text is at (x; y).
48
+ //! \param text Formatted text without line-breaks.
49
+ void draw(const std::wstring& text, double x, double y, ZPos z,
50
+ double factorX = 1, double factorY = 1,
51
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
52
+
53
+ //! Draws text at a position relative to (x; y).
54
+ //! \param relX Determines where the text is drawn horizontally. If
55
+ //! relX is 0.0, the text will be to the right of x, if it is 1.0,
56
+ //! the text will be to the left of x, if it is 0.5, it will be
57
+ //! centered on x. Of course, all real numbers are possible values.
58
+ //! \param relY See relX.
59
+ void drawRel(const std::wstring& text, double x, double y, ZPos z,
60
+ double relX, double relY, double factorX = 1, double factorY = 1,
61
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
62
+
63
+ #ifndef SWIG
64
+ GOSU_DEPRECATED
65
+ #endif
66
+ //! DEPRECATED: Analogous to draw, but rotates the text by a given angle. Use
67
+ //! a simple pushTransform to achieve the same effect.
68
+ void drawRot(const std::wstring& text, double x, double y, ZPos z, double angle,
69
+ double factorX = 1, double factorY = 1,
70
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
71
+ };
72
+ }
73
+
74
+ #endif
@@ -0,0 +1,30 @@
1
+ //! \file Fwd.hpp
2
+ //! Contains declarations of all of Gosu's available classes.
3
+
4
+ #ifndef GOSU_FWD_HPP
5
+ #define GOSU_FWD_HPP
6
+
7
+ //! The library's main namespace.
8
+ namespace Gosu
9
+ {
10
+ class Audio;
11
+ class Bitmap;
12
+ class Buffer;
13
+ class Color;
14
+ class File;
15
+ class Font;
16
+ class Graphics;
17
+ class Image;
18
+ class ImageData;
19
+ class Input;
20
+ class Reader;
21
+ class Resource;
22
+ class Sample;
23
+ class Song;
24
+ class TextInput;
25
+ class Timer;
26
+ class Window;
27
+ class Writer;
28
+ }
29
+
30
+ #endif
@@ -0,0 +1,33 @@
1
+ //! \file Gosu.hpp
2
+ //! Umbrella header for lazy people with fast compilers, or pre-compiled headers.
3
+
4
+ //! \mainpage Gosu C++ Documentation
5
+ //!
6
+ //! These pages serve as a reference on the C++ interface of Gosu. For a higher-level
7
+ //! discussion of concepts and ideas behind the library, see the Wiki entries linked
8
+ //! from the official website, http://www.libgosu.org/.
9
+
10
+ #ifndef GOSU_GOSU_HPP
11
+ #define GOSU_GOSU_HPP
12
+
13
+ #include <Gosu/Audio.hpp>
14
+ #include <Gosu/Bitmap.hpp>
15
+ #include <Gosu/Color.hpp>
16
+ #include <Gosu/Directories.hpp>
17
+ #include <Gosu/Font.hpp>
18
+ #include <Gosu/Graphics.hpp>
19
+ #include <Gosu/Image.hpp>
20
+ #include <Gosu/ImageData.hpp>
21
+ #include <Gosu/Input.hpp>
22
+ #include <Gosu/IO.hpp>
23
+ #include <Gosu/Math.hpp>
24
+ #include <Gosu/Platform.hpp>
25
+ #include <Gosu/Sockets.hpp>
26
+ #include <Gosu/Text.hpp>
27
+ #include <Gosu/TextInput.hpp>
28
+ #include <Gosu/Timing.hpp>
29
+ #include <Gosu/Utility.hpp>
30
+ #include <Gosu/Version.hpp>
31
+ #include <Gosu/Window.hpp>
32
+
33
+ #endif
@@ -0,0 +1,118 @@
1
+ //! \file Graphics.hpp
2
+ //! Interface of the Graphics class.
3
+
4
+ #ifndef GOSU_GRAPHICS_HPP
5
+ #define GOSU_GRAPHICS_HPP
6
+
7
+ #include <Gosu/Fwd.hpp>
8
+ #include <Gosu/Color.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
10
+ #include <boost/array.hpp>
11
+ #include <boost/function.hpp>
12
+ #include <boost/scoped_ptr.hpp>
13
+ #include <memory>
14
+
15
+ namespace Gosu
16
+ {
17
+ //! Returns the width, in pixels, of the user's primary screen.
18
+ unsigned screenWidth();
19
+
20
+ //! Returns the height, in pixels, of the user's primary screen.
21
+ unsigned screenHeight();
22
+
23
+ //! Returns the maximum size of an texture that will be allocated
24
+ //! internally by Gosu.
25
+ //! Useful when extending Gosu using OpenGL.
26
+ unsigned const MAX_TEXTURE_SIZE = 1024;
27
+
28
+ typedef boost::array<double, 16> Transform;
29
+ Transform translate(double x, double y);
30
+ Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
31
+ Transform scale(double factor);
32
+ Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
33
+
34
+ //! Serves as the target of all drawing and provides primitive drawing
35
+ //! functionality.
36
+ //! Usually created internally by Gosu::Window.
37
+ class Graphics
38
+ {
39
+ struct Impl;
40
+ boost::scoped_ptr<Impl> pimpl;
41
+
42
+ public:
43
+ Graphics(unsigned physicalWidth, unsigned physicalHeight, bool fullscreen);
44
+ ~Graphics();
45
+
46
+ // Undocumented until I have thought about this...
47
+ void setResolution(unsigned virtualWidth, unsigned virtualHeight);
48
+ // End of Undocumented
49
+
50
+ unsigned width() const;
51
+ unsigned height() const;
52
+ bool fullscreen() const;
53
+
54
+ //! Prepares the graphics object for drawing. Nothing must be drawn
55
+ //! without calling begin.
56
+ bool begin(Color clearWithColor = Color::BLACK);
57
+ //! Every call to begin must have a matching call to end.
58
+ void end();
59
+ //! Flushes the Z queue to the screen and starts a new one.
60
+ //! Useful for games that are *very* composite in nature (splitscreen).
61
+ void flush();
62
+
63
+ //! Finishes all pending Gosu drawing operations and executes
64
+ //! the following OpenGL code in a clean environment.
65
+ void beginGL();
66
+ //! Resets Gosu into its default rendering state.
67
+ void endGL();
68
+ //! (Experimental)
69
+ //! Schedules a custom GL functor to be executed at a certain Z level.
70
+ //! The functor is called in a clean GL context (as given by beginGL/endGL).
71
+ //! Gosu's rendering up to the Z level may not yet have been glFlush()ed.
72
+ //! Note: Unlike normal drawing operations on the same Z level, the order
73
+ //! of custom GL functors is NOT DEFINED.
74
+ //! Note: You may not call any Gosu rendering functions from within the
75
+ //! functor, and you must schedule it from within Window::draw's call tree.
76
+ void scheduleGL(const boost::function<void()>& functor, ZPos z);
77
+
78
+ //! Enables clipping to a specified rectangle.
79
+ void beginClipping(double x, double y, double width, double height);
80
+ //! Disables clipping.
81
+ void endClipping();
82
+
83
+ //! Starts recording a macro. Cannot be nested.
84
+ void beginRecording();
85
+ //! Finishes building the macro and returns it as a drawable object.
86
+ //! Most usually, the return value is passed to Image::Image().
87
+ std::auto_ptr<Gosu::ImageData> endRecording();
88
+
89
+ //! Pushes one transformation onto the transformation stack.
90
+ void pushTransform(const Transform& transform);
91
+ //! Pops one transformation from the transformation stack.
92
+ void popTransform();
93
+
94
+ //! Draws a line from one point to another (last pixel exclusive).
95
+ void drawLine(double x1, double y1, Color c1,
96
+ double x2, double y2, Color c2,
97
+ ZPos z, AlphaMode mode = amDefault);
98
+
99
+ void drawTriangle(double x1, double y1, Color c1,
100
+ double x2, double y2, Color c2,
101
+ double x3, double y3, Color c3,
102
+ ZPos z, AlphaMode mode = amDefault);
103
+
104
+ void drawQuad(double x1, double y1, Color c1,
105
+ double x2, double y2, Color c2,
106
+ double x3, double y3, Color c3,
107
+ double x4, double y4, Color c4,
108
+ ZPos z, AlphaMode mode = amDefault);
109
+
110
+ //! Turns a portion of a bitmap into something that can be drawn on
111
+ //! this graphics object.
112
+ std::auto_ptr<ImageData> createImage(const Bitmap& src,
113
+ unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
114
+ unsigned borderFlags);
115
+ };
116
+ }
117
+
118
+ #endif
@@ -0,0 +1,69 @@
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 <limits>
9
+
10
+ namespace Gosu
11
+ {
12
+ //! Represents the Z position of something drawn with Gosu's graphics
13
+ //! system. Draw calls with higher ZPos values will cover those with a
14
+ //! lower ZPos value, that is, they are performed last.
15
+ typedef double ZPos;
16
+
17
+ //! The lowest possible Z position. By using this, you tell Gosu that
18
+ //! your drawing operation does not need Z ordering and can be performed
19
+ //! immediately.
20
+ //! Deprecated because this turned out not be very useful in optimizing.
21
+ #ifndef SWIG
22
+ GOSU_DEPRECATED
23
+ #endif
24
+ const double zImmediate = -std::numeric_limits<double>::infinity();
25
+
26
+ //! Determines the way colors are combined when one is drawn onto
27
+ //! another.
28
+ enum AlphaMode
29
+ {
30
+ //! The color's channels will be interpolated. The alpha channel
31
+ //! specifies the opacity of the new color, 255 is full opacity.
32
+ amDefault,
33
+ //! The colors' channels will be added. The alpha channel specifies
34
+ //! the percentage of the new color's channels that will be added
35
+ //! to the old color's channels.
36
+ amAdditive,
37
+ //! The color's channels will be multiplied with each other.
38
+ amMultiply
39
+ };
40
+
41
+ enum FontFlags
42
+ {
43
+ ffBold = 1,
44
+ ffItalic = 2,
45
+ ffUnderline = 4,
46
+ ffCombinations = 8
47
+ };
48
+
49
+ enum TextAlign
50
+ {
51
+ taLeft,
52
+ taRight,
53
+ taCenter,
54
+ taJustify
55
+ };
56
+
57
+ //! Flags that affect the tileability of an image.
58
+ enum BorderFlags
59
+ {
60
+ bfSmooth = 0,
61
+ bfTileableLeft = 1,
62
+ bfTileableTop = 2,
63
+ bfTileableRight = 4,
64
+ bfTileableBottom = 8,
65
+ bfTileable = bfTileableLeft | bfTileableTop | bfTileableRight | bfTileableBottom
66
+ };
67
+ }
68
+
69
+ #endif
@@ -0,0 +1,252 @@
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
+ //! 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 : boost::noncopyable
143
+ {
144
+ public:
145
+ virtual ~Resource()
146
+ {
147
+ }
148
+
149
+ //! Convenience: Creates a new Reader that reads from the start of
150
+ //! the resource.
151
+ Reader frontReader() const
152
+ {
153
+ return Reader(*this, 0);
154
+ }
155
+
156
+ //! Convenience: Creates a new Writer that appends data at the
157
+ //! end of the resource.
158
+ Writer backWriter()
159
+ {
160
+ return Writer(*this, size());
161
+ }
162
+
163
+ virtual std::size_t size() const = 0;
164
+
165
+ virtual void resize(std::size_t newSize) = 0;
166
+
167
+ virtual void read(std::size_t offset, std::size_t length,
168
+ void* destBuffer) const = 0;
169
+
170
+ virtual void write(std::size_t offset, std::size_t length,
171
+ const void* sourceBuffer) = 0;
172
+ };
173
+
174
+ //! Piece of memory with the Resource interface.
175
+ class Buffer : public Resource
176
+ {
177
+ std::vector<char> buf;
178
+
179
+ public:
180
+ Buffer()
181
+ {
182
+ }
183
+
184
+ Buffer(const Buffer& other)
185
+ : buf(other.buf)
186
+ {
187
+ }
188
+
189
+ Buffer& operator=(const Buffer& other)
190
+ {
191
+ buf = other.buf;
192
+ return *this;
193
+ }
194
+
195
+ std::size_t size() const;
196
+ void resize(std::size_t newSize);
197
+
198
+ void read(std::size_t offset, std::size_t length,
199
+ void* destBuffer) const;
200
+
201
+ void write(std::size_t offset, std::size_t length,
202
+ const void* sourceBuffer);
203
+
204
+ const void* data() const
205
+ {
206
+ return &buf[0];
207
+ }
208
+
209
+ void* data()
210
+ {
211
+ return &buf[0];
212
+ }
213
+ };
214
+
215
+ enum FileMode
216
+ {
217
+ //! Opens an existing file for reading; throws an exception if the file
218
+ //! cannot be found.
219
+ fmRead,
220
+ //! Writes data to a file. If the file already exists, is emptied on
221
+ //! opening. If the file does not exist, it is created.
222
+ fmReplace,
223
+ //! Opens or creates a file with writing access, but does not clear
224
+ //! existing contents.
225
+ fmAlter
226
+ };
227
+
228
+ //! File with the Resource interface.
229
+ class File : public Resource
230
+ {
231
+ struct Impl;
232
+ boost::scoped_ptr<Impl> pimpl;
233
+
234
+ public:
235
+ explicit File(const std::wstring& filename, FileMode mode = fmRead);
236
+ ~File();
237
+
238
+ std::size_t size() const;
239
+ void resize(std::size_t newSize);
240
+ void read(std::size_t offset, std::size_t length,
241
+ void* destBuffer) const;
242
+ void write(std::size_t offset, std::size_t length,
243
+ const void* sourceBuffer);
244
+ };
245
+
246
+ //! Loads a whole file into a buffer.
247
+ void loadFile(Buffer& buffer, const std::wstring& filename);
248
+ //! Creates or overwrites a file with the contents of a buffer.
249
+ void saveFile(const Buffer& buffer, const std::wstring& filename);
250
+ }
251
+
252
+ #endif