From e4f92494287346231b40edb8fadbfed2c72504e7 Mon Sep 17 00:00:00 2001 From: steffen Date: Sun, 24 Feb 2013 00:39:59 +0000 Subject: [PATCH] some fixes.. --- gui/gui.c | 144 ++++++++++++++++++++++++++--------------------- gui/gui_button.c | 10 +++- sdlgl/sdl_gfx.c | 10 +--- sdlgl/sdl_main.c | 5 +- 4 files changed, 93 insertions(+), 76 deletions(-) diff --git a/gui/gui.c b/gui/gui.c index 44b881a..dc78ed5 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -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; }; diff --git a/gui/gui_button.c b/gui/gui_button.c index de02c71..c0abafa 100644 --- a/gui/gui_button.c +++ b/gui/gui_button.c @@ -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 * @@ -64,3 +64,11 @@ GUIButton *gui_button_new (char *caption, int x, int y, int w, int h) { 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); + } +}; + diff --git a/sdlgl/sdl_gfx.c b/sdlgl/sdl_gfx.c index 8685884..aedf662 100644 --- a/sdlgl/sdl_gfx.c +++ b/sdlgl/sdl_gfx.c @@ -155,15 +155,11 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl int i; gfx_fbo_switch (dimg); - if (dimg) { - d_printf ("%d,%d", dimg->width, dimg->height); - } glBegin (GL_POLYGON); glColor4f (c.c.r, c.c.g, c.c.b, 1.0f); - for (i = 0; i < pcnt; i++) { - d_printf (" %d, %d", p[i].x, p[i].y); + for (i = 0; i < pcnt; i++) glVertex2i (p[i].x, p[i].y); - } + glEnd (); 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); 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); glVertex2i (dx, dy); glTexCoord2d (fx, fy+fh); diff --git a/sdlgl/sdl_main.c b/sdlgl/sdl_main.c index 5af9e97..445a60c 100644 --- a/sdlgl/sdl_main.c +++ b/sdlgl/sdl_main.c @@ -139,7 +139,6 @@ int msdl_eventloop () { gevent.mousebtn = 0; gevent.event = EGUI_MOUSEMOVE; gui_event (gevent); - draw_mousemove (event.motion.x, event.motion.y, -1); break; case SDL_MOUSEBUTTONDOWN: @@ -147,7 +146,7 @@ int msdl_eventloop () { gevent.mousepos.y = event.motion.y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSEPRESSED; - if (gui_event (gevent) == 0) draw_mousebtndown (gevent.mousepos.x, gevent.mousepos.y, 1); + gui_event (gevent); break; case SDL_MOUSEBUTTONUP: @@ -155,7 +154,7 @@ int msdl_eventloop () { gevent.mousepos.y = event.motion.y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSERELEASED; - if (gui_event (gevent) == 0) draw_mousebtnup (gevent.mousepos.x, gevent.mousepos.y, 1); + gui_event (gevent); break; case SDL_KEYDOWN: