-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.cpp
More file actions
238 lines (216 loc) · 5.47 KB
/
Copy pathinterface.cpp
File metadata and controls
238 lines (216 loc) · 5.47 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "Console.h"
#include "function.h"
#include "main.h"
#include <iostream>
#include <fstream>
#include <windows.h>
//Co dang dich hay khong
bool BTrangThaiDichTu = false;
#define MENU_TEXT_ROW ConsoleHeight/2
/*
* Black 0
* Blue 1
* Green 2
* Cyan 3
* Red 4
* Magenta 5
* Yellow 6
* White 7
* Gray 8
* Light Blue 9
* Light Green 10
* Light Cyan 11
* Light Red 12
* Light Magenta 13
* Light Yellow 14
* Bright White 15
*/
void veTieuDeTuDien()
{
short i;
for (i = 0; i < ConsoleWidth; ++i)
{
printf("%c", 45);
}
const char* STRTitle = "Dictionary";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRTitle) / 2), 1, 14, 0, STRTitle);
STRTitle = "Made by Group 11\n";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRTitle) / 2), 2, 14, 0, STRTitle);
setColor(7);
for (i = 0; i < ConsoleWidth; ++i)
{
printf("%c", 45);
}
}
void veMenuChinh(short SIndex)
{
//Cap nhat lai vi tri dang chon va tong muc cua menu
SViTriChon = SIndex;
STongMuc = 2;
//Ve menu
const char* STRNewGame = " Select language ";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW, 15, ((SIndex == 0) ? 2 : 0), STRNewGame);
STRNewGame = " Exit ";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW+1, 15, ((SIndex == 1) ? 2 : 0), STRNewGame);
}
void veMenuNgonNgu(short SIndex)
{
//Cap nhat lai vi tri dang chon va tong muc cua menu
SViTriChon = SIndex;
STongMuc = 4;
//Ve menu
const char* STRNewGame = "English to English";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW, 15, ((SIndex == 0) ? 2 : 0), STRNewGame);
STRNewGame = "English to Vietnamese";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW+1, 15, ((SIndex == 1) ? 2 : 0), STRNewGame);
STRNewGame = "Vietnamese to English";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW+2, 15, ((SIndex == 2) ? 2 : 0), STRNewGame);
STRNewGame = "Return";
setColorBGTextXY((ConsoleWidth / 2) - (strlen(STRNewGame) / 2), MENU_TEXT_ROW+3, 15, ((SIndex == 3) ? 2 : 0), STRNewGame);
}
/*Cac loai menu
* 1) Menu chinh
* 2) chon ngon ngu
* 3) Translate
*/
void xuLyPhim(KEY_EVENT_RECORD key)
{
if (key.bKeyDown) // Co nhan phim
{
switch (key.wVirtualKeyCode)
{
case VK_UP: // mui ten len
//std::cout << "Up" << std::endl;
switch (STrang)
{
case 1: //menu chinh
if (STongMuc == 2)
{
if (SViTriChon == 0)
SViTriChon = STongMuc - 1;
else
SViTriChon -= 1;
veMenuChinh(SViTriChon);
}
break;
case 2: //ngon ngu
if (STongMuc == 4)
{
if (SViTriChon == 0)
SViTriChon = STongMuc - 1;
else
SViTriChon -= 1;
veMenuNgonNgu(SViTriChon);
}
break;
case 3: //dich
if (BTrangThaiDichTu)
{
//insert translation initializing code here
}
break;
}
break;
case VK_DOWN: // mui ten xuong
//std::cout << "Down" << std::endl;
switch (STrang)
{
case 1: //menu chinh
if (STongMuc == 2)
{
if (SViTriChon == STongMuc - 1)
SViTriChon = 0;
else
SViTriChon += 1;
veMenuChinh(SViTriChon);
}
break;
case 2: //ngon ngu
if (STongMuc == 4)
{
if (SViTriChon == STongMuc - 1)
SViTriChon = 0;
else
SViTriChon += 1;
veMenuNgonNgu(SViTriChon);
}
break;
case 3: //dich
if (BTrangThaiDichTu)
{
//insert translation initializing code here
}
break;
}
break;
case VK_LEFT: // mui ten trai
//std::cout << "Left" << std::endl;
break;
case VK_RIGHT: // mui ten phai
//std::cout << "Right" << std::endl;
break;
case VK_RETURN: // phim enter
//std::cout << "Enter" << std::endl;
switch (STrang)
{
case 1: //menu chinh
if (SViTriChon == 0)
{
STrang = 2;
deleteRow(MENU_TEXT_ROW, 3);
veMenuNgonNgu(0);
}
else exit(0);
break;
case 2: //ngon ngu
switch (SViTriChon)
{
case 0:
STrang = 3;
deleteRow(MENU_TEXT_ROW, 3);
//Them code init dictionary o day
break;
case 1:
STrang = 3;
deleteRow(MENU_TEXT_ROW, 3);
//Them code init dictionary o day
break;
case 2:
STrang = 3;
deleteRow(MENU_TEXT_ROW, 3);
//Them code init dictionary o day
break;
case 3:
STrang = 1;
deleteRow(MENU_TEXT_ROW, 6);
veMenuChinh(0);
}
break;
}
}
}
}
void xuLySuKien()
{
while (1)
{
DWORD DWNumberOfEvents = 0; //Luu lai su kien tai
DWORD DWNumberOfEventsRead = 0; //Luu lai so luong su kien da duoc loc
HANDLE HConsoleInput = GetStdHandle(STD_INPUT_HANDLE); //Thiet bi dau vao
GetNumberOfConsoleInputEvents(HConsoleInput, &DWNumberOfEvents); // Dat su kien dau vao cua giao dien cho bien DWNumberOfEvents
if (DWNumberOfEvents)
{
INPUT_RECORD* IREventBuffer = new INPUT_RECORD[DWNumberOfEvents];//Con tro EventBuffer
ReadConsoleInput(HConsoleInput, IREventBuffer, DWNumberOfEvents, &DWNumberOfEventsRead); //Dat cac su kien duoc luu tru vao con tro
//chay vong lap de doc su kien
for (DWORD i = 0; i < DWNumberOfEvents; ++i)
{
if (IREventBuffer[i].EventType == KEY_EVENT) //Neu la su kien phim
{
xuLyPhim(IREventBuffer[i].Event.KeyEvent);
}
//else if (IREventBuffer[i].EventType == MOUSE_EVENT) // Su kien chuot
}
}
}
}