-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMenu.cpp
More file actions
216 lines (203 loc) · 5.38 KB
/
CMenu.cpp
File metadata and controls
216 lines (203 loc) · 5.38 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// CMenu.cpp : Defines the entry point for the console application.
//
#include "Structures.cpp"
#include "Windows.h"
#include "locale.h"
#include "string.h"
#include "time.h"
#include "conio.h"
/*------------------------------------------------------\
|*Ñîçäàòåëü Íàçàð Óêîëîâ |
|*Ññûëêà íà ðåïðîçèòîðèé: https://github.com/pes7/CMenu |
|*Ññûëêà âê: https://vk.com/wowpes7 |
-------------------------------------------------------*/
HANDLE hStdout;
void Say(char*, Point*);
void MassageBox(char*, int, Point*);
void CrateBorder(Point*, Point*);
void SmartChoose(Menu*);
Menu *CMenu(Menu*, int);
void MenuFree(Menu*);
/*Êàñòîìíàÿ î÷èñòêà åêðàíà*/
void cls(HANDLE hConsole)
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) {
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
if (!FillConsoleOutputCharacter(hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten)) {
return;
}
if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) {
return;
}
if (!FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten)) {
return;
}
SetConsoleCursorPosition(hConsole, coordScreen);
}
/*Âûäåëåíèå ïàìÿòè íà Menu*/
Menu *CMenu(Menu *menu, int slots) {
menu = (Menu*)malloc(sizeof(Menu));
menu->binds = (Binds*)malloc(sizeof(Binds) * slots);
menu->properties.dbreak = *(Binds*)malloc(sizeof(Binds) * slots);
menu->text = (Word*)malloc(sizeof(Word) * slots);
menu->pointers = (int*)malloc(sizeof(int) * slots);
menu->properties.dbreak.binds = NULL;
menu->slots = 0;
return menu;
}
/*Èíèöèàëèçàöèÿ ìåíþ*/
void SmartChoose(Menu *menu) {
char i;
unsigned int d = 0, j, g;
Point p, p1;
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
do {
cls(hStdout);
/*Âûùåòêà ïîçèöèé îêàíòîâêè*/
p.x = menu->properties.size.width;
p.y = menu->properties.size.height;
p1.x = menu->properties.coords.x - 2;
p1.y = menu->properties.coords.y - 2;
CrateBorder(&p, &p1);
/*Âûùåòêà ïîçèöèè çàãîëîâêà*/
p.x = p.x / 2 - strlen(menu->properties.header) / 2 + menu->properties.coords.x - 2;
p.y = menu->properties.coords.y - 1;
Say(menu->properties.header, &p);
/*Âèçóàëèçóåì ïóíêòû*/
for (j = 0; j <= menu->slots; j++) {
p.x = 0 + menu->properties.coords.x;
p.y = 1 + j * (menu->properties.height + 3) + menu->properties.coords.y;
MassageBox(menu->text[j].str, menu->properties.height, &p);
}
/*----------------- */
i = _getch();
i = toupper(i);
//printf_s("You pressed: %c\n",i);
/*Ïðîâèðÿåì Bind êàæäåãî ïóíêòà*/
if (menu->slots > 0) {
for (j = 0; j <= menu->slots; j++) {
if (menu->binds[j].binds != NULL) {
for (g = 0; g < strlen(menu->binds[j].binds); g++) {
if (menu->binds[j].binds[g] == i && menu->binds[j].binds[g] != (int)NULL) {
cls(hStdout);
void(*does)() = (void*)menu->pointers[j];
if (*does != NULL) {
does();
}
}
}
}
}
}
/*Ïðîâåðêà íà ïåðåðûâàíèå åñëè òàêîâîå èìååòüñÿ*/
if (menu->properties.dbreak.binds != NULL) {
for (j = 0; j < strlen(menu->properties.dbreak.binds); j++) {
if (i == menu->properties.dbreak.binds[j]) {
d = 1;
}
}
}
} while (d == 0);
//MenuFree(menu);
}
/*Î÷èñòèòü ñòðóêòóðó Menu*/
void MenuFree(Menu *menu) {
free(menu->binds);
free(menu->pointers);
free(menu->text);
free(menu);
}
/*Âûâåñòè ëþáîé òåêñò íà åêðàí ïî êîîðäèíàòàõ*/
void Say(char* string, Point* p) {
HANDLE consoleoutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Coord;
unsigned int i;
for (i = 0; i < strlen(string); i++) {
Coord.X = i + p->x;
Coord.Y = p->y;
SetConsoleCursorPosition(consoleoutput, Coord);
printf_s("%c", string[i]);
}
}
/*Ñîçäàíèå îêàíòîâêè ïî øèðåíå è âûñîòå + ñòàðòîâîé êîîðäèíàòå*/
void CrateBorder(Point* p, Point* p1) {
HANDLE consoleoutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Coord;
int i, j;
for (i = 0; i < p->y; i++) {
for (j = 0; j <= p->x; j++) {
Coord.X = j + p1->x;
Coord.Y = i + p1->y;
SetConsoleCursorPosition(consoleoutput, Coord);
if (j == p->x && i == p->y - 1) {
printf_s("/");
}
if (j == 0 && i == p->y - 1) {
printf_s("‰");
}
if (j == 0 && i == 0) {
printf_s("ã");
}
if (j == p->x && i == 0) {
printf_s("¬");
}
if (j == 0 || j == p->x && i != 0 && i != p->y - 1) {
printf_s("¦");
}
if ((i == 0 || i == p->y - 1) && j != p->x) {
printf_s("-");
}
}
}
}
/*Âûâåñëè ñîîáùåíèå íà åêðàí ïî êîîðäèíàòå + âûñîòå îêàíòîâêè*/
void MassageBox(char* string, int sl, Point* p) {
HANDLE consoleoutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD Coord;
int er = 1, i;
unsigned int j;
for (i = 0; i < sl + 3; i++) {
for (j = 0; j <= strlen(string) + 1; j++) {
Coord.X = j + p->x;
Coord.Y = i + p->y;
SetConsoleCursorPosition(consoleoutput, Coord);
if (j == strlen(string) + 1 && i == sl + 2) {
printf_s("/");
}
if (j == 0 && i == sl + 2) {
printf_s("‰");
}
if (j == 0 && i == 0) {
printf_s("ã");
}
if (j == strlen(string) + 1 && i == 0) {
printf_s("¬");
}
if (j == 0 || j == strlen(string) + 1 && i != 0 && i != sl + 2) {
printf_s("¦");
}
else {
er = 0;
}
if ((i == 0 || i == sl + 2) && j != strlen(string) + 1) {
printf_s("-");
}
else {
er = 0;
}
if (er == 0 && i == (sl + 3) / 2) {
printf_s("%c", string[j - 1]);
}
}
}
}
#include "stdafx.h"