-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·72 lines (60 loc) · 1.59 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·72 lines (60 loc) · 1.59 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
#include <chrono>
#include <clocale>
#include <cstdlib>
#include <ncurses.h>
#include <utility>
#include <vector>
#define Framerate 40
int main(void) {
MEVENT mouseEvent;
int c;
std::vector<std::pair<int, int>> pixels;
std::chrono::milliseconds loopTime{1000 / Framerate};
std::chrono::time_point<std::chrono::system_clock> lastTime =
std::chrono::system_clock::now();
setlocale(LC_ALL, "");
initscr();
clear();
cbreak();
noecho();
curs_set(0);
keypad(stdscr, TRUE);
halfdelay(1);
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
while (1) {
if (std::chrono::system_clock::now().time_since_epoch() -
lastTime.time_since_epoch() >
loopTime) {
c = getch();
clear();
box(stdscr, 0, 0);
if (c == KEY_MOUSE) {
if (getmouse(&mouseEvent) == OK) {
if (mouseEvent.bstate & BUTTON1_PRESSED) {
pixels.push_back(std::make_pair(mouseEvent.y, mouseEvent.x));
}
}
}
for (auto i = pixels.begin(); i != pixels.end(); i++) {
mvaddwstr(i->first, i->second, L"\u2588");
if (i->first < LINES - 2) {
bool toInc = true;
for (auto j = pixels.begin(); j != pixels.end(); j++) {
if (i == j)
continue;
if ((j->second == i->second) && (i->first + 1 == j->first)) {
toInc = false;
}
}
if (toInc)
i->first++;
}
}
move(LINES, COLS);
refresh();
lastTime = std::chrono::system_clock::now();
}
}
endwin();
return 0;
}