diff --git a/inc/App.hpp b/inc/App.hpp index e4a9b1c..7a1d08a 100644 --- a/inc/App.hpp +++ b/inc/App.hpp @@ -37,4 +37,7 @@ private: std::array unit = {0}; DnaManager manager; + + Rectangle likedTextBox; + Rectangle genTextBox; }; diff --git a/inc/Math.hpp b/inc/Math.hpp index efd4bee..8440506 100644 --- a/inc/Math.hpp +++ b/inc/Math.hpp @@ -1,4 +1,5 @@ #include Color ColorAdd(Color c1, Color c2); -Color ColorAddValue(Color c, int add); \ No newline at end of file +Color ColorAddValue(Color c, int add); +Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin); \ No newline at end of file diff --git a/src/App.cpp b/src/App.cpp index 06ec688..5492310 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -7,9 +7,14 @@ #include #include -#define TOP 1 - pos +#define TOP (1 - pos) #define BOTTOM pos +// Dimentions for font size 20 +// DISLIKE 83 +// LIKE 46 +// GEN 9999: 999/999 -> 196 + void App::init(int screenWidth, int screenHeight) { this->screenWidth = screenWidth; @@ -37,10 +42,22 @@ void App::init(int screenWidth, int screenHeight) float posY = (screenHeight - screenWidth) / 2.0f; + likedTextBox = TextInSpace({0, + 0, + (float)screenWidth, + posY}, + 20.0f, 83.0f, 0.02f); + + genTextBox = TextInSpace({0, + posY + screenWidth, + (float)screenWidth, + posY}, + 20.0f, 196.0f, 0.02f); + destB = {0, posY, (float)screenWidth, (float)screenWidth}; destA = destB; - float recPosX = screenWidth * 0.2f; + float recPosX = screenWidth * 0.3f; disLikeBox = {0, posY, (float)recPosX, (float)screenWidth}; likeBox = {screenWidth - recPosX, posY, (float)recPosX, (float)screenWidth}; } @@ -116,6 +133,7 @@ void App::update() } rotation = 0.0f; destA = destB; + topLiked = Liked::tbd; } } @@ -131,15 +149,15 @@ void App::draw() DrawTexturePro(canvasTexure[TOP].texture, source, destA, origin, 360 - rotation, WHITE); const char *text = TextFormat("GEN %d: %d / %d", manager.generation, unit[TOP].index + 1, NUM_PER_GEN); - DrawText(text, destB.x + 10, destB.y - 30, 20, BLACK); + DrawText(text, genTextBox.x, genTextBox.y, genTextBox.height, BLACK); switch (topLiked) { case Liked::yes: - DrawText("LIKED", destB.x + 10, destB.y - 50, 20, BLACK); + DrawText("LIKED", likedTextBox.x, likedTextBox.y, likedTextBox.height, BLACK); break; case Liked::no: - DrawText("DISLIKE", destB.x + 10, destB.y - 50, 20, BLACK); + DrawText("DISLIKE", likedTextBox.x, likedTextBox.y, likedTextBox.height, BLACK); break; default: break; diff --git a/src/Math.cpp b/src/Math.cpp index 8955f2a..607b5c9 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -23,4 +23,34 @@ Color ColorAdd(Color c1, Color c2) int a = std::clamp(c1.a + c2.a, 0, 255); return {(unsigned char)r, (unsigned char)g, (unsigned char)b, (unsigned char)a}; +} + +Rectangle TextInSpace(Rectangle box, float textH, float textW, float margin) +{ + float br = box.width / box.height; + float tr = textW / textH; + + Rectangle ret = {0, 0, 0, 0}; + + 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; + + if (br < tr) + { + // bolj kvadrat izracunaj visino iz sirine + ret.height = ret.width / tr; + } + else + { + // bolj podolgovat izracunaj sirino iz visine + ret.width = ret.height * tr; + } + + return ret; } \ No newline at end of file