diff options
| -rw-r--r-- | main.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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; |
