From 5342f1b9280f64530abe8d00808e8a37a86806e4 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Mon, 20 Jan 2025 02:43:53 +0100 Subject: [PATCH] Change position of text --- inc/Math.hpp | 2 +- src/App.cpp | 14 ++++++++++---- src/Math.cpp | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/inc/Math.hpp b/inc/Math.hpp index 8440506..bc5533f 100644 --- a/inc/Math.hpp +++ b/inc/Math.hpp @@ -2,4 +2,4 @@ Color ColorAdd(Color c1, Color c2); Color ColorAddValue(Color c, int add); -Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin); \ No newline at end of file +Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom); \ No newline at end of file diff --git a/src/App.cpp b/src/App.cpp index 5492310..78dd0e1 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -13,14 +13,20 @@ // Dimentions for font size 20 // DISLIKE 83 // LIKE 46 -// GEN 9999: 999/999 -> 196 +// GEN 9999: 999/999 -> 200 +constexpr float textMargin = 0.02f; void App::init(int screenWidth, int screenHeight) { + SetTextLineSpacing(0); + this->screenWidth = screenWidth; this->screenHeight = screenHeight; this->canvas.init(screenWidth); + // int s = MeasureText("GEN 9999: 999/999", 20); + // TraceLog(LOG_INFO, "%d", s); + for (size_t i = 0; i < canvasTexure.size(); i++) { canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth); @@ -44,15 +50,15 @@ void App::init(int screenWidth, int screenHeight) likedTextBox = TextInSpace({0, 0, - (float)screenWidth, + (float)screenWidth / 2.0f, posY}, - 20.0f, 83.0f, 0.02f); + 20.0f, 83.0f, textMargin, false); genTextBox = TextInSpace({0, posY + screenWidth, (float)screenWidth, posY}, - 20.0f, 196.0f, 0.02f); + 20.0f, 200.0f, textMargin, true); destB = {0, posY, (float)screenWidth, (float)screenWidth}; destA = destB; diff --git a/src/Math.cpp b/src/Math.cpp index 607b5c9..525318f 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -25,7 +25,7 @@ Color ColorAdd(Color c1, Color c2) return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a}; } -Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin) +Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin, bool topOrBottom) { float br = box.width / box.height; float tr = textW / textH; @@ -35,9 +35,6 @@ Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin) float hm = box.height * margin; float wm = box.width * margin; - ret.y = box.y + hm; - ret.x = box.x + wm; - ret.height = box.height - hm; ret.width = box.width - wm; @@ -52,5 +49,16 @@ Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin) ret.width = ret.height * tr; } + if (topOrBottom) + { + ret.y = box.y + hm; + } + else + { + ret.y = box.y + box.height - hm - ret.height; + } + + ret.x = box.x + wm; + return ret; } \ No newline at end of file