-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSequential.cpp
126 lines (102 loc) · 3.16 KB
/
Sequential.cpp
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
124
125
126
#include "Sequential.h"
#include "Intermediate.h"
Sequential::Sequential(sf::RenderWindow* window, std::stack<std::unique_ptr<State>>* stack)
: State(window, stack)
{
initButtons();
initFiles();
}
void Sequential::update()
{
updateMousePosition();
updateButtons();
}
void Sequential::render()
{
renderButtons();
}
void Sequential::initFiles()
{
file.open("Files/sort.txt");
if (!file.is_open())
std::cout << "Could not open file" << std::endl;
}
void Sequential::initButtons()
{
buttonMap["Bubble"] = new Button(40.f, 200.f, 1800.f, 20.f,
"BubbleSort", sf::Color(100, 100, 100, 100), sf::Color(150,150,150,150));
buttonMap["Merge"] = new Button(40.f, 200.f, 1800.f, 70.f,
"MergeSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Quick"] = new Button(40.f, 200.f, 1800.f, 120.f,
"QuickSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Insertion"] = new Button(40.f, 200.f, 1800.f, 170.f,
"InsertionSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Selection"] = new Button(40.f, 200.f, 1800.f, 220.f,
"SelectionSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Heap"] = new Button(40.f, 200.f, 1800.f, 270.f,
"HeapSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Bucket"] = new Button(40.f, 200.f, 1800.f, 320.f,
"BucketSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Radix"] = new Button(40.f, 200.f, 1800.f, 370.f,
"RadixSort", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
buttonMap["Exit"] = new Button(40.f, 200.f, 1800.f, 470.f,
"Exit", sf::Color(100, 100, 100, 100), sf::Color(150, 150, 150, 150));
}
void Sequential::updateButtons()
{
for (auto& it : buttonMap)
{
it.second->update(mousePosView);
}
if (buttonMap["Exit"]->isPressed())
{
stack_of_states->pop();
}
/*if (buttonMap["Bubble"]->isPressed())
{
file << "a";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Merge"]->isPressed())
{
file << "b";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Quick"]->isPressed())
{
file << "c";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Insertion"]->isPressed())
{
file << "d";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Selection"]->isPressed())
{
file << "e";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Heap"]->isPressed())
{
file << "f";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Bucket"]->isPressed())
{
file << "g";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}
if (buttonMap["Radix"]->isPressed())
{
file << "h";
stack_of_states->push(std::make_unique<Intermediate>(window, stack_of_states, true));
}*/
}
void Sequential::renderButtons()
{
for (auto& it : buttonMap)
{
it.second->render(window);
}
}