From ec415d7a9ff5f5870e797c89bf43b1085d5e8fa1 Mon Sep 17 00:00:00 2001 From: steffen Date: Sun, 24 Feb 2013 12:42:14 +0000 Subject: [PATCH] adding buttons to main menu.. --- gui/gui.c | 20 ++++++++++---------- main/gui_mainmenu.c | 34 ++++++++++++++++++++++++++++++++-- sdlgl/sdl_main.c | 12 +++++++++--- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/gui/gui.c b/gui/gui.c index dc78ed5..ca5d20a 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -1,4 +1,4 @@ -/* $Id: gui.c,v 1.8 2013/02/24 00:39:59 steffen Exp $ */ +/* $Id: gui.c,v 1.9 2013/02/24 12:42:14 steffen Exp $ */ /*************************************************************************** * gui.c * @@ -143,10 +143,9 @@ int gui_event (GUIEvent event) { int i; iPoint winpos = { 0 }; static int event_called = 0; - int nogui = 0; if (event_called) return 1; - event_called = 1; + event_called = 1; if (currentwin) { winpos.x = event.mousepos.x - currentwin->x; @@ -157,8 +156,8 @@ int gui_event (GUIEvent event) { 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); +// 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; @@ -172,7 +171,7 @@ int gui_event (GUIEvent event) { case (GUI_ENTRY): { GUIEntry *entry = (GUIEntry*) currentwin->items[i].item; if (GUI_ITEM_IS_INSIDE (entry, winpos)) { - d_printf ("entry.."); +// d_printf ("entry.."); gui_entry_event (entry, &event); event_called = 0; return 1; @@ -183,22 +182,23 @@ int gui_event (GUIEvent event) { case (GUI_LIST): { GUIList *list = (GUIList *) currentwin->items[i].item; if (GUI_ITEM_IS_INSIDE (list, winpos)) { - d_printf ("list.."); +// d_printf ("list.."); gui_list_event (list, &event); event_called = 0; return 1; } } + break; } if (currentwin->focus) { - d_printf ("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; + break; case (GUI_LIST): gui_list_event ((GUIList*)currentwin->focus->item, &event); event_called = 1; @@ -211,7 +211,7 @@ int gui_event (GUIEvent event) { } /* no gui active nor any window is responsible.. */ - d_printf ("no event.."); +// d_printf ("no event.."); switch (event.event) { case (EGUI_MOUSERELEASED): draw_mousebtnup (event.mousepos.x, event.mousepos.y, event.mousebtn); diff --git a/main/gui_mainmenu.c b/main/gui_mainmenu.c index 3349ae4..5d009ab 100644 --- a/main/gui_mainmenu.c +++ b/main/gui_mainmenu.c @@ -1,4 +1,4 @@ -/* $Id: gui_mainmenu.c,v 1.5 2013/02/22 20:46:26 steffen Exp $ */ +/* $Id: gui_mainmenu.c,v 1.6 2013/02/24 12:42:14 steffen Exp $ */ /*************************************************************************** * gui_mainmenu.c * @@ -53,11 +53,41 @@ void gui_mainmenu_show () { wmmenu.style = WGUI_S_VCENTER | WGUI_S_HCENTER; /* add buttons */ + if (mbtn_map == NULL) { + mbtn_map = gui_button_new (_("Map Settings"), 5, 30, 190, 20); + mbtn_map->callback_clicked = (void*)gui_mainmenu_close; + } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_map); + + if (mbtn_routing == NULL) { + mbtn_routing = gui_button_new (_("Routing"), 5, 60, 190, 20); + mbtn_routing->callback_clicked = (void*)gui_mainmenu_close; + } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_routing); + + if (mbtn_gps == NULL) { + mbtn_gps = gui_button_new (_("GPS"), 5, 90, 190, 20); + mbtn_gps->callback_clicked = (void*)gui_mainmenu_close; + } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_gps); + + if (mbtn_config == NULL) { + mbtn_config = gui_button_new (_("Config"), 5, 120, 130, 20); + mbtn_config->callback_clicked = (void*)gui_mainmenu_close; + } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_config); + + if (mbtn_quit == NULL) { + mbtn_quit = gui_button_new (_("Quit"), 145, 120, 50, 20); + mbtn_quit->callback_clicked = (void*)gui_mainmenu_close; + } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_quit); + if (mbtn_close == NULL) { mbtn_close = gui_button_new (_("Close"), 5, 155, 190, 20); mbtn_close->callback_clicked = (void*)gui_mainmenu_close; - gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_close); } + gui_window_item_add (&wmmenu, GUI_BUTTON, mbtn_close); gui_show (&wmmenu); }; diff --git a/sdlgl/sdl_main.c b/sdlgl/sdl_main.c index 445a60c..d900bb8 100644 --- a/sdlgl/sdl_main.c +++ b/sdlgl/sdl_main.c @@ -111,11 +111,17 @@ Uint32 msdl_timercallback (Uint32 interval, void *param) { int msdl_eventloop () { - SDL_Event event; - int eventstate; + SDL_Event event, lastevent; + int gotevent = 0, keeppoll = 1; GUIEvent gevent; - if ((eventstate = SDL_PollEvent (&event)) != 0) { + while (keeppoll && SDL_PollEvent (&lastevent)) { + event = lastevent; + gotevent = 1; + keeppoll = 0; + if (event.type == SDL_MOUSEMOTION) keeppoll = 1; + } + if (gotevent) { switch (event.type) { case (SDL_QUIT): app.status = APPSTATUS_quit;