-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.cpp
More file actions
83 lines (74 loc) · 1.21 KB
/
Input.cpp
File metadata and controls
83 lines (74 loc) · 1.21 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
#include "stdafx.h"
#include "Input.h"
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include "ConsoleApplication.h"
Input::Input()
{
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
}
void Input::UpdateKeyboard()
{
for (int i = 0; i < 255; ++i)
{
keyboard[i] = 0;
}
if (_kbhit())
{
char c = _getch();
if (c == 27)
{
App->appstate = INVALID;
}
if (c == 13)
{
istyping = !istyping;
}
else
{
if (!istyping)
{
keyboard[c] = 1;
}
else if (c == 8 && !typing.empty())
{
typing.pop_back();
}
else
{
typing += c;
typing.erase(std::remove(typing.begin(), typing.end(), '\0'), typing.end());
}
}
}
printf_s(" ");
if (typing.length() > 0)
{
for (int i = 0; i < typing.length(); ++i)
{
printf_s(" ");
}
SetColor(WHITEISH);
App->scene.BackgroundCursor.SetPosition(0, SCENE_HEIGHT + 1);
printf_s("%s", typing.c_str());
App->scene.BackgroundCursor.ResetPosition();
}
}
int Input::GetKeyState(int keycode)
{
return keyboard[keycode];
}
void Input::SetColor(color c, int other_color)
{
int new_color = 0;
if (c == OTHER)
{
new_color = other_color;
}
else
{
new_color = (int)c;
}
SetConsoleTextAttribute(hConsole,new_color);
}