int scroll_offset;
bool focused;
WINDOW* menu_win;
- WINDOW* sub_win;
int max_height;
int max_width;
void* userdata;
return menu->menu_win;
}
-WINDOW*
-get_menu_subwin(Menu* menu)
-{
- return menu->sub_win;
-}
-
MenuItem*
get_menu_item(Menu* menu, int index)
{
/* create a subwin (also prob free old subwin?) */
menu->max_height = height-MENU_PAD_TOP-MENU_PAD_BOTTOM;
menu->max_width = width-MENU_PAD_LEFT-MENU_PAD_RIGHT;
- menu->sub_win = derwin(
- menu->menu_win,
- menu->max_height,
- menu->max_width,
- MENU_PAD_TOP,
- MENU_PAD_LEFT
- );
return 0;
}
/* move cursor to right spot */
ungetstr(menu->menu_items[insert_index]->title);
- mvwgetnstr(menu->sub_win,
+ mvwgetnstr(menu->menu_win,
insert_pos,
0,
temp,
int
render_menu(Menu* menu)
{
- /* draw outer menu (prob dont need this every render) */
- /* wclear(menu->menu_win); */
- int titlecolor;
- titlecolor = COLOR_PAIR((menu->focused == true) ? TS_MENU_SELECTED: TS_MENU_NONSELECTED);
- wattron(menu->menu_win, titlecolor);
- mvwprintw(menu->menu_win, 0, MENU_PAD_LEFT, menu->menu_name);
- wattroff(menu->menu_win, titlecolor);
-
- /* draw inner menu */
- wclear(menu->sub_win);
+ wclear(menu->menu_win);
/* calculate scroll */
int visible;
);
}
- /* char abuf[20]; */
- /* int y; */
- /* int x; */
- /* getmaxyx(menu->sub_win, y, x); */
- /* sprintf(abuf, "%d,%d,%d max:%d,%d", menu->selected_item, visible, menu->scroll_offset,y,x); */
- /* mvprintw(19, 27, abuf); */
-
+ /* render menu items */
int curline = 0;
for (int i = menu->scroll_offset; i < menu->menu_length; i++) {
curline += render_item(menu, i, curline);
}
- wrefresh(menu->sub_win);
+ wrefresh(menu->menu_win);
wrefresh(menu->menu_win);
return 0;
/* color selected item */
hlcolor = COLOR_PAIR((item_index == menu->selected_item && menu->focused == true) ? TS_SELECTED : TS_NONSELECTED);
- wattron(menu->sub_win, hlcolor);
- mvwprintw(menu->sub_win, start_y, 0, curitem->title);
- wattroff(menu->sub_win, hlcolor);
+ wattron(menu->menu_win, hlcolor);
+ mvwprintw(menu->menu_win, start_y, 0, curitem->title);
+ wattroff(menu->menu_win, hlcolor);
/* display number of items */
if (strlen(curitem->description) > 0) {
- mvwprintw(menu->sub_win, start_y+1, 0, curitem->description);
+ wattron(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT));
+ mvwprintw(menu->menu_win, start_y+1, 0, curitem->description);
+ wattroff(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT));
}
return item_height(curitem);
int maxheight;
int maxwidth; // unused
- getmaxyx(menu->sub_win, maxheight, maxwidth);
+ getmaxyx(menu->menu_win, maxheight, maxwidth);
int vis = 0;
int lines = 0;
int maxheight;
int maxwidth; // unused
- getmaxyx(menu->sub_win, maxheight, maxwidth);
+ getmaxyx(menu->menu_win, maxheight, maxwidth);
int vis = 0;
int lines = 0;
init_pair(TS_NONSELECTED, non_selected_color, COLOR_BLACK);
init_pair(TS_MENU_SELECTED, menu_selected_color, COLOR_BLACK);
init_pair(TS_MENU_NONSELECTED, menu_non_selected_color, COLOR_BLACK);
+ init_pair(TS_ITEMCOUNT, item_count_color, COLOR_BLACK);
return 0;
}
return newboard;
}
+int
+render_board(Board* board)
+{
+
+ return 0;
+}
+
int
set_selected_menu(BoardMenu* boardmenu, int index)
{
POPUP_BORDER,
POPUP_BORDER*2
);
- box(popup_win, 0, 0);
set_menu_win(new_popup_menu, popup_win);
set_menu_focus(new_popup_menu, 1);
popup_win = get_menu_win(popup_menu);
wclear(popup_win);
- box(popup_win, 0, 0);
-
render_menu(popup_menu);
wrefresh(popup_win);
void popup_renderstep(BoardMenu* boardmenu);
void save_to_file(char* filepath, BoardMenu* boardmenu);
+void exit_step(BoardMenu* boardmenu);
+
int
main(int argc, char** argv)
{
normal_renderstep(boardmenu);
int ch;
- while ((ch = getch()) != BINDING_QUIT) {
+ while (1) {
+
+ ch = getch();
if (boardmenu->popup_open == 0) {
normal_handleinput(boardmenu, ch);
/* save on exit - this causes weird stuff to happen, maybe it's not given enough time to write before program exits? */
/* save_to_file(boardfile_name, boardmenu); */
- exit_tscurses();
return 0;
}
case BINDING_WRITE:
save_to_file(boardfile_name, boardmenu);
break;
+ case BINDING_QUIT:
+ exit_step(boardmenu);
+ break;
case KEY_RESIZE:
/* ; */
/* int y, x; */
case BINDING_SCROLL_DOWN:
menu_driver(popup_menu, MENU_DOWN);
break;
+ case BINDING_QUIT:
+ boardmenu->popup_open = 0;
+ break;
}
}
begin_write(filepath, writeboard);
free_board(writeboard);
}
+
+void
+exit_step(BoardMenu* boardmenu)
+{
+ exit_tscurses();
+ exit(0);
+}