Skip to content

Commit 2c49561

Browse files
committed
Fix drawtextcenter point to respect args
1 parent 20353c0 commit 2c49561

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

include/Shirag.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "../src/discord/discord.hpp" // make so only if discord deps is installed
44
#include "../src/drawing/circle/circle.hpp"
5+
#include "../src/drawing/rectangle/rectangle.hpp"
56
#include "../src/drawing/text/text.hpp"
67
#include "../src/gui/windowSystem/windowSystem.hpp"
78
#include "../src/raytrace/raytrace.hpp"

src/drawing/text/text.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ void Shirag::Drawing::drawTextCenterPoint(Vector2 Center, std::string& Text, int
1717
float spacing = FontSize / 10.0f;
1818
Vector2 textSize = MeasureTextEx(Font, Text.c_str(), FontSize, spacing);
1919

20+
float x = Center.x;
21+
float y = Center.y;
22+
23+
if (CenterX)
24+
x = Center.x - textSize.x / 2.0f;
25+
if (CenterY)
26+
y = Center.y - textSize.y / 2.0f;
27+
2028
DrawTextEx(Font,
2129
Text.c_str(),
22-
{ Center.x - textSize.x / 2.0f, Center.y - textSize.y / 2.0f },
30+
{ x, y },
2331
FontSize,
2432
spacing,
2533
TextColor);
@@ -28,5 +36,10 @@ void Shirag::Drawing::drawTextCenterPoint(Vector2 Center, std::string& Text, int
2836
void Shirag::Drawing::drawTextCenterRect(Rectangle Rect, std::string& Text, int FontSize, Color TextColor, bool CenterX, bool CenterY, Font Font) {
2937
Vector2 centerPoint = { Rect.x + Rect.width / 2.0f, Rect.y + Rect.height / 2.0f };
3038

39+
if (!CenterX)
40+
centerPoint.x = Rect.x;
41+
if (!CenterY)
42+
centerPoint.y = Rect.y;
43+
3144
drawTextCenterPoint(centerPoint, Text, FontSize, TextColor, CenterX, CenterY, Font);
3245
}

0 commit comments

Comments
 (0)