You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spOSMroute/gui/gui_list.c

129 lines
3.8 KiB

/* $Id: gui_list.c,v 1.9 2013/03/24 00:38:50 steffen Exp $ */
/***************************************************************************
* gui_list.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* main.c is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
/****************************************************************************
* list
*/
void gui_list_draw (GUIItem *item) {
struct line_style ls;
int max, i, x, y, j;
GUIList *list = NULL;
if (item == NULL) return;
else list = (GUIList *) item->data;
ls.width = 1.0;
if (currentwin->focus == item)
ls.c = ls.borderc = color[COLOR_white][3];
else
ls.c = ls.borderc = color[COLOR_white][2];
gfx_draw_line (currentwin->screen, item->x, item->y, item->x+item->w, item->y, 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, item->x+item->w, item->y+item->h, item->x, item->y+item->h, ls);
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x, item->y, ls);
/* find last max */
max = 0;
for (max = 0; list->data[max] != NULL; max++);
/* range to display */
i = max - item->h/16;
if (i < list->vs) list->vs = i;
if (list->vs < 0) list->vs = 0;
for (i = list->vs; i < (list->vs + item->h/16) && i < max; i++) {
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][2]);
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];
for (i = -1; i < 2; i += 2) {
if (i < 0) y = item->y + item->h;
else y = item->y;
x = item->x + item->w;
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 -j, y+ i*5, x-5, y, ls);
}
}
};
/*
* event handling
*/
int gui_list_event (GUIItem *item, GUIEvent *event) {
int x = event->mousepos.x - item->x;
int y = event->mousepos.y - item->y;
int i;
GUIList *list = NULL;
static GUIItem *olditem = NULL;
if (item == NULL) return 0;
else list = (GUIList *) item->data;
/* set focus */
if (event->event == EGUI_MOUSEPRESSED) {
olditem = item;
}
else if (event->event == EGUI_MOUSERELEASED && olditem == item) {
gui_set_focus (item);
if (y <= 5 && x >= item->w - 10) list->vs--;
else if (y >= item->h - 5 && x >= item->w - 10) list->vs++;
else { /* select entry */
i = (y-5)/16 + list->vs;
list->selected = i;
if (list->callback_selectitem) list->callback_selectitem (i);
}
}
currentwin->screen_changed = 1;
draw ();
return 1;
};
GUIItem *gui_list_new (int x, int y, int w, int h) {
GUIItem *item = (GUIItem *) ml_malloc (sizeof (GUIList) + sizeof (GUIItem) + POINTERALIGNMENT);
GUIList *list = (GUIList *) item->data;
item->type = GUI_LIST;
item->x = x;
item->y = y;
item->w = w;
item->h = h;
list->selected = -1;
list->vs = 0;
list->callback_selectitem = NULL;
return item;
};