aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-04-18 22:23:13 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-04-18 22:23:13 +0300
commit3cf19b60cfdf860267a6c0eecebcb9d4fb8b7148 (patch)
treebccd39cb23d1520e347bb15f37a7b78d164530da
parent3ed7459c2edeb3a1bce55522ee68687f8b493b42 (diff)
downloadastar-3cf19b60cfdf860267a6c0eecebcb9d4fb8b7148.tar.xz
Implement holding mwheel to drag map around
-rw-r--r--main.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/main.c b/main.c
index 95ee0f6..20c3b57 100644
--- a/main.c
+++ b/main.c
@@ -27,6 +27,7 @@
void sigint_handler(int sig) {
(void)sig; /* We know it's a SIGINT */
+ printf("\033[?1003l\n"); /* Makes the terminal NOT report mouse movements */
endwin();
printf("Received SIGINT\n");
exit(1);
@@ -149,10 +150,36 @@ int main(int argc, char **argv) {
set_message("PID: %i", getpid());
#endif
+ MEVENT mevent;
+ //char mwheeldown = 0;
+ //mousemask(BUTTON3_PRESSED | BUTTON3_RELEASED | REPORT_MOUSE_POSITION, NULL);
+ mousemask(BUTTON2_PRESSED | BUTTON2_RELEASED, NULL);
+ mouseinterval(0);
+
while (1) {
draw_map(map, cell_costs, width, height, start_pos, end_pos, NULL, path, visited, NULL);
int c = getch();
switch (c) {
+ case KEY_MOUSE:
+ if (getmouse(&mevent) == OK && (mevent.bstate & BUTTON2_PRESSED)) {
+ /* FIXME: it's buggy. if we quickly click mwheel, it doesn't let go */
+ mousemask(BUTTON2_PRESSED | BUTTON2_RELEASED | REPORT_MOUSE_POSITION, NULL);
+ printf("\033[?1003h"); fflush(stdout); /* Makes the terminal report mouse movements */
+ int init_x = mevent.x,
+ init_y = mevent.y,
+ init_map_offset_x = map_offset_x,
+ init_map_offset_y = map_offset_y;
+ while ((c = getch()) == KEY_MOUSE \
+ && getmouse(&mevent) == OK && !(mevent.bstate & BUTTON2_RELEASED)) {
+ map_offset_y = init_map_offset_y + (mevent.y - init_y);
+ map_offset_x = init_map_offset_x + ((mevent.x - init_x) / 2 * 2);
+ draw_map(map, cell_costs, width, height, start_pos, end_pos, NULL, path, visited, NULL);
+ }
+ mousemask(BUTTON2_PRESSED | BUTTON2_RELEASED, NULL);
+ printf("\033[?1003l"); fflush(stdout); /* Makes the terminal NOT report mouse movements */
+ }
+ break;
+
case 'h': map_offset_x += 2; break;
case 'l': map_offset_x -= 2; break;
case 'j': map_offset_y -= 1; break;