Compare commits

..

96 Commits

Author SHA1 Message Date
steffen 374c865c36 memory optimisation
4 years ago
steffen 64b2f34043 increasing hasnoeds during convert
4 years ago
steffen b707c3fbd2 update
4 years ago
steffen 632afcf333 update
4 years ago
steffen 536a34160e android..
11 years ago
steffen 136a51f1f0 some fixes..
12 years ago
steffen 09b8c79772 fixes..
12 years ago
steffen 867acfafcd gui_list fixed, quit during routign fixed.
12 years ago
steffen e018fef72b gui_list fixed, quit during routign fixed.
12 years ago
steffen e93500869a gui_list fixed, quit during routign fixed.
12 years ago
steffen 3c01d729cd WindowsCE version
12 years ago
steffen 465eb3647f enabling detection of long button pressing..
12 years ago
steffen bb720fa2d8 enabling detection of long button pressing..
12 years ago
steffen c7d32001a0 gtk version is running again..
12 years ago
steffen 3c54de751f gtk version is running again..
12 years ago
steffen 52088304b9 changes..
12 years ago
steffen 87f0fac506 fixed makefile..
12 years ago
steffen fb279bdbb2 changes.. in android and quit code..
12 years ago
steffen dc3b085f0f android added compiler files
12 years ago
steffen f844e7e712 moving the map works different now..
12 years ago
steffen cc7d2dd753 added mouse button state on mousemove.
12 years ago
steffen eb328d6c47 speeding up things..
12 years ago
steffen 30cbec28c6 speeding up converting process.
12 years ago
steffen a96d5ccc04 adding routing..
13 years ago
steffen a6225615e6 softkeyboard adding enter key.
13 years ago
steffen f6afe7f426 softkeyboard adding enter key.
13 years ago
steffen 5e5ef1b898 softkeyboard fixed.. and moved to utf8
13 years ago
steffen d1afa786f9 softkeys fixed and moved to utf8
13 years ago
steffen b2db01d39c fixed searching..
13 years ago
steffen 9ecdcbcd13 need to rewrite search code again
13 years ago
steffen b63076aa3f need torewrite search code again..
13 years ago
steffen 01b9406ca3 added delete to entrys and search box..
13 years ago
steffen 60d26e354a changes..
13 years ago
steffen 4d21bcae1d utf8 decode works fine.
13 years ago
steffen 698cf67bd4 need to convert from utf8 to utf-32bit
13 years ago
steffen a8bfba1032 some fixes..
13 years ago
steffen 8cc646d18e font fixed..
13 years ago
steffen 56379bb493 gps seems to work on android now.
13 years ago
steffen bfbfe09312 some updates..
13 years ago
steffen 98347c53eb rotate only once..
13 years ago
steffen 33eb721c22 slowly it works..
13 years ago
steffen 98ad19dc03 slowly it works..
13 years ago
steffen 3bc2432a44 slowly it works..
13 years ago
steffen 5c0bfbe028 some fixes on splitting areas..
13 years ago
steffen 08d75cf3b5 resetting subid
13 years ago
steffen 48a81d7683 adding max subid to areas..
13 years ago
steffen 5d5fefe138 ncurses version fixed..
13 years ago
steffen 6eb422d368 displaying issues on opengles
13 years ago
steffen 168d3b386d osm_webload fixed.. refresh from openstreetmap.
13 years ago
steffen 6d74261ba5 fixing gui entry and gtk version
13 years ago
steffen 5832946569 adding memory dump...
13 years ago
steffen 095f214710 android is downloading data and accessing gps..
13 years ago
steffen 28f2b6b2ca fixed gui_listdir
13 years ago
steffen 804e195cd4 some changes..
13 years ago
steffen 5bab311f8a selecting map works..
13 years ago
steffen 7ef7965350 gui fixes..
13 years ago
steffen f6a5fb5a83 some changes gui and gps..
13 years ago
steffen ce4b8e828a some changes gui and gps..
13 years ago
steffen 5ff050d5b1 changes..
13 years ago
steffen 1cab6b20ac fixed checkbox..
13 years ago
steffen a1fb6bc179 android: gps seems to be running now. Strings will be transmitted between java and c++
13 years ago
steffen ede8fc0768 entry button should not have focus..
13 years ago
steffen 6527314883 adding java calls needed for android gps types..
13 years ago
steffen b1e2fca3f9 color is nowalways a pointer.
13 years ago
steffen 5057228a2e softkeyboard added, gui changed..
13 years ago
steffen 1a0e4a2af0 checkbox added, config screen seems slowly to work..
13 years ago
steffen a28bbd52a1 softkeyboard events..
13 years ago
steffen 1529314588 working on soft keyboard..
13 years ago
steffen b0143e2a8c softkey first steps..
13 years ago
steffen e752a97d6d working on the gui..
13 years ago
steffen c8eb9d6e0c ...
13 years ago
steffen afd9c27f83 changes..
13 years ago
steffen a5f20a0a64 config window..
13 years ago
steffen 01f66ec740 config window..
13 years ago
steffen 9aceb2934a guientry fixed.. also some other little bugfixes..
13 years ago
steffen cff2c9a7cf guientry fixed.. also some other little bugfixes..
13 years ago
steffen 68803c1921 gui events and items changed..
13 years ago
steffen 1f2310937e gui events and items changed..
13 years ago
steffen 49eff650b6 GUIList changes...
13 years ago
steffen 66d2be5f8a GUIList changes...
13 years ago
steffen 0da7441a73 updates..
13 years ago
steffen 87e6a631eb search dialog..
13 years ago
steffen beb62b5b03 adding screens..
13 years ago
steffen ec415d7a9f adding buttons to main menu..
13 years ago
steffen e4f9249428 some fixes..
13 years ago
steffen 36592a0d14 android... fixed stuff..
13 years ago
steffen 4817c88996 some fixes..
13 years ago
steffen 322630948e gui elements starting to work again..
13 years ago
steffen aecda8e878 working on the new gui structure..
13 years ago
steffen d09e264688 working on the new gui structure..
13 years ago
steffen 26cbac58f3 gui changes... still needs more work..
13 years ago
steffen 475db83d4c splitting into different files..
13 years ago
steffen 86ef5ffb33 update..
13 years ago
steffen fecfe775c2 update..
13 years ago
steffen bcac14b12f pressing mouse works..
13 years ago
steffen 4084e0475d gfx sdlgl verion slowly slowly..
13 years ago

@ -1,6 +1,85 @@
Version 0.0.2: name changed to spOSMroute, since on there had been another
OSMroute already.
=============================================================================
(2014-02-27):
- fixed: progressbar is back working again.
- fixed: during start up the draw_setscalef function wasn't called.
- got all systems back working again: Windows, WindowsCE, SDLGL, Android
and GTK
(2014-02-12):
- fixed: quiting while in routing did not work.
- fixed: gui_list elements where almost unable use.
(2014-02-05):
- fixed: windowsCE version is running again.
- fixed: pressing the button long time did not work.
(2014-01-20):
- fixed: disabled screensaver on Android
(2013-08-28):
- fixed: some search messages created a crash on 32bit systems.
- fixed: saving of last position works now from inside the main menu.
(2013-08-01):
- moving around the map works better.
(2013-07-23):
- added map_way_append_to_hash and map_area_append_to_hash to speedup
map_hash_realloc, which took most almost 30% of all time.
(2013-07-19):
- speeding up converting process.
(2013-06-17):
- fixed: softkeyboard is working now with utf8.
(2013-06-16):
- fixed: searching for citys is back working again and this time it seems
working fine.
(2013-06-09):
- fixed: utf8 will now also work in gui entry, delete and cursor movement
is also working now.
- fixed: changing map data location is working fine.
- fixed: on reloading the map, no need to change scale to draw the map.
(2013-06-06):
- fixed: utf8 will be displayed on OpenGL and OpenGLES devices correctly.
(2013-05-28):
- fixed: on android devices gps seems to work now fine.
(2013-05-15):
- fixed: areas will be split into peaces if there is an angle above 180°.
needed for displaying on GLES supported devices..
(2013-05-02):
- fixed: ncurses version fixed, the last patches made it impossible to
compile.
- fixed: areas haven't been updated right.
- added: areas have subid now.
- changed: saving subid within the id by shifting bits to the left.
saving 2 bytes each way.
- fixed: areas get split into different parts on each inside angle above 180°
should fix displaying issues on opengl and opengles devices.
(2013-03-11):
- rewrote most parts of the gui handling.
- added software keyboard.
- added config screen (config map, gps device, softkeyboard, debug).
(2013-02-14):
- android: changed to GLES2.0. Offscreen rendering works fine. Enabled
gui on android.

@ -20,7 +20,7 @@ sposmedit:
do if ! make -C $$i; then \
exit -2; \
fi done
$(CC) -o sposmedit -lmain -lncurses -lmapsys -lbase -lmain -Lbase -Lmapsys -Lmain `pkg-config --libs libxml-2.0` -lbz2 -ggdb -pg $(DEBUG)
$(CC) -o sposmedit -lm -lmain -lncurses -lmapsys -lbase -lmain -Lbase -Lmapsys -Lmain `pkg-config --libs libxml-2.0` -lbz2 -lm -ggdb -pg $(DEBUG)
cleanapp:
rm -rf sposmedit
@ -39,7 +39,7 @@ sposmroutegl:
do if ! make -C $$i; then \
exit -2; \
fi done
$(CC) -o sposmroute -lsdlgl -lmain -lgui -lmain -lmapsys -ldraw -lsdlgl -lbase -Lbase -Lmain -Lsdlgl -Ldraw -Lgui -Lmapsys -lbz2 $(DEBUG) `sdl-config --libs` `pkg-config --libs freetype2 libpng` -lGL -lGLU -L/usr/X11R6/lib -L/usr/lib
$(CC) -o sposmroute -lsdlgl -lm -lmain -lgui -lmain -lmapsys -ldraw -lsdlgl -lbase -lmain -Lbase -Lmain -Lsdlgl -Ldraw -Lgui -Lmapsys -lbz2 $(DEBUG) -lm `sdl-config --libs` `pkg-config --libs freetype2 libpng` -lm -lGL -lGLU -L/usr/X11R6/lib -L/usr/lib
cleanapp:
rm -rf sposmroutegl
endif
@ -56,7 +56,7 @@ sposmroute:
do if ! make -C $$i; then \
exit -2; \
fi done
$(CC) -o sposmroute -lgtk -lmapsys -lgui -ldraw -lmain -lbase -Lbase -Lmain -Lgtk -Ldraw -Lgui -Lmapsys `pkg-config --libs gtk+-2.0 libxml-2.0` -lbz2 $(DEBUG)
$(CC) -o sposmroute -lgtk -lmapsys -lgui -ldraw -lmain -lbase -lgui -Lbase -Lmain -Lgtk -Ldraw -Lgui -Lmapsys `pkg-config --libs gtk+-3.0 gmodule-export-2.0 libxml-2.0` -lbz2 -lm $(DEBUG)
cleanapp:
rm -rf sposmroute
@ -95,7 +95,8 @@ sposmroutece.exe:
do if ! make -C $$i; then \
exit -2; \
fi done
$(CC) -o sposmroutece.exe wince/wince.rsc -lwince -lmapsys -ldraw -lbase -lgui -lmain -Lbase -Lmain -Ldraw -Lgui -Lmapsys -Lwince $(LIBS) $(DEBUG)
$(CC) -o sposmroutece.exe wince/wince.rsc `for i in \`make -sf wince/Makefile displayobj\`; do echo wince/$$i; done` -ldraw -lmapsys -lgui -lmain -lbase -Lbase -Lmain -Ldraw -Lgui -Lmapsys -Lwince $(LIBS) $(DEBUG)
# $(CC) -o sposmroutece.exe wince/wince.rsc -lwince -lmapsys -ldraw -lbase -lgui -lmain -Lbase -Lmain -Ldraw -Lgui -Lmapsys -Lwince $(LIBS) $(DEBUG)
cleanapp:
rm -rf sposmroutece.exe
@ -115,7 +116,6 @@ endif
help:
echo "no configuration found yet, please run"
echo " make configwin to configure windows version"
@ -127,6 +127,9 @@ help:
configandroid: clean
cp -f Makefile.rules.android Makefile.rules
mkdir android/assets
cp -f data/*.ttf android/assets
cp -f data/*.png android/assets
for i in $(ANDROIDDIRS); do ln -s ../../$$i android/jni/ ; done
configwin: clean
@ -154,7 +157,9 @@ clean:
for i in $(NCURSESDIRS); do make -C $$i clean; done
for i in $(GTKDIRS); do make -C $$i clean; done
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
@ -165,6 +170,7 @@ cleanall:
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 sposmroute
rm -rf sposmroutegl

@ -6,7 +6,7 @@ DEPENDFILE = .depend
DEBUG = -ggdb -pg
AR = /usr/bin/ar
CC = /usr/bin/gcc
CFLAGS = -Wall -g -I../main -I../ -I../mapsys -I../gui -I../gtk -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_LOCALE_H -DHAVE_GTK `pkg-config --cflags libxml-2.0 gtk+-2.0` $(DEBUG) -Wl,--export-dynamic
CFLAGS = -Wall -g -I../main -I../ -I../mapsys -I../gui -I../gtk -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_LOCALE_H -DHAVE_GTK `pkg-config --cflags libxml-2.0 gtk+-3.0 gmodule-export-2.0` $(DEBUG) -Wl,--export-dynamic
%.o: %.c
$(CC) $(CFLAGS) -c $<

@ -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

@ -3,10 +3,10 @@
WINCEVERSION = 1
DEPENDFILE = .depend
DEBUG = -ggdb
AR = /opt/mingw32ce/bin/arm-mingw32ce-ar
CC = /opt/mingw32ce/bin/arm-mingw32ce-gcc
AR = arm-mingw32ce-ar
CC = arm-mingw32ce-gcc
CFLAGS = -Wall -g -I../main -I../ -I../mapsys -I../gui -I../wince -I../draw -I../base -DSPOSMROUTE -DHAVE_WINAPI -D_WIN32_IE=0x400 $(DEBUG)
WINRES = /opt/mingw32ce/bin/arm-mingw32ce-windres
WINRES = arm-mingw32ce-windres
LIBS = -lcommctrl -laygshell -lws2
%.o: %.c

@ -9,11 +9,11 @@
<uses-sdk android:minSdkVersion="9" />
<!-- This .apk has no Java code itself, so set hasCode to false. -->
<application android:label="@string/app_name" android:hasCode="false" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<application android:label="@string/app_name" android:hasCode="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
<activity android:name="de.gulpe.sposmroute.spOSMrNActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<!-- Tell NativeActivity the name of or .so -->
@ -26,10 +26,10 @@
</activity>
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>
<!-- END_INCLUDE(manifest) -->

@ -34,7 +34,7 @@ include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
FREETYPE_SRC_PATH := freetype2/
LOCAL_MODULE := freetype2-static
LOCAL_CFLAGS := -DANDROID_NDK -DFT2_BUILD_LIBRARY=1
LOCAL_CFLAGS := -DANDROID_NDK -DFT2_BUILD_LIBRARY=1 -DSPOSMROUTE
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/$(FREETYPE_SRC_PATH)/include \
$(LOCAL_PATH)/$(FREETYPE_SRC_PATH)/src
@ -72,15 +72,18 @@ LOCAL_CFLAGS := -DANDROID -DSPOSMROUTE -I$(LOCAL_PATH)/base -I$(LOCAL_PATH)/gui
-I$(LOCAL_PATH)/freetype2/include
LOCAL_SRC_FILES := \
main.c android_gfx.c android_font.c \
base/config.c base/memoryleak.c base/system.c base/vector.c \
base/config.c base/memoryleak.c base/system.c base/vector.c base/utf8.c \
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 gui/gui_checkbox.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/gui_selectfile.c \
main/linux_gps.c main/wnd_routing.c main/wnd_mapcontext.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

@ -4,6 +4,7 @@
#include "osmroute.h"
#include "system.h"
#include "utf8.h"
#include <ft2build.h>
#include FT_FREETYPE_H
@ -58,6 +59,7 @@ struct font* font_load(char *fname) {
FT_Set_Pixel_Sizes(f->face, 0, 16);
d_printf ("font loaded (size:%d).", f->buffersize);
FT_Select_Charmap(f->face, FT_ENCODING_UNICODE);
return f;
}
@ -69,6 +71,7 @@ struct font* font_load(char *fname) {
void font_draw (struct font *f, char *text, float x, float y, float sx, float sy) {
char *p;
int i;
uint32_t u8chr;
GLfloat vp[12] = { 0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
@ -99,10 +102,16 @@ void font_draw (struct font *f, char *text, float x, float y, float sx, float sy
glUniform1i(engine.gles_txsampler, 0);
/* Loop through all characters */
for (p = text; *p; p++) {
for (p = text; *p;) {
u8chr = u8_decode (p, &i);
if (i == 0) {
p++;
continue;
}
p = p + i;
/* Try to load and render the character */
if ((i = FT_Load_Char(f->face, *p, FT_LOAD_RENDER))) {
if ((i = FT_Load_Char(f->face, u8chr, FT_LOAD_RENDER))) {
d_printf ("error:%d", i);
continue;
}
@ -121,8 +130,8 @@ void font_draw (struct font *f, char *text, float x, float y, float sx, float sy
glVertexAttribPointer (engine.gles_txcoord, 2, GL_FLOAT, GL_FALSE, 0, vt);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glVertexAttribPointer (engine.gles_pos, 3, GL_FLOAT, GL_FALSE, 0, vp);
glDrawArrays(GL_LINES,0,2);
// glVertexAttribPointer (engine.gles_pos, 3, GL_FLOAT, GL_FALSE, 0, vp);
// glDrawArrays(GL_LINES,0,2);
/* Advance the cursor to the start of the next character */

@ -239,7 +239,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 GLfloat *polygon = NULL;
static int polygon_cnt = 0;
int i;
@ -262,9 +262,19 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl
glUseProgram (engine.gles_prgobject);
glUniform1i (engine.gles_txenabled, 0);
glUniform4fv(engine.gles_color, 1, c.c.array);
glUniform4fv(engine.gles_color, 1, c->c.array);
glVertexAttribPointer (engine.gles_pos, 3, GL_FLOAT, GL_FALSE, 0, polygon);
glDrawArrays (GL_TRIANGLE_FAN, 0, pcnt);
// if (style.width < 1.0) style.width = 1.0;
// glLineWidth (style.width);
//
// glUseProgram (engine.gles_prgobject);
// glUniform1i (engine.gles_txenabled, 0);
// glUniform4fv(engine.gles_color, 1, style.c.c.array);
// glVertexAttribPointer (engine.gles_pos, 3, GL_FLOAT, GL_FALSE, 0, polygon);
// glDrawArrays (GL_LINE_LOOP, 0, pcnt);
};
@ -556,3 +566,8 @@ struct image* gfx_img_load (char *name) {
return img;
};
/******************************************************************
* convert polygon into triangles..
*/

@ -17,14 +17,13 @@
#include <jni.h>
#include <errno.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>
#include "android_port.h"
#include "osmroute.h"
#include "gui.h"
#include "system.h"
@ -32,78 +31,15 @@
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sposmroute", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "sposmroute", __VA_ARGS__))
#define MAX_EVENTS 128
GUIEvent eventlist[MAX_EVENTS] = {0};
int eventcnt = 0;
struct engine engine;
/*************************************************************************
*
* only needed for testing
*
*************************************************************************/
struct image *img, *img1;
void test_img () {
struct line_style style;
d_printf ("*** test_img () ***");
style.width = 1;
style.c = color[COLOR_green][3];
img = gfx_img_alloc (400, 300);
gfx_clear (img, &color[COLOR_blue][2]);
img1 = gfx_img_load ("sample_01.png");
gfx_draw_img (img, 10, 10, 150, 150, img1, 100, 250);
gfx_draw_text (img, 20, 10, "sample_01.png nur ein toller test bla bla", &color[COLOR_yellow][3]);
gfx_draw_text (img, 20, 30, "sample_01.png nur ein toller test bla bla", &color[COLOR_yellow][3]);
gfx_draw_text (NULL, 20, 10, "sample_01.png nur ein toller test bla bla", &color[COLOR_yellow][3]);
gfx_draw_text (NULL, 20, 30, "sample_01.png nur ein toller test bla bla", &color[COLOR_yellow][3]);
gfx_draw_line (img, 0, 0, 200, 200, style);
};
#define TEST_WIDTH 200
void test_draw () {
static int once = 1;
static int _tmpx, _tmpy = 0;
static int _tmpdx = 1, _tmpdy = 1;
struct line_style style;
GLfloat vp[] = {500, 210, 540, 210};
gfx_clear (NULL, &color[COLOR_white][0]);
if (once) {
once = 0;
test_img ();
}
if (_tmpx > img->width-TEST_WIDTH) _tmpdx = -1;
if (_tmpx < 0) _tmpdx = 1;
_tmpx += _tmpdx;
if (_tmpy > img->height-TEST_WIDTH) _tmpdy = -1;
if (_tmpy < 0) _tmpdy = 1;
_tmpy += _tmpdy;
style.width = 1;
style.c = color[COLOR_white][3];
gfx_draw_line (NULL, 0, gfx_screensize.y, gfx_screensize.x, 0, style);
gfx_draw_line (NULL, gfx_screensize.x, gfx_screensize.y, 0, 0, style);
glLineWidth (style.width);
gfx_draw_img (NULL, 10, 10, TEST_WIDTH, TEST_WIDTH, img, _tmpx, _tmpy);
style.c = color[COLOR_yellow][3];
gfx_draw_line (NULL, gfx_screensize.x, 0, 0, 10, style);
gfx_draw_text (NULL, 10, 300, "sollte gehen", &color[COLOR_red][3]);
gfx_draw_img (NULL, 20, 320, 150, 150, img1, 200, 200);
gfx_flip();
};
int gevent_push (GUIEvent *event);
int gevent_pop (GUIEvent *event);
void gevent_clear ();
struct engine engine;
/**
* Initialize an EGL context for the current display.
@ -163,7 +99,6 @@ static int engine_init_display(struct engine* engine) {
engine->width = w;
engine->height = h;
engine->state.angle = 0;
gfx_init (w, h);
return 0;
}
@ -191,6 +126,7 @@ static void engine_term_display(struct engine* engine) {
/**
* Process the next input event.
* save events inside a EVENT list.
*/
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) {
GUIEvent gevent;
@ -199,27 +135,26 @@ 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);
gevent_push (&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);
return;
gevent_push (&gevent);
return 1;
}
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);
return;
gevent_push (&gevent);
return 1;
}
}
@ -297,6 +232,56 @@ 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;
int t = 0;
GUIEvent event;
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;
}
}
while (gevent_pop(&event)) {
gui_event (event);
}
t1 = time(NULL);
if (t1 != t2) {
t2 = t1;
app_loop ();
}
}
/**
* 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
@ -331,66 +316,129 @@ void android_main(struct android_app* state) {
app_init (0, NULL);
// loop waiting for stuff to do.
while (1) {
// Read all pending events.
int ident;
int events;
struct android_poll_source* source;
while (app.status != APPSTATUS_quit) {
main_event ();
}
d_printf ("shutdown?");
app_shutdown ();
exit (0);
}
// 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(engine.animating ? 0 : -1, 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);
}
}
/*************************************************************************
* main functions for sposmroute...
*/
void main_wnd_update () {
main_event ();
}
/*************************************************************************
*
* calling java code here for using the internal GPS devices.
*
*************************************************************************/
int gps_android_device_open () {
d_printf ("gps_android_device_open:");
ANativeActivity* activity = engine.app->activity;
JavaVM* jvm = engine.app->activity->vm;
JNIEnv* env = NULL;
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
if (res == JNI_ERR) {
// Failed to retrieve JVM environment
d_printf ("gps_android_device_open: JNI_Error");
return 0;
}
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStart", "()V");
(*env)->CallVoidMethod(env, activity->clazz, methodID);
(*jvm)->DetachCurrentThread(jvm);
return 1;
};
// Check if we are exiting.
if (state->destroyRequested != 0) {
engine_term_display(&engine);
void gps_android_device_close () {
d_printf ("gps_android_device_close:");
ANativeActivity* activity = engine.app->activity;
JavaVM* jvm = engine.app->activity->vm;
JNIEnv* env = NULL;
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
if (res == JNI_ERR) {
// Failed to retrieve JVM environment
d_printf ("gps_android_device_close: JNI_Error");
return;
}
}
if (engine.animating) {
// Done with events; draw next animation frame.
engine.state.angle += .01f;
if (engine.state.angle > 1) {
engine.state.angle = 0;
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataStop", "()V");
(*env)->CallVoidMethod(env, activity->clazz, methodID);
(*jvm)->DetachCurrentThread(jvm);
return;
};
int gps_android_device_read (char *ptr, int ptrsize) {
ANativeActivity* activity = engine.app->activity;
JavaVM* jvm = engine.app->activity->vm;
JNIEnv* env = NULL;
jstring jstr;
const char *str;
d_printf ("gps_android_device_read:");
(*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6);
jint res = (*jvm)->AttachCurrentThread(jvm, &env, NULL);
if (res == JNI_ERR) {
// Failed to retrieve JVM environment
d_printf ("gps_android_device_read: JNI_Error");
return 0;
}
// Drawing is throttled to the screen update rate, so there
// is no need to do timing here.
draw();
// test_draw ();
/* call up the java method to prepare a new line */
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
jmethodID methodID = (*env)->GetMethodID(env, clazz, "GPSDataGetLine", "()V");
(*env)->CallVoidMethod(env, activity->clazz, methodID);
/* retrieve the new line, copy new line, release new line */
jfieldID fid = (*env)->GetFieldID(env, clazz, "gpsline", "Ljava/lang/String;");
jstr = (*env)->GetObjectField(env, activity->clazz, fid);
str = (*env)->GetStringUTFChars(env, jstr, 0);
if (str != NULL) {
// d_printf ("str:ptrsize:%d strsize:%d '%s'", ptrsize, strlen(str), str);
strncpy (ptr, str, ptrsize);
}
else ptr[0] = 0;
(*env)->ReleaseStringUTFChars(env, jstr, str);
(*jvm)->DetachCurrentThread(jvm);
return strlen (ptr);
};
int gevent_push (GUIEvent *event) {
if (eventcnt < MAX_EVENTS) {
memcpy (&eventlist[eventcnt], event, sizeof (GUIEvent));
eventcnt++;
return 1;
}
}
return 0;
};
/*************************************************************************
* main functions for sposmroute...
*/
void main_wnd_loop (long long int cur, long long int max) {
}
int gevent_pop (GUIEvent *event) {
if (eventcnt > 0) {
eventcnt--;
memcpy (event, &eventlist[eventcnt], sizeof (GUIEvent));
return 1;
}
return 0;
};
void gevent_clear () {
int i;
void main_wnd_update () {
}
memset (eventlist, 0x0, MAX_EVENTS * sizeof (GUIEvent));
};

@ -0,0 +1,85 @@
package de.gulpe.sposmroute;
import android.app.NativeActivity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.content.Context;
import android.location.GpsStatus.NmeaListener;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
public class spOSMrNActivity extends NativeActivity {
private static final String TAG = "spOSMroute Java";
spOSMrNActivity _activity;
String gpsline;
String nmealine;
boolean started = false;
private LocationManager mLocMan;
private LocationListener mLocListener;
public void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mLocMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocListener = new MyLocationListener();
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocListener);
mLocMan.addNmeaListener(new NmeaListener() {
public void onNmeaReceived(long timestamp, String nmea) {
if (started) {
nmealine = nmealine + nmea;
}
// Log.i(TAG, "GPSData (cur nmea:"+nmealine+")");
}
});
super.onCreate(savedInstanceState);
_activity = this;
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
// get gps data fill one line into gpsline
public void GPSDataGetLine() {
// Log.i(TAG, "GPSDataGetLine called sending:'"+nmealine+"'");
gpsline = nmealine;
nmealine = "";
}
// start gps part
public void GPSDataStart() {
Log.i(TAG, "GPSDataStart called");
started = true;
}
// stop gps part
public void GPSDataStop() {
Log.i(TAG, "GPSDataStop called");
started = false;
}
// Do some cleanup
@Override
public void onDestroy() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onDestroy();
}
}

@ -3,7 +3,8 @@ include ../Makefile.rules
OBJBASE = config.o \
system.o \
vector.o \
memoryleak.o
memoryleak.o \
utf8.o
OBJ = $(OBJBASE)
SRC = $(OBJ:%.o=%.c)

@ -54,7 +54,7 @@ void config_init () {
struct stat sb;
strcpy (cfg.mappath, "map/");
strcpy (cfg.appdatapath, "android/assets");
strcpy (cfg.appdatapath, "data");
strcpy (cfg.cachepath, "cache/");
strcpy (cfg.configpath, "");
strcpy (cfg.logpath, "logs/");
@ -63,36 +63,41 @@ 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)
if (engine.app->activity->internalDataPath == NULL)
strcpy (cfg.appdatapath, "android/assets");
if (engine.app->activity->internalDataPath == NULL) {
strncpy (cfg.configpath, "/data/data/de.gulpe.sposmroute/", LEN_FILENAME);
else
strncpy (cfg.logpath, "/data/data/de.gulpe.sposmroute/", LEN_FILENAME);
}
else {
strncpy (cfg.configpath, engine.app->activity->internalDataPath, LEN_FILENAME);
strncpy (cfg.logpath, engine.app->activity->internalDataPath, LEN_FILENAME);
}
/* std::string dataPath(internalPath);
// internalDataPath points directly to the files/ directory
std::string configFile = dataPath + "/app_config.xml";
*/
#else
/* windows ce version */
#if defined(__MINGW32CE__) || defined(_WIN32_WCE)
#if defined(__MINGW32CE__) || defined(_WIN32_WCE)
strcpy (cfg.mappath, "\\Storage Card\\map\\");
strcpy (cfg.configpath, "\\My Documents\\wOSMroute\\");
strcpy (cfg.logpath, "\\My Documents\\wOSMroute\\Logdir\\");
#endif
#endif
/* windows version */
#if defined(__MINGW32__) && !defined(__MINGW32CE__) && !defined(_WIN32_WCE)
#if defined(__MINGW32__) && !defined(__MINGW32CE__) && !defined(_WIN32_WCE)
TCHAR szPath[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0, szPath))) {
snprintf (cfg.configpath, LEN_FILENAME, "%s\\wOSMroute\\", szPath);
snprintf (cfg.logpath, LEN_FILENAME, "%s\\wOSMroute\\Logdir\\", szPath);
}
#endif
#endif
/* linux version */
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
char *hd;
if ((hd = getenv ("HOME")) == NULL) {
@ -104,7 +109,7 @@ void config_init () {
snprintf (cfg.configpath, LEN_FILENAME, "%s/.OSMroute/", hd);
snprintf (cfg.logpath, LEN_FILENAME, "%s/.OSMroute/Logdir/", hd);
}
#endif
#endif
d_print_init();
if (stat(cfg.configpath, &sb) == -1) {
@ -112,12 +117,15 @@ void config_init () {
strncpy (fn, cfg.configpath, LEN_FILENAME);
fn[strlen(fn)-1] = 0;
d_printf ("create config dir:%s", fn);
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
mkdir (fn, 0755);
#else
#else
mkdir (fn);
#endif
#endif
}
#endif
config_load ();
if (stat(cfg.logpath, &sb) == -1) {
char fn[LEN_FILENAME];
@ -130,9 +138,28 @@ void config_init () {
mkdir (fn);
#endif
}
if (stat(cfg.mappath, &sb) == -1) {
char fn[LEN_FILENAME];
strncpy (fn, cfg.mappath, LEN_FILENAME);
fn[strlen(fn)-1] = 0;
d_printf ("create map dir:%s", fn);
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
mkdir (fn, 0755);
#else
mkdir (fn);
#endif
config_load ();
}
config_save ();
#if defined(SPOSMROUTE)
if (cfg.gps_flags) SETFLAG(gpsflags, GPSF_LOG);
else DELFLAG(gpsflags, GPSF_LOG);
if (cfg.debug) SETFLAG(view_flags, DRAW_DEBUG);
else DELFLAG(view_flags, DRAW_DEBUG);
#endif
};
@ -176,6 +203,8 @@ void config_load () {
strncpy (cfg.mappath, value, LEN_FILENAME);
if (!strcmp (keyword, "temppath"))
strncpy (cfg.temppath, value, LEN_FILENAME);
if (!strcmp (keyword, "cachepath"))
strncpy (cfg.cachepath, value, LEN_FILENAME);
if (!strcmp (keyword, "logpath"))
strncpy (cfg.logpath, value, LEN_FILENAME);
#if defined(SPOSMROUTE)
@ -193,6 +222,9 @@ void config_load () {
if (!strcmp (keyword, "debug")) {
cfg.debug = atoi (value);
}
if (!strcmp (keyword, "softkeyboard")) {
cfg.softkeyboard = atoi (value);
}
#endif
}
fclose (f);
@ -220,6 +252,7 @@ void config_save () {
fprintf (f, "# config file for osmroute\n\n");
fprintf (f, "mappath=%s\n", cfg.mappath);
fprintf (f, "logpath=%s\n", cfg.logpath);
fprintf (f, "cachepath=%s\n", cfg.cachepath);
fprintf (f, "temppath=%s\n", cfg.temppath);
#if defined(SPOSMROUTE)
fprintf (f, "last_lon=%f\n", cfg.last_lon);
@ -229,6 +262,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);
}

@ -92,7 +92,7 @@ int execwait (struct s_execcall *p) {
#endif
#ifndef ANDROID
// #ifndef ANDROID
void d_printf (char *fmt,...) {
va_list args;
char text1[1024];
@ -103,14 +103,14 @@ void d_printf (char *fmt,...) {
// return;
#endif
va_start (args, fmt);
vsnprintf (text1, 1024, fmt, args);
vsnprintf (text1, 1023, fmt, args);
va_end (args);
text1[1023] = 0;
text2[1023] = 0;
snprintf (fn, LEN_FILENAME, "%slogfile.txt", cfg.logpath);
snprintf (text2, 1024, "%-6d %s", (int)(time(NULL) - starttime), text1);
snprintf (text2, 1023, "%-6d %s", (int)(time(NULL) - starttime), text1);
#ifndef COSMROUTE
fprintf (stderr, "%s\n", text2);
@ -128,7 +128,7 @@ void d_printf (char *fmt,...) {
close (f);
}
};
#endif
// #endif
void d_print_init() {
@ -169,6 +169,38 @@ void d_print_init() {
};
#define D_PRINT_COL 16
void d_print_data (char *data, int len) {
int i, j;
int val;
char txt1 [256] = {0};
char txt2 [256] = {0};
char left [256] = {0};
char right [256] = {0};
d_printf ("memdump: len:%d", len);
for (i = 0; i < len; i++) {
val = data[i] & 0x00FF;
sprintf (txt1, "%2x ", val);
if (data[i] >= ' ' && data[i] <= '~') sprintf (txt2, "%c", data[i]);
else sprintf (txt2, ".");
strncat (left, txt1, 256);
strncat (right, txt2, 256);
if ((i%D_PRINT_COL)==D_PRINT_COL-1 || i == len-1) {
sprintf (txt1, " ");
sprintf (txt2, " ");
for (j = i%D_PRINT_COL; j != 0 && j < D_PRINT_COL; j++) {
strncat (left, txt1, 256);
strncat (right, txt2, 256);
}
d_printf (" |%s | %s |", left, right);
memset (left, 0x0, 256);
memset (right, 0x0, 256);
}
}
};
unsigned long long int getticks () {
static unsigned long long int ticks = 0;
@ -303,24 +335,24 @@ void memswap (void *mem1, void *mem2, int size) {
};
#endif
struct stat *file_exist (char *fn) {
static struct stat fs;
int file_exist (char *fn) {
struct stat fs;
if (stat(fn, &fs) != 0)
return NULL;
return 0;
return &fs;
return 1;
};
struct stat *dir_exist (char *fn) {
static struct stat fs;
int dir_exist (char *fn) {
struct stat fs;
if (stat(fn, &fs) == 0) {
if (S_ISDIR(fs.st_mode))
return &fs;
return 1;
}
return NULL;
return 0;
}

@ -54,11 +54,14 @@
#if defined(__MINGW32CE__) || defined(_WIN32_WCE)
#define DIR_SEP '/'
#define ROOT_DIR "/"
#else
#if defined(__MINGW32__)
#define DIR_SEP '\\'
#define ROOT_DIR "C:\\"
#else
#define DIR_SEP '/'
#define ROOT_DIR "/"
#endif
#endif
@ -87,7 +90,8 @@ extern int cmpd (double d1, double d2);
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sposmroute", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "sposmroute", __VA_ARGS__))
#define d_printf(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sposmroute", __VA_ARGS__))
// #define d_printf(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sposmroute", __VA_ARGS__))
extern void d_printf (char *fmt,...);
#else
extern void d_printf (char *fmt,...);
@ -95,6 +99,7 @@ extern void d_printf (char *fmt,...);
extern void d_print_init();
extern void d_print_backtrace ();
extern void d_print_stat ();
extern void d_print_data (char *data, int len);
extern void errorexit (int nr);
extern int execcall (struct s_execcall *p, char *prg, char **argv);
@ -111,8 +116,8 @@ extern char *memstrpop (void *mem, void *dest, int *size);
extern void memswap (void *mem1, void *mem2, int size); // maximum 32 bytes
#endif
struct stat *file_exist (char *fn);
struct stat *dir_exist (char *fn);
int file_exist (char *fn);
int dir_exist (char *fn);
extern char* flags2text (int f, char *text);

@ -0,0 +1,238 @@
/* $Id: utf8.c,v 1.3 2013/06/09 20:11:30 steffen Exp $ */
/* utf8.c
* Copyright (C) Steffen Pohle 2013 <steffen@gulpe.de>
*
* spOSMroute 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.
*
* spOSMroute 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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <strings.h>
#include "system.h"
#include "utf8.h"
/*
* 84218421 84218421 84218421 84218421
* -----------------------------------
* 00000000 00000000 00000000 0aaaaaaa = FF FF FF 80 > 0
* 00000000 00000000 00000bbb bbaaaaaa = FF FF F8 00 > 1
* 00000000 00000000 ccccbbbb bbaaaaaa = FF FF 00 00 > 2
* 00000000 000dddcc ccccbbbb bbaaaaaa = FF E0 00 00 > 3
* 000000ee ddddddcc ccccbbbb bbaaaaaa = FC 00 00 00 > 4
* 0feeeeee ddddddcc ccccbbbb bbaaaaaa > 5
*/
void u8_encode (char *dest, uint32_t key) {
uint8_t maskor = 0;
uint8_t maskand = 0;
int blocks = 0;
if ((key & 0xFFFFFF80) == 0) {
blocks = 0;
maskand = 0x7F;
maskor = 0x00;
}
else if ((key & 0xFFFFF800) == 0) {
blocks = 1;
maskand = 0x1F;
maskor = 0xC0;
}
else if ((key & 0xFFFF0000) == 0) {
blocks = 2;
maskand = 0x0F;
maskor = 0xE0;
}
else if ((key & 0xFFE00000) == 0) {
blocks = 3;
maskand = 0x07;
maskor = 0xF0;
}
else if ((key & 0xFC000000) == 0) {
blocks = 4;
maskand = 0x03;
maskor = 0xF8;
}
else {
blocks = 5;
maskand = 0x01;
maskor = 0xFC;
}
dest[blocks+1] = 0;
while (blocks>0) {
dest[blocks] = (uint8_t)((key & 0x3F) | 0x80);
key = key >> 6;
blocks--;
}
*dest = (key & maskand) | maskor;
};
uint32_t u8_decode (char *str, int *charsize) {
uint32_t chr = 0;
int block = 0;
uint8_t c = 0;
/* check how many elements */
c = *str;
if ((c & 0x80) == 0) {
block = 0;
chr = c;
}
else if ((c & 0xE0) == 0xC0) { // (str[0] & 111x xxxx) == 110x xxxx
block = 1;
chr = c & 0x1F;
}
else if ((c & 0xF0) == 0xE0) { // (str[0] & 1111 xxxx) == 1110 xxxx
block = 2;
chr = c & 0x0F;
}
else if ((c & 0xF8) == 0xF0) { // (str[0] & 1111 1xxx) == 1111 0xxx
block = 3;
chr = c & 0x07;
}
else if ((c & 0xFC) == 0xF8) { // (str[0] & 1111 11xx) == 1111 10xx
block = 4;
chr = c & 0x03;
}
else if ((c & 0xFE) == 0xFC) { // (str[0] & 1111 111x) == 1111 110x
block = 5;
chr = c & 0x01;
}
else {
/* error: no valid code */
if (charsize != NULL) *charsize = 0;
return 0;
}
if (charsize != NULL) *charsize = block+1; /* return size in bytes for utf8 char */
str++;
for (;block > 0; block--) {
c = *str;
if ((c & 0xC0) != 0X80) {
/* error: no valid code */
*charsize = 0;
return 0;
}
chr <<= 6;
chr |= (c & 0x3F);
str++;
}
return chr;
};
/* return the size in chars not in bytes. */
int u8_strlen (char *str) {
int cnt, i, j;
int bytelen = strlen (str);
for (cnt = 0, i = 0; i < bytelen;) {
if (u8_decode (str+i, &j) == 0) {
d_printf ("u8_strlen: something went wrong. str:%s i:%d str+i:%s", str, i, str+i);
return 0;
}
cnt++;
i += j;
}
return cnt;
};
void u8_strcpy (char *dest, char *src, int pos, int len) {
int curpos = 0;
int size = 0;
while (*src != 0 && curpos < pos+len) {
u8_decode (src, &size);
if (curpos >= pos) {
memcpy (dest, src, size);
dest += size;
}
curpos++;
src += size;
}
*dest = 0;
};
void u8_strncat (char *dest, int size, char *src) {
int len;
len = strlen (src)+1;
if (len + strlen(dest) > size)
len = size - strlen(dest) - 1;
memcpy (dest+strlen(dest), src, len);
dest[size-1] = 0;
};
void u8_strdel (char *str, int start, int len) {
int curpos = 0;
char *nstr = str;
int slen = u8_strlen (str);
int size = 0;
int clen = strlen (str);
while (*nstr != 0 && curpos < slen) {
u8_decode (nstr, &size);
if (curpos >= start && curpos < start+len) memmove (nstr, nstr+size, clen-(nstr-str));
else nstr += size;
curpos++;
}
*nstr = 0;
};
void u8_strninsert (char *str, int size, char *text, int pos) {
char *nstr = str;
int curpos = 0;
int chrsize = 0;
int len = u8_strlen (str);
int clen = strlen (str);
while (curpos <= len && curpos <= pos) { // no need to move
if (curpos == pos) {
int cnt = strlen (text);
if (nstr-str + cnt >= size) {
memcpy (nstr, text, size-(nstr-str)-1);
str[size-1] = 0;
break;
}
else if (clen + strlen(text) >= size) { // need to move only part
memmove (nstr+cnt, nstr, size-(nstr-str)-strlen(text));
str[size-1] = 0;
}
else { // no overrun
memmove (nstr+cnt, nstr, clen-(nstr-str));
str[clen+cnt] = 0;
}
memcpy (nstr, text, strlen(text));
break;
}
u8_decode (nstr, &chrsize);
curpos++;
nstr += chrsize;
}
};

@ -0,0 +1,34 @@
/* $Id: utf8.h,v 1.4 2021/07/06 20:52:00 steffen Exp $ */
/* utf8.h
* Copyright (C) Steffen Pohle 2013 <steffen@gulpe.de>
*
* spOSMroute 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.
*
* spOSMroute 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _UTF8_H_
#define _UTF8_H_
#include <stdint.h>
uint32_t u8_decode (char *str, int *size);
void u8_encode (char *dest, uint32_t key);
int u8_strlen (char *str);
void u8_strcpy (char *dest, char *src, int pos, int len);
void u8_strncat (char *dest, int size, char *src);
void u8_strdel (char *str, int start, int len);
void u8_strninsert (char *str, int size, char *text, int pos);
#endif

@ -21,10 +21,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include "osmroute.h"
#include "vector.h"
fPoint vec_add (fPoint veca, fPoint vecb) {
inline fPoint vec_add (fPoint veca, fPoint vecb) {
fPoint r;
r.x = veca.x + vecb.x;
@ -34,7 +35,7 @@ fPoint vec_add (fPoint veca, fPoint vecb) {
};
fPoint vec_sub (fPoint veca, fPoint vecb) {
inline fPoint vec_sub (fPoint veca, fPoint vecb) {
fPoint r;
r.x = veca.x - vecb.x;
@ -108,3 +109,23 @@ fPoint vec_mul (fPoint v, float f) {
a.y = f * v.y;
return a;
};
/* calc angle of three points assuming v2 is the center.. */
float point_angle (fPoint v1, fPoint v2, fPoint v3) {
float a1;
float a3;
float delta;
v1 = vec_sub (v1, v2);
v3 = vec_sub (v3, v2);
a1 = atan2f (v1.y, v1.x);
a3 = atan2f (v3.y, v3.x);
if (a1 < 0.0) a1 += 2.0*M_PI;
if (a3 < 0.0) a3 += 2.0*M_PI;
if ((delta = a1-a3) < 0.0) delta += 2.0*M_PI;
return delta;
};

@ -35,4 +35,6 @@ extern fPoint vec_mirror (fPoint veca);
extern float vec_len (fPoint veca);
extern fPoint vec_mul (fPoint v, float f);
extern float point_angle (fPoint v1, fPoint v2, fPoint v3);
#endif

Binary file not shown.

Binary file not shown.

@ -151,6 +151,7 @@ void draw_setscalef (float newscale) {
break;
default:
draw_type [i] = FALSE;
break;
}
}
}
@ -166,6 +167,7 @@ void draw_setscalef (float newscale) {
break;
default:
draw_type [i] = FALSE;
break;
}
}
}
@ -196,7 +198,7 @@ void draw_init () {
view_lon = cfg.last_lon;
view_lat = cfg.last_lat;
view_scale = cfg.last_scale;
draw_setscalef (cfg.last_scale);
};
void draw_init_color () {
@ -282,7 +284,7 @@ void draw_init_color () {
case (MWAY_unknown):
case (MWAY_unknown_way):
default:
gfx_color_alloc (&draw_linestyle[n].c, 0x7000,0x5000,0x5000);
gfx_color_alloc (&draw_linestyle[n].c, 0xA000,0x5000,0x5000);
break;
}
}
@ -339,6 +341,22 @@ void draw_rectangle (struct image *dimg, int x1, int y1, int x2, int y2, struct
};
void draw_fillrectangle (struct image *dimg, int x1, int y1, int x2, int y2, struct color *c) {
struct line_style ls;
ls.c = *c;
ls.borderc = *c;
ls.width = 1.0;
iPoint points[4] = { {x1, y1},
{x2, y1},
{x2, y2},
{x1, y2} };
gfx_draw_polygon (dimg, points, 4, ls, c);
};
/*
* lines
*/
@ -383,7 +401,7 @@ void draw_polygonadd (int x, int y) {
};
void draw_polygonfinish (struct image *dimg, struct line_style ls, struct color c, int border) {
void draw_polygonfinish (struct image *dimg, struct line_style ls, struct color *c, int border) {
int i;
gfx_draw_polygon (dimg, _polypoints, _polycnt, ls, c);
@ -467,16 +485,22 @@ void draw_map () {
|| ((view_scale < 0.1 && (n % 2) == 0) || carea->p_cnt < 5)
|| ((view_scale < 0.1 && (n % 4) == 0) || carea->p_cnt < 10)) {
p1 = draw_geo2screen (view_lon, view_lat, carea->p[n].lon, carea->p[n].lat);
// if (n == 0) {
// draw_line (img_map, p1.x + center.x - 5, p1.y + center.y - 5, p1.x + center.x + 5, p1.y + center.y + 5, tmplinestyle);
// draw_line (img_map, p1.x + center.x + 5, p1.y + center.y - 5, p1.x + center.x - 5, p1.y + center.y + 5, tmplinestyle);
// }
// if (n == 0) sprintf (text, "%d:%d", n, carea->subid);
// else sprintf (text, "%d", n);
// gfx_draw_text (img_map, p1.x + center.x - 20, p1.y + center.y - 10, text, &color[COLOR_white][3]);
draw_polygonadd (p1.x + center.x, p1.y + center.y);
}
draw_polygonfinish (img_map, tmplinestyle, color_polygon[carea->type], 0);
draw_polygonfinish (img_map, tmplinestyle, &color_polygon[carea->type], 0);
}
carea = carea->next;
}
}
}
/*
* draw ways
*/
@ -661,7 +685,6 @@ void draw_map () {
}
}
/*
* draw places, pois just on top layers
*/
@ -724,6 +747,7 @@ void draw_map () {
default:
sprintf (text, "?");
c = &color[COLOR_red][3];
break;
}
gfx_draw_text (img_map, p1.x-4, p1.y-4, text, c);
gfx_draw_text (img_map, p1.x-strlen(cpoi->name)*2, p1.y+8, cpoi->name, c);

@ -137,10 +137,10 @@ extern void draw_redrawmap ();
extern void draw_line (struct image *img, int x1, int y1, int x2, int y2, struct line_style style);
extern void draw_lineway (struct image *img, int x1, int y1, int x2, int y2, struct line_style style);
extern void draw_rectangle (struct image *img, int x1, int y1, int x2, int y2, struct line_style style);
extern void draw_fillrectangle (struct image *img, int x1, int y1, int x2, int y2, struct color *c);
extern void draw_polygonstart ();
extern void draw_polygonadd (int x, int y);
extern void draw_polygonfinish (struct image *img, struct line_style ls, struct color c, int border);
extern void draw_polygonfinish (struct image *img, struct line_style ls, struct color *c, int border);
/*
@ -155,8 +155,8 @@ extern int gfx_color_alloc (struct color *c, unsigned short int r, unsigned shor
extern void gfx_draw_img (struct image *dimg, int dx, int dy, int dw, int dh, struct image *simg, int sx, int sy);
extern void gfx_draw_line (struct image *dimg, int x1, int y1, int x2, int y2, struct line_style style);
extern void gfx_draw_text (struct image *dimg, int x, int y, char *text, struct color *c);
extern void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_style style, struct color c);
extern void gfx_draw_rect (struct image *dimg, int x1, int y1, int x2, int y2, struct color *c);
extern void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_style style, struct color *c);
// extern void gfx_draw_rect (struct image *dimg, int x1, int y1, int x2, int y2, struct color *c);
extern void gfx_clear (struct image *dimg, struct color *c);
extern struct image *gfx_img_alloc (int w, int h);

@ -37,7 +37,8 @@
iPoint mousepos;
int mousebtn;
time_t mousebtnpresstime;
iPoint mousebtnpresspos = {0 , 0};
iPoint mousebtnpresspos = {0.0, 0.0};
struct map_pos mousebtnpressgpos = {0, 0};
int mousebtnpresslongtime = 0;
unsigned long long int mouse_over_way_id = 0;
unsigned short int mouse_over_way_sid = 0;
@ -51,8 +52,24 @@ char mouse_over_way_name[MAP_W_NAMELEN] = "\0";
* if btn == -1 mean no button pressed or selected
*/
void draw_mousemove (int x, int y, int btn) {
float lon, lat, lonold, latold;
mousepos.x = x;
mousepos.y = y;
if (mousebtn) {
latold = -map_km2lat(((float)(mousebtnpresspos.y-gfx_screensize.y/2)) * view_scale);
lonold = map_km2lon(((float)(mousebtnpresspos.x-gfx_screensize.x/2)) * view_scale, view_lat + latold);
lat = -map_km2lat(((float)(y-gfx_screensize.y/2)) * view_scale);
lon = map_km2lon(((float)(x-gfx_screensize.x/2)) * view_scale, view_lat + lat);
lat = lat - latold;
lon = lon - lonold;
view_lat = mousebtnpressgpos.lat - lat;
view_lon = mousebtnpressgpos.lon - lon;
draw_del_flag (DRAW_GPSFOLLOW);
}
draw ();
};
@ -61,15 +78,19 @@ void draw_mousebtndown (int x, int y, int btn) {
mousebtnpresstime = time (NULL);
mousebtnpresspos.x = x;
mousebtnpresspos.y = y;
mousebtnpressgpos.lon = view_lon;
mousebtnpressgpos.lat = view_lat;
mousebtn = btn;
mousebtnpresslongtime = 0;
draw ();
};
void draw_mousebtnup (int x, int y, int btn) {
void draw_mousebtnup (int x, int y, int btn)
{
time_t t = time(NULL);
float lon, lat;
int dx, dy;
if (!mousebtn) return; /* button is no longer pressed */
mousebtn = 0;
@ -84,16 +105,13 @@ void draw_mousebtnup (int x, int y, int btn) {
lat = -map_km2lat(((float)(y-gfx_screensize.y/2)) * view_scale);
lon = map_km2lon(((float)(x-gfx_screensize.x/2)) * view_scale, view_lat + lat);
if (t - mousebtnpresstime <= 1) {
dx = abs (mousebtnpresspos.x-x)*100/gfx_screensize.x;
dy = abs (mousebtnpresspos.y-y)*100/gfx_screensize.y;
/* short time button pressing */
if (btn == 1) {
view_lat = view_lat + lat;
view_lon = view_lon + lon;
draw_del_flag (DRAW_GPSFOLLOW);
}
}
else {
/* long time button pressed */
d_printf ("released mouse button..");
if (t - mousebtnpresstime <= 1) {
if (dx < 10 && dy < 10) {
if (select_enabled) {
select_enabled = 0;
}
@ -104,6 +122,11 @@ void draw_mousebtnup (int x, int y, int btn) {
}
}
}
else if (mousebtnpresslongtime && dx < 10 && dy < 10) {
/* long time button pressed */
wnd_mapcontext_show ();
}
}
draw ();
};
@ -114,6 +137,7 @@ void draw_mouseloop () {
if (mousebtn && t - mousebtnpresstime > 1) {
mousebtnpresslongtime = 1;
d_printf ("draw_mouseloop: long press..");
draw ();
}
@ -156,7 +180,6 @@ void draw_gui () {
tmplinestyle.c = tmplinestyle.borderc = color[COLOR_white][3];
draw_line (NULL, mousepos.x-5, mousepos.y-5, mousepos.x+5, mousepos.y+5, tmplinestyle);
draw_line (NULL, mousepos.x+5, mousepos.y-5, mousepos.x-5, mousepos.y+5, tmplinestyle);
gfx_draw_text (NULL, mousepos.x, mousepos.y, "nur ein test.", &color[COLOR_yellow][2]);
/*
* draw selected position
@ -184,8 +207,8 @@ void draw_gui () {
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
p1.x = gfx_screensize.x/2-100;
p2.x = gfx_screensize.x/2+100;
p1.x = gfx_screensize.x/2-101;
p2.x = gfx_screensize.x/2+101;
p1.y = gfx_screensize.y-32;
p2.y = gfx_screensize.y-10;
@ -194,8 +217,21 @@ void draw_gui () {
draw_polygonadd (p2.x, p1.y);
draw_polygonadd (p2.x, p2.y);
draw_polygonadd (p1.x, p2.y);
draw_polygonfinish (NULL, ls, color[COLOR_blue][3], 1);
gfx_draw_text (NULL, p1.x + 2, p1.y + 2, app.statusline_text, &color[COLOR_white][3]);
draw_polygonfinish (NULL, ls, &color[COLOR_white][0], 1);
p1.x = gfx_screensize.x/2-(float)(100.0*app.statusline_progress);
p2.x = gfx_screensize.x/2+(float)(100.0*app.statusline_progress);
p1.y = gfx_screensize.y-31;
p2.y = gfx_screensize.y-11;
draw_polygonstart ();
draw_polygonadd (p1.x, p1.y);
draw_polygonadd (p2.x, p1.y);
draw_polygonadd (p2.x, p2.y);
draw_polygonadd (p1.x, p2.y);
draw_polygonfinish (NULL, ls, &color[COLOR_blue][3], 0);
gfx_draw_text (NULL, gfx_screensize.x/2-98, p1.y + 2, app.statusline_text, &color[COLOR_white][3]);
}
/*

@ -152,7 +152,7 @@ void gfx_draw_text (struct image *dimg, int x, int y, char *text, struct color *
};
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 GdkPoint *polygon = NULL;
static int polygon_cnt = 0;
int i;
@ -171,7 +171,7 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl
polygon[i].y = p[i].y;
}
gdk_gc_set_foreground (dimg->gc, &c.c);
gdk_gc_set_foreground (dimg->gc, &c->c);
gdk_draw_polygon (dimg->pixmap, dimg->gc, TRUE, polygon, pcnt);
};

@ -63,7 +63,7 @@ void main_menu_refresh () {
he.lon = view_lon + 2.0 * map_km2lon(view_scale * ((float)ss.x/10), he.lat);
map_load_web (hs, he);
app_status ("", -1);
app_status (-1, "", 0.0);
draw ();
}
};
@ -80,9 +80,9 @@ void main_menu_mapdefrag () {
void main_menu_saveall () {
app_status (_("save all"), -1);
app_status (-1,_("save all"), 0.0);
map_save_all();
app_status ("", -1);
app_status (-1, "", 0.0);
};
@ -127,14 +127,13 @@ void main_menu_osmimport () {
osm_loadfile (fn);
draw_redrawmap ();
}
app_status ("", -1);
app.status = APPSTATUS_nothing;
app_status (APPSTATUS_nothing, "", 0.0);
};
void main_menu_map_searchsort () {
map_search_sort ();
app_status ("", -1);
app_status (-1, "", 0.0);
};
@ -145,7 +144,7 @@ void main_menu_map_searchrefresh () {
map_search_get_filename (lfn, LEN_FILENAME);
map_webload (rfn, lfn, NULL);
app_status ("", -1);
app_status (-1, "", 0.0);
};

@ -107,18 +107,12 @@ static gboolean main_wnd_delete_event(GtkWidget *widget, GdkEvent *event, gpoint
* callback function for the cyclic loop
*/
gboolean main_wnd_cyclicloop (gpointer data) {
struct gps_data *gpspos;
// d_printf ("%s:%d main_wnd_cyclicloop", __FILE__, __LINE__);
while (gtk_events_pending()) // make sure we handle also other GTK events..
gtk_main_iteration();
if (gps_isrunning () > 0) {
if ((gpspos = gps_loop ())) {
drawgps_set_pos (gpspos);
}
}
draw_mouseloop ();
app_loop ();
return TRUE;
};
@ -217,7 +211,7 @@ void main_wnd_loop (long long int cur, long long int max) {
t1 = time (NULL);
if (to != t1) {
app_status (NULL, 0);
app_status (-1, NULL, 0.0);
to = t1;
}

@ -36,7 +36,7 @@ GtkWidget *map_da = NULL;
GdkGC *gc;
GdkGCValues gcvalues;
GdkColormap *colormap = NULL;
guint last_event_keyval;
/*
* draw event callback
@ -58,8 +58,8 @@ gboolean map_da_button_press_event (GtkWidget *widget, GdkEventButton *event, gp
if (event->button == 2) btn = 4;
if (event->button == 3) btn = 2;
gevent.mousepos.x = x;
gevent.mousepos.y = y;
gevent.scr_mpos.x = x;
gevent.scr_mpos.y = y;
gevent.mousebtn = btn;
gevent.event = EGUI_MOUSEPRESSED;
if (gui_event (gevent) == 0) draw_mousebtndown (x, y, btn);
@ -78,8 +78,8 @@ gboolean map_da_button_release_event (GtkWidget *widget, GdkEventButton *event,
if (event->button == 2) btn = 4;
if (event->button == 3) btn = 2;
gevent.mousepos.x = x;
gevent.mousepos.y = y;
gevent.scr_mpos.x = x;
gevent.scr_mpos.y = y;
gevent.mousebtn = btn;
gevent.event = EGUI_MOUSERELEASED;
if (gui_event (gevent) == 0) draw_mousebtnup (x, y, btn);
@ -93,8 +93,8 @@ gboolean map_da_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, g
int y = event->y;
GUIEvent gevent;
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;
@ -107,18 +107,37 @@ gboolean map_da_motion_notify_event (GtkWidget *widget, GdkEventMotion *event, g
gboolean map_da_key_release_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
last_event_keyval = 0;
return FALSE;
};
gboolean map_da_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
GUIEvent gevent = {0};
int lo, hi;
gevent.keyval = event->keyval;
gevent.event = EGUI_KEYRELEASED;
if (gui_event (gevent) == 0) {
if (event->keyval == '+') draw_setscale (- 1);
if (event->keyval == '-') draw_setscale (+ 1);
}
if (last_event_keyval == event->keyval) return FALSE;
lo = event->keyval & 0x00FF;
hi = (event->keyval & 0xFF00) > 8;
if (hi == 0) gevent.keychar = lo;
if (hi == 1 && lo == 0x08) gevent.keychar = lo;
if (hi == 1 && lo == 0x1b) gevent.keychar = lo;
if (hi == 1 && lo == 0x0d) gevent.keychar = lo;
if (hi == 1 && lo == 0x51) gevent.keychar = lo;
if (hi == 1 && lo == 0x53) gevent.keychar = lo;
d_printf ("keyval: '%c' lo(%x) hi(%x) gevent:%lx", event->keyval, lo, hi, gevent.keychar);
gevent.event = EGUI_KEYCHAR;
gui_event (gevent);
main_wnd_update ();
draw ();
last_event_keyval = event->keyval;
return FALSE;
};
@ -161,6 +180,7 @@ GtkWidget *map_da_create () {
g_signal_connect (G_OBJECT (map_da), "button_press_event", G_CALLBACK (map_da_button_press_event), NULL);
g_signal_connect (G_OBJECT (map_da), "button_release_event", G_CALLBACK (map_da_button_release_event), NULL);
g_signal_connect (G_OBJECT (map_da), "scroll_event", G_CALLBACK (map_da_scroll_event), NULL);
g_signal_connect (G_OBJECT (map_da), "key_press_event", G_CALLBACK (map_da_key_press_event), NULL);
g_signal_connect (G_OBJECT (map_da), "key_release_event", G_CALLBACK (map_da_key_release_event), NULL);
g_signal_connect (G_OBJECT (map_da), "motion_notify_event", G_CALLBACK (map_da_motion_notify_event), NULL);
gfx_resize (100, 100);

@ -1,6 +1,14 @@
include ../Makefile.rules
OBJ = gui.o
OBJ = gui.o \
gui_window.o \
gui_checkbox.o \
gui_button.o \
gui_list.o \
gui_entry.o \
gui_label.o \
gui_image.o \
gui_softkeyboard.o
SRC = $(OBJ:%.o=%.c)

@ -1,3 +1,4 @@
/* $Id: gui.c,v 1.28 2014/03/06 22:21:46 steffen Exp $ */
/***************************************************************************
* gui.c
*
@ -28,6 +29,12 @@
GUIWindow *currentwin = NULL;
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
*/
@ -64,7 +71,9 @@ void gui_draw () {
if (currentwin == NULL) gui_buttons_show ();
if (currentwin->screen == NULL) {
currentwin->screen = gfx_img_alloc (currentwin->w, currentwin->h);
currentwin->screen_changed = 1;
}
// d_printf ("GUI draw: %p %s screen:%p(changed:%d) pos: %d,%d size:%d,%d", currentwin, currentwin->title, currentwin->screen, currentwin->screen_changed, currentwin->x, currentwin->y, currentwin->w, currentwin->h);
if (currentwin && (currentwin->screen_changed || now-1 > lastupdate || now < lastupdate)) {
lastupdate = now;
@ -73,46 +82,79 @@ void gui_draw () {
}
else {
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
ls.c = ls.borderc = color[COLOR_red][3];
draw_polygonstart ();
draw_polygonadd (0, 0);
draw_polygonadd (0, currentwin->h-1);
draw_polygonadd (currentwin->w-1, currentwin->h-1);
draw_polygonadd (currentwin->w-1, 0);
draw_polygonfinish (currentwin->screen, ls, color[COLOR_white][0], 1);
draw_polygonadd (0, currentwin->h);
draw_polygonadd (currentwin->w, currentwin->h);
draw_polygonadd (currentwin->w, 0);
draw_polygonfinish (currentwin->screen, ls, &color[COLOR_white][0], 1);
gfx_draw_text (currentwin->screen, 4, 0, currentwin->title, &color[COLOR_white][3]);
}
for (i = 0; i < GUI_WIN_BUTTONS; i++) if (currentwin->buttons[i].id != 0) {
if (currentwin->buttons[i].callback_draw != NULL)
currentwin->buttons[i].callback_draw (&currentwin->buttons[i]);
else gui_button_draw (&currentwin->buttons[i]);
}
for (i = 0; i < GUI_WIN_LABELS; i++) if (currentwin->labels[i].id != 0) {
gui_label_draw (&currentwin->labels[i]);
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->entrys[i].id != 0) {
gui_entry_draw (&currentwin->entrys[i]);
}
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->lists[i].id != 0) {
gui_list_draw (&currentwin->lists[i]);
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) if (currentwin->checkboxes[i].id != 0) {
// gui_draw_label (&currentwin->labels[i]);
if (currentwin->title[0] != 0) gfx_draw_line (currentwin->screen, 0, 18, currentwin->w, 18, ls);
}
/* draw items.. */
for (i = 0; i < GUI_MAX_ITEM; i++) if (currentwin->items[i])
switch (currentwin->items[i]->type) {
case (GUI_BUTTON): {
GUIButton *button = (GUIButton *) currentwin->items[i]->data;
if (button->func_draw != NULL) button->func_draw (currentwin->items[i]);
else gui_button_draw (currentwin->items[i]);
}
break;
case (GUI_LABEL):
gui_label_draw (currentwin->items[i]);
break;
case (GUI_ENTRY):
gui_entry_draw (currentwin->items[i]);
break;
case (GUI_LIST):
gui_list_draw (currentwin->items[i]);
break;
case (GUI_CHECKBOX):
gui_checkbox_draw (currentwin->items[i]);
break;
default:
break;
}
currentwin->screen_changed = 0;
}
if (currentwin) {
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VCENTER) currentwin->x = gfx_screensize.x/2 - currentwin->w/2;
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VLEFT) currentwin->x = 0;
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VRIGHT) currentwin->x = gfx_screensize.x - currentwin->w;
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VCENTER)
currentwin->x = gfx_screensize.x/2 - currentwin->w/2;
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VLEFT)
currentwin->x = 0;
if ((currentwin->style & WGUI_S_VCENTER) == WGUI_S_VRIGHT)
currentwin->x = gfx_screensize.x - currentwin->w;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HCENTER)
currentwin->y = gfx_screensize.y/2 - currentwin->h/2;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HTOP)
currentwin->y = 0;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HBOTTOM)
currentwin->y = gfx_screensize.y - currentwin->h;
/* draw the windows or just the part of the entry which is focused
* and draw the softkeyb
*/
if (currentwin->focus && softkeyb && softkeyb->enabled) {
int ys, yh;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HCENTER) currentwin->y = gfx_screensize.y/2 - currentwin->h/2;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HTOP) currentwin->y = 0;
if ((currentwin->style & WGUI_S_HCENTER) == WGUI_S_HBOTTOM) currentwin->y = gfx_screensize.y - currentwin->h;
/* drawing and display softkeyb */
gui_softkeyb_draw ();
softkeyb->offset.x = (gfx_screensize.x-softkeyb->screen->width)/2;
softkeyb->offset.y = gfx_screensize.y-softkeyb->screen->height;
gfx_draw_img (NULL, softkeyb->offset.x, softkeyb->offset.y,
softkeyb->screen->width, softkeyb->screen->height, softkeyb->screen, 0, 0);
gfx_draw_img (NULL, currentwin->x, currentwin->y, currentwin->w, currentwin->h, currentwin->screen, 0, 0);
/* drawing part of the screen where the entry element is set up.. */
ys = currentwin->focus->y- 16;
yh = gfx_screensize.y-softkeyb->screen->height;
currentwin->y = -ys;
if ((currentwin->h - (currentwin->focus->y-16)) < yh) yh = currentwin->h - (currentwin->focus->y - 16);
gfx_draw_img (NULL, currentwin->x, 0, currentwin->w, yh, currentwin->screen, 0, ys);
}
else gfx_draw_img (NULL, currentwin->x, currentwin->y, currentwin->w, currentwin->h, currentwin->screen, 0, 0);
}
};
@ -122,361 +164,46 @@ void gui_draw () {
* return 0 for nothing done.. or 1 for eventhandling done
*/
int gui_event (GUIEvent event) {
int i;
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;
}
// 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_WIN_BUTTONS; i++) {
// if (currentwin->buttons[i].id != 0)
// d_printf ("%d %d,%d %d,%d - %d,%d", currentwin->buttons[i].id, currentwin->buttons[i].x, currentwin->buttons[i].y, currentwin->buttons[i].w, currentwin->buttons[i].h, event.mousepos.x, event.mousepos.y);
if (currentwin->buttons[i].id != 0
&& currentwin->buttons[i].x <= event.mousepos.x && currentwin->buttons[i].x+currentwin->buttons[i].w >= event.mousepos.x
&& currentwin->buttons[i].y <= event.mousepos.y && currentwin->buttons[i].y+currentwin->buttons[i].h >= event.mousepos.y) {
if (currentwin->buttons[i].callback_clicked != NULL && event.event == EGUI_MOUSEPRESSED) {
d_printf ("GUI BUTTON PRESSED: %d:%s", currentwin->buttons[i].id, currentwin->buttons[i].caption);
currentwin->buttons[i].callback_clicked (event.mousepos.x-currentwin->buttons[i].x, event.mousepos.y-currentwin->buttons[i].y);
event_called = 0;
currentwin->screen_changed = 1;
return 1;
}
}
}
for (i = 0; i < GUI_WIN_LABELS; i++) if (currentwin->labels[i].id != 0) {
// gui_event_label (&currentwin->labels[i]);
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->entrys[i].id != 0) {
if (currentwin->entrys[i].id != 0
&& currentwin->entrys[i].x <= event.mousepos.x && currentwin->entrys[i].x+currentwin->entrys[i].w >= event.mousepos.x
&& currentwin->entrys[i].y <= event.mousepos.y && currentwin->entrys[i].y+currentwin->entrys[i].h >= event.mousepos.y) {
gui_entry_event (&currentwin->entrys[i], &event);
event_called = 0;
return 1;
}
}
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->lists[i].id != 0) {
if (currentwin->lists[i].x <= event.mousepos.x && currentwin->lists[i].x+currentwin->lists[i].w >= event.mousepos.x
&& currentwin->lists[i].y <= event.mousepos.y && currentwin->lists[i].y+currentwin->lists[i].h >= event.mousepos.y) {
gui_list_event (&currentwin->lists[i], &event);
event_called = 0;
return 1;
}
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) if (currentwin->checkboxes[i].id != 0) {
// gui_event_label (&currentwin->labels[i]);
}
if (currentwin->focus != NULL) {
for (i = 0; i < GUI_WIN_ENTRYS; i++) if (currentwin->focus == &currentwin->entrys[i]) {
gui_entry_event (&currentwin->entrys[i], &event);
event_called = 0;
return 1;
}
for (i = 0; i < GUI_WIN_LISTS; i++) if (currentwin->focus == &currentwin->lists[i]) {
gui_list_event (&currentwin->lists[i], &event);
event_called = 0;
return 1;
}
}
event_called = 0;
return 1;
};
/***************************************************************************
* basic windows functions
***************************************************************************/
void guiwindow_new (GUIWindow *win, int w, int h) {
int i;
for (i = 0; i < GUI_WIN_BUTTONS; i++) {
win->buttons[i].caption[0] = '\0';
win->buttons[i].id = 0;
win->buttons[i].col = &color[COLOR_white][2];
win->buttons[i].textcol = &color[COLOR_white][3];
win->buttons[i].callback_clicked = NULL;
win->buttons[i].callback_draw = NULL;
}
for (i = 0; i < GUI_WIN_LABELS; i++) {
win->labels[i].text[0] = '\0';
win->labels[i].textcol = &color[COLOR_white][2];
win->labels[i].id = 0;
}
for (i = 0; i < GUI_WIN_LISTS; i++) {
win->lists[i].id = 0;
win->lists[i].selected = -1;
win->lists[i].callback_selectitem = NULL;
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) {
win->entrys[i].text[0] = '\0';
win->entrys[i].callback_enter = NULL;
win->entrys[i].callback_changed = NULL;
win->entrys[i].id = 0;
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) {
win->checkboxes[i].text[0] = '\0';
win->checkboxes[i].callback_changed = NULL;
win->checkboxes[i].id = 0;
win->labels[i].text[0] = '\0';
}
win->title[0] = 0;
win->screen = NULL;
win->screen_changed = 1;
win->h = h;
win->w = w;
win->focus = NULL;
d_printf ("guiwindow_new %p width:%d height:%d", win, w, h);
};
/*
* set focus
*/
/*
* closes the window, but does not free the memory.
*/
void guiwindow_close (GUIWindow *win) {
int i;
for (i = 0; i < GUI_WIN_BUTTONS; i++) {
win->buttons[i].caption[0] = '\0';
win->buttons[i].id = 0;
win->buttons[i].callback_clicked = NULL;
win->buttons[i].callback_draw = NULL;
}
for (i = 0; i < GUI_WIN_LABELS; i++) {
win->labels[i].text[0] = '\0';
win->labels[i].textcol = &color[COLOR_white][2];
win->labels[i].id = 0;
}
for (i = 0; i < GUI_WIN_ENTRYS; i++) {
win->entrys[i].text[0] = '\0';
win->entrys[i].callback_enter = NULL;
win->entrys[i].callback_changed = NULL;
win->entrys[i].id = 0;
}
for (i = 0; i < GUI_WIN_CHECKBOXES; i++) {
win->checkboxes[i].text[0] = '\0';
win->checkboxes[i].callback_changed = NULL;
win->checkboxes[i].id = 0;
}
win->title[0] = 0;
gfx_img_free (win->screen);
win->screen = NULL;
win->screen_changed = 1;
win->h = 0;
win->w = 0;
};
/****************************************************************************
****************************************************************************
** gui elements
**
**/
/****************************************************************************
* button
*/
void gui_button_draw (GUIButton *button) {
struct line_style ls;
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
draw_polygonstart ();
draw_polygonadd (button->x, button->y);
draw_polygonadd (button->x, button->y + button->h);
draw_polygonadd (button->x + button->w, button->y + button->h);
draw_polygonadd (button->x + button->w, button->y);
draw_polygonfinish (currentwin->screen, ls, *button->col, 1);
gfx_draw_text (currentwin->screen, button->x + 2, button->y + 2, button->caption, button->textcol);
};
/****************************************************************************
* label
*/
void gui_label_draw (GUILabel *label) {
struct line_style ls;
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
gfx_draw_text (currentwin->screen, label->x, label->y, label->text, label->textcol);
};
/****************************************************************************
* entry
*/
void gui_entry_draw (GUIEntry *entry) {
char text1[GUI_TEXTLEN];
char text2[GUI_TEXTLEN];
struct line_style ls;
ls.width = 1.0;
if (currentwin->focus == entry)
ls.c = ls.borderc = color[COLOR_white][3];
else
ls.c = ls.borderc = color[COLOR_white][2];
gfx_draw_line (currentwin->screen, entry->x, entry->y+entry->h, entry->x+entry->w, entry->y+entry->h, ls);
gfx_draw_line (currentwin->screen, entry->x, entry->y+entry->h, entry->x, entry->y+entry->h-2, ls);
gfx_draw_line (currentwin->screen, entry->x+entry->w, entry->y+entry->h, entry->x+entry->w, entry->y+entry->h-2, ls);
if (entry->curpos >= strlen (entry->text)) {
entry->curpos = strlen (entry->text);
snprintf (text1, GUI_TEXTLEN, "%s|", entry->text);
}
else if (entry->curpos <= 0) {
entry->curpos = 0;
snprintf (text1, GUI_TEXTLEN, "|%s", entry->text);
d_printf ("gui_event...");
if (currentwin) {
event.guiwin_mpos.x = event.scr_mpos.x - currentwin->x;
event.guiwin_mpos.y = event.scr_mpos.y - currentwin->y;
if (gui_window_event (currentwin, &event)) return 1;
}
else {
strncpy (text2, entry->text, entry->curpos);
snprintf (text1, GUI_TEXTLEN, "%s|%s", text2, entry->text+entry->curpos);
}
gfx_draw_text (currentwin->screen, entry->x+2, entry->y, text1, &color[COLOR_white][3]);
};
/*
* event handling
*/
void gui_entry_event (GUIEntry *entry, GUIEvent *event) {
char text1[GUI_TEXTLEN];
if (event->event == EGUI_MOUSERELEASED
&& entry->x <= event->mousepos.x && entry->x+entry->w >= event->mousepos.x
&& entry->y <= event->mousepos.y && entry->y+entry->h >= event->mousepos.y) {
d_printf ("gui_entry_event set focus");
currentwin->focus = entry;
event.guiwin_mpos.x = -1;
event.guiwin_mpos.y = -1;
}
/* no gui active nor any window is responsible.. */
//d_printf ("no event..");
switch (event.event) {
case (EGUI_MOUSERELEASED):
draw_mousebtnup (event.scr_mpos.x, event.scr_mpos.y, event.mousebtn);
break;
case (EGUI_MOUSEPRESSED):
draw_mousebtndown (event.scr_mpos.x, event.scr_mpos.y, event.mousebtn);
break;
case (EGUI_MOUSEMOVE):
draw_mousemove (event.scr_mpos.x, event.scr_mpos.y, event.mousebtn);
break;
default:
break;
}
else if (event->event == EGUI_KEYRELEASED) {
d_printf ("gui_entry_event: curpos:%d len:%d text:%s char:%x", entry->curpos, strlen (entry->text), entry->text, event->keyval);
if (event->keyval == 0xff08) { // backspace
// strncpy (text1, entry->text, entry->curpos-1);
// snprintf (text2, GUI_TEXTLEN, "%s%s", text1, entry->text+entry->curpos);
// strncpy (entry->text, text2, GUI_TEXTLEN);
// entry->curpos--;
entry->text[0] = 0;
entry->curpos = 0;
}
else if (event->keyval == 0xff1b) { // esc
gui_close ();
}
else if (event->keyval == 0xff0d) { // enter
if (entry->callback_enter) entry->callback_enter ();
}
else if (event->keyval == 0xff51) { // left
// entry->curpos--;
}
else if (event->keyval == 0xff53) { // right
// entry->curpos++;
}
else if ((event->keyval & 0xff00) == 0xff00) {
// ignore all the rest
}
else {
strncpy (text1, entry->text, GUI_TEXTLEN );
snprintf (entry->text, GUI_TEXTLEN, "%s%c", text1, event->keyval);
entry->curpos++;
}
}
currentwin->screen_changed = 1;
return;
return 0;
};
/****************************************************************************
* list
*/
void gui_list_draw (GUIList *list) {
struct line_style ls;
int max, i, x, y, j;
ls.width = 1.0;
if (currentwin->focus == list)
ls.c = ls.borderc = color[COLOR_white][3];
else
ls.c = ls.borderc = color[COLOR_white][2];
gfx_draw_line (currentwin->screen, list->x, list->y, list->x+list->w, list->y, ls);
gfx_draw_line (currentwin->screen, list->x+list->w, list->y, list->x+list->w, list->y+list->h, ls);
gfx_draw_line (currentwin->screen, list->x+list->w, list->y+list->h, list->x, list->y+list->h, ls);
gfx_draw_line (currentwin->screen, list->x, list->y+list->h, list->x, list->y, ls);
if (list->data == NULL) return;
for (max = 0; list->data[max] != NULL; max++);
/* range to display */
i = max - list->h/16;
if (i < list->vs) list->vs = i;
if (list->vs < 0) list->vs = 0;
for (i = list->vs; i < (list->vs + list->h/16) && i < max; i++) {
if (i == list->selected) gfx_draw_text (currentwin->screen, list->x + 5, list->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_red][1]);
else gfx_draw_text (currentwin->screen, list->x + 5, list->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_white][3]);
}
ls.c = ls.borderc = color[COLOR_white][3];
for (i = -1; i < 2; i += 2) {
if (i < 0) y = list->y + list->h;
else y = list->y;
x = list->x + list->w;
for (j = 0; j <= 5; j++) {
gfx_draw_line (currentwin->screen, x - 5, y, x-j, y + i*5, ls);
gfx_draw_line (currentwin->screen, x - 5 -j, y+ i*5, x-5, y, ls);
}
}
void gui_event_addmousepos (GUIEvent *event, iPoint pos, int neg) {
event->scr_mpos.x += neg ? pos.x : -pos.x;
event->scr_mpos.y += neg ? pos.y : -pos.y;
return;
};
/*
* event handling
*/
void gui_list_event (GUIList *list, GUIEvent *event) {
int x = event->mousepos.x - list->x;
int y = event->mousepos.y - list->y;
int i;
/* set focus */
if (event->event == EGUI_MOUSERELEASED && x >= 0 && x <= list->w && y >= 0 && y <= list->h) {
currentwin->focus = list;
if (y <= 5 && x >= list->w - 10) list->vs--;
else if (y >= list->h - 5 && x >= list->w - 10) list->vs++;
else { /* select entry */
i = (y-5)/16 + list->vs;
list->selected = i;
if (list->callback_selectitem) list->callback_selectitem (i);
d_printf ("selected nr: %d", i);
}
}
void gui_set_focus (GUIItem *item) {
if (item == NULL || item->type != GUI_ENTRY) gui_softkeyb_show (FALSE);
currentwin->focus = item;
currentwin->screen_changed = 1;
draw ();
};

@ -28,16 +28,24 @@
#include "osmroute.h"
#define GUI_TEXTLEN 256
#define GUI_MAX_ITEM 256
enum {
EGUI_NONE,
EGUI_KEYPRESSED,
EGUI_KEYRELEASED,
EGUI_KEYCHAR,
EGUI_MOUSEMOVE,
EGUI_MOUSEPRESSED,
EGUI_MOUSERELEASED
};
enum {
GUI_NONE,
GUI_BUTTON,
GUI_LIST,
GUI_ENTRY,
GUI_CHECKBOX,
GUI_LABEL
};
/*
* styles for the windows..
@ -52,28 +60,40 @@ enum {
// #define WGUI_S_**** 0x0080
#define WGUI_S_MODAL 0x0100
#define GUIKEY_UP 0x0111
#define GUIKEY_DOWN 0x0112
#define GUIKEY_RIGHT 0x0113
#define GUIKEY_LEFT 0x0114
struct _GUIEvent_ {
int event;
uint32_t keyval; // needed for utf8 (max was 32bit?)
iPoint mousepos;
uint16_t key; // the key which was pressed
uint32_t keychar; // the utf char for this key
iPoint scr_mpos; // mousepos on screen
iPoint guiwin_mpos; // mousepos on gui (setup from gui_event)
int mousebtn;
} typedef GUIEvent;
struct _GUIButton_ {
struct _GUIItem_ {
int type;
int x, y, w, h;
int id;
char data[];
} typedef GUIItem;
struct _GUIButton_ {
char caption[GUI_TEXTLEN];
struct color *col;
struct color *textcol;
void (*callback_clicked) (int x, int y);
void (*callback_draw) (struct _GUIButton_ *btn);
void (*func_draw) (GUIItem *item);
} typedef GUIButton;
struct _GUIList_ {
int x, y, w, h;
int id;
char **data;
int vs; // first element to draw
int selected;
@ -82,57 +102,35 @@ struct _GUIList_ {
struct {
int x, y;
int id;
char text[GUI_TEXTLEN];
struct color *textcol;
} typedef GUILabel;
struct {
int x, y, w, h;
int id;
char text[GUI_TEXTLEN];
int curpos;
int overwrite;
void (*callback_enter) ();
void (*callback_esc) ();
void (*callback_changed) ();
} typedef GUIEntry;
struct {
int x, y, w, h;
int id;
char text[GUI_TEXTLEN];
int checked;
void (*callback_changed) ();
} typedef GUICheckbox;
#define GUI_WIN_BUTTONS 16
#define GUI_WIN_ENTRYS 8
#define GUI_WIN_LABELS 16
#define GUI_WIN_CHECKBOXES 16
#define GUI_WIN_LISTS 4
#define GUI_WIN_ELEMENTS 32
enum {
GUINONE,
GUIBUTTON,
GUILIST,
GUIENTRY,
GUICHECKBOX,
GUILABEL
};
struct _GUIWindow_ {
void (*callback_close) ();
struct _GUIWindow_ *parent;
struct image *screen;
int screen_changed;
int event_called; // mark if we proceed any event call already.
char title[GUI_TEXTLEN];
int x;
int y;
@ -140,41 +138,87 @@ struct _GUIWindow_ {
int h;
int style;
GUIButton buttons[GUI_WIN_BUTTONS];
GUIEntry entrys[GUI_WIN_ENTRYS];
GUICheckbox checkboxes[GUI_WIN_CHECKBOXES];
GUILabel labels[GUI_WIN_LABELS];
GUIList lists[GUI_WIN_LISTS];
void *focus; // element which holds the focus
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;
int linepos[2][4]; /* y positions of lines */
int btnpos[2][8]; /* holds position keys: Left, Right, Shift, Symbols, Space, Del, Close */
iPoint offset; /* screenoffset .. will be set during last draw */
struct image *screen;
int last_col;
int last_line;
uint32_t 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 ();
extern void gui_close ();
extern int gui_event (GUIEvent event);
extern void gui_event_addmousepos (GUIEvent *event, iPoint pos, int neg);
extern void gui_set_focus (GUIItem *item);
#define GUI_ITEM_IS_INSIDE(__item__,__pos__) gui_is_inside(__item__->x, __item__->y, __item__->w, __item__->h, __pos__)
extern int gui_is_inside (int x, int y, int w, int h, iPoint pos);
extern void guiwindow_new (GUIWindow *win, int w, int h);
extern void guiwindow_close (GUIWindow *win);
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);
extern int gui_window_event (GUIWindow *win, GUIEvent *event);
/* softkeyboard functions. */
extern void gui_softkeyb_show (int enable);
extern int gui_softkeyb_event (GUIEvent *event);
extern void gui_softkeyb_draw ();
/* button functions */
extern void gui_button_draw (GUIButton *button);
#define GUI_BUTTON_T(_item_) ((GUIButton*)(_item_)->data)
extern void gui_button_draw (GUIItem *item);
extern int gui_button_event (GUIItem *item, GUIEvent *event);
extern GUIItem *gui_button_new (char *name, int x, int y, int w, int h);
/* checkbox functions */
#define GUI_CHECKBOX_T(_item_) ((GUICheckbox*)(_item_)->data)
extern void gui_checkbox_draw (GUIItem *item);
extern int gui_checkbox_event (GUIItem *item, GUIEvent *event);
extern GUIItem *gui_checkbox_new (char *text, int initialvalue, int x, int y);
/* label functions */
extern void gui_label_draw (GUILabel *label);
#define GUI_LABEL_T(_item_) ((GUILabel*)(_item_)->data)
extern void gui_label_draw (GUIItem *item);
extern GUIItem *gui_label_new (char *text, int x, int y);
/* entry functions */
extern void gui_entry_draw (GUIEntry *entry);
extern void gui_entry_event (GUIEntry *entry, GUIEvent *event);
#define GUI_ENTRY_T(_item_) ((GUIEntry*)(_item_)->data)
extern void gui_entry_draw (GUIItem *item);
extern int gui_entry_event (GUIItem *item, GUIEvent *event);
extern GUIItem *gui_entry_new (char *text, int x, int y, int w, int h);
extern void gui_entry_settext (GUIItem *item, char *text);
/* list functions */
extern void gui_list_draw (GUIList *list);
extern void gui_list_event (GUIList *list, GUIEvent *event);
extern void gui_list_setselect (GUIList *list);
#define GUI_LIST_T(_item_) ((GUIList*)(_item_)->data)
extern void gui_list_draw (GUIItem *item);
extern int gui_list_event (GUIItem *item, GUIEvent *event);
extern void gui_list_setselect (GUIItem *item);
extern GUIItem *gui_list_new (int x, int y, int w, int h);
/**************************************************************************
* gui windows
@ -183,6 +227,10 @@ extern void gui_search_show ();
extern void gui_fav_show ();
extern void gui_mainmenu_show ();
extern void gui_buttons_show ();
extern char *gui_sfile_show (char *startpath);
extern void gui_config_show ();
extern void gpswin_show ();
extern void wnd_routing_show ();
extern void wnd_mapcontext_show ();
#endif

@ -0,0 +1,97 @@
/* $Id: gui_button.c,v 1.11 2013/04/03 21:52:27 steffen Exp $ */
/***************************************************************************
* gui_button.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
/****************************************************************************
* button
*/
void gui_button_draw (GUIItem *item) {
struct line_style ls;
GUIButton *button = NULL;
if (item == NULL || item->type != GUI_BUTTON) {
d_printf ("GUIButton %p not type GUIButton", item);
errorexit (-1);
}
button = (GUIButton *) item->data;
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
// d_printf ("gui_button_draw \"%s\" %d,%d,%d,%d", button->caption, item->x, item->y, item->w, item->h);
draw_polygonstart ();
draw_polygonadd (item->x, item->y);
draw_polygonadd (item->x, item->y + item->h);
draw_polygonadd (item->x + item->w, item->y + item->h);
draw_polygonadd (item->x + item->w, item->y);
draw_polygonfinish (currentwin->screen, ls, button->col, 1);
gfx_draw_text (currentwin->screen, item->x + 2, item->y + 2, button->caption, button->textcol);
};
GUIItem *gui_button_new (char *caption, int x, int y, int w, int h) {
GUIItem *item = (GUIItem*) ml_malloc (sizeof (GUIItem) + sizeof (GUIButton) + POINTERALIGNMENT);
GUIButton *button = (GUIButton *) item->data;
memset (item, 0x0, sizeof (GUIItem) + sizeof (GUIButton) + POINTERALIGNMENT);
if (caption == NULL) button->caption[0] = 0;
else strncpy (button->caption, caption, GUI_TEXTLEN);
item->x = x;
item->y = y;
item->w = w;
item->h = h;
item->type = GUI_BUTTON;
button->col = &color[COLOR_white][1];
button->textcol = &color[COLOR_white][3];
button->callback_clicked = NULL;
button->func_draw = NULL;
return item;
};
int gui_button_event (GUIItem *item, GUIEvent *event) {
GUIButton *button = NULL;
if (item == NULL || item->type != GUI_BUTTON) {
d_printf ("GUIButton %p not type GUIButton", item);
errorexit (-1);
}
button = (GUIButton *) item->data;
if (button->callback_clicked != NULL && event->event == EGUI_MOUSEPRESSED) {
gui_set_focus (NULL);
button->callback_clicked (event->guiwin_mpos.x-item->x, event->guiwin_mpos.y-item->y);
}
return 1;
};

@ -0,0 +1,95 @@
/* $Id: gui_checkbox.c,v 1.3 2013/04/03 21:52:27 steffen Exp $ */
/***************************************************************************
* gui_checkbox.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* checkbox gui element
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
/****************************************************************************
* label
*/
void gui_checkbox_draw (GUIItem *item) {
GUICheckbox *checkbox = NULL;
struct line_style ls;
if (item) checkbox = (GUICheckbox*) item->data;
ls.c = color[COLOR_white][3];
ls.width = 1.0;
ls.borderc = ls.c;
draw_rectangle (currentwin->screen, item->x , item->y, item->x + 15, item->y + 15, ls);
if (checkbox->checked) {
gfx_draw_line (currentwin->screen, item->x , item->y, item->x + 15, item->y + 15, ls);
gfx_draw_line (currentwin->screen, item->x + 15 , item->y, item->x, item->y + 15, ls);
}
gfx_draw_text (currentwin->screen, item->x + 17, item->y, checkbox->text, &ls.c);
};
GUIItem *gui_checkbox_new (char *text, int initialvalue, int x, int y) {
GUIItem *item = (GUIItem*) ml_malloc (sizeof (GUICheckbox) + sizeof (GUIItem) + POINTERALIGNMENT);
GUICheckbox *checkbox = NULL;
if (item) checkbox = (GUICheckbox*) item->data;
if (text == NULL) checkbox->text[0] = 0;
else strncpy (checkbox->text, text, GUI_TEXTLEN);
item->x = x;
item->y = y;
item->w = 15;
item->h = 15;
checkbox->checked = initialvalue;
checkbox->callback_changed = NULL;
item->type = GUI_CHECKBOX;
return item;
};
int gui_checkbox_event (GUIItem *item, GUIEvent *event) {
GUICheckbox *checkbox = NULL;
if (item) checkbox = (GUICheckbox*) item->data;
if (item == NULL || item->type != GUI_CHECKBOX) {
d_printf ("GUIButton %p not type GUICheckbox", item);
errorexit (-1);
}
d_printf ("checkbox:%s %d,%d,%d,%d %d,%d", checkbox->text, item->x, item->y, item->w, item->h, event->guiwin_mpos.x, event->guiwin_mpos.y);
if (event->event == EGUI_MOUSEPRESSED) {
checkbox->checked = !checkbox->checked;
if (checkbox->callback_changed != NULL) {
gui_set_focus (NULL);
checkbox->callback_changed ();
}
currentwin->screen_changed = 1;
draw();
return 1;
}
return 0;
};

@ -0,0 +1,165 @@
/* $Id: gui_entry.c,v 1.18 2013/06/20 21:28:04 steffen Exp $ */
/***************************************************************************
* gui_entry.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include "utf8.h"
/****************************************************************************
* entry
*/
void gui_entry_draw (GUIItem *item) {
char text1[GUI_TEXTLEN];
char text2[GUI_TEXTLEN];
struct line_style ls;
GUIEntry *entry = NULL;
if (item) entry = (GUIEntry *) item->data;
else return;
// d_printf ("gui_entry curpos:%d len:%d", entry->curpos, strlen(entry->text));
// d_print_data (entry->text, strlen (entry->text)+1);
ls.width = 1.0;
if (currentwin->focus == (void*) item)
ls.c = ls.borderc = color[COLOR_white][3];
else
ls.c = ls.borderc = color[COLOR_white][2];
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x+item->w, item->y+item->h, ls);
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x, item->y+item->h-2, ls);
gfx_draw_line (currentwin->screen, item->x+item->w, item->y+item->h, item->x+item->w, item->y+item->h-2, ls);
if (entry->curpos >= strlen (entry->text)) {
entry->curpos = strlen (entry->text);
snprintf (text1, GUI_TEXTLEN, "%s|", entry->text);
}
else if (entry->curpos <= 0) {
entry->curpos = 0;
snprintf (text1, GUI_TEXTLEN, "|%s", entry->text);
}
else {
u8_strcpy (text1, entry->text, 0, entry->curpos);
u8_strcpy (text2, "|", 0, 1);
u8_strncat (text1, GUI_TEXTLEN, text2);
u8_strcpy (text2, entry->text, entry->curpos, u8_strlen (entry->text)-entry->curpos);
u8_strncat (text1, GUI_TEXTLEN, text2);
}
gfx_draw_text (currentwin->screen, item->x+2, item->y, text1, &color[COLOR_white][3]);
};
/*
* event handling
*/
int gui_entry_event (GUIItem *item, GUIEvent *event) {
char u8chr[12] = {0};
GUIEntry *entry = NULL;
if (item) entry = (GUIEntry *) item->data;
if (event->event == EGUI_MOUSEPRESSED) {
gui_set_focus (item);
gui_softkeyb_show (TRUE);
}
else if (event->event == EGUI_KEYCHAR) {
d_printf ("gui_entry curpos:%d key:%lx keychar:%lx", entry->curpos, event->key, event->keychar);
if (entry->curpos < 0) entry->curpos = 0;
if (entry->curpos > u8_strlen (entry->text)) entry->curpos = u8_strlen (entry->text);
if (event->key == 0x08) { // backspace
d_printf ("gui_entry:backspace");
if (entry->curpos > 0) {
u8_strdel (entry->text, entry->curpos-1, 1);
entry->curpos--;
}
}
else if (event->key == 0x7f) { // delete
d_printf ("gui_entry:delete");
if (entry->curpos >= 0 && entry->curpos-1 < u8_strlen (entry->text)) {
u8_strdel (entry->text, entry->curpos, 1);
}
}
else if (event->key == 0x1b) { // esc
d_printf ("gui_entry:esc");
if (entry->callback_esc) entry->callback_esc ();
}
else if (event->key == 0x0d) { // enter
d_printf ("gui_entry:enter");
if (entry->callback_enter) entry->callback_enter ();
}
else if (event->key == GUIKEY_LEFT) { // left
d_printf ("gui_entry:curpos--");
if (entry->curpos > 0) entry->curpos--;
}
else if (event->key == GUIKEY_RIGHT) { // right
d_printf ("gui_entry:curpos++");
if (entry->curpos < u8_strlen (entry->text)) entry->curpos++;
}
else if (event->keychar != 0) {
u8_encode (u8chr, event->keychar);
u8_strninsert (entry->text, GUI_TEXTLEN, u8chr, entry->curpos);
entry->curpos++;
}
}
currentwin->screen_changed = 1;
draw ();
return 1;
};
GUIItem *gui_entry_new (char *text, int x, int y, int w, int h) {
GUIItem *item = (GUIItem*) ml_malloc (sizeof (GUIItem) + sizeof (GUIEntry) + POINTERALIGNMENT);
GUIEntry *entry = NULL;
if (item) entry = (GUIEntry *) item->data;
if (text == NULL) entry->text[0] = 0;
else strncpy (entry->text, text, GUI_TEXTLEN);
item->x = x;
item->y = y;
item->w = w;
item->h = h;
item->type = GUI_ENTRY;
entry->callback_changed = NULL;
entry->callback_enter = NULL;
entry->callback_esc = NULL;
return item;
};
void gui_entry_settext (GUIItem *item, char *text) {
GUIEntry *entry = NULL;
if (item) entry = (GUIEntry *) item->data;
strncpy (entry->text, text, GUI_TEXTLEN);
entry->curpos = strlen (entry->text);
currentwin->screen_changed = 1;
};

@ -0,0 +1,30 @@
/* $Id: gui_image.c,v 1.1 2013/02/17 00:52:20 steffen Exp $ */
/***************************************************************************
* gui_image.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"

@ -0,0 +1,62 @@
/* $Id: gui_label.c,v 1.3 2013/02/27 22:21:35 steffen Exp $ */
/***************************************************************************
* gui_label.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
/****************************************************************************
* label
*/
void gui_label_draw (GUIItem *item) {
GUILabel *label = NULL;
if (item) label = (GUILabel*) item->data;
struct line_style ls;
ls.width = 1.0;
ls.c = ls.borderc = color[COLOR_white][3];
gfx_draw_text (currentwin->screen, item->x, item->y, label->text, label->textcol);
};
GUIItem *gui_label_new (char *text, int x, int y) {
GUIItem *item = (GUIItem*) ml_malloc (sizeof (GUILabel) + sizeof (GUIItem) + POINTERALIGNMENT);
GUILabel *label = NULL;
if (item) label = (GUILabel*) item->data;
if (text == NULL) label->text[0] = 0;
else strncpy (label->text, text, GUI_TEXTLEN);
item->x = x;
item->y = y;
label->textcol = &color[COLOR_white][2];
item->type = GUI_LABEL;
return item;
};

@ -0,0 +1,134 @@
/* $Id: gui_list.c,v 1.13 2014/02/12 21:21:07 steffen Exp $ */
/***************************************************************************
* gui_list.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#define GUI_ARROW_WIDTH 16
#define GUI_ARROW_HEIGHT 16
/****************************************************************************
* list
*/
void gui_list_draw (GUIItem *item) {
struct line_style ls;
int max, i, x, y, j;
GUIList *list = NULL;
if (item == NULL) return;
else list = (GUIList *) item->data;
ls.width = 1.0;
if (currentwin->focus == item)
ls.c = ls.borderc = color[COLOR_white][3];
else
ls.c = ls.borderc = color[COLOR_white][2];
gfx_draw_line (currentwin->screen, item->x, item->y, item->x+item->w, item->y, ls);
gfx_draw_line (currentwin->screen, item->x+item->w, item->y, item->x+item->w, item->y+item->h, ls);
gfx_draw_line (currentwin->screen, item->x+item->w, item->y+item->h, item->x, item->y+item->h, ls);
gfx_draw_line (currentwin->screen, item->x, item->y+item->h, item->x, item->y, ls);
/* find last max */
max = 0;
if (list->data == NULL) max = 0;
else for (max = 0; list->data[max] != NULL; max++);
/* range to display */
i = max - item->h/16;
if (i < list->vs) list->vs = i;
if (list->vs < 0) list->vs = 0;
for (i = list->vs; i < (list->vs + item->h/16) && i < max; i++) {
if (i == list->selected) gfx_draw_text (currentwin->screen, item->x + 5, item->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_red][2]);
else gfx_draw_text (currentwin->screen, item->x + 5, item->y + 5 + 16 * (i - list->vs), list->data[i], &color[COLOR_white][3]);
}
ls.c = ls.borderc = color[COLOR_white][3];
for (i = -1; i < 2; i += 2) {
if (i < 0) y = item->y + item->h;
else y = item->y;
x = item->x + item->w;
for (j = 0; j <= GUI_ARROW_WIDTH/2; j++) {
gfx_draw_line (currentwin->screen, x - GUI_ARROW_WIDTH/2, y, x-j, y + i*GUI_ARROW_HEIGHT, ls);
gfx_draw_line (currentwin->screen, x - GUI_ARROW_WIDTH/2 -j, y+ i*GUI_ARROW_HEIGHT, x-GUI_ARROW_WIDTH/2, y, ls);
}
}
};
/*
* event handling
*/
int gui_list_event (GUIItem *item, GUIEvent *event) {
int x = event->guiwin_mpos.x - item->x;
int y = event->guiwin_mpos.y - item->y;
int i;
GUIList *list = NULL;
static GUIItem *olditem = NULL;
if (item == NULL) return 0;
else list = (GUIList *) item->data;
/* set focus */
if (event->event == EGUI_MOUSEPRESSED) {
olditem = item;
}
else if (event->event == EGUI_MOUSERELEASED && olditem == item &&
x >= 0 && y >= 0 && x <= item->w && y <= item->h) {
gui_set_focus (item);
if (y <= GUI_ARROW_HEIGHT && x >= item->w - GUI_ARROW_WIDTH) list->vs--;
else if (y >= item->h - GUI_ARROW_HEIGHT && x >= item->w - GUI_ARROW_WIDTH) list->vs++;
else { /* select entry */
i = (y-5)/16 + list->vs;
list->selected = i;
if (list->callback_selectitem) list->callback_selectitem (i);
}
}
currentwin->screen_changed = 1;
draw ();
return 1;
};
GUIItem *gui_list_new (int x, int y, int w, int h) {
GUIItem *item = (GUIItem *) ml_malloc (sizeof (GUIList) + sizeof (GUIItem) + POINTERALIGNMENT);
GUIList *list = (GUIList *) item->data;
item->type = GUI_LIST;
item->x = x;
item->y = y;
item->w = w;
item->h = h;
list->selected = -1;
list->vs = 0;
list->callback_selectitem = NULL;
list->data = NULL;
return item;
};

@ -0,0 +1,280 @@
/* $Id: gui_softkeyboard.c,v 1.10 2013/06/18 22:24:21 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include "utf8.h"
GUISoftkeyboard *softkeyb = NULL;
void gui_softkeyb_getpos (int row, int btnnr, int *x1, int *x2, int *y1, int *y2);
void gui_softkeyb_show (int enable) {
/* keys which are displayed.. */
char *line[GUI_SOFTKEYB_MODE_MAX][GUI_SOFTKEYB_Y] = {
{ "qwertzuiopü",
"asdfghjklöä",
"yxcvbnm,.-/" },
{ "QWERTZUIOPÜ",
"ASDFGHIKLÖÄ",
"YXCVBNM;:+\\" },
{ "0123456789=",
"{([])} ",
"!\"§$%&<>~ " }};
int i, j, x, size;
/* 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++) {
char *str = line[i][j];
for (x = 0; x < GUI_SOFTKEYB_X; x++) {
softkeyb->keys[i][j][x] = u8_decode (str, &size);
str += size;
}
}
softkeyb->enabled = TRUE;
softkeyb->mode = GUI_SOFTKEYB_MODE_NORM;
softkeyb->last_line = -1;
softkeyb->last_col = -1;
};
/* only preparing the screen image... copying to the screen will be done later... */
static float _linepos[2][4] = { { 5.0, 25.0, 45.0, 65.0 },
{ 20.0, 40.0, 60.0, 95.0 } };
static float _btnpos[2][8] = { { 2.0, 6.0, 10.0, 16.0, 28.0, 70.0, 80.0, 90.0 },
{ 6.0, 10.0, 16.0, 26.0, 68.0, 80.0, 90.0, 98.0 } };
void gui_softkeyb_getpos (int row, int btnnr, int *x1, int *y1, int *x2, int *y2) {
if (row < 3) {
*x1 = 5 + (btnnr * (softkeyb->screen->width - 10)) / GUI_SOFTKEYB_X;
*x2 = 5 + ((btnnr + 1) * (softkeyb->screen->width - 10)) / GUI_SOFTKEYB_X;
*y1 = (_linepos[0][row] * softkeyb->screen->height)/100;
*y2 = (_linepos[1][row] * softkeyb->screen->height)/100;
}
else if (row == 3) {
*x1 = (_btnpos[0][btnnr] * softkeyb->screen->width)/100;
*x2 = (_btnpos[1][btnnr] * softkeyb->screen->width)/100;
*y1 = (_linepos[0][row] * softkeyb->screen->height)/100;
*y2 = (_linepos[1][row] * softkeyb->screen->height)/100;
}
};
void gui_softkeyb_draw () {
struct line_style ls;
int i, j, x1, x2, y1, y2;
char c[16] = { 0 };
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);
}
/* setup the lines... */
for (j = 0; j < 2; j++) for (i = 0; i < 5; i++) {
if (i < 4) softkeyb->linepos[j][i] = _linepos[j][i] * softkeyb->screen->width;
softkeyb->btnpos[j][i] = _btnpos[j][i] * softkeyb->screen->height;
}
/* draw border */
ls.c = color[COLOR_red][2];
ls.width = 1;
gfx_clear (softkeyb->screen, &color[COLOR_white][1]);
draw_rectangle (softkeyb->screen, 1, 1, softkeyb->screen->width-2, softkeyb->screen->height-2, ls);
/* draw 3 key rows.. */
ls.c = color[COLOR_white][2];
ls.width = 1;
for (j = 0; j < 3; j++) {
for (i = 0; i < GUI_SOFTKEYB_X; i++) {
gui_softkeyb_getpos (j, i, &x1, &y1, &x2, &y2);
if (softkeyb->last_col == i && softkeyb->last_line == j)
draw_fillrectangle (softkeyb->screen, x1, y1, x2, y2, &color[COLOR_white][0]);
draw_rectangle (softkeyb->screen, x1, y1, x2, y2, ls);
u8_encode (c, softkeyb->keys[softkeyb->mode][j][i]);
gfx_draw_text (softkeyb->screen, x1+(x2-x1-12)/2, y1+(y2-y1-12)/2, c, &color[COLOR_white][3]);
}
}
/* draw the last keys */
for (j = 3, i = 0; i < 8; i++) {
gui_softkeyb_getpos (j, i, &x1, &y1, &x2, &y2);
if (softkeyb->last_col == i && softkeyb->last_line == 3)
draw_fillrectangle (softkeyb->screen, x1, y1, x2, y2, &color[COLOR_white][0]);
draw_rectangle (softkeyb->screen, x1, y1, x2, y2, ls);
switch (i) {
case (0):
snprintf (c, 16, _("<"));
break;
case (1):
snprintf (c, 16, _(">"));
break;
case (2):
snprintf (c, 16, _("SYM"));
break;
case (3):
snprintf (c, 16, _("SHIFT"));
break;
case (4):
snprintf (c, 16, _(" "));
break;
case (5):
snprintf (c, 16, _("Del"));
break;
case (6):
snprintf (c, 16, _("Enter"));
break;
case (7):
snprintf (c, 16, _("Close"));
break;
}
gfx_draw_text (softkeyb->screen, x1+(x2-x1-8*strlen (c))/2, y1+(y2-y1-12)/2, c, &color[COLOR_white][3]);
}
};
int gui_softkeyb_event (GUIEvent *event) {
int i, j, x1, y1, x2, y2;
GUIEvent newevent;
iPoint mp = { event->scr_mpos.x - softkeyb->offset.x, event->scr_mpos.y - softkeyb->offset.y };
if (event->event != EGUI_MOUSEPRESSED && event->event != EGUI_MOUSERELEASED) return 0;
/* check if we pressed one of the keys.. */
for (j = 0; j < 3; j++)
for (i = 0; i < GUI_SOFTKEYB_X; i++) {
gui_softkeyb_getpos (j, i, &x1, &y1, &x2, &y2);
if (x1 <= mp.x && mp.x <= x2 && y1 <= mp.y && mp.y <= y2) {
if (event->event == EGUI_MOUSEPRESSED) {
d_printf ("softkey: %d %d %d", softkeyb->mode, j, i);
softkeyb->last_line = j;
softkeyb->last_col = i;
newevent.key = softkeyb->keys[softkeyb->mode][j][i];
newevent.keychar = softkeyb->keys[softkeyb->mode][j][i];
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
}
else {
softkeyb->last_line = -1;
softkeyb->last_col = -1;
}
currentwin->screen_changed = 1;
draw ();
return 1;
}
}
for (i = 0; i < 8; i++) {
gui_softkeyb_getpos (3, i, &x1, &y1, &x2, &y2);
if (x1 <= mp.x && mp.x <= x2 && y1 <= mp.y && mp.y <= y2) {
if (event->event == EGUI_MOUSEPRESSED) {
softkeyb->last_line = 3;
softkeyb->last_col = i;
switch (i) {
case (0):
newevent.key = GUIKEY_LEFT;
newevent.keychar = 0x0;
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
break;
case (1):
newevent.key = GUIKEY_RIGHT;
newevent.keychar = 0x0;
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
break;
case (2):
softkeyb->mode = (softkeyb->mode == GUI_SOFTKEYB_MODE_SYMBOL) ? 0 : GUI_SOFTKEYB_MODE_SYMBOL;
break;
case (3):
softkeyb->mode = (softkeyb->mode == GUI_SOFTKEYB_MODE_SHIFT) ? 0 : GUI_SOFTKEYB_MODE_SHIFT;
break;
case (4):
newevent.key = ' ';
newevent.keychar = u8_decode (" ", NULL);
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
return 1;
break;
case (5):
newevent.key = 0x08;
newevent.keychar = 0x0;
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
return 1;
break;
case (6):
newevent.key = 0x0d;
newevent.keychar = 0x0;
newevent.event = EGUI_KEYCHAR;
newevent.guiwin_mpos.x = newevent.scr_mpos.x = -1;
newevent.guiwin_mpos.y = newevent.scr_mpos.y = -1;
gui_entry_event (currentwin->focus, &newevent);
return 1;
break;
case (7):
softkeyb->enabled = 0;
currentwin->screen_changed = 1;
draw ();
return 1;
break;
}
}
else {
softkeyb->last_line = -1;
softkeyb->last_col = -1;
}
}
}
return 0;
};

@ -0,0 +1,159 @@
/* $Id: gui_window.c,v 1.9 2013/06/18 22:24:21 steffen Exp $ */
/***************************************************************************
* gui_window.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
***************************************************************************
* basic windows functions
***************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
/*
* reset all window data, do not allocate anything
*/
void gui_window_new (GUIWindow *win, int w, int h, char *title) {
int i;
for (i = 0; i < GUI_MAX_ITEM; i++) win->items[i] = NULL;
if (title == NULL) win->title[0] = 0;
else strncpy (win->title, title, GUI_TEXTLEN);
win->screen = NULL;
win->screen_changed = 1;
win->h = h;
win->w = w;
win->focus = NULL;
d_printf ("gui_window_new [%s] %p width:%d height:%d", title, win, w, h);
};
/*
* closes the window, but does not free the memory.
*/
void gui_window_close (GUIWindow *win) {
d_printf ("gui_window_close [%s] %p", win->title, win);
/* delete screen so we know it's disabled.. */
if (win->screen) gfx_img_free (win->screen);
win->screen = NULL;
win->screen_changed = 1;
if (currentwin == win) currentwin = NULL;
};
/*
* add pointer to item to the window data structure..
* the items will have to be hold inside the application
*/
void gui_window_item_add (GUIWindow *win, GUIItem *item) {
int i, ifree = -1;
if (item == NULL || win == NULL) return;
for (i = 0; i < GUI_MAX_ITEM; i++) {
if (win->items[i] == NULL && ifree == -1) ifree = i;
if (win->items[i] == item) {
d_printf ("item already added to item list.");
ifree = i;
}
}
if (ifree == -1) {
d_printf ("no free item slot");
exit (1);
}
win->items[ifree] = item;
win->screen_changed = 1;
d_printf ("gui_window_item_add win:%p ifree:%d item:%p", win, ifree, item);
};
/*
* Handle gui events within the gui.
*/
int gui_window_event (GUIWindow *win, GUIEvent *event) {
GUIItem *item = win->focus;
int i;
if (win->event_called) return -1;
win->event_called = 1;
/* check if softkeyb is opened */
if ((softkeyb && softkeyb->enabled && softkeyb->screen)
&& (event->event == EGUI_MOUSERELEASED || event->event == EGUI_MOUSEPRESSED)) {
int x1 = (gfx_screensize.x-softkeyb->screen->width)/2,
x2 = gfx_screensize.x-(gfx_screensize.x-softkeyb->screen->width)/2,
y1 = gfx_screensize.y-softkeyb->screen->height,
y2 = gfx_screensize.y;
if ( x1 <= event->scr_mpos.x && x2 >= event->scr_mpos.x
&& y1 <= event->scr_mpos.y && y2 >= event->scr_mpos.y) {
gui_softkeyb_event (event);
win->event_called = 0;
return 1;
}
}
for (i = 0; i < GUI_MAX_ITEM; i++) if (currentwin->items[i] != NULL)
if (GUI_ITEM_IS_INSIDE (currentwin->items[i], event->guiwin_mpos))
item = currentwin->items[i];
if (item) switch (item->type) {
case (GUI_BUTTON):
gui_button_event (item, event);
win->event_called = 0;
return 1;
break;
case (GUI_ENTRY):
gui_entry_event (item, event);
win->event_called = 0;
return 1;
break;
case (GUI_LIST):
gui_list_event (item, event);
win->event_called = 0;
return 1;
break;
case (GUI_CHECKBOX):
gui_checkbox_event (item, event);
win->event_called = 0;
return 1;
break;
default:
break;
}
win->event_called = 0;
if (event->event == EGUI_MOUSERELEASED || event->event == EGUI_MOUSEPRESSED) {
if (event->guiwin_mpos.x >=0 && event->guiwin_mpos.x < win->w
&& event->guiwin_mpos.y >=0 && event->guiwin_mpos.y < win->h)
return 1;
}
return 0;
};

@ -3,7 +3,7 @@ include ../Makefile.rules
OBJBASE = favorites.o main.o
ifeq "$(GTKVERSION)" "1"
GTK = linux_gps.o gps.o routing.o gui_buttons.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o
GTK = linux_gps.o gps.o routing.o gui_selectdir.o gui_selectfile.o gui_config.o gui_buttons.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o wnd_routing.o wnd_mapcontext.o
endif
ifeq "$(NCURSESVERSION)" "1"
@ -11,15 +11,15 @@ CURSES = ncurses_main.o
endif
ifeq "$(WINVERSION)" "1"
WIN = gps.o routing.o gui_buttons.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o
WIN = gps.o routing.o gui_buttons.o gui_config.o gui_selectdir.o gui_selectfile.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o wnd_routing.o wnd_mapcontext.o
endif
ifeq "$(WINCEVERSION)" "1"
WIN = gps.o routing.o gui_buttons.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o
WIN = gps.o routing.o gui_buttons.o gui_config.o gui_favorites.o gui_selectdir.o gui_selectfile.o gui_mainmenu.o gui_search.o guiw_gpsfile.o wnd_routing.o wnd_mapcontext.o
endif
ifeq "$(SDLGLVERSION)" "1"
SDLGL = linux_gps.o gps.o routing.o gui_buttons.o gui_favorites.o gui_mainmenu.o gui_search.o guiw_gpsfile.o
SDLGL = linux_gps.o gps.o routing.o gui_config.o gui_buttons.o gui_favorites.o gui_selectdir.o gui_selectfile.o gui_mainmenu.o gui_search.o guiw_gpsfile.o wnd_routing.o wnd_mapcontext.o
endif

@ -47,9 +47,13 @@ struct gps_data gpspos;
struct gps_data gpsposvalid;
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
char gpsdevice[GPS_DEVICELEN] = "serial:/dev/rfcomm0";
#if defined ANDROID
char gpsdevice[GPS_DEVICELEN] = "android:";
#else
char gpsdevice[GPS_DEVICELEN] = "serial:/dev/rfcomm0";
#endif
#else
char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400";
char gpsdevice[GPS_DEVICELEN] = "serial:com1,38400";
#endif
int gpsflags = GPSF_LOG;
@ -387,6 +391,7 @@ float gps_getlat (char *text) {
int gps_get_devicetype () {
if (strncmp (gpsdevice, "serial:", 7) == 0) return GPS_T_SERIAL;
else if (strncmp (gpsdevice, "file:", 5) == 0) return GPS_T_FILE;
else if (strncmp (gpsdevice, "android:", 8) == 0) return GPS_T_ANDROID;
else return GPS_T_NONE;
};
@ -433,6 +438,9 @@ void gps_start () {
gpslasttype = gps_get_devicetype ();
if (gpslasttype == GPS_T_SERIAL) error = gps_serial_device_open ();
else if (gpslasttype == GPS_T_FILE) error = gps_file_device_open ();
#ifdef ANDROID
else if (gpslasttype == GPS_T_ANDROID) error = gps_android_device_open ();
#endif
else error = 0;
if (error) {
@ -447,12 +455,16 @@ void gps_start () {
}
gpsdatalen = 0;
draw ();
};
void gps_stop () {
d_printf ("%s:%d gps_stop", __FILE__, __LINE__);
if (gpslasttype == GPS_T_SERIAL) gps_serial_device_close ();
#ifdef ANDROID
else if (gpslasttype == GPS_T_ANDROID) gps_android_device_close ();
#endif
else if (gpslasttype == GPS_T_FILE) gps_file_device_close ();
gpsstatus = 0;
gpsdatalen = 0;
@ -624,6 +636,8 @@ struct gps_data *gps_loop () {
setlocale(LC_ALL, "C");
#endif
d_printf ("gps_loop");
gpspos.valid = gpsposvalid.valid = 0;
call = time (NULL);
/*
@ -634,19 +648,26 @@ struct gps_data *gps_loop () {
/*
* check if gps is open and fillup the buffer
*/
if (gpsstatus <= 0) return NULL;
if (gpsstatus <= 0) {
d_printf ("gps loop : status:%d", gpsstatus);
return NULL;
}
if (gpslasttype == GPS_T_SERIAL) dataread = gps_serial_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
#ifdef ANDROID
else if (gpslasttype == GPS_T_ANDROID) dataread = gps_android_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
#endif
else if (gpslasttype == GPS_T_FILE) dataread = gps_file_device_read (gpsdata + gpsdatalen, GPS_INBUFSIZE - gpsdatalen);
else dataread = -1;
if (dataread < 0) {
d_printf ("gps_loop data read < 0");
gps_stop();
gpsstatus = -1;
return NULL;
}
else if (dataread+gpsdatalen > GPS_INBUFSIZE) {
d_printf ("%s:%d gps_loop: ERROR datapos(%d) > GPS_INBUFSIZE(%d)", __FILE__, __LINE__, gpsdatalen + dataread, GPS_INBUFSIZE);
gpsdatalen = GPS_INBUFSIZE;
gps_stop ();
}
else gpsdatalen += dataread;
@ -667,6 +688,7 @@ struct gps_data *gps_loop () {
line[i] = 0;
/* write into logfile */
// d_printf ("gps line:'%s'", line);
if (i > 0) {
if (gpslasttype != GPS_T_FILE && gpsflags & GPSF_LOG) gps_save_log (logfile, line);
if (gps_convert_line (line, &gpspos) == 0) gpspos.valid = 0;

@ -37,7 +37,7 @@
#define GPS_DEVICELEN 256
#define GPS_ROUTEPOILEN 128
#define GPS_INBUFSIZE 128
#define GPS_INBUFSIZE 2048
#define GPS_LINELEN 100
#define GPS_MAXSAT 32
@ -50,6 +50,7 @@
enum {
GPS_T_NONE,
GPS_T_SERIAL,
GPS_T_ANDROID,
GPS_T_FILE
};
@ -149,5 +150,11 @@ extern void gps_file_set_pos (int newpos);
extern int gps_file_get_pos ();
extern int gps_file_get_size ();
#ifdef ANDROID
extern int gps_android_device_open ();
extern void gps_android_device_close ();
extern int gps_android_device_read (char *ptr, int ptrsize);
#endif
#endif

@ -38,8 +38,13 @@ enum {
static GUIWindow wbutton = {0};
static GUIItem *btn_zoomin = NULL,
*btn_zoomout = NULL,
*btn_gps = NULL,
*btn_menu = NULL,
*btn_fav = NULL;
void gui_buttons_closecallback ();
void gui_buttons_draw (GUIButton *btn);
void gui_buttons_draw (GUIItem *btn);
void gui_buttons_zoomin();
void gui_buttons_zoomout();
void gui_buttons_gps();
@ -48,62 +53,49 @@ void gui_buttons_fav();
void gui_buttons_show () {
d_printf ("GUI: buttons show screen:%p", wbutton.screen);
if (wbutton.screen == NULL) guiwindow_new (&wbutton, 192, 32);
wbutton.screen_changed = 1;
wbutton.callback_close = (void*)gui_buttons_closecallback;
wbutton.style = WGUI_S_VCENTER | WGUI_S_HTOP;
/* add buttons */
strncpy (wbutton.buttons[0].caption, _("+"), GUI_TEXTLEN);
wbutton.buttons[0].callback_clicked = (void*)gui_buttons_zoomin;
wbutton.buttons[0].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[0].id = BTNWIN_ZIN;
wbutton.buttons[0].w = 31;
wbutton.buttons[0].h = 31;
wbutton.buttons[0].x = 0;
wbutton.buttons[0].y = 0;
strncpy (wbutton.buttons[1].caption, _("-"), GUI_TEXTLEN);
wbutton.buttons[1].callback_clicked = (void*)gui_buttons_zoomout;
wbutton.buttons[1].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[1].id = BTNWIN_ZOUT;
wbutton.buttons[1].w = 31;
wbutton.buttons[1].h = 31;
wbutton.buttons[1].x = 40;
wbutton.buttons[1].y = 0;
strncpy (wbutton.buttons[2].caption, _("GPS"), GUI_TEXTLEN);
wbutton.buttons[2].callback_clicked = (void*)gui_buttons_gps;
wbutton.buttons[2].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[2].id = BTNWIN_GPS;
wbutton.buttons[2].w = 31;
wbutton.buttons[2].h = 31;
wbutton.buttons[2].x = 80;
wbutton.buttons[2].y = 0;
strncpy (wbutton.buttons[3].caption, _("M"), GUI_TEXTLEN);
wbutton.buttons[3].callback_clicked = (void*)gui_buttons_menu;
wbutton.buttons[3].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[3].id = BTNWIN_MENU;
wbutton.buttons[3].w = 31;
wbutton.buttons[3].h = 31;
wbutton.buttons[3].x = 120;
wbutton.buttons[3].y = 0;
strncpy (wbutton.buttons[4].caption, _("Fav"), GUI_TEXTLEN);
wbutton.buttons[4].callback_clicked = (void*)gui_buttons_fav;
wbutton.buttons[4].callback_draw = (void*)gui_buttons_draw;
wbutton.buttons[4].id = BTNWIN_FAV;
wbutton.buttons[4].w = 31;
wbutton.buttons[4].h = 31;
wbutton.buttons[4].x = 160;
wbutton.buttons[4].y = 0;
if (btn_zoomin == NULL) {
btn_zoomin = gui_button_new (_("+"), 1, 1, 30, 30);
GUI_BUTTON_T(btn_zoomin)->callback_clicked = (void*)gui_buttons_zoomin;
GUI_BUTTON_T(btn_zoomin)->func_draw = (void*)gui_buttons_draw;
}
if (btn_zoomout == NULL) {
btn_zoomout = gui_button_new (_("-"), 41, 1, 30, 30);
GUI_BUTTON_T(btn_zoomout)->callback_clicked = (void*)gui_buttons_zoomout;
GUI_BUTTON_T(btn_zoomout)->func_draw = (void*)gui_buttons_draw;
}
if (btn_gps == NULL) {
btn_gps = gui_button_new (_("GPS"), 81, 1, 30, 30);
GUI_BUTTON_T(btn_gps)->callback_clicked = (void*)gui_buttons_gps;
GUI_BUTTON_T(btn_gps)->func_draw = (void*)gui_buttons_draw;
}
if (btn_menu == NULL) {
btn_menu = gui_button_new (_("M"), 121, 1, 30, 30);
GUI_BUTTON_T(btn_menu)->callback_clicked = (void*)gui_buttons_menu;
GUI_BUTTON_T(btn_menu)->func_draw = (void*)gui_buttons_draw;
}
if (btn_fav == NULL) {
btn_fav = gui_button_new (_("F"), 161, 1, 30, 30);
GUI_BUTTON_T(btn_fav)->callback_clicked = (void*)gui_buttons_fav;
GUI_BUTTON_T(btn_fav)->func_draw = (void*)gui_buttons_draw;
}
if (wbutton.screen == NULL) {
gui_window_new (&wbutton, 192, 32, NULL);
gui_window_item_add (&wbutton, btn_fav);
gui_window_item_add (&wbutton, btn_zoomin);
gui_window_item_add (&wbutton, btn_zoomout);
gui_window_item_add (&wbutton, btn_gps);
gui_window_item_add (&wbutton, btn_menu);
}
gui_show (&wbutton);
};
@ -112,19 +104,19 @@ void gui_buttons_show () {
void gui_buttons_closecallback () {
d_printf ("GUI: buttons close");
guiwindow_close (&wbutton);
gui_window_close (&wbutton);
};
void gui_buttons_draw (GUIButton *btn) {
void gui_buttons_draw (GUIItem *btn) {
int j;
if (btn->id == BTNWIN_GPS) {
if (btn == btn_gps) {
j = gps_isrunning ();
if (j == 0) btn->col = &color[COLOR_white][2];
else if (j < 0) btn->col = &color[COLOR_red][2];
else if (view_flags & DRAW_GPSFOLLOW) btn->col = &color[COLOR_green][3];
else btn->col = &color[COLOR_green][2];
if (j == 0) GUI_BUTTON_T(btn)->col = &color[COLOR_white][2];
else if (j < 0) GUI_BUTTON_T(btn)->col = &color[COLOR_red][2];
else if (view_flags & DRAW_GPSFOLLOW) GUI_BUTTON_T(btn)->col = &color[COLOR_green][3];
else GUI_BUTTON_T(btn)->col = &color[COLOR_green][2];
}
gui_button_draw (btn);
@ -145,7 +137,6 @@ void gui_buttons_zoomout() {
void gui_buttons_gps() {
if (gps_isrunning () <= 0) {
gps_start ();
main_wnd_update();
}
else {
if (view_flags & DRAW_GPSFOLLOW) {

@ -0,0 +1,177 @@
/* %Id: Exp $ */
/***************************************************************************
* gui_config.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
void gui_config_close ();
void gui_config_seldir ();
void gui_config_gpsfile ();
void gui_config_gpslist (int nr);
void gui_config_checkbox_changed ();
GUIWindow wcfg = {0};
GUIItem *map_path = NULL;
GUIItem *map_seldir = NULL;
GUIItem *gps_device = NULL;
GUIItem *gps_list = NULL;
GUIItem *gps_file = NULL;
GUIItem *log_file = NULL;
GUIItem *cb_debug = NULL;
GUIItem *cb_softkeyb = NULL;
GUIItem *wcfg_close = NULL;
GUIItem *label1 = NULL;
GUIItem *label2 = NULL;
char gpscfg_dev[8][LEN_FILENAME] = {
#ifdef ANDROID
"android:",
#else
"serial:/dev/rfcomm0",
#endif
"serial:com1,38400",
"serial:com1,4800",
"",
"",
"",
"",
""};
char *gpscfg_dev_ptr[8] = {
gpscfg_dev[0],
gpscfg_dev[1],
gpscfg_dev[2],
NULL,
NULL,
NULL,
NULL,
NULL
};
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;
if (label1 == NULL) label1 = gui_label_new (_("mapdata path:"), 5, 20);
gui_window_item_add (&wcfg, label1);
if (map_path == NULL) map_path = gui_entry_new (cfg.mappath, 10, 36, 150, 20);
gui_window_item_add (&wcfg, map_path);
if (map_seldir == NULL) map_seldir = gui_button_new (_("Browse"), 170, 36, 40, 20);
GUI_BUTTON_T (map_seldir)->callback_clicked = gui_config_seldir;
gui_window_item_add (&wcfg, map_seldir);
if (label2 == NULL) label2 = gui_label_new (_("gps device:"), 5, 66);
gui_window_item_add (&wcfg, label2);
if (gps_device == NULL) gps_device = gui_entry_new (cfg.gps_device, 10, 82, 150, 20);
gui_window_item_add (&wcfg, gps_device);
if (gps_list == NULL) gps_list = gui_list_new (10, 112, 150, 60);
GUI_LIST_T (gps_list)->callback_selectitem = gui_config_gpslist;
GUI_LIST_T (gps_list)->data = gpscfg_dev_ptr;
gui_window_item_add (&wcfg, gps_list);
if (gps_file == NULL) gps_file = gui_button_new (_("File"), 170, 112, 40, 20);
GUI_BUTTON_T (gps_file)->callback_clicked = gui_config_gpsfile;
gui_window_item_add (&wcfg, gps_file);
if (log_file == NULL)
log_file = gui_checkbox_new (_("Create GPS-Log"), cfg.gps_flags & GPSF_LOG, 10, 172);
gui_window_item_add (&wcfg, log_file);
GUI_CHECKBOX_T (log_file)->callback_changed = gui_config_checkbox_changed;
if (cb_debug == NULL)
cb_debug = gui_checkbox_new (_("Debug"), cfg.debug, 5, 200);
gui_window_item_add (&wcfg, cb_debug);
GUI_CHECKBOX_T (cb_debug)->callback_changed = gui_config_checkbox_changed;
if (cb_softkeyb == NULL)
cb_softkeyb = gui_checkbox_new (_("Softkeyboard"), cfg.softkeyboard, 100, 200);
gui_window_item_add (&wcfg, cb_softkeyb);
GUI_CHECKBOX_T (cb_softkeyb)->callback_changed = gui_config_checkbox_changed;
if (wcfg_close == NULL) wcfg_close =
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);
};
void gui_config_close () {
strncpy (cfg.mappath, GUI_ENTRY_T(map_path)->text, LEN_FILENAME);
strncpy (cfg.gps_device, GUI_ENTRY_T(gps_device)->text, LEN_FILENAME);
gui_config_checkbox_changed ();
gui_close ();
map_clear ();
map_init ();
draw_redrawmap ();
};
void gui_config_checkbox_changed () {
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;
if (GUI_CHECKBOX_T(log_file)->checked) cfg.gps_flags |= GPSF_LOG;
else cfg.gps_flags &= (0x0FFFF-GPSF_LOG);
if (cfg.gps_flags) SETFLAG(gpsflags, GPSF_LOG);
else DELFLAG(gpsflags, GPSF_LOG);
};
void gui_config_gpslist (int nr) {
d_printf ("select nr:%d", nr);
if (nr >= 0 && nr < 8)
gui_entry_settext (gps_device, gpscfg_dev[nr]);
};
void gui_config_seldir () {
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);
};
void gui_config_gpsfile () {
char *new_file = NULL;
char text[LEN_FILENAME];
d_printf ("select gps file...");
new_file = gui_sfile_show ("");
if (new_file != NULL) {
snprintf (text, LEN_FILENAME, "file:%s", new_file);
gui_entry_settext (gps_device, text);
d_printf ("gpsdevice:%s", GUI_ENTRY_T(gps_device)->text);
}
};

@ -28,17 +28,6 @@
#include "memoryleak.h"
#include "system.h"
enum {
FAVWIN_UNDEF = 0,
FAVWIN_LIST,
FAVWIN_ADD,
FAVWIN_REN,
FAVWIN_DEL,
FAVWIN_NAME,
FAVWIN_CLOSE
};
void gui_fav_close ();
void gui_fav_add ();
void gui_fav_del ();
@ -50,86 +39,18 @@ void gui_fav_selitem (int nr);
void gui_fav_fl_create ();
void gui_fav_fl_free ();
GUIList *fav_list = NULL;
GUIEntry *fav_name = NULL;
GUIItem *favlist = NULL;
GUIItem *faventry_name = NULL;
GUIItem *favbtn_close = NULL;
GUIItem *favbtn_add = NULL;
GUIItem *favbtn_ren = NULL;
GUIItem *favbtn_del = NULL;
char **fl_array = NULL; // array to all elements
int fl_array_cnt = 0;
static GUIWindow wfav = {0};
void gui_fav_show () {
int btn = 0;
fav_new ();
fav_load (fav_getfilename());
if (wfav.screen == NULL) guiwindow_new (&wfav, 220, 240);
wfav.screen_changed = 1;
wfav.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1;
wfav.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
strncpy (wfav.title, _("Favorites"), GUI_TEXTLEN);
/* favotires buttons */
strncpy (wfav.buttons[btn].caption, _("Close"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_close;
wfav.buttons[btn].id = FAVWIN_CLOSE;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 5;
wfav.buttons[btn].y = 210;
strncpy (wfav.buttons[++btn].caption, _("Add"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_add;
wfav.buttons[btn].id = FAVWIN_ADD;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 5;
wfav.buttons[btn].y = 15;
strncpy (wfav.buttons[++btn].caption, _("Del"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_del;
wfav.buttons[btn].id = FAVWIN_DEL;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 70;
wfav.buttons[btn].y = 15;
strncpy (wfav.buttons[++btn].caption, _("Ren"), GUI_TEXTLEN);
wfav.buttons[btn].callback_clicked = (void*)gui_fav_ren;
wfav.buttons[btn].id = FAVWIN_REN;
wfav.buttons[btn].w = 60;
wfav.buttons[btn].h = 20;
wfav.buttons[btn].x = 135;
wfav.buttons[btn].y = 15;
/* add the list */
btn = 0;
wfav.lists[btn].callback_selectitem = (void*)gui_fav_selitem;
wfav.lists[btn].id = FAVWIN_LIST;
wfav.lists[btn].w = 210;
wfav.lists[btn].h = 130;
wfav.lists[btn].x = 5;
wfav.lists[btn].y = 45;
fav_list = &wfav.lists[btn];
/* add entry */
btn = 0;
wfav.entrys[btn].id = FAVWIN_NAME;
wfav.entrys[btn].w = 210;
wfav.entrys[btn].h = 20;
wfav.entrys[btn].x = 5;
wfav.entrys[btn].y = 180;
fav_name = &wfav.entrys[btn];
fav_name->text[0] = 0;
gui_fav_refresh ();
gui_show (&wfav);
};
void gui_fav_close () {
gui_close ();
};
@ -137,9 +58,9 @@ void gui_fav_close () {
void gui_fav_add () {
struct favorite f;
if (fav_name->text[0] == 0) return;
d_printf ("gui_fav_add: '%s'", fav_name->text);
strncpy (f.name, fav_name->text, FAV_NAME_LEN);
if (GUI_ENTRY_T(faventry_name)->text[0] == 0) return;
d_printf ("gui_fav_add: '%s'", GUI_ENTRY_T(faventry_name)->text);
strncpy (f.name, GUI_ENTRY_T(faventry_name)->text, FAV_NAME_LEN);
f.pos.lon = view_lon;
f.pos.lat = view_lat;
fav_add (-1, &f);
@ -148,28 +69,28 @@ void gui_fav_add () {
void gui_fav_del () {
if (fav_list->selected < 0) return;
fav_del (fav_list->selected);
if (GUI_LIST_T(favlist)->selected < 0) return;
fav_del (GUI_LIST_T(favlist)->selected);
gui_fav_refresh ();
};
void gui_fav_ren () {
if (fav_list->selected < 0 || fav_name->text[0] == 0) return;
strncpy (favorites[fav_list->selected].name, fav_name->text, FAV_NAME_LEN);
if (GUI_LIST_T(favlist)->selected < 0 || GUI_ENTRY_T(faventry_name)->text[0] == 0) return;
strncpy (favorites[GUI_LIST_T(favlist)->selected].name, GUI_ENTRY_T(faventry_name)->text, FAV_NAME_LEN);
gui_fav_refresh ();
};
void gui_fav_selitem (int nr) {
if (nr < favorites_cnt) {
strncpy (fav_name->text, favorites[nr].name, GUI_TEXTLEN);
strncpy (GUI_ENTRY_T(faventry_name)->text, favorites[nr].name, GUI_TEXTLEN);
view_lon = favorites[nr].pos.lon;
view_lat = favorites[nr].pos.lat;
gui_close ();
draw_del_flag (DRAW_GPSFOLLOW);
}
else fav_name->text[0] = 0;
else GUI_ENTRY_T(faventry_name)->text[0] = 0;
};
@ -181,8 +102,8 @@ void gui_fav_callback_close () {
void gui_fav_refresh () {
gui_fav_fl_create ();
fav_name->text[0] = 0;
fav_list->data = fl_array;
GUI_ENTRY_T(faventry_name)->text[0] = 0;
GUI_LIST_T(favlist)->data = fl_array;
};
@ -208,3 +129,52 @@ void gui_fav_fl_free () {
fl_array_cnt = 0;
};
void gui_fav_show () {
fav_new ();
fav_load (fav_getfilename());
if (wfav.screen == NULL) gui_window_new (&wfav, 220, 240, _("Favorites"));
wfav.callback_close = (void*)gui_fav_callback_close;
wfav.screen_changed = 1;
wfav.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
/* favotires buttons */
if (favbtn_close == NULL) {
favbtn_close = gui_button_new (_("Close"), 5, 210, 60, 20);
GUI_BUTTON_T(favbtn_close)->callback_clicked = (void*)gui_fav_close;
}
if (favbtn_add == NULL) {
favbtn_add = gui_button_new (_("Add"), 5, 15, 60, 20);
GUI_BUTTON_T(favbtn_add)->callback_clicked = (void*)gui_fav_add;
}
if (favbtn_del == NULL) {
favbtn_del = gui_button_new (_("Del"), 70, 15, 60, 20);
GUI_BUTTON_T(favbtn_del)->callback_clicked = (void*)gui_fav_ren;
}
if (favbtn_ren == NULL) {
favbtn_ren = gui_button_new (_("Ren"), 135, 15, 60, 20);
GUI_BUTTON_T(favbtn_ren)->callback_clicked = (void*)gui_fav_ren;
}
if (favlist == NULL) {
favlist = gui_list_new (5, 45, 210, 130);
GUI_LIST_T(favlist)->callback_selectitem = (void*)gui_fav_selitem;
}
if (faventry_name == NULL) {
faventry_name = gui_entry_new (NULL, 5, 180, 210, 20);
}
gui_window_item_add (&wfav, faventry_name);
gui_window_item_add (&wfav, favlist);
gui_window_item_add (&wfav, favbtn_ren);
gui_window_item_add (&wfav, favbtn_del);
gui_window_item_add (&wfav, favbtn_add);
gui_window_item_add (&wfav, favbtn_close);
gui_fav_refresh ();
gui_show (&wfav);
};

@ -1,3 +1,4 @@
/* $Id: gui_mainmenu.c,v 1.15 2014/03/06 22:21:46 steffen Exp $ */
/***************************************************************************
* gui_mainmenu.c
*
@ -27,124 +28,72 @@
#include "system.h"
#include "routing.h"
enum {
MMENWIN_UNDEF = 0,
MMENWIN_SEARCH,
MMENWIN_MAPREFRESH,
MMENWIN_IDXREFRESH,
MMENWIN_GPSCONFIG,
MMENWIN_GPSSTARTSTOP,
MMENWIN_MAPCONFIG,
MMENWIN_CLOSE,
MMENWIN_SETDEST,
MMENWIN_DEBUG,
MMENWIN_QUIT
};
void gui_mainmenu_close ();
void gui_mainmenu_search ();
void gui_mainmenu_quit ();
void gui_mainmenu_refresh ();
void gui_mainmenu_refreshidx ();
void gui_mainmenu_gpsconfig ();
void gui_mainmenu_gpsstartstop ();
void gui_mainmenu_mapconfig ();
void gui_mainmenu_setdest ();
void gui_mainmenu_debug ();
void gui_mainmenu_search ();
void gui_mainmenu_quit ();
void gui_mainmenu_routing ();
void gui_mainmenu_config ();
GUIItem *mbtn_close = NULL;
GUIItem *mbtn_quit = NULL;
GUIItem *mbtn_refreshidx = NULL;
GUIItem *mbtn_refresh = NULL;
GUIItem *mbtn_search = NULL;
GUIItem *mbtn_routing= NULL;
GUIItem *mbtn_config= NULL;
static GUIWindow wmmenu = {0};
void gui_mainmenu_show () {
int item = 0;
if (wmmenu.screen == NULL) guiwindow_new (&wmmenu, 175, 200);
if (wmmenu.screen == NULL) gui_window_new (&wmmenu, 200, 200, _("OSMroute Menu"));
wmmenu.screen_changed = 1;
// wmmenu.callback_close = (void*)gui_mainmenu_closecallback;
wmmenu.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
strncpy (wmmenu.title, _("OSMroute Menu"), GUI_TEXTLEN);
/* add buttons */
strncpy (wmmenu.buttons[item].caption, _("Close"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_close;
wmmenu.buttons[item].id = MMENWIN_CLOSE;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 170;
strncpy (wmmenu.buttons[++item].caption, _("Quit"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_quit;
wmmenu.buttons[item].id = MMENWIN_QUIT;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 90;
wmmenu.buttons[item].y = 170;
strncpy (wmmenu.buttons[++item].caption, _("GPS Config"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_gpsconfig;
wmmenu.buttons[item].id = MMENWIN_GPSCONFIG;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 140;
strncpy (wmmenu.buttons[++item].caption, _("GPS On/Off"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_gpsstartstop;
wmmenu.buttons[item].id = MMENWIN_GPSSTARTSTOP;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 110;
strncpy (wmmenu.buttons[++item].caption, _("MAP Config"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_mapconfig;
wmmenu.buttons[item].id = MMENWIN_MAPCONFIG;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 90;
wmmenu.buttons[item].y = 140;
strncpy (wmmenu.buttons[++item].caption, _("MAP Refresh"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_refresh;
wmmenu.buttons[item].id = MMENWIN_MAPREFRESH;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 90;
wmmenu.buttons[item].y = 110;
strncpy (wmmenu.buttons[++item].caption, _("Debug"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_debug;
wmmenu.buttons[item].id = MMENWIN_DEBUG;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 80;
strncpy (wmmenu.buttons[++item].caption, _("IDX Refresh"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_refreshidx;
wmmenu.buttons[item].id = MMENWIN_IDXREFRESH;
wmmenu.buttons[item].w = 80;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 90;
wmmenu.buttons[item].y = 80;
strncpy (wmmenu.buttons[++item].caption, _("Set Destination"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_setdest;
wmmenu.buttons[item].id = MMENWIN_SETDEST;
wmmenu.buttons[item].w = 165;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 15;
strncpy (wmmenu.buttons[++item].caption, _("Search"), GUI_TEXTLEN);
wmmenu.buttons[item].callback_clicked = (void*)gui_mainmenu_search;
wmmenu.buttons[item].id = MMENWIN_SEARCH;
wmmenu.buttons[item].w = 165;
wmmenu.buttons[item].h = 25;
wmmenu.buttons[item].x = 5;
wmmenu.buttons[item].y = 45;
if (mbtn_refresh == NULL) {
mbtn_refresh = gui_button_new (_("Update Map"), 5, 30, 90, 20);
GUI_BUTTON_T(mbtn_refresh)->callback_clicked = (void*)gui_mainmenu_refresh;
}
gui_window_item_add (&wmmenu, mbtn_refresh);
if (mbtn_refreshidx == NULL) {
mbtn_refreshidx = gui_button_new (_("Update Index"), 105, 30, 90, 20);
GUI_BUTTON_T(mbtn_refreshidx)->callback_clicked = (void*)gui_mainmenu_refreshidx;
}
gui_window_item_add (&wmmenu, mbtn_refreshidx);
if (mbtn_routing == NULL) {
mbtn_routing = gui_button_new (_("Routing"), 5, 60, 190, 20);
GUI_BUTTON_T(mbtn_routing)->callback_clicked = (void*)gui_mainmenu_routing;
}
gui_window_item_add (&wmmenu, mbtn_routing);
if (mbtn_search == NULL) {
mbtn_search = gui_button_new (_("Search"), 5, 90, 190, 20);
GUI_BUTTON_T(mbtn_search)->callback_clicked = (void*)gui_mainmenu_search;
}
gui_window_item_add (&wmmenu, mbtn_search);
if (mbtn_config == NULL) {
mbtn_config = gui_button_new (_("Config"), 5, 120, 130, 20);
GUI_BUTTON_T(mbtn_config)->callback_clicked = (void*)gui_mainmenu_config;
}
gui_window_item_add (&wmmenu, mbtn_config);
if (mbtn_quit == NULL) {
mbtn_quit = gui_button_new (_("Quit"), 145, 120, 50, 20);
GUI_BUTTON_T(mbtn_quit)->callback_clicked = (void*)gui_mainmenu_quit;
}
gui_window_item_add (&wmmenu, mbtn_quit);
if (mbtn_close == NULL) {
mbtn_close = gui_button_new (_("Close"), 5, 155, 190, 20);
GUI_BUTTON_T(mbtn_close)->callback_clicked = (void*)gui_mainmenu_close;
}
gui_window_item_add (&wmmenu, mbtn_close);
gui_show (&wmmenu);
};
@ -155,6 +104,18 @@ void gui_mainmenu_close () {
};
void gui_mainmenu_routing () {
gui_close ();
wnd_routing_show ();
};
void gui_mainmenu_config () {
gui_close ();
gui_config_show ();
};
void gui_mainmenu_search () {
gui_close ();
gui_search_show ();
@ -181,19 +142,6 @@ void gui_mainmenu_setdest () {
};
void gui_mainmenu_gpsconfig () {
gui_close ();
#ifdef HAVE_WINAPI
gps_wince_settings ();
#else
#ifdef HAVE_GTK
gpssetting_wnd_show (main_wnd);
#endif
#endif
config_save ();
};
void gui_mainmenu_gpsstartstop () {
gui_close ();
if (gps_isrunning () != 0) gps_stop ();
@ -251,18 +199,21 @@ void gui_mainmenu_refresh () {
void gui_mainmenu_refreshidx () {
char lfn[LEN_FILENAME];
static int _working = 0;
if (_working) return;
_working = 1;
#ifndef _WINDOWSCE_
char lfn[LEN_FILENAME];
char rfn[LEN_FILENAME] = "search.mapidx";
#endif
gui_close ();
map_search_get_filename (lfn, LEN_FILENAME);
#ifndef _WINDOWSCE_
map_webload (rfn, lfn, NULL);
#endif
map_search_sort ();
draw_redrawmap ();
#endif
};
@ -271,10 +222,7 @@ void gui_mainmenu_quit () {
#ifdef _WINDOWSCE_
wince_taskbar (hMainWnd, TRUE);
#endif
route_stop ();
map_save_all ();
config_save ();
exit (0);
app.status = APPSTATUS_quit;
};

@ -26,139 +26,107 @@
#include "gui.h"
#include "system.h"
enum {
SEARCHWIN_UNDEF = 0,
SEARCHWIN_SEARCH,
SEARCHWIN_NEXT,
SEARCHWIN_PREV,
SEARCHWIN_CLOSE,
SEARCHWIN_LABEL,
SEARCHWIN_REFRESH,
SEARCHWIN_TEXT
};
#define SEARCH_MAXRESULT 32
void gui_search_close ();
void gui_search_refresh ();
void gui_search_next ();
void gui_search_prev ();
void gui_search_search ();
void gui_search_city ();
void gui_search_switch (int pos);
struct map_search_dataex {
float distance;
char text[GUI_TEXTLEN];
};
struct map_search_data search_data[SEARCH_MAXRESULT];
struct map_search_dataex search_dataex[SEARCH_MAXRESULT];
char *search_chars[SEARCH_MAXRESULT+1];
struct map_pos search_pos;
int search_data_cnt = 0;
int search_data_cur = -1;
static GUIWindow wsearch = {0};
GUIItem *ws_entryname = NULL;
GUIItem *ws_labelname = NULL;
GUIItem *ws_entrystreet = NULL;
GUIItem *ws_labelstreet = NULL;
GUIItem *ws_btnok = NULL;
GUIItem *ws_btncancel = NULL;
GUIItem *ws_list = NULL;
GUIItem *ws_map = NULL; /* need to finish working on: gui_images and map_view */
void gui_search_show () {
int btn = 0;
int i;
if (wsearch.screen == NULL) guiwindow_new (&wsearch, 220, 60);
if (wsearch.screen == NULL) gui_window_new (&wsearch, 220, 260, _("Search.."));
wsearch.screen_changed = 1;
wsearch.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
strncpy (wsearch.title, _("Search"), GUI_TEXTLEN);
// wmmenu.callback_close = (void*)gui_mainmenu_closecallback;
wsearch.screen_changed = 1;
wsearch.style = WGUI_S_VCENTER | WGUI_S_HTOP;
wsearch.title[0] = 0;
/* search buttons */
strncpy (wsearch.buttons[btn].caption, _("<"), GUI_TEXTLEN);
wsearch.buttons[btn].callback_clicked = (void*)gui_search_prev;
wsearch.buttons[btn].id = SEARCHWIN_PREV;
wsearch.buttons[btn].w = 20;
wsearch.buttons[btn].h = 20;
wsearch.buttons[btn].x = 5;
wsearch.buttons[btn].y = 35;
strncpy (wsearch.buttons[++btn].caption, _(">"), GUI_TEXTLEN);
wsearch.buttons[btn].callback_clicked = (void*)gui_search_next;
wsearch.buttons[btn].id = SEARCHWIN_NEXT;
wsearch.buttons[btn].w = 20;
wsearch.buttons[btn].h = 20;
wsearch.buttons[btn].x = 85;
wsearch.buttons[btn].y = 35;
strncpy (wsearch.buttons[++btn].caption, _("Search"), GUI_TEXTLEN);
wsearch.buttons[btn].callback_clicked = (void*)gui_search_search;
wsearch.buttons[btn].id = SEARCHWIN_SEARCH;
wsearch.buttons[btn].w = 50;
wsearch.buttons[btn].h = 20;
wsearch.buttons[btn].x = 110;
wsearch.buttons[btn].y = 35;
strncpy (wsearch.buttons[++btn].caption, _("Ref"), GUI_TEXTLEN);
wsearch.buttons[btn].callback_clicked = (void*)gui_search_refresh;
wsearch.buttons[btn].id = SEARCHWIN_REFRESH;
wsearch.buttons[btn].w = 30;
wsearch.buttons[btn].h = 20;
wsearch.buttons[btn].x = 165;
wsearch.buttons[btn].y = 35;
strncpy (wsearch.buttons[++btn].caption, _("X"), GUI_TEXTLEN);
wsearch.buttons[btn].callback_clicked = (void*)gui_search_close;
wsearch.buttons[btn].id = SEARCHWIN_CLOSE;
wsearch.buttons[btn].w = 15;
wsearch.buttons[btn].h = 20;
wsearch.buttons[btn].x = 200;
wsearch.buttons[btn].y = 35;
/* add label */
btn = 0;
strncpy (wsearch.labels[btn].text, "0/0", GUI_TEXTLEN);
wsearch.labels[btn].x = 35;
wsearch.labels[btn].y = 37;
wsearch.labels[btn].id = SEARCHWIN_LABEL;
wsearch.labels[btn].textcol = &color[COLOR_white][3];
/* add entry box */
btn = 0;
strncpy (wsearch.entrys[btn].text, "", GUI_TEXTLEN);
wsearch.entrys[btn].id = SEARCHWIN_TEXT;
wsearch.entrys[btn].x = 5;
wsearch.entrys[btn].y = 5;
wsearch.entrys[btn].w = 210;
wsearch.entrys[btn].h = 20;
wsearch.entrys[btn].curpos = 4;
wsearch.entrys[btn].overwrite = 0;
wsearch.entrys[btn].callback_enter = (void*)gui_search_search;
/* Name Ok Button */
if (ws_labelname == NULL) ws_labelname = gui_label_new (_("City:"), 5, 10);
gui_window_item_add (&wsearch, ws_labelname);
gui_show (&wsearch);
};
if (ws_entryname == NULL) ws_entryname = gui_entry_new (_(""), 50, 10, 100, 20);
gui_window_item_add (&wsearch, ws_entryname);
GUI_ENTRY_T (ws_entryname)->callback_enter = gui_search_city;
if (ws_btnok == NULL) ws_btnok = gui_button_new (_("Ok"), 165, 5, 50, 20);
GUI_BUTTON_T (ws_btnok)->callback_clicked = (void*) gui_search_close;
gui_window_item_add (&wsearch, ws_btnok);
void gui_search_close () {
gui_close ();
};
/* street Cancel Button */
if (ws_labelstreet == NULL) ws_labelstreet = gui_label_new (_("Street:"), 5, 35);
gui_window_item_add (&wsearch, ws_labelstreet);
if (ws_entrystreet == NULL) ws_entrystreet = gui_entry_new (_(""), 50, 30, 100, 20);
gui_window_item_add (&wsearch, ws_entrystreet);
void gui_search_refresh () {
map_refresh (view_lon, view_lat);
draw_redrawmap ();
draw ();
};
if (ws_btncancel == NULL) ws_btncancel = gui_button_new (_("Cancel"), 165, 30, 50, 20);
GUI_BUTTON_T (ws_btncancel)->callback_clicked = (void*) gui_search_close;
gui_window_item_add (&wsearch, ws_btncancel);
/* result list */
if (ws_list == NULL) ws_list = gui_list_new (5, 55, 210, 100);
GUI_LIST_T(ws_list)->callback_selectitem = (void*) gui_search_switch;
gui_window_item_add (&wsearch, ws_list);
void gui_search_prev () {
d_printf ("search_data_cur:%d", search_data_cur);
gui_search_switch (search_data_cur-1);
d_printf ("search_data_cur:%d", search_data_cur);
if (gps_isrunning()) {
struct gps_data *gpsdata = gps_getposition ();
search_pos.lon = gpsdata->lon;
search_pos.lat = gpsdata->lat;
}
else {
search_pos.lon = view_lon;
search_pos.lat = view_lat;
}
for (i = 0; i < SEARCH_MAXRESULT+1; i++) search_chars[i] = NULL;
gui_show (&wsearch);
};
void gui_search_next () {
d_printf ("search_data_cur:%d", search_data_cur);
gui_search_switch (search_data_cur+1);
d_printf ("search_data_cur:%d", search_data_cur);
void gui_search_close () {
gui_close ();
};
void gui_search_search () {
d_printf ("search for %s", wsearch.entrys[0].text);
void gui_search_city () {
int i;
struct map_pos pos;
search_data_cnt = map_search (GUI_ENTRY_T(ws_entryname)->text, search_data, SEARCH_MAXRESULT);
for (i = 0; i < search_data_cnt && i < SEARCH_MAXRESULT; i++) {
pos.lon = search_data[i].lon;
pos.lat = search_data[i].lat;
search_dataex[i].distance = map_getdistance (pos, search_pos);
snprintf (search_dataex[i].text, GUI_TEXTLEN, "%4.0fkm %s", search_dataex[i].distance, search_data[i].name);
search_chars[i] = search_dataex[i].text;
search_data_cnt = map_search (wsearch.entrys[0].text, search_data, SEARCH_MAXRESULT);
gui_search_switch (0);
d_printf (" %-3d:%s distance:%f '%s'",i , search_data[i].name, search_dataex[i].distance, search_dataex[i].text);
}
search_chars[i] = NULL;
GUI_LIST_T(ws_list)->data = search_chars;
};
@ -169,14 +137,10 @@ void gui_search_switch (int pos) {
else if (search_data_cur >= search_data_cnt) search_data_cur = 0;
else if (search_data_cur < 0) search_data_cur = search_data_cnt - 1;
if (search_data_cur == -1) strncpy (wsearch.labels[0].text, _("0"), GUI_TEXTLEN);
else {
snprintf (wsearch.labels[0].text, GUI_TEXTLEN, _("%d of %d"), search_data_cur+1, search_data_cnt);
strncpy (wsearch.entrys[0].text, search_data[search_data_cur].name, GUI_TEXTLEN);
if (search_data_cur >= 0) {
view_lon = search_data[search_data_cur].lon;
view_lat = search_data[search_data_cur].lat;
wsearch.screen_changed = 1;
wsearch.entrys[0].curpos = strlen (wsearch.entrys[0].text);
draw ();
}
};

@ -0,0 +1,200 @@
/* %Id: Exp $ */
/***************************************************************************
* gui_selectdir.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include <sys/types.h>
#include <dirent.h>
void gui_sdir_close ();
void gui_sdir_update ();
void gui_sdir_clear ();
void gui_sdir_clicklist (int nr);
GUIWindow wsdir = {0};
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];
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;
};
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;
}
d_printf ("dir:%s", fname);
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;
}
};

@ -0,0 +1,192 @@
/* $Id: gui_selectfile.c,v 1.4 2014/02/12 23:05:35 steffen Exp $ */
/***************************************************************************
* gui_selectdir.c
*
* Copyright (C) 2013 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include <sys/types.h>
#include <dirent.h>
void gui_sfile_close ();
void gui_sfile_update ();
void gui_sfile_clear ();
void gui_sfile_clicklist (int nr);
GUIWindow wsfile = {0};
GUIItem *wsf_close = NULL;
GUIItem *wsf_file = NULL;
GUIItem *wsf_flist = NULL;
char **wsf_list = NULL;
int wsf_listmax = 0;
char wsf_select_file[LEN_FILENAME];
char *gui_sfile_show (char *startpath) {
if (wsfile.screen == NULL) gui_window_new (&wsfile, 220, 250, _("Select File"));
wsfile.screen_changed = 1;
wsfile.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
/* close Button */
if (wsf_close == NULL) wsf_close = gui_button_new (_("Close"), 50, 220, 100, 20);
GUI_BUTTON_T (wsf_close)->callback_clicked = (void*) gui_sfile_close;
gui_window_item_add (&wsfile, wsf_close);
if (wsf_file == NULL) wsf_file = gui_entry_new (startpath, 10, 25, 200, 25);
gui_window_item_add (&wsfile, wsf_file);
if (wsf_flist == NULL) wsf_flist = gui_list_new (10, 55, 200, 140);
GUI_LIST_T (wsf_flist)->callback_selectitem = gui_sfile_clicklist;
GUI_LIST_T (wsf_flist)->data = wsf_list;
gui_window_item_add (&wsfile, wsf_flist);
gui_sfile_update ();
gui_show (&wsfile);
while (currentwin == &wsfile) {
main_wnd_update ();
}
strncpy (wsf_select_file, GUI_ENTRY_T(wsf_file)->text, LEN_FILENAME-1);
return wsf_select_file;
};
void gui_sfile_close () {
gui_close ();
};
void gui_sfile_clicklist (int nr) {
char fname[LEN_FILENAME];
char *seperate;
d_printf ("selected nr:%d '%s'", nr, nr < wsf_listmax ? wsf_list[nr] : "nr >= wsf_listmax");
if (nr >= wsf_listmax || wsf_list[nr] == NULL) return;
if (strcmp (wsf_list[nr], ".") == 0) return;
if (strcmp (wsf_list[nr], "..") == 0) {
strncpy (fname, GUI_ENTRY_T(wsf_file)->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 (wsf_file, fname);
}
else {
if (GUI_ENTRY_T(wsf_file)->text[strlen (GUI_ENTRY_T(wsf_file)->text)-1] == DIR_SEP)
snprintf (fname, LEN_FILENAME, "%s%s", GUI_ENTRY_T(wsf_file)->text, wsf_list[nr]);
else
snprintf (fname, LEN_FILENAME, "%s%c%s", GUI_ENTRY_T(wsf_file)->text, DIR_SEP, wsf_list[nr]);
gui_entry_settext (wsf_file, fname);
}
gui_sfile_update ();
};
void gui_sfile_update () {
int cnt;
DIR *dir = NULL;
struct dirent *direntry = NULL;
char fname[LEN_FILENAME];
struct stat stbuf;
/* clear list and reopen directory */
gui_sfile_clear ();
if ((dir = opendir (GUI_ENTRY_T(wsf_file)->text)) == NULL) {
/* if open fails, reopen with ROOT_DIR which is defined in system.h */
gui_entry_settext (wsf_file, ROOT_DIR);
if ((dir = opendir (GUI_ENTRY_T(wsf_file)->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 = wsf_listmax = 0;
/* need more memory? */
while ((direntry = readdir (dir))) {
if (GUI_ENTRY_T(wsf_file)->text[strlen (GUI_ENTRY_T(wsf_file)->text)-1] == DIR_SEP)
snprintf (fname, LEN_FILENAME, "%s%s", GUI_ENTRY_T(wsf_file)->text, direntry->d_name);
else
snprintf (fname, LEN_FILENAME, "%s%c%s", GUI_ENTRY_T(wsf_file)->text, DIR_SEP, direntry->d_name);
if (stat(fname, &stbuf) == -1) {
d_printf ("could not read stat of file: %s", fname);
continue;
}
d_printf ("dir:%s", fname);
if (cnt >= wsf_listmax) {
/* save old pointer and counter */
char **tmp = wsf_list;
int i = wsf_listmax-1;
/* allocate new list */
wsf_listmax += 512;
wsf_list = ml_malloc (wsf_listmax * sizeof(void*));
memset (wsf_list, 0x0, wsf_listmax * sizeof(void*));
/* copy list */
if (tmp) {
for (; i >= 0; i--) wsf_list[i] = tmp[i];
ml_free (tmp);
}
/* setup new list */
GUI_LIST_T (wsf_flist)->data = wsf_list;
}
wsf_list[cnt] = ml_malloc (LEN_FILENAME);
if (S_ISDIR(stbuf.st_mode)) snprintf (wsf_list[cnt], LEN_FILENAME, "[%s]", direntry->d_name);
else snprintf (wsf_list[cnt], LEN_FILENAME, "%s", direntry->d_name);
d_printf ("added entry:%-3d '%s'", cnt, direntry->d_name);
cnt++;
}
closedir (dir);
};
/*
* remove all listentrys and free list
*/
void gui_sfile_clear () {
int i;
if (wsf_list == NULL) return;
for (i = 0; wsf_list[i]; i++) {
if (wsf_list[i]) ml_free (wsf_list[i]);
wsf_list[i] = NULL;
}
};

@ -43,14 +43,14 @@ void gpswin_btnclose(int x, int y);
void gpswin_show () {
d_printf ("GUI: gps file screen");
if (gpswin.screen == NULL) guiwindow_new (&gpswin, 250, 32);
if (gpswin.screen == NULL) gui_window_new (&gpswin, 250, 32, _("GPS"));
gpswin.screen_changed = 1;
gpswin.callback_close = (void*)gpswin_closecallback;
gpswin.style = WGUI_S_VCENTER | WGUI_S_HBOTTOM;
/* add buttons */
strncpy (gpswin.buttons[0].caption, _("P"), GUI_TEXTLEN);
/* strncpy (gpswin.buttons[0].caption, _("P"), GUI_TEXTLEN);
gpswin.buttons[0].callback_clicked = (void*)gpswin_btnpauseplay;
gpswin.buttons[0].id = GPSWIN_PAUSEPLAY;
gpswin.buttons[0].callback_draw = (void*)gpswin_btndraw;
@ -75,7 +75,7 @@ void gpswin_show () {
gpswin.buttons[2].h = 31;
gpswin.buttons[2].x = 250-32;
gpswin.buttons[2].y = 0;
*/
gui_show (&gpswin);
};
@ -83,13 +83,12 @@ void gpswin_show () {
void gpswin_closecallback () {
d_printf ("GUI: gps win close");
guiwindow_close (&gpswin);
gui_window_close (&gpswin);
};
void gpswin_btndraw (GUIButton *btn) {
int i;
if (btn->id == GPSWIN_PAUSEPLAY) {
/* if (btn->id == GPSWIN_PAUSEPLAY) {
i = gps_file_get_state ();
if (i == GPSF_END) btn->col = &color[COLOR_white][1];
else if (i == GPSF_INIT) btn->col = &color[COLOR_green][0];
@ -125,6 +124,7 @@ void gpswin_btndraw (GUIButton *btn) {
draw_line (currentwin->screen, btn->x + x, btn->y, btn->x + x, btn->y + btn->h, ls);
}
*/
};

@ -18,15 +18,11 @@ int app_init (int argc, char **argv) {
app.status = APPSTATUS_nothing;
config_init ();
d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
map_init ();
d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
#ifdef SPOSMROUTE
draw_init ();
d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
fav_load (fav_getfilename ());
d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
#endif
return 0;
};
@ -48,15 +44,35 @@ int app_shutdown () {
};
int app_loop () {
#ifdef SPOSMROUTE
struct gps_data *gpspos;
if (gps_isrunning () > 0) {
if ((gpspos = gps_loop ())) {
drawgps_set_pos (gpspos);
}
}
draw_mouseloop ();
#endif
return 0;
};
/******************************************************************************
* update stausbar
*/
void app_status (char *text, int progress) {
void app_status (int status, char *text, float progress) {
static char oldtext[255];
if (text) strncpy (app.statusline_text, text, 255);
else strncpy (app.statusline_text, oldtext, 255);
app.statusline_progress = progress;
if (status >= 0) app.status = status;
if (progress < 0.0) app.statusline_progress = 0.0;
else if (progress > 1.0) app.statusline_progress = 1.0;
else app.statusline_progress = progress;
#ifdef SPOSMROUTE
if (currentwin) currentwin->screen_changed = 1;

@ -47,7 +47,7 @@
#include "memoryleak.h"
#include "map.h"
#include "convert_port.h"
#include "ncurses_port.h"
#include "system.h"
char curfile[LEN_FILENAME];
@ -307,8 +307,8 @@ int main (int argc, char *argv[]) {
mkdir (cfg.cachepath, 0755);
}
if (stat(cfg.datapath, &sb) == -1) {
mkdir (cfg.datapath, 0755);
if (stat(cfg.mappath, &sb) == -1) {
mkdir (cfg.mappath, 0755);
}
config_init ();

@ -42,16 +42,26 @@
#include <stdio.h>
#include <string.h>
#ifdef HAVE_SDL
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/* #ifdef HAVE_SDL
#include <SDL.h>
#define FALSE 0
#define TRUE 1
#endif
#ifdef ANDROID
#define FALSE 0
#define TRUE 1
#endif
*/
/*
* Standard gettext macros.
@ -86,6 +96,7 @@
#include "map.h"
#include "system.h"
#include "memoryleak.h"
enum { /* what we're doing at the moment */
APPSTATUS_nothing,
@ -120,12 +131,15 @@ struct cfgdata {
float last_lon;
float last_lat;
float last_scale;
int softkeyboard;
int debug;
};
struct appdata {
char statusline_text[255];
int statusline_progress;
float statusline_progress; // value in 0.0 to 1.0
int status;
float debug_lon;
float debug_lat;
@ -160,7 +174,8 @@ extern struct appdata app;
*/
extern int app_init (int argc, char **argv);
extern int app_shutdown ();
extern void app_status (char *text, int progress);
extern void app_status (int status, char *text, float progress);
extern int app_loop ();
extern void config_init ();
extern void config_draw_load (char *fn);
@ -175,4 +190,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

@ -143,7 +143,7 @@ void rtrl_addwayname (struct rtdata *r, struct rtreflist *rtrl, struct map_way *
int nr; // segment number
int i, n;
struct rtref *ref; // pointer to reference data
static struct rtwayid _rtrl_wlist [RTRL_MAXWAYS]; // only create this once, saves time..
// static struct rtwayid _rtrl_wlist [RTRL_MAXWAYS]; // only create this once, saves time..
int _rtrl_wlist_cnt = 0; // re-init with zero elements
d_printf (" rtrl_addwayname '%s' id:%lld:%d mw->ref:%s", name, mw->id, mw->subid, mw->ref);
@ -202,7 +202,7 @@ void rtrl_addwayname (struct rtdata *r, struct rtreflist *rtrl, struct map_way *
struct map_way *mwtmp = NULL;
struct rtwayid fromdir[2]; /* 0.. left, 1.. right */
struct map_way *mwdir[2] = {NULL, NULL};
int pnrdir[2] = {-1, -1}; /* pnr: where we entered the way */
// int pnrdir[2] = {-1, -1}; /* pnr: where we entered the way */
int dir;
d_printf (" found closest way nr:%d way:%lld:%d dist:%f",
@ -237,11 +237,11 @@ void rtrl_addwayname (struct rtdata *r, struct rtreflist *rtrl, struct map_way *
/* found way */
if (mwdir[0] == NULL) {
mwdir[0]= mwtmp1;
pnrdir[0] = mwtmp->n[i].d_pnr;
// pnrdir[0] = mwtmp->n[i].d_pnr;
}
else if (mwdir[1] == NULL) {
mwdir[1]= mwtmp1;
pnrdir[1] = mwtmp->n[i].d_pnr;
// pnrdir[1] = mwtmp->n[i].d_pnr;
}
else {
d_printf ("%s:%d %s: why there are three connecting referneces? ignoring way:%lld:%d",
@ -272,7 +272,7 @@ void rtrl_addwayname (struct rtdata *r, struct rtreflist *rtrl, struct map_way *
if (map_way_getdistance (mwtmp1, &ref->ways[nr].pos, NULL) * 1.5 < dist) {
fromdir[dir].id = mwdir[dir]->id;
fromdir[dir].sid = mwdir[dir]->subid;
pnrdir[dir] = mwdir[dir]->n[i].d_pnr;
// pnrdir[dir] = mwdir[dir]->n[i].d_pnr;
mwdir[dir] = mwtmp1;
}
else mwdir[dir] = NULL;
@ -968,6 +968,8 @@ void route_start (struct map_pos dest) {
}
}
if (app.status == APPSTATUS_quit) route_stop ();
if (route->state == ROUTING_CALC) {
if ((++calcto) % 200 == 0) main_wnd_update ();
}

@ -0,0 +1,103 @@
/* $Id: wnd_mapcontext.c,v 1.2 2014/03/06 22:21:46 steffen Exp $ */
/***************************************************************************
* wnd_mapcontext.c
*
* 2014-02-12
* Copyright (C) 2014 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* 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.
*
* sposmroute 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
#include "routing.h"
void wnd_mapcontext_close ();
void wnd_mapcontext_addfav ();
void wnd_mapcontext_setdest ();
GUIItem *mcbtn_close = NULL;
GUIItem *mcbtn_addfav = NULL;
GUIItem *mcbtn_setdest = NULL;
static GUIWindow wmmapc = {0};
void wnd_mapcontext_show () {
if (wmmapc.screen == NULL) gui_window_new (&wmmapc, 200, 200, _("Map Menu"));
wmmapc.screen_changed = 1;
wmmapc.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
/* add buttons */
if (mcbtn_addfav == NULL) mcbtn_addfav = gui_button_new (_("Add Favorites"), 5, 30, 110, 20);
if (mcbtn_setdest == NULL) mcbtn_setdest = gui_button_new (_("Set Destination"), 5, 60, 110, 20);
if (select_enabled) {
GUI_BUTTON_T(mcbtn_setdest)->col = GUI_BUTTON_T(mcbtn_addfav)->col = &color[COLOR_white][1];
GUI_BUTTON_T(mcbtn_setdest)->textcol = GUI_BUTTON_T(mcbtn_addfav)->textcol = &color[COLOR_white][3];
GUI_BUTTON_T(mcbtn_addfav)->callback_clicked = (void*)wnd_mapcontext_addfav;
GUI_BUTTON_T(mcbtn_setdest)->callback_clicked = (void*)wnd_mapcontext_setdest;
}
else {
GUI_BUTTON_T(mcbtn_setdest)->col = GUI_BUTTON_T(mcbtn_addfav)->col = &color[COLOR_white][1];
GUI_BUTTON_T(mcbtn_setdest)->textcol = GUI_BUTTON_T(mcbtn_addfav)->textcol = &color[COLOR_white][2];
GUI_BUTTON_T(mcbtn_addfav)->callback_clicked = NULL;
GUI_BUTTON_T(mcbtn_setdest)->callback_clicked = NULL;
}
gui_window_item_add (&wmmapc, mcbtn_addfav);
gui_window_item_add (&wmmapc, mcbtn_setdest);
if (mcbtn_close == NULL) {
mcbtn_close = gui_button_new (_("Close"), 5, 90, 110, 20);
GUI_BUTTON_T(mcbtn_close)->callback_clicked = (void*)wnd_mapcontext_close;
}
gui_window_item_add (&wmmapc, mcbtn_close);
gui_show (&wmmapc);
};
void wnd_mapcontext_close () {
d_printf ("gui_mapcontext_close");
gui_close ();
};
void wnd_mapcontext_setdest () {
static int _setdest = 0;
wmmapc.event_called = 0; // make events possible, because route_start will
// not come back until routing is finished or aborted.
d_printf ("gui_mapcontext_setdest");
d_printf ("set destination routing start");
gui_close ();
if (select_enabled == 0) d_printf ("no destination selected.");
if (_setdest == 1) d_printf ("routing already active");
else {
_setdest = 1;
route_start (select_pos);
_setdest = 0;
}
};
void wnd_mapcontext_addfav () {
d_printf ("gui_mapcontext_addfav");
gui_close ();
};

@ -0,0 +1,112 @@
/* $Id: wnd_routing.c,v 1.3 2013/06/20 21:28:04 steffen Exp $ */
/***************************************************************************
* wnd_routing.c
*
* Created on: 18.06.2013
* Copyright (C) 2011 Steffen Pohle
* steffen@gulpe.de
****************************************************************************/
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "osmroute.h"
#include "draw.h"
#include "gui.h"
#include "system.h"
static GUIWindow wrouting = {0};
GUIItem *wr_label[5] = { NULL };
GUIItem *wr_entrytxt = NULL;
GUIItem *wr_entrylon = NULL;
GUIItem *wr_entrylat = NULL;
GUIItem *wr_labellon = NULL;
GUIItem *wr_labellat = NULL;
GUIItem *wr_labeldest = NULL;
GUIItem *wr_btnfav = NULL;
GUIItem *wr_btnsearch = NULL;
GUIItem *wr_btnnavigate = NULL;
GUIItem *wr_btnclose = NULL;
void wnd_routing_search ();
void wnd_routing_navigate ();
void wnd_routing_close ();
void wnd_routing_fav ();
void wnd_routing_show () {
char text[128];
if (wrouting.screen == NULL) gui_window_new (&wrouting, 220, 130, NULL);
wrouting.screen_changed = 1;
wrouting.style = WGUI_S_VCENTER | WGUI_S_HCENTER;
if (wr_label[0] == NULL) wr_label[0] = gui_label_new (_("destination:"), 5, 5);
gui_window_item_add (&wrouting, wr_label[0]);
if (wr_entrytxt == NULL) wr_entrytxt = gui_entry_new ("", 80, 5, 100, 20);
gui_window_item_add (&wrouting, wr_entrytxt);
if (wr_btnsearch == NULL) wr_btnsearch = gui_button_new (_("Search"), 25, 55, 70, 20);
GUI_BUTTON_T(wr_btnsearch)->callback_clicked = wnd_routing_search;
gui_window_item_add (&wrouting, wr_btnsearch);
if (wr_btnfav == NULL) wr_btnfav = gui_button_new (_("Favorites"), 100, 55, 70, 20);
GUI_BUTTON_T(wr_btnfav)->callback_clicked = wnd_routing_fav;
gui_window_item_add (&wrouting, wr_btnfav);
if (wr_label[1] == NULL) wr_label[1] = gui_label_new (_("lon:"), 5, 30);
gui_window_item_add (&wrouting, wr_label[1]);
if (wr_entrylon == NULL) {
sprintf (text, "%9.6f", view_lon);
wr_entrylon = gui_entry_new (text, 30, 30, 75, 20);
}
gui_window_item_add (&wrouting, wr_entrylon);
if (wr_label[2] == NULL) wr_label[2] = gui_label_new (_("lat:"), 110, 30);
gui_window_item_add (&wrouting, wr_label[2]);
if (wr_entrylat == NULL) {
sprintf (text, "%9.6f", view_lat);
wr_entrylat = gui_entry_new (text, 135, 30, 75, 20);
}
gui_window_item_add (&wrouting, wr_entrylat);
if (wr_btnnavigate == NULL) wr_btnnavigate = gui_button_new (_("Navigate"), 60, 105, 75, 20);
GUI_BUTTON_T(wr_btnnavigate)->callback_clicked = wnd_routing_navigate;
gui_window_item_add (&wrouting, wr_btnnavigate);
if (wr_btnclose == NULL) wr_btnclose = gui_button_new (_("Close"), 140, 105, 75, 20);
GUI_BUTTON_T(wr_btnclose)->callback_clicked = wnd_routing_close;
gui_window_item_add (&wrouting, wr_btnclose);
gui_show (&wrouting);
};
void wnd_routing_fav () {
};
void wnd_routing_search () {
};
void wnd_routing_navigate () {
};
void wnd_routing_close () {
gui_close ();
};

@ -30,7 +30,6 @@
struct map_hash **mhash = NULL;
int mhash_max = 0;
int mhash_pos = 0;
struct map_lsstat *mlsstat = NULL;
int map_busy = 0;
extern int map_search_fd;
@ -42,12 +41,25 @@ extern int map_search_fd;
*/
void map_init () {
int i, j;
char fn[LEN_FILENAME];
d_printf ("map_init");
d_printf (" MAP_HASH_DEGFACTOR:%f", MAP_HASH_DEGFACTOR);
d_printf (" MAP_OSMWEB_DELTA:%f", MAP_OSMWEB_DELTA);
d_printf (" MAP_LSHASHFACTOR:%d", MAP_LSHASHFACTOR);
d_printf (" MAP_LSSTAT_MAX:%d", MAP_LSSTAT_MAX);
d_printf (" Directory: %s", cfg.mappath);
strncpy (fn, cfg.mappath, LEN_FILENAME);
if (fn[(i=strlen(fn))-1] == DIR_SEP) fn[i] = '\0';
else {
d_printf (" append '%c' to mappath.", DIR_SEP);
cfg.mappath[strlen(cfg.mappath)+1] = '\0';
cfg.mappath[strlen(cfg.mappath)] = DIR_SEP;
}
if (!dir_exist (fn)) {
d_printf ("***************** dir does not exist **************************");
}
if (mlsstat == NULL)
mlsstat = (struct map_lsstat*) ml_malloc (MAP_LSSTAT_MAX*sizeof (struct map_lsstat));
@ -70,7 +82,6 @@ void map_init () {
mhash_max = MAP_HASH_MAX;
mhash = (struct map_hash**) ml_malloc (sizeof (void*) * (mhash_max));
mhash_pos = mhash_max/2;
for (i = 0; i < mhash_max; i++)
mhash[i] = NULL;
};
@ -240,6 +251,9 @@ void map_refresh (float lon, float lat) {
map_ls_get_filename (rfn, LEN_FILENAME, map_geo2igeo (lon), map_geo2igeo (lat));
#if defined(SPOSMROUTE)
map_webload (fn, rfn, NULL);
map_clear ();
map_init ();
draw_redrawmap ();
#endif
};
@ -293,6 +307,12 @@ void map_refreshblock (struct map_pos start, struct map_pos end, float delta) {
#endif
}
}
map_clear ();
map_init ();
#if defined(SPOSMROUTE)
draw_redrawmap ();
#endif
};

@ -34,7 +34,7 @@
#define MAP_W_NAMELEN 64
#define MAP_HASH_DEGFACTOR 80.0f
#define MAP_OSMWEB_DELTA 0.025f
#define MAP_OSMWEB_DELTA 0.0125f
#define MAP_LSHASHFACTOR 80
#define MAP_LSFREECNT 4096
@ -44,7 +44,7 @@
#define MAP_LSSTAT_MAX 128
#endif
#define MAP_LSSIZE_HASH 28
#define MAP_LSSIZE_WAY 16
#define MAP_LSSIZE_WAY 14
#define MAP_LSSIZE_WAYNODE 23
#define MAP_LSSIZE_POS 8
#define MAP_LSSIZE_AREA 12
@ -53,7 +53,7 @@
#define MAP_SEARCHLINE_LEN 128
#define MAP_HASH_DEFAULTSIZE 4096
#define MAP_HASH_DEFAULTSIZE 0x20000
#if defined(__MINGW32CE__) || defined(_WIN32_WCE)
#define MAP_HASH_MAX 128
@ -176,6 +176,7 @@ struct map_way {
struct map_area {
char status;
unsigned long long int id;
unsigned short int subid;
unsigned char type;
unsigned char flags;
@ -375,6 +376,7 @@ extern struct map_way *map_way_find (struct map_hash *mh, unsigned long long int
extern void map_way_copy (struct map_way *dest, struct map_way *src);
extern int map_way_add (struct map_way *way, int loadflags);
extern int map_way_add_to_hash (struct map_hash *mh, struct map_way *mw);
extern int map_way_append_to_hash (struct map_hash *mh, struct map_way *mw);
extern int map_way_getsize (struct map_way *way);
extern int map_way_findclosest (struct map_pos *pos, struct map_pos *waypos, int idh, char *name, int namelen, unsigned long long int *closest_id, unsigned short int *closest_sid);
extern float map_way_getdistance (struct map_way *mw, struct map_pos *pos, struct map_pos *waypos);
@ -389,6 +391,7 @@ extern struct map_area *map_area_find (struct map_hash *mh, unsigned long long i
extern void map_area_copy (struct map_area *dest, struct map_area *src);
extern int map_area_add (struct map_area *area, int loadflags);
extern int map_area_add_to_hash (struct map_hash *mh, struct map_area *ma);
extern int map_area_append_to_hash (struct map_hash *mh, struct map_area *ma);
extern int map_area_getsize (struct map_area *area);

@ -32,6 +32,27 @@
*
*/
/*
* add the area without checking for it's size, also no update is done
*/
int map_area_append_to_hash (struct map_hash *mh, struct map_area *ma) {
int size;
struct map_area *a = mh->areas;
mh->areas = (struct map_area*) map_hash_getfree_aligned (mh, POINTERALIGNMENT);
/* copy the area data to the free entry
* calc size and set free entry to it's new place */
size = map_area_getsize (ma);
map_area_copy (mh->areas, ma);
mh->areas->next = a;
mh->free = mh->free + size;
mh->areascnt++;
SETFLAG(mh->status, MS_changed);
return 1;
};
/*
* add the area without checking for it's size, but do an update
*/
@ -39,11 +60,18 @@ int map_area_add_to_hash (struct map_hash *mh, struct map_area *ma) {
int size;
struct map_area *a;
/* check if the first element is already the one we want to update */
if (mh->areas && mh->areas->id == ma->id && mh->areas->subid == ma->subid) {
mh->areas = mh->areas->next;
mh->areascnt--;
}
/* find possible update and go to the end */
if (mh->areas) {
/* find last way */
a = mh->areas;
while (a && a->next) {
if (a->next->id == ma->id) {
if (a->next->id == ma->id && a->next->subid == a->subid) {
/* found old way.. just delete .. */
a->next = a->next->next;
mh->areascnt--;
@ -85,6 +113,8 @@ int map_area_add (struct map_area *area, int loadflags) {
int size;
if (area->p == NULL || area->p_cnt == 0) return 0;
// area->type = area->subid % MAREA_campsite + 1;
// d_printf ("subid:%d type:%d cnt:%d", area->subid, area->type, area->p_cnt);
size = map_area_getsize (area);
mh = map_hash_get (area->p[0].lon, area->p[0].lat, loadflags);
@ -110,6 +140,7 @@ void map_area_copy (struct map_area *dest, struct map_area *src) {
int i;
dest->id = src->id;
dest->subid = src->subid;
dest->type = src->type;
dest->p_cnt = src->p_cnt;
dest->p = (struct map_pos*) (dest->data);

@ -73,39 +73,28 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) {
struct map_hash *res = NULL;
int hi;
hi = mhash_pos;
if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) res = mhash[hi];
else {
hi = mhash_pos+1;
if (hi >= mhash_max) hi = 0;
while (hi != mhash_pos) {
for (hi = 0; hi < mhash_max; hi++)
if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) {
res = mhash[hi];
break;
for (; hi > 0; hi--) mhash[hi] = mhash[hi-1];
mhash[0] = res;
return res;
}
if (++hi >= mhash_max) hi = 0;
if (loadflags & MHLOAD_RELOAD) {
if (mhash[mhash_max-1]) {
map_hash_free (mhash[mhash_max-1], 1);
mhash[mhash_max-1] = NULL;
}
memmove (&mhash[1], &mhash[0], sizeof (struct map_hash*)*mhash_max-1);
mhash[0] = NULL;
if (res == NULL && loadflags & MHLOAD_RELOAD) {
res = map_load_hash (ilon, ilat);
if (res) {
if ((--mhash_pos) < 0) mhash_pos = mhash_max-1;
/* add on the givin place, delete old entry */
if (mhash[mhash_pos]) {
map_hash_free (mhash[mhash_pos], 1);
mhash[mhash_pos] = NULL;
}
/* add or update */
if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__);
mhash[mhash_pos] = res;
mhash[0] = res;
DELFLAG (res->status, MS_changed);
}
}
}
return res;
};
@ -116,18 +105,22 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) {
* if it already excist exchange it and free the old hash data from the memory
*/
int map_hash_add (struct map_hash *mh) {
int i;
int i, fi = -1; /* fi: free hash position */
struct map_hash *mhold = NULL;
if (mh == NULL) return 0;
/* check if we need to "UPDATE" or to add the hash data */
for (mhold = NULL, i = 0; i < mhash_max; i++) if (mhash[i]) {
for (mhold = NULL, i = 0; i < mhash_max; i++) {
if (mhash[i]) {
if (mhash[i]->pos.ilon == mh->pos.ilon && mhash[i]->pos.ilat == mh->pos.ilat) {
mhold = mhash[i];
fi = i;
break;
}
}
else if (fi == -1) fi = i;
}
if (mhold != NULL) { /* update !! NOSAVEING !! */
mhash[i] = NULL;
@ -135,18 +128,18 @@ int map_hash_add (struct map_hash *mh) {
mhold = NULL;
}
if ((--mhash_pos) < 0) mhash_pos = mhash_max-1;
/* add on the givin place, delete old entry */
mhold = NULL;
if (mhash[mhash_pos]) {
map_hash_free (mhash[mhash_pos], 1);
mhash[mhash_pos] = NULL;
if (fi == -1) {
if (mhash[mhash_max-1]) {
map_hash_free (mhash[mhash_max-1], 1);
mhash[mhash_max-1] = NULL;
}
/* add or update */
if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__);
mhash[mhash_pos] = mh;
memmove (&mhash[0], &mhash[1], sizeof (struct map_hash*)*mhash_max-1);
mhash[0] = NULL;
mhash[0] = mh;
}
else
mhash[fi] = mh;
return 1;
};
@ -174,10 +167,11 @@ void map_hash_free (struct map_hash *mh, int noremove) {
* allocate new memory, copy all the data and free the momory again.
*/
struct map_hash *map_hash_realloc (struct map_hash *mhorg, int memsize) {
struct map_hash *res;
struct map_hash *res = NULL;
int i = memsize;
if (i < mhorg->datasize) i = mhorg->datasize;
if (i < mhorg->datasize) return res;
res = map_hash_alloc (i);
map_hash_copy (res, mhorg);
@ -214,7 +208,7 @@ void map_hash_copy (struct map_hash *hd, struct map_hash *hs) {
i = 0;
mw = hs->ways;
while (mw && i < hs->wayscnt) {
map_way_add_to_hash (hd, mw);
map_way_append_to_hash (hd, mw);
mw = mw->next;
i++;
}
@ -226,7 +220,7 @@ void map_hash_copy (struct map_hash *hd, struct map_hash *hs) {
ma = hs->areas;
i = 0;
while (ma && i < hs->areascnt) {
map_area_add_to_hash (hd, ma);
map_area_append_to_hash (hd, ma);
ma = ma->next;
i++;
}

@ -38,6 +38,8 @@
#include "memoryleak.h"
#include "osmroute.h"
#define MAP_BITS_SUBID 8
char *lsrw_data = NULL;
int lsrw_data_size = 0;
char *lshash_data = NULL;
@ -215,7 +217,7 @@ struct map_lsstat *map_ls_statopen (char *fname) {
mlss.r_fd = mlss.w_fd = 0;
mlss.changed = 0;
if (file_exist (mlss.fname) == NULL) {
if (file_exist (mlss.fname) == 0) {
d_printf ("map_ls_statopen file '%s' not found.", mlss.fname);
mlss.r_fd = 0;
return &mlss;
@ -576,9 +578,8 @@ char *map_ls_hash2data (struct map_hash *mh, int *size) {
/* save the basic data */
ui64 = mw->id; /* id */
ui64 = (ui64 << MAP_BITS_SUBID) | mw->subid;
woutpos = mempush (woutpos, &ui64, 8);
ui16 = mw->subid; /* subid */
woutpos = mempush (woutpos, &ui16, 2);
ui8 = mw->type; /* type */
woutpos = mempush (woutpos, &ui8, 1);
ui8 = mw->flags; /* flags */
@ -644,7 +645,7 @@ char *map_ls_hash2data (struct map_hash *mh, int *size) {
map_ls_hashdatacheckpos (*size, &woutpos);
/* save the basic data */
ui64 = ma->id; /* id */
ui64 = (ma->id << MAP_BITS_SUBID) | ma->subid; /* id */
woutpos = mempush (woutpos, &ui64, 8);
ui8 = ma->type; /* type */
woutpos = mempush (woutpos, &ui8, 1);
@ -839,9 +840,8 @@ struct map_hash *map_ls_data2hash (char *data, int size) {
for (cnt = 0; cnt < lsh.ways; cnt++) {
/* load basic data */
inpos = mempop (inpos, &ui64, 8);
way->id = ui64;
inpos = mempop (inpos, &ui16, 2);
way->subid = ui16;
way->subid = ui64 % (1<<MAP_BITS_SUBID);
way->id = (ui64 >> MAP_BITS_SUBID);
inpos = mempop (inpos, &ui8, 1);
way->type = ui8;
inpos = mempop (inpos, &ui8, 1);
@ -914,6 +914,7 @@ struct map_hash *map_ls_data2hash (char *data, int size) {
area->next = NULL;
inpos = mempop (inpos, &ui64, 8);
area->subid = ui64 % (1<<MAP_BITS_SUBID);
area->id = ui64;
inpos = mempop (inpos, &ui8, 1);
area->type = ui8;
@ -1114,7 +1115,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++) {

@ -34,6 +34,7 @@
#include "map.h"
#include "system.h"
#include "memoryleak.h"
#include "vector.h"
#include <locale.h>
#include <unistd.h>
@ -119,7 +120,9 @@ struct s_osm_xmlcallback {
long long int filepos;
};
#define OSM_HASHNODES 16
//
// number of Hashnodes to keep in memory
#define OSM_HASHNODES 32
static struct s_osm_hashnodes _hashnodes[OSM_HASHNODES];
static struct s_osm_hashnodes *hashnodes[OSM_HASHNODES];
@ -190,6 +193,7 @@ void osm_waynodes_checknode (struct s_osm_hashnodes *nhash, struct osm_node *nod
void osm_marea_new (struct s_osmmarea *a, int max);
void osm_area_save (struct osm_way *oway, struct s_osmmarea *marea);
int osm_area_split_add (struct s_osmmarea *marea);
void osm_nodedetail_save (struct osm_nodedetail *onoded, struct osm_node *node);
@ -413,7 +417,7 @@ struct s_osm_hashnodes *osm_hashnodes_load (short int hid, int loadhash) {
/*
* all data will be saved imedatly so we need only to close the file
* all data will be saved immediately so we need only to close the file
*/
void osm_hashnodes_free (struct s_osm_hashnodes *hnode) {
if (hnode->hid == -1) return;
@ -659,7 +663,8 @@ int osm_node_load (struct osm_node *node, unsigned long long int id) {
* save the waynode data inside the hash file to read all needed data later on
* and check the waynodes inside the map files.
*/
void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned long long int id, unsigned short int subid, unsigned short int pnr) {
void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned long long int id,
unsigned short int subid, unsigned short int pnr) {
struct s_osm_hashnodes *hnodes = NULL;
struct osm_nodehash hash;
struct osm_waynode wn;
@ -695,7 +700,8 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
do {
lseek (hnodes->nodes_fd, wpos, SEEK_SET);
if (read (hnodes->nodes_fd, &wn, sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__,
hnodes->fnnodes, hash.pos);
errorexit (-1);
}
wpos = wn.next;
@ -706,7 +712,8 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
pos = 0 - (long long int)sizeof (struct osm_waynode);
lseek (hnodes->nodes_fd, pos, SEEK_CUR);
if (write (hnodes->nodes_fd, &wn, sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
d_printf ("%s:%d could not write data to file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
d_printf ("%s:%d could not write data to file:%s pos:%d", __FILE__, __LINE__,
hnodes->fnnodes, hash.pos);
errorexit (-1);
}
}
@ -718,7 +725,6 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
errorexit (-1);
}
return;
};
@ -733,14 +739,15 @@ void osm_waynodes_check () {
for (hid = 0; hid < osm_hidmax; hid++) {
sprintf (text, _("checking for waynodes in hid %d"), hid);
app_status (text, 0);
app_status (-1, text, 0.0);
ohash = osm_hashnodes_load (hid, 1);
for (i = 0; i < ohash->hash_cnt; i++) {
if ((i%1024) == 0) main_wnd_loop (i, ohash->hash_cnt);
/* read node */
lseek (ohash->nodes_fd, ohash->hash[i].pos, SEEK_SET);
if (read (ohash->nodes_fd, &node, sizeof (struct osm_node)) < sizeof (struct osm_node)) {
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, ohash->fnnodes, ohash->hash[i].pos);
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__,
ohash->fnnodes, ohash->hash[i].pos);
errorexit (-1);
}
osm_waynodes_checknode (ohash, &node);
@ -776,7 +783,8 @@ void osm_waynodes_checknode (struct s_osm_hashnodes *ohash, struct osm_node *nod
do {
/* read waynode */
if (read (ohash->nodes_fd, &osm_wnode[wncnt], sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, ohash->fnnodes, osm_wnode[wncnt].next);
d_printf ("%s:%d could not read data from file:%s pos:%d",
__FILE__, __LINE__, ohash->fnnodes, osm_wnode[wncnt].next);
errorexit (-1);
}
lseek (ohash->nodes_fd, osm_wnode[wncnt].next, SEEK_SET);
@ -1012,6 +1020,7 @@ void osm_marea_new (struct s_osmmarea *a, int max) {
}
a->marea->id = 0;
a->marea->subid = 0;
a->marea->type = MAREA_unknown;
a->marea->p = (struct map_pos*) a->marea->data;
a->marea->p_cnt = 0;
@ -1023,7 +1032,8 @@ void osm_marea_new (struct s_osmmarea *a, int max) {
* hash data block. I case the way goes over more hash segments the
* way will be slit into peaces
*
* splitting into peaces does not work yet
* splitting into peaces does not work yet, also taking care of the
* polygons, no angles over 180°.
*
* CALL with NULL will free all unneeded memory
*/
@ -1034,6 +1044,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
static int nodestat_alloc = 0; // size of the struct
struct map_pos pos, p1; // current hash, pos
struct osm_node curnode, node; // current node, node
int sid = 0;
/* check if we just need to free all data */
if (oway == NULL) {
@ -1103,6 +1114,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
/* save first node */
area->marea->id = oway->wid;
area->marea->subid = sid;
area->marea->type = oway->type;
area->marea->p_cnt = 1;
area->marea->p = (struct map_pos *) area->marea->data;
@ -1118,7 +1130,8 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
if (++nd >= oway->ncnt) nd = 0; /* count +1, check for overrun */
while (nd != ndfirst) {
if (osm_node_load (&node, oway->nid[nd]) == -1) {
d_printf ("%s:%d osm_area_save count not find node number: %lld", __FILE__, __LINE__, oway->nid[nd]);
d_printf ("%s:%d osm_area_save count not find node number: %lld",
__FILE__, __LINE__, oway->nid[nd]);
return;
}
pos.lon = node.lon;
@ -1148,7 +1161,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
}
if (++nd >= oway->ncnt) nd = 0; /* count +1, check for overrun */
}
map_area_add (area->marea, MHLOAD_RELOAD);
osm_area_split_add (area);
}
} while (ndfirst < oway->ncnt);
@ -1156,10 +1169,218 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
};
/*
* convert area into a polygon without angles above 180°
* it saves time late in drawing on slow devices.
* only needed because of GL_TRIANGLE_STRIP and return
* last subid saved.
*/
struct s_osmareapnt {
int pnr;
fPoint km;
float angle;
float sel_dist;
float sel_angle;
};
#define MAX_SUBID 250
int osm_area_split_add (struct s_osmmarea *marea) {
/* allocate enought memory */
struct map_area *a = NULL;
struct s_osmareapnt *pt = ml_malloc (sizeof (struct s_osmareapnt) * marea->marea->p_cnt);
int i, st, pt_c, c;
int _debug = 0, rotated = 0;
float angle_sum;
// if (marea->marea->id == 22963835) _debug = 1;
// else return 1;
// d_printf ("marea: %lld cnt:%d", marea->marea->id, marea->marea->p_cnt);
// map_area_add (marea->marea, MHLOAD_RELOAD);
// return 1;
if (_debug) d_printf ("area:%lld:%d", marea->marea->id, marea->marea->subid);
a = ml_malloc (map_area_getsize (marea->marea));
map_area_copy (a, marea->marea);
/* calculate all klon, klat and prepare start struct, also
* ignore double entrys */
for (pt_c = 0, i = 0; i < marea->marea->p_cnt; i++) {
if (i == 0) st = marea->marea->p_cnt-1;
else st = i-1;
if (marea->marea->p[i].lon == marea->marea->p[st].lon
&& marea->marea->p[i].lat == marea->marea->p[st].lat) continue;
pt[pt_c].pnr = i;
pt[pt_c].angle = -1.0;
pt[pt_c].km.x = map_lon2km (marea->marea->p[i].lon, marea->marea->p[i].lat);
pt[pt_c].km.y = map_lat2km (marea->marea->p[i].lat);
if (_debug) d_printf ("pt[%-3d].pnr:%d km.x:%f km.y:%f", pt_c, pt[pt_c].pnr, pt[pt_c].km.x, pt[pt_c].km.y);
pt_c++;
}
while (pt[0].pnr >= 0 && pt_c > 2 && a->subid < MAX_SUBID) {
/* st - will keep first pt to start checking polygon
* c - count how many angles are above 180° */
if (_debug) d_printf ("**************** subid:%d pt_c:%d", a->subid, pt_c);
for (angle_sum = 0.0, st = -1, c = 0, i = 0; i < pt_c; i++) {
if (i == pt_c-1) pt[i].angle = point_angle (pt[i-1].km, pt[i].km, pt[0].km);
else if (i == 0) pt[i].angle = point_angle (pt[pt_c-1].km, pt[i].km, pt[i+1].km);
else pt[i].angle = point_angle (pt[i-1].km, pt[i].km, pt[i+1].km);
if (pt[i].angle > M_PI) { /* only select first pt */
if (st == -1) st = i;
else if (pt[st].angle < pt[i].angle) st = i;
c++;
}
angle_sum += pt[i].angle;
if (_debug) d_printf ("i:%-2d pnr:%-2d angle:%f",i, pt[i].pnr, pt[i].angle);
}
angle_sum /= (float)pt_c;
if (_debug) d_printf ("c:%d pt_c:%d st:%d angle_sum:%f",c, pt_c, st, angle_sum);
/* make sure we going counterclock direction, only first area */
if (rotated == 0 && angle_sum > M_PI && a->subid == marea->marea->subid) {
struct s_osmareapnt *pt_ = ml_malloc (sizeof (struct s_osmareapnt) * pt_c);
if (_debug) d_printf ("change rotation ...");
for (i = 0; i < pt_c; i++) pt_[pt_c - i - 1] = pt[i];
ml_free (pt);
pt = pt_;
rotated = 1;
continue;
}
/* if c==0 save last areapart */
else if (c == 0) {
a->p_cnt = 0;
for (i = 0; i < pt_c; i++) {
if (_debug) d_printf ("0: added %d pnr:%d", a->p_cnt, pt[i].pnr);
a->p[a->p_cnt++] = marea->marea->p[pt[i].pnr];
pt[i].pnr = -1;
}
map_area_add (a, MHLOAD_RELOAD);
a->subid++;
}
/* if c==1 select j as 0 then quit, if GL_TRIANGLE_STRIP gets kicked out of
* openGL we need to change this */
else if (c == 1) {
for (a->p_cnt = 0, i = st; a->p_cnt < pt_c;) {
if (_debug) d_printf ("1: added %d pnr:%d", a->p_cnt, pt[i].pnr);
a->p[a->p_cnt++] = marea->marea->p[pt[i].pnr];
pt[i].pnr = -1;
if (i < pt_c-1) i++;
else i = 0;
}
map_area_add (a, MHLOAD_RELOAD);
a->subid++;
}
/* check again for the part to split the area. */
else {
int j, sel, s, i_old, c;
float dist;
float angle;
/* check if selected start is working for us */
sel = st;
i_old = -1;
do {
/* fill up all sel_angles and sel_dists */
if (sel < pt_c-1) s = sel + 1;
else s = 0;
if (_debug) d_printf ("select %d [pnr:%d] second:%d", sel, pt[sel].pnr, s);
for (i = 0; i < pt_c; i++) {
if (i != sel) {
pt[i].sel_angle = point_angle (pt[i].km, pt[sel].km, pt[s].km);
pt[i].sel_dist = vec_len (vec_sub (pt[i].km, pt[sel].km));
}
else {
pt[i].sel_angle = -2.0;
pt[i].sel_dist = -2.0;
}
if (_debug) d_printf (" %-2d pnr:%-2d angle:%f dist:%f", i, pt[i].pnr, pt[i].sel_angle, pt[i].sel_dist);
}
a->p_cnt = 0;
a->p[a->p_cnt++] = marea->marea->p[pt[sel].pnr];
angle = 0.0;
if (_debug) d_printf (" check for possible loop: i:%d s:%d st:%d sel:%d angle:%f pt[i].sel_angle:%f", i, s, st, sel, angle, pt[i].sel_angle);
for (i_old = -1, i = s, angle = 0.0; i != sel && angle <= pt[i].sel_angle;) {
if (_debug) d_printf (" i:%d sel:%d angle:%f pt[i].sel_angle:%f", i, st, angle, pt[i].sel_angle);
for (j = i; j != sel;) {
if (_debug) d_printf (" j:%d (pnr:%d, angle:%f, dist:%f) i:%d (pnr:%d, angle:%f, dist:%f) ", j, pt[j].pnr, pt[j].sel_angle, pt[j].sel_dist, i, pt[i].pnr, pt[i].sel_angle, pt[i].sel_dist);
if (pt[i].sel_angle > pt[j].sel_angle && pt[i].sel_dist > pt[j].sel_dist) {
if (_debug) d_printf (" break 1");
break;
}
j++; if (j >= pt_c) j = 0;
}
if (j != sel) {
/* something is in the way */
if (_debug) d_printf (" break 2");
break;
}
else {
/* found something */
if (i_old >= 0) pt[i_old].pnr = -1; /* already second pass */
a->p[a->p_cnt++] = marea->marea->p[pt[i].pnr];
if (_debug) d_printf ("add nr:%d pnr:%d", a->p_cnt-1, pt[i].pnr);
angle = pt[i].sel_angle;
}
i_old = i;
i++; if (i >= pt_c) i = 0;
}
if (a->p_cnt < 3) {
/* found nothing try next one */
sel++; if (sel >= pt_c) sel = 0;
}
} while (sel != st && a->p_cnt < 3);
/* add element */
if (a->p_cnt >= 3) {
map_area_add (a, MHLOAD_RELOAD);
a->subid++;
}
}
/* recreate pall list, delete unneeded elements (pnr == -1) */
for (c = 0, i = 0; i < pt_c; i++) if (pt[i].pnr != -1) pt[c++] = pt[i];
if (pt_c == c) {
d_printf ("%s:%d pt_c == c : nothing deleted.. something went wrong.", __FILE__, __LINE__);
d_printf (" rotated:%d", rotated);
break;
}
pt_c = c;
}
if (a->subid >= MAX_SUBID) {
d_printf ("%s:%d max subid reached. area id:%lld", __FILE__, __LINE__, a->id);
}
if (pt[0].pnr >= 0 && pt_c > 2) {
d_printf ("%s:%d osm_area_split_add: something went very wrong", __FILE__, __LINE__);
d_printf (" marea->id: %lld:%d", a->id, a->subid);
d_printf (" pt[0].pnr:%d pt[1].pnr:%d pall_cnt: %d", pt[0].pnr, pt[1].pnr, pt_c);
}
/* free unneeded memory and return to caller */
ml_free (a);
ml_free (pt);
return a->subid;
};
/********************************************************************
* save detail information of the node. This will also create the
* search table.
* search index.
*/
void osm_nodedetail_save (struct osm_nodedetail *onoded, struct osm_node *node) {
int i, j;
@ -1386,7 +1607,7 @@ void osm_processdata (xmlTextReaderPtr reader) {
osm.oway->type -= MWAY_MAX;
osm_area_cnt++;
osm_area_save (osm.oway, &osm.area);
if (osm.oway->type != MAREA_ignore) osm_area_save (osm.oway, &osm.area);
}
else {
osm_ways_cnt++;
@ -1446,7 +1667,7 @@ void osm_processdata (xmlTextReaderPtr reader) {
return;
}
onoded.id = onoded.id;
onoded.id = onode.id;
osm_nodedetail_append (&onoded, (char*)k, (char*)v);
free ((void *)k);
free ((void *)v);
@ -1505,7 +1726,7 @@ void osm_processdata (xmlTextReaderPtr reader) {
else if (strcmp ((char*) v, (char*) "steps") == 0) osm.oway->type = MWAY_footway;
else {
osm.oway->type = MWAY_unknown_way;
// printf ("unknown highway:'%s'\n", v);
printf ("unknown highway:'%s'\n", v);
}
}
@ -1703,7 +1924,7 @@ void osm_loadfile (char *fn) {
osm_init ();
if (fn == NULL) return;
app_status (_("converting file"), 0);
app_status (-1, _("converting file"), 0.0);
d_printf ("osm_loadfile (%s)", fn);
/* check the extension of the osm file */
@ -1765,7 +1986,7 @@ void osm_loadfile (char *fn) {
/* reset the locale setting back to the environment setting */
setlocale (LC_ALL, NULL);
osm_free ();
app_status (_(""), -1);
app_status (-1, _(""), 0.0);
};
@ -1785,11 +2006,26 @@ void map_load_web (struct map_pos hs, struct map_pos he) {
char fcache[LEN_FILENAME];
} wl[MLWEBMAX];
d_printf ("map_load_web: (%f , %f) --> (%f , %f)", hs.lon, hs.lat, he.lon, he.lat);
/* check for cache directory */
if (stat(cfg.cachepath, &sb) == -1) {
char fn[LEN_FILENAME];
strncpy (fn, cfg.cachepath, LEN_FILENAME);
fn[strlen(fn)-1] = 0;
d_printf ("create cache dir:%s", fn);
#if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) && !defined(__MINGW32__)
mkdir (fn, 0755);
#else
mkdir (fn);
#endif
}
app.status = APPSTATUS_loadfromweb;
#if defined (_LINUX_)
osm_load_from_web_end = he;
osm_load_from_web_start = hs;
app_status (_("refresh from OpenStreetMap.org"), 0);
app_status (-1, _("refresh from OpenStreetMap.org"), 0.0);
for (ret = 0; ret < MLWEBMAX; ret++) wl[ret].p.used = 0;
for (ret = 0; ret < 13; ret++) args[ret] = NULL;
@ -1798,12 +2034,14 @@ void map_load_web (struct map_pos hs, struct map_pos he) {
for (h.lat = hs.lat; h.lat < he.lat || cmpf(h.lat, he.lat); h.lat = h.lat + MAP_OSMWEB_DELTA) {
do {
main_wnd_loop (-1,-1);
/* check for any finished forked processes
* if so, call osm_loadfile */
for (i = 0; i < MLWEBMAX; i++) {
if (wl[i].p.used) {
ret = execwait (&wl[i].p);
if (ret == 1) {
osm_loadfile (wl[i].fcache);
app_status (_("refresh from OpenStreetMap.org"), 0);
app_status (-1, _("refresh from OpenStreetMap.org"), 0.0);
main_wnd_update ();
}
}
@ -1811,7 +2049,7 @@ void map_load_web (struct map_pos hs, struct map_pos he) {
for (i = 0; i < MLWEBMAX && wl[i].p.used == 1; i++);
}
while (i >= MLWEBMAX);
while (i >= MLWEBMAX); /* exit if we can fork another process */
y1 = CALC_START (h.lon, MAP_OSMWEB_DELTA);
x1 = CALC_START (h.lat, MAP_OSMWEB_DELTA);

@ -116,10 +116,11 @@ void map_search_add (char *country, char *name, unsigned long long int id, float
/* copy country */
cp = dataline;
strncpy (cp, n, MAP_SEARCHLINE_LEN-(cp-dataline));
strncpy (cp, n, MAP_SEARCHLINE_LEN-(cp-dataline)-3);
cp = cp + strlen (cp); cp[0] = 0; cp++;
strncpy (cp, c, MAP_SEARCHLINE_LEN-(cp-dataline));
strncpy (cp, c, MAP_SEARCHLINE_LEN-(cp-dataline)-2);
cp = cp + strlen (cp); cp[0] = 0; cp++;
snprintf (cp, MAP_SEARCHLINE_LEN-(cp-dataline), "%lld %f %f\n", id, lon, lat);
@ -200,7 +201,7 @@ void map_search_sort_alg1 (struct maps_sort *data) {
}
if (j % 100 == 0) {
sprintf (text, _("Sorting search.mapidx %d/%d"), j, data->cnt);
app_status (text, 0);
app_status (-1, text, 0.0);
main_wnd_update ();
}
}
@ -350,7 +351,7 @@ void map_search_sort_alg2 (struct maps_sort *data) {
/* display update on the screen */
if (to++ < 0 || to > 250) {
sprintf (text, _("sorting search.mapidx %d"), maps_qs_pos);
app_status (text, 0);
app_status (-1, text, 0.0);
main_wnd_update ();
to = 0;
}
@ -440,7 +441,7 @@ void map_search_sort () {
lid = msd.id;
if (i % 10000 == 0) {
sprintf (text, _("save search.mapidx %d"), i);
app_status (text, 0);
app_status (-1, text, 0.0);
main_wnd_update ();
}
}
@ -471,8 +472,8 @@ void map_search_sort () {
* the size on file.
*/
static char maps_line[MAP_SEARCHLINE_LEN*4];
#warning maps_readpos.. read current position without checing and return
#warning start of next line.
#warning maps_readpos.. read current position without checking
#warning and return start of next line.
/*
* read an random position, check if we are at the start of valid data. If not
@ -480,7 +481,7 @@ static char maps_line[MAP_SEARCHLINE_LEN*4];
* parameter: pos - entry position inside file
* data - destination of found data
* size - size of data block
* return: next position to read data.
* return: final start of current data block
*/
unsigned long int maps_readpos (unsigned long int pos, struct map_search_data *data, int *size) {
size_t realpos;
@ -496,33 +497,37 @@ unsigned long int maps_readpos (unsigned long int pos, struct map_search_data *d
if (readsize <= 0) return -1;
/* search where the current line starts (go to the left) */
for (start = pos-realpos; start > 0; start--)
// d_printf ("start at: pos:%ld realpos:%d start:%d", pos, realpos, pos-realpos);
for (start = pos-realpos; start > 0; start--) {
// d_printf (" found:start:%-4d %x '%c' delta:%d", start, maps_line[start], maps_line[start], realpos+start-pos);
if (maps_line[start] == '\n') {
start++;
break;
}
}
if (start < 0) { /* underrun buffer? */
d_printf ("maps_readpos: found no start. pos:%ld realpos:%lld", pos, realpos);
return -1;
}
d_printf ("start:%d", start);
// d_printf (" maps_readpos pos:%ld start:%d delta:%d", pos, start, (realpos+start)-pos);
/* search where the current line ends */
for (end = start; end < readsize && maps_line[end] != '\n'; end++);
if (end >= readsize) {
// d_printf ("maps_readpos: found no end.");
d_printf ("maps_readpos: found no end.");
return -1;
}
*data = map_search_line2data (maps_line+start);
*size = end-start;
// d_printf (" size:%d", *size);
return realpos+start;
};
int map_search (char *name, struct map_search_data *data, int datasize) {
size_t blocksize, blockstart;
uint64_t blocksize, blockstart, realstart;
struct stat buf;
int i, j, cmpres, k;
@ -535,33 +540,65 @@ int map_search (char *name, struct map_search_data *data, int datasize) {
blocksize = buf.st_size;
blockstart = 0;
/* search for name inside the data */
do {
i = maps_readpos (blocksize/2+blockstart, data, &j);
if (i < 0) {
d_printf ("map_search something went wrong. i < 0 name:%s", name);
realstart = maps_readpos (blocksize/2+blockstart, data, &j);
if (realstart < 0) {
d_printf ("map_search something went wrong. realstart < 0 name:%s", name);
return 0;
}
d_printf ("search blocksize:%lld blockstart:%lld i:%d j:%d", blocksize, blockstart, i, j);
if ((cmpres = strcasecmp (name, data->name)) > 0) {
d_printf ("search blocksize:%lld blockstart:%lld realstart:%lld j:%d", (long long int)blocksize, (long long int)blockstart, (long long int)realstart, j, data->name);
if ((cmpres = strncasecmp (name, data->name, strlen (name)))> 0) {
/* name is lager than data */
blocksize = blocksize - ((i+j) - blockstart);
blockstart = i+j;
blocksize = blocksize - (realstart+j-blockstart);
blockstart = realstart+j+1;
}
else if (cmpres < 0) {
/* name is smaller than data */
blocksize = i - blockstart;
blocksize = realstart - blockstart;
}
d_printf ("compare: '%s' with '%s' returns:%d", name, data->name, cmpres);
} while (cmpres != 0 && blocksize > MAP_SEARCHLINE_LEN*2);
d_printf ("found blockstart:%lld datasize:%d, i:%d", blockstart, datasize, i);
blockstart = i-MAP_SEARCHLINE_LEN;
/* find first data inside list, go backwards until no match found */
d_printf ("found blockstart:%lld blocksize:%lld, realstart:%lld text:'%-12s'", (long long int)blockstart,
(long long int)blocksize, (long long int)realstart, data->name);
j = 0;
if (cmpres <= 0) {
blockstart = realstart;
d_printf ("<=0 blockstart:%lld realstart:%lld name:%s", (long long int)blockstart,
(long long int)realstart, name);
do {
realstart = maps_readpos (blockstart, data, &j);
d_printf ("blockstart:%lld realstart:%lld data->name:%s", (long long int) blockstart, (long long int) realstart, data->name);
blockstart = realstart-2;
cmpres = strncasecmp (name, data->name, strlen (name));
d_printf (" cmpres:%d", cmpres);
} while (blockstart >= 0 && cmpres <= 0 && realstart >= 0);
blockstart = realstart+j;
}
else if (cmpres > 0) {
blockstart = realstart;
d_printf (">0 blockstart:%lld realstart:%lld name:%s", (long long int) blockstart, (long long int) realstart, name);
do {
realstart = maps_readpos (blockstart, data, &j);
d_printf ("blockstart:%lld realstart:%lld data->name:%s", (long long int)blockstart, (long long int)realstart, data->name);
blockstart = realstart+j;
cmpres = strncasecmp (name, data->name, strlen (name));
d_printf (" cmpres:%d", cmpres);
} while (cmpres > 0 && realstart >= 0);
blockstart = realstart;
}
if (realstart < 0) return 0;
if (blockstart < 0) blockstart = 0;
for (i = 0, k = 0; i < datasize*2 && k < datasize; i++) {
blockstart = maps_readpos (blockstart, data+k, &j);
d_printf ("create list: k:%d i:%d blockstart:%lld j:%d", k, i, blockstart, j);
if (blockstart < 0) break;
blockstart += j;
realstart = maps_readpos (blockstart, data+k, &j);
d_printf ("create list: k:%d i:%d blockstart:%lld j:%d '%s'", k, i, (long long int)blockstart, j, data[k].name);
if (realstart < 0) break;
blockstart = realstart + j;
if (strncasecmp (name, data[k].name, strlen (name)) == 0) k++;
}

@ -88,6 +88,36 @@ int map_way_add_to_hash (struct map_hash *mh, struct map_way *mw) {
};
/*
* append the way without checking for it's size or double entry, no update done
*/
int map_way_append_to_hash (struct map_hash *mh, struct map_way *mw) {
int size;
struct map_way *w = mh->ways;
/* check if the hash pos and the waypos are valid */
if (mw->p_cnt > 0) if (map_geo2igeo (mw->p[0].lon) != mh->pos.ilon ||
map_geo2igeo (mw->p[0].lat) != mh->pos.ilat) {
d_printf ("p[0]:%d,%d mhpos:%d,%d way does not bleong to hash.", __FUNCTION__, map_geo2igeo (mw->p[0].lon), map_geo2igeo (mw->p[0].lat), mh->pos.ilon, mh->pos.ilat);
errorexit (-1);
}
/* check if the first element is already the one we want to update */
mh->ways = (struct map_way*) map_hash_getfree_aligned (mh, POINTERALIGNMENT);
/* copy the way data to the free entry
* calc size and set free entry to it's new place */
size = map_way_getsize (mw);
map_way_copy (mh->ways, mw);
mh->ways->next = w;
mh->free = mh->free + size;
mh->wayscnt++;
SETFLAG(mh->status, MS_changed);
return 1;
};
/******************************************************************************
* Add/Update way information
* - load/ get hash table

@ -346,7 +346,7 @@ int map_webload (char *remotefn, char *localfn, char *statustext) {
else strncpy (_statustext, statustext, 255);
d_printf ("map_webload started");
app.status = APPSTATUS_loadfromweb;
app_status(APPSTATUS_loadfromweb, NULL, 0.0);
strncpy (host, HOST, NET_HOSTLEN);
strncpy (port, PORT, NET_PORTLEN);
@ -399,6 +399,7 @@ int map_webload (char *remotefn, char *localfn, char *statustext) {
to = time(NULL);
if (filesize > 0) sprintf (text, _("%s%d/%dkb loaded"), _statustext, filelen/1024, filesize/1024);
else sprintf (text, _("%s%dkb loaded"), _statustext, filelen/1024);
app_status(-1, text, (float)((float)filelen/(float)filesize));
main_wnd_update ();
}
}
@ -418,9 +419,7 @@ int map_webload (char *remotefn, char *localfn, char *statustext) {
if (file_exist (tmpfn)) unlink (tmpfn);
}
map_clear ();
app.status = APPSTATUS_nothing;
app_status(NULL, -1);
app_status(APPSTATUS_nothing, NULL, 0.0);
return 0;
};

@ -2,6 +2,7 @@
#include "osmroute.h"
#include "system.h"
#include "memoryleak.h"
#include "utf8.h"
#include <ft2build.h>
#include FT_FREETYPE_H
@ -55,9 +56,12 @@ struct font* font_load(char *name) {
exit (1);;
}
FT_Set_Pixel_Sizes(f->face, 0, 16);
FT_Set_Pixel_Sizes(f->face, 0, 12);
d_printf ("font loaded (size:%d).", f->buffersize);
if (FT_Select_Charmap(f->face, FT_ENCODING_UNICODE))
d_printf ("FT_Select_Charmap: error");
return f;
}
@ -68,6 +72,7 @@ struct font* font_load(char *name) {
*/
void font_draw (struct font *f, char *text, float x, float y, float sx, float sy) {
char *p;
uint32_t u8chr;
int i;
GLfloat vp[8];
GLfloat vt[8] = {0, 1,
@ -93,10 +98,16 @@ void font_draw (struct font *f, char *text, float x, float y, float sx, float sy
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
/* Loop through all characters */
for (p = text; *p; p++) {
for (p = text; *p;) {
u8chr = u8_decode (p, &i);
if (i == 0) {
p++;
continue;
}
p = p + i;
/* Try to load and render the character */
if ((i = FT_Load_Char(f->face, *p, FT_LOAD_RENDER))) {
if ((i = FT_Load_Char(f->face, u8chr, FT_LOAD_RENDER))) {
d_printf ("error:%d", i);
continue;
}
@ -104,7 +115,7 @@ void font_draw (struct font *f, char *text, float x, float y, float sx, float sy
/* Upload the "bitmap", which contains an 8-bit grayscale image, as an alpha texture */
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, g->bitmap.width, g->bitmap.rows, 0, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);
/* Calculate the vertex and texture coordinates */
// d_printf ("x: %f advance:%d %d", x, g->advance.x, g->advance.x >> 6);
// d_printf ("char:%c bitmap.rows:%d bitmap_top:%d", *p, g->bitmap.rows, g->bitmap_top);
vp[0] = x; vp[1] = y + g->bitmap.rows - g->bitmap_top;
vp[2] = x + g->bitmap.width; vp[3] = y + g->bitmap.rows - g->bitmap_top;
@ -116,11 +127,10 @@ void font_draw (struct font *f, char *text, float x, float y, float sx, float sy
glDrawArrays(GL_TRIANGLE_FAN,0,4);
// glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vp);
glDrawArrays(GL_LINES,0,2);
// glVertexPointer(2, GL_FLOAT, 0, vp);
// glDrawArrays(GL_LINES,0,2);
// glDisableClientState(GL_VERTEX_ARRAY);
/* Advance the cursor to the start of the next character */
// x += (g->advance.x >> 6);
// y -= (g->advance.y >> 6);

@ -39,7 +39,7 @@
iPoint gfx_screensize = {0, 0};
int gfx_last_alloc_img = 0;
int gfx_last_img_fbo = 0;
struct font *font = NULL;
void gfx_fbo_switch (struct image *img);
/*****************************************************************************/
@ -64,6 +64,9 @@ void gfx_init (int width, int height) {
gfx_screensize.x = width;
gfx_screensize.y = height;
gfx_resize (width, height);
font_init ();
font = font_load ("FreeSans.ttf");
};
@ -138,8 +141,13 @@ void gfx_draw_line (struct image *dimg, int x1, int y1, int x2, int y2, struct l
/* polygon mit runden ecken....? bei width > 1 */
gfx_fbo_switch (dimg);
if (style.width < 1.0) style.width = 1.0;
glColor4f(style.c.c.r, style.c.c.g, style.c.c.b, 1.0);
glPointSize(style.width*0.5);
glBegin (GL_POINTS);
glVertex2i (x1, y1);
glVertex2i (x2, y2);
glEnd ();
glLineWidth (style.width);
glColor3f (style.c.c.r, style.c.c.g, style.c.c.b);
glBegin (GL_LINES);
glVertex2i (x1, y1);
glVertex2i (x2, y2);
@ -150,23 +158,16 @@ 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) {
int i;
gfx_fbo_switch (dimg);
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++)
glVertex2i (p[i].x, p[i].y);
glEnd ();
// glBegin (GL_LINES);
// d_printf ("line width: %f",style.width);
// glLineWidth (style.width/2.0);
// glColor4f (style.c.c.r, style.c.c.g, style.c.c.b, 1.0f);
// for (i = 0; i < pcnt; i++)
// glVertex2i (p[i].x, p[i].y);
// glEnd ();
glEnd ();
};
@ -175,6 +176,8 @@ void gfx_draw_polygon (struct image *dimg, iPoint *p, int pcnt, struct line_styl
*/
void gfx_draw_text (struct image *dimg, int x, int y, char *text, struct color *c) {
gfx_fbo_switch (dimg);
glColor4f (c->c.r, c->c.g, c->c.b, 1.0f);
font_draw (font, text, x, y+12.0, 1.0, 1.0);
};
@ -191,10 +194,10 @@ void gfx_draw_img (struct image *dimg, int dx, int dy, int dw, int dh, struct im
glBegin (GL_QUADS);
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
fx = (float) sx/(float) simg->width;
fy = (float) sy/(float) simg->height;
fw = (float) dw/(float) simg->width;
fh = (float) dh/(float) simg->height;
fx = (float) sx/(float) (simg->width);
fy = (float) sy/(float) (simg->height);
fw = (float) dw/(float) (simg->width);
fh = (float) dh/(float) (simg->height);
glTexCoord2d (fx, fy);
glVertex2i (dx, dy);
@ -292,11 +295,6 @@ void gfx_img_free (struct image *img) {
};
void gfx_draw_rect (struct image *dimg, int x1, int y1, int x2, int y2, struct color *c) {
};
#define HEADER_SIZE 8
int gfxpng_fd = 0;
void png_fd_read(png_structp png, png_bytep data, png_size_t size) {

@ -1,4 +1,4 @@
/* $Id: sdl_main.c,v 1.16 2014/03/06 22:21:46 steffen Exp $ */
#include <SDL.h>
#include "osmroute.h"
#include "system.h"
@ -61,7 +61,7 @@ void test_draw () {
}
if (_tmpx > img->width-TEST_WIDTH) _tmpdx = -1;
if (_tmpx < 0) _tmpdx = 1;
if (_delay % 20 == 0) _tmpx += _tmpdx;
if (_delay % 1 == 0) _tmpx += _tmpdx;
if (_tmpy > img->height-TEST_WIDTH) _tmpdy = -1;
if (_tmpy < 0) _tmpdy = 1;
@ -96,13 +96,7 @@ void test_draw () {
Uint32 msdl_timercallback (Uint32 interval, void *param) {
struct gps_data *gpspos;
if (gps_isrunning () > 0) {
if ((gpspos = gps_loop ())) {
drawgps_set_pos (gpspos);
}
}
app_loop ();
d_printf ("timer %d", interval);
@ -111,11 +105,19 @@ 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) {
static int oldkey = 0;
/* only the last MOUSEMOTION event will handled */
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;
@ -130,26 +132,53 @@ int msdl_eventloop () {
exit (2);
}
gfx_resize (event.resize.w, event.resize.h);
// draw ();
test_draw ();
draw ();
}
break;
case SDL_MOUSEMOTION:
gevent.mousepos.x = event.motion.x;
gevent.mousepos.y = event.motion.y;
gevent.mousebtn = 0;
gevent.scr_mpos.x = event.motion.x;
gevent.scr_mpos.y = event.motion.y;
gevent.mousebtn = event.motion.state;
gevent.event = EGUI_MOUSEMOVE;
// gui_event (gevent);
// draw_mousemove (event.motion.x, event.motion.y, -1);
test_draw();
gui_event (gevent);
break;
case SDL_MOUSEBUTTONDOWN:
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.scr_mpos.x = event.motion.x;
gevent.scr_mpos.y = event.motion.y;
gevent.mousebtn = 1;
gevent.event = EGUI_MOUSERELEASED;
gui_event (gevent);
break;
case SDL_KEYDOWN:
case SDL_KEYDOWN: {
int keyu = 0;
d_printf ("keydown. old_key:%d keysym:%d ukey:%d", oldkey, event.key.keysym.sym, event.key.keysym.unicode);
if (oldkey != event.key.keysym.sym) {
keyu = oldkey = event.key.keysym.unicode;
gevent.keychar = keyu;
if (event.key.keysym.sym == SDLK_UP) gevent.key = GUIKEY_UP;
else if (event.key.keysym.sym == SDLK_DOWN) gevent.key = GUIKEY_DOWN;
else if (event.key.keysym.sym == SDLK_LEFT) gevent.key = GUIKEY_LEFT;
else if (event.key.keysym.sym == SDLK_RIGHT) gevent.key = GUIKEY_RIGHT;
else gevent.key = event.key.keysym.sym;
gevent.event = EGUI_KEYCHAR;
gevent.scr_mpos.x = -1;
gevent.scr_mpos.y = -1;
if (gui_event (gevent) != 0) draw();
}
} break;
case SDL_KEYUP:
d_printf ("keyup. old_key:%d keysym:%d ukey:%d", oldkey, event.key.keysym.sym, event.key.keysym.unicode);
oldkey = 0;
break;
default:
@ -161,8 +190,71 @@ int msdl_eventloop () {
};
/*
* some input handling code.. in sdl it seemed to work fine... used alot
* within the bomberclone code.
*
int key = 0, keyu = 0;
ki->changed = 0;
if (event->type == SDL_KEYDOWN && keybinput_oldkey != event->key.keysym.sym) {
key = keybinput_oldkey = event->key.keysym.sym;
keyu = event->key.keysym.unicode;
if (key == 8) { // BACKSPACE
if (ki->curpos > 0) {
ki->curpos--;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
else if (ki->type == KEYBI_text && ((keyu >= 32 && keyu <= 126) || (keyu >= 128 && keyu <= 255))) {
if (ki->curpos < ki->maxlen) {
ki->text[ki->curpos++] = event->key.keysym.unicode;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
else if (ki->type == KEYBI_int && (keyu == '-' || (keyu >= '0' && keyu <= '9'))) {
if (ki->curpos < 255) {
ki->text[ki->curpos] = event->key.keysym.unicode;
if (atoi(ki->text) <= ki->maxlen)
ki->curpos++;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
else if (ki->type == KEYBI_float && (keyu == '-' || keyu == '.' || (keyu >= '0' && keyu <= '9'))) {
if (ki->curpos < 255) {
ki->text[ki->curpos++] = event->key.keysym.unicode;
ki->text[ki->curpos] = 0;
ki->changed = 1;
}
}
ki->len = strlen (ki->text);
}
if (keybinput_oldkey == SDLK_RETURN && event->type == SDL_KEYUP)
keyu = 1;
else if (keybinput_oldkey == SDLK_ESCAPE && event->type == SDL_KEYUP)
keyu = -1;
else
keyu = 0;
if (event->type == SDL_KEYUP)
keybinput_oldkey = 0;
return keyu;
*/
int main (int argc, char **argv) {
SDL_Surface *scr;
static time_t to;
time_t t1;
/* Initialize SDL for video output */
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
@ -177,16 +269,22 @@ int main (int argc, char **argv) {
SDL_Quit();
exit (2);
}
SDL_EnableUNICODE(1);
app_init (argc, argv);
gfx_init (RESOLUTION_X, RESOLUTION_Y);
test_draw ();
// draw ();
draw ();
while (app.status != APPSTATUS_quit) {
msdl_eventloop ();
test_draw ();
// draw ();
while (msdl_eventloop ());
t1 = time (NULL);
if (to != t1) {
app_loop ();
to = t1;
}
draw ();
}
SDL_Quit ();
@ -196,10 +294,9 @@ 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 : %d", app.status);
app_loop();
while (msdl_eventloop ());
}

@ -34,6 +34,8 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include <SDL.h>
/*****************************************************************************
* gfx stuff...

@ -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);

@ -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,18 +407,18 @@ 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);
draw_mousemove (x, y, -1);
break;
case WM_CHAR:
if (wParam < ' ') gevent.keyval = 0xff00 | wParam;
else gevent.keyval = wParam;
gevent.event = EGUI_KEYRELEASED;
d_printf ("char wParam:%x keyval:%x", wParam, gevent.keyval);
if (wParam < ' ') gevent.keychar = 0xff00 | wParam;
else gevent.keychar = wParam;
gevent.event = EGUI_KEYCHAR;
d_printf ("char wParam:%x keyval:%x", wParam, gevent.keychar);
if (gui_event (gevent) != 0) draw();
break;
// case WM_KEYUP:
@ -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 ();
}
@ -488,7 +488,7 @@ void DoMenuActions(HWND hWnd, INT id) {
map_webload (rfn, lfn, NULL);
map_search_sort ();
#endif
app_status ("", -1);
app_status (-1, "", 0.0);
}
break;
case IDM_MENU_MAP_WEBLOAD:
@ -568,4 +568,3 @@ void main_wnd_update () {
DispatchMessage(&message);
}
};

Loading…
Cancel
Save