-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColouring.h
95 lines (88 loc) · 2.45 KB
/
Colouring.h
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
#define FAIZAN_H
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
// Made by faizan uet Lahore
/**
* @author @
*/
void arrow_control(int up, int low, char key, int& selected)
{
/**
* @brief Handles arrow key controls for navigating menus.
*
* @param up The upper bound of the menu options.
* @param low The lower bound of the menu options.
* @param key The pressed arrow key.
* @param selected The currently selected menu option (updated by reference).
* @return The updated selected menu option.
*/
switch (key)
{
case 72:
if (selected != low)
selected--;
else if (selected == low)
selected = up;
break;
case 80:
if (selected != up)
selected++;
else if (selected == up)
selected = low;
}
return;
}
void printmenu(string line, int selected, int x, int colour_selected, int colour_unselected)
{
/**
* @brief Prints a menu option with appropriate coloring.
*
* @param line The menu option text.
* @param selected The currently selected menu option.
* @param x The position of the menu option.
* @param colour_selected The color for the selected menu option.
* @param colour_unselected The color for unselected menu options.
*/
if (selected == x)
{
SetConsoleTextAttribute(h, colour_selected);
cout << line << endl;
}
else
{
SetConsoleTextAttribute(h, colour_unselected);
cout << line << endl;
}
}
int complete_menu(string arr[], int size, int colour = 13, int colour2 = 15)
{ /**
* @brief Displays an interactive menu and handles user input.
*
* @param arr An array of menu options.
* @param size The size of the menu options array.
* @param colour The default color for menu options.
* @param colour2 The color for the selected menu option.
* @return The selected menu option.
*/
char key;
int selected = 1;
do
{
system("cls");
for (int i = 0; i < size; i++)
printmenu(arr[i], selected, i + 1, colour, colour2);
key = _getch();
if (key == 13)
{
SetConsoleTextAttribute(h, 15);
return selected;
}
if (key != 13)
arrow_control(size, 1, key, selected);
} while (key != 27);
SetConsoleTextAttribute(h, 15);
return -1;
}