-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileNode.cpp
More file actions
126 lines (93 loc) · 2.63 KB
/
FileNode.cpp
File metadata and controls
126 lines (93 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// Created by Kristal Hong on 11/21/23.
//
#include "FileNode.h"
void FileNode::reposition() const {
sf::Vector2f position = data.getPosition();
position.x += 50;
position.y += data.getGlobalBounds().height;
if (checkState(SHOW_CHILDREN)) {
for (auto &c : children) {
c.second->getData().setPosition(position);
position.y += c.second->getGlobalBounds().height;
c.second->reposition();
}
}
}
FileNode::FileNode() {
disableState(SHOW_CHILDREN);
}
FileNode::FileNode(std::string text, sf::Vector2f size, sf::Vector2f position)
: data(text, size, position) {
disableState(SHOW_CHILDREN);
}
void FileNode::draw(sf::RenderTarget &window, sf::RenderStates states) const {
data.draw(window, states);
// window.draw(data);
// Draw the children recursively if they should be shown
if (checkState(SHOW_CHILDREN)) {
// for (const auto& child : children) {
// child.second->draw(window, states);
// }
for (auto i = children.begin(); i != children.end(); ++i) {
window.draw(*(i->second));
}
}
}
void FileNode::addEventHandler(sf::RenderWindow &window, sf::Event event) {
data.addEventHandler(window, event);
if (MouseEvents::isClicked(data, window)) {
enableState(SELECTED);
toggleChildren();
}
if (checkState(SHOW_CHILDREN)) {
for (auto i = children.begin(); i != children.end(); ++i) {
i->second->addEventHandler(window, event);
if(MouseEvents::isClicked(*i->second, window))
{
disableState(SELECTED);
disableState(SHOW_CHILDREN);
}
}
}
}
void FileNode::update() {
//
}
Snapshot FileNode::getSnapshot() {
//
}
void FileNode::applySnapshot(const Snapshot &snapshot) {
//
}
sf::FloatRect FileNode::getGlobalBounds() {
// Get the global bounds for the current node
sf::FloatRect bounds = data.getGlobalBounds();
if (checkState(SHOW_CHILDREN) && !children.empty()) {
for (auto& c: children) {
bounds.height += c.second->getGlobalBounds().height;
}
}
return bounds;
}
bool FileNode::isLeaf() const {
return children.empty();
}
FileItem &FileNode::getData() {
return data;
}
void FileNode::setData(FileItem newData) {
data = newData;
}
std::map<std::string, FileNode *> &FileNode::getChildren() {
return children;
}
FileNode::iterator FileNode::begin() {
return children.begin();
}
FileNode::iterator FileNode::end() {
return children.end();
}
void FileNode::toggleChildren() {
toggleState(SHOW_CHILDREN);
}