diff --git a/Makefile.rules.win b/Makefile.rules.win index 077a6b7..a2e2531 100644 --- a/Makefile.rules.win +++ b/Makefile.rules.win @@ -5,7 +5,8 @@ DEPENDFILE = .depend DEBUG = -ggdb AR = i586-mingw32msvc-ar CC = i586-mingw32msvc-gcc -CFLAGS = -Wall -I../main -I../ -I../mapsys -I../gui -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_WINAPI -D_WIN32_IE=0x400 $(DEBUG) +# CFLAGS = -Wall -I../main -I../ -I../mapsys -I../gui -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_WINAPI -D_WIN32_IE=0x400 $(DEBUG) +CFLAGS = -Wall -I../main -I../ -I../mapsys -I../gui -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_WINAPI $(DEBUG) WINRES = i586-mingw32msvc-windres LIBS = -lgdi32 -lcomdlg32 -lwsock32 diff --git a/android/jni/main.c b/android/jni/main.c index aff32ce..a097751 100644 --- a/android/jni/main.c +++ b/android/jni/main.c @@ -197,26 +197,29 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) struct engine* engine = (struct engine*)app->userData; if (type == AINPUT_EVENT_TYPE_MOTION) { int32_t subtype = AMotionEvent_getAction (event); - gevent.mousepos.x = AMotionEvent_getX(event, 0); - gevent.mousepos.y = AMotionEvent_getY(event, 0); + gevent.scr_mpos.x = AMotionEvent_getX(event, 0); + gevent.scr_mpos.y = AMotionEvent_getY(event, 0); if (subtype == AMOTION_EVENT_ACTION_MOVE) { gevent.event = EGUI_MOUSEMOVE; - if (gui_event (gevent) == 0) draw_mousemove (gevent.mousepos.x, gevent.mousepos.y, 0); +// if (gui_event (gevent) == 0) draw_mousemove (gevent.scr_mpos.x, gevent.scr_mpos.y, 0); + gui_event (gevent); return 1; } else if (subtype == AMOTION_EVENT_ACTION_UP) { gevent.mousebtn = 1; gevent.event = EGUI_MOUSERELEASED; - if (gui_event (gevent) == 0) draw_mousebtnup (gevent.mousepos.x, gevent.mousepos.y, 1); +// if (gui_event (gevent) == 0) draw_mousebtnup (gevent.scr_mpos.x, gevent.scr_mpos.y, 1); + gui_event (gevent); return; } else if (subtype == AMOTION_EVENT_ACTION_DOWN) { char *tmp; gevent.mousebtn = 1; gevent.event = EGUI_MOUSEPRESSED; - if (gui_event (gevent) == 0) draw_mousebtndown (gevent.mousepos.x, gevent.mousepos.y, 1); +// if (gui_event (gevent) == 0) draw_mousebtndown (gevent.scr_mpos.x, gevent.scr_mpos.y, 1); + gui_event (gevent); return; } } @@ -295,18 +298,64 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { } } + +void main_event () { + // Read all pending events. + time_t t1 = time(NULL), t2 = time(NULL); + struct gps_data *gpspos; + int ident; + int events; + struct android_poll_source* source; + + // If not animating, we will block forever waiting for events. + // If animating, we loop until all events are read, then continue + // to draw the next frame of animation. + while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { + + // Process this event. + if (source != NULL) { + source->process(engine.app, source); + } + + // If a sensor has data, process it now. + if (ident == LOOPER_ID_USER) { + if (engine.accelerometerSensor != NULL) { + ASensorEvent event; + while (ASensorEventQueue_getEvents(engine.sensorEventQueue, + &event, 1) > 0) { +// LOGI("accelerometer: x=%f y=%f z=%f", +// event.acceleration.x, event.acceleration.y, +// event.acceleration.z); + } + } + } + + // Check if we are exiting. + if (engine.app->destroyRequested != 0) { + engine_term_display(&engine); + return; + } + } + t1 = time(NULL); + if (t1 != t2) { + t2 = t1; + if (gps_isrunning () > 0) { + if ((gpspos = gps_loop ())) { + drawgps_set_pos (gpspos); + } + } + } +} + /** * This is the main entry point of a native application that is using * android_native_app_glue. It runs in its own thread, with its own * event loop for receiving input events and doing other things. */ void android_main(struct android_app* state) { - time_t t1 = time(NULL), t2 = time(NULL); - struct gps_data *gpspos; - // Make sure glue isn't stripped. app_dummy(); - + d_printf ("Android Version"); memset(&engine, 0, sizeof(engine)); state->userData = &engine; @@ -316,7 +365,7 @@ void android_main(struct android_app* state) { d_printf ("internal data path: %s", state->activity->internalDataPath); d_printf ("external data path: %s", state->activity->externalDataPath); - + // Prepare to monitor accelerometer engine.sensorManager = ASensorManager_getInstance(); engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager, @@ -333,61 +382,17 @@ void android_main(struct android_app* state) { // loop waiting for stuff to do. while (1) { - // Read all pending events. - int ident; - int events; - struct android_poll_source* source; - - // If not animating, we will block forever waiting for events. - // If animating, we loop until all events are read, then continue - // to draw the next frame of animation. - while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) { - - // Process this event. - if (source != NULL) { - source->process(state, source); - } - - // If a sensor has data, process it now. - if (ident == LOOPER_ID_USER) { - if (engine.accelerometerSensor != NULL) { - ASensorEvent event; - while (ASensorEventQueue_getEvents(engine.sensorEventQueue, - &event, 1) > 0) { -// LOGI("accelerometer: x=%f y=%f z=%f", -// event.acceleration.x, event.acceleration.y, -// event.acceleration.z); - } - } - } - - // Check if we are exiting. - if (state->destroyRequested != 0) { - engine_term_display(&engine); - return; - } - } - t1 = time(NULL); - if (t1 != t2) { - t2 = t1; - if (gps_isrunning () > 0) { - if ((gpspos = gps_loop ())) { - drawgps_set_pos (gpspos); - } - } - } + main_event (); } } + /************************************************************************* * main functions for sposmroute... */ -void main_wnd_loop (long long int cur, long long int max) { -} - - void main_wnd_update () { + main_event (); } diff --git a/base/system.h b/base/system.h index f9a9c5f..d8a417d 100644 --- a/base/system.h +++ b/base/system.h @@ -54,11 +54,14 @@ #if defined(__MINGW32CE__) || defined(_WIN32_WCE) #define DIR_SEP '/' + #define ROOT_DIR "/" #else #if defined(__MINGW32__) - #define DIR_SEP '\\' + #define DIR_SEP '\\' + #define ROOT_DIR "C:\\" #else #define DIR_SEP '/' + #define ROOT_DIR "/" #endif #endif diff --git a/main/gui_config.c b/main/gui_config.c index 96c2c30..33c0c50 100644 --- a/main/gui_config.c +++ b/main/gui_config.c @@ -74,8 +74,6 @@ void gui_config_show () { if (wcfg.screen == NULL) gui_window_new (&wcfg, 220, 280, _("Config")); wcfg.screen_changed = 1; wcfg.style = WGUI_S_VCENTER | WGUI_S_HCENTER; - gui_show (&wcfg); - if (label1 == NULL) label1 = gui_label_new (_("mapdata path:"), 5, 20); gui_window_item_add (&wcfg, label1); @@ -117,6 +115,8 @@ void gui_config_show () { gui_button_new (_("Close"), 5, wcfg.h-25, wcfg.w-10, 20); GUI_BUTTON_T (wcfg_close)->callback_clicked = gui_config_close; gui_window_item_add (&wcfg, wcfg_close); + + gui_show (&wcfg); }; @@ -129,7 +129,7 @@ void gui_config_close () { void gui_config_checkbox_changed () { - if (cfg.debug = GUI_CHECKBOX_T(cb_debug)->checked) SETFLAG(view_flags, DRAW_DEBUG); + if ((cfg.debug = GUI_CHECKBOX_T(cb_debug)->checked)) SETFLAG(view_flags, DRAW_DEBUG); else DELFLAG(view_flags, DRAW_DEBUG); cfg.softkeyboard = GUI_CHECKBOX_T(cb_softkeyb)->checked; @@ -148,7 +148,12 @@ void gui_config_gpslist (int nr) { void gui_config_seldir () { - d_printf ("select dir..."); + char *new_dir = NULL; + + new_dir = gui_sdir_show (GUI_ENTRY_T(map_path)->text); + d_printf ("new_dir:%s", new_dir); + gui_entry_settext (map_path, new_dir); + d_printf ("mapdir:%s", GUI_ENTRY_T(map_path)->text); }; diff --git a/main/gui_selectdir.c b/main/gui_selectdir.c index d2e1d32..bd4b56e 100644 --- a/main/gui_selectdir.c +++ b/main/gui_selectdir.c @@ -26,16 +26,56 @@ #include "gui.h" #include "system.h" +#include +#include + void gui_sdir_close (); +void gui_sdir_update (); +void gui_sdir_clear (); +void gui_sdir_clicklist (int nr); GUIWindow wsdir = {0}; -char select_dir[LEN_FILENAME]; +GUIItem *wsd_close = NULL; +GUIItem *wsd_path = NULL; +GUIItem *wsd_dirlist = NULL; + +char **wsd_list = NULL; +int wsd_listmax = 0; +char wsd_select_dir[LEN_FILENAME]; -void gui_sdir_show () { - if (wsdir.screen == NULL) gui_window_new (&wsdir, 220, 240, _("Select Dir")); - wsdir.callback_close = (void*)gui_sdir_close; +char *gui_sdir_show (char *startpath) { + if (wsdir.screen == NULL) gui_window_new (&wsdir, 220, 250, _("Select Dir")); wsdir.screen_changed = 1; wsdir.style = WGUI_S_VCENTER | WGUI_S_HCENTER; + + /* close Button */ + if (wsd_close == NULL) wsd_close = gui_button_new (_("Close"), 50, 220, 100, 20); + GUI_BUTTON_T (wsd_close)->callback_clicked = (void*) gui_sdir_close; + gui_window_item_add (&wsdir, wsd_close); + + if (wsd_path == NULL) wsd_path = gui_entry_new (startpath, 10, 25, 200, 25); + gui_window_item_add (&wsdir, wsd_path); + + if (wsd_dirlist == NULL) wsd_dirlist = gui_list_new (10, 55, 200, 140); + GUI_LIST_T (wsd_dirlist)->callback_selectitem = gui_sdir_clicklist; + GUI_LIST_T (wsd_dirlist)->data = wsd_list; + gui_window_item_add (&wsdir, wsd_dirlist); + + gui_sdir_update (); + + gui_show (&wsdir); + while (currentwin == &wsdir) { + main_wnd_update (); + } + strncpy (wsd_select_dir, GUI_ENTRY_T(wsd_path)->text, LEN_FILENAME-1); + + if (wsd_select_dir[strlen(wsd_select_dir)-1] != DIR_SEP) { + int i = strlen(wsd_select_dir); + wsd_select_dir[i] = DIR_SEP; + wsd_select_dir[i+1] = '\0'; + } + + return wsd_select_dir; }; @@ -43,3 +83,117 @@ void gui_sdir_close () { gui_close (); }; + +void gui_sdir_clicklist (int nr) { + char fname[LEN_FILENAME]; + char *seperate; + + d_printf ("selected nr:%d '%s'", nr, nr < wsd_listmax ? wsd_list[nr] : "nr >= wsd_listmax"); + if (nr >= wsd_listmax && wsd_list[nr] == NULL) return; + + if (strcmp (wsd_list[nr], ".") == 0) return; + if (strcmp (wsd_list[nr], "..") == 0) { + strncpy (fname, GUI_ENTRY_T(wsd_path)->text, LEN_FILENAME); + while (strlen (fname)>1 && fname[strlen (fname) -1] == DIR_SEP) + fname[strlen (fname)-1] = '\0'; + if (strlen (fname) > 1) { + seperate = strrchr(fname, DIR_SEP); + if (seperate != NULL) { + seperate[0] = '\0'; + } + } + gui_entry_settext (wsd_path, fname); + } + else { + if (GUI_ENTRY_T(wsd_path)->text[strlen (GUI_ENTRY_T(wsd_path)->text)-1] == DIR_SEP) + snprintf (fname, LEN_FILENAME, "%s%s", GUI_ENTRY_T(wsd_path)->text, wsd_list[nr]); + else + snprintf (fname, LEN_FILENAME, "%s%c%s", GUI_ENTRY_T(wsd_path)->text, DIR_SEP, wsd_list[nr]); + + gui_entry_settext (wsd_path, fname); + } + + gui_sdir_update (); +// wsdir.screen_changed = 1; +// draw (); +}; + + +void gui_sdir_update () { + int cnt; + DIR *dir = NULL; + struct dirent *direntry = NULL; + char fname[LEN_FILENAME]; + struct stat stbuf; + + /* clear list and reopen directory */ + gui_sdir_clear (); + if ((dir = opendir (GUI_ENTRY_T(wsd_path)->text)) == NULL) { + /* if open fails, reopen with ROOT_DIR which is defined in system.h */ + gui_entry_settext (wsd_path, ROOT_DIR); + if ((dir = opendir (GUI_ENTRY_T(wsd_path)->text)) == NULL) { + d_printf ("could not open dir for reading. errno:%d '%s'", errno, strerror(errno)); + return; + } + } + + /* go through the directory but only add directory entries */ + cnt = wsd_listmax = 0; + + /* need more memory? */ + while ((direntry = readdir (dir))) { + if (GUI_ENTRY_T(wsd_path)->text[strlen (GUI_ENTRY_T(wsd_path)->text)-1] == DIR_SEP) + snprintf (fname, LEN_FILENAME, "%s%s", GUI_ENTRY_T(wsd_path)->text, direntry->d_name); + else + snprintf (fname, LEN_FILENAME, "%s%c%s", GUI_ENTRY_T(wsd_path)->text, DIR_SEP, direntry->d_name); + if (stat(fname, &stbuf) == -1) { + d_printf ("could not read stat of file: %s", fname); + continue; + } + if (S_ISDIR(stbuf.st_mode)) { + /* need more memory? */ + if (cnt >= wsd_listmax) { + /* save old pointer and counter */ + char **tmp = wsd_list; + int i = wsd_listmax-1; + + /* allocate new list */ + wsd_listmax += 512; + wsd_list = ml_malloc (wsd_listmax * sizeof(void*)); + memset (wsd_list, 0x0, wsd_listmax * sizeof(void*)); + + /* copy list */ + if (tmp) { + for (; i >= 0; i--) wsd_list[i] = tmp[i]; + ml_free (tmp); + } + + /* setup new list */ + GUI_LIST_T (wsd_dirlist)->data = wsd_list; + } + + wsd_list[cnt] = ml_malloc (LEN_FILENAME); + strncpy (wsd_list[cnt], direntry->d_name, LEN_FILENAME); + d_printf ("added entry:%-3d '%s'", cnt, direntry->d_name); + cnt++; + } + } + + closedir (dir); +}; + + +/* + * remove all listentrys and free list + */ +void gui_sdir_clear () { + int i; + + if (wsd_list == NULL) return; + + for (i = 0; wsd_list[i]; i++) { + if (wsd_list[i]) ml_free (wsd_list[i]); + wsd_list[i] = NULL; + } +}; + diff --git a/main/osmroute.h b/main/osmroute.h index 9a213b0..1f1fc20 100644 --- a/main/osmroute.h +++ b/main/osmroute.h @@ -189,4 +189,6 @@ extern void main_wnd_enable (int enabled); extern void main_wnd_loop (long long int cur, long long int max); extern void main_wnd_update (); +extern char *gui_sdir_show (char *startpath); + #endif diff --git a/mapsys/map_loadsave.c b/mapsys/map_loadsave.c index 0094699..52cdeab 100644 --- a/mapsys/map_loadsave.c +++ b/mapsys/map_loadsave.c @@ -1114,7 +1114,7 @@ void map_save_all () { if (map_save_hash (mhash[i]) == 0) DELFLAG(mhash[i]->status, MS_changed); break; } - main_wnd_loop (i, mhash_max); + main_wnd_update (); } for (i = 0; i < MAP_LSSTAT_MAX; i++) { diff --git a/sdlgl/sdl_main.c b/sdlgl/sdl_main.c index b9336e3..d15727f 100644 --- a/sdlgl/sdl_main.c +++ b/sdlgl/sdl_main.c @@ -116,6 +116,7 @@ int msdl_eventloop () { GUIEvent gevent; static int oldkey = 0; + /* only the last MOUSEMOTION event will handled */ while (keeppoll && SDL_PollEvent (&lastevent)) { event = lastevent; gotevent = 1; @@ -141,24 +142,24 @@ int msdl_eventloop () { } break; case SDL_MOUSEMOTION: - gevent.mousepos.x = event.motion.x; - gevent.mousepos.y = event.motion.y; + gevent.scr_mpos.x = event.motion.x; + gevent.scr_mpos.y = event.motion.y; gevent.mousebtn = 0; gevent.event = EGUI_MOUSEMOVE; gui_event (gevent); break; case SDL_MOUSEBUTTONDOWN: - gevent.mousepos.x = event.motion.x; - gevent.mousepos.y = event.motion.y; + gevent.scr_mpos.x = event.motion.x; + gevent.scr_mpos.y = event.motion.y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSEPRESSED; gui_event (gevent); break; case SDL_MOUSEBUTTONUP: - gevent.mousepos.x = event.motion.x; - gevent.mousepos.y = event.motion.y; + gevent.scr_mpos.x = event.motion.x; + gevent.scr_mpos.y = event.motion.y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSERELEASED; gui_event (gevent); @@ -171,8 +172,8 @@ int msdl_eventloop () { keyu = oldkey = event.key.keysym.unicode; gevent.keyval = keyu; gevent.event = EGUI_KEYCHAR; - gevent.mousepos.x = -1; - gevent.mousepos.y = -1; + gevent.scr_mpos.x = -1; + gevent.scr_mpos.y = -1; if (gui_event (gevent) != 0) draw(); } } break; @@ -251,7 +252,6 @@ int msdl_eventloop () { */ - int main (int argc, char **argv) { SDL_Surface *scr; @@ -287,10 +287,8 @@ int main (int argc, char **argv) { } -void main_wnd_loop (long long int cur, long long int max) { -} - - void main_wnd_update () { +// d_printf ("main_wnd_update"); + while (msdl_eventloop ()); } diff --git a/wince/wince_gfx.c b/wince/wince_gfx.c index 947bfa5..597b098 100644 --- a/wince/wince_gfx.c +++ b/wince/wince_gfx.c @@ -157,7 +157,7 @@ void gfx_draw_line (struct image *dimg, int x1, int y1, int x2, int y2, struct l /* * draw polygon */ -void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_style style, struct color c) { +void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_style style, struct color *c) { static POINT *polygon = NULL; static int polygon_cnt = 0; int i; @@ -179,8 +179,8 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl polygon[i].y = p[i].y; } - tmp_brush = SelectObject (dimg->hdc, c.brush); - tmp_pen = SelectObject (dimg->hdc, c.pen); + tmp_brush = SelectObject (dimg->hdc, c->brush); + tmp_pen = SelectObject (dimg->hdc, c->pen); Polygon (dimg->hdc, polygon, pcnt); SelectObject (dimg->hdc, tmp_brush); SelectObject (dimg->hdc, tmp_pen); diff --git a/wince/wince_main.c b/wince/wince_main.c index c9734db..e7590c8 100644 --- a/wince/wince_main.c +++ b/wince/wince_main.c @@ -389,8 +389,8 @@ LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_LBUTTONUP: x = (lParam & 0xFFFF); y = (lParam >> 16); - gevent.mousepos.x = x; - gevent.mousepos.y = y; + gevent.scr_mpos.x = x; + gevent.scr_mpos.y = y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSERELEASED; if (gui_event (gevent) == 0) draw_mousebtnup (x, y, 1); @@ -398,8 +398,8 @@ LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDOWN: x = (lParam & 0xFFFF); y = (lParam >> 16); - gevent.mousepos.x = x; - gevent.mousepos.y = y; + gevent.scr_mpos.x = x; + gevent.scr_mpos.y = y; gevent.mousebtn = 1; gevent.event = EGUI_MOUSEPRESSED; if (gui_event (gevent) == 0) draw_mousebtndown (x, y, 1); @@ -407,8 +407,8 @@ LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: x = (lParam & 0xFFFF); y = (lParam >> 16); - gevent.mousepos.x = x; - gevent.mousepos.y = y; + gevent.scr_mpos.x = x; + gevent.scr_mpos.y = y; gevent.mousebtn = 0; gevent.event = EGUI_MOUSEMOVE; gui_event (gevent); @@ -417,7 +417,7 @@ LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) case WM_CHAR: if (wParam < ' ') gevent.keyval = 0xff00 | wParam; else gevent.keyval = wParam; - gevent.event = EGUI_KEYRELEASED; + gevent.event = EGUI_KEYCHAR; d_printf ("char wParam:%x keyval:%x", wParam, gevent.keyval); if (gui_event (gevent) != 0) draw(); break; @@ -455,12 +455,12 @@ void DoMenuActions(HWND hWnd, INT id) { { char *fn; // wince_taskbar (hWnd, TRUE); - fn = select_dir_dialog ("MapData", cfg.datapath); + fn = select_dir_dialog ("MapData", cfg.mappath); // wince_taskbar (hWnd, FALSE); if (fn) { - d_printf ("config: changed data path from '%s' to '%s'.", cfg.datapath, fn); + d_printf ("config: changed data path from '%s' to '%s'.", cfg.mappath, fn); map_clear(); - strncpy (cfg.datapath, fn, LEN_FILENAME); + strncpy (cfg.mappath, fn, LEN_FILENAME); map_clear(); draw_redrawmap (); }