From 1711a426f84b59f6f0507401f857d2faf09ff622 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 20 Nov 2012 01:53:30 +0000 Subject: Added basic mouse wheel handling --- src/input_win.c | 2 +- src/windows.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/input_win.c b/src/input_win.c index 7d5a7485..fa61e1e3 100644 --- a/src/input_win.c +++ b/src/input_win.c @@ -367,7 +367,7 @@ static int _printable(const int ch) { return (ch != ERR && ch != '\n' && - ch != KEY_PPAGE && ch != KEY_NPAGE && + ch != KEY_PPAGE && ch != KEY_NPAGE && ch != KEY_MOUSE && ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) && ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) && ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) && diff --git a/src/windows.c b/src/windows.c index 1881f23a..e4718b5e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -107,6 +107,8 @@ gui_init(void) initscr(); cbreak(); keypad(stdscr, TRUE); + mousemask(ALL_MOUSE_EVENTS, NULL); + mouseinterval(5); if (has_colors()) { use_default_colors(); @@ -1761,8 +1763,37 @@ _win_handle_page(const int * const ch) int page_space = rows - 4; int *page_start = &_wins[_curr_prof_win].y_pos; + MEVENT mouse_event; + + if (*ch == KEY_MOUSE) { + if (getmouse(&mouse_event) == OK) { + if (mouse_event.bstate & BUTTON2_PRESSED) { // mouse wheel down + (*page_start)++; + + // only got half a screen, show full screen + if ((y - (*page_start)) < page_space) + *page_start = y - page_space; + + // went past end, show full screen + else if (*page_start >= y) + *page_start = y - page_space; + + _wins[_curr_prof_win].paged = 1; + dirty = TRUE; + } else if (mouse_event.bstate & BUTTON4_PRESSED) { // mouse wheel up + (*page_start)--; + + // went past beginning, show first page + if (*page_start < 0) + *page_start = 0; + + _wins[_curr_prof_win].paged = 1; + dirty = TRUE; + } + } + // page up - if (*ch == KEY_PPAGE) { + } else if (*ch == KEY_PPAGE) { *page_start -= page_space; // went past beginning, show first page -- cgit 1.4.1-2-gfad0