File: [Platon] / tucniak / term / tt_menu.c (download)
Revision 1.1.1.1 (vendor branch), Fri Nov 11 16:08:27 2005 UTC (18 years, 5 months ago) by koli
Changes since 1.1: +0 -0
lines
Initial import
|
// Copyright (c) 2003 Juraj Kolesár (koli) <koli@koli.sk>
#include "tt.h"
/* {{{ horizontal *************************************************************/
int tt_menu_horizontal (POS point, T_CELLIST *items) {
int i = 0;
int Select = 0;
int Cursor = 1;
int Width;
int Length = g_list_length(g_list_first(items)) - 1;
bool End = false;
T_CELL *menu_item;
T_CELLIST * list = g_list_first(items);
while (list->next != NULL) { //Draws menu items
menu_item = list->data;
mvwprintw(GET_POS(point) + Cursor, menu_item->value);
Cursor += menu_item->width + 1;
if (list == items) Select = i;
list = g_list_next(list);
i++;
}
menu_item = items->data;
Cursor = t_cellist_width_sum(items, Select) - menu_item->width + Select;
do { //main cycle - key input handling
mvwprintw(GET_POS(point) + Cursor, ">");
mvwprintw(GET_POS(point) + Cursor + menu_item->width, "<");
wmove(GET_POS(point) + Cursor);
wrefresh(point.win);
mvwprintw(GET_POS(point) + Cursor, " ");
mvwprintw(GET_POS(point) + Cursor + menu_item->width, " ");
switch (getch()) {
case KEY_LEFT:
if (Select > 0) {
Select--;
items = g_list_previous(items);
menu_item = items->data;
Cursor -= (menu_item->width + 1);
} else {
items = g_list_last(items);
items = g_list_previous(items);
menu_item = items->data;
Select = Length - 1;
Cursor = t_cellist_width_sum(items, Select-1) + Select;
}
break;
case KEY_RIGHT:
if (Select < Length - 1) {
Select++;
Cursor += menu_item->width + 1;
items = g_list_next(items);
menu_item = items->data;
} else {
items = g_list_first(items);
menu_item = items->data;
Select = 0;
Cursor = 0;
}
break;
case KEY_DOWN: //CONFIRM
End = true;
return(Select);
break;
case 10: //what the hell is KEY_ENTER it doesn't work here
End = true;
return(Select);
break;
case LOCAL_ESCAPE_KEY:
End = true;
return(__TT_ESC);
break;
}
} while (!End);
return Select;
}
/* }}} */
/* {{{ vertical ***************************************************************/
int tt_menu_vertical (POS point, T_CELLIST *items, int Width) {
int i = 0;
int Select = 0;
int Length = g_list_length(g_list_first(items)) - 1;
bool End = false;
T_CELL *menu_item;
T_CELLIST *list = g_list_first(items);
while (list->next != NULL) { //Draws menu items
menu_item = list->data;
mvwprintw(point.win,point.y + i, point.x + 1, menu_item->value);
if (list == items) Select = i;
list = g_list_next(list);
i++;
}
menu_item = items->data;
do { //main cycle - key input handling
mvwprintw(point.win, point.y + Select, point.x, ">");
mvwprintw(point.win, point.y + Select, point.x + Width, "<");
wmove(point.win, point.y + Select, point.x);
wrefresh(point.win);
mvwprintw(point.win, point.y + Select, point.x, " ");
mvwprintw(point.win, point.y + Select, point.x + Width, " ");
switch (getch()) {
case KEY_UP:
if (Select > 0) {
Select--;
items = g_list_previous(items);
menu_item = items->data;
} else {
items = g_list_last(items);
items = g_list_previous(items);
menu_item = items->data;
Select = Length - 1;
}
break;
case KEY_DOWN:
if (Select < Length - 1) {
Select++;
items = g_list_next(items);
menu_item = items->data;
} else {
items = g_list_first(items);
menu_item = items->data;
Select = 0;
}
break;
case KEY_RIGHT: //CONFIRM
End = true;
return(Select);
break;
case KEY_LEFT: //ESCAPE
End = true;
return(__TT_ESC);
break;
case 10: //what the hell is KEY_ENTER it doesn't work here
End = true;
return(Select);
break;
case LOCAL_ESCAPE_KEY:
End = true;
return(__TT_ESC);
break;
}
} while (!End);
return Select;
}
/* }}} */
Platon Group <platon@platon.org> http://platon.org/
|