gosu 0.8.7.2 → 0.9.0.pre1
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.
- checksums.yaml +4 -4
- data/COPYING +29 -0
- data/Gosu/Audio.hpp +1 -0
- data/Gosu/Font.hpp +8 -4
- data/Gosu/Graphics.hpp +28 -18
- data/Gosu/GraphicsBase.hpp +17 -13
- data/Gosu/Image.hpp +54 -45
- data/Gosu/Input.hpp +5 -5
- data/Gosu/Version.hpp +3 -3
- data/Gosu/Window.hpp +1 -8
- data/README.txt +25 -0
- data/ext/gosu/gosu_wrap.cxx +1495 -1275
- data/ext/gosu/gosu_wrap.h +2 -2
- data/lib/gosu/patches.rb +71 -35
- data/lib/gosu/preview.rb +9 -142
- data/lib/gosu/swig_patches.rb +20 -10
- data/rdoc/gosu.rb +1185 -0
- data/src/Bitmap/BitmapUtils.cpp +9 -9
- data/src/Graphics/Common.hpp +3 -1
- data/src/Graphics/Graphics.cpp +100 -38
- data/src/Graphics/Image.cpp +57 -15
- data/src/Graphics/LargeImageData.cpp +9 -10
- data/src/Graphics/LargeImageData.hpp +1 -1
- data/src/Graphics/TexChunk.cpp +5 -6
- data/src/Graphics/TexChunk.hpp +1 -4
- data/src/Graphics/Texture.cpp +10 -3
- data/src/Graphics/Texture.hpp +1 -2
- data/src/Iconv.hpp +2 -2
- data/src/Input/Input.cpp +25 -9
- data/src/Input/InputTouch.mm +5 -3
- data/src/Text/Font.cpp +13 -8
- data/src/Window.cpp +66 -37
- data/src/WindowTouch.mm +3 -3
- metadata +79 -92
- data/examples/ChipmunkIntegration.rb +0 -275
- data/examples/CptnRuby.rb +0 -223
- data/examples/GosuZen.rb +0 -68
- data/examples/MoreChipmunkAndRMagick.rb +0 -155
- data/examples/OpenGLIntegration.rb +0 -226
- data/examples/RMagickIntegration.rb +0 -417
- data/examples/TextInput.rb +0 -154
- data/examples/Tutorial.rb +0 -131
- data/examples/media/Beep.wav +0 -0
- data/examples/media/CptnRuby Gem.png +0 -0
- data/examples/media/CptnRuby Map.txt +0 -25
- data/examples/media/CptnRuby Tileset.png +0 -0
- data/examples/media/CptnRuby.png +0 -0
- data/examples/media/Cursor.png +0 -0
- data/examples/media/Earth.png +0 -0
- data/examples/media/Explosion.wav +0 -0
- data/examples/media/Landscape.svg +0 -10
- data/examples/media/LargeStar.png +0 -0
- data/examples/media/Smoke.png +0 -0
- data/examples/media/Soldier.png +0 -0
- data/examples/media/Space.png +0 -0
- data/examples/media/Star.png +0 -0
- data/examples/media/Starfighter.bmp +0 -0
data/src/Bitmap/BitmapUtils.cpp
CHANGED
@@ -32,7 +32,7 @@ Gosu::Writer Gosu::saveToBMP(const Bitmap& bitmap, Writer writer)
|
|
32
32
|
|
33
33
|
void Gosu::applyBorderFlags(Bitmap& dest, const Bitmap& source,
|
34
34
|
unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
35
|
-
unsigned
|
35
|
+
unsigned imageFlags)
|
36
36
|
{
|
37
37
|
dest.resize(srcWidth + 2, srcHeight + 2);
|
38
38
|
|
@@ -40,34 +40,34 @@ void Gosu::applyBorderFlags(Bitmap& dest, const Bitmap& source,
|
|
40
40
|
// borders.
|
41
41
|
|
42
42
|
// Top.
|
43
|
-
if (
|
43
|
+
if (imageFlags & ifTileableTop)
|
44
44
|
dest.insert(source, 1, 0, srcX, srcY, srcWidth, 1);
|
45
45
|
// Bottom.
|
46
|
-
if (
|
46
|
+
if (imageFlags & ifTileableBottom)
|
47
47
|
dest.insert(source, 1, dest.height() - 1,
|
48
48
|
srcX, srcY + srcHeight - 1, srcWidth, 1);
|
49
49
|
// Left.
|
50
|
-
if (
|
50
|
+
if (imageFlags & ifTileableLeft)
|
51
51
|
dest.insert(source, 0, 1, srcX, srcY, 1, srcHeight);
|
52
52
|
// Right.
|
53
|
-
if (
|
53
|
+
if (imageFlags & ifTileableRight)
|
54
54
|
dest.insert(source, dest.width() - 1, 1,
|
55
55
|
srcX + srcWidth - 1, srcY, 1, srcHeight);
|
56
56
|
|
57
57
|
// Top left.
|
58
|
-
if ((
|
58
|
+
if ((imageFlags & ifTileableTop) && (imageFlags & ifTileableLeft))
|
59
59
|
dest.setPixel(0, 0,
|
60
60
|
source.getPixel(srcX, srcY));
|
61
61
|
// Top right.
|
62
|
-
if ((
|
62
|
+
if ((imageFlags & ifTileableTop) && (imageFlags & ifTileableRight))
|
63
63
|
dest.setPixel(dest.width() - 1, 0,
|
64
64
|
source.getPixel(srcX + srcWidth - 1, srcY));
|
65
65
|
// Bottom left.
|
66
|
-
if ((
|
66
|
+
if ((imageFlags & ifTileableBottom) && (imageFlags & ifTileableLeft))
|
67
67
|
dest.setPixel(0, dest.height() - 1,
|
68
68
|
source.getPixel(srcX, srcY + srcHeight - 1));
|
69
69
|
// Bottom right.
|
70
|
-
if ((
|
70
|
+
if ((imageFlags & ifTileableBottom) && (imageFlags & ifTileableRight))
|
71
71
|
dest.setPixel(dest.width() - 1, dest.height() - 1,
|
72
72
|
source.getPixel(srcX + srcWidth - 1, srcY + srcHeight - 1));
|
73
73
|
|
data/src/Graphics/Common.hpp
CHANGED
@@ -34,7 +34,7 @@ namespace Gosu
|
|
34
34
|
const GLuint NO_TEXTURE = static_cast<GLuint>(-1);
|
35
35
|
const unsigned NO_CLIPPING = 0xffffffff;
|
36
36
|
|
37
|
-
// In various places in Gosu, width==NO_CLIPPING
|
37
|
+
// In various places in Gosu, width==NO_CLIPPING by convention means
|
38
38
|
// that no clipping should happen.
|
39
39
|
struct ClipRect
|
40
40
|
{
|
@@ -118,6 +118,8 @@ namespace Gosu
|
|
118
118
|
|
119
119
|
bool isEntity(const std::wstring& name);
|
120
120
|
const Bitmap& entityBitmap(const std::wstring& name);
|
121
|
+
|
122
|
+
void ensureCurrentContext();
|
121
123
|
}
|
122
124
|
|
123
125
|
#endif
|
data/src/Graphics/Graphics.cpp
CHANGED
@@ -12,6 +12,25 @@
|
|
12
12
|
#include <algorithm>
|
13
13
|
#include <limits>
|
14
14
|
|
15
|
+
namespace Gosu
|
16
|
+
{
|
17
|
+
namespace
|
18
|
+
{
|
19
|
+
Graphics* currentGraphicsPointer = 0;
|
20
|
+
|
21
|
+
Graphics& currentGraphics()
|
22
|
+
{
|
23
|
+
if (currentGraphicsPointer == 0)
|
24
|
+
throw std::logic_error("Gosu::Graphics can only be drawn to while rendering");
|
25
|
+
|
26
|
+
return *currentGraphicsPointer;
|
27
|
+
}
|
28
|
+
|
29
|
+
typedef std::vector<std::tr1::shared_ptr<Texture> > Textures;
|
30
|
+
Textures textures;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
15
34
|
struct Gosu::Graphics::Impl
|
16
35
|
{
|
17
36
|
unsigned virtWidth, virtHeight;
|
@@ -19,8 +38,6 @@ struct Gosu::Graphics::Impl
|
|
19
38
|
double blackWidth, blackHeight;
|
20
39
|
bool fullscreen;
|
21
40
|
DrawOpQueueStack queues;
|
22
|
-
typedef std::vector<std::tr1::shared_ptr<Texture> > Textures;
|
23
|
-
Textures textures;
|
24
41
|
};
|
25
42
|
|
26
43
|
Gosu::Graphics::Graphics(unsigned physWidth, unsigned physHeight, bool fullscreen)
|
@@ -55,6 +72,8 @@ Gosu::Graphics::Graphics(unsigned physWidth, unsigned physHeight, bool fullscree
|
|
55
72
|
|
56
73
|
Gosu::Graphics::~Graphics()
|
57
74
|
{
|
75
|
+
if (currentGraphicsPointer == this)
|
76
|
+
currentGraphicsPointer = 0;
|
58
77
|
}
|
59
78
|
|
60
79
|
unsigned Gosu::Graphics::width() const
|
@@ -106,6 +125,11 @@ bool Gosu::Graphics::begin(Gosu::Color clearWithColor)
|
|
106
125
|
clearWithColor.blue() / 255.f, clearWithColor.alpha() / 255.f);
|
107
126
|
glClear(GL_COLOR_BUFFER_BIT);
|
108
127
|
|
128
|
+
if (currentGraphicsPointer != 0)
|
129
|
+
throw std::logic_error("Cannot nest calls to Gosu::Graphics::begin()");
|
130
|
+
|
131
|
+
currentGraphicsPointer = this;
|
132
|
+
|
109
133
|
return true;
|
110
134
|
}
|
111
135
|
|
@@ -115,7 +139,7 @@ void Gosu::Graphics::end()
|
|
115
139
|
pimpl->queues.resize(1);
|
116
140
|
|
117
141
|
flush();
|
118
|
-
|
142
|
+
|
119
143
|
if (pimpl->blackHeight || pimpl->blackWidth) {
|
120
144
|
if (pimpl->blackHeight) {
|
121
145
|
drawQuad(0, -pimpl->blackHeight, Color::BLACK,
|
@@ -141,20 +165,26 @@ void Gosu::Graphics::end()
|
|
141
165
|
}
|
142
166
|
|
143
167
|
glFlush();
|
168
|
+
|
169
|
+
currentGraphicsPointer = 0;
|
144
170
|
}
|
145
171
|
|
146
172
|
void Gosu::Graphics::flush()
|
147
173
|
{
|
148
|
-
|
174
|
+
Graphics& cg = currentGraphics();
|
175
|
+
|
176
|
+
if (cg.pimpl->queues.size() != 1)
|
149
177
|
throw std::logic_error("Flushing to screen is not allowed while creating a macro");
|
150
178
|
|
151
|
-
pimpl->queues.front().performDrawOpsAndCode();
|
152
|
-
pimpl->queues.front().clearQueue();
|
179
|
+
cg.pimpl->queues.front().performDrawOpsAndCode();
|
180
|
+
cg.pimpl->queues.front().clearQueue();
|
153
181
|
}
|
154
182
|
|
155
183
|
void Gosu::Graphics::beginGL()
|
156
184
|
{
|
157
|
-
|
185
|
+
Graphics& cg = currentGraphics();
|
186
|
+
|
187
|
+
if (cg.pimpl->queues.size() > 1)
|
158
188
|
throw std::logic_error("Custom OpenGL is not allowed while creating a macro");
|
159
189
|
|
160
190
|
#ifdef GOSU_IS_OPENGLES
|
@@ -172,6 +202,8 @@ void Gosu::Graphics::endGL()
|
|
172
202
|
#ifdef GOSU_IS_OPENGLES
|
173
203
|
throw std::logic_error("Custom OpenGL ES is not supported yet");
|
174
204
|
#else
|
205
|
+
Graphics& cg = currentGraphics();
|
206
|
+
|
175
207
|
glPopAttrib();
|
176
208
|
|
177
209
|
// Restore matrices.
|
@@ -179,8 +211,8 @@ void Gosu::Graphics::endGL()
|
|
179
211
|
|
180
212
|
glMatrixMode(GL_PROJECTION);
|
181
213
|
glLoadIdentity();
|
182
|
-
glViewport(0, 0, pimpl->physWidth, pimpl->physHeight);
|
183
|
-
glOrtho(0, pimpl->physWidth, pimpl->physHeight, 0, -1, 1);
|
214
|
+
glViewport(0, 0, cg.pimpl->physWidth, cg.pimpl->physHeight);
|
215
|
+
glOrtho(0, cg.pimpl->physWidth, cg.pimpl->physHeight, 0, -1, 1);
|
184
216
|
|
185
217
|
glMatrixMode(GL_MODELVIEW);
|
186
218
|
glLoadIdentity();
|
@@ -223,64 +255,82 @@ namespace Gosu
|
|
223
255
|
|
224
256
|
void Gosu::Graphics::scheduleGL(const std::tr1::function<void()>& functor, Gosu::ZPos z)
|
225
257
|
{
|
226
|
-
|
258
|
+
Graphics& cg = currentGraphics();
|
259
|
+
|
260
|
+
cg.pimpl->queues.back().scheduleGL(RunGLFunctor(cg, functor), z);
|
227
261
|
}
|
228
262
|
#endif
|
229
263
|
|
230
264
|
void Gosu::Graphics::beginClipping(double x, double y, double width, double height)
|
231
265
|
{
|
232
|
-
|
266
|
+
Graphics& cg = currentGraphics();
|
267
|
+
|
268
|
+
if (cg.pimpl->queues.size() > 1)
|
233
269
|
throw std::logic_error("Clipping is not allowed while creating a macro yet");
|
234
270
|
|
235
|
-
pimpl->queues.back().beginClipping(x, y, width, height, pimpl->physHeight);
|
271
|
+
cg.pimpl->queues.back().beginClipping(x, y, width, height, cg.pimpl->physHeight);
|
236
272
|
}
|
237
273
|
|
238
274
|
void Gosu::Graphics::endClipping()
|
239
275
|
{
|
240
|
-
|
276
|
+
Graphics& cg = currentGraphics();
|
277
|
+
|
278
|
+
cg.pimpl->queues.back().endClipping();
|
241
279
|
}
|
242
280
|
|
243
281
|
void Gosu::Graphics::beginRecording()
|
244
282
|
{
|
245
|
-
|
283
|
+
Graphics& cg = currentGraphics();
|
284
|
+
|
285
|
+
cg.pimpl->queues.resize(cg.pimpl->queues.size() + 1);
|
246
286
|
}
|
247
287
|
|
248
288
|
GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::endRecording(int width, int height)
|
249
289
|
{
|
250
|
-
|
290
|
+
Graphics& cg = currentGraphics();
|
291
|
+
|
292
|
+
if (cg.pimpl->queues.size() == 1)
|
251
293
|
throw std::logic_error("No macro recording in progress that can be captured");
|
252
294
|
|
253
|
-
GOSU_UNIQUE_PTR<ImageData> result(new Macro(
|
254
|
-
pimpl->queues.pop_back();
|
295
|
+
GOSU_UNIQUE_PTR<ImageData> result(new Macro(cg, cg.pimpl->queues.back(), width, height));
|
296
|
+
cg.pimpl->queues.pop_back();
|
255
297
|
return result;
|
256
298
|
}
|
257
299
|
|
258
300
|
void Gosu::Graphics::pushTransform(const Gosu::Transform& transform)
|
259
301
|
{
|
260
|
-
|
302
|
+
Graphics& cg = currentGraphics();
|
303
|
+
|
304
|
+
cg.pimpl->queues.back().pushTransform(transform);
|
261
305
|
}
|
262
306
|
|
263
307
|
void Gosu::Graphics::popTransform()
|
264
308
|
{
|
265
|
-
|
309
|
+
Graphics& cg = currentGraphics();
|
310
|
+
|
311
|
+
cg.pimpl->queues.back().popTransform();
|
266
312
|
}
|
267
313
|
|
268
314
|
void Gosu::Graphics::drawLine(double x1, double y1, Color c1,
|
269
315
|
double x2, double y2, Color c2, ZPos z, AlphaMode mode)
|
270
316
|
{
|
317
|
+
Graphics& cg = currentGraphics();
|
318
|
+
|
271
319
|
DrawOp op;
|
272
320
|
op.renderState.mode = mode;
|
273
321
|
op.verticesOrBlockIndex = 2;
|
274
322
|
op.vertices[0] = DrawOp::Vertex(x1, y1, c1);
|
275
323
|
op.vertices[1] = DrawOp::Vertex(x2, y2, c2);
|
276
324
|
op.z = z;
|
277
|
-
pimpl->queues.back().scheduleDrawOp(op);
|
325
|
+
cg.pimpl->queues.back().scheduleDrawOp(op);
|
278
326
|
}
|
279
327
|
|
280
328
|
void Gosu::Graphics::drawTriangle(double x1, double y1, Color c1,
|
281
329
|
double x2, double y2, Color c2, double x3, double y3, Color c3,
|
282
330
|
ZPos z, AlphaMode mode)
|
283
331
|
{
|
332
|
+
Graphics& cg = currentGraphics();
|
333
|
+
|
284
334
|
DrawOp op;
|
285
335
|
op.renderState.mode = mode;
|
286
336
|
op.verticesOrBlockIndex = 3;
|
@@ -292,13 +342,15 @@ void Gosu::Graphics::drawTriangle(double x1, double y1, Color c1,
|
|
292
342
|
op.vertices[3] = op.vertices[2];
|
293
343
|
#endif
|
294
344
|
op.z = z;
|
295
|
-
pimpl->queues.back().scheduleDrawOp(op);
|
345
|
+
cg.pimpl->queues.back().scheduleDrawOp(op);
|
296
346
|
}
|
297
347
|
|
298
348
|
void Gosu::Graphics::drawQuad(double x1, double y1, Color c1,
|
299
349
|
double x2, double y2, Color c2, double x3, double y3, Color c3,
|
300
350
|
double x4, double y4, Color c4, ZPos z, AlphaMode mode)
|
301
351
|
{
|
352
|
+
Graphics& cg = currentGraphics();
|
353
|
+
|
302
354
|
reorderCoordinatesIfNecessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4);
|
303
355
|
|
304
356
|
DrawOp op;
|
@@ -315,22 +367,33 @@ void Gosu::Graphics::drawQuad(double x1, double y1, Color c1,
|
|
315
367
|
op.vertices[2] = DrawOp::Vertex(x4, y4, c4);
|
316
368
|
#endif
|
317
369
|
op.z = z;
|
318
|
-
pimpl->queues.back().scheduleDrawOp(op);
|
370
|
+
cg.pimpl->queues.back().scheduleDrawOp(op);
|
371
|
+
}
|
372
|
+
|
373
|
+
void Gosu::Graphics::scheduleDrawOp(const Gosu::DrawOp &op)
|
374
|
+
{
|
375
|
+
Graphics& cg = currentGraphics();
|
376
|
+
|
377
|
+
cg.pimpl->queues.back().scheduleDrawOp(op);
|
319
378
|
}
|
320
379
|
|
321
380
|
GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
322
381
|
const Bitmap& src, unsigned srcX, unsigned srcY,
|
323
|
-
unsigned srcWidth, unsigned srcHeight, unsigned
|
382
|
+
unsigned srcWidth, unsigned srcHeight, unsigned flags)
|
324
383
|
{
|
325
384
|
static const unsigned maxSize = MAX_TEXTURE_SIZE;
|
385
|
+
|
386
|
+
// Backwards compatibility: This used to be 'bool tileable'.
|
387
|
+
if (flags == 1)
|
388
|
+
flags = ifTileable;
|
326
389
|
|
327
|
-
// Special case: If the texture is supposed to have hard borders,
|
328
|
-
//
|
390
|
+
// Special case: If the texture is supposed to have hard borders, is
|
391
|
+
// quadratic, has a size that is at least 64 pixels but no more than maxSize
|
329
392
|
// pixels and a power of two, create a single texture just for this image.
|
330
|
-
if ((
|
393
|
+
if ((flags & ifTileable) == ifTileable &&
|
331
394
|
srcWidth == srcHeight &&
|
332
395
|
(srcWidth & (srcWidth - 1)) == 0 &&
|
333
|
-
srcWidth >= 64)
|
396
|
+
srcWidth >= 64 && srcWidth <= maxSize)
|
334
397
|
{
|
335
398
|
std::tr1::shared_ptr<Texture> texture(new Texture(srcWidth));
|
336
399
|
GOSU_UNIQUE_PTR<ImageData> data;
|
@@ -340,14 +403,13 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
340
403
|
if (srcX == 0 && srcWidth == src.width() &&
|
341
404
|
srcY == 0 && srcHeight == src.height())
|
342
405
|
{
|
343
|
-
data = texture->tryAlloc(
|
406
|
+
data = texture->tryAlloc(texture, src, 0);
|
344
407
|
}
|
345
408
|
else
|
346
409
|
{
|
347
|
-
Bitmap
|
348
|
-
|
349
|
-
|
350
|
-
data = texture->tryAlloc(*this, pimpl->queues, texture, trimmedSrc, 0);
|
410
|
+
Bitmap bmp(srcWidth, srcHeight);
|
411
|
+
bmp.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
|
412
|
+
data = texture->tryAlloc(texture, bmp, 0);
|
351
413
|
}
|
352
414
|
|
353
415
|
if (!data.get())
|
@@ -361,20 +423,20 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
361
423
|
Bitmap bmp(srcWidth, srcHeight);
|
362
424
|
bmp.insert(src, 0, 0, srcX, srcY, srcWidth, srcHeight);
|
363
425
|
GOSU_UNIQUE_PTR<ImageData> lidi;
|
364
|
-
lidi.reset(new LargeImageData(
|
426
|
+
lidi.reset(new LargeImageData(bmp, maxSize - 2, maxSize - 2, flags));
|
365
427
|
return GOSU_MOVE_UNIQUE_PTR(lidi);
|
366
428
|
}
|
367
429
|
|
368
430
|
Bitmap bmp;
|
369
|
-
applyBorderFlags(bmp, src, srcX, srcY, srcWidth, srcHeight,
|
431
|
+
applyBorderFlags(bmp, src, srcX, srcY, srcWidth, srcHeight, flags);
|
370
432
|
|
371
433
|
// Try to put the bitmap into one of the already allocated textures.
|
372
|
-
for (
|
434
|
+
for (Textures::iterator i = textures.begin(); i != textures.end(); ++i)
|
373
435
|
{
|
374
436
|
std::tr1::shared_ptr<Texture> texture(*i);
|
375
437
|
|
376
438
|
GOSU_UNIQUE_PTR<ImageData> data;
|
377
|
-
data = texture->tryAlloc(
|
439
|
+
data = texture->tryAlloc(texture, bmp, 1);
|
378
440
|
if (data.get())
|
379
441
|
return GOSU_MOVE_UNIQUE_PTR(data);
|
380
442
|
}
|
@@ -383,10 +445,10 @@ GOSU_UNIQUE_PTR<Gosu::ImageData> Gosu::Graphics::createImage(
|
|
383
445
|
|
384
446
|
std::tr1::shared_ptr<Texture> texture;
|
385
447
|
texture.reset(new Texture(maxSize));
|
386
|
-
|
448
|
+
textures.push_back(texture);
|
387
449
|
|
388
450
|
GOSU_UNIQUE_PTR<ImageData> data;
|
389
|
-
data = texture->tryAlloc(
|
451
|
+
data = texture->tryAlloc(texture, bmp, 1);
|
390
452
|
if (!data.get())
|
391
453
|
throw std::logic_error("Internal texture block allocation error");
|
392
454
|
|
data/src/Graphics/Image.cpp
CHANGED
@@ -6,35 +6,34 @@
|
|
6
6
|
#include <Gosu/IO.hpp>
|
7
7
|
#include <stdexcept>
|
8
8
|
|
9
|
-
Gosu::Image::Image(
|
9
|
+
Gosu::Image::Image(const std::wstring& filename, unsigned flags)
|
10
10
|
{
|
11
11
|
// Forward.
|
12
12
|
Bitmap bmp;
|
13
13
|
loadImageFile(bmp, filename);
|
14
|
-
Image(
|
14
|
+
Image(bmp, flags).data.swap(data);
|
15
15
|
}
|
16
16
|
|
17
|
-
Gosu::Image::Image(
|
17
|
+
Gosu::Image::Image(const std::wstring& filename,
|
18
18
|
unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
19
|
-
|
19
|
+
unsigned flags)
|
20
20
|
{
|
21
21
|
// Forward.
|
22
22
|
Bitmap bmp;
|
23
23
|
loadImageFile(bmp, filename);
|
24
|
-
Image(
|
24
|
+
Image(bmp, srcX, srcY, srcWidth, srcHeight, flags).data.swap(data);
|
25
25
|
}
|
26
26
|
|
27
|
-
Gosu::Image::Image(
|
27
|
+
Gosu::Image::Image(const Bitmap& source, unsigned flags)
|
28
28
|
{
|
29
29
|
// Forward.
|
30
|
-
Image(
|
30
|
+
Image(source, 0, 0, source.width(), source.height(), flags).data.swap(data);
|
31
31
|
}
|
32
32
|
|
33
|
-
Gosu::Image::Image(
|
33
|
+
Gosu::Image::Image(const Bitmap& source,
|
34
34
|
unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
35
|
-
|
36
|
-
: data(
|
37
|
-
tileable ? Gosu::bfTileable : Gosu::bfSmooth).release())
|
35
|
+
unsigned flags)
|
36
|
+
: data(Graphics::createImage(source, srcX, srcY, srcWidth, srcHeight, flags).release())
|
38
37
|
{
|
39
38
|
}
|
40
39
|
|
@@ -115,7 +114,8 @@ Gosu::ImageData& Gosu::Image::getData() const
|
|
115
114
|
return *data;
|
116
115
|
}
|
117
116
|
|
118
|
-
std::vector<Gosu::Image> Gosu::loadTiles(
|
117
|
+
std::vector<Gosu::Image> Gosu::loadTiles(const Bitmap& bmp,
|
118
|
+
int tileWidth, int tileHeight, unsigned flags)
|
119
119
|
{
|
120
120
|
int tilesX, tilesY;
|
121
121
|
std::vector<Image> images;
|
@@ -138,14 +138,56 @@ std::vector<Gosu::Image> Gosu::loadTiles(Graphics& graphics, const Bitmap& bmp,
|
|
138
138
|
|
139
139
|
for (int y = 0; y < tilesY; ++y)
|
140
140
|
for (int x = 0; x < tilesX; ++x)
|
141
|
-
images.push_back(Image(
|
141
|
+
images.push_back(Image(bmp, x * tileWidth, y * tileHeight, tileWidth, tileHeight, flags));
|
142
142
|
|
143
143
|
return images;
|
144
144
|
}
|
145
145
|
|
146
|
-
std::vector<Gosu::Image> Gosu::loadTiles(
|
146
|
+
std::vector<Gosu::Image> Gosu::loadTiles(const std::wstring& filename,
|
147
|
+
int tileWidth, int tileHeight, unsigned flags)
|
147
148
|
{
|
148
149
|
Bitmap bmp;
|
149
150
|
loadImageFile(bmp, filename);
|
150
|
-
return loadTiles(
|
151
|
+
return loadTiles(bmp, tileWidth, tileHeight, flags);
|
151
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
|
+
|