Added functions for init and end, fixed bug with double-click

master
Aadhavan Srinivasan 2 years ago
parent e35c11c968
commit 7464adb129

@ -1,13 +1,16 @@
#include <ncurses.h>
#include <menu.h>
#include <stdlib.h>
int curs_init();
int curs_end(ITEM* item);
int main() {
initscr();
cbreak();
noecho();
curs_set(0);
keypad(stdscr,TRUE);
mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON1_CLICKED,NULL);
curs_init();
init_color();
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED,NULL);
MEVENT event;
int c;
ITEM* cur_item;
@ -30,7 +33,9 @@ int main() {
getmaxyx(stdscr,maxy,maxx);
WINDOW* subwindow = derwin(stdscr,1,maxx-1,1,1);
WINDOW* subwindow = derwin(stdscr,1,maxx-1,0,0);
keypad(subwindow,TRUE);
set_menu_sub(menu,subwindow);
@ -52,13 +57,22 @@ int main() {
menu_driver(menu,REQ_RIGHT_ITEM);
break;
case KEY_MOUSE:
menu_driver(menu,c);
if (getmouse(&event) == OK) {
if (event.bstate & BUTTON1_DOUBLE_CLICKED) {
cur_item = current_item(menu);
curs_end(cur_item);
return 0;
} else {
ungetmouse(&event);
menu_driver(menu,c);
break;
}
}
break;
case 10:
cur_item = current_item(menu);
endwin();
printf("You selected %s\n",item_name(cur_item));
curs_end(cur_item);
return 0;
@ -69,3 +83,19 @@ int main() {
endwin();
}
int curs_init() {
initscr();
cbreak();
noecho();
curs_set(0);
keypad(stdscr,TRUE);
return 0;
}
int curs_end(ITEM* item) {
endwin();
printf("You selected %s\n",item_name(item));
return 0;
}

Loading…
Cancel
Save