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,295 @@
1
+ #include <Gosu/Graphics.hpp>
2
+ #include <GosuImpl/Graphics/Common.hpp>
3
+ #include <GosuImpl/Graphics/DrawOp.hpp>
4
+ #include <GosuImpl/Graphics/Texture.hpp>
5
+ #include <GosuImpl/Graphics/TexChunk.hpp>
6
+ #include <GosuImpl/Graphics/LargeImageData.hpp>
7
+ #include <Gosu/Bitmap.hpp>
8
+ #if 0
9
+ #include <boost/thread.hpp>
10
+ #endif
11
+ #include <cmath>
12
+
13
+ struct Gosu::Graphics::Impl
14
+ {
15
+ unsigned physWidth, physHeight;
16
+ unsigned virtWidth, virtHeight;
17
+ double factorX, factorY;
18
+ bool fullscreen;
19
+ DrawOpQueue queue;
20
+ typedef std::vector<boost::shared_ptr<Texture> > Textures;
21
+ Textures textures;
22
+ #if 0
23
+ boost::mutex texMutex;
24
+ #endif
25
+ };
26
+
27
+ Gosu::Graphics::Graphics(unsigned physWidth, unsigned physHeight, bool fullscreen)
28
+ : pimpl(new Impl)
29
+ {
30
+ pimpl->physWidth = pimpl->virtWidth = physWidth;
31
+ pimpl->physHeight = pimpl->virtHeight = physHeight;
32
+ pimpl->factorX = pimpl->factorY = 1.0;
33
+ pimpl->fullscreen = fullscreen;
34
+
35
+ glMatrixMode(GL_PROJECTION);
36
+ glLoadIdentity();
37
+ glViewport(0, 0, pimpl->physWidth, pimpl->physHeight);
38
+ glOrtho(0, pimpl->virtWidth, pimpl->virtHeight, 0, -1, 1);
39
+
40
+ glMatrixMode(GL_MODELVIEW);
41
+ glLoadIdentity();
42
+
43
+ glEnable(GL_BLEND);
44
+ }
45
+
46
+ Gosu::Graphics::~Graphics()
47
+ {
48
+ }
49
+
50
+ unsigned Gosu::Graphics::width() const
51
+ {
52
+ return pimpl->virtWidth;
53
+ }
54
+
55
+ unsigned Gosu::Graphics::height() const
56
+ {
57
+ return pimpl->virtHeight;
58
+ }
59
+
60
+ bool Gosu::Graphics::fullscreen() const
61
+ {
62
+ return pimpl->fullscreen;
63
+ }
64
+
65
+ double Gosu::Graphics::factorX() const
66
+ {
67
+ return pimpl->factorX;
68
+ }
69
+
70
+ double Gosu::Graphics::factorY() const
71
+ {
72
+ return pimpl->factorY;
73
+ }
74
+
75
+ void Gosu::Graphics::setResolution(unsigned virtualWidth, unsigned virtualHeight)
76
+ {
77
+ if (virtualWidth * virtualHeight < 1)
78
+ throw std::invalid_argument("Invalid virtual resolution.");
79
+
80
+ pimpl->virtWidth = virtualWidth;
81
+ pimpl->virtHeight = virtualHeight;
82
+ pimpl->factorX = 1.0 / virtualWidth * pimpl->physWidth;
83
+ pimpl->factorY = 1.0 / virtualHeight * pimpl->physHeight;
84
+ }
85
+
86
+ bool Gosu::Graphics::begin(Gosu::Color clearWithColor)
87
+ {
88
+ // Flush leftover clippings
89
+ endClipping();
90
+
91
+ glClearColor(clearWithColor.red()/255.0,
92
+ clearWithColor.green()/255.0,
93
+ clearWithColor.blue()/255.0,
94
+ clearWithColor.alpha()/255.0);
95
+ glClear(GL_COLOR_BUFFER_BIT);
96
+
97
+ return true;
98
+ }
99
+
100
+ void Gosu::Graphics::end()
101
+ {
102
+ pimpl->queue.performDrawOps();
103
+ glFlush();
104
+ }
105
+
106
+ void Gosu::Graphics::beginGL()
107
+ {
108
+ pimpl->queue.performDrawOps();
109
+ glPushAttrib(GL_ALL_ATTRIB_BITS);
110
+ glDisable(GL_BLEND);
111
+ }
112
+
113
+ void Gosu::Graphics::endGL()
114
+ {
115
+ glPopAttrib();
116
+
117
+ // Restore matrices.
118
+
119
+ glMatrixMode(GL_PROJECTION);
120
+ glLoadIdentity();
121
+ glViewport(0, 0, pimpl->physWidth, pimpl->physHeight);
122
+ glOrtho(0, pimpl->virtWidth, pimpl->virtHeight, 0, -1, 1);
123
+
124
+ glMatrixMode(GL_MODELVIEW);
125
+ glLoadIdentity();
126
+ glEnable(GL_BLEND);
127
+ }
128
+
129
+ void Gosu::Graphics::beginClipping(int x, int y, unsigned width, unsigned height)
130
+ {
131
+ // In doubt, make the clipping region smaller than requested.
132
+
133
+ int physX = static_cast<int>(std::ceil(x * factorX()));
134
+ int physY = static_cast<int>(std::ceil((0.0 + this->height() - y - height) * factorY()));
135
+ unsigned physWidth = static_cast<unsigned>(width * factorX());
136
+ unsigned physHeight = static_cast<unsigned>(height * factorY());
137
+
138
+ pimpl->queue.beginClipping(physX, physY, physWidth, physHeight);
139
+ }
140
+
141
+ void Gosu::Graphics::endClipping()
142
+ {
143
+ pimpl->queue.endClipping();
144
+ }
145
+
146
+ void Gosu::Graphics::drawLine(double x1, double y1, Color c1,
147
+ double x2, double y2, Color c2,
148
+ ZPos z, AlphaMode mode)
149
+ {
150
+ DrawOp op;
151
+
152
+ x1 *= factorX();
153
+ y1 *= factorY();
154
+ x2 *= factorX();
155
+ y2 *= factorY();
156
+
157
+ op.mode = mode;
158
+ op.usedVertices = 2;
159
+ op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
160
+ op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
161
+
162
+ pimpl->queue.addDrawOp(op, z);
163
+ }
164
+
165
+ void Gosu::Graphics::drawTriangle(double x1, double y1, Color c1,
166
+ double x2, double y2, Color c2,
167
+ double x3, double y3, Color c3,
168
+ ZPos z, AlphaMode mode)
169
+ {
170
+ DrawOp op;
171
+
172
+ x1 *= factorX();
173
+ y1 *= factorY();
174
+ x2 *= factorX();
175
+ y2 *= factorY();
176
+ x3 *= factorX();
177
+ y3 *= factorY();
178
+
179
+ op.mode = mode;
180
+ op.usedVertices = 3;
181
+ op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
182
+ op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
183
+ op.vertices[2] = DrawOp::Vertex(x3, y3, c3);
184
+
185
+ pimpl->queue.addDrawOp(op, z);
186
+ }
187
+
188
+ void Gosu::Graphics::drawQuad(double x1, double y1, Color c1,
189
+ double x2, double y2, Color c2,
190
+ double x3, double y3, Color c3,
191
+ double x4, double y4, Color c4,
192
+ ZPos z, AlphaMode mode)
193
+ {
194
+ DrawOp op;
195
+
196
+ x1 *= factorX();
197
+ y1 *= factorY();
198
+ x2 *= factorX();
199
+ y2 *= factorY();
200
+ x3 *= factorX();
201
+ y3 *= factorY();
202
+ x4 *= factorX();
203
+ y4 *= factorY();
204
+
205
+ op.mode = mode;
206
+ op.usedVertices = 4;
207
+ op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
208
+ op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
209
+ op.vertices[3] = DrawOp::Vertex(x3, y3, c3);
210
+ op.vertices[2] = DrawOp::Vertex(x4, y4, c4);
211
+
212
+ pimpl->queue.addDrawOp(op, z);
213
+ }
214
+
215
+ std::auto_ptr<Gosu::ImageData> Gosu::Graphics::createImage(
216
+ const Bitmap& src, unsigned srcX, unsigned srcY,
217
+ unsigned srcWidth, unsigned srcHeight, unsigned borderFlags)
218
+ {
219
+ static const unsigned maxSize = Texture::maxTextureSize();
220
+
221
+ // Special case: If the texture is supposed to have hard borders,
222
+ // is quadratic, has a size that is at least 64 pixels but less than 256
223
+ // pixels and a power of two, create a single texture just for this image.
224
+ /*if ((borderFlags & bfHard) == bfHard &&
225
+ srcWidth == srcHeight &&
226
+ srcWidth >= 64 && srcWidth <= 256 &&
227
+ (srcWidth & (srcWidth - 1)) == 0)
228
+ {
229
+ boost::shared_ptr<Texture> texture(new Texture(srcWidth));
230
+ std::auto_ptr<ImageData> data;
231
+
232
+ // Use the source bitmap directly if the source area completely covers
233
+ // it.
234
+ if (srcX == 0 && srcWidth == src.width() &&
235
+ srcY == 0 && srcHeight == src.height())
236
+ {
237
+ data = texture->tryAlloc(*this, pimpl->queue, texture,
238
+ src, 0, 0, src.width(), src.height(), 0);
239
+ }
240
+ else
241
+ {
242
+ Bitmap trimmedSrc;
243
+ trimmedSrc.resize(srcWidth, srcHeight);
244
+ trimmedSrc.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
245
+ data = texture->tryAlloc(*this, pimpl->queue, texture,
246
+ trimmedSrc, 0, 0, trimmedSrc.width(), trimmedSrc.height(), 0);
247
+ }
248
+
249
+ if (!data.get())
250
+ throw std::logic_error("Internal texture block allocation error");
251
+ return data;
252
+ }*/
253
+
254
+ // Too large to fit on a single texture.
255
+ if (srcWidth > maxSize - 2 || srcHeight > maxSize - 2)
256
+ {
257
+ Bitmap bmp;
258
+ bmp.resize(srcWidth, srcHeight);
259
+ bmp.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
260
+ std::auto_ptr<ImageData> lidi;
261
+ lidi.reset(new LargeImageData(*this, bmp, maxSize - 2, maxSize - 2, borderFlags));
262
+ return lidi;
263
+ }
264
+
265
+ Bitmap bmp;
266
+ applyBorderFlags(bmp, src, srcX, srcY, srcWidth, srcHeight, borderFlags);
267
+
268
+ #if 0
269
+ boost::mutex::scoped_lock lock(pimpl->texMutex);
270
+ #endif
271
+
272
+ // Try to put the bitmap into one of the already allocated textures.
273
+ for (Impl::Textures::iterator i = pimpl->textures.begin(); i != pimpl->textures.end(); ++i)
274
+ {
275
+ boost::shared_ptr<Texture> texture(*i);
276
+
277
+ std::auto_ptr<ImageData> data;
278
+ data = texture->tryAlloc(*this, pimpl->queue, texture, bmp, 0, 0, bmp.width(), bmp.height(), 1);
279
+ if (data.get())
280
+ return data;
281
+ }
282
+
283
+ // All textures are full: Create a new one.
284
+
285
+ boost::shared_ptr<Texture> texture;
286
+ texture.reset(new Texture(maxSize));
287
+ pimpl->textures.push_back(texture);
288
+
289
+ std::auto_ptr<ImageData> data;
290
+ data = texture->tryAlloc(*this, pimpl->queue, texture, bmp, 0, 0, bmp.width(), bmp.height(), 1);
291
+ if (!data.get())
292
+ throw std::logic_error("Internal texture block allocation error");
293
+
294
+ return data;
295
+ }
@@ -0,0 +1,159 @@
1
+ #include <Gosu/Image.hpp>
2
+ #include <Gosu/Bitmap.hpp>
3
+ #include <Gosu/Graphics.hpp>
4
+ #include <Gosu/ImageData.hpp>
5
+ #include <Gosu/Math.hpp>
6
+ #include <Gosu/IO.hpp>
7
+
8
+ Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, bool hardBorders)
9
+ {
10
+ // Forward.
11
+ Image(graphics, quickLoadBitmap(filename), hardBorders).data.swap(data);
12
+ }
13
+
14
+ Gosu::Image::Image(Graphics& graphics, const std::wstring& filename,
15
+ unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
16
+ bool hardBorders)
17
+ {
18
+ // Forward.
19
+ Image(graphics, quickLoadBitmap(filename), srcX, srcY, srcWidth, srcHeight, hardBorders).data.swap(data);
20
+ }
21
+
22
+ Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool hardBorders)
23
+ {
24
+ // Forward.
25
+ Image(graphics, source, 0, 0, source.width(), source.height(), hardBorders).data.swap(data);
26
+ }
27
+
28
+ Gosu::Image::Image(Graphics& graphics, const Bitmap& source,
29
+ unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
30
+ bool hardBorders)
31
+ : data(graphics.createImage(source, srcX, srcY, srcWidth, srcHeight,
32
+ hardBorders ? Gosu::bfHard : Gosu::bfSoft))
33
+ {
34
+ }
35
+
36
+ Gosu::Image::~Image()
37
+ {
38
+ }
39
+
40
+ unsigned Gosu::Image::width() const
41
+ {
42
+ return data->width();
43
+ }
44
+
45
+ unsigned Gosu::Image::height() const
46
+ {
47
+ return data->height();
48
+ }
49
+
50
+ void Gosu::Image::draw(double x, double y, ZPos z,
51
+ double factorX, double factorY,
52
+ Color c,
53
+ AlphaMode mode) const
54
+ {
55
+ double x2 = x + width() * factorX;
56
+ double y2 = y + height() * factorY;
57
+
58
+ data->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
59
+ }
60
+
61
+ void Gosu::Image::drawMod(double x, double y, ZPos z,
62
+ double factorX, double factorY,
63
+ Color c1, Color c2, Color c3, Color c4,
64
+ AlphaMode mode) const
65
+ {
66
+ double x2 = x + width() * factorX;
67
+ double y2 = y + height() * factorY;
68
+
69
+ data->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
70
+ }
71
+
72
+ void Gosu::Image::drawRot(double x, double y, ZPos z,
73
+ double angle, double centerX, double centerY,
74
+ double factorX, double factorY,
75
+ Color c,
76
+ AlphaMode mode) const
77
+ {
78
+ double sizeX = width() * factorX;
79
+ double sizeY = height() * factorY;
80
+ double offsX = offsetX(angle, 1);
81
+ double offsY = offsetY(angle, 1);
82
+
83
+ // Offset to the centers of the original Image's edges when it is rotated
84
+ // by <angle> degrees.
85
+ double distToLeftX = +offsY * sizeX * centerX;
86
+ double distToLeftY = -offsX * sizeX * centerX;
87
+ double distToRightX = -offsY * sizeX * (1 - centerX);
88
+ double distToRightY = +offsX * sizeX * (1 - centerX);
89
+ double distToTopX = +offsX * sizeY * centerY;
90
+ double distToTopY = +offsY * sizeY * centerY;
91
+ double distToBottomX = -offsX * sizeY * (1 - centerY);
92
+ double distToBottomY = -offsY * sizeY * (1 - centerY);
93
+
94
+ data->draw(x + distToLeftX + distToTopX,
95
+ y + distToLeftY + distToTopY, c,
96
+ x + distToRightX + distToTopX,
97
+ y + distToRightY + distToTopY, c,
98
+ x + distToLeftX + distToBottomX,
99
+ y + distToLeftY + distToBottomY, c,
100
+ x + distToRightX + distToBottomX,
101
+ y + distToRightY + distToBottomY,
102
+ c, z, mode);
103
+ }
104
+
105
+ void Gosu::Image::drawRotFlip(double x, double y, ZPos z,
106
+ RotFlip rf,
107
+ double factorX, double factorY,
108
+ Color c,
109
+ AlphaMode mode) const
110
+ {
111
+ drawRotFlipMod(x, y, z, rf, factorX, factorY, c, c, c, c, mode);
112
+ }
113
+
114
+ void Gosu::Image::drawRotFlipMod(double x, double y, ZPos z,
115
+ RotFlip rf,
116
+ double factorX, double factorY,
117
+ Color c1, Color c2, Color c3, Color c4,
118
+ AlphaMode mode) const
119
+ {
120
+ double offsetX;
121
+ double offsetY;
122
+
123
+ if (rf.rotated())
124
+ {
125
+ offsetX = height() * factorY / 2;
126
+ offsetY = width() * factorX / 2;
127
+ }
128
+ else
129
+ {
130
+ offsetX = width() * factorX / 2;
131
+ offsetY = height() * factorY / 2;
132
+ }
133
+
134
+ struct Point
135
+ {
136
+ double x, y;
137
+ };
138
+
139
+ Point corners[4] = { { x - offsetX, y - offsetY },
140
+ { x + offsetX, y - offsetY },
141
+ { x - offsetX, y + offsetY },
142
+ { x + offsetX, y + offsetY } };
143
+
144
+ Point* vertices[4] =
145
+ { &corners[rf.mapCorner(0)], &corners[rf.mapCorner(1)],
146
+ &corners[rf.mapCorner(2)], &corners[rf.mapCorner(3)] };
147
+
148
+ data->draw(
149
+ vertices[0]->x, vertices[0]->y, c1,
150
+ vertices[1]->x, vertices[1]->y, c2,
151
+ vertices[2]->x, vertices[2]->y, c3,
152
+ vertices[3]->x, vertices[3]->y, c4,
153
+ z, mode);
154
+ }
155
+
156
+ const Gosu::ImageData& Gosu::Image::getData() const
157
+ {
158
+ return *data;
159
+ }