-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
114 lines (82 loc) · 2.74 KB
/
Application.cpp
File metadata and controls
114 lines (82 loc) · 2.74 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
//
// Created by Kristal Hong on 11/16/23.
//
#include "Application.h"
std::vector<GUIComponent*> Application::components;
Application::Application() {
//
}
void Application::addComponent(GUIComponent &component) {
components.push_back(&component);
}
void Application::run() {
sf::RenderWindow window({1000, 800}, "Final Project");
window.setFramerateLimit(100);
window.clear(sf::Color::White);
Canvas canvas({200, 220}, {800, 350});
TextInput textInput;
DropdownMenu dropdownMenu;
dropdownMenu.addItem("OpenSans");
dropdownMenu.addItem("ComicSans");
dropdownMenu.addItem("Whisper");
dropdownMenu.addItem("Lobster");
dropdownMenu.setSize({200, 40});
dropdownMenu.setPosition({745, 530});
Menu menu1 ("Create/View");
///functional parameter
menu1.addItem("Create Note", [&](const std::string& str) {
// std::cout << str << " new Node created\n";
textInput.disableState(HIDDEN);
});
Menu menu2 ("Edit");
menu2.addItem("Highlighter", [&](const std::string& str) {
canvas.disableState(HIDDEN);
});
MenuBar menuBar;
menuBar.addMenu(menu1);
menuBar.addMenu(menu2);
menuBar.setMenuSize({180, 50.f});
menuBar.setPosition({600.f, 10.f});
FileTree testFileTree;
testFileTree.setPosition({10, 10});
testFileTree.pathPush("Notes/Reading.png", "file");
testFileTree.pathPush("Notes/Text.png", "file");
addComponent(canvas);
addComponent(textInput);
addComponent(dropdownMenu);
addComponent(menuBar);
addComponent(testFileTree);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
window.close();
}
for (GUIComponent *&g: components) {
g->addEventHandler(window, event);
}
if (KeyShortcuts::isUndo() && History::canUndo()) {
// Handle undo action
History::undo();
}
// Check if user wants to change font
if(dropdownMenu.getString() == "OpenSans"){
textInput.setFont(OPEN_SANS);
} else if(dropdownMenu.getString() == "ComicSans"){
textInput.setFont(COMIC_SANS);
} else if(dropdownMenu.getString() == "Whisper"){
textInput.setFont(WHISPER);
}else if(dropdownMenu.getString() == "Lobster"){
textInput.setFont(LOBSTER);
}
}
for (GUIComponent *&g: components) {
g->update();
}
window.clear(sf::Color::White);
for (GUIComponent *&g: components) {
window.draw(*g);
}
window.display();
}
}