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.
Files changed (249) hide show
  1. data/COPYING.txt +29 -0
  2. data/Gosu/Async.hpp +48 -0
  3. data/Gosu/Audio.hpp +145 -0
  4. data/Gosu/AutoLink.hpp +16 -0
  5. data/Gosu/Bitmap.hpp +85 -0
  6. data/Gosu/ButtonsMac.hpp +114 -0
  7. data/Gosu/ButtonsWin.hpp +111 -0
  8. data/Gosu/ButtonsX.hpp +115 -0
  9. data/Gosu/Color.hpp +172 -0
  10. data/Gosu/Directories.hpp +36 -0
  11. data/Gosu/Font.hpp +59 -0
  12. data/Gosu/Fwd.hpp +31 -0
  13. data/Gosu/Gosu.hpp +26 -0
  14. data/Gosu/Graphics.hpp +86 -0
  15. data/Gosu/GraphicsBase.hpp +45 -0
  16. data/Gosu/IO.hpp +255 -0
  17. data/Gosu/Image.hpp +148 -0
  18. data/Gosu/ImageData.hpp +45 -0
  19. data/Gosu/Input.hpp +116 -0
  20. data/Gosu/Math.hpp +95 -0
  21. data/Gosu/Platform.hpp +61 -0
  22. data/Gosu/RotFlip.hpp +116 -0
  23. data/Gosu/Sockets.hpp +129 -0
  24. data/Gosu/Text.hpp +47 -0
  25. data/Gosu/TextInput.hpp +57 -0
  26. data/Gosu/Timing.hpp +16 -0
  27. data/Gosu/Utility.hpp +24 -0
  28. data/Gosu/WinUtility.hpp +76 -0
  29. data/Gosu/Window.hpp +84 -0
  30. data/GosuImpl/Async.cpp +37 -0
  31. data/GosuImpl/AudioFmod.cpp +417 -0
  32. data/GosuImpl/AudioSDL.cpp +255 -0
  33. data/GosuImpl/DirectoriesMac.mm +38 -0
  34. data/GosuImpl/DirectoriesUnix.cpp +48 -0
  35. data/GosuImpl/DirectoriesWin.cpp +42 -0
  36. data/GosuImpl/FileUnix.cpp +100 -0
  37. data/GosuImpl/FileWin.cpp +83 -0
  38. data/GosuImpl/Graphics/Bitmap.cpp +116 -0
  39. data/GosuImpl/Graphics/BitmapBMP.cpp +232 -0
  40. data/GosuImpl/Graphics/BitmapColorKey.cpp +39 -0
  41. data/GosuImpl/Graphics/BitmapPNG.cpp +276 -0
  42. data/GosuImpl/Graphics/BitmapUtils.cpp +67 -0
  43. data/GosuImpl/Graphics/BlockAllocator.cpp +127 -0
  44. data/GosuImpl/Graphics/BlockAllocator.hpp +34 -0
  45. data/GosuImpl/Graphics/Color.cpp +126 -0
  46. data/GosuImpl/Graphics/Common.hpp +21 -0
  47. data/GosuImpl/Graphics/DrawOp.hpp +154 -0
  48. data/GosuImpl/Graphics/Font.cpp +110 -0
  49. data/GosuImpl/Graphics/Graphics.cpp +295 -0
  50. data/GosuImpl/Graphics/Image.cpp +159 -0
  51. data/GosuImpl/Graphics/LargeImageData.cpp +115 -0
  52. data/GosuImpl/Graphics/LargeImageData.hpp +37 -0
  53. data/GosuImpl/Graphics/RotFlip.cpp +184 -0
  54. data/GosuImpl/Graphics/TexChunk.cpp +77 -0
  55. data/GosuImpl/Graphics/TexChunk.hpp +40 -0
  56. data/GosuImpl/Graphics/Text.cpp +223 -0
  57. data/GosuImpl/Graphics/TextMac.cpp +242 -0
  58. data/GosuImpl/Graphics/TextPangoFT.cpp +186 -0
  59. data/GosuImpl/Graphics/TextWin.cpp +172 -0
  60. data/GosuImpl/Graphics/Texture.cpp +104 -0
  61. data/GosuImpl/Graphics/Texture.hpp +34 -0
  62. data/GosuImpl/IO.cpp +48 -0
  63. data/GosuImpl/InputMac.mm +677 -0
  64. data/GosuImpl/InputWin.cpp +444 -0
  65. data/GosuImpl/InputX.cpp +158 -0
  66. data/GosuImpl/MacUtility.hpp +48 -0
  67. data/GosuImpl/Math.cpp +49 -0
  68. data/GosuImpl/RubyGosu.swg +474 -0
  69. data/GosuImpl/RubyGosuStub.mm +17 -0
  70. data/GosuImpl/RubyGosu_DllMain.cxx +30 -0
  71. data/GosuImpl/RubyGosu_wrap.cxx +8521 -0
  72. data/GosuImpl/RubyGosu_wrap.h +31 -0
  73. data/GosuImpl/Sockets/CommSocket.cpp +304 -0
  74. data/GosuImpl/Sockets/ListenerSocket.cpp +60 -0
  75. data/GosuImpl/Sockets/MessageSocket.cpp +136 -0
  76. data/GosuImpl/Sockets/Socket.cpp +145 -0
  77. data/GosuImpl/Sockets/Sockets.hpp +66 -0
  78. data/GosuImpl/TextInputMac.mm +207 -0
  79. data/GosuImpl/TextInputWin.cpp +197 -0
  80. data/GosuImpl/TextInputX.cpp +201 -0
  81. data/GosuImpl/TextTTFWin.cpp +247 -0
  82. data/GosuImpl/TimingUnix.cpp +17 -0
  83. data/GosuImpl/TimingWin.cpp +28 -0
  84. data/GosuImpl/Utility.cpp +140 -0
  85. data/GosuImpl/WinMain.cpp +69 -0
  86. data/GosuImpl/WinUtility.cpp +137 -0
  87. data/GosuImpl/WindowMac.mm +466 -0
  88. data/GosuImpl/WindowWin.cpp +447 -0
  89. data/GosuImpl/WindowX.cpp +392 -0
  90. data/GosuImpl/X11vroot.h +118 -0
  91. data/README.txt +13 -0
  92. data/Rakefile +178 -0
  93. data/examples/ChipmunkIntegration.rb +275 -0
  94. data/examples/CptnRuby.rb +231 -0
  95. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  96. data/examples/OpenGLIntegration.rb +232 -0
  97. data/examples/RMagickIntegration.rb +449 -0
  98. data/examples/TextInput.cpp +170 -0
  99. data/examples/TextInput.rb +139 -0
  100. data/examples/Tutorial.cpp +215 -0
  101. data/examples/Tutorial.rb +137 -0
  102. data/examples/media/Beep.wav +0 -0
  103. data/examples/media/CptnRuby Gem.png +0 -0
  104. data/examples/media/CptnRuby Map.txt +25 -0
  105. data/examples/media/CptnRuby Tileset.png +0 -0
  106. data/examples/media/CptnRuby.png +0 -0
  107. data/examples/media/Cursor.png +0 -0
  108. data/examples/media/Earth.png +0 -0
  109. data/examples/media/Explosion.wav +0 -0
  110. data/examples/media/LargeStar.png +0 -0
  111. data/examples/media/Sky.jpg +0 -0
  112. data/examples/media/Smoke.png +0 -0
  113. data/examples/media/Soldier.png +0 -0
  114. data/examples/media/Space.png +0 -0
  115. data/examples/media/Star.png +0 -0
  116. data/examples/media/Starfighter.bmp +0 -0
  117. data/linux/Makefile.in +98 -0
  118. data/linux/configure +5658 -0
  119. data/linux/configure.ac +126 -0
  120. data/linux/extconf.rb +11 -0
  121. data/mac/English.lproj/InfoPlist.strings +0 -0
  122. data/mac/Gosu-Info.plist +26 -0
  123. data/mac/Gosu.xcodeproj/project.pbxproj +1194 -0
  124. data/mac/RubyGosu Template-Info.plist +26 -0
  125. data/mac/libboost_thread_1_34_1_universal.a +0 -0
  126. data/mac/libboost_thread_d_1_34_1_universal.a +0 -0
  127. data/mac/libfmod_universal.a +0 -0
  128. data/mac/libpng_universal.a +0 -0
  129. data/mac/libz_universal.a +0 -0
  130. data/reference/Async_8hpp-source.html +70 -0
  131. data/reference/Audio_8hpp-source.html +114 -0
  132. data/reference/Audio_8hpp.html +50 -0
  133. data/reference/AutoLink_8hpp-source.html +38 -0
  134. data/reference/AutoLink_8hpp.html +34 -0
  135. data/reference/Bitmap_8hpp-source.html +85 -0
  136. data/reference/Bitmap_8hpp.html +58 -0
  137. data/reference/ButtonsMac_8hpp-source.html +133 -0
  138. data/reference/ButtonsWin_8hpp-source.html +133 -0
  139. data/reference/ButtonsX_8hpp-source.html +134 -0
  140. data/reference/Color_8hpp-source.html +169 -0
  141. data/reference/Color_8hpp.html +85 -0
  142. data/reference/Directories_8hpp-source.html +42 -0
  143. data/reference/Directories_8hpp.html +46 -0
  144. data/reference/Font_8hpp-source.html +65 -0
  145. data/reference/Font_8hpp.html +41 -0
  146. data/reference/Fwd_8hpp-source.html +52 -0
  147. data/reference/Fwd_8hpp.html +37 -0
  148. data/reference/Gosu_8hpp-source.html +48 -0
  149. data/reference/Gosu_8hpp.html +34 -0
  150. data/reference/GraphicsBase_8hpp-source.html +57 -0
  151. data/reference/GraphicsBase_8hpp.html +56 -0
  152. data/reference/Graphics_8hpp-source.html +96 -0
  153. data/reference/Graphics_8hpp.html +53 -0
  154. data/reference/IO_8hpp-source.html +255 -0
  155. data/reference/IO_8hpp.html +74 -0
  156. data/reference/ImageData_8hpp-source.html +62 -0
  157. data/reference/ImageData_8hpp.html +43 -0
  158. data/reference/Image_8hpp-source.html +126 -0
  159. data/reference/Image_8hpp.html +48 -0
  160. data/reference/Input_8hpp-source.html +118 -0
  161. data/reference/Input_8hpp.html +50 -0
  162. data/reference/Math_8hpp-source.html +92 -0
  163. data/reference/Math_8hpp.html +74 -0
  164. data/reference/Platform_8hpp-source.html +83 -0
  165. data/reference/Platform_8hpp.html +73 -0
  166. data/reference/RotFlip_8hpp-source.html +138 -0
  167. data/reference/RotFlip_8hpp.html +77 -0
  168. data/reference/Sockets_8hpp-source.html +130 -0
  169. data/reference/Sockets_8hpp.html +66 -0
  170. data/reference/TextInput_8hpp-source.html +64 -0
  171. data/reference/TextInput_8hpp.html +41 -0
  172. data/reference/Text_8hpp-source.html +51 -0
  173. data/reference/Text_8hpp.html +46 -0
  174. data/reference/Timing_8hpp-source.html +36 -0
  175. data/reference/Timing_8hpp.html +42 -0
  176. data/reference/Utility_8hpp-source.html +44 -0
  177. data/reference/Utility_8hpp.html +48 -0
  178. data/reference/WinUtility_8hpp-source.html +79 -0
  179. data/reference/WinUtility_8hpp.html +64 -0
  180. data/reference/Window_8hpp-source.html +91 -0
  181. data/reference/Window_8hpp.html +41 -0
  182. data/reference/annotated.html +51 -0
  183. data/reference/classGosu_1_1Audio-members.html +34 -0
  184. data/reference/classGosu_1_1Audio.html +46 -0
  185. data/reference/classGosu_1_1Bitmap-members.html +44 -0
  186. data/reference/classGosu_1_1Bitmap.html +263 -0
  187. data/reference/classGosu_1_1Buffer-members.html +44 -0
  188. data/reference/classGosu_1_1Buffer.html +78 -0
  189. data/reference/classGosu_1_1Buffer.png +0 -0
  190. data/reference/classGosu_1_1Button-members.html +36 -0
  191. data/reference/classGosu_1_1Button.html +143 -0
  192. data/reference/classGosu_1_1Color-members.html +56 -0
  193. data/reference/classGosu_1_1Color.html +387 -0
  194. data/reference/classGosu_1_1File-members.html +41 -0
  195. data/reference/classGosu_1_1File.html +69 -0
  196. data/reference/classGosu_1_1File.png +0 -0
  197. data/reference/classGosu_1_1Font-members.html +39 -0
  198. data/reference/classGosu_1_1Font.html +309 -0
  199. data/reference/classGosu_1_1Graphics-members.html +50 -0
  200. data/reference/classGosu_1_1Graphics.html +234 -0
  201. data/reference/classGosu_1_1Image-members.html +45 -0
  202. data/reference/classGosu_1_1Image.html +518 -0
  203. data/reference/classGosu_1_1ImageData-members.html +37 -0
  204. data/reference/classGosu_1_1ImageData.html +60 -0
  205. data/reference/classGosu_1_1Input-members.html +44 -0
  206. data/reference/classGosu_1_1Input.html +223 -0
  207. data/reference/classGosu_1_1MessageSocket-members.html +40 -0
  208. data/reference/classGosu_1_1MessageSocket.html +233 -0
  209. data/reference/classGosu_1_1Resource-members.html +39 -0
  210. data/reference/classGosu_1_1Resource.html +116 -0
  211. data/reference/classGosu_1_1Resource.png +0 -0
  212. data/reference/classGosu_1_1Sample-members.html +37 -0
  213. data/reference/classGosu_1_1Sample.html +200 -0
  214. data/reference/classGosu_1_1SampleInstance-members.html +38 -0
  215. data/reference/classGosu_1_1SampleInstance.html +169 -0
  216. data/reference/classGosu_1_1Song-members.html +43 -0
  217. data/reference/classGosu_1_1Song.html +260 -0
  218. data/reference/classGosu_1_1TextInput-members.html +38 -0
  219. data/reference/classGosu_1_1TextInput.html +121 -0
  220. data/reference/classGosu_1_1Window-members.html +50 -0
  221. data/reference/classGosu_1_1Window.html +271 -0
  222. data/reference/doxyfile +233 -0
  223. data/reference/doxygen.css +433 -0
  224. data/reference/doxygen.png +0 -0
  225. data/reference/files.html +54 -0
  226. data/reference/functions.html +236 -0
  227. data/reference/functions_enum.html +45 -0
  228. data/reference/functions_func.html +227 -0
  229. data/reference/functions_vars.html +47 -0
  230. data/reference/hierarchy.html +53 -0
  231. data/reference/index.html +26 -0
  232. data/reference/namespaceGosu.html +2890 -0
  233. data/reference/namespaceGosu_1_1Colors.html +70 -0
  234. data/reference/namespaceGosu_1_1Win.html +275 -0
  235. data/reference/namespacemembers.html +216 -0
  236. data/reference/namespacemembers_enum.html +52 -0
  237. data/reference/namespacemembers_eval.html +54 -0
  238. data/reference/namespacemembers_func.html +185 -0
  239. data/reference/namespacemembers_type.html +46 -0
  240. data/reference/namespacemembers_vars.html +46 -0
  241. data/reference/namespaces.html +35 -0
  242. data/reference/tab_b.gif +0 -0
  243. data/reference/tab_l.gif +0 -0
  244. data/reference/tab_r.gif +0 -0
  245. data/reference/tabs.css +102 -0
  246. data/windows/Gosu.sln +29 -0
  247. data/windows/Gosu.vcproj +553 -0
  248. data/windows/RubyGosu.vcproj +138 -0
  249. 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
@@ -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
@@ -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
@@ -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