Skip to content

Commit 4730128

Browse files
authored
Merge pull request #192 from zomgtehderpy/foolingaround
Add scaling to bitmap primitives
2 parents 39f3b88 + 6ebee1a commit 4730128

File tree

7 files changed

+153
-11
lines changed

7 files changed

+153
-11
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
103103

104104
- New `SceneMan` function `CastAllMOsRay(startVector, rayVector, table ignoreMOIDs, ignoreTeam, ignoreMaterial, bool ignoreAllTerrain, int skip)` which returns an iterator with pointers to all the non-ignored MOs met along the ray.
105105

106+
- Added scaling capability to Bitmap primitives.
107+
New draw bindings with argument for scale are:
108+
```
109+
PrimitiveMan:DrawBitmapPrimitive(pos, moSprite, rotAngle, frame, scale)
110+
PrimitiveMan:DrawBitmapPrimitive(pos, moSprite, rotAngle, frame, scale, bool hFlipped, bool vFlipped)
111+
PrimitiveMan:DrawBitmapPrimitive(player, pos, moSprite, rotAngle, frame, scale)
112+
PrimitiveMan:DrawBitmapPrimitive(player, pos, moSprite, rotAngle, frame, scale, bool hFlipped, bool vFlipped)
113+
PrimitiveMan:DrawBitmapPrimitive(pos, filePath, rotAngle, scale)
114+
PrimitiveMan:DrawBitmapPrimitive(pos, filePath, rotAngle, scale, bool hFlipped, bool vFlipped)
115+
PrimitiveMan:DrawBitmapPrimitive(player, pos, filePath, rotAngle, scale)
116+
PrimitiveMan:DrawBitmapPrimitive(player, pos, filePath, rotAngle, scale, bool hFlipped, bool vFlipped)
117+
```
118+
As well as constructors:
119+
```
120+
BitmapPrimitive(player, pos, moSprite, rotAngle, frame, scale, hFlipped, vFlipped)
121+
BitmapPrimitive(player, pos, filePath, rotAngle, scale, hFlipped, vFlipped)
122+
```
123+
Original bindings with no scale argument are untouched and can be called as they were.
124+
106125
</details>
107126

108127
<details><summary><b>Changed</b></summary>

Source/Lua/LuaBindingsManagers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,21 @@ LuaBindingRegisterFunctionDefinitionForType(ManagerLuaBindings, PrimitiveMan) {
262262
.def("DrawTextPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& text, bool isSmall, int alignment)) & PrimitiveMan::DrawTextPrimitive)
263263
.def("DrawTextPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& text, bool isSmall, int alignment, float rotAngle)) & PrimitiveMan::DrawTextPrimitive)
264264
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame)) & PrimitiveMan::DrawBitmapPrimitive)
265+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale)) & PrimitiveMan::DrawBitmapPrimitive)
265266
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
267+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
266268
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame)) & PrimitiveMan::DrawBitmapPrimitive)
269+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale)) & PrimitiveMan::DrawBitmapPrimitive)
267270
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
271+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
268272
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const std::string& filePath, float rotAngle)) & PrimitiveMan::DrawBitmapPrimitive)
273+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const std::string& filePath, float rotAngle, float scale)) & PrimitiveMan::DrawBitmapPrimitive)
269274
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
275+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(const Vector& start, const std::string& filePath, float rotAngle, float scale, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
270276
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& filePath, float rotAngle)) & PrimitiveMan::DrawBitmapPrimitive)
277+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& filePath, float rotAngle, float scale)) & PrimitiveMan::DrawBitmapPrimitive)
271278
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
279+
.def("DrawBitmapPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, const std::string& filePath, float rotAngle, float scale, bool hFlipped, bool vFlipped)) & PrimitiveMan::DrawBitmapPrimitive)
272280
.def("DrawIconPrimitive", (void(PrimitiveMan::*)(const Vector& start, Entity* entity)) & PrimitiveMan::DrawIconPrimitive)
273281
.def("DrawIconPrimitive", (void(PrimitiveMan::*)(int player, const Vector& start, Entity* entity)) & PrimitiveMan::DrawIconPrimitive)
274282

Source/Lua/LuaBindingsPrimitives.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ LuaBindingRegisterFunctionDefinitionForType(PrimitiveLuaBindings, TextPrimitive)
9595
LuaBindingRegisterFunctionDefinitionForType(PrimitiveLuaBindings, BitmapPrimitive) {
9696
return luabind::class_<BitmapPrimitive, GraphicalPrimitive>("BitmapPrimitive")
9797

98+
.def(luabind::constructor<int, const Vector&, const MOSprite*, float, unsigned int, float, bool, bool>())
99+
.def(luabind::constructor<int, const Vector&, const std::string&, float, float, bool, bool>())
98100
.def(luabind::constructor<int, const Vector&, const MOSprite*, float, unsigned int, bool, bool>())
99101
.def(luabind::constructor<int, const Vector&, const std::string&, float, bool, bool>());
100102
}

Source/Managers/PrimitiveMan.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ void PrimitiveMan::DrawTextPrimitive(int player, const Vector& start, const std:
217217
SchedulePrimitive(std::make_unique<TextPrimitive>(player, start, text, isSmall, alignment, rotAngle));
218218
}
219219

220-
void PrimitiveMan::DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped) {
221-
SchedulePrimitive(std::make_unique<BitmapPrimitive>(player, centerPos, moSprite, rotAngle, frame, hFlipped, vFlipped));
220+
void PrimitiveMan::DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale, bool hFlipped, bool vFlipped) {
221+
SchedulePrimitive(std::make_unique<BitmapPrimitive>(player, centerPos, moSprite, rotAngle, frame, scale, hFlipped, vFlipped));
222222
}
223223

224-
void PrimitiveMan::DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped) {
225-
SchedulePrimitive(std::make_unique<BitmapPrimitive>(player, centerPos, filePath, rotAngle, hFlipped, vFlipped));
224+
void PrimitiveMan::DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, float scale, bool hFlipped, bool vFlipped) {
225+
SchedulePrimitive(std::make_unique<BitmapPrimitive>(player, centerPos, filePath, rotAngle, scale, hFlipped, vFlipped));
226226
}
227227

228228
void PrimitiveMan::DrawIconPrimitive(int player, const Vector& centerPos, Entity* entity) {

Source/Managers/PrimitiveMan.h

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ namespace RTE {
311311
/// @param frame Frame to draw.
312312
void DrawBitmapPrimitive(const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame) { DrawBitmapPrimitive(-1, centerPos, moSprite, rotAngle, frame, false, false); }
313313

314+
/// Schedule to draw a bitmap primitive.
315+
/// @param centerPos Position of primitive's center in scene coordinates.
316+
/// @param moSprite A MOSprite to draw BITMAP from.
317+
/// @param rotAngle Rotation angle in radians.
318+
/// @param frame Frame to draw.
319+
/// @param scale Drawing scale.
320+
void DrawBitmapPrimitive(const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale) { DrawBitmapPrimitive(-1, centerPos, moSprite, rotAngle, scale, frame, false, false); }
321+
314322
/// Schedule to draw a bitmap primitive with the option to flip the primitive horizontally and vertically.
315323
/// @param centerPos Position of primitive's center in scene coordinates.
316324
/// @param moSprite A MOSprite to draw BITMAP from.
@@ -320,6 +328,16 @@ namespace RTE {
320328
/// @param vFlipped Whether to flip the sprite vertically.
321329
void DrawBitmapPrimitive(const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(-1, centerPos, moSprite, rotAngle, frame, hFlipped, vFlipped); }
322330

331+
/// Schedule to draw a bitmap primitive with the option to flip the primitive horizontally and vertically.
332+
/// @param centerPos Position of primitive's center in scene coordinates.
333+
/// @param moSprite A MOSprite to draw BITMAP from.
334+
/// @param rotAngle Rotation angle in radians.
335+
/// @param frame Frame to draw.
336+
/// @param scale Drawing scale.
337+
/// @param hFlipped Whether to flip the sprite horizontally.
338+
/// @param vFlipped Whether to flip the sprite vertically.
339+
void DrawBitmapPrimitive(const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(-1, centerPos, moSprite, rotAngle, frame, scale, hFlipped, vFlipped); }
340+
323341
/// Schedule to draw a bitmap primitive visible only to a specified player.
324342
/// @param player Player screen to draw primitive on.
325343
/// @param centerPos Position of primitive's center in scene coordinates.
@@ -328,22 +346,49 @@ namespace RTE {
328346
/// @param frame Frame to draw.
329347
void DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame) { DrawBitmapPrimitive(player, centerPos, moSprite, rotAngle, frame, false, false); }
330348

349+
/// Schedule to draw a bitmap primitive visible only to a specified player.
350+
/// @param player Player screen to draw primitive on.
351+
/// @param centerPos Position of primitive's center in scene coordinates.
352+
/// @param moSprite A MOSprite to draw BITMAP from.
353+
/// @param rotAngle Rotation angle in radians.
354+
/// @param frame Frame to draw.
355+
/// @param scale Drawing scale.
356+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale) { DrawBitmapPrimitive(player, centerPos, moSprite, rotAngle, frame, scale, false, false); }
357+
358+
/// Schedule to draw a bitmap primitive visible only to a specified player with the option to flip the primitive horizontally or vertically.
359+
/// @param player Player screen to draw primitive on.
360+
/// @param centerPos Position of primitive's center in scene coordinates.
361+
/// @param moSprite A MOSprite to draw BITMAP from.
362+
/// @param rotAngle Rotation angle in radians.
363+
/// @param frame Frame to draw.
364+
/// @param hFlipped Whether to flip the sprite horizontally.
365+
/// @param vFlipped Whether to flip the sprite vertically.
366+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(player, centerPos, moSprite, rotAngle, frame, 1.0f, false, false); }
367+
331368
/// Schedule to draw a bitmap primitive visible only to a specified player with the option to flip the primitive horizontally or vertically.
332369
/// @param player Player screen to draw primitive on.
333370
/// @param centerPos Position of primitive's center in scene coordinates.
334371
/// @param moSprite A MOSprite to draw BITMAP from.
335372
/// @param rotAngle Rotation angle in radians.
336373
/// @param frame Frame to draw.
374+
/// @param scale Drawing scale.
337375
/// @param hFlipped Whether to flip the sprite horizontally.
338376
/// @param vFlipped Whether to flip the sprite vertically.
339-
void DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, bool hFlipped, bool vFlipped);
377+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const MOSprite* moSprite, float rotAngle, unsigned int frame, float scale, bool hFlipped, bool vFlipped);
340378

341379
/// Schedule to draw a bitmap primitive.
342380
/// @param centerPos Position of primitive's center in scene coordinates.
343381
/// @param filePath Path to the bitmap to draw.
344382
/// @param rotAngle Rotation angle in radians.
345383
void DrawBitmapPrimitive(const Vector& centerPos, const std::string& filePath, float rotAngle) { DrawBitmapPrimitive(-1, centerPos, filePath, rotAngle, false, false); }
346384

385+
/// Schedule to draw a bitmap primitive.
386+
/// @param centerPos Position of primitive's center in scene coordinates.
387+
/// @param filePath Path to the bitmap to draw.
388+
/// @param rotAngle Rotation angle in radians.
389+
/// @param scale Drawing scale.
390+
void DrawBitmapPrimitive(const Vector& centerPos, const std::string& filePath, float rotAngle, float scale) { DrawBitmapPrimitive(-1, centerPos, filePath, rotAngle, scale, false, false); }
391+
347392
/// Schedule to draw a bitmap primitive with the option to flip the primitive horizontally and vertically.
348393
/// @param centerPos Position of primitive's center in scene coordinates.
349394
/// @param filePath An entity to draw sprite from.
@@ -352,21 +397,48 @@ namespace RTE {
352397
/// @param vFlipped Whether to flip the sprite vertically.
353398
void DrawBitmapPrimitive(const Vector& centerPos, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(-1, centerPos, filePath, rotAngle, hFlipped, vFlipped); }
354399

400+
/// Schedule to draw a bitmap primitive with the option to flip the primitive horizontally and vertically.
401+
/// @param centerPos Position of primitive's center in scene coordinates.
402+
/// @param filePath An entity to draw sprite from.
403+
/// @param rotAngle Rotation angle in radians.
404+
/// @param scale Drawing scale.
405+
/// @param hFlipped Whether to flip the sprite horizontally.
406+
/// @param vFlipped Whether to flip the sprite vertically.
407+
void DrawBitmapPrimitive(const Vector& centerPos, const std::string& filePath, float rotAngle, float scale, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(-1, centerPos, filePath, rotAngle, scale, hFlipped, vFlipped); }
408+
355409
/// Schedule to draw a bitmap primitive visible only to a specified player.
356410
/// @param player Player screen to draw primitive on.
357411
/// @param centerPos Position of primitive's center in scene coordinates.
358412
/// @param filePath Path to the bitmap to draw.
359413
/// @param rotAngle Rotation angle in radians.
360414
void DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle) { DrawBitmapPrimitive(player, centerPos, filePath, rotAngle, false, false); }
361415

416+
/// Schedule to draw a bitmap primitive visible only to a specified player.
417+
/// @param player Player screen to draw primitive on.
418+
/// @param centerPos Position of primitive's center in scene coordinates.
419+
/// @param filePath Path to the bitmap to draw.
420+
/// @param rotAngle Rotation angle in radians.
421+
/// @param scale Drawing scale.
422+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, float scale) { DrawBitmapPrimitive(player, centerPos, filePath, rotAngle, scale, false, false); }
423+
424+
/// Schedule to draw a bitmap primitive visible only to a specified player with the option to flip the primitive horizontally or vertically.
425+
/// @param player Player screen to draw primitive on.
426+
/// @param centerPos Position of primitive's center in scene coordinates.
427+
/// @param filePath Path to the bitmap to draw.
428+
/// @param rotAngle Rotation angle in radians.
429+
/// @param hFlipped Whether to flip the sprite horizontally.
430+
/// @param vFlipped Whether to flip the sprite vertically.
431+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped) { DrawBitmapPrimitive(player, centerPos, filePath, rotAngle, 1.0f, false, false); }
432+
362433
/// Schedule to draw a bitmap primitive visible only to a specified player with the option to flip the primitive horizontally or vertically.
363434
/// @param player Player screen to draw primitive on.
364435
/// @param centerPos Position of primitive's center in scene coordinates.
365436
/// @param filePath Path to the bitmap to draw.
366437
/// @param rotAngle Rotation angle in radians.
438+
/// @param scale Drawing scale.
367439
/// @param hFlipped Whether to flip the sprite horizontally.
368440
/// @param vFlipped Whether to flip the sprite vertically.
369-
void DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, bool hFlipped, bool vFlipped);
441+
void DrawBitmapPrimitive(int player, const Vector& centerPos, const std::string& filePath, float rotAngle, float scale, bool hFlipped, bool vFlipped);
370442

371443
/// Schedule to draw the GUI icon of an object.
372444
/// @param centerPos Position of primitive's center in scene coordinates.

Source/System/GraphicalPrimitive.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,13 @@ void BitmapPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
504504
return;
505505
}
506506

507-
BITMAP* bitmapToDraw = create_bitmap_ex(8, m_Bitmap->w, m_Bitmap->h);
507+
BITMAP* bitmapToDraw = create_bitmap_ex(8, m_Bitmap->w * m_Scale, m_Bitmap->h * m_Scale);
508508
clear_to_color(bitmapToDraw, ColorKeys::g_MaskColor);
509-
draw_sprite(bitmapToDraw, m_Bitmap, 0, 0);
509+
if (m_Scale == 1.0f) {
510+
draw_sprite(bitmapToDraw, m_Bitmap, 0, 0);
511+
} else {
512+
stretch_sprite(bitmapToDraw, m_Bitmap, 0, 0, m_Bitmap->w * m_Scale, m_Bitmap->h * m_Scale);
513+
}
510514

511515
if (m_HFlipped || m_VFlipped) {
512516
BITMAP* flipBitmap = create_bitmap_ex(8, bitmapToDraw->w, bitmapToDraw->h);

0 commit comments

Comments
 (0)