-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.cpp
76 lines (53 loc) · 1.12 KB
/
Menu.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
#include "Menu.h"
#include "Utils.h"
#include <conio.h>
using namespace std;
Menu::Menu(vector<string> &options) :
m_options{options} {
Utils::ShowConsoleCursor(false);
}
Menu::~Menu() {
clear();
Utils::ShowConsoleCursor(true);
}
/* This function returns when ENTER is pressed */
int Menu::run() {
int key = 0;
while (key != ENTER) {
clear();
showOpt();
key = _getch();
/* getch () function returns two keycodes for arrow keys. Arrow put to getch '\033' and '[' and letter from A to D (up, down, right, left).
Check if the first value is escape and skip */
if (key == 224)
key = _getch();
switch (key) {
case UP_ARROW:
m_selIndex--;
if (m_selIndex == -1)
m_selIndex = 2;
break;
case DWN_ARROW:
m_selIndex++;
if (m_selIndex == 3)
m_selIndex = 0;
break;
default:
break;
}
}
return m_selIndex;
}
void Menu::showOpt() {
for (int i = 0; i < m_options.size(); i++) {
if (i == m_selIndex)
Utils::setColor(HIGHLIGHT_TXT);
else
Utils::setColor(DEFAULT_TXT);
cout << m_options.at(i) << endl;
}
}
void Menu::clear() {
Utils::resetColor();
system("cls");
}