Diff of /trunk/src/osm-gps-map.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 58 by harbaum, Mon Aug 17 10:51:56 2009 UTC revision 231 by harbaum, Mon Dec 7 16:14:50 2009 UTC
# Line 49  Line 49 
49    
50  #define EXTRA_BORDER (TILESIZE / 2)  #define EXTRA_BORDER (TILESIZE / 2)
51    
52    #define OSM_GPS_MAP_SCROLL_STEP 10
53    
54    /* any defined key enables key support */
55    #if (defined(OSM_GPS_MAP_KEY_FULLSCREEN) || \
56         defined(OSM_GPS_MAP_KEY_ZOOMIN) || \
57         defined(OSM_GPS_MAP_KEY_ZOOMOUT) || \
58         defined(OSM_GPS_MAP_KEY_UP) || \
59         defined(OSM_GPS_MAP_KEY_DOWN) || \
60         defined(OSM_GPS_MAP_KEY_LEFT) || \
61         defined(OSM_GPS_MAP_KEY_RIGHT))
62    #define OSM_GPS_MAP_KEYS
63    #endif
64    
65    #ifdef OSM_GPS_MAP_KEYS
66    #include <gdk/gdkkeysyms.h>
67    #endif
68    
69    #define USER_AGENT "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
70    
71  struct _OsmGpsMapPrivate  struct _OsmGpsMapPrivate
72  {  {
73      GHashTable *tile_queue;      GHashTable *tile_queue;
# Line 78  struct _OsmGpsMapPrivate Line 97  struct _OsmGpsMapPrivate
97      char *proxy_uri;      char *proxy_uri;
98    
99      //where downloaded tiles are cached      //where downloaded tiles are cached
100        char *tile_dir;
101      char *cache_dir;      char *cache_dir;
     gboolean cache_dir_is_full_path;  
102    
103      //contains flags indicating the various special characters      //contains flags indicating the various special characters
104      //the uri string contains, that will be replaced when calculating      //the uri string contains, that will be replaced when calculating
# Line 96  struct _OsmGpsMapPrivate Line 115  struct _OsmGpsMapPrivate
115      gboolean show_trip_history;      gboolean show_trip_history;
116      GSList *trip_history;      GSList *trip_history;
117      coord_t *gps;      coord_t *gps;
118        float gps_heading;
119      gboolean gps_valid;      gboolean gps_valid;
120    
121      //a balloon with additional info  #ifdef ENABLE_OSD
122      struct {      //the osd controls (if present)
123          coord_t *coo;      osm_gps_map_osd_t *osd;
124          gboolean valid;  #ifdef OSD_DOUBLE_BUFFER
125          OsmGpsMapRect_t rect;      GdkPixmap *dbuf_pixmap;
126          OsmGpsMapBalloonCallback cb;  #endif
127          gpointer data;  #endif
     } balloon;  
128    
129    #ifdef OSM_GPS_MAP_KEY_FULLSCREEN
130        gboolean fullscreen;
131    #endif
132    
133      //additional images or tracks added to the map      //additional images or tracks added to the map
134      GSList *tracks;      GSList *tracks;
135      GSList *images;      GSList *images;
# Line 126  struct _OsmGpsMapPrivate Line 149  struct _OsmGpsMapPrivate
149      int drag_start_mouse_y;      int drag_start_mouse_y;
150      int drag_start_map_x;      int drag_start_map_x;
151      int drag_start_map_y;      int drag_start_map_y;
152        guint drag_expose;
153    
154      //for customizing the redering of the gps track      //for customizing the redering of the gps track
155      int ui_gps_track_width;      int ui_gps_track_width;
# Line 158  enum Line 182  enum
182      PROP_REPO_URI,      PROP_REPO_URI,
183      PROP_PROXY_URI,      PROP_PROXY_URI,
184      PROP_TILE_CACHE_DIR,      PROP_TILE_CACHE_DIR,
     PROP_TILE_CACHE_DIR_IS_FULL_PATH,  
185      PROP_ZOOM,      PROP_ZOOM,
186      PROP_MAX_ZOOM,      PROP_MAX_ZOOM,
187      PROP_MIN_ZOOM,      PROP_MIN_ZOOM,
# Line 319  static void Line 342  static void
342  inspect_map_uri(OsmGpsMap *map)  inspect_map_uri(OsmGpsMap *map)
343  {  {
344      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
345        priv->uri_format = 0;
346        priv->the_google = FALSE;
347    
348      if (g_strrstr(priv->repo_uri, URI_MARKER_X))      if (g_strrstr(priv->repo_uri, URI_MARKER_X))
349          priv->uri_format |= URI_HAS_X;          priv->uri_format |= URI_HAS_X;
# Line 555  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 580  osm_gps_map_draw_gps_point (OsmGpsMap *m
580          int x, y;          int x, y;
581          int r = priv->ui_gps_point_inner_radius;          int r = priv->ui_gps_point_inner_radius;
582          int r2 = priv->ui_gps_point_outer_radius;          int r2 = priv->ui_gps_point_outer_radius;
583          // int lw = priv->ui_gps_track_width;          int mr = MAX(3*r,r2);
         int mr = MAX(r,r2);  
584    
585          map_x0 = priv->map_x - EXTRA_BORDER;          map_x0 = priv->map_x - EXTRA_BORDER;
586          map_y0 = priv->map_y - EXTRA_BORDER;          map_y0 = priv->map_y - EXTRA_BORDER;
# Line 587  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 611  osm_gps_map_draw_gps_point (OsmGpsMap *m
611    
612          // draw ball gradient          // draw ball gradient
613          if (r > 0) {          if (r > 0) {
614                // draw direction arrow
615                if(!isnan(priv->gps_heading))
616                {
617                    cairo_move_to (cr, x-r*cos(priv->gps_heading), y-r*sin(priv->gps_heading));
618                    cairo_line_to (cr, x+3*r*sin(priv->gps_heading), y-3*r*cos(priv->gps_heading));
619                    cairo_line_to (cr, x+r*cos(priv->gps_heading), y+r*sin(priv->gps_heading));
620                    cairo_close_path (cr);
621    
622                    cairo_set_source_rgba (cr, 0.3, 0.3, 1.0, 0.5);
623                    cairo_fill_preserve (cr);
624    
625                    cairo_set_line_width (cr, 1.0);
626                    cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
627                    cairo_stroke(cr);
628                }
629    
630              pat = cairo_pattern_create_radial (x-(r/5), y-(r/5), (r/5), x,  y, r);              pat = cairo_pattern_create_radial (x-(r/5), y-(r/5), (r/5), x,  y, r);
631              cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1.0);              cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1.0);
632              cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 1, 1.0);              cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 1, 1.0);
# Line 600  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 640  osm_gps_map_draw_gps_point (OsmGpsMap *m
640              cairo_arc (cr, x, y, r, 0, 2 * M_PI);              cairo_arc (cr, x, y, r, 0, 2 * M_PI);
641              cairo_stroke(cr);              cairo_stroke(cr);
642          }          }
643    
644          cairo_destroy(cr);          cairo_destroy(cr);
645          gtk_widget_queue_draw_area (GTK_WIDGET(map),          gtk_widget_queue_draw_area (GTK_WIDGET(map),
646                                      x-mr,                                      x-mr,
# Line 642  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 682  osm_gps_map_draw_gps_point (OsmGpsMap *m
682      }      }
683  }  }
684    
 /* most visual effects are hardcoded by now, but may be made */  
 /* available via properties later */  
 #define BALLOON_AREA_WIDTH           250  
 #define BALLOON_AREA_HEIGHT           75  
   
 #define BALLOON_CORNER_RADIUS         20  
 #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/4)  
 #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)  
 #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)  
 #define BALLOON_TRANSPARENCY         0.8  
 #define POINTER_HEIGHT                20  
 #define POINTER_FOOT_WIDTH            20  
 #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)  
 #define BALLOON_SHADOW                5  
 #define BALLOON_SHADOW_TRANSPARENCY  0.2  
   
 #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS/3)  
   
   
 /* draw the bubble shape. this is used twice, once for the shape and once */  
 /* for the shadow */  
 static void  
 osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,  
        gboolean bottom, int px, int py, int px0, int px1) {  
   
     cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);  
     cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);  
     if(!bottom) {  
         /* insert top pointer */  
         cairo_line_to (cr, px1, y0);  
         cairo_line_to (cr, px, py);  
         cairo_line_to (cr, px0, y0);  
     }  
   
     cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);  
     cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS);  
     cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);  
     cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);  
     if(bottom) {  
         /* insert bottom pointer */  
         cairo_line_to (cr, px0, y1);  
         cairo_line_to (cr, px, py);  
         cairo_line_to (cr, px1, y1);  
     }  
   
     cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);  
     cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS);  
   
     cairo_close_path (cr);  
 }  
   
 /* http://cairographics.org/samples/ */  
 static void  
 osm_gps_map_draw_balloon_int (OsmGpsMap *map)  
 {  
     OsmGpsMapPrivate *priv = map->priv;  
   
     if (priv->balloon.valid) {  
   
         /* ------- convert given coordinate into screen position --------- */  
         int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -  
             priv->map_x + EXTRA_BORDER;  
         int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -  
             priv->map_y + EXTRA_BORDER;  
   
         /* check position of this relative to screen center to determine */  
         /* pointer direction ... */  
         int pointer_x = x0, pointer_x0, pointer_x1;  
         int pointer_y = y0;  
   
         /* ... and calculate position */  
         if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) {  
             x0 -= BALLOON_WIDTH - POINTER_OFFSET;  
             pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);  
             pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;  
         } else {  
             x0 -= POINTER_OFFSET;  
             pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);  
             pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;  
         }  
   
         gboolean bottom = FALSE;  
         if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) {  
             bottom = TRUE;  
             y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;  
         } else  
             y0 += POINTER_HEIGHT;  
   
         /* calculate bottom/right of box */  
         int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;  
   
         /* save balloon screen coordinates for later use */  
         priv->balloon.rect.x = x0 + BALLOON_BORDER;  
         priv->balloon.rect.y = y0 + BALLOON_BORDER;  
         priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;  
         priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;  
   
 #ifdef USE_CAIRO  
         cairo_t *cr = gdk_cairo_create(priv->pixmap);  
   
         /* --------- draw shadow --------------- */  
         osm_gps_map_draw_balloon_shape (cr,  
                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,  
                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,  
                     bottom, pointer_x, pointer_y,  
                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);  
   
         cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);  
         cairo_fill_preserve (cr);  
         cairo_set_source_rgba (cr, 1, 0, 0, 1.0);  
         cairo_set_line_width (cr, 0);  
         cairo_stroke (cr);  
   
         /* --------- draw main shape ----------- */  
         osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,  
                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);  
   
         cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);  
         cairo_fill_preserve (cr);  
         cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);  
         cairo_set_line_width (cr, 1);  
         cairo_stroke (cr);  
   
   
         /* ---------- draw close button --------- */  
   
         int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;  
         int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;  
         int crad = CLOSE_BUTTON_RADIUS;  
   
         cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);  
         cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);  
         cairo_fill_preserve (cr);  
         cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);  
         cairo_set_line_width (cr, 2);  
         cairo_stroke(cr);  
   
         cairo_set_source_rgba (cr, 1, 1, 1, 1.0);  
         cairo_set_line_width (cr, 3);  
         cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);  
         cairo_move_to (cr, cx - crad/2, cy - crad/2);  
         cairo_line_to (cr, cx + crad/2, cy + crad/2);  
         cairo_stroke (cr);  
         cairo_move_to (cr, cx + crad/2, cy - crad/2);  
         cairo_line_to (cr, cx - crad/2, cy + crad/2);  
         cairo_stroke (cr);  
   
         if (priv->balloon.cb) {  
             /* clip in case application tries to draw in */  
             /* exceed of the balloon */  
             cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,  
                              priv->balloon.rect.w, priv->balloon.rect.h);  
             cairo_clip (cr);  
             cairo_new_path (cr);  /* current path is not  
                                      consumed by cairo_clip() */  
   
             priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);  
         }  
   
         gtk_widget_queue_draw_area (GTK_WIDGET(map),  
                                     x0, y0, BALLOON_WIDTH,  
                                     BALLOON_HEIGHT + POINTER_HEIGHT);  
 #else  
 #warning "Balloon display lacks a non-cairo implementation!"  
 #endif  
     }  
 }  
   
 /* the user clicked into the balloons main area. handle this */  
 static void  
 osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)  
 {  
     OsmGpsMapPrivate *priv = map->priv;  
   
     printf("clocked at %d %d\n", x, y);  
   
     if (!priv->balloon.valid)  
         return;  
   
     /* check if the close button was clicked */  
     if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&  
         (x < priv->balloon.rect.w) &&  
         (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {  
   
         priv->balloon.valid = FALSE;  
         osm_gps_map_map_redraw_idle(map);  
     }  
 }  
   
 /* return true if balloon is being displayed and if */  
 /* the given coordinate is within this balloon */  
 static gboolean  
 osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)  
 {  
     return (priv->balloon.valid &&  
             (x > priv->balloon.rect.x) &&  
             (x < priv->balloon.rect.x + priv->balloon.rect.w) &&  
             (y > priv->balloon.rect.y) &&  
             (y < priv->balloon.rect.y + priv->balloon.rect.h));  
 }  
   
685  static void  static void
686  osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y)  osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y)
687  {  {
# Line 905  osm_gps_map_tile_download_complete (Soup Line 744  osm_gps_map_tile_download_complete (Soup
744              }              }
745              else              else
746              {              {
747                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
748                              dl->folder);
749                    perror("perror:");
750              }              }
751          }          }
752    
# Line 1052  osm_gps_map_download_tile (OsmGpsMap *ma Line 893  osm_gps_map_download_tile (OsmGpsMap *ma
893                  }                  }
894              }              }
895    
896    #ifdef LIBSOUP22
897                soup_message_headers_append(msg->request_headers,
898                                            "User-Agent", USER_AGENT);
899    #endif
900    
901              g_hash_table_insert (priv->tile_queue, dl->uri, msg);              g_hash_table_insert (priv->tile_queue, dl->uri, msg);
902              soup_session_queue_message (priv->soup_session, msg, osm_gps_map_tile_download_complete, dl);              soup_session_queue_message (priv->soup_session, msg, osm_gps_map_tile_download_complete, dl);
903          } else {          } else {
# Line 1402  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1248  osm_gps_map_map_redraw (OsmGpsMap *map)
1248  {  {
1249      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1250    
1251        /* on diablo the map comes up at 1x1 pixel size and */
1252        /* isn't really usable. we'll just ignore this ... */
1253        if((GTK_WIDGET(map)->allocation.width < 2) ||
1254           (GTK_WIDGET(map)->allocation.height < 2)) {
1255            printf("not a useful sized map yet ...\n");
1256            return FALSE;
1257        }
1258    
1259      priv->idle_map_redraw = 0;      priv->idle_map_redraw = 0;
1260    
1261    #ifdef ENABLE_OSD
1262        /* don't redraw the entire map while the OSD is doing */
1263        /* some animation or the like. This is to keep the animation */
1264        /* fluid */
1265        if (priv->osd->busy(priv->osd))
1266            return FALSE;
1267    #endif
1268    
1269    #ifdef DRAG_DEBUG
1270        printf("trying redraw\n");
1271    #endif
1272    
1273      /* the motion_notify handler uses priv->pixmap to redraw the area; if we      /* the motion_notify handler uses priv->pixmap to redraw the area; if we
1274       * change it while we are dragging, we will end up showing it in the wrong       * change it while we are dragging, we will end up showing it in the wrong
1275       * place. This could be fixed by carefully recompute the coordinates, but       * place. This could be fixed by carefully recompute the coordinates, but
# Line 1411  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1277  osm_gps_map_map_redraw (OsmGpsMap *map)
1277      if (priv->dragging)      if (priv->dragging)
1278          return FALSE;          return FALSE;
1279    
1280        /* undo all offsets that may have happened when dragging */
1281        priv->drag_mouse_dx = 0;
1282        priv->drag_mouse_dy = 0;
1283    
1284      priv->redraw_cycle++;      priv->redraw_cycle++;
1285    
1286      /* draw white background to initialise pixmap */      /* draw white background to initialise pixmap */
# Line 1427  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1297  osm_gps_map_map_redraw (OsmGpsMap *map)
1297      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1298      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1299      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
     osm_gps_map_draw_balloon_int(map);  
1300    
1301      //osm_gps_map_osd_speed(map, 1.5);  #ifdef ENABLE_OSD
1302        /* OSD may contain a coordinate/scale, so we may have to re-render it */
1303        if(priv->osd && OSM_IS_GPS_MAP (priv->osd->widget))
1304            priv->osd->render (priv->osd);
1305    #endif
1306    
1307      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
1308      gtk_widget_queue_draw (GTK_WIDGET (map));      gtk_widget_queue_draw (GTK_WIDGET (map));
1309    
# Line 1445  osm_gps_map_map_redraw_idle (OsmGpsMap * Line 1319  osm_gps_map_map_redraw_idle (OsmGpsMap *
1319          priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map);          priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map);
1320  }  }
1321    
1322    #ifdef OSM_GPS_MAP_KEYS
1323    static gboolean
1324    on_window_key_press(GtkWidget *widget,
1325                             GdkEventKey *event, OsmGpsMapPrivate *priv) {
1326      gboolean handled = FALSE;
1327      int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP;
1328    
1329      // the map handles some keys on its own ...
1330      switch(event->keyval) {
1331    #ifdef OSM_GPS_MAP_KEY_FULLSCREEN
1332      case OSM_GPS_MAP_KEY_FULLSCREEN: {
1333          GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget));
1334          if(!priv->fullscreen)
1335              gtk_window_fullscreen(GTK_WINDOW(toplevel));
1336          else
1337              gtk_window_unfullscreen(GTK_WINDOW(toplevel));
1338    
1339          priv->fullscreen = !priv->fullscreen;
1340          handled = TRUE;
1341          } break;
1342    #endif
1343    
1344    #ifdef OSM_GPS_MAP_KEY_ZOOMIN
1345      case OSM_GPS_MAP_KEY_ZOOMIN:
1346          osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
1347          handled = TRUE;
1348          break;
1349    #endif
1350    
1351    #ifdef OSM_GPS_MAP_KEY_ZOOMOUT
1352      case OSM_GPS_MAP_KEY_ZOOMOUT:
1353          osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
1354          handled = TRUE;
1355          break;
1356    #endif
1357    
1358    #ifdef OSM_GPS_MAP_KEY_UP
1359      case OSM_GPS_MAP_KEY_UP:
1360          priv->map_y -= step;
1361          priv->center_coord_set = FALSE;
1362          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1363          handled = TRUE;
1364          break;
1365    #endif
1366    
1367    #ifdef OSM_GPS_MAP_KEY_DOWN
1368      case OSM_GPS_MAP_KEY_DOWN:
1369          priv->map_y += step;
1370          priv->center_coord_set = FALSE;
1371          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1372          handled = TRUE;
1373          break;
1374    #endif
1375    
1376    #ifdef OSM_GPS_MAP_KEY_LEFT
1377      case OSM_GPS_MAP_KEY_LEFT:
1378          priv->map_x -= step;
1379          priv->center_coord_set = FALSE;
1380          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1381          handled = TRUE;
1382          break;
1383    #endif
1384    
1385    #ifdef OSM_GPS_MAP_KEY_RIGHT
1386      case OSM_GPS_MAP_KEY_RIGHT:
1387          priv->map_x += step;
1388          priv->center_coord_set = FALSE;
1389          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1390          handled = TRUE;
1391          break;
1392    #endif
1393    
1394      default:
1395          break;
1396      }
1397    
1398      return handled;
1399    }
1400    #endif
1401    
1402  static void  static void
1403  osm_gps_map_init (OsmGpsMap *object)  osm_gps_map_init (OsmGpsMap *object)
1404  {  {
# Line 1458  osm_gps_map_init (OsmGpsMap *object) Line 1412  osm_gps_map_init (OsmGpsMap *object)
1412      priv->trip_history = NULL;      priv->trip_history = NULL;
1413      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1414      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1415        priv->gps_heading = OSM_GPS_MAP_INVALID;
1416    
1417    #ifdef ENABLE_OSD
1418        priv->osd = NULL;
1419    #endif
1420    
1421      priv->balloon.coo = g_new0(coord_t, 1);  #ifdef OSM_GPS_MAP_BUTTON_FULLSCREEN
1422      priv->balloon.valid = FALSE;      priv->fullscreen = FALSE;
1423      priv->balloon.cb = NULL;  #endif
1424    
1425      priv->tracks = NULL;      priv->tracks = NULL;
1426      priv->images = NULL;      priv->images = NULL;
# Line 1479  osm_gps_map_init (OsmGpsMap *object) Line 1438  osm_gps_map_init (OsmGpsMap *object)
1438    
1439  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1440      //Change naumber of concurrent connections option?      //Change naumber of concurrent connections option?
1441      priv->soup_session = soup_session_async_new_with_options(      priv->soup_session =
1442                                                               SOUP_SESSION_USER_AGENT,          soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT,
1443                                                               "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11",                                              USER_AGENT, NULL);
                                                              NULL);  
1444  #else  #else
1445      /* libsoup-2.2 seems not to be able to set the user agent */      /* libsoup-2.2 has no special way to set the user agent, so we */
1446        /* set it seperately as an extra header field for each reuest */
1447      priv->soup_session = soup_session_async_new();      priv->soup_session = soup_session_async_new();
1448  #endif  #endif
1449    
# Line 1507  osm_gps_map_init (OsmGpsMap *object) Line 1466  osm_gps_map_init (OsmGpsMap *object)
1466      GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS);      GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS);
1467    
1468      g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL);      g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL);
 }  
1469    
1470  #ifndef G_CHECKSUM_MD5  #ifdef OSM_GPS_MAP_KEYS
1471  /* simple hash algorithm hack if md5 is not present */      g_signal_connect(G_OBJECT(object), "key_press_event",
1472  static char *simple_hash(char *str) {                       G_CALLBACK(on_window_key_press), priv);
     union {  
         char str[4];  
         gulong val;  
     } hash = { .val = 0x55555555 };  
   
     while(*str) {  
         hash.str[(int)str & 3] ^= *str;  
         str++;  
     }  
     return g_strdup_printf("%08lX", hash.val);  
 }  
1473  #endif  #endif
1474    }
1475    
1476  static GObject *  static void
1477  osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties)  osm_gps_map_setup(OsmGpsMapPrivate *priv) {
 {  
     GObject *object;  
     OsmGpsMapPrivate *priv;  
     OsmGpsMap *map;  
1478      const char *uri;      const char *uri;
1479    
     //Always chain up to the parent constructor  
     object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);  
     map = OSM_GPS_MAP(object);  
     priv = OSM_GPS_MAP_PRIVATE(object);  
   
1480      //user can specify a map source ID, or a repo URI as the map source      //user can specify a map source ID, or a repo URI as the map source
1481      uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);      uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);
1482      if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {      if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {
# Line 1562  osm_gps_map_constructor (GType gtype, gu Line 1501  osm_gps_map_constructor (GType gtype, gu
1501          }          }
1502      }      }
1503    
1504      if (!priv->cache_dir_is_full_path) {      const char *fname = osm_gps_map_source_get_friendly_name(priv->map_source);
1505  #ifdef G_CHECKSUM_MD5      if(!fname) fname = "_unknown_";
         char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1);  
 #else  
         char *md5 = simple_hash(priv->repo_uri);  
 #endif  
1506    
1507          if (priv->cache_dir) {      if (priv->tile_dir) {
1508              char *old = priv->cache_dir;          //the new cachedir is the given cache dir + the friendly name of the repo_uri
1509              //the new cachedir is the given cache dir + the md5 of the repo_uri          priv->cache_dir = g_strdup_printf("%s%c%s", priv->tile_dir, G_DIR_SEPARATOR, fname);
1510              priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5);          g_debug("Adjusting cache dir %s -> %s", priv->tile_dir, priv->cache_dir);
             g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);  
             g_free(old);  
         } else {  
             //the new cachedir is the current dir + the md5 of the repo_uri  
             priv->cache_dir = g_strdup(md5);  
         }  
   
         g_free(md5);  
1511      }      }
1512    }
1513    
1514    static GObject *
1515    osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties)
1516    {
1517        //Always chain up to the parent constructor
1518        GObject *object =
1519            G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);
1520    
1521        osm_gps_map_setup(OSM_GPS_MAP_PRIVATE(object));
1522    
1523      inspect_map_uri(map);      inspect_map_uri(OSM_GPS_MAP(object));
1524    
1525      return object;      return object;
1526  }  }
# Line 1620  osm_gps_map_dispose (GObject *object) Line 1557  osm_gps_map_dispose (GObject *object)
1557      if (priv->idle_map_redraw != 0)      if (priv->idle_map_redraw != 0)
1558          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1559    
1560        if (priv->drag_expose != 0)
1561            g_source_remove (priv->drag_expose);
1562    
1563      g_free(priv->gps);      g_free(priv->gps);
1564      g_free(priv->balloon.coo);  
1565    #ifdef ENABLE_OSD
1566        if(priv->osd)
1567            priv->osd->free(priv->osd);
1568    
1569    #ifdef OSD_DOUBLE_BUFFER
1570        if(priv->dbuf_pixmap)
1571            g_object_unref (priv->dbuf_pixmap);
1572    #endif
1573    #endif
1574    
1575      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
1576  }  }
# Line 1632  osm_gps_map_finalize (GObject *object) Line 1581  osm_gps_map_finalize (GObject *object)
1581      OsmGpsMap *map = OSM_GPS_MAP(object);      OsmGpsMap *map = OSM_GPS_MAP(object);
1582      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1583    
1584      g_free(priv->cache_dir);      if(priv->tile_dir)
1585            g_free(priv->tile_dir);
1586    
1587        if(priv->cache_dir)
1588            g_free(priv->cache_dir);
1589    
1590      g_free(priv->repo_uri);      g_free(priv->repo_uri);
1591      g_free(priv->image_format);      g_free(priv->image_format);
1592    
# Line 1689  osm_gps_map_set_property (GObject *objec Line 1643  osm_gps_map_set_property (GObject *objec
1643              break;              break;
1644          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1645              if ( g_value_get_string(value) )              if ( g_value_get_string(value) )
1646                  priv->cache_dir = g_value_dup_string (value);                  priv->tile_dir = g_value_dup_string (value);
             break;  
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             priv->cache_dir_is_full_path = g_value_get_boolean (value);  
1647              break;              break;
1648          case PROP_ZOOM:          case PROP_ZOOM:
1649              priv->map_zoom = g_value_get_int (value);              priv->map_zoom = g_value_get_int (value);
# Line 1720  osm_gps_map_set_property (GObject *objec Line 1671  osm_gps_map_set_property (GObject *objec
1671          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1672              priv->ui_gps_point_outer_radius = g_value_get_int (value);              priv->ui_gps_point_outer_radius = g_value_get_int (value);
1673              break;              break;
1674          case PROP_MAP_SOURCE:          case PROP_MAP_SOURCE: {
1675                gint old = priv->map_source;
1676              priv->map_source = g_value_get_int (value);              priv->map_source = g_value_get_int (value);
1677              break;              if(old >= OSM_GPS_MAP_SOURCE_NULL &&
1678                   priv->map_source != old &&
1679                   priv->map_source >= OSM_GPS_MAP_SOURCE_NULL &&
1680                   priv->map_source <= OSM_GPS_MAP_SOURCE_LAST) {
1681    
1682                    /* we now have to switch the entire map */
1683    
1684                    /* flush the ram cache */
1685                    g_hash_table_remove_all(priv->tile_cache);
1686    
1687                    osm_gps_map_setup(priv);
1688    
1689                    inspect_map_uri(map);
1690    
1691                    /* adjust zoom if necessary */
1692                    if(priv->map_zoom > priv->max_zoom)
1693                        osm_gps_map_set_zoom(map, priv->max_zoom);
1694    
1695                    if(priv->map_zoom < priv->min_zoom)
1696                        osm_gps_map_set_zoom(map, priv->min_zoom);
1697    
1698                } } break;
1699          case PROP_IMAGE_FORMAT:          case PROP_IMAGE_FORMAT:
1700              priv->image_format = g_value_dup_string (value);              priv->image_format = g_value_dup_string (value);
1701              break;              break;
# Line 1763  osm_gps_map_get_property (GObject *objec Line 1736  osm_gps_map_get_property (GObject *objec
1736          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1737              g_value_set_string(value, priv->cache_dir);              g_value_set_string(value, priv->cache_dir);
1738              break;              break;
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             g_value_set_boolean(value, priv->cache_dir_is_full_path);  
             break;  
1739          case PROP_ZOOM:          case PROP_ZOOM:
1740              g_value_set_int(value, priv->map_zoom);              g_value_set_int(value, priv->map_zoom);
1741              break;              break;
# Line 1838  osm_gps_map_button_press (GtkWidget *wid Line 1808  osm_gps_map_button_press (GtkWidget *wid
1808  {  {
1809      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
1810    
1811      /* don't drag if the user clicked within the balloon */  #ifdef ENABLE_OSD
1812      if (osm_gps_map_in_balloon(priv,      /* pressed inside OSD control? */
1813                     event->x + EXTRA_BORDER,      if(priv->osd) {
1814                     event->y + EXTRA_BORDER))          osd_button_t but =
1815      {              priv->osd->check(priv->osd, TRUE, event->x, event->y);
1816          priv->drag_counter = -1;  
1817          return FALSE;          if(but != OSD_NONE)
1818            {
1819                int step =
1820                    GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP;
1821                priv->drag_counter = -1;
1822    
1823                switch(but) {
1824                case OSD_UP:
1825                    priv->map_y -= step;
1826                    priv->center_coord_set = FALSE;
1827                    g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL);
1828                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1829                    break;
1830    
1831                case OSD_DOWN:
1832                    priv->map_y += step;
1833                    priv->center_coord_set = FALSE;
1834                    g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL);
1835                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1836                    break;
1837    
1838                case OSD_LEFT:
1839                    priv->map_x -= step;
1840                    priv->center_coord_set = FALSE;
1841                    g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL);
1842                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1843                    break;
1844    
1845                case OSD_RIGHT:
1846                    priv->map_x += step;
1847                    priv->center_coord_set = FALSE;
1848                    g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL);
1849                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1850                    break;
1851    
1852                case OSD_IN:
1853                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
1854                    break;
1855    
1856                case OSD_OUT:
1857                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
1858                    break;
1859    
1860                default:
1861                    /* all custom buttons are forwarded to the application */
1862                    if(priv->osd->cb)
1863                        priv->osd->cb(but, priv->osd->data);
1864                    break;
1865                }
1866    
1867                return FALSE;
1868            }
1869      }      }
1870    #endif
1871    
1872      priv->drag_counter = 0;      priv->drag_counter = 0;
1873      priv->drag_start_mouse_x = (int) event->x;      priv->drag_start_mouse_x = (int) event->x;
# Line 1861  osm_gps_map_button_release (GtkWidget *w Line 1883  osm_gps_map_button_release (GtkWidget *w
1883  {  {
1884      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
1885    
     /* released inside the balloon? */  
     if (osm_gps_map_in_balloon(priv,  
                    event->x + EXTRA_BORDER,  
                    event->y + EXTRA_BORDER))  
     {  
         osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),  
              event->x - priv->balloon.rect.x + EXTRA_BORDER,  
              event->y - priv->balloon.rect.y + EXTRA_BORDER);  
         return FALSE;  
     }  
   
     if (priv->drag_counter < 0)  
         return FALSE;  
   
1886      if (priv->dragging)      if (priv->dragging)
1887      {      {
1888          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1889  osm_gps_map_button_release (GtkWidget *w Line 1897  osm_gps_map_button_release (GtkWidget *w
1897    
1898          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1899      }      }
1900    #ifdef ENABLE_OSD
1901        /* pressed inside OSD control? */
1902        else if(priv->osd)
1903            priv->osd->check(priv->osd, FALSE, event->x, event->y);
1904    #endif
1905    
1906    #ifdef DRAG_DEBUG
1907        printf("dragging done\n");
1908    #endif
1909    
     priv->drag_mouse_dx = 0;  
     priv->drag_mouse_dy = 0;  
1910      priv->drag_counter = -1;      priv->drag_counter = -1;
1911    
1912      return FALSE;      return FALSE;
1913  }  }
1914    
1915  static gboolean  static gboolean
1916    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);
1917    
1918    static gboolean
1919    osm_gps_map_map_expose (GtkWidget *widget)
1920    {
1921        OsmGpsMapPrivate *priv = OSM_GPS_MAP(widget)->priv;
1922    
1923        priv->drag_expose = 0;
1924        osm_gps_map_expose (widget, NULL);
1925        return FALSE;
1926    }
1927    
1928    static gboolean
1929  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)
1930  {  {
1931      int x, y;      int x, y;
# Line 1920  osm_gps_map_motion_notify (GtkWidget *wi Line 1948  osm_gps_map_motion_notify (GtkWidget *wi
1948      if (priv->drag_counter < 0)      if (priv->drag_counter < 0)
1949          return FALSE;          return FALSE;
1950    
1951      priv->drag_counter++;      /* not yet dragged far enough? */
1952        if(!priv->drag_counter &&
1953      // we havent dragged more than 6 pixels         ( (x - priv->drag_start_mouse_x) * (x - priv->drag_start_mouse_x) +
1954      if (priv->drag_counter < 6)           (y - priv->drag_start_mouse_y) * (y - priv->drag_start_mouse_y) <
1955             10*10))
1956          return FALSE;          return FALSE;
1957    
1958        priv->drag_counter++;
1959    
1960      priv->dragging = TRUE;      priv->dragging = TRUE;
1961    
1962      if (priv->map_auto_center)      if (priv->map_auto_center)
# Line 1934  osm_gps_map_motion_notify (GtkWidget *wi Line 1965  osm_gps_map_motion_notify (GtkWidget *wi
1965      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
1966      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
1967    
1968      gdk_draw_drawable (      /* instead of redrawing directly just add an idle function */
1969                         widget->window,      if (!priv->drag_expose)
1970                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],          priv->drag_expose =
1971                         priv->pixmap,              g_idle_add ((GSourceFunc)osm_gps_map_map_expose, widget);
                        0,0,  
                        priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER,  
                        -1,-1);  
   
     //Paint white outside of the map if dragging. Its less  
     //ugly than painting the corrupted map  
     if(priv->drag_mouse_dx>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
     else if (-priv->drag_mouse_dx > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,  
                             -priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
   
     if (priv->drag_mouse_dy>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             widget->allocation.width,  
                             priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
     else if (-priv->drag_mouse_dy > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,  
                             widget->allocation.width,  
                             -priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
1972    
1973      return FALSE;      return FALSE;
1974  }  }
# Line 1997  osm_gps_map_configure (GtkWidget *widget Line 1983  osm_gps_map_configure (GtkWidget *widget
1983          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
1984    
1985      priv->pixmap = gdk_pixmap_new (      priv->pixmap = gdk_pixmap_new (
1986                                     widget->window,                          widget->window,
1987                                     widget->allocation.width + EXTRA_BORDER * 2,                          widget->allocation.width + EXTRA_BORDER * 2,
1988                                     widget->allocation.height + EXTRA_BORDER * 2,                          widget->allocation.height + EXTRA_BORDER * 2,
1989                                     -1);                          -1);
1990    
1991    #ifdef ENABLE_OSD
1992    
1993    #ifdef OSD_DOUBLE_BUFFER
1994        if (priv->dbuf_pixmap)
1995            g_object_unref (priv->dbuf_pixmap);
1996    
1997        priv->dbuf_pixmap = gdk_pixmap_new (
1998                            widget->window,
1999                            widget->allocation.width,
2000                            widget->allocation.height,
2001                            -1);
2002    #endif
2003    
2004        /* the osd needs some references to map internal objects */
2005        if(priv->osd)
2006            priv->osd->widget = widget;
2007    #endif
2008    
2009      /* and gc, used for clipping (I think......) */      /* and gc, used for clipping (I think......) */
2010      if(priv->gc_map)      if(priv->gc_map)
# Line 2018  osm_gps_map_expose (GtkWidget *widget, G Line 2022  osm_gps_map_expose (GtkWidget *widget, G
2022  {  {
2023      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2024    
2025      gdk_draw_drawable (  #if defined(ENABLE_OSD) && defined(OSD_DOUBLE_BUFFER)
2026                         widget->window,      GdkDrawable *drawable = priv->dbuf_pixmap;
2027    #else
2028        GdkDrawable *drawable = widget->window;
2029    #endif
2030    
2031    #ifdef DRAG_DEBUG
2032        printf("expose, map %d/%d\n", priv->map_x, priv->map_y);
2033    #endif
2034    
2035        if (!priv->drag_mouse_dx && !priv->drag_mouse_dy && event)
2036        {
2037    #ifdef DRAG_DEBUG
2038            printf("  dragging = %d, event = %p\n", priv->dragging, event);
2039    #endif
2040    
2041            gdk_draw_drawable (drawable,
2042                               widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2043                               priv->pixmap,
2044                               event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,
2045                               event->area.x, event->area.y,
2046                               event->area.width, event->area.height);
2047        }
2048        else
2049        {
2050    #ifdef DRAG_DEBUG
2051            printf("  drag_mouse %d/%d\n",
2052                   priv->drag_mouse_dx - EXTRA_BORDER,
2053                   priv->drag_mouse_dy - EXTRA_BORDER);
2054    #endif
2055    
2056            gdk_draw_drawable (drawable,
2057                               widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2058                               priv->pixmap,
2059                               0,0,
2060                               priv->drag_mouse_dx - EXTRA_BORDER,
2061                               priv->drag_mouse_dy - EXTRA_BORDER,
2062                               -1,-1);
2063    
2064            //Paint white outside of the map if dragging. Its less
2065            //ugly than painting the corrupted map
2066            if(priv->drag_mouse_dx>EXTRA_BORDER) {
2067                gdk_draw_rectangle (drawable,
2068                                    widget->style->white_gc,
2069                                    TRUE,
2070                                    0, 0,
2071                                    priv->drag_mouse_dx - EXTRA_BORDER,
2072                                    widget->allocation.height);
2073            }
2074            else if (-priv->drag_mouse_dx > EXTRA_BORDER)
2075            {
2076                gdk_draw_rectangle (drawable,
2077                                    widget->style->white_gc,
2078                                    TRUE,
2079                                    priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,
2080                                    -priv->drag_mouse_dx - EXTRA_BORDER,
2081                                    widget->allocation.height);
2082            }
2083    
2084            if (priv->drag_mouse_dy>EXTRA_BORDER) {
2085                gdk_draw_rectangle (drawable,
2086                                    widget->style->white_gc,
2087                                    TRUE,
2088                                    0, 0,
2089                                    widget->allocation.width,
2090                                    priv->drag_mouse_dy - EXTRA_BORDER);
2091            }
2092            else if (-priv->drag_mouse_dy > EXTRA_BORDER)
2093            {
2094                gdk_draw_rectangle (drawable,
2095                                    widget->style->white_gc,
2096                                    TRUE,
2097                                    0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,
2098                                    widget->allocation.width,
2099                                    -priv->drag_mouse_dy - EXTRA_BORDER);
2100            }
2101        }
2102    
2103    #ifdef ENABLE_OSD
2104        /* draw new OSD */
2105        if(priv->osd)
2106            priv->osd->draw (priv->osd, drawable);
2107    
2108    #ifdef OSD_DOUBLE_BUFFER
2109        gdk_draw_drawable (widget->window,
2110                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2111                         priv->pixmap,                         priv->dbuf_pixmap,
2112                         event->area.x + EXTRA_BORDER,                         0,0,0,0,-1,-1);
2113                         event->area.y + EXTRA_BORDER,  #endif
                        event->area.x, event->area.y,  
                        event->area.width, event->area.height);  
2114    
2115    #endif
2116    
2117      return FALSE;      return FALSE;
2118  }  }
2119    
# Line 2108  osm_gps_map_class_init (OsmGpsMapClass * Line 2195  osm_gps_map_class_init (OsmGpsMapClass *
2195                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2196    
2197      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
                                      PROP_TILE_CACHE_DIR_IS_FULL_PATH,  
                                      g_param_spec_boolean ("tile-cache-is-full-path",  
                                                            "tile cache is full path",  
                                                            "if true, the path passed to tile-cache is interpreted as the full cache path",  
                                                            FALSE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
2198                                       PROP_ZOOM,                                       PROP_ZOOM,
2199                                       g_param_spec_int ("zoom",                                       g_param_spec_int ("zoom",
2200                                                         "zoom",                                                         "zoom",
# Line 2212  osm_gps_map_class_init (OsmGpsMapClass * Line 2291  osm_gps_map_class_init (OsmGpsMapClass *
2291                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2292                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2293                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2294                                                         5,                                                         10,
2295                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2296    
2297      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 2233  osm_gps_map_class_init (OsmGpsMapClass * Line 2312  osm_gps_map_class_init (OsmGpsMapClass *
2312                                                         -1,           /* minimum property value */                                                         -1,           /* minimum property value */
2313                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2314                                                         -1,                                                         -1,
2315                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2316    
2317      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
2318                                       PROP_IMAGE_FORMAT,                                       PROP_IMAGE_FORMAT,
# Line 2252  osm_gps_map_source_get_friendly_name(Osm Line 2331  osm_gps_map_source_get_friendly_name(Osm
2331          case OSM_GPS_MAP_SOURCE_NULL:          case OSM_GPS_MAP_SOURCE_NULL:
2332              return "None";              return "None";
2333          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2334              return "OpenStreetMap";              return "OpenStreetMap I";
2335          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2336              return "OpenStreetMap Renderer";              return "OpenStreetMap II";
2337          case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:          case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP:
2338              return "OpenAerialMap";              return "OpenCycleMap";
2339            case OSM_GPS_MAP_SOURCE_OSMC_TRAILS:
2340                return "OSMC Trails";
2341          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2342              return "Maps-For-Free";              return "Maps-For-Free";
2343          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
# Line 2298  osm_gps_map_source_get_repo_uri(OsmGpsMa Line 2379  osm_gps_map_source_get_repo_uri(OsmGpsMa
2379              return OSM_REPO_URI;              return OSM_REPO_URI;
2380          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2381              return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";              return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";
2382          case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:          case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP:
2383              return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg";              return "http://c.andy.sandbox.cloudmade.com/tiles/cycle/#Z/#X/#Y.png";
2384            case OSM_GPS_MAP_SOURCE_OSMC_TRAILS:
2385                return "http://topo.geofabrik.de/trails/#Z/#X/#Y.png";
2386          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2387              return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";              return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";
2388          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
# Line 2337  osm_gps_map_source_get_image_format(OsmG Line 2420  osm_gps_map_source_get_image_format(OsmG
2420          case OSM_GPS_MAP_SOURCE_NULL:          case OSM_GPS_MAP_SOURCE_NULL:
2421          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2422          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2423            case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP:
2424            case OSM_GPS_MAP_SOURCE_OSMC_TRAILS:
2425              return "png";              return "png";
2426          case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2427          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2428            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2429          case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:          case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2430          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2431          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
# Line 2347  osm_gps_map_source_get_image_format(OsmG Line 2433  osm_gps_map_source_get_image_format(OsmG
2433          case OSM_GPS_MAP_SOURCE_YAHOO_STREET:          case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2434          case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:          case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2435          case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:          case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
         case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:  
2436              return "jpg";              return "jpg";
2437          default:          default:
2438              return "bin";              return "bin";
# Line 2370  osm_gps_map_source_get_max_zoom(OsmGpsMa Line 2454  osm_gps_map_source_get_max_zoom(OsmGpsMa
2454          case OSM_GPS_MAP_SOURCE_NULL:          case OSM_GPS_MAP_SOURCE_NULL:
2455              return 18;              return 18;
2456          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2457            case OSM_GPS_MAP_SOURCE_OPENCYCLEMAP:
2458              return OSM_MAX_ZOOM;              return OSM_MAX_ZOOM;
2459          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:          case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
         case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:  
2460          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:          case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2461          case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:          case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2462          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:          case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
# Line 2382  osm_gps_map_source_get_max_zoom(OsmGpsMa Line 2466  osm_gps_map_source_get_max_zoom(OsmGpsMa
2466          case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:          case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2467          case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:          case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2468              return 17;              return 17;
2469            case OSM_GPS_MAP_SOURCE_OSMC_TRAILS:
2470                return 15;
2471          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:          case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2472              return 11;              return 11;
2473          case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:          case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
# Line 2521  osm_gps_map_set_zoom (OsmGpsMap *map, in Line 2607  osm_gps_map_set_zoom (OsmGpsMap *map, in
2607          g_debug("Zoom changed from %d to %d factor:%f x:%d",          g_debug("Zoom changed from %d to %d factor:%f x:%d",
2608                  zoom_old, priv->map_zoom, factor, priv->map_x);                  zoom_old, priv->map_zoom, factor, priv->map_x);
2609    
2610    #ifdef ENABLE_OSD
2611            /* OSD may contain a scale, so we may have to re-render it */
2612            if(priv->osd && OSM_IS_GPS_MAP (priv->osd->widget))
2613                priv->osd->render (priv->osd);
2614    #endif
2615    
2616          osm_gps_map_map_redraw_idle(map);          osm_gps_map_map_redraw_idle(map);
2617      }      }
2618      return priv->map_zoom;      return priv->map_zoom;
# Line 2606  osm_gps_map_clear_images (OsmGpsMap *map Line 2698  osm_gps_map_clear_images (OsmGpsMap *map
2698  }  }
2699    
2700  void  void
 osm_gps_map_osd_speed (OsmGpsMap *map, float speed)  
 {  
     OsmGpsMapPrivate *priv;  
   
     PangoContext        *context = NULL;  
     PangoLayout     *layout  = NULL;  
     PangoFontDescription    *desc    = NULL;  
   
     GdkColor color;  
     GdkGC *gc;  
   
     gchar *buffer;  
     //static int x = 10, y = 10;  
     static int width = 0, height = 0;  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
   
     buffer = g_strdup_printf("%.0f", speed);  
   
     /* pango initialisation */  
     context = gtk_widget_get_pango_context (GTK_WIDGET(map));  
     layout  = pango_layout_new (context);  
     desc    = pango_font_description_new();  
   
     pango_font_description_set_size (desc, 40 * PANGO_SCALE);  
     pango_layout_set_font_description (layout, desc);  
     pango_layout_set_text (layout, buffer, strlen(buffer));  
   
     gc = gdk_gc_new (GTK_WIDGET(map)->window);  
   
     color.red = (0 > 50) ? 0xffff : 0;  
     color.green = 0;  
     color.blue = 0;  
   
     gdk_gc_set_rgb_fg_color (gc, &color);  
   
     /* faster / less flicker alternative:*/  
     gdk_draw_drawable (  
                        GTK_WIDGET(map)->window,  
                        GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(map)],  
                        priv->pixmap,  
                        0,0,  
                        0,0,  
                        width+10,width+10);  
   
     gdk_draw_layout(GTK_WIDGET(map)->window,  
                     gc,  
                     0, 0,  
                     layout);  
   
     /* set width and height */  
     pango_layout_get_pixel_size(layout, &width, &height);  
   
     g_free(buffer);  
     pango_font_description_free (desc);  
     g_object_unref (layout);  
     g_object_unref (gc);  
 }  
   
 void  
2701  osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading)  osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading)
2702  {  {
2703      int pixel_x, pixel_y;      int pixel_x, pixel_y;
# Line 2678  osm_gps_map_draw_gps (OsmGpsMap *map, fl Line 2709  osm_gps_map_draw_gps (OsmGpsMap *map, fl
2709      priv->gps->rlat = deg2rad(latitude);      priv->gps->rlat = deg2rad(latitude);
2710      priv->gps->rlon = deg2rad(longitude);      priv->gps->rlon = deg2rad(longitude);
2711      priv->gps_valid = TRUE;      priv->gps_valid = TRUE;
2712        priv->gps_heading = deg2rad(heading);
2713    
2714      // pixel_x,y, offsets      // pixel_x,y, offsets
2715      pixel_x = lon2pixel(priv->map_zoom, priv->gps->rlon);      pixel_x = lon2pixel(priv->map_zoom, priv->gps->rlon);
# Line 2767  osm_gps_map_geographic_to_screen (OsmGps Line 2799  osm_gps_map_geographic_to_screen (OsmGps
2799      priv = map->priv;      priv = map->priv;
2800    
2801      if (pixel_x)      if (pixel_x)
2802          *pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) - priv->map_x;          *pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) -
2803                priv->map_x + priv->drag_mouse_dx;
2804      if (pixel_y)      if (pixel_y)
2805          *pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) - priv->map_y;          *pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) -
2806                priv->map_y + priv->drag_mouse_dy;
2807  }  }
2808    
2809  void  void
# Line 2784  osm_gps_map_scroll (OsmGpsMap *map, gint Line 2818  osm_gps_map_scroll (OsmGpsMap *map, gint
2818      priv->map_x += dx;      priv->map_x += dx;
2819      priv->map_y += dy;      priv->map_y += dy;
2820    
2821    #ifdef ENABLE_OSD
2822        /* OSD may contain a coordinate, so we may have to re-render it */
2823        if(priv->osd && OSM_IS_GPS_MAP (priv->osd->widget))
2824            priv->osd->render (priv->osd);
2825    #endif
2826    
2827      osm_gps_map_map_redraw_idle (map);      osm_gps_map_map_redraw_idle (map);
2828  }  }
2829    
# Line 2792  osm_gps_map_get_scale(OsmGpsMap *map) Line 2832  osm_gps_map_get_scale(OsmGpsMap *map)
2832  {  {
2833      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
2834    
2835      g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN);      g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_GPS_MAP_INVALID);
2836      priv = map->priv;      priv = map->priv;
2837    
2838      return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);      return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);
2839  }  }
2840    
2841    #ifdef ENABLE_OSD
2842    
2843    void
2844    osm_gps_map_redraw (OsmGpsMap *map)
2845    {
2846        osm_gps_map_map_redraw_idle(map);
2847    }
2848    
2849    osm_gps_map_osd_t *
2850    osm_gps_map_osd_get(OsmGpsMap *map)
2851    {
2852        g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL);
2853        return map->priv->osd;
2854    }
2855    
2856  void  void
2857  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd)
                           OsmGpsMapBalloonCallback cb, gpointer data)  
2858  {  {
2859      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
2860    
     /* remove and previously installed balloon */  
     osm_gps_map_clear_balloon (map);  
   
2861      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
     priv = map->priv;  
   
     priv->balloon.coo->rlat = deg2rad(latitude);  
     priv->balloon.coo->rlon = deg2rad(longitude);  
     priv->balloon.valid = TRUE;  
2862    
2863      priv->balloon.cb = cb;      priv = map->priv;
2864      priv->balloon.data = data;      g_return_if_fail (!priv->osd);
2865    
2866      // this redraws the map      priv->osd = osd;
     osm_gps_map_map_redraw_idle(map);  
2867  }  }
2868    
2869  void  void
2870  osm_gps_map_clear_balloon (OsmGpsMap *map)  osm_gps_map_repaint (OsmGpsMap *map)
2871  {  {
2872      OsmGpsMapPrivate *priv;      osm_gps_map_expose (GTK_WIDGET(map), NULL);
2873    }
2874    
2875      g_return_if_fail (OSM_IS_GPS_MAP (map));  coord_t *
2876      priv = map->priv;  osm_gps_map_get_gps (OsmGpsMap *map)
2877    {
2878        g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL);
2879    
2880      priv->balloon.valid = FALSE;      if(!map->priv->gps_valid)
2881            return NULL;
2882    
2883      osm_gps_map_map_redraw_idle(map);      return map->priv->gps;
2884  }  }
2885    
2886    #endif

Legend:
Removed from v.58  
changed lines
  Added in v.231