gosu 0.8.6-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/Gosu/Audio.hpp +171 -0
  3. data/Gosu/AutoLink.hpp +16 -0
  4. data/Gosu/Bitmap.hpp +96 -0
  5. data/Gosu/Buttons.hpp +265 -0
  6. data/Gosu/Color.hpp +204 -0
  7. data/Gosu/Directories.hpp +36 -0
  8. data/Gosu/Font.hpp +83 -0
  9. data/Gosu/Fwd.hpp +31 -0
  10. data/Gosu/Gosu.hpp +34 -0
  11. data/Gosu/Graphics.hpp +115 -0
  12. data/Gosu/GraphicsBase.hpp +110 -0
  13. data/Gosu/IO.hpp +269 -0
  14. data/Gosu/Image.hpp +122 -0
  15. data/Gosu/ImageData.hpp +61 -0
  16. data/Gosu/Input.hpp +149 -0
  17. data/Gosu/Inspection.hpp +14 -0
  18. data/Gosu/Math.hpp +135 -0
  19. data/Gosu/Platform.hpp +93 -0
  20. data/Gosu/Sockets.hpp +156 -0
  21. data/Gosu/TR1.hpp +56 -0
  22. data/Gosu/Text.hpp +71 -0
  23. data/Gosu/TextInput.hpp +70 -0
  24. data/Gosu/Timing.hpp +16 -0
  25. data/Gosu/Utility.hpp +28 -0
  26. data/Gosu/Version.hpp +19 -0
  27. data/Gosu/WinUtility.hpp +75 -0
  28. data/Gosu/Window.hpp +145 -0
  29. data/examples/ChipmunkIntegration.rb +275 -0
  30. data/examples/CptnRuby.rb +223 -0
  31. data/examples/GosuZen.rb +68 -0
  32. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  33. data/examples/OpenGLIntegration.rb +226 -0
  34. data/examples/RMagickIntegration.rb +417 -0
  35. data/examples/TextInput.rb +154 -0
  36. data/examples/Tutorial.rb +131 -0
  37. data/examples/media/Beep.wav +0 -0
  38. data/examples/media/CptnRuby Gem.png +0 -0
  39. data/examples/media/CptnRuby Map.txt +25 -0
  40. data/examples/media/CptnRuby Tileset.png +0 -0
  41. data/examples/media/CptnRuby.png +0 -0
  42. data/examples/media/Cursor.png +0 -0
  43. data/examples/media/Earth.png +0 -0
  44. data/examples/media/Explosion.wav +0 -0
  45. data/examples/media/Landscape.svg +10 -0
  46. data/examples/media/LargeStar.png +0 -0
  47. data/examples/media/Smoke.png +0 -0
  48. data/examples/media/Soldier.png +0 -0
  49. data/examples/media/Space.png +0 -0
  50. data/examples/media/Star.png +0 -0
  51. data/examples/media/Starfighter.bmp +0 -0
  52. data/lib/gosu.rb +20 -0
  53. data/lib/gosu/patches.rb +81 -0
  54. data/lib/gosu/preview.rb +139 -0
  55. data/lib/gosu/run.rb +11 -0
  56. data/lib/gosu/swig_patches.rb +60 -0
  57. data/lib/gosu/zen.rb +89 -0
  58. data/lib64/2.1/gosu.so +0 -0
  59. data/lib64/FreeImage.dll +0 -0
  60. data/lib64/OpenAL32.dll +0 -0
  61. data/lib64/SDL2.dll +0 -0
  62. data/lib64/libsndfile.dll +0 -0
  63. metadata +110 -0
@@ -0,0 +1,110 @@
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
+ GOSU_DEPRECATED constexpr AlphaMode amDefault = AlphaMode::DEFAULT;
35
+ GOSU_DEPRECATED constexpr AlphaMode amInterpolate = AlphaMode::INTERPOLATE;
36
+ GOSU_DEPRECATED constexpr AlphaMode amAdd = AlphaMode::ADD;
37
+ GOSU_DEPRECATED constexpr AlphaMode amAdditive = AlphaMode::ADD;
38
+ GOSU_DEPRECATED 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
+ //! Flags that affect the tileability of an image.
72
+ enum BorderFlags
73
+ {
74
+ bfSmooth = 0,
75
+ bfTileableLeft = 1,
76
+ bfTileableTop = 2,
77
+ bfTileableRight = 4,
78
+ bfTileableBottom = 8,
79
+ bfTileable = bfTileableLeft | bfTileableTop | bfTileableRight | bfTileableBottom
80
+ };
81
+
82
+ #ifdef GOSU_IS_MAC
83
+ // TODO: Without this gigantic hack, Gosu crashes in the "scale" function,
84
+ // but _only_ when used from Ruby 1.9. It is unclear what might cause this -
85
+ // maybe a compiler bug that tries to use SSE functions with the wrong
86
+ // alignment. Adding __attribute__((aligned(16))) does not help, though.
87
+ struct Transform
88
+ {
89
+ double value[16];
90
+ bool operator==(const Transform &other) { for (int i = 0; i < 16; ++i) if ((*this)[i] != other[i]) return false; return true; }
91
+ const double &operator[](std::size_t idx) const { return value[idx]; }
92
+ double &operator[](std::size_t idx) { return value[idx]; }
93
+ };
94
+ #else
95
+ typedef std::tr1::array<double, 16> Transform;
96
+ #endif
97
+ Transform translate(double x, double y);
98
+ Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
99
+ Transform scale(double factor);
100
+ Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
101
+ Transform concat(const Transform& lhs, const Transform& rhs);
102
+
103
+ #ifndef SWIG
104
+ // A not so useful optimization - this was supposed to bypass the Z queue for immediate rendering.
105
+ // In retrospect, the only useful optimization would be to work down the Z queue on a second thread.
106
+ GOSU_DEPRECATED const double zImmediate = -std::numeric_limits<double>::infinity();
107
+ #endif
108
+ }
109
+
110
+ #endif
@@ -0,0 +1,269 @@
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
@@ -0,0 +1,122 @@
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 that can be drawn onto
23
+ //! graphics.
24
+ //! This constructor can handle PNG and BMP images. A color key of #ff00ff is
25
+ //! automatically applied to BMP type images. For more flexibility, use the
26
+ //! corresponding constructor that uses a Bitmap object.
27
+ Image(Graphics& graphics, const std::wstring& filename,
28
+ bool tileable = false);
29
+ //! Loads a portion of the the image at the given filename that can be
30
+ //! drawn onto graphics.
31
+ //! This constructor can handle PNG and BMP images. A color key of #ff00ff is
32
+ //! automatically applied to BMP type images. For more flexibility, use the
33
+ //! corresponding constructor that uses a Bitmap object.
34
+ Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
35
+ unsigned srcY, unsigned srcWidth, unsigned srcHeight,
36
+ bool tileable = false);
37
+
38
+ //! Converts the given bitmap into an image that can be drawn onto
39
+ //! graphics.
40
+ Image(Graphics& graphics, const Bitmap& source,
41
+ bool tileable = false);
42
+ //! Converts a portion of the given bitmap into an image that can be
43
+ //! drawn onto graphics.
44
+ Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
45
+ unsigned srcY, unsigned srcWidth, unsigned srcHeight,
46
+ bool tileable = false);
47
+
48
+ //! Creates an Image from a user-supplied instance of the ImageData interface.
49
+ explicit Image(GOSU_UNIQUE_PTR<ImageData> data);
50
+
51
+ unsigned width() const;
52
+ unsigned height() const;
53
+
54
+ //! Draws the image so its upper left corner is at (x; y).
55
+ void draw(double x, double y, ZPos z,
56
+ double factorX = 1, double factorY = 1,
57
+ Color c = Color::WHITE,
58
+ AlphaMode mode = amDefault) const;
59
+ //! Like draw(), but allows to give modulation colors for all four
60
+ //! corners.
61
+ void drawMod(double x, double y, ZPos z,
62
+ double factorX, double factorY,
63
+ Color c1, Color c2, Color c3, Color c4,
64
+ AlphaMode mode = amDefault) const;
65
+
66
+ //! Draws the image rotated by the given angle so that its rotation
67
+ //! center is at (x; y). Note that this is different from how all the
68
+ //! other drawing functions work!
69
+ //! \param angle See Math.hpp for an explanation of how Gosu interprets
70
+ //! angles.
71
+ //! \param centerX Relative horizontal position of the rotation center
72
+ //! on the image. 0 is the left border, 1 is the right border, 0.5 is
73
+ //! the center (and default).
74
+ //! \param centerY See centerX.
75
+ void drawRot(double x, double y, ZPos z,
76
+ double angle, double centerX = 0.5, double centerY = 0.5,
77
+ double factorX = 1, double factorY = 1,
78
+ Color c = Color::WHITE,
79
+ AlphaMode mode = amDefault) const;
80
+
81
+ //! Provides access to the underlying image data object.
82
+ ImageData& getData() const;
83
+ };
84
+
85
+ std::vector<Gosu::Image> loadTiles(Graphics& graphics, const Bitmap& bmp, int tileWidth, int tileHeight, bool tileable);
86
+ std::vector<Gosu::Image> loadTiles(Graphics& graphics, const std::wstring& bmp, int tileWidth, int tileHeight, bool tileable);
87
+
88
+ //! Convenience function that splits a BMP or PNG file into an array
89
+ //! of small rectangles and creates images from them.
90
+ //! \param tileWidth If positive, specifies the width of one tile in
91
+ //! pixels. If negative, the bitmap is divided into -tileWidth rows.
92
+ //! \param tileHeight See tileWidth.
93
+ //! \param appendTo STL container to which the images will be appended.
94
+ //! Must provide a push_back member function; vector<tr1::shared_ptr<Image>>
95
+ //! or boost::ptr_vector<Image> are good choices.
96
+ template<typename Container>
97
+ void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename, int tileWidth, int tileHeight, bool tileable, Container& appendTo)
98
+ {
99
+ std::vector<Gosu::Image> tiles = loadTiles(graphics, filename, tileWidth, tileHeight, tileable);
100
+ for (int i = 0, num = tiles.size(); i < num; ++i)
101
+ appendTo.push_back(typename Container::value_type(new Gosu::Image(tiles[i])));
102
+ }
103
+
104
+ //! Convenience function that splits a bitmap into an area of array
105
+ //! rectangles and creates images from them.
106
+ //! \param tileWidth If positive, specifies the width of one tile in
107
+ //! pixels. If negative, the bitmap is divided into -tileWidth rows.
108
+ //! \param tileHeight See tileWidth.
109
+ //! \param appendTo STL container to which the images will be appended.
110
+ //! Must provide a push_back member function; std::vector<std::tr1::shared_ptr<Image>>
111
+ //! or boost::ptr_vector<Image> are good choices.
112
+ template<typename Container>
113
+ void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
114
+ int tileWidth, int tileHeight, bool tileable, Container& appendTo)
115
+ {
116
+ std::vector<Gosu::Image> tiles = loadTiles(graphics, bmp, 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
+ }
121
+
122
+ #endif