|
|
|
@ -1,4 +1,4 @@
|
|
|
|
/* $Id: gui_list.c,v 1.3 2013/02/21 23:07:19 steffen Exp $ */
|
|
|
|
/* $Id: gui_list.c,v 1.4 2013/02/26 22:13:04 steffen Exp $ */
|
|
|
|
/***************************************************************************
|
|
|
|
/***************************************************************************
|
|
|
|
* gui_list.c
|
|
|
|
* gui_list.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -32,38 +32,43 @@
|
|
|
|
/****************************************************************************
|
|
|
|
/****************************************************************************
|
|
|
|
* list
|
|
|
|
* list
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void gui_list_draw (GUIList *list) {
|
|
|
|
void gui_list_draw (GUIItem *item) {
|
|
|
|
struct line_style ls;
|
|
|
|
struct line_style ls;
|
|
|
|
int max, i, x, y, j;
|
|
|
|
int max, i, x, y, j;
|
|
|
|
|
|
|
|
GUIList *list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item == NULL) return;
|
|
|
|
|
|
|
|
else list = (GUIList *) item->data;
|
|
|
|
|
|
|
|
|
|
|
|
ls.width = 1.0;
|
|
|
|
ls.width = 1.0;
|
|
|
|
if (currentwin->focus != NULL && currentwin->focus->item == (void *) list)
|
|
|
|
if (currentwin->focus == item)
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
|
|
else
|
|
|
|
else
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][2];
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][2];
|
|
|
|
gfx_draw_line (currentwin->screen, list->x, list->y, list->x+list->w, list->y, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, item->x, item->y, item->x+item->w, item->y, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, list->x+list->w, list->y, list->x+list->w, list->y+list->h, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, item->x+item->w, item->y, item->x+item->w, item->y+item->h, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, list->x+list->w, list->y+list->h, list->x, list->y+list->h, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, item->x+item->w, item->y+item->h, item->x, item->y+item->h, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, list->x, list->y+list->h, list->x, list->y, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x, item->y, ls);
|
|
|
|
|
|
|
|
|
|
|
|
if (list->data == NULL) return;
|
|
|
|
/* find last max */
|
|
|
|
for (max = 0; list->data[max] != NULL; max++);
|
|
|
|
max = 0;
|
|
|
|
|
|
|
|
// for (max = 0; list->data[max] != NULL; max++);
|
|
|
|
|
|
|
|
|
|
|
|
/* range to display */
|
|
|
|
/* range to display */
|
|
|
|
i = max - list->h/16;
|
|
|
|
i = max - item->h/16;
|
|
|
|
if (i < list->vs) list->vs = i;
|
|
|
|
if (i < list->vs) list->vs = i;
|
|
|
|
if (list->vs < 0) list->vs = 0;
|
|
|
|
if (list->vs < 0) list->vs = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = list->vs; i < (list->vs + list->h/16) && i < max; i++) {
|
|
|
|
for (i = list->vs; i < (list->vs + item->h/16) && i < max; i++) {
|
|
|
|
if (i == list->selected) gfx_draw_text (currentwin->screen, list->x + 5, list->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_red][1]);
|
|
|
|
if (i == list->selected) gfx_draw_text (currentwin->screen, item->x + 5, item->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_red][1]);
|
|
|
|
else gfx_draw_text (currentwin->screen, list->x + 5, list->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_white][3]);
|
|
|
|
else gfx_draw_text (currentwin->screen, item->x + 5, item->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_white][3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
|
|
for (i = -1; i < 2; i += 2) {
|
|
|
|
for (i = -1; i < 2; i += 2) {
|
|
|
|
if (i < 0) y = list->y + list->h;
|
|
|
|
if (i < 0) y = item->y + item->h;
|
|
|
|
else y = list->y;
|
|
|
|
else y = item->y;
|
|
|
|
x = list->x + list->w;
|
|
|
|
x = item->x + item->w;
|
|
|
|
for (j = 0; j <= 5; j++) {
|
|
|
|
for (j = 0; j <= 5; j++) {
|
|
|
|
gfx_draw_line (currentwin->screen, x - 5, y, x-j, y + i*5, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, x - 5, y, x-j, y + i*5, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, x - 5 -j, y+ i*5, x-5, y, ls);
|
|
|
|
gfx_draw_line (currentwin->screen, x - 5 -j, y+ i*5, x-5, y, ls);
|
|
|
|
@ -75,17 +80,21 @@ void gui_list_draw (GUIList *list) {
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* event handling
|
|
|
|
* event handling
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void gui_list_event (GUIList *list, GUIEvent *event) {
|
|
|
|
void gui_list_event (GUIItem *item, GUIEvent *event) {
|
|
|
|
int x = event->mousepos.x - list->x;
|
|
|
|
int x = event->mousepos.x - item->x;
|
|
|
|
int y = event->mousepos.y - list->y;
|
|
|
|
int y = event->mousepos.y - item->y;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GUIList *list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (item == NULL) return;
|
|
|
|
|
|
|
|
else list = (GUIList *) item->data;
|
|
|
|
|
|
|
|
|
|
|
|
/* set focus */
|
|
|
|
/* set focus */
|
|
|
|
if (event->event == EGUI_MOUSERELEASED && x >= 0 && x <= list->w && y >= 0 && y <= list->h) {
|
|
|
|
if (event->event == EGUI_MOUSERELEASED && x >= 0 && x <= item->w && y >= 0 && y <= item->h) {
|
|
|
|
currentwin->focus = (void *) list;
|
|
|
|
currentwin->focus = (void *) item;
|
|
|
|
|
|
|
|
|
|
|
|
if (y <= 5 && x >= list->w - 10) list->vs--;
|
|
|
|
if (y <= 5 && x >= item->w - 10) list->vs--;
|
|
|
|
else if (y >= list->h - 5 && x >= list->w - 10) list->vs++;
|
|
|
|
else if (y >= item->h - 5 && x >= item->w - 10) list->vs++;
|
|
|
|
else { /* select entry */
|
|
|
|
else { /* select entry */
|
|
|
|
i = (y-5)/16 + list->vs;
|
|
|
|
i = (y-5)/16 + list->vs;
|
|
|
|
list->selected = i;
|
|
|
|
list->selected = i;
|
|
|
|
@ -98,16 +107,16 @@ void gui_list_event (GUIList *list, GUIEvent *event) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GUIList *gui_list_new (int x, int y, int w, int h) {
|
|
|
|
GUIItem *gui_list_new (int x, int y, int w, int h) {
|
|
|
|
GUIList *item = (GUIList*) ml_malloc (sizeof (GUIList));
|
|
|
|
GUIItem *item = (GUIItem *) ml_malloc (sizeof (GUIList) + sizeof (GUIItem) + POINTERALIGNMENT);
|
|
|
|
|
|
|
|
GUIList *list = (GUIList *) item->data;
|
|
|
|
|
|
|
|
|
|
|
|
item->x = x;
|
|
|
|
item->x = x;
|
|
|
|
item->y = y;
|
|
|
|
item->y = y;
|
|
|
|
item->w = w;
|
|
|
|
item->w = w;
|
|
|
|
item->h = h;
|
|
|
|
item->h = h;
|
|
|
|
item->data = NULL;
|
|
|
|
list->selected = -1;
|
|
|
|
item->selected = -1;
|
|
|
|
list->vs = 0;
|
|
|
|
item->vs = 0;
|
|
|
|
list->callback_selectitem = NULL;
|
|
|
|
item->callback_selectitem = NULL;
|
|
|
|
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|