-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModePromptInteger.h
75 lines (66 loc) · 2.03 KB
/
ModePromptInteger.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
class ModePromptInteger : public ModeBase
{
public:
ModePromptInteger(Mode* base, Buffer& status, const COORD& pos, const wchar_t* p)
: ModeBase(base)
, buffer(status)
, pos(pos)
, p(p)
, len(wcslen(p))
, ret(0)
{
}
void Draw(Screen& screen, const EditScheme& scheme, bool focus) const
{
ModeBase::Draw(screen, scheme, false);
WORD wAttribute = 0;
scheme.get(EditScheme::STATUSFOCUS).apply(wAttribute);
buffer.clear(wAttribute, L' ');
WriteBegin(buffer, _COORD(1, 0), p);
WriteBegin(buffer, _COORD(static_cast<SHORT>(len + 2), 0), pk.c_str());
DrawBuffer(screen.hOut, buffer, pos);
if (focus)
{
SetCursorVisible(screen.hOut, screen.cci, TRUE);
COORD cursor = { static_cast<SHORT>(len + pk.size() + 2), 0 };
SetConsoleCursorPosition(screen.hOut, cursor + pos);
}
}
bool Do(const KEY_EVENT_RECORD& ker, Screen& /*screen*/, const EditScheme& /*scheme*/)
{
bool cont = true;
if (ker.bKeyDown)
{
if (ker.wVirtualKeyCode == VK_ESCAPE)
{
ret = 0;
cont = false;
}
else if (pk.size() < 5 && ker.wVirtualKeyCode >= L'0' && ker.wVirtualKeyCode <= L'9')
{
pk.push_back(ker.uChar.UnicodeChar);
}
else if (!pk.empty() && ker.wVirtualKeyCode == VK_BACK)
{
pk.pop_back();
}
else if (!pk.empty() && ker.wVirtualKeyCode == VK_RETURN)
{
ret = _wtoi(pk.c_str());
cont = false;
}
else
Beep();
};
return cont;
}
bool Do(const MOUSE_EVENT_RECORD& /*mer*/, Screen& /*screen*/, const EditScheme& /*scheme*/) { return true; }
int Ret() const { return ret; }
private:
Buffer& buffer;
const COORD& pos;
const wchar_t* p;
size_t len;
std::wstring pk;
int ret;
};