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
*
@ -84,23 +84,30 @@ void gui_draw () {
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) {
if (currentwin->buttons[i].callback_draw != NULL)
currentwin->buttons[i].callback_draw (&currentwin->buttons[i]);
else gui_button_draw (&currentwin->buttons[i]);
}
for (i = 0; i < GUI_WIN_LABELS; i++) if (currentwin->labels[i].id != 0) {
gui_label_draw (&currentwin->labels[i]);
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->entrys[i].id != 0) {
gui_entry_draw (&currentwin->entrys[i]);
}
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->lists[i].id != 0) {
gui_list_draw (&currentwin->lists[i]);
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) if (currentwin->checkboxes[i].id != 0) {
// gui_draw_label (&currentwin->labels[i]);
}
/* draw items.. */
for (i = 0; i < GUI_MAX_ITEM; i++)
switch (currentwin->items[i].type) {
case (GUI_BUTTON): {
GUIButton *button = (GUIButton *) currentwin->items[i].item;
if (button->callback_draw != NULL) button->callback_draw (button);
else gui_button_draw (button);
}
break;
case (GUI_LABEL):
gui_label_draw ((GUILabel*)currentwin->items[i].item);
break;
case (GUI_ENTRY):
gui_entry_draw ((GUIEntry*)currentwin->items[i].item);
break;
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;
}
@ -141,58 +148,65 @@ int gui_event (GUIEvent event) {
if (event_called) return 1;
event_called = 1;
for (i = 0; i < GUI_WIN_BUTTONS; i++) {
// if (currentwin->buttons[i].id != 0)
// 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);
if (currentwin->buttons[i].id != 0
&& currentwin->buttons[i].x <= event.mousepos.x && currentwin->buttons[i].x+currentwin->buttons[i].w >= event.mousepos.x
&& currentwin->buttons[i].y <= event.mousepos.y && currentwin->buttons[i].y+currentwin->buttons[i].h >= event.mousepos.y) {
if (currentwin->buttons[i].callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) {
d_printf ("GUI BUTTON PRESSED: %d:%s", currentwin->buttons[i].id, currentwin->buttons[i].caption);
currentwin->buttons[i].callback_clicked (event.mousepos.x-currentwin->buttons[i].x, event.mousepos.y-currentwin->buttons[i].y);
event_called = 0;
currentwin->screen_changed = 1;
return 1;
for (i = 0; i < GUI_MAX_ITEM; i++)
switch (currentwin->items[i].type) {
case (GUI_BUTTON): {
GUIButton *button = (GUIButton *) currentwin->items[i].item;
if (button->x <= event.mousepos.x &&
button->x+button->w >= event.mousepos.x &&
button->y <= event.mousepos.y &&
button->y+button->h >= event.mousepos.y) {
if (button->callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) {
d_printf ("GUI BUTTON PRESSED: %s", button->caption);
button->callback_clicked (event.mousepos.x-button->x, event.mousepos.y-button->y);
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) {
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->focus == &currentwin->entrys[i]) {
gui_entry_event (&currentwin->entrys[i], &event);
event_called = 0;
return 1;
}
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;
if (currentwin->focus != NULL)
switch (currentwin->focus->type) {
case (GUI_BUTTON):
gui_entry_event ((GUIEntry*)currentwin->focus->item, &event);
break;
case (GUI_LIST):
gui_list_event ((GUIList*)currentwin->focus->item, &event);
break;
default:
break;
}
}
event_called = 0;
return 1;

@ -71,7 +71,6 @@ struct _GUIEvent_ {
struct _GUIButton_ {
int x, y, w, h;
int id;
char caption[GUI_TEXTLEN];
struct color *col;
struct color *textcol;
@ -82,7 +81,6 @@ struct _GUIButton_ {
struct _GUIList_ {
int x, y, w, h;
int id;
char **data;
int vs; // first element to draw
int selected;
@ -92,7 +90,6 @@ struct _GUIList_ {
struct {
int x, y;
int id;
char text[GUI_TEXTLEN];
struct color *textcol;
} typedef GUILabel;
@ -100,7 +97,6 @@ struct {
struct {
int x, y, w, h;
int id;
char text[GUI_TEXTLEN];
int curpos;
int overwrite;
@ -111,7 +107,6 @@ struct {
struct {
int x, y, w, h;
int id;
char text[GUI_TEXTLEN];
int checked;
void (*callback_changed) ();
@ -138,7 +133,7 @@ struct _GUIWindow_ {
int style;
GUIItem items[GUI_MAX_ITEM];
void *focus;
GUIItem *focus;
} typedef GUIWindow;
extern GUIWindow *currentwin;
@ -153,19 +148,22 @@ extern void gui_window_close (GUIWindow *win);
/* button functions */
extern void gui_button_draw (GUIButton *button);
extern GUIButton *gui_button_new (char *name, int x, int y, int w, int h);
/* label functions */
extern void gui_label_draw (GUILabel *label);
extern GUILabel *gui_label_new (char *name, int x, int y);
/* entry functions */
extern void gui_entry_draw (GUIEntry *entry);
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 */
extern void gui_list_draw (GUIList *list);
extern void gui_list_event (GUIList *list, GUIEvent *event);
extern void gui_list_setselect (GUIList *list);
extern GUIList *gui_list_new (int x, int y, int w, int h);
/**************************************************************************
* 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
*
@ -37,7 +37,7 @@ void gui_list_draw (GUIList *list) {
int max, i, x, y, j;
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];
else
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
*
@ -36,8 +36,8 @@ 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;
win->items[i].item = NULL;
win->items[i].type = GUI_NONE;
}
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) {
int i;
for (i = 0; i < GUI_WIN_BUTTONS; i++) {
win->buttons[i].caption[0] = '\0';
win->buttons[i].id = 0;
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;
for (i = 0; i < GUI_MAX_ITEM; i++) {
win->items[i].type = GUI_NONE;
win->items[i].item = NULL;
}
win->title[0] = 0;

@ -38,6 +38,11 @@ enum {
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_draw (GUIButton *btn);
void gui_buttons_zoomin();
@ -49,61 +54,42 @@ void gui_buttons_fav();
void gui_buttons_show () {
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.callback_close = (void*)gui_buttons_closecallback;
wbutton.style = WGUI_S_VCENTER | WGUI_S_HTOP;
/* add buttons */
strncpy (wbutton.buttons[0].caption, _("+"), GUI_TEXTLEN);
wbutton.buttons[0].callback_clicked = (void*)gui_buttons_zoomin;
wbutton.buttons[0].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[0].id = BTNWIN_ZIN;
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);
wbutton.buttons[4].callback_clicked = (void*)gui_buttons_fav;
wbutton.buttons[4].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[4].id = BTNWIN_FAV;
wbutton.buttons[4].w = 31;
wbutton.buttons[4].h = 31;
wbutton.buttons[4].x = 160;
wbutton.buttons[4].y = 0;
if (btn_zoomin == NULL) {
btn_zoomin = gui_button_new (_("+"), 0, 0, 31, 31);
btn_zoomin->callback_clicked = (void*)gui_buttons_zoomin;
btn_zoomin->callback_draw = (void*)gui_buttons_draw;
}
if (btn_zoomout == NULL) {
btn_zoomout = gui_button_new (_("-"), 40, 0, 31, 31);
btn_zoomout->callback_clicked = (void*)gui_buttons_zoomout;
btn_zoomout->callback_draw = (void*)gui_buttons_draw;
}
if (btn_gps == NULL) {
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);
};
@ -112,14 +98,14 @@ void gui_buttons_show () {
void gui_buttons_closecallback () {
d_printf ("GUI: buttons close");
guiwindow_close (&wbutton);
gui_window_close (&wbutton);
};
void gui_buttons_draw (GUIButton *btn) {
int j;
if (btn->id == BTNWIN_GPS) {
if (btn == btn_gps) {
j = gps_isrunning ();
if (j == 0) btn->col = &color[COLOR_white][2];
else if (j < 0) btn->col = &color[COLOR_red][2];

@ -65,7 +65,7 @@ void gui_fav_show () {
fav_new ();
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.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1;

Loading…
Cancel
Save