From e752a97d6dd8281bd26194b06ee6db4b3636078f Mon Sep 17 00:00:00 2001 From: steffen Date: Wed, 6 Mar 2013 23:27:25 +0000 Subject: [PATCH] working on the gui.. --- Makefile | 1 + android/jni/Android.mk | 5 +-- base/config.c | 5 +++ gui/Makefile | 3 +- gui/gui.c | 3 +- gui/gui.h | 24 +++++++++++++ gui/gui_button.c | 3 +- gui/gui_entry.c | 7 ++-- gui/gui_list.c | 8 ++--- gui/gui_softkeyboard.c | 78 ++++++++++++++++++++++++++++++++++++++++++ main/gui_mainmenu.c | 4 +-- main/osmroute.h | 3 ++ 12 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 gui/gui_softkeyboard.c diff --git a/Makefile b/Makefile index 9b3fdd4..3e8d79e 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,7 @@ clean: for i in $(WINCEDIRS); do make -C $$i clean; done for i in $(SDLGLDIRS); do make -C $$i clean; done for i in $(ANDROIDDIRS); do rm -f android/jni/$$i; done + rm -rf android/assets cd android; make clean; cd .. rm -rf Makefile.rules diff --git a/android/jni/Android.mk b/android/jni/Android.mk index bc48744..b35b19a 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -76,11 +76,12 @@ LOCAL_SRC_FILES := \ mapsys/map_area.c mapsys/map_hash.c mapsys/map_nodepois.c \ mapsys/map_webload.c mapsys/map_searchhash.c\ mapsys/map.c mapsys/map_loadsave.c mapsys/map_way.c \ - gui/gui.c \ + gui/gui.c gui/gui_button.c gui/gui_entry.c gui/gui_image.c gui/gui_label.c \ + gui/gui_list.c gui/gui_window.c gui\gui_softkeyboard.c \ draw/draw.c draw/draw_favorites.c draw/draw_gps.c draw/draw_gui.c draw/draw_route.c \ main/favorites.c main/gui_buttons.c main/gui_mainmenu.c main/guiw_gpsfile.c \ main/main.c main/routing.c main/gps.c main/gui_favorites.c \ - main/gui_search.c main/linux_gps.c + main/gui_search.c main/gui_config.c main/gui_selectdir.c main/linux_gps.c # LOCAL_LDLIBS := -shared -llog -landroid -lEGL -lGLESv1_CM -lz LOCAL_LDLIBS := -shared -llog -landroid -lEGL -lGLESv2 -lz LOCAL_STATIC_LIBRARIES := android_native_app_glue zlib png freetype2-static diff --git a/base/config.c b/base/config.c index 99fd4f0..1946a8d 100644 --- a/base/config.c +++ b/base/config.c @@ -63,6 +63,7 @@ void config_init () { cfg.last_scale = 0.001; cfg.last_lon = 11.183; cfg.last_lat = 48.736; + cfg.softkeyboard = 1; /* Android version will not need config and log path.. */ #if defined(ANDROID) @@ -194,6 +195,9 @@ void config_load () { if (!strcmp (keyword, "debug")) { cfg.debug = atoi (value); } + if (!strcmp (keyword, "softkeyboard")) { + cfg.softkeyboard = atoi (value); + } #endif } fclose (f); @@ -230,6 +234,7 @@ void config_save () { fprintf (f, "gps_flags=%d\n", cfg.gps_flags); fprintf (f, "gps_device=%s\n", cfg.gps_device); fprintf (f, "debug=%d\n", cfg.debug); + fprintf (f, "softkeyboard=%d\n", cfg.softkeyboard); #endif fclose (f); } diff --git a/gui/Makefile b/gui/Makefile index 7293799..eb3a65a 100644 --- a/gui/Makefile +++ b/gui/Makefile @@ -6,7 +6,8 @@ OBJ = gui.o \ gui_list.o \ gui_entry.o \ gui_label.o \ - gui_image.o + gui_image.o \ + gui_softkeyboard.o SRC = $(OBJ:%.o=%.c) diff --git a/gui/gui.c b/gui/gui.c index 29dafd8..d1fed03 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -1,4 +1,4 @@ -/* $Id: gui.c,v 1.16 2013/03/01 19:56:56 steffen Exp $ */ +/* $Id: gui.c,v 1.17 2013/03/06 23:27:25 steffen Exp $ */ /*************************************************************************** * gui.c * @@ -212,6 +212,7 @@ void gui_event_addmousepos (GUIEvent *event, iPoint pos, int neg) { void gui_set_focus (GUIItem *item) { + if (item == NULL || item->type != GUI_ENTRY) gui_softkeyb_show (FALSE); currentwin->focus = item; currentwin->screen_changed = 1; }; \ No newline at end of file diff --git a/gui/gui.h b/gui/gui.h index 93093c5..c5eafa7 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -129,11 +129,31 @@ struct _GUIWindow_ { int h; int style; + void (*callback_clicked) (int x, int y); + GUIItem *items[GUI_MAX_ITEM]; GUIItem *focus; } typedef GUIWindow; +#define GUI_SOFTKEYB_X 11 +#define GUI_SOFTKEYB_Y 3 +enum { + GUI_SOFTKEYB_MODE_NORM = 0, + GUI_SOFTKEYB_MODE_SHIFT, + GUI_SOFTKEYB_MODE_SYMBOL, + + GUI_SOFTKEYB_MODE_MAX +}; + +struct _GUISoftkeyboard_ { + int mode; + int enabled; + struct image *screen; + char keys[GUI_SOFTKEYB_MODE_MAX][GUI_SOFTKEYB_Y][GUI_SOFTKEYB_X]; +} typedef GUISoftkeyboard; + extern GUIWindow *currentwin; +extern GUISoftkeyboard *softkeyb; extern void gui_show (GUIWindow *win); extern void gui_draw (); @@ -146,6 +166,10 @@ extern void gui_window_new (GUIWindow *win, int w, int h, char *title); extern void gui_window_close (GUIWindow *win); extern void gui_window_item_add (GUIWindow *win, GUIItem *item); +/* softkeyboard functions. */ +void gui_softkeyb_show (int enable); + + /* button functions */ #define GUI_BUTTON_T(_item_) ((GUIButton*)(_item_)->data) extern void gui_button_draw (GUIItem *item); diff --git a/gui/gui_button.c b/gui/gui_button.c index af54076..bc95e0c 100644 --- a/gui/gui_button.c +++ b/gui/gui_button.c @@ -1,4 +1,4 @@ -/* $Id: gui_button.c,v 1.6 2013/02/27 22:21:35 steffen Exp $ */ +/* $Id: gui_button.c,v 1.7 2013/03/06 23:27:25 steffen Exp $ */ /*************************************************************************** * gui_button.c * @@ -88,6 +88,7 @@ void gui_button_event (GUIItem *item, GUIEvent *event) { button = (GUIButton *) item->data; if (button->callback_clicked != NULL && event->event == EGUI_MOUSEPRESSED) { + gui_set_focus (item); button->callback_clicked (event->mousepos.x-item->x, event->mousepos.y-item->y); } }; diff --git a/gui/gui_entry.c b/gui/gui_entry.c index 3dadac0..c36f1f2 100644 --- a/gui/gui_entry.c +++ b/gui/gui_entry.c @@ -1,4 +1,4 @@ -/* $Id: gui_entry.c,v 1.9 2013/03/01 19:56:56 steffen Exp $ */ +/* $Id: gui_entry.c,v 1.10 2013/03/06 23:27:25 steffen Exp $ */ /*************************************************************************** * gui_entry.c * @@ -79,7 +79,10 @@ void gui_entry_event (GUIItem *item, GUIEvent *event) { d_printf ("gui_entry_event: %d pos: %d,%d key:%d", event->event, event->mousepos.x, event->mousepos.y, event->keyval); - if (event->event == EGUI_MOUSERELEASED) gui_set_focus (item); + if (event->event == EGUI_MOUSERELEASED) { + gui_set_focus (item); + gui_softkeyb_show (TRUE); + } else if (event->event == EGUI_KEYCHAR) { d_printf ("gui_entry_event: curpos:%d len:%d text:%s char:%x", entry->curpos, strlen (entry->text), entry->text, event->keyval); diff --git a/gui/gui_list.c b/gui/gui_list.c index e248869..890c092 100644 --- a/gui/gui_list.c +++ b/gui/gui_list.c @@ -1,4 +1,4 @@ -/* $Id: gui_list.c,v 1.5 2013/02/27 22:21:35 steffen Exp $ */ +/* $Id: gui_list.c,v 1.6 2013/03/06 23:27:25 steffen Exp $ */ /*************************************************************************** * gui_list.c * @@ -90,9 +90,9 @@ void gui_list_event (GUIItem *item, GUIEvent *event) { else list = (GUIList *) item->data; /* set focus */ - if (event->event == EGUI_MOUSERELEASED && x >= 0 && x <= item->w && y >= 0 && y <= item->h) { - currentwin->focus = (void *) item; - + if (event->event == EGUI_MOUSERELEASED) { + gui_set_focus (item); + if (y <= 5 && x >= item->w - 10) list->vs--; else if (y >= item->h - 5 && x >= item->w - 10) list->vs++; else { /* select entry */ diff --git a/gui/gui_softkeyboard.c b/gui/gui_softkeyboard.c new file mode 100644 index 0000000..5d0dd04 --- /dev/null +++ b/gui/gui_softkeyboard.c @@ -0,0 +1,78 @@ +/* $Id: gui_softkeyboard.c,v 1.1 2013/03/06 23:28:15 steffen Exp $ */ +/*************************************************************************** + * gui_softkeyboard.c + * + * Copyright (C) 2013 Steffen Pohle + * steffen@gulpe.de + *************************************************************************** + * softkeyboard: self written softkeyboard. + ***************************************************************************/ + +/* + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * main.c is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + + +#include "osmroute.h" +#include "draw.h" +#include "gui.h" +#include "system.h" + +GUISoftkeyboard *softkeyb = NULL; + +void gui_softkeyb_show (int enable) { + /* keys which are displayed.. */ + char line[GUI_SOFTKEYB_MODE_MAX][GUI_SOFTKEYB_X][GUI_SOFTKEYB_X] = { + { "qwertzuiop?", + "asdfghjkl??", + "yxcvbnm,.-_" }, + { "QWERTZUIOP?", + "ASDFGHIKL??", + "YXCVBNM;:#+" }, + { "0123456789=", + " ", + " " }}; + int i, j; + + /* disable software keyboard */ + if (cfg.softkeyboard == 0 || enable == 0) { + if (softkeyb) softkeyb->enabled = FALSE; + return; + } + + /* check for allocation.. */ + if (softkeyb == NULL) { + softkeyb = (GUISoftkeyboard*) ml_malloc (sizeof (GUISoftkeyboard)); + memset (softkeyb, 0x0, sizeof (GUISoftkeyboard)); + } + + /* reset data */ + for (i = 0; i < GUI_SOFTKEYB_MODE_MAX; i++) for (j = 0; j < 3; j++) + strncpy (softkeyb->keys[i][j], line[i][j], GUI_SOFTKEYB_X); + + softkeyb->enabled = TRUE; + softkeyb->mode = GUI_SOFTKEYB_MODE_NORM; +}; + + +/* only preparing the screen image... copying to the screen will be done later... */ +void gui_softkeyb_draw () { + if (softkeyb == NULL || gfx_screensize.x < 0 || softkeyb->enabled == FALSE) return; + if (softkeyb->screen == NULL || softkeyb->screen->width != gfx_screensize.x) { + if (softkeyb->screen) gfx_img_free (softkeyb->screen); + softkeyb->screen = gfx_img_alloc (gfx_screensize.x, gfx_screensize.y * 0.8); + } + + gfx_clear (softkeyb->screen, &color[COLOR_white][1]); +}; diff --git a/main/gui_mainmenu.c b/main/gui_mainmenu.c index 17bdf17..764d734 100644 --- a/main/gui_mainmenu.c +++ b/main/gui_mainmenu.c @@ -1,4 +1,4 @@ -/* $Id: gui_mainmenu.c,v 1.9 2013/02/27 22:21:35 steffen Exp $ */ +/* $Id: gui_mainmenu.c,v 1.10 2013/03/06 23:27:25 steffen Exp $ */ /*************************************************************************** * gui_mainmenu.c * @@ -59,8 +59,8 @@ void gui_mainmenu_show () { } gui_window_item_add (&wmmenu, mbtn_refresh); - if (mbtn_refreshidx == NULL) { mbtn_refreshidx = gui_button_new (_("Update Index"), 105, 30, 90, 20); + if (mbtn_refreshidx == NULL) { GUI_BUTTON_T(mbtn_refreshidx)->callback_clicked = (void*)gui_mainmenu_refreshidx; } gui_window_item_add (&wmmenu, mbtn_refreshidx); diff --git a/main/osmroute.h b/main/osmroute.h index e28a2c3..e752a89 100644 --- a/main/osmroute.h +++ b/main/osmroute.h @@ -121,6 +121,9 @@ struct cfgdata { float last_lon; float last_lat; float last_scale; + + int softkeyboard; + int debug; };