2
2
#include " Matrix.h"
3
3
#include " FrameMan.h"
4
4
#include " SceneMan.h"
5
+ #include " GLResourceMan.h"
6
+ #include " SLTerrain.h"
5
7
6
8
#include " GUI.h"
7
9
#include " AllegroBitmap.h"
@@ -34,23 +36,18 @@ Vector GraphicalPrimitive::WrapCoordinates(Vector targetPos, const Vector& scene
34
36
}
35
37
36
38
void GraphicalPrimitive::DrawTiled (BITMAP* drawScreen, const Vector& targetPos) {
37
- DrawLineV (-targetPos + Vector (-30 , -30 ), -targetPos + Vector (30 , 30 ), {53 , 0 , 0 , 255 });
38
- DrawLineV (-targetPos + Vector (30 , -30 ), -targetPos + Vector (-30 , 30 ), {53 , 0 , 0 , 255 });
39
-
40
39
Vector tiledTarget{targetPos};
41
40
if (g_SceneMan.SceneWrapsX ()) {
42
41
tiledTarget.m_X = std::fmodf (targetPos.m_X , g_SceneMan.GetSceneWidth ());
43
42
}
44
43
if (g_SceneMan.SceneWrapsY ()) {
45
44
tiledTarget.m_Y = std::fmodf (targetPos.m_Y , g_SceneMan.GetSceneHeight ());
46
45
}
47
- DrawLineV (-tiledTarget + Vector (-30 , -30 ), -tiledTarget + Vector (30 , 30 ), {53 , 0 , 0 , 255 });
48
- DrawLineV (-tiledTarget + Vector (30 , -30 ), -tiledTarget + Vector (-30 , 30 ), {53 , 0 , 0 , 255 });
49
46
50
47
float bitmapWidth = g_SceneMan.GetSceneWidth ();
51
48
float bitmapHeight = g_SceneMan.GetSceneHeight ();
52
- int areaToCoverX = drawScreen->w ;
53
- int areaToCoverY = drawScreen->h ;
49
+ float areaToCoverX = drawScreen->w + g_SceneMan. GetTerrain ()-> GetOffset (). m_X ;
50
+ float areaToCoverY = drawScreen->h + g_SceneMan. GetTerrain ()-> GetOffset (). m_Y ;
54
51
55
52
for (int tiledOffsetX = 0 ; tiledOffsetX < areaToCoverX;) {
56
53
float destX = tiledOffsetX - tiledTarget.m_X ;
@@ -213,46 +210,47 @@ void PolygonFillPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
213
210
DrawTriangleStrip (drawPoints.data (), drawPoints.size (), {m_Color, 0 , 0 , 255 });
214
211
}
215
212
216
- void TextPrimitive::Draw (BITMAP* drawScreen, const Vector& targetPos) {
217
- if (m_Text.empty ()) {
213
+
214
+ void TextPrimitive::CreateTextBitmap () {
215
+ if (m_Text.empty ()) {
218
216
return ;
219
217
}
220
-
221
- AllegroBitmap playerGUIBitmap (drawScreen);
222
218
GUIFont* font = m_IsSmall ? g_FrameMan.GetSmallFont () : g_FrameMan.GetLargeFont ();
223
219
Matrix rotation = Matrix (m_RotAngle);
224
220
Vector targetPosAdjustment = Vector ();
225
221
226
- BITMAP* tempDrawBitmap = nullptr ;
227
- if (m_BlendMode > DrawBlendMode::NoBlend || m_RotAngle != 0 ) {
228
- int textWidth = font->CalculateWidth (m_Text);
229
- int textHeight = font->CalculateHeight (m_Text);
222
+ int textWidth = font->CalculateWidth (m_Text);
223
+ int textHeight = font->CalculateHeight (m_Text);
224
+
225
+ drawing_mode (DRAW_MODE_SOLID, nullptr , 0 , 0 );
226
+
227
+ m_TextBitmap = create_bitmap_ex (8 , textWidth * 2 , textHeight);
228
+ clear_to_color (m_TextBitmap, ColorKeys::g_MaskColor);
229
+ AllegroBitmap tempDrawAllegroBitmap (m_TextBitmap);
230
+ font->DrawAligned (&tempDrawAllegroBitmap, textWidth, 0 , m_Text, m_Alignment);
230
231
231
- tempDrawBitmap = create_bitmap_ex (8 , textWidth * 2 , textHeight);
232
- clear_to_color (tempDrawBitmap, ColorKeys::g_MaskColor);
233
- AllegroBitmap tempDrawAllegroBitmap (tempDrawBitmap);
234
- font->DrawAligned (&tempDrawAllegroBitmap, textWidth, 0 , m_Text, m_Alignment);
232
+ m_TargetPosAlignment = Vector (static_cast <float >(textWidth), 0 );
233
+ }
235
234
236
- targetPosAdjustment = Vector (static_cast <float >(textWidth), 0 );
235
+ void TextPrimitive::Draw (BITMAP* drawScreen, const Vector& targetPos) {
236
+ if (!m_TextBitmap) {
237
+ return ;
237
238
}
238
239
239
- Vector drawStart = WrapCoordinates (targetPos, m_StartPos) - targetPosAdjustment;
240
+ Vector drawStart = WrapCoordinates (targetPos, m_StartPos) - m_TargetPosAlignment;
241
+ Rectangle bitmapRect (0 .0f , 0 .0f , m_TextBitmap->w , m_TextBitmap->h );
242
+ Rectangle destRect (
243
+ drawStart.m_X ,
244
+ drawStart.m_Y ,
245
+ m_TextBitmap->w ,
246
+ m_TextBitmap->h );
247
+ DrawTexturePro (m_TextBitmap, bitmapRect, destRect, {0 .0f , 0 .0f }, m_RotAngle, {255 , 255 , 255 , 255 });
248
+ }
240
249
241
- if (m_BlendMode > DrawBlendMode::NoBlend) {
242
- if (m_RotAngle != 0 ) {
243
- rotate_sprite_trans (drawScreen, tempDrawBitmap, drawStart.GetFloorIntX (), drawStart.GetFloorIntY (), ftofix (rotation.GetAllegroAngle ()));
244
- } else {
245
- draw_trans_sprite (drawScreen, tempDrawBitmap, drawStart.GetFloorIntX (), drawStart.GetFloorIntY ());
246
- }
247
- } else {
248
- if (m_RotAngle != 0 ) {
249
- rotate_sprite (drawScreen, tempDrawBitmap, drawStart.GetFloorIntX (), drawStart.GetFloorIntY (), ftofix (rotation.GetAllegroAngle ()));
250
- } else {
251
- font->DrawAligned (&playerGUIBitmap, drawStart.GetFloorIntX (), drawStart.GetFloorIntY (), m_Text, m_Alignment);
252
- }
253
- }
254
- if (tempDrawBitmap) {
255
- destroy_bitmap (tempDrawBitmap);
250
+ TextPrimitive::~TextPrimitive () {
251
+ if (m_TextBitmap) {
252
+ g_GLResourceMan.DestroyBitmapInfo (m_TextBitmap);
253
+ destroy_bitmap (m_TextBitmap);
256
254
}
257
255
}
258
256
@@ -261,33 +259,14 @@ void BitmapPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
261
259
return ;
262
260
}
263
261
264
- BITMAP* bitmapToDraw = create_bitmap_ex (8 , m_Bitmap->w , m_Bitmap->h );
265
- clear_to_color (bitmapToDraw, ColorKeys::g_MaskColor);
266
- draw_sprite (bitmapToDraw, m_Bitmap, 0 , 0 );
267
-
268
- if (m_HFlipped || m_VFlipped) {
269
- BITMAP* flipBitmap = create_bitmap_ex (8 , bitmapToDraw->w , bitmapToDraw->h );
270
- clear_to_color (flipBitmap, ColorKeys::g_MaskColor);
271
-
272
- if (m_HFlipped && !m_VFlipped) {
273
- draw_sprite_h_flip (flipBitmap, bitmapToDraw, 0 , 0 );
274
- } else if (!m_HFlipped && m_VFlipped) {
275
- draw_sprite_v_flip (flipBitmap, bitmapToDraw, 0 , 0 );
276
- } else if (m_HFlipped && m_VFlipped) {
277
- draw_sprite_vh_flip (flipBitmap, bitmapToDraw, 0 , 0 );
278
- }
279
-
280
- blit (flipBitmap, bitmapToDraw, 0 , 0 , 0 , 0 , bitmapToDraw->w , bitmapToDraw->h );
281
- destroy_bitmap (flipBitmap);
282
- }
262
+ Vector drawStart = WrapCoordinates (targetPos, m_StartPos);
283
263
284
- Matrix rotation = Matrix (m_RotAngle);
264
+ Rectangle flippedRect (
265
+ drawStart.m_X - m_Bitmap->w / 2 ,
266
+ drawStart.m_Y - m_Bitmap->h / 2 ,
267
+ m_VFlipped ? -m_Bitmap->w : m_Bitmap->w ,
268
+ m_HFlipped ? -m_Bitmap->h : m_Bitmap->h
269
+ );
285
270
286
- Vector drawStart = WrapCoordinates (targetPos, m_StartPos);
287
- if (m_BlendMode > DrawBlendMode::NoBlend) {
288
- pivot_scaled_sprite_trans (drawScreen, bitmapToDraw, drawStart.GetFloorIntX (), drawStart.GetFloorIntY (), bitmapToDraw->w / 2 , bitmapToDraw->h / 2 , ftofix (rotation.GetAllegroAngle ()), ftofix (1.0 ));
289
- } else {
290
- pivot_scaled_sprite (drawScreen, bitmapToDraw, drawStart.GetFloorIntX (), drawStart.GetFloorIntY (), bitmapToDraw->w / 2 , bitmapToDraw->h / 2 , ftofix (rotation.GetAllegroAngle ()), ftofix (1.0 ));
291
- }
292
- destroy_bitmap (bitmapToDraw);
271
+ DrawTexturePro (m_Bitmap, Rectangle (0 .0f , 0 .0f , m_Bitmap->w , m_Bitmap->h ), flippedRect, {0 .0f , 0 .0f }, m_RotAngle, {255 , 255 , 255 , 255 });
293
272
}
0 commit comments