-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathConsole.cpp
101 lines (80 loc) · 1.53 KB
/
Console.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
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
#ifndef CONSOLE_H
#define CONSOLE_H
#include "Console.h"
#include <conio.h>
#include <stdio.h>
static HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
void gotoxy(int x, int y)
{
static HANDLE hStdout = NULL;
COORD wrapper;
wrapper.X = x;
wrapper.Y = y;
if(!hStdout)
{
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
SetConsoleCursorPosition(hStdout,wrapper);
}
void ClearScreen()
{
static CONSOLE_SCREEN_BUFFER_INFO csbi;
const COORD startCoords = {0,0};
DWORD dummy;
if(!hStdout)
{
GetConsoleScreenBufferInfo(hStdout,&csbi);
}
FillConsoleOutputCharacter(hStdout,
' ',
csbi.dwSize.X * csbi.dwSize.Y,
startCoords,
&dummy);
gotoxy(0,0);
}
void ResizeConsole(int x, int y)
{
COORD con_size = {x, y};
SetConsoleTextAttribute(hStdout, 0x07);
SetConsoleScreenBufferSize(hStdout, con_size);
}
void SetConsoleTextColor(const WORD c)
{
SetConsoleTextAttribute(hStdout, c);
}
int WaitForKey()
{
while(!_kbhit()) /* æäåì... */;
return _getche();
}
void WaitForSart(const char* str, int sec, int pos_x)
{
for(int i=sec*1000; i>0; i-=1000)
{
printf("%s: %d ", str, i/1000);
Sleep(1000);
COORD pos = {0, pos_x};
SetConsoleCursorPosition(hStdout, pos);
if(_kbhit())
{
_getche();
printf("\n");
break;
}
}
}
int PauseAndContinue()
{
if (_kbhit())
{
int c = _getche();
if (c != 'q' && c != 'Q')
{
WaitForKey();
}
else
return 0;
}
return 1;
}
#endif