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,115 @@
1
+ #include <GosuImpl/Graphics/LargeImageData.hpp>
2
+ #include <Gosu/Bitmap.hpp>
3
+ #include <Gosu/Graphics.hpp>
4
+ #include <Gosu/Math.hpp>
5
+ #include <cmath>
6
+ using namespace std;
7
+
8
+ Gosu::LargeImageData::LargeImageData(Graphics& graphics,
9
+ const Bitmap& source, unsigned partWidth, unsigned partHeight,
10
+ unsigned borderFlags)
11
+ {
12
+ fullWidth = source.width();
13
+ fullHeight = source.height();
14
+ partsX = trunc(ceil(1.0 * source.width() / partWidth));
15
+ partsY = trunc(ceil(1.0 * source.height() / partHeight));
16
+ this->partWidth = partWidth;
17
+ this->partHeight = partHeight;
18
+
19
+ parts.resize(partsX * partsY);
20
+
21
+ for (unsigned y = 0; y < partsY; ++y)
22
+ for (unsigned x = 0; x < partsX; ++x)
23
+ {
24
+ // The right-most parts don't necessarily have the full width.
25
+ unsigned srcWidth = partWidth;
26
+ if (x == partsX - 1 && source.width() % partWidth != 0)
27
+ srcWidth = source.width() % partWidth;
28
+
29
+ // Same for the parts on the bottom.
30
+ unsigned srcHeight = partHeight;
31
+ if (y == partsY - 1 && source.height() % partHeight != 0)
32
+ srcHeight = source.height() % partHeight;
33
+
34
+ unsigned localBorderFlags = bfHard;
35
+ if (x == 0)
36
+ localBorderFlags &= ~(borderFlags & bfHardLeft);
37
+ else if (x == partsX - 1)
38
+ localBorderFlags &= ~(borderFlags & bfHardRight);
39
+ if (y == 0)
40
+ localBorderFlags &= ~(borderFlags & bfHardTop);
41
+ else if (y == partsY - 1)
42
+ localBorderFlags &= ~(borderFlags & bfHardBottom);
43
+
44
+ parts[y * partsX + x].reset(graphics.createImage(source,
45
+ x * partWidth, y * partHeight, srcWidth, srcHeight,
46
+ localBorderFlags).release());
47
+ }
48
+ }
49
+
50
+ unsigned Gosu::LargeImageData::width() const
51
+ {
52
+ return fullWidth;
53
+ }
54
+
55
+ unsigned Gosu::LargeImageData::height() const
56
+ {
57
+ return fullHeight;
58
+ }
59
+
60
+ namespace
61
+ {
62
+ // Local interpolation helper functions.
63
+
64
+ double ipl(double a, double b, double ratio)
65
+ {
66
+ return a + (b - a) * ratio;
67
+ }
68
+
69
+ Gosu::Color ipl(Gosu::Color a, Gosu::Color b, double ratio)
70
+ {
71
+ Gosu::Color result;
72
+ result.setAlpha(Gosu::round(ipl(a.alpha(), b.alpha(), ratio)));
73
+ result.setRed (Gosu::round(ipl(a.red(), b.red(), ratio)));
74
+ result.setGreen(Gosu::round(ipl(a.green(), b.green(), ratio)));
75
+ result.setBlue (Gosu::round(ipl(a.blue(), b.blue(), ratio)));
76
+ return result;
77
+ }
78
+ }
79
+
80
+ void Gosu::LargeImageData::draw(double x1, double y1, Color c1,
81
+ double x2, double y2, Color c2, double x3, double y3, Color c3,
82
+ double x4, double y4, Color c4, ZPos z, AlphaMode mode) const
83
+ {
84
+ if (parts.empty())
85
+ return;
86
+
87
+ for (unsigned py = 0; py < partsY; ++py)
88
+ for (unsigned px = 0; px < partsX; ++px)
89
+ {
90
+ const ImageData& part = *parts[py * partsX + px];
91
+
92
+ double relXL = static_cast<double>(px * partWidth) / width();
93
+ double relXR = static_cast<double>(px * partWidth + part.width()) / width();
94
+ double relYT = static_cast<double>(py * partHeight) / height();
95
+ double relYB = static_cast<double>(py * partHeight + part.height()) / height();
96
+
97
+ double absXTL = ipl(ipl(x1, x3, relYT), ipl(x2, x4, relYT), relXL);
98
+ double absXTR = ipl(ipl(x1, x3, relYT), ipl(x2, x4, relYT), relXR);
99
+ double absXBL = ipl(ipl(x1, x3, relYB), ipl(x2, x4, relYB), relXL);
100
+ double absXBR = ipl(ipl(x1, x3, relYB), ipl(x2, x4, relYB), relXR);
101
+
102
+ double absYTL = ipl(ipl(y1, y3, relYT), ipl(y2, y4, relYT), relXL);
103
+ double absYTR = ipl(ipl(y1, y3, relYT), ipl(y2, y4, relYT), relXR);
104
+ double absYBL = ipl(ipl(y1, y3, relYB), ipl(y2, y4, relYB), relXL);
105
+ double absYBR = ipl(ipl(y1, y3, relYB), ipl(y2, y4, relYB), relXR);
106
+
107
+ Color absCTL = ipl(ipl(c1, c3, relYT), ipl(c2, c4, relYT), relXL);
108
+ Color absCTR = ipl(ipl(c1, c3, relYT), ipl(c2, c4, relYT), relXR);
109
+ Color absCBL = ipl(ipl(c1, c3, relYB), ipl(c2, c4, relYB), relXL);
110
+ Color absCBR = ipl(ipl(c1, c3, relYB), ipl(c2, c4, relYB), relXR);
111
+
112
+ part.draw(absXTL, absYTL, absCTL, absXTR, absYTR, absCTR,
113
+ absXBL, absYBL, absCBL, absXBR, absYBR, absCBR, z, mode);
114
+ }
115
+ }
@@ -0,0 +1,37 @@
1
+ #ifndef GOSUIMPL_LARGEIMAGEDATA_HPP
2
+ #define GOSUIMPL_LARGEIMAGEDATA_HPP
3
+
4
+ #include <Gosu/Fwd.hpp>
5
+ #include <Gosu/ImageData.hpp>
6
+ #include <boost/none.hpp>
7
+ #include <boost/shared_ptr.hpp>
8
+ #include <vector>
9
+
10
+ namespace Gosu
11
+ {
12
+ class LargeImageData : public ImageData
13
+ {
14
+ unsigned fullWidth, fullHeight, partsX, partsY, partWidth, partHeight;
15
+ std::vector<boost::shared_ptr<ImageData> > parts;
16
+
17
+ public:
18
+ LargeImageData(Graphics& graphics, const Bitmap& source,
19
+ unsigned partWidth, unsigned partHeight, unsigned borderFlags);
20
+
21
+ unsigned width() const;
22
+ unsigned height() const;
23
+
24
+ void draw(double x1, double y1, Color c1,
25
+ double x2, double y2, Color c2,
26
+ double x3, double y3, Color c3,
27
+ double x4, double y4, Color c4,
28
+ ZPos z, AlphaMode mode) const;
29
+
30
+ boost::optional<GLTexInfo> glTexInfo() const
31
+ {
32
+ return boost::none;
33
+ }
34
+ };
35
+ }
36
+
37
+ #endif
@@ -0,0 +1,184 @@
1
+ #include <Gosu/RotFlip.hpp>
2
+ #include <algorithm>
3
+
4
+ const Gosu::RotFlip::TransTable Gosu::RotFlip::flipXTable =
5
+ {
6
+ // rfDefault ->
7
+ rfFlipX,
8
+ // rfRotate90 ->
9
+ rfRotate90FlipX,
10
+ // rfRotate180 ->
11
+ rfRotate180FlipX,
12
+ // rfRotate270 ->
13
+ rfRotate270FlipX,
14
+ // rfFlipX ->
15
+ rfDefault,
16
+ // rfRotate90FlipX ->
17
+ rfRotate90,
18
+ // rfRotate180FlipX ->
19
+ rfRotate180,
20
+ // rfRotate270FlipX ->
21
+ rfRotate270
22
+ };
23
+
24
+ const Gosu::RotFlip::TransTable Gosu::RotFlip::flipYTable =
25
+ {
26
+ // rfDefault ->
27
+ rfFlipY,
28
+ // rfRotate90 ->
29
+ rfRotate90FlipY,
30
+ // rfRotate180 ->
31
+ rfRotate180FlipY,
32
+ // rfRotate270 ->
33
+ rfRotate270FlipY,
34
+ // rfFlipX ->
35
+ rfRotate180,
36
+ // rfRotate90FlipX ->
37
+ rfRotate270,
38
+ // rfRotate180FlipX ->
39
+ rfDefault,
40
+ // rfRotate270FlipX ->
41
+ rfRotate90
42
+ };
43
+
44
+ const Gosu::RotFlip::TransTable Gosu::RotFlip::rotate90Table =
45
+ {
46
+ // rfDefault ->
47
+ rfRotate90,
48
+ // rfRotate90 ->
49
+ rfRotate180,
50
+ // rfRotate180 ->
51
+ rfRotate270,
52
+ // rfRotate270 ->
53
+ rfDefault,
54
+ // rfFlipX ->
55
+ rfFlipXRotate90,
56
+ // rfRotate90FlipX ->
57
+ rfFlipX,
58
+ // rfRotate180FlipX ->
59
+ rfFlipYRotate90,
60
+ // rfRotate270FlipX ->
61
+ rfFlipY
62
+ };
63
+
64
+ const Gosu::RotFlip::TransTable Gosu::RotFlip::rotate180Table =
65
+ {
66
+ // rfDefault ->
67
+ rotate90Table[rotate90Table[rfDefault]],
68
+ // rfRotate90 ->
69
+ rotate90Table[rotate90Table[rfRotate90]],
70
+ // rfRotate180 ->
71
+ rotate90Table[rotate90Table[rfRotate180]],
72
+ // rfRotate270 ->
73
+ rotate90Table[rotate90Table[rfRotate270]],
74
+ // rfFlipX ->
75
+ rotate90Table[rotate90Table[rfFlipX]],
76
+ // rfRotate90FlipX ->
77
+ rotate90Table[rotate90Table[rfRotate90FlipX]],
78
+ // rfRotate180FlipX ->
79
+ rotate90Table[rotate90Table[rfRotate180FlipX]],
80
+ // rfRotate270FlipX ->
81
+ rotate90Table[rotate90Table[rfRotate270FlipX]],
82
+ };
83
+
84
+ const Gosu::RotFlip::TransTable Gosu::RotFlip::rotate270Table =
85
+ {
86
+ // rfDefault ->
87
+ rotate90Table[rotate180Table[rfDefault]],
88
+ // rfRotate90 ->
89
+ rotate90Table[rotate180Table[rfRotate90]],
90
+ // rfRotate180 ->
91
+ rotate90Table[rotate180Table[rfRotate180]],
92
+ // rfRotate270 ->
93
+ rotate90Table[rotate180Table[rfRotate270]],
94
+ // rfFlipX ->
95
+ rotate90Table[rotate180Table[rfFlipX]],
96
+ // rfRotate90FlipX ->
97
+ rotate90Table[rotate180Table[rfRotate90FlipX]],
98
+ // rfRotate180FlipX ->
99
+ rotate90Table[rotate180Table[rfRotate180FlipX]],
100
+ // rfRotate270FlipX ->
101
+ rotate90Table[rotate180Table[rfRotate270FlipX]],
102
+ };
103
+
104
+ const Gosu::RotFlip::CornerTable Gosu::RotFlip::mapCornerTable =
105
+ {
106
+ // rfDefault ->
107
+ { 0, 1, 2, 3 },
108
+ // rfRotate90 ->
109
+ { 1, 3, 0, 2 },
110
+ // rfRotate180 ->
111
+ { 3, 2, 1, 0 },
112
+ // rfRotate270 ->
113
+ { 2, 0, 3, 1 },
114
+ // rfFlipX ->
115
+ { 1, 0, 3, 2 },
116
+ // rfRotate90FlipX ->
117
+ { 0, 2, 1, 3 },
118
+ // rfRotate180FlipX ->
119
+ { 2, 3, 0, 1 },
120
+ // rfRotate270FlipX ->
121
+ { 3, 1, 2, 0 }
122
+ };
123
+
124
+ const Gosu::RotFlip::CornerTable Gosu::RotFlip::realCornerTable =
125
+ {
126
+ // rfDefault ->
127
+ { 0, 1, 2, 3 },
128
+ // rfRotate90 ->
129
+ { 1, 3, 0, 2 },
130
+ // rfRotate180 ->
131
+ { 3, 2, 1, 0 },
132
+ // rfRotate270 ->
133
+ { 1, 3, 0, 2 },
134
+ // rfFlipX ->
135
+ { 1, 0, 3, 2 },
136
+ // rfRotate90FlipX ->
137
+ { 3, 1, 2, 0 },
138
+ // rfRotate180FlipX ->
139
+ { 2, 3, 0, 1 },
140
+ // rfRotate270FlipX ->
141
+ { 0, 2, 1, 3 }
142
+ };
143
+
144
+ void Gosu::applyToPoint(Gosu::RotFlip rotFlip, int& x, int& y, int max)
145
+ {
146
+ switch (rotFlip.name())
147
+ {
148
+ case rfDefault:
149
+ return;
150
+
151
+ case rfRotate90:
152
+ std::swap(x, y);
153
+ y = max - y;
154
+ return;
155
+
156
+ case rfRotate180:
157
+ x = max - x;
158
+ y = max - y;
159
+ return;
160
+
161
+ case rfRotate270:
162
+ std::swap(x, y);
163
+ x = max - x;
164
+ return;
165
+
166
+ case rfFlipX:
167
+ x = max - x;
168
+ return;
169
+
170
+ case rfRotate90FlipX:
171
+ std::swap(x, y);
172
+ return;
173
+
174
+ case rfRotate180FlipX: // == rfFlipY
175
+ y = max - y;
176
+ return;
177
+
178
+ case rfRotate270FlipX:
179
+ int temp = x;
180
+ x = max - y;
181
+ y = max - temp;
182
+ return;
183
+ }
184
+ }
@@ -0,0 +1,77 @@
1
+ #include <GosuImpl/Graphics/TexChunk.hpp>
2
+ #include <GosuImpl/Graphics/Texture.hpp>
3
+ #include <GosuImpl/Graphics/DrawOp.hpp>
4
+ #include <Gosu/Bitmap.hpp>
5
+ #include <Gosu/Graphics.hpp>
6
+
7
+ Gosu::TexChunk::TexChunk(Graphics& graphics, DrawOpQueue& queue,
8
+ boost::shared_ptr<Texture> texture,
9
+ int x, int y, int w, int h, int padding)
10
+ : graphics(&graphics), queue(&queue), texture(texture), x(x), y(y), w(w), h(h), padding(padding)
11
+ {
12
+ }
13
+
14
+ Gosu::TexChunk::~TexChunk()
15
+ {
16
+ texture->free(x - padding, y - padding);
17
+ }
18
+
19
+ unsigned int Gosu::TexChunk::width() const
20
+ {
21
+ return w;
22
+ }
23
+
24
+ unsigned int Gosu::TexChunk::height() const
25
+ {
26
+ return h;
27
+ }
28
+
29
+ GLuint Gosu::TexChunk::texName() const
30
+ {
31
+ return texture->texName();
32
+ }
33
+
34
+ void Gosu::TexChunk::getCoords(double& left, double& top, double& right, double& bottom) const
35
+ {
36
+ left = double(x) / texture->size();
37
+ top = double(y) / texture->size();
38
+ right = double(x + w) / texture->size();
39
+ bottom = double(y + h) / texture->size();
40
+ }
41
+
42
+ void Gosu::TexChunk::draw(double x1, double y1, Color c1,
43
+ double x2, double y2, Color c2,
44
+ double x3, double y3, Color c3,
45
+ double x4, double y4, Color c4,
46
+ ZPos z, AlphaMode mode) const
47
+ {
48
+ DrawOp newDrawOp;
49
+
50
+ x1 *= graphics->factorX();
51
+ y1 *= graphics->factorY();
52
+ x2 *= graphics->factorX();
53
+ y2 *= graphics->factorY();
54
+ x3 *= graphics->factorX();
55
+ y3 *= graphics->factorY();
56
+ x4 *= graphics->factorX();
57
+ y4 *= graphics->factorY();
58
+
59
+ newDrawOp.usedVertices = 4;
60
+ newDrawOp.vertices[0] = DrawOp::Vertex(x1, y1, c1);
61
+ newDrawOp.vertices[1] = DrawOp::Vertex(x2, y2, c2);
62
+ newDrawOp.vertices[3] = DrawOp::Vertex(x3, y3, c3);
63
+ newDrawOp.vertices[2] = DrawOp::Vertex(x4, y4, c4);
64
+ newDrawOp.chunk = this;
65
+ newDrawOp.mode = mode;
66
+
67
+ queue->addDrawOp(newDrawOp, z);
68
+ }
69
+
70
+
71
+ boost::optional<Gosu::GLTexInfo> Gosu::TexChunk::glTexInfo() const
72
+ {
73
+ Gosu::GLTexInfo info;
74
+ info.texName = texName();
75
+ getCoords(info.left, info.top, info.right, info.bottom);
76
+ return info;
77
+ }
@@ -0,0 +1,40 @@
1
+ #ifndef GOSUIMPL_GRAPHICS_TEXCHUNK_HPP
2
+ #define GOSUIMPL_GRAPHICS_TEXCHUNK_HPP
3
+
4
+ #include <Gosu/Fwd.hpp>
5
+ #include <Gosu/ImageData.hpp>
6
+ #include <GosuImpl/Graphics/Common.hpp>
7
+ #include <memory>
8
+ #include <vector>
9
+ #include <stdexcept>
10
+ #include <boost/shared_ptr.hpp>
11
+
12
+ class Gosu::TexChunk : public Gosu::ImageData
13
+ {
14
+ Graphics* graphics;
15
+ DrawOpQueue* queue;
16
+ boost::shared_ptr<Texture> texture;
17
+ int x, y, w, h, padding;
18
+
19
+ public:
20
+ TexChunk(Graphics& graphics, DrawOpQueue& queue, boost::shared_ptr<Texture> texture,
21
+ int x, int y, int w, int h, int padding);
22
+ ~TexChunk();
23
+
24
+ unsigned int width() const;
25
+ unsigned int height() const;
26
+
27
+ GLuint texName() const;
28
+ void getCoords(double& left, double& top, double& right, double& bottom) const;
29
+
30
+ void draw(double x1, double y1, Color c1,
31
+ double x2, double y2, Color c2,
32
+ double x3, double y3, Color c3,
33
+ double x4, double y4, Color c4,
34
+ ZPos z, AlphaMode mode) const;
35
+
36
+ boost::optional<GLTexInfo> glTexInfo() const;
37
+ };
38
+
39
+ #endif
40
+