--- trunk/src/map-tool.c 2009/08/17 10:51:56 58 +++ trunk/src/map-tool.c 2009/08/19 14:21:14 65 @@ -18,6 +18,7 @@ */ #include "gpxview.h" +#include "converter.h" #include // for isnan #ifdef ENABLE_OSM_GPS_MAP @@ -27,12 +28,6 @@ #define MAP_SOURCE OSM_GPS_MAP_SOURCE_OPENSTREETMAP #define GPS_DEFAULT_ZOOM 13 -/* equatorial radius in meters */ -#define EQ_RADIUS (6378137.0) - -#define RAD2DEG(a) (((a)*180.0)/M_PI) -#define DEG2RAD(a) (((a)*M_PI)/180.0) - #define PROXY_KEY "/system/http_proxy/" static const char *get_proxy_uri(appdata_t *appdata) { @@ -71,37 +66,8 @@ return NULL; } -static void map_zoom(map_context_t *context, int step) { - gint zoom; - OsmGpsMap *map = OSM_GPS_MAP(context->widget); - g_object_get(map, "zoom", &zoom, NULL); - zoom = osm_gps_map_set_zoom(map, zoom+step); - - /* enable/disable zoom buttons as required */ - gtk_widget_set_sensitive(context->zoomin, - zoom < osm_gps_map_source_get_max_zoom(MAP_SOURCE)); - gtk_widget_set_sensitive(context->zoomout, - zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE)); - - /* hmm ... this doesn't really work */ - osm_gps_map_osd_speed(map, zoom); - - /* save new zoom */ - context->appdata->map.zoom = zoom; -} - -static gboolean -cb_map_zoomin(GtkButton *button, map_context_t *context) { - map_zoom(context, +1); - return FALSE; -} - -static gboolean -cb_map_zoomout(GtkButton *button, map_context_t *context) { - map_zoom(context, -1); - return FALSE; -} - +/* TODO: This needs to be wired to the GPS button in osm_gps_map */ +#if 0 static gboolean cb_map_gps(GtkButton *button, map_context_t *context) { pos_t *refpos = get_pos(context->appdata); @@ -116,18 +82,7 @@ return FALSE; } - -static GtkWidget -*map_add_button(int icon, GCallback cb, gpointer data, - char *tooltip) { - GtkWidget *button = gtk_button_new(); - gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon)); - g_signal_connect(button, "clicked", cb, data); -#ifndef USE_MAEMO - gtk_widget_set_tooltip_text(button, tooltip); #endif - return button; -} static int dist2pixel(map_context_t *context, float km, float lat) { return 1000.0*km/osm_gps_map_get_scale(OSM_GPS_MAP(context->widget)); @@ -141,7 +96,7 @@ gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); /* ... and enable "goto" button if it's valid */ - gtk_widget_set_sensitive(context->gps, ok); + /* TODO: gtk_widget_set_sensitive(context->gps, ok); */ if(ok) { float heading = NAN; @@ -251,8 +206,8 @@ /* translate between osm-gps-map positions and gpxview ones */ pos_t coord2pos(coord_t coo) { pos_t pos; - pos.lat = RAD2DEG(coo.rlat); - pos.lon = RAD2DEG(coo.rlon); + pos.lat = rad2deg(coo.rlat); + pos.lon = rad2deg(coo.rlon); return pos; } @@ -301,9 +256,16 @@ // now draw this onto the original context cairo_set_source_surface(cr, image_surface, x, y); + cairo_paint(cr); } +#ifndef BIG_BALLOONS +#define LINE_SKIP 7 +#else +#define LINE_SKIP 12 +#endif + static void balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { cache_t *cache = (cache_t*)data; @@ -329,23 +291,95 @@ /* ... and right of it the waypoint id */ cairo_text_extents_t extents; - cairo_select_font_face (cr, "Sans", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_BOLD); + if(cache->id) { + cairo_select_font_face (cr, "Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, 20.0); - cairo_text_extents (cr, cache->id, &extents); +#ifndef BIG_BALLOONS + cairo_set_font_size (cr, 20.0); +#else + cairo_set_font_size (cr, 36.0); +#endif - /* draw right of icon vertically centered */ - x += gdk_pixbuf_get_width(icon) + 5; - y += (gdk_pixbuf_get_height(icon) + extents.height)/2; - - cairo_move_to (cr, x,y); - printf("trying to draw %s\n", cache->id); - cairo_set_source_rgba (cr, 0, 0, 0, 1); - cairo_show_text (cr, cache->id); - cairo_stroke (cr); + cairo_text_extents (cr, cache->id, &extents); + + /* display id right of icon vertically centered */ + x += gdk_pixbuf_get_width(icon) + 5; + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + cairo_move_to (cr, x, y); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_show_text (cr, cache->id); + cairo_stroke (cr); + + y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; + } else + y += gdk_pixbuf_get_height(icon); + + /* return to the left border and below icon/text */ + x = rect->x; + + /* everything from here uses the same font */ + cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); +#ifndef BIG_BALLOONS + cairo_set_font_size (cr, 14.0); +#else + cairo_set_font_size (cr, 24.0); +#endif + + if(cache->name) { + /* draw cache name */ + cairo_text_extents (cr, cache->name, &extents); + y += extents.height; + cairo_move_to (cr, x, y); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_show_text (cr, cache->name); + cairo_stroke (cr); + /* return to the left border and below text */ + y += LINE_SKIP; + x = rect->x; + } + + if(cache->terrain) { + /* draw cache rating */ + const char *terrain = "Terrain:"; + icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); + cairo_text_extents (cr, _(terrain), &extents); + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + + /* draw "Terrain:" string */ + cairo_move_to (cr, x, y); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_show_text (cr, _(terrain)); + cairo_stroke (cr); + x += extents.width + 2; + + /* draw terrain stars */ + cairo_draw_pixbuf(cr, icon, x, y - + (gdk_pixbuf_get_height(icon) + extents.height)/2); + + x += gdk_pixbuf_get_width(icon) + LINE_SKIP; + y -= (gdk_pixbuf_get_height(icon) + extents.height)/2; + } + + if(cache->difficulty) { + const char *difficulty = "Difficulty:"; + cairo_text_extents (cr, _(difficulty), &extents); + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + + /* draw "Difficulty:" string */ + cairo_move_to (cr, x, y); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_show_text (cr, _(difficulty)); + cairo_stroke (cr); + x += extents.width + 2; + + icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); + cairo_draw_pixbuf(cr, icon, x, y - + (gdk_pixbuf_get_height(icon) + extents.height)/2); + } } static gboolean @@ -420,8 +454,6 @@ context = appdata->map.context = g_new0(map_context_t, 1); context->appdata = appdata; - GtkWidget *hbox = gtk_hbox_new(FALSE, 0); - char *path = g_strdup_printf("%s/map/", appdata->image_path); const char *proxy = get_proxy_uri(appdata); @@ -484,30 +516,10 @@ g_signal_connect(G_OBJECT(context->widget), "button-release-event", G_CALLBACK(on_map_button_release_event), context); - gtk_box_pack_start_defaults(GTK_BOX(hbox), context->widget); - /* zoom button box */ - GtkWidget *vbox = gtk_vbox_new(FALSE,0); - - context->zoomin = - map_add_button(10, G_CALLBACK(cb_map_zoomin), - context, _("Zoom in")); - gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); - - context->zoomout = - map_add_button(11, G_CALLBACK(cb_map_zoomout), - context, _("Zoom out")); - gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); - - context->gps = - map_add_button(9, G_CALLBACK(cb_map_gps), - context, _("Jump to GPS position")); - gtk_widget_set_sensitive(context->gps, FALSE); + /* TODO: gtk_widget_set_sensitive(context->gps, FALSE); */ /* install handler for timed updates of the gps button */ context->handler_id = gtk_timeout_add(1000, map_gps_update, context); - gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0); - - gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); #if MAEMO_VERSION_MAJOR == 5 /* prevent some of the main screen things */ @@ -518,6 +530,6 @@ g_signal_connect(G_OBJECT(context->window), "destroy", G_CALLBACK(on_window_destroy), context); - gtk_container_add(GTK_CONTAINER(context->window), hbox); + gtk_container_add(GTK_CONTAINER(context->window), context->widget); gtk_widget_show_all(GTK_WIDGET(context->window)); }