gosu 0.10.9.pre1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/Gosu/Audio.hpp +35 -66
  3. data/Gosu/AutoLink.hpp +14 -16
  4. data/Gosu/Bitmap.hpp +50 -37
  5. data/Gosu/Buttons.hpp +246 -265
  6. data/Gosu/Color.hpp +32 -76
  7. data/Gosu/Directories.hpp +14 -17
  8. data/Gosu/Font.hpp +28 -34
  9. data/Gosu/Fwd.hpp +27 -31
  10. data/Gosu/Gosu.hpp +2 -5
  11. data/Gosu/Graphics.hpp +31 -48
  12. data/Gosu/GraphicsBase.hpp +27 -58
  13. data/Gosu/IO.hpp +44 -56
  14. data/Gosu/Image.hpp +29 -73
  15. data/Gosu/ImageData.hpp +13 -17
  16. data/Gosu/Input.hpp +42 -57
  17. data/Gosu/Inspection.hpp +2 -6
  18. data/Gosu/Math.hpp +32 -38
  19. data/Gosu/Platform.hpp +10 -29
  20. data/Gosu/Text.hpp +30 -39
  21. data/Gosu/TextInput.hpp +29 -36
  22. data/Gosu/Timing.hpp +14 -16
  23. data/Gosu/Utility.hpp +10 -15
  24. data/Gosu/Version.hpp +13 -14
  25. data/Gosu/Window.hpp +53 -68
  26. data/README.md +23 -11
  27. data/ext/gosu/extconf.rb +31 -81
  28. data/lib/gosu/patches.rb +35 -19
  29. data/lib/gosu/run.rb +13 -4
  30. data/rdoc/gosu.rb +24 -20
  31. data/src/ALChannelManagement.hpp +119 -0
  32. data/src/{Audio/Audio.cpp → Audio.cpp} +177 -211
  33. data/src/AudioFile.hpp +57 -0
  34. data/src/AudioToolboxFile.hpp +214 -0
  35. data/src/Bitmap.cpp +159 -0
  36. data/src/BitmapIO.cpp +141 -0
  37. data/src/BlockAllocator.cpp +133 -0
  38. data/src/{Graphics/BlockAllocator.hpp → BlockAllocator.hpp} +34 -35
  39. data/src/ClipRectStack.hpp +87 -0
  40. data/src/{Graphics/Color.cpp → Color.cpp} +30 -28
  41. data/src/DirectoriesApple.cpp +68 -0
  42. data/src/DirectoriesUnix.cpp +20 -18
  43. data/src/DirectoriesWin.cpp +40 -41
  44. data/src/DrawOp.hpp +168 -0
  45. data/src/DrawOpQueue.hpp +190 -0
  46. data/src/FileUnix.cpp +40 -46
  47. data/src/FileWin.cpp +42 -38
  48. data/src/Font.cpp +165 -0
  49. data/src/{Text/FormattedString.hpp → FormattedString.hpp} +114 -114
  50. data/src/GosuAppDelegate.cpp +30 -0
  51. data/src/{UIKit/GosuAppDelegate.h → GosuAppDelegate.h} +0 -0
  52. data/src/{UIKit/GosuGLView.mm → GosuGLView.cpp} +22 -17
  53. data/src/{UIKit/GosuGLView.h → GosuGLView.h} +0 -0
  54. data/src/GosuViewController.cpp +231 -0
  55. data/src/{UIKit/GosuViewController.h → GosuViewController.h} +0 -0
  56. data/src/Graphics.cpp +464 -0
  57. data/src/{Graphics/Common.hpp → GraphicsImpl.hpp} +29 -32
  58. data/src/IO.cpp +17 -16
  59. data/src/Iconv.hpp +13 -22
  60. data/src/Image.cpp +142 -0
  61. data/src/Input.cpp +459 -0
  62. data/src/InputUIKit.cpp +197 -0
  63. data/src/Inspection.cpp +4 -5
  64. data/src/LargeImageData.cpp +151 -0
  65. data/src/LargeImageData.hpp +43 -0
  66. data/src/{Graphics/Macro.cpp → Macro.cpp} +77 -78
  67. data/src/Macro.hpp +30 -0
  68. data/src/Math.cpp +17 -29
  69. data/src/{Audio/OggFile.hpp → OggFile.hpp} +19 -24
  70. data/src/RenderState.hpp +205 -0
  71. data/src/Resolution.cpp +86 -0
  72. data/src/ResolutionApple.cpp +25 -0
  73. data/{ext/gosu/gosu_wrap.cxx → src/RubyGosu.cxx} +2256 -1707
  74. data/{ext/gosu/gosu_wrap.h → src/RubyGosu.h} +9 -9
  75. data/src/{Audio/SndFile.hpp → SndFile.hpp} +54 -43
  76. data/src/TexChunk.cpp +117 -0
  77. data/src/{Graphics/TexChunk.hpp → TexChunk.hpp} +13 -18
  78. data/src/Text.cpp +371 -0
  79. data/src/TextApple.cpp +209 -0
  80. data/src/TextInput.cpp +278 -0
  81. data/src/TextTTFWin.cpp +251 -0
  82. data/src/{Text/TextUnix.cpp → TextUnix.cpp} +96 -92
  83. data/src/TextWin.cpp +194 -0
  84. data/src/{Graphics/Texture.cpp → Texture.cpp} +35 -38
  85. data/src/{Graphics/Texture.hpp → Texture.hpp} +9 -13
  86. data/src/TimingApple.cpp +11 -7
  87. data/src/TimingUnix.cpp +13 -7
  88. data/src/TimingWin.cpp +6 -1
  89. data/src/{Graphics/Transform.cpp → Transform.cpp} +17 -12
  90. data/src/{Graphics/TransformStack.hpp → TransformStack.hpp} +24 -25
  91. data/src/Utility.cpp +29 -70
  92. data/src/UtilityApple.cpp +52 -0
  93. data/src/UtilityWin.cpp +7 -4
  94. data/src/Version.cpp +22 -0
  95. data/src/WinMain.cpp +30 -33
  96. data/src/WinUtility.cpp +24 -22
  97. data/src/WinUtility.hpp +11 -20
  98. data/src/Window.cpp +142 -112
  99. data/src/WindowUIKit.cpp +155 -0
  100. data/src/stb_image.h +384 -173
  101. data/src/stb_vorbis.c +20 -18
  102. metadata +60 -62
  103. data/Gosu/TR1.hpp +0 -56
  104. data/src/AppleUtility.hpp +0 -66
  105. data/src/Audio/ALChannelManagement.hpp +0 -114
  106. data/src/Audio/Audio.mm +0 -1
  107. data/src/Audio/AudioFile.hpp +0 -53
  108. data/src/Audio/AudioToolboxFile.hpp +0 -207
  109. data/src/Bitmap/Bitmap.cpp +0 -183
  110. data/src/Bitmap/BitmapIO.cpp +0 -176
  111. data/src/DirectoriesApple.mm +0 -71
  112. data/src/Graphics/BlockAllocator.cpp +0 -142
  113. data/src/Graphics/ClipRectStack.hpp +0 -93
  114. data/src/Graphics/DrawOp.hpp +0 -175
  115. data/src/Graphics/DrawOpQueue.hpp +0 -188
  116. data/src/Graphics/Graphics.cpp +0 -478
  117. data/src/Graphics/Image.cpp +0 -193
  118. data/src/Graphics/LargeImageData.cpp +0 -133
  119. data/src/Graphics/LargeImageData.hpp +0 -46
  120. data/src/Graphics/Macro.hpp +0 -36
  121. data/src/Graphics/RenderState.hpp +0 -211
  122. data/src/Graphics/Resolution.cpp +0 -91
  123. data/src/Graphics/ResolutionApple.mm +0 -19
  124. data/src/Graphics/TexChunk.cpp +0 -112
  125. data/src/Input/Input.cpp +0 -463
  126. data/src/Input/InputUIKit.mm +0 -190
  127. data/src/Input/TextInput.cpp +0 -261
  128. data/src/Text/Font.cpp +0 -175
  129. data/src/Text/Text.cpp +0 -391
  130. data/src/Text/TextApple.mm +0 -227
  131. data/src/Text/TextTTFWin.cpp +0 -249
  132. data/src/Text/TextWin.cpp +0 -186
  133. data/src/UIKit/GosuAppDelegate.mm +0 -24
  134. data/src/UIKit/GosuViewController.mm +0 -211
  135. data/src/UtilityApple.mm +0 -63
  136. data/src/WindowUIKit.mm +0 -139
@@ -1,193 +0,0 @@
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
- #include <stdexcept>
8
-
9
- Gosu::Image::Image(const std::wstring& filename, unsigned flags)
10
- {
11
- // Forward.
12
- Bitmap bmp;
13
- loadImageFile(bmp, filename);
14
- Image(bmp, flags).data.swap(data);
15
- }
16
-
17
- Gosu::Image::Image(const std::wstring& filename,
18
- unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
19
- unsigned flags)
20
- {
21
- // Forward.
22
- Bitmap bmp;
23
- loadImageFile(bmp, filename);
24
- Image(bmp, srcX, srcY, srcWidth, srcHeight, flags).data.swap(data);
25
- }
26
-
27
- Gosu::Image::Image(const Bitmap& source, unsigned flags)
28
- {
29
- // Forward.
30
- Image(source, 0, 0, source.width(), source.height(), flags).data.swap(data);
31
- }
32
-
33
- Gosu::Image::Image(const Bitmap& source,
34
- unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
35
- unsigned flags)
36
- : data(Graphics::createImage(source, srcX, srcY, srcWidth, srcHeight, flags).release())
37
- {
38
- }
39
-
40
- Gosu::Image::Image(GOSU_UNIQUE_PTR<ImageData> data)
41
- : data(data.release())
42
- {
43
- if (this->data.get() == 0)
44
- throw std::invalid_argument("Gosu::Image cannot be initialized with an ImageData null pointer");
45
- }
46
-
47
- unsigned Gosu::Image::width() const
48
- {
49
- return data->width();
50
- }
51
-
52
- unsigned Gosu::Image::height() const
53
- {
54
- return data->height();
55
- }
56
-
57
- void Gosu::Image::draw(double x, double y, ZPos z,
58
- double factorX, double factorY,
59
- Color c,
60
- AlphaMode mode) const
61
- {
62
- double x2 = x + width() * factorX;
63
- double y2 = y + height() * factorY;
64
-
65
- data->draw(x, y, c, x2, y, c, x, y2, c, x2, y2, c, z, mode);
66
- }
67
-
68
- void Gosu::Image::drawMod(double x, double y, ZPos z,
69
- double factorX, double factorY,
70
- Color c1, Color c2, Color c3, Color c4,
71
- AlphaMode mode) const
72
- {
73
- double x2 = x + width() * factorX;
74
- double y2 = y + height() * factorY;
75
-
76
- data->draw(x, y, c1, x2, y, c2, x, y2, c3, x2, y2, c4, z, mode);
77
- }
78
-
79
- void Gosu::Image::drawRot(double x, double y, ZPos z,
80
- double angle, double centerX, double centerY,
81
- double factorX, double factorY,
82
- Color c,
83
- AlphaMode mode) const
84
- {
85
- double sizeX = width() * factorX;
86
- double sizeY = height() * factorY;
87
- double offsX = offsetX(angle, 1);
88
- double offsY = offsetY(angle, 1);
89
-
90
- // Offset to the centers of the original Image's edges when it is rotated
91
- // by <angle> degrees.
92
- double distToLeftX = +offsY * sizeX * centerX;
93
- double distToLeftY = -offsX * sizeX * centerX;
94
- double distToRightX = -offsY * sizeX * (1 - centerX);
95
- double distToRightY = +offsX * sizeX * (1 - centerX);
96
- double distToTopX = +offsX * sizeY * centerY;
97
- double distToTopY = +offsY * sizeY * centerY;
98
- double distToBottomX = -offsX * sizeY * (1 - centerY);
99
- double distToBottomY = -offsY * sizeY * (1 - centerY);
100
-
101
- data->draw(x + distToLeftX + distToTopX,
102
- y + distToLeftY + distToTopY, c,
103
- x + distToRightX + distToTopX,
104
- y + distToRightY + distToTopY, c,
105
- x + distToLeftX + distToBottomX,
106
- y + distToLeftY + distToBottomY, c,
107
- x + distToRightX + distToBottomX,
108
- y + distToRightY + distToBottomY,
109
- c, z, mode);
110
- }
111
-
112
- Gosu::ImageData& Gosu::Image::getData() const
113
- {
114
- return *data;
115
- }
116
-
117
- std::vector<Gosu::Image> Gosu::loadTiles(const Bitmap& bmp,
118
- int tileWidth, int tileHeight, unsigned flags)
119
- {
120
- int tilesX, tilesY;
121
- std::vector<Image> images;
122
-
123
- if (tileWidth > 0)
124
- tilesX = bmp.width() / tileWidth;
125
- else
126
- {
127
- tilesX = -tileWidth;
128
- tileWidth = bmp.width() / tilesX;
129
- }
130
-
131
- if (tileHeight > 0)
132
- tilesY = bmp.height() / tileHeight;
133
- else
134
- {
135
- tilesY = -tileHeight;
136
- tileHeight = bmp.height() / tilesY;
137
- }
138
-
139
- for (int y = 0; y < tilesY; ++y)
140
- for (int x = 0; x < tilesX; ++x)
141
- images.push_back(Image(bmp, x * tileWidth, y * tileHeight, tileWidth, tileHeight, flags));
142
-
143
- return images;
144
- }
145
-
146
- std::vector<Gosu::Image> Gosu::loadTiles(const std::wstring& filename,
147
- int tileWidth, int tileHeight, unsigned flags)
148
- {
149
- Bitmap bmp;
150
- loadImageFile(bmp, filename);
151
- return loadTiles(bmp, tileWidth, tileHeight, flags);
152
- }
153
-
154
- // Deprecated constructors.
155
-
156
- Gosu::Image::Image(Graphics& graphics, const std::wstring& filename, bool tileable)
157
- {
158
- Image(filename, tileable).data.swap(data);
159
- }
160
-
161
- Gosu::Image::Image(Graphics& graphics, const std::wstring& filename,
162
- unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
163
- bool tileable)
164
- {
165
- Image(filename, srcX, srcY, srcWidth, srcHeight, tileable).data.swap(data);
166
- }
167
-
168
- Gosu::Image::Image(Graphics& graphics, const Bitmap& source, bool tileable)
169
- {
170
- Image(source, tileable).data.swap(data);
171
- }
172
-
173
- Gosu::Image::Image(Graphics& graphics, const Bitmap& source,
174
- unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
175
- bool tileable)
176
- {
177
- Image(source, srcX, srcY, srcWidth, srcHeight, tileable).data.swap(data);
178
- }
179
-
180
- // Deprecated helpers.
181
-
182
- std::vector<Gosu::Image> Gosu::loadTiles(Gosu::Graphics& graphics, const Bitmap& bmp,
183
- int tileWidth, int tileHeight, bool tileable)
184
- {
185
- return Gosu::loadTiles(bmp, tileWidth, tileHeight, tileable);
186
- }
187
-
188
- std::vector<Gosu::Image> Gosu::loadTiles(Gosu::Graphics& graphics, const std::wstring& filename,
189
- int tileWidth, int tileHeight, bool tileable)
190
- {
191
- return Gosu::loadTiles(filename, tileWidth, tileHeight, tileable);
192
- }
193
-
@@ -1,133 +0,0 @@
1
- #include "LargeImageData.hpp"
2
- #include "Common.hpp"
3
- #include <Gosu/Bitmap.hpp>
4
- #include <Gosu/Graphics.hpp>
5
- #include <Gosu/Math.hpp>
6
- #include <cmath>
7
- using namespace std;
8
-
9
- Gosu::LargeImageData::LargeImageData(const Bitmap& source,
10
- unsigned partWidth, unsigned partHeight, unsigned imageFlags)
11
- {
12
- fullWidth = source.width();
13
- fullHeight = source.height();
14
- partsX = static_cast<unsigned>(trunc(ceil(1.0 * source.width() / partWidth)));
15
- partsY = static_cast<unsigned>(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 localFlags = ifTileable | imageFlags;
35
- if (x == 0)
36
- localFlags = (localFlags & ~ifTileableLeft) | (imageFlags & ifTileableLeft);
37
- if (x == partsX - 1)
38
- localFlags = (localFlags & ~ifTileableRight) | (imageFlags & ifTileableRight);
39
- if (y == 0)
40
- localFlags = (localFlags & ~ifTileableTop) | (imageFlags & ifTileableTop);
41
- if (y == partsY - 1)
42
- localFlags = (localFlags & ~ifTileableBottom) | (imageFlags & ifTileableBottom);
43
-
44
- parts[y * partsX + x].reset(Graphics::createImage(source,
45
- x * partWidth, y * partHeight, srcWidth, srcHeight,
46
- localFlags).release());
47
- }
48
- }
49
-
50
- int Gosu::LargeImageData::width() const
51
- {
52
- return fullWidth;
53
- }
54
-
55
- int 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
- reorderCoordinatesIfNecessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
88
-
89
- for (unsigned py = 0; py < partsY; ++py)
90
- for (unsigned px = 0; px < partsX; ++px)
91
- {
92
- ImageData& part = *parts[py * partsX + px];
93
-
94
- double relXL = static_cast<double>(px * partWidth) / width();
95
- double relXR = static_cast<double>(px * partWidth + part.width()) / width();
96
- double relYT = static_cast<double>(py * partHeight) / height();
97
- double relYB = static_cast<double>(py * partHeight + part.height()) / height();
98
-
99
- double absXTL = ipl(ipl(x1, x3, relYT), ipl(x2, x4, relYT), relXL);
100
- double absXTR = ipl(ipl(x1, x3, relYT), ipl(x2, x4, relYT), relXR);
101
- double absXBL = ipl(ipl(x1, x3, relYB), ipl(x2, x4, relYB), relXL);
102
- double absXBR = ipl(ipl(x1, x3, relYB), ipl(x2, x4, relYB), relXR);
103
-
104
- double absYTL = ipl(ipl(y1, y3, relYT), ipl(y2, y4, relYT), relXL);
105
- double absYTR = ipl(ipl(y1, y3, relYT), ipl(y2, y4, relYT), relXR);
106
- double absYBL = ipl(ipl(y1, y3, relYB), ipl(y2, y4, relYB), relXL);
107
- double absYBR = ipl(ipl(y1, y3, relYB), ipl(y2, y4, relYB), relXR);
108
-
109
- Color absCTL = ipl(ipl(c1, c3, relYT), ipl(c2, c4, relYT), relXL);
110
- Color absCTR = ipl(ipl(c1, c3, relYT), ipl(c2, c4, relYT), relXR);
111
- Color absCBL = ipl(ipl(c1, c3, relYB), ipl(c2, c4, relYB), relXL);
112
- Color absCBR = ipl(ipl(c1, c3, relYB), ipl(c2, c4, relYB), relXR);
113
-
114
- part.draw(absXTL, absYTL, absCTL, absXTR, absYTR, absCTR,
115
- absXBL, absYBL, absCBL, absXBR, absYBR, absCBR, z, mode);
116
- }
117
- }
118
-
119
- Gosu::Bitmap Gosu::LargeImageData::toBitmap() const
120
- {
121
- Bitmap bitmap(width(), height());
122
- for (int x = 0; x < partsX; ++x)
123
- for (int y = 0; y < partsY; ++y)
124
- bitmap.insert(parts[y * partsX + x]->toBitmap(), x * partWidth, y * partHeight);
125
- return bitmap;
126
- }
127
-
128
- void Gosu::LargeImageData::insert(const Bitmap& bitmap, int atX, int atY)
129
- {
130
- for (int x = 0; x < partsX; ++x)
131
- for (int y = 0; y < partsY; ++y)
132
- parts[y * partsX + x]->insert(bitmap, atX - x * partWidth, atY - y * partHeight);
133
- }
@@ -1,46 +0,0 @@
1
- #ifndef GOSU_SRC_LARGEIMAGEDATA_HPP
2
- #define GOSU_SRC_LARGEIMAGEDATA_HPP
3
-
4
- #include <Gosu/Fwd.hpp>
5
- #include <Gosu/ImageData.hpp>
6
- #include <Gosu/TR1.hpp>
7
- #include <Gosu/Platform.hpp>
8
- #include <stdexcept>
9
- #include <vector>
10
-
11
- namespace Gosu
12
- {
13
- class LargeImageData : public ImageData
14
- {
15
- unsigned fullWidth, fullHeight, partsX, partsY, partWidth, partHeight;
16
- std::vector<std::tr1::shared_ptr<ImageData> > parts;
17
-
18
- public:
19
- LargeImageData(const Bitmap& source,
20
- unsigned partWidth, unsigned partHeight, unsigned imageFlags);
21
-
22
- int width() const;
23
- int height() const;
24
-
25
- void draw(double x1, double y1, Color c1,
26
- double x2, double y2, Color c2,
27
- double x3, double y3, Color c3,
28
- double x4, double y4, Color c4,
29
- ZPos z, AlphaMode mode) const;
30
-
31
- const GLTexInfo* glTexInfo() const
32
- {
33
- return 0;
34
- }
35
-
36
- GOSU_UNIQUE_PTR<ImageData> subimage(int x, int y, int w, int h) const
37
- {
38
- return GOSU_UNIQUE_PTR<ImageData>();
39
- }
40
-
41
- Bitmap toBitmap() const;
42
- void insert(const Bitmap& bitmap, int x, int y);
43
- };
44
- }
45
-
46
- #endif
@@ -1,36 +0,0 @@
1
- #ifndef GOSU_SRC_GRAPHICS_MACRO_HPP
2
- #define GOSU_SRC_GRAPHICS_MACRO_HPP
3
-
4
- #include <Gosu/Fwd.hpp>
5
- #include <Gosu/ImageData.hpp>
6
- #include <Gosu/TR1.hpp>
7
- #include <Gosu/Platform.hpp>
8
- #include "Common.hpp"
9
-
10
- class Gosu::Macro : public Gosu::ImageData
11
- {
12
- struct Impl;
13
- std::tr1::shared_ptr<Impl> pimpl;
14
-
15
- public:
16
- Macro(DrawOpQueue& queue, int width, int height);
17
-
18
- int width() const;
19
- int height() const;
20
-
21
- void draw(double x1, double y1, Color c1,
22
- double x2, double y2, Color c2,
23
- double x3, double y3, Color c3,
24
- double x4, double y4, Color c4,
25
- ZPos z, AlphaMode mode) const;
26
-
27
- const Gosu::GLTexInfo* glTexInfo() const;
28
-
29
- Gosu::Bitmap toBitmap() const;
30
-
31
- GOSU_UNIQUE_PTR<ImageData> subimage(int x, int y, int width, int height) const;
32
-
33
- void insert(const Bitmap& bitmap, int x, int y);
34
- };
35
-
36
- #endif
@@ -1,211 +0,0 @@
1
- #ifndef GOSU_SRC_GRAPHICS_RENDERSTATE_HPP
2
- #define GOSU_SRC_GRAPHICS_RENDERSTATE_HPP
3
-
4
- #include "Common.hpp"
5
- #include "Texture.hpp"
6
-
7
- // Properties that potentially need to be changed between each draw operation.
8
- // This does not include the color or vertex data of the actual quads.
9
- struct Gosu::RenderState
10
- {
11
- std::tr1::shared_ptr<Texture> texture;
12
- const Transform* transform;
13
- ClipRect clipRect;
14
- AlphaMode mode;
15
-
16
- RenderState()
17
- : transform(0), mode(amDefault)
18
- {
19
- clipRect.width = NO_CLIPPING;
20
- }
21
-
22
- bool operator==(const RenderState& rhs) const
23
- {
24
- return texture == rhs.texture && transform == rhs.transform &&
25
- clipRect == rhs.clipRect && mode == rhs.mode;
26
- }
27
-
28
- void applyTexture() const
29
- {
30
- if (texture)
31
- {
32
- glEnable(GL_TEXTURE_2D);
33
- glBindTexture(GL_TEXTURE_2D, texture->texName());
34
- }
35
- else
36
- {
37
- glDisable(GL_TEXTURE_2D);
38
- }
39
- }
40
-
41
- void applyAlphaMode() const
42
- {
43
- if (mode == amAdd)
44
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
45
- else if (mode == amMultiply)
46
- glBlendFunc(GL_DST_COLOR, GL_ZERO);
47
- else
48
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
49
- }
50
-
51
- void applyClipRect() const
52
- {
53
- if (clipRect.width == NO_CLIPPING)
54
- {
55
- glDisable(GL_SCISSOR_TEST);
56
- }
57
- else
58
- {
59
- glEnable(GL_SCISSOR_TEST);
60
- glScissor(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
61
- }
62
- }
63
-
64
- // Only used by Macro so far
65
- #ifndef GOSU_IS_OPENGLES
66
- void apply() const
67
- {
68
- applyTexture();
69
- // TODO: No inner clipRect yet - how would this work?!
70
- applyAlphaMode();
71
- }
72
- #endif
73
- };
74
-
75
- // Manages the OpenGL rendering state. It caches the current state, only forwarding the
76
- // changes to OpenGL if the new state is really different.
77
- class Gosu::RenderStateManager : private Gosu::RenderState
78
- {
79
- // Not copyable
80
- RenderStateManager(const RenderStateManager&);
81
- RenderStateManager& operator=(const RenderStateManager&);
82
-
83
- void applyTransform() const
84
- {
85
- glMatrixMode(GL_MODELVIEW);
86
- glLoadIdentity();
87
-
88
- #ifndef GOSU_IS_OPENGLES
89
- glMultMatrixd(&(*transform)[0]);
90
- #else
91
- // TODO: Ouch, should always use floats!
92
- GLfloat matrix[16];
93
- for (int i = 0; i < 16; ++i)
94
- matrix[i] = (*transform)[i];
95
- glMultMatrixf(matrix);
96
- #endif
97
- }
98
-
99
- public:
100
- RenderStateManager()
101
- {
102
- applyAlphaMode();
103
- // Preserve previous MV matrix
104
- glMatrixMode(GL_MODELVIEW);
105
- glPushMatrix();
106
- }
107
-
108
- ~RenderStateManager()
109
- {
110
- ClipRect noClipping;
111
- noClipping.width = NO_CLIPPING;
112
- setClipRect(noClipping);
113
- setTexture(std::tr1::shared_ptr<Texture>());
114
- // Return to previous MV matrix
115
- glMatrixMode(GL_MODELVIEW);
116
- glPopMatrix();
117
- }
118
-
119
- void setRenderState(const RenderState& rs)
120
- {
121
- setTexture(rs.texture);
122
- setTransform(rs.transform);
123
- setClipRect(rs.clipRect);
124
- setAlphaMode(rs.mode);
125
- }
126
-
127
- void setTexture(std::tr1::shared_ptr<Texture> newTexture)
128
- {
129
- if (newTexture == texture)
130
- return;
131
-
132
- if (newTexture)
133
- {
134
- // New texture *is* really a texture - change to it.
135
-
136
- if (!texture)
137
- glEnable(GL_TEXTURE_2D);
138
- glBindTexture(GL_TEXTURE_2D, newTexture->texName());
139
- }
140
- else
141
- // New texture is NO_TEXTURE, disable texturing.
142
- glDisable(GL_TEXTURE_2D);
143
- texture = newTexture;
144
- }
145
-
146
- void setTransform(const Transform* newTransform)
147
- {
148
- if (newTransform == transform)
149
- return;
150
- transform = newTransform;
151
- applyTransform();
152
- }
153
-
154
- void setClipRect(const ClipRect& newClipRect)
155
- {
156
- if (newClipRect.width == NO_CLIPPING)
157
- {
158
- // Disable clipping
159
- if (clipRect.width != NO_CLIPPING)
160
- {
161
- glDisable(GL_SCISSOR_TEST);
162
- clipRect.width = NO_CLIPPING;
163
- }
164
- }
165
- else
166
- {
167
- // Enable clipping if off
168
- if (clipRect.width == NO_CLIPPING)
169
- {
170
- glEnable(GL_SCISSOR_TEST);
171
- clipRect = newClipRect;
172
- glScissor(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
173
- }
174
- // Adjust clipping if necessary
175
- else if (!(clipRect == newClipRect))
176
- {
177
- clipRect = newClipRect;
178
- glScissor(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
179
- }
180
- }
181
- }
182
-
183
- void setAlphaMode(AlphaMode newMode)
184
- {
185
- if (newMode == mode)
186
- return;
187
- mode = newMode;
188
- applyAlphaMode();
189
- }
190
-
191
- // The cached values may have been messed with. Reset them again.
192
- void enforceAfterUntrustedGL() const
193
- {
194
- applyTexture();
195
- applyTransform();
196
- applyClipRect();
197
- applyAlphaMode();
198
- }
199
- };
200
-
201
- namespace Gosu
202
- {
203
- struct VertexArray
204
- {
205
- RenderState renderState;
206
- std::vector<ArrayVertex> vertices;
207
- };
208
- typedef std::list<VertexArray> VertexArrays;
209
- }
210
-
211
- #endif