Skip to content

Commit

Permalink
fixed tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
memeToasty committed Sep 5, 2022
1 parent caea669 commit c4a58c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
16 changes: 9 additions & 7 deletions source/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
#include "node.hpp"
#include <citro2d.h>

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();
}
4 changes: 2 additions & 2 deletions source/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
17 changes: 6 additions & 11 deletions source/visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
SwkbdState swkbd;
char mybuf[10];

static const int PADDING = 30;

void accessElement(unsigned int accessedIndex)
{
activeIndex = accessedIndex;
Expand Down Expand Up @@ -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) {

Expand All @@ -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 ));
}
}
}
Expand Down

0 comments on commit c4a58c3

Please sign in to comment.