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_window.c

96 lines
2.5 KiB

/* $Id: gui_window.c,v 1.4 2013/02/21 23:07:19 steffen Exp $ */
/***************************************************************************
* gui_window.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"
/*
* reset all window data, do not allocate anything
*/
void gui_window_new (GUIWindow *win, int w, int h, char *title) {
int i;
for (i = 0; i < GUI_MAX_ITEM; i++) {
win->items[i].item = NULL;
win->items[i].type = GUI_NONE;
}
if (title == NULL) win->title[0] = 0;
else strncpy (win->title, title, GUI_TEXTLEN);
win->screen = NULL;
win->screen_changed = 1;
win->h = h;
win->w = w;
win->focus = NULL;
d_printf ("gui_window_new [%s] %p width:%d height:%d", title, win, w, h);
};
/*
* closes the window, but does not free the memory.
*/
void gui_window_close (GUIWindow *win) {
d_printf ("gui_window_close [%s] %p", win->title, win);
/* delete screen so we know it's disabled.. */
if (win->screen) gfx_img_free (win->screen);
win->screen = NULL;
win->screen_changed = 1;
if (currentwin == win) currentwin = NULL;
};
/*
* add pointer to item to the window data structure..
* the items will have to be hold inside the application
*/
void gui_window_item_add (GUIWindow *win, int type, void *item) {
int i, ifree = -1;
if (item == NULL || win == NULL) return;
for (i = 0; i < GUI_MAX_ITEM; i++) {
if (win->items[i].type == GUI_NONE && ifree == -1) ifree = i;
if (win->items[i].item == item) {
d_printf ("item already added to item list.");
ifree = i;
}
}
if (ifree == -1) {
d_printf ("no free item slot");
exit (1);
}
win->items[ifree].type = type;
win->items[ifree].item = item;
};