From c4a58c3f5c17dbef444ba8b6afce42db467c6196 Mon Sep 17 00:00:00 2001 From: memeToasty Date: Mon, 5 Sep 2022 21:38:12 +0200 Subject: [PATCH] fixed tree view --- source/node.cpp | 16 +++++++++------- source/node.hpp | 4 ++-- source/visuals.cpp | 17 ++++++----------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/source/node.cpp b/source/node.cpp index 383711d..4b16137 100644 --- a/source/node.cpp +++ b/source/node.cpp @@ -2,21 +2,23 @@ #include "node.hpp" #include -Node::Node(const char* text, float x, float y, float size) { - this->size = size * 20; +Node::Node(const char* text, float x, float y, float scale) { + this->scale = scale; this->x = x; this->y = y; - this->text = new Text(text, this->x, this->y, size); - // TODO why the hell does this not work?! - this->text->xPos -= this->text->staticText.width; + this->text = new Text(text, x, y, scale); } void Node::render(bool active) { + + this->text->xPos = this->x - (this->text->staticText.width / 2 * scale); + this->text->yPos = this->y - (this->scale * 15); + if (active) { - C2D_DrawCircleSolid(x, y, 0, size, activeColor); + C2D_DrawCircleSolid(x, y, 0, scale * 15, activeColor); } else { - C2D_DrawCircleSolid(x, y, 0, size, color); + C2D_DrawCircleSolid(x, y, 0, scale * 15, color); } this->text->render(); } \ No newline at end of file diff --git a/source/node.hpp b/source/node.hpp index f8b6faf..a11df1e 100644 --- a/source/node.hpp +++ b/source/node.hpp @@ -11,9 +11,9 @@ class Node { public: Text* text; float x,y; - float size; + float scale; - Node(const char* text, float x, float y, float size); + Node(const char* text, float x, float y, float scale); void render(bool active); }; diff --git a/source/visuals.cpp b/source/visuals.cpp index d075a2e..194ada0 100644 --- a/source/visuals.cpp +++ b/source/visuals.cpp @@ -12,6 +12,8 @@ SwkbdState swkbd; char mybuf[10]; +static const int PADDING = 30; + void accessElement(unsigned int accessedIndex) { activeIndex = accessedIndex; @@ -94,13 +96,9 @@ void initArray() } // Init Tree view nodeArray.clear(); - for (unsigned short i = 0; i < arrayLen; i++) - { - nodeArray.push_back(new Node(&std::to_string(array[i]).c_str()[0],0,i*10, 0.5f)); - } - unsigned short height = (unsigned short) floor(log2(nodeArray.size())); - float yGap = SCREEN_HEIGHT / height; + unsigned short height = (unsigned short) floor(log2(arrayLen)); + float yGap = (SCREEN_HEIGHT - (2 * PADDING)) / height; //Go through every layer of binary tree with size of the nodeArray for (unsigned short h = 0; h <= height; ++h) { @@ -110,14 +108,11 @@ void initArray() for (unsigned short i = 0; i < (unsigned short) pow(2,h); ++i) { int absoluteI = pow(2,h) - 1 + i; - if (absoluteI > (int) nodeArray.size() - 1) { + if (absoluteI > (int) arrayLen - 1) { break; } - Node* currentNode = nodeArray.at(absoluteI); - - currentNode->x = leftOffset + i * xGap; - currentNode->y = h * yGap; + nodeArray.push_back(new Node(std::to_string(array[i]).c_str(), leftOffset + i * xGap, h * yGap + PADDING, 10.0f / arrayLen )); } } }