some fixes..

master
steffen 13 years ago
parent 36592a0d14
commit e4f9249428

@ -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 * gui.c
* *
@ -29,6 +29,14 @@
GUIWindow *currentwin = NULL; 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 * show window
*/ */
@ -133,40 +141,29 @@ void gui_draw () {
*/ */
int gui_event (GUIEvent event) { int gui_event (GUIEvent event) {
int i; int i;
iPoint winpos = { 0 };
static int event_called = 0; static int event_called = 0;
int nogui = 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;
}
// d_printf ("event called %d event:%d mousepos:(%d,%d)", __LINE__, event.event, event.mousepos.x, event.mousepos.y);
if (event_called) return 1; if (event_called) return 1;
event_called = 1; 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++) for (i = 0; i < GUI_MAX_ITEM; i++)
switch (currentwin->items[i].type) { switch (currentwin->items[i].type) {
case (GUI_BUTTON): { case (GUI_BUTTON): {
GUIButton *button = (GUIButton *) currentwin->items[i].item; GUIButton *button = (GUIButton *) currentwin->items[i].item;
if (button->x <= event.mousepos.x && if (GUI_ITEM_IS_INSIDE (button, winpos)) {
button->x+button->w >= event.mousepos.x && d_printf ("button: %d,%d,%d,%d pos:%d,%d event:%d,%d ",
button->y <= event.mousepos.y && button->x, button->y, button->w, button->h, winpos.x, winpos.y, event.mousepos.x, event.mousepos.y);
button->y+button->h >= event.mousepos.y) { gui_button_event (button, event);
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 = 0;
return 1; return 1;
} }
} }
}
break; break;
case (GUI_LABEL): case (GUI_LABEL):
@ -174,10 +171,8 @@ int gui_event (GUIEvent event) {
case (GUI_ENTRY): { case (GUI_ENTRY): {
GUIEntry *entry = (GUIEntry*) currentwin->items[i].item; GUIEntry *entry = (GUIEntry*) currentwin->items[i].item;
if (entry->x <= event.mousepos.x && if (GUI_ITEM_IS_INSIDE (entry, winpos)) {
entry->x+entry->w >= event.mousepos.x && d_printf ("entry..");
entry->y <= event.mousepos.y &&
entry->y+entry->h >= event.mousepos.y) {
gui_entry_event (entry, &event); gui_entry_event (entry, &event);
event_called = 0; event_called = 0;
return 1; return 1;
@ -187,10 +182,8 @@ int gui_event (GUIEvent event) {
case (GUI_LIST): { case (GUI_LIST): {
GUIList *list = (GUIList *) currentwin->items[i].item; GUIList *list = (GUIList *) currentwin->items[i].item;
if (list->x <= event.mousepos.x && if (GUI_ITEM_IS_INSIDE (list, winpos)) {
list->x+list->w >= event.mousepos.x && d_printf ("list..");
list->y <= event.mousepos.y &&
list->y+list->h >= event.mousepos.y) {
gui_list_event (list, &event); gui_list_event (list, &event);
event_called = 0; event_called = 0;
return 1; return 1;
@ -198,19 +191,42 @@ int gui_event (GUIEvent event) {
} }
} }
if (currentwin->focus != NULL) if (currentwin->focus) {
d_printf ("focus..");
switch (currentwin->focus->type) { switch (currentwin->focus->type) {
case (GUI_BUTTON): case (GUI_ENTRY):
gui_entry_event ((GUIEntry*)currentwin->focus->item, &event); gui_entry_event ((GUIEntry*)currentwin->focus->item, &event);
event_called = 1;
return 1;
break; break;
case (GUI_LIST): case (GUI_LIST):
gui_list_event ((GUIList*)currentwin->focus->item, &event); 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; break;
default: default:
break; break;
} }
event_called = 0; event_called = 0;
return 1; return 0;
}; };

@ -1,4 +1,4 @@
/* $Id: gui_button.c,v 1.2 2013/02/21 23:07:19 steffen Exp $ */ /* $Id: gui_button.c,v 1.3 2013/02/24 00:39:59 steffen Exp $ */
/*************************************************************************** /***************************************************************************
* gui_button.c * gui_button.c
* *
@ -64,3 +64,11 @@ GUIButton *gui_button_new (char *caption, int x, int y, int w, int h) {
return item; return item;
}; };
void gui_button_event (GUIButton *button, GUIEvent event) {
if (button->callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) {
button->callback_clicked (event.mousepos.x-button->x, event.mousepos.y-button->y);
}
};

@ -155,15 +155,11 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl
int i; int i;
gfx_fbo_switch (dimg); gfx_fbo_switch (dimg);
if (dimg) {
d_printf ("%d,%d", dimg->width, dimg->height);
}
glBegin (GL_POLYGON); glBegin (GL_POLYGON);
glColor4f (c.c.r, c.c.g, c.c.b, 1.0f); glColor4f (c.c.r, c.c.g, c.c.b, 1.0f);
for (i = 0; i < pcnt; i++) { for (i = 0; i < pcnt; i++)
d_printf (" %d, %d", p[i].x, p[i].y);
glVertex2i (p[i].x, p[i].y); glVertex2i (p[i].x, p[i].y);
}
glEnd (); glEnd ();
if (style.width > 0.0) { if (style.width > 0.0) {
@ -205,8 +201,6 @@ void gfx_draw_img (struct image *dimg, int dx, int dy, int dw, int dh, struct im
fw = (float) dw/(float) (simg->width); fw = (float) dw/(float) (simg->width);
fh = (float) dh/(float) (simg->height); fh = (float) dh/(float) (simg->height);
d_printf ("%d, %d ---- (%d, %d, %d, %d) --- (%f, %f, %f, %f)", simg->width, simg->height, sx, sy, dw, dh, fx, fy, fw, fh);
glTexCoord2d (fx, fy); glTexCoord2d (fx, fy);
glVertex2i (dx, dy); glVertex2i (dx, dy);
glTexCoord2d (fx, fy+fh); glTexCoord2d (fx, fy+fh);

@ -139,7 +139,6 @@ int msdl_eventloop () {
gevent.mousebtn = 0; gevent.mousebtn = 0;
gevent.event = EGUI_MOUSEMOVE; gevent.event = EGUI_MOUSEMOVE;
gui_event (gevent); gui_event (gevent);
draw_mousemove (event.motion.x, event.motion.y, -1);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@ -147,7 +146,7 @@ int msdl_eventloop () {
gevent.mousepos.y = event.motion.y; gevent.mousepos.y = event.motion.y;
gevent.mousebtn = 1; gevent.mousebtn = 1;
gevent.event = EGUI_MOUSEPRESSED; gevent.event = EGUI_MOUSEPRESSED;
if (gui_event (gevent) == 0) draw_mousebtndown (gevent.mousepos.x, gevent.mousepos.y, 1); gui_event (gevent);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
@ -155,7 +154,7 @@ int msdl_eventloop () {
gevent.mousepos.y = event.motion.y; gevent.mousepos.y = event.motion.y;
gevent.mousebtn = 1; gevent.mousebtn = 1;
gevent.event = EGUI_MOUSERELEASED; gevent.event = EGUI_MOUSERELEASED;
if (gui_event (gevent) == 0) draw_mousebtnup (gevent.mousepos.x, gevent.mousepos.y, 1); gui_event (gevent);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:

Loading…
Cancel
Save