gui changes... still needs more work..

master
steffen 13 years ago
parent 475db83d4c
commit 26cbac58f3

@ -1,4 +1,4 @@
/* $Id: gui.c,v 1.4 2013/02/17 00:52:20 steffen Exp $ */ /* $Id: gui.c,v 1.5 2013/02/18 00:06:44 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui.c * gui.c
* *
@ -83,24 +83,31 @@ void gui_draw () {
draw_polygonfinish (currentwin->screen, ls, color[COLOR_white][0], 1); draw_polygonfinish (currentwin->screen, ls, color[COLOR_white][0], 1);
gfx_draw_text (currentwin->screen, 4, 0, currentwin->title, &color[COLOR_white][3]); gfx_draw_text (currentwin->screen, 4, 0, currentwin->title, &color[COLOR_white][3]);
} }
for (i = 0; i < GUI_WIN_BUTTONS; i++) if (currentwin->buttons[i].id != 0) { /* draw items.. */
if (currentwin->buttons[i].callback_draw != NULL) for (i = 0; i < GUI_MAX_ITEM; i++)
currentwin->buttons[i].callback_draw (&currentwin->buttons[i]); switch (currentwin->items[i].type) {
else gui_button_draw (&currentwin->buttons[i]); case (GUI_BUTTON): {
} GUIButton *button = (GUIButton *) currentwin->items[i].item;
for (i = 0; i < GUI_WIN_LABELS; i++) if (currentwin->labels[i].id != 0) { if (button->callback_draw != NULL) button->callback_draw (button);
gui_label_draw (&currentwin->labels[i]); else gui_button_draw (button);
} }
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->entrys[i].id != 0) { break;
gui_entry_draw (&currentwin->entrys[i]); case (GUI_LABEL):
} gui_label_draw ((GUILabel*)currentwin->items[i].item);
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->lists[i].id != 0) { break;
gui_list_draw (&currentwin->lists[i]); case (GUI_ENTRY):
} gui_entry_draw ((GUIEntry*)currentwin->items[i].item);
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) if (currentwin->checkboxes[i].id != 0) { break;
// gui_draw_label (&currentwin->labels[i]); case (GUI_LIST):
} gui_list_draw ((GUIList*)currentwin->items[i].item);
break;
// case (GUI_ENTRY):
// gui_entry_draw ((GUIEntry*)currentwin->items[i].item);
// break;
default:
break;
}
currentwin->screen_changed = 0; currentwin->screen_changed = 0;
} }
@ -140,59 +147,66 @@ int gui_event (GUIEvent event) {
if (event_called) return 1; if (event_called) return 1;
event_called = 1; event_called = 1;
for (i = 0; i < GUI_WIN_BUTTONS; i++) { for (i = 0; i < GUI_MAX_ITEM; i++)
// if (currentwin->buttons[i].id != 0) switch (currentwin->items[i].type) {
// d_printf ("%d %d,%d %d,%d - %d,%d", currentwin->buttons[i].id, currentwin->buttons[i].x, currentwin->buttons[i].y, currentwin->buttons[i].w, currentwin->buttons[i].h, event.mousepos.x, event.mousepos.y); case (GUI_BUTTON): {
if (currentwin->buttons[i].id != 0 GUIButton *button = (GUIButton *) currentwin->items[i].item;
&& currentwin->buttons[i].x <= event.mousepos.x && currentwin->buttons[i].x+currentwin->buttons[i].w >= event.mousepos.x if (button->x <= event.mousepos.x &&
&& currentwin->buttons[i].y <= event.mousepos.y && currentwin->buttons[i].y+currentwin->buttons[i].h >= event.mousepos.y) { button->x+button->w >= event.mousepos.x &&
if (currentwin->buttons[i].callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) { button->y <= event.mousepos.y &&
d_printf ("GUI BUTTON PRESSED: %d:%s", currentwin->buttons[i].id, currentwin->buttons[i].caption); button->y+button->h >= event.mousepos.y) {
currentwin->buttons[i].callback_clicked (event.mousepos.x-currentwin->buttons[i].x, event.mousepos.y-currentwin->buttons[i].y); if (button->callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) {
event_called = 0; d_printf ("GUI BUTTON PRESSED: %s", button->caption);
currentwin->screen_changed = 1; button->callback_clicked (event.mousepos.x-button->x, event.mousepos.y-button->y);
return 1; currentwin->screen_changed = 1;
event_called = 0;
return 1;
}
}
} }
break;
case (GUI_LABEL):
break;
case (GUI_ENTRY): {
GUIEntry *entry = (GUIEntry*) currentwin->items[i].item;
if (entry->x <= event.mousepos.x &&
entry->x+entry->w >= event.mousepos.x &&
entry->y <= event.mousepos.y &&
entry->y+entry->h >= event.mousepos.y) {
gui_entry_event (entry, &event);
event_called = 0;
return 1;
}
}
break;
case (GUI_LIST): {
GUIList *list = (GUIList *) currentwin->items[i].item;
if (list->x <= event.mousepos.x &&
list->x+list->w >= event.mousepos.x &&
list->y <= event.mousepos.y &&
list->y+list->h >= event.mousepos.y) {
gui_list_event (list, &event);
event_called = 0;
return 1;
}
} }
}
for (i = 0; i < GUI_WIN_LABELS; i++) if (currentwin->labels[i].id != 0) {
// gui_event_label (&currentwin->labels[i]);
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->entrys[i].id != 0) {
if (currentwin->entrys[i].id != 0
&& currentwin->entrys[i].x <= event.mousepos.x && currentwin->entrys[i].x+currentwin->entrys[i].w >= event.mousepos.x
&& currentwin->entrys[i].y <= event.mousepos.y && currentwin->entrys[i].y+currentwin->entrys[i].h >= event.mousepos.y) {
gui_entry_event (&currentwin->entrys[i], &event);
event_called = 0;
return 1;
} }
}
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->lists[i].id != 0) {
if (currentwin->lists[i].x <= event.mousepos.x && currentwin->lists[i].x+currentwin->lists[i].w >= event.mousepos.x
&& currentwin->lists[i].y <= event.mousepos.y && currentwin->lists[i].y+currentwin->lists[i].h >= event.mousepos.y) {
gui_list_event (&currentwin->lists[i], &event);
event_called = 0;
return 1;
}
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) if (currentwin->checkboxes[i].id != 0) {
// gui_event_label (&currentwin->labels[i]);
}
if (currentwin->focus != NULL) { if (currentwin->focus != NULL)
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->focus == &currentwin->entrys[i]) { switch (currentwin->focus->type) {
gui_entry_event (&currentwin->entrys[i], &event); case (GUI_BUTTON):
event_called = 0; gui_entry_event ((GUIEntry*)currentwin->focus->item, &event);
return 1; break;
case (GUI_LIST):
gui_list_event ((GUIList*)currentwin->focus->item, &event);
break;
default:
break;
} }
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->focus == &currentwin->lists[i]) {
gui_list_event (&currentwin->lists[i], &event);
event_called = 0;
return 1;
}
}
event_called = 0; event_called = 0;
return 1; return 1;

@ -71,7 +71,6 @@ struct _GUIEvent_ {
struct _GUIButton_ { struct _GUIButton_ {
int x, y, w, h; int x, y, w, h;
int id;
char caption[GUI_TEXTLEN]; char caption[GUI_TEXTLEN];
struct color *col; struct color *col;
struct color *textcol; struct color *textcol;
@ -82,7 +81,6 @@ struct _GUIButton_ {
struct _GUIList_ { struct _GUIList_ {
int x, y, w, h; int x, y, w, h;
int id;
char **data; char **data;
int vs; // first element to draw int vs; // first element to draw
int selected; int selected;
@ -92,7 +90,6 @@ struct _GUIList_ {
struct { struct {
int x, y; int x, y;
int id;
char text[GUI_TEXTLEN]; char text[GUI_TEXTLEN];
struct color *textcol; struct color *textcol;
} typedef GUILabel; } typedef GUILabel;
@ -100,7 +97,6 @@ struct {
struct { struct {
int x, y, w, h; int x, y, w, h;
int id;
char text[GUI_TEXTLEN]; char text[GUI_TEXTLEN];
int curpos; int curpos;
int overwrite; int overwrite;
@ -111,7 +107,6 @@ struct {
struct { struct {
int x, y, w, h; int x, y, w, h;
int id;
char text[GUI_TEXTLEN]; char text[GUI_TEXTLEN];
int checked; int checked;
void (*callback_changed) (); void (*callback_changed) ();
@ -138,7 +133,7 @@ struct _GUIWindow_ {
int style; int style;
GUIItem items[GUI_MAX_ITEM]; GUIItem items[GUI_MAX_ITEM];
void *focus; GUIItem *focus;
} typedef GUIWindow; } typedef GUIWindow;
extern GUIWindow *currentwin; extern GUIWindow *currentwin;
@ -153,19 +148,22 @@ extern void gui_window_close (GUIWindow *win);
/* button functions */ /* button functions */
extern void gui_button_draw (GUIButton *button); extern void gui_button_draw (GUIButton *button);
extern GUIButton *gui_button_new (char *name, int x, int y, int w, int h);
/* label functions */ /* label functions */
extern void gui_label_draw (GUILabel *label); extern void gui_label_draw (GUILabel *label);
extern GUILabel *gui_label_new (char *name, int x, int y);
/* entry functions */ /* entry functions */
extern void gui_entry_draw (GUIEntry *entry); extern void gui_entry_draw (GUIEntry *entry);
extern void gui_entry_event (GUIEntry *entry, GUIEvent *event); extern void gui_entry_event (GUIEntry *entry, GUIEvent *event);
extern GUIEntry *gui_entry_new (char *text, int x, int y, int w, int h);
/* list functions */ /* list functions */
extern void gui_list_draw (GUIList *list); extern void gui_list_draw (GUIList *list);
extern void gui_list_event (GUIList *list, GUIEvent *event); extern void gui_list_event (GUIList *list, GUIEvent *event);
extern void gui_list_setselect (GUIList *list); extern void gui_list_setselect (GUIList *list);
extern GUIList *gui_list_new (int x, int y, int w, int h);
/************************************************************************** /**************************************************************************
* gui windows * gui windows

@ -1,4 +1,4 @@
/* $Id: gui_list.c,v 1.1 2013/02/17 00:52:20 steffen Exp $ */ /* $Id: gui_list.c,v 1.2 2013/02/18 00:06:44 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui_list.c * gui_list.c
* *
@ -37,7 +37,7 @@ void gui_list_draw (GUIList *list) {
int max, i, x, y, j; int max, i, x, y, j;
ls.width = 1.0; ls.width = 1.0;
if (currentwin->focus == list) if (currentwin->focus != NULL && currentwin->focus->item == (void *) list)
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];

@ -1,4 +1,4 @@
/* $Id: gui_window.c,v 1.1 2013/02/17 00:52:20 steffen Exp $ */ /* $Id: gui_window.c,v 1.2 2013/02/18 00:06:44 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui_window.c * gui_window.c
* *
@ -36,8 +36,8 @@ void gui_window_new (GUIWindow *win, int w, int h, char *title) {
int i; int i;
for (i = 0; i < GUI_MAX_ITEM; i++) { for (i = 0; i < GUI_MAX_ITEM; i++) {
win->items[i]->item = NULL; win->items[i].item = NULL;
win->items[i]->type = GUI_NONE; win->items[i].type = GUI_NONE;
} }
strncpy (win->title, title, GUI_TEXTLEN); strncpy (win->title, title, GUI_TEXTLEN);
@ -58,27 +58,9 @@ void gui_window_new (GUIWindow *win, int w, int h, char *title) {
void gui_window_close (GUIWindow *win) { void gui_window_close (GUIWindow *win) {
int i; int i;
for (i = 0; i < GUI_WIN_BUTTONS; i++) { for (i = 0; i < GUI_MAX_ITEM; i++) {
win->buttons[i].caption[0] = '\0'; win->items[i].type = GUI_NONE;
win->buttons[i].id = 0; win->items[i].item = NULL;
win->buttons[i].callback_clicked = NULL;
win->buttons[i].callback_draw = NULL;
}
for (i = 0; i < GUI_WIN_LABELS; i++) {
win->labels[i].text[0] = '\0';
win->labels[i].textcol = &color[COLOR_white][2];
win->labels[i].id = 0;
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) {
win->entrys[i].text[0] = '\0';
win->entrys[i].callback_enter = NULL;
win->entrys[i].callback_changed = NULL;
win->entrys[i].id = 0;
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) {
win->checkboxes[i].text[0] = '\0';
win->checkboxes[i].callback_changed = NULL;
win->checkboxes[i].id = 0;
} }
win->title[0] = 0; win->title[0] = 0;

@ -38,6 +38,11 @@ enum {
static GUIWindow wbutton = {0}; static GUIWindow wbutton = {0};
static GUIButton *btn_zoomin = NULL,
*btn_zoomout = NULL,
*btn_gps = NULL,
*btn_menu = NULL,
*btn_fav = NULL;
void gui_buttons_closecallback (); void gui_buttons_closecallback ();
void gui_buttons_draw (GUIButton *btn); void gui_buttons_draw (GUIButton *btn);
void gui_buttons_zoomin(); void gui_buttons_zoomin();
@ -49,61 +54,42 @@ void gui_buttons_fav();
void gui_buttons_show () { void gui_buttons_show () {
d_printf ("GUI: buttons show screen:%p", wbutton.screen); d_printf ("GUI: buttons show screen:%p", wbutton.screen);
if (wbutton.screen == NULL) guiwindow_new (&wbutton, 192, 32); if (wbutton.screen == NULL) gui_window_new (&wbutton, 192, 32, NULL);
wbutton.screen_changed = 1; wbutton.screen_changed = 1;
wbutton.callback_close = (void*)gui_buttons_closecallback; wbutton.callback_close = (void*)gui_buttons_closecallback;
wbutton.style = WGUI_S_VCENTER | WGUI_S_HTOP; wbutton.style = WGUI_S_VCENTER | WGUI_S_HTOP;
/* add buttons */ /* add buttons */
strncpy (wbutton.buttons[0].caption, _("+"), GUI_TEXTLEN); if (btn_zoomin == NULL) {
wbutton.buttons[0].callback_clicked = (void*)gui_buttons_zoomin; btn_zoomin = gui_button_new (_("+"), 0, 0, 31, 31);
wbutton.buttons[0].callback_draw = (void*)gui_buttons_draw; btn_zoomin->callback_clicked = (void*)gui_buttons_zoomin;
wbutton.buttons[0].id = BTNWIN_ZIN; btn_zoomin->callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[0].w = 31; }
wbutton.buttons[0].h = 31;
wbutton.buttons[0].x = 0;
wbutton.buttons[0].y = 0;
strncpy (wbutton.buttons[1].caption, _("-"), GUI_TEXTLEN);
wbutton.buttons[1].callback_clicked = (void*)gui_buttons_zoomout;
wbutton.buttons[1].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[1].id = BTNWIN_ZOUT;
wbutton.buttons[1].w = 31;
wbutton.buttons[1].h = 31;
wbutton.buttons[1].x = 40;
wbutton.buttons[1].y = 0;
strncpy (wbutton.buttons[2].caption, _("GPS"), GUI_TEXTLEN);
wbutton.buttons[2].callback_clicked = (void*)gui_buttons_gps;
wbutton.buttons[2].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[2].id = BTNWIN_GPS;
wbutton.buttons[2].w = 31;
wbutton.buttons[2].h = 31;
wbutton.buttons[2].x = 80;
wbutton.buttons[2].y = 0;
strncpy (wbutton.buttons[3].caption, _("M"), GUI_TEXTLEN);
wbutton.buttons[3].callback_clicked = (void*)gui_buttons_menu;
wbutton.buttons[3].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[3].id = BTNWIN_MENU;
wbutton.buttons[3].w = 31;
wbutton.buttons[3].h = 31;
wbutton.buttons[3].x = 120;
wbutton.buttons[3].y = 0;
strncpy (wbutton.buttons[4].caption, _("Fav"), GUI_TEXTLEN); if (btn_zoomout == NULL) {
wbutton.buttons[4].callback_clicked = (void*)gui_buttons_fav; btn_zoomout = gui_button_new (_("-"), 40, 0, 31, 31);
wbutton.buttons[4].callback_draw = (void*)gui_buttons_draw; btn_zoomout->callback_clicked = (void*)gui_buttons_zoomout;
wbutton.buttons[4].id = BTNWIN_FAV; btn_zoomout->callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[4].w = 31; }
wbutton.buttons[4].h = 31;
wbutton.buttons[4].x = 160; if (btn_gps == NULL) {
wbutton.buttons[4].y = 0; btn_gps = gui_button_new (_("GPS"), 80, 0, 31, 31);
btn_gps->callback_clicked = (void*)gui_buttons_gps;
btn_gps->callback_draw = (void*)gui_buttons_draw;
}
if (btn_menu == NULL) {
btn_menu = gui_button_new (_("M"), 120, 0, 31, 31);
btn_menu->callback_clicked = (void*)gui_buttons_menu;
btn_menu->callback_draw = (void*)gui_buttons_draw;
}
if (btn_fav == NULL) {
btn_menu = gui_button_new (_("F"), 160, 0, 31, 31);
btn_menu->callback_clicked = (void*)gui_buttons_fav;
btn_menu->callback_draw = (void*)gui_buttons_draw;
}
gui_show (&wbutton); gui_show (&wbutton);
}; };
@ -112,14 +98,14 @@ void gui_buttons_show () {
void gui_buttons_closecallback () { void gui_buttons_closecallback () {
d_printf ("GUI: buttons close"); d_printf ("GUI: buttons close");
guiwindow_close (&wbutton); gui_window_close (&wbutton);
}; };
void gui_buttons_draw (GUIButton *btn) { void gui_buttons_draw (GUIButton *btn) {
int j; int j;
if (btn->id == BTNWIN_GPS) { if (btn == btn_gps) {
j = gps_isrunning (); j = gps_isrunning ();
if (j == 0) btn->col = &color[COLOR_white][2]; if (j == 0) btn->col = &color[COLOR_white][2];
else if (j < 0) btn->col = &color[COLOR_red][2]; else if (j < 0) btn->col = &color[COLOR_red][2];

@ -65,7 +65,7 @@ void gui_fav_show () {
fav_new (); fav_new ();
fav_load (fav_getfilename()); fav_load (fav_getfilename());
if (wfav.screen == NULL) guiwindow_new (&wfav, 220, 240); if (wfav.screen == NULL) gui_window_new (&wfav, 220, 240);
wfav.screen_changed = 1; wfav.screen_changed = 1;
wfav.callback_close = (void*)gui_fav_callback_close; wfav.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1; wfav.screen_changed = 1;

Loading…
Cancel
Save