|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: gui.c,v 1.7 2013/02/22 20:46:26 steffen Exp $ */
|
|
|
|
|
/* $Id: gui.c,v 1.8 2013/02/24 00:39:59 steffen Exp $ */
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* gui.c
|
|
|
|
|
*
|
|
|
|
|
@ -29,6 +29,14 @@
|
|
|
|
|
|
|
|
|
|
GUIWindow *currentwin = NULL;
|
|
|
|
|
|
|
|
|
|
#define GUI_ITEM_IS_INSIDE(__item__,__pos__) gui_is_inside(__item__->x, __item__->y, __item__->w, __item__->h, __pos__)
|
|
|
|
|
|
|
|
|
|
int gui_is_inside (int x, int y, int w, int h, iPoint pos) {
|
|
|
|
|
if (x <= pos.x && x+w >= pos.x && y <= pos.y && y+h >= pos.y) return 1;
|
|
|
|
|
else return 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* show window
|
|
|
|
|
*/
|
|
|
|
|
@ -133,84 +141,92 @@ void gui_draw () {
|
|
|
|
|
*/
|
|
|
|
|
int gui_event (GUIEvent event) {
|
|
|
|
|
int i;
|
|
|
|
|
iPoint winpos = { 0 };
|
|
|
|
|
static int event_called = 0;
|
|
|
|
|
|
|
|
|
|
if (currentwin == NULL) return 0;
|
|
|
|
|
|
|
|
|
|
event.mousepos.x -= currentwin->x;
|
|
|
|
|
event.mousepos.y -= currentwin->y;
|
|
|
|
|
if (currentwin->focus == NULL && (event.mousepos.x < 0 || event.mousepos.x > currentwin->w
|
|
|
|
|
|| event.mousepos.y < 0 || event.mousepos.y > currentwin->h)) {
|
|
|
|
|
event_called = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
int nogui = 0;
|
|
|
|
|
|
|
|
|
|
// d_printf ("event called %d event:%d mousepos:(%d,%d)", __LINE__, event.event, event.mousepos.x, event.mousepos.y);
|
|
|
|
|
|
|
|
|
|
if (event_called) return 1;
|
|
|
|
|
event_called = 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;
|
|
|
|
|
event_called = 1;
|
|
|
|
|
|
|
|
|
|
if (currentwin) {
|
|
|
|
|
winpos.x = event.mousepos.x - currentwin->x;
|
|
|
|
|
winpos.y = event.mousepos.y - currentwin->y;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < GUI_MAX_ITEM; i++)
|
|
|
|
|
switch (currentwin->items[i].type) {
|
|
|
|
|
case (GUI_BUTTON): {
|
|
|
|
|
GUIButton *button = (GUIButton *) currentwin->items[i].item;
|
|
|
|
|
if (GUI_ITEM_IS_INSIDE (button, winpos)) {
|
|
|
|
|
d_printf ("button: %d,%d,%d,%d pos:%d,%d event:%d,%d ",
|
|
|
|
|
button->x, button->y, button->w, button->h, winpos.x, winpos.y, event.mousepos.x, event.mousepos.y);
|
|
|
|
|
gui_button_event (button, event);
|
|
|
|
|
event_called = 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (GUI_LABEL):
|
|
|
|
|
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;
|
|
|
|
|
case (GUI_ENTRY): {
|
|
|
|
|
GUIEntry *entry = (GUIEntry*) currentwin->items[i].item;
|
|
|
|
|
if (GUI_ITEM_IS_INSIDE (entry, winpos)) {
|
|
|
|
|
d_printf ("entry..");
|
|
|
|
|
gui_entry_event (entry, &event);
|
|
|
|
|
event_called = 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
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;
|
|
|
|
|
case (GUI_LIST): {
|
|
|
|
|
GUIList *list = (GUIList *) currentwin->items[i].item;
|
|
|
|
|
if (GUI_ITEM_IS_INSIDE (list, winpos)) {
|
|
|
|
|
d_printf ("list..");
|
|
|
|
|
gui_list_event (list, &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:
|
|
|
|
|
if (currentwin->focus) {
|
|
|
|
|
d_printf ("focus..");
|
|
|
|
|
switch (currentwin->focus->type) {
|
|
|
|
|
case (GUI_ENTRY):
|
|
|
|
|
gui_entry_event ((GUIEntry*)currentwin->focus->item, &event);
|
|
|
|
|
event_called = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
break;
|
|
|
|
|
case (GUI_LIST):
|
|
|
|
|
gui_list_event ((GUIList*)currentwin->focus->item, &event);
|
|
|
|
|
event_called = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* no gui active nor any window is responsible.. */
|
|
|
|
|
d_printf ("no event..");
|
|
|
|
|
switch (event.event) {
|
|
|
|
|
case (EGUI_MOUSERELEASED):
|
|
|
|
|
draw_mousebtnup (event.mousepos.x, event.mousepos.y, event.mousebtn);
|
|
|
|
|
break;
|
|
|
|
|
case (EGUI_MOUSEPRESSED):
|
|
|
|
|
draw_mousebtndown (event.mousepos.x, event.mousepos.y, event.mousebtn);
|
|
|
|
|
break;
|
|
|
|
|
case (EGUI_MOUSEMOVE):
|
|
|
|
|
draw_mousemove (event.mousepos.x, event.mousepos.y, 0);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event_called = 0;
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|