working on the new gui structure..

master
steffen 13 years ago
parent 26cbac58f3
commit d09e264688

@ -145,6 +145,7 @@ extern int gui_event (GUIEvent event);
extern void gui_window_new (GUIWindow *win, int w, int h, char *title); extern void gui_window_new (GUIWindow *win, int w, int h, char *title);
extern void gui_window_close (GUIWindow *win); extern void gui_window_close (GUIWindow *win);
extern void gui_window_item_add (GUIWindow *win, int type, void *item);
/* button functions */ /* button functions */
extern void gui_button_draw (GUIButton *button); extern void gui_button_draw (GUIButton *button);

@ -1,4 +1,4 @@
/* $Id: gui_window.c,v 1.2 2013/02/18 00:06:44 steffen Exp $ */ /* $Id: gui_window.c,v 1.3 2013/02/18 23:09:11 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui_window.c * gui_window.c
* *
@ -72,3 +72,30 @@ void gui_window_close (GUIWindow *win) {
win->w = 0; win->w = 0;
}; };
/*
* 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;
};

@ -65,32 +65,37 @@ void gui_buttons_show () {
btn_zoomin = gui_button_new (_("+"), 0, 0, 31, 31); btn_zoomin = gui_button_new (_("+"), 0, 0, 31, 31);
btn_zoomin->callback_clicked = (void*)gui_buttons_zoomin; btn_zoomin->callback_clicked = (void*)gui_buttons_zoomin;
btn_zoomin->callback_draw = (void*)gui_buttons_draw; btn_zoomin->callback_draw = (void*)gui_buttons_draw;
gui_window_item_add (&wbutton, GUI_BUTTON, btn_zoomin);
} }
if (btn_zoomout == NULL) { if (btn_zoomout == NULL) {
btn_zoomout = gui_button_new (_("-"), 40, 0, 31, 31); btn_zoomout = gui_button_new (_("-"), 40, 0, 31, 31);
btn_zoomout->callback_clicked = (void*)gui_buttons_zoomout; btn_zoomout->callback_clicked = (void*)gui_buttons_zoomout;
btn_zoomout->callback_draw = (void*)gui_buttons_draw; btn_zoomout->callback_draw = (void*)gui_buttons_draw;
gui_window_item_add (&wbutton, GUI_BUTTON, btn_zoomout);
} }
if (btn_gps == NULL) { if (btn_gps == NULL) {
btn_gps = gui_button_new (_("GPS"), 80, 0, 31, 31); btn_gps = gui_button_new (_("GPS"), 80, 0, 31, 31);
btn_gps->callback_clicked = (void*)gui_buttons_gps; btn_gps->callback_clicked = (void*)gui_buttons_gps;
btn_gps->callback_draw = (void*)gui_buttons_draw; btn_gps->callback_draw = (void*)gui_buttons_draw;
gui_window_item_add (&wbutton, GUI_BUTTON, btn_gps);
} }
if (btn_menu == NULL) { if (btn_menu == NULL) {
btn_menu = gui_button_new (_("M"), 120, 0, 31, 31); btn_menu = gui_button_new (_("M"), 120, 0, 31, 31);
btn_menu->callback_clicked = (void*)gui_buttons_menu; btn_menu->callback_clicked = (void*)gui_buttons_menu;
btn_menu->callback_draw = (void*)gui_buttons_draw; btn_menu->callback_draw = (void*)gui_buttons_draw;
gui_window_item_add (&wbutton, GUI_BUTTON, btn_menu);
} }
if (btn_fav == NULL) { if (btn_fav == NULL) {
btn_menu = gui_button_new (_("F"), 160, 0, 31, 31); btn_menu = gui_button_new (_("F"), 160, 0, 31, 31);
btn_menu->callback_clicked = (void*)gui_buttons_fav; btn_menu->callback_clicked = (void*)gui_buttons_fav;
btn_menu->callback_draw = (void*)gui_buttons_draw; btn_menu->callback_draw = (void*)gui_buttons_draw;
gui_window_item_add (&wbutton, GUI_BUTTON, btn_fav);
} }
gui_show (&wbutton); gui_show (&wbutton);
}; };

@ -28,17 +28,6 @@
#include "memoryleak.h" #include "memoryleak.h"
#include "system.h" #include "system.h"
enum {
FAVWIN_UNDEF = 0,
FAVWIN_LIST,
FAVWIN_ADD,
FAVWIN_REN,
FAVWIN_DEL,
FAVWIN_NAME,
FAVWIN_CLOSE
};
void gui_fav_close (); void gui_fav_close ();
void gui_fav_add (); void gui_fav_add ();
void gui_fav_del (); void gui_fav_del ();
@ -50,8 +39,12 @@ void gui_fav_selitem (int nr);
void gui_fav_fl_create (); void gui_fav_fl_create ();
void gui_fav_fl_free (); void gui_fav_fl_free ();
GUIList *fav_list = NULL; GUIList *favlist = NULL;
GUIEntry *fav_name = NULL; GUIEntry *faventry_name = NULL;
GUIButton *favbtn_close = NULL;
GUIButton *favbtn_add = NULL;
GUIButton *favbtn_ren = NULL;
GUIButton *favbtn_del = NULL;
char **fl_array = NULL; // array to all elements char **fl_array = NULL; // array to all elements
int fl_array_cnt = 0; int fl_array_cnt = 0;
@ -59,77 +52,6 @@ int fl_array_cnt = 0;
static GUIWindow wfav = {0}; static GUIWindow wfav = {0};
void gui_fav_show () {
int btn = 0;
fav_new ();
fav_load (fav_getfilename());
if (wfav.screen == NULL) gui_window_new (&wfav, 220, 240);
wfav.screen_changed = 1;
wfav.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1;
wfav.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
strncpy (wfav.title, _("Favorites"), GUI_TEXTLEN);
/* favotires buttons */
strncpy (wfav.buttons[btn].caption, _("Close"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_close;
wfav.buttons[btn].id = FAVWIN_CLOSE;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 5;
wfav.buttons[btn].y = 210;
strncpy (wfav.buttons[++btn].caption, _("Add"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_add;
wfav.buttons[btn].id = FAVWIN_ADD;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 5;
wfav.buttons[btn].y = 15;
strncpy (wfav.buttons[++btn].caption, _("Del"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_del;
wfav.buttons[btn].id = FAVWIN_DEL;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 70;
wfav.buttons[btn].y = 15;
strncpy (wfav.buttons[++btn].caption, _("Ren"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_ren;
wfav.buttons[btn].id = FAVWIN_REN;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 135;
wfav.buttons[btn].y = 15;
/* add the list */
btn = 0;
wfav.lists[btn].callback_selectitem = (void*)gui_fav_selitem;
wfav.lists[btn].id = FAVWIN_LIST;
wfav.lists[btn].w = 210;
wfav.lists[btn].h = 130;
wfav.lists[btn].x = 5;
wfav.lists[btn].y = 45;
fav_list = &wfav.lists[btn];
/* add entry */
btn = 0;
wfav.entrys[btn].id = FAVWIN_NAME;
wfav.entrys[btn].w = 210;
wfav.entrys[btn].h = 20;
wfav.entrys[btn].x = 5;
wfav.entrys[btn].y = 180;
fav_name = &wfav.entrys[btn];
fav_name->text[0] = 0;
gui_fav_refresh ();
gui_show (&wfav);
};
void gui_fav_close () { void gui_fav_close () {
gui_close (); gui_close ();
}; };
@ -137,9 +59,9 @@ void gui_fav_close () {
void gui_fav_add () { void gui_fav_add () {
struct favorite f; struct favorite f;
if (fav_name->text[0] == 0) return; if (faventry_name->text[0] == 0) return;
d_printf ("gui_fav_add: '%s'", fav_name->text); d_printf ("gui_fav_add: '%s'", faventry_name->text);
strncpy (f.name, fav_name->text, FAV_NAME_LEN); strncpy (f.name, faventry_name->text, FAV_NAME_LEN);
f.pos.lon = view_lon; f.pos.lon = view_lon;
f.pos.lat = view_lat; f.pos.lat = view_lat;
fav_add (-1, &f); fav_add (-1, &f);
@ -148,28 +70,28 @@ void gui_fav_add () {
void gui_fav_del () { void gui_fav_del () {
if (fav_list->selected < 0) return; if (favlist->selected < 0) return;
fav_del (fav_list->selected); fav_del (favlist->selected);
gui_fav_refresh (); gui_fav_refresh ();
}; };
void gui_fav_ren () { void gui_fav_ren () {
if (fav_list->selected < 0 || fav_name->text[0] == 0) return; if (favlist->selected < 0 || faventry_name->text[0] == 0) return;
strncpy (favorites[fav_list->selected].name, fav_name->text, FAV_NAME_LEN); strncpy (favorites[favlist->selected].name, faventry_name->text, FAV_NAME_LEN);
gui_fav_refresh (); gui_fav_refresh ();
}; };
void gui_fav_selitem (int nr) { void gui_fav_selitem (int nr) {
if (nr < favorites_cnt) { if (nr < favorites_cnt) {
strncpy (fav_name->text, favorites[nr].name, GUI_TEXTLEN); strncpy (faventry_name->text, favorites[nr].name, GUI_TEXTLEN);
view_lon = favorites[nr].pos.lon; view_lon = favorites[nr].pos.lon;
view_lat = favorites[nr].pos.lat; view_lat = favorites[nr].pos.lat;
gui_close (); gui_close ();
draw_del_flag (DRAW_GPSFOLLOW); draw_del_flag (DRAW_GPSFOLLOW);
} }
else fav_name->text[0] = 0; else faventry_name->text[0] = 0;
}; };
@ -181,8 +103,8 @@ void gui_fav_callback_close () {
void gui_fav_refresh () { void gui_fav_refresh () {
gui_fav_fl_create (); gui_fav_fl_create ();
fav_name->text[0] = 0; faventry_name->text[0] = 0;
fav_list->data = fl_array; favlist->data = fl_array;
}; };
@ -208,3 +130,52 @@ void gui_fav_fl_free () {
fl_array_cnt = 0; fl_array_cnt = 0;
}; };
void gui_fav_show () {
fav_new ();
fav_load (fav_getfilename());
if (wfav.screen == NULL) gui_window_new (&wfav, 220, 240, _("Favorites"));
wfav.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1;
wfav.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
/* favotires buttons */
if (favbtn_close == NULL) {
favbtn_close = gui_button_new (_("Close"), 5, 210, 60, 20);
favbtn_close->callback_clicked = (void*)gui_fav_close;
gui_window_item_add (&wfav, GUI_BUTTON, favbtn_close);
}
if (favbtn_add == NULL) {
favbtn_add = gui_button_new (_("Add"), 5, 15, 60, 20);
favbtn_add->callback_clicked = (void*)gui_fav_add;
gui_window_item_add (&wfav, GUI_BUTTON, favbtn_add);
}
if (favbtn_del == NULL) {
favbtn_del = gui_button_new (_("Del"), 70, 15, 60, 20);
favbtn_del->callback_clicked = (void*)gui_fav_ren;
gui_window_item_add (&wfav, GUI_BUTTON, favbtn_del);
}
if (favbtn_ren == NULL) {
favbtn_ren = gui_button_new (_("Ren"), 135, 15, 60, 20);
favbtn_ren->callback_clicked = (void*)gui_fav_ren;
gui_window_item_add (&wfav, GUI_BUTTON, favbtn_ren);
}
if (favlist == NULL) {
favlist = gui_list_new (5, 45, 210, 130);
favlist->callback_selectitem = (void*)gui_fav_selitem;
gui_window_item_add (&wfav, GUI_LIST, favlist);
}
if (faventry_name == NULL) {
faventry_name = gui_entry_new (NULL, 5, 180, 210, 20);
gui_window_item_add (&wfav, GUI_ENTRY, faventry_name);
}
gui_fav_refresh ();
gui_show (&wfav);
};

@ -1,3 +1,4 @@
/* $Id: gui_mainmenu.c,v 1.3 2013/02/18 23:09:40 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui_mainmenu.c * gui_mainmenu.c
* *
@ -58,12 +59,9 @@ static GUIWindow wmmenu = {0};
void gui_mainmenu_show () { void gui_mainmenu_show () {
int item = 0; int item = 0;
if (wmmenu.screen == NULL) guiwindow_new (&wmmenu, 175, 200); if (wmmenu.screen == NULL) gui_window_new (&wmmenu, 175, 200, _("OSMroute Menu"));
wmmenu.screen_changed = 1; wmmenu.screen_changed = 1;
// wmmenu.callback_close = (void*)gui_mainmenu_closecallback;
wmmenu.style = WGUI_S_VCENTER | WGUI_S_HCENTER; wmmenu.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
strncpy (wmmenu.title, _("OSMroute Menu"), GUI_TEXTLEN);
/* add buttons */ /* add buttons */
strncpy (wmmenu.buttons[item].caption, _("Close"), GUI_TEXTLEN); strncpy (wmmenu.buttons[item].caption, _("Close"), GUI_TEXTLEN);

Loading…
Cancel
Save