-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMenu.cpp
More file actions
116 lines (101 loc) · 2.28 KB
/
Menu.cpp
File metadata and controls
116 lines (101 loc) · 2.28 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
#include "Menu.h"
#include <iostream>
Menu::Menu(std::string text)
{
this->text = text;
this->ShowCursor(false);
}
Menu::Menu(std::string header, std::string footer)
{
this->text = header;
this->footer = footer;
this->ShowCursor(false);
}
void Menu::AddOption(std::string text, int status)
{
Button option = Button(text, status);
this->buttons.push_back(option);
this->Options.push_back(0);
}
void Menu::AddOption(float minValue, float maxValue, bool active)
{
ProgressBar progressBar = ProgressBar(minValue, maxValue, active);
this->progressBars.push_back(progressBar);
this->Options.push_back(1);
}
void Menu::Print()
{
int button_counter = 0;
int progressbar_counter = 0;
system("CLS");
std::cout << this->text << "\n\n";
for (int i : Options) {
if (i == 0) {
buttons[button_counter].Print();
button_counter++;
}
else if (i == 1) {
progressBars[progressbar_counter].Print();
progressbar_counter++;
}
}
std::cout << "\n\n" << this->footer;
//std::cout.flush();
}
void Menu::UpdateOption()
{
for (std::vector<Button>::size_type i = 0; i != buttons.size(); i++) {
buttons[i].UpdateStatus();
}
this->Print();
}
void Menu::UpdateOption(bool on)
{
for (std::vector<Button>::size_type i = 0; i != buttons.size(); i++) {
if(on)
buttons[i].UpdateStatus(2);
else
buttons[i].UpdateStatus(0);
}
this->Print();
}
void Menu::UpdateOption(int index)
{
try {
buttons[index].UpdateStatus();
}
catch (const std::exception & e) { std::cout << e.what(); };
this->Print();
}
void Menu::UpdateOption(int index, int status)
{
try {
buttons[index].UpdateStatus(status);
}
catch (const std::exception& e) { std::cout << e.what(); };
this->Print();
}
void Menu::UpdateOption(int index, bool status)
{
try {
buttons[index].UpdateStatus(status);
}
catch (const std::exception& e) { std::cout << e.what(); };
this->Print();
}
void Menu::UpdateProgressBar(int index, float currentValue)
{
try {
this->progressBars[index].Update(currentValue);
}
catch (const std::exception & e) { std::cout << e.what(); };
this->Print();
}
void Menu::ShowCursor(bool showFlag)
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showFlag;
SetConsoleCursorInfo(out, &cursorInfo);
}