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

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

revision 32 by harbaum, Tue Jul 28 13:21:22 2009 UTC revision 75 by harbaum, Mon Aug 24 12:57:15 2009 UTC
# Line 33  Line 33 
33    
34  #include <gdk/gdk.h>  #include <gdk/gdk.h>
35  #include <glib.h>  #include <glib.h>
36    #include <glib/gstdio.h>
37  #include <glib/gprintf.h>  #include <glib/gprintf.h>
38  #include <libsoup/soup.h>  #include <libsoup/soup.h>
39    
# Line 83  struct _OsmGpsMapPrivate Line 84  struct _OsmGpsMapPrivate
84      //contains flags indicating the various special characters      //contains flags indicating the various special characters
85      //the uri string contains, that will be replaced when calculating      //the uri string contains, that will be replaced when calculating
86      //the uri to download.      //the uri to download.
87        OsmGpsMapSource_t map_source;
88      char *repo_uri;      char *repo_uri;
89        char *image_format;
90      int uri_format;      int uri_format;
91      //flag indicating if the map source is located on the google      //flag indicating if the map source is located on the google
92      gboolean the_google;      gboolean the_google;
# Line 95  struct _OsmGpsMapPrivate Line 98  struct _OsmGpsMapPrivate
98      coord_t *gps;      coord_t *gps;
99      gboolean gps_valid;      gboolean gps_valid;
100    
101    #ifdef ENABLE_BALLOON
102        //a balloon with additional info
103        struct {
104            coord_t *coo;
105            gboolean valid;
106            OsmGpsMapRect_t rect;
107            OsmGpsMapBalloonCallback cb;
108            gpointer data;
109        } balloon;
110    #endif
111    
112    #ifdef ENABLE_OSD
113        //the osd controls (if present)
114        osm_gps_map_osd_t *osd;
115    #ifdef OSD_DOUBLE_BUFFER
116        GdkPixmap *dbuf_pixmap;
117    #endif
118    #endif
119    
120      //additional images or tracks added to the map      //additional images or tracks added to the map
121      GSList *tracks;      GSList *tracks;
122      GSList *images;      GSList *images;
# Line 104  struct _OsmGpsMapPrivate Line 126  struct _OsmGpsMapPrivate
126      GdkGC *gc_map;      GdkGC *gc_map;
127    
128      //The tile painted when one cannot be found      //The tile painted when one cannot be found
129      //GdkPixbuf *missing_tile;      GdkPixbuf *null_tile;
130    
131      //For tracking click and drag      //For tracking click and drag
132      int drag_counter;      int drag_counter;
# Line 157  enum Line 179  enum
179      PROP_TILES_QUEUED,      PROP_TILES_QUEUED,
180      PROP_GPS_TRACK_WIDTH,      PROP_GPS_TRACK_WIDTH,
181      PROP_GPS_POINT_R1,      PROP_GPS_POINT_R1,
182      PROP_GPS_POINT_R2      PROP_GPS_POINT_R2,
183        PROP_MAP_SOURCE,
184        PROP_IMAGE_FORMAT
185  };  };
186    
187  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);
# Line 171  static gchar    *replace_map_uri(OsmGpsM Line 195  static gchar    *replace_map_uri(OsmGpsM
195  static void     osm_gps_map_print_images (OsmGpsMap *map);  static void     osm_gps_map_print_images (OsmGpsMap *map);
196  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);
197  static void     osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y);  static void     osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y);
198    #ifdef LIBSOUP22
199    static void     osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data);
200    #else
201    static void     osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data);
202    #endif
203  static void     osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw);  static void     osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw);
204  static void     osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y);  static void     osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y);
205  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);
# Line 420  my_log_handler (const gchar * log_domain Line 449  my_log_handler (const gchar * log_domain
449          g_log_default_handler (log_domain, log_level, message, user_data);          g_log_default_handler (log_domain, log_level, message, user_data);
450  }  }
451    
452    static float
453    osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon)
454    {
455        /* world at zoom 1 == 512 pixels */
456        return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom));
457    }
458    
459  /* clears the trip list and all resources */  /* clears the trip list and all resources */
460  static void  static void
461  osm_gps_map_free_trip (OsmGpsMap *map)  osm_gps_map_free_trip (OsmGpsMap *map)
# Line 529  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 565  osm_gps_map_draw_gps_point (OsmGpsMap *m
565          int x, y;          int x, y;
566          int r = priv->ui_gps_point_inner_radius;          int r = priv->ui_gps_point_inner_radius;
567          int r2 = priv->ui_gps_point_outer_radius;          int r2 = priv->ui_gps_point_outer_radius;
568            // int lw = priv->ui_gps_track_width;
569          int mr = MAX(r,r2);          int mr = MAX(r,r2);
570    
571          map_x0 = priv->map_x - EXTRA_BORDER;          map_x0 = priv->map_x - EXTRA_BORDER;
# Line 539  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 576  osm_gps_map_draw_gps_point (OsmGpsMap *m
576          cairo_t *cr;          cairo_t *cr;
577          cairo_pattern_t *pat;          cairo_pattern_t *pat;
578  #else  #else
         int lw = priv->ui_gps_track_width;  
579          GdkColor color;          GdkColor color;
580          GdkGC *marker;          GdkGC *marker;
581  #endif  #endif
# Line 614  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 650  osm_gps_map_draw_gps_point (OsmGpsMap *m
650                                      (mr*2)+lw+lw);                                      (mr*2)+lw+lw);
651  #endif  #endif
652      }      }
653    }
654    
655    #ifdef ENABLE_BALLOON
656    /* most visual effects are hardcoded by now, but may be made */
657    /* available via properties later */
658    #ifndef BALLOON_AREA_WIDTH
659    #define BALLOON_AREA_WIDTH           290
660    #endif
661    #ifndef BALLOON_AREA_HEIGHT
662    #define BALLOON_AREA_HEIGHT           75
663    #endif
664    #ifndef BALLOON_CORNER_RADIUS
665    #define BALLOON_CORNER_RADIUS         10
666    #endif
667    
668    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
669    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
670    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
671    #define BALLOON_TRANSPARENCY         0.8
672    #define POINTER_HEIGHT                20
673    #define POINTER_FOOT_WIDTH            20
674    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
675    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
676    #define BALLOON_SHADOW_TRANSPARENCY  0.2
677    
678    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
679    
680    
681    /* draw the bubble shape. this is used twice, once for the shape and once */
682    /* for the shadow */
683    static void
684    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
685           gboolean bottom, int px, int py, int px0, int px1) {
686    
687        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
688        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
689                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
690        if(!bottom) {
691            /* insert top pointer */
692            cairo_line_to (cr, px1, y0);
693            cairo_line_to (cr, px, py);
694            cairo_line_to (cr, px0, y0);
695        }
696    
697        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
698        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
699                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
700        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
701        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
702                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
703        if(bottom) {
704            /* insert bottom pointer */
705            cairo_line_to (cr, px0, y1);
706            cairo_line_to (cr, px, py);
707            cairo_line_to (cr, px1, y1);
708        }
709    
710        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
711        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
712                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
713    
714        cairo_close_path (cr);
715    }
716    
717    static void
718    osm_gps_map_draw_balloon_int (OsmGpsMap *map)
719    {
720        OsmGpsMapPrivate *priv = map->priv;
721    
722        if (priv->balloon.valid) {
723    
724            /* ------- convert given coordinate into screen position --------- */
725            int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -
726                priv->map_x + EXTRA_BORDER;
727            int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -
728                priv->map_y + EXTRA_BORDER;
729    
730            /* check position of this relative to screen center to determine */
731            /* pointer direction ... */
732            int pointer_x = x0, pointer_x0, pointer_x1;
733            int pointer_y = y0;
734    
735            /* ... and calculate position */
736            if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) {
737                x0 -= BALLOON_WIDTH - POINTER_OFFSET;
738                pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
739                pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
740            } else {
741                x0 -= POINTER_OFFSET;
742                pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
743                pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
744            }
745    
746            gboolean bottom = FALSE;
747            if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) {
748                bottom = TRUE;
749                y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;
750            } else
751                y0 += POINTER_HEIGHT;
752    
753            /* calculate bottom/right of box */
754            int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
755    
756            /* save balloon screen coordinates for later use */
757            priv->balloon.rect.x = x0 + BALLOON_BORDER;
758            priv->balloon.rect.y = y0 + BALLOON_BORDER;
759            priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
760            priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
761    
762    #ifdef USE_CAIRO
763            cairo_t *cr = gdk_cairo_create(priv->pixmap);
764    
765            /* --------- draw shadow --------------- */
766            osm_gps_map_draw_balloon_shape (cr,
767                        x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
768                        x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
769                        bottom, pointer_x, pointer_y,
770                        pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
771    
772            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
773            cairo_fill_preserve (cr);
774            cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
775            cairo_set_line_width (cr, 0);
776            cairo_stroke (cr);
777    
778            /* --------- draw main shape ----------- */
779            osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
780                        bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
781    
782            cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
783            cairo_fill_preserve (cr);
784            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
785            cairo_set_line_width (cr, 1);
786            cairo_stroke (cr);
787    
788    
789            /* ---------- draw close button --------- */
790    
791            int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;
792            int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;
793            int crad = CLOSE_BUTTON_RADIUS;
794    
795            cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
796            cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
797            cairo_fill_preserve (cr);
798            cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
799            cairo_set_line_width (cr, 2);
800            cairo_stroke(cr);
801    
802            cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
803            cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);
804            cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
805            cairo_move_to (cr, cx - crad/2, cy - crad/2);
806            cairo_line_to (cr, cx + crad/2, cy + crad/2);
807            cairo_stroke (cr);
808            cairo_move_to (cr, cx + crad/2, cy - crad/2);
809            cairo_line_to (cr, cx - crad/2, cy + crad/2);
810            cairo_stroke (cr);
811    
812            if (priv->balloon.cb) {
813                /* clip in case application tries to draw in */
814                /* exceed of the balloon */
815                cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
816                                 priv->balloon.rect.w, priv->balloon.rect.h);
817                cairo_clip (cr);
818                cairo_new_path (cr);  /* current path is not
819                                         consumed by cairo_clip() */
820    
821                priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
822            }
823    
824            cairo_destroy(cr);
825    
826            gtk_widget_queue_draw_area (GTK_WIDGET(map),
827                                        x0, y0, BALLOON_WIDTH,
828                                        BALLOON_HEIGHT + POINTER_HEIGHT);
829    #else
830    #warning "Balloon display lacks a non-cairo implementation!"
831    #endif
832        }
833  }  }
834    
835    /* the user clicked into the balloons main area. handle this */
836    static void
837    osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)
838    {
839        OsmGpsMapPrivate *priv = map->priv;
840    
841        if (!priv->balloon.valid)
842            return;
843    
844        /* check if the close button was clicked */
845        if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&
846            (x < priv->balloon.rect.w) &&
847            (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {
848    
849            priv->balloon.valid = FALSE;
850            osm_gps_map_map_redraw_idle(map);
851        }
852    }
853    
854    /* return true if balloon is being displayed and if */
855    /* the given coordinate is within this balloon */
856    static gboolean
857    osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)
858    {
859        return (priv->balloon.valid &&
860                (x > priv->balloon.rect.x) &&
861                (x < priv->balloon.rect.x + priv->balloon.rect.w) &&
862                (y > priv->balloon.rect.y) &&
863                (y < priv->balloon.rect.y + priv->balloon.rect.h));
864    }
865    #endif // ENABLE_BALLOON
866    
867  static void  static void
868  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)
869  {  {
870      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
871    
872      g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y,      g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, TILESIZE,TILESIZE);
             TILESIZE,TILESIZE);  
873    
874      /* draw pixbuf onto pixmap */      /* draw pixbuf onto pixmap */
875      gdk_draw_pixbuf (priv->pixmap,      gdk_draw_pixbuf (priv->pixmap,
# Line 654  static void Line 901  static void
901  osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data)  osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data)
902  #endif  #endif
903  {  {
904      int fd;      FILE *file;
905      tile_download_t *dl = (tile_download_t *)user_data;      tile_download_t *dl = (tile_download_t *)user_data;
906      OsmGpsMap *map = OSM_GPS_MAP(dl->map);      OsmGpsMap *map = OSM_GPS_MAP(dl->map);
907      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 667  osm_gps_map_tile_download_complete (Soup Line 914  osm_gps_map_tile_download_complete (Soup
914          {          {
915              if (g_mkdir_with_parents(dl->folder,0700) == 0)              if (g_mkdir_with_parents(dl->folder,0700) == 0)
916              {              {
917                  fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);                  file = g_fopen(dl->filename, "wb");
918                  if (fd != -1)                  if (file != NULL)
919                  {                  {
920                      write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg));                      fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file);
921                      file_saved = TRUE;                      file_saved = TRUE;
922                        g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);
923                        fclose (file);
924    
                     g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);  
                     close (fd);  
925                  }                  }
926              }              }
927              else              else
928              {              {
929                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
930                              dl->folder);
931                    perror("perror:");
932              }              }
933          }          }
934    
# Line 687  osm_gps_map_tile_download_complete (Soup Line 936  osm_gps_map_tile_download_complete (Soup
936          {          {
937              GdkPixbuf *pixbuf = NULL;              GdkPixbuf *pixbuf = NULL;
938    
939                /* if the file was actually stored on disk, we can simply */
940                /* load and decode it from that file */
941              if (priv->cache_dir)              if (priv->cache_dir)
942              {              {
943                  if (file_saved)                  if (file_saved)
# Line 720  osm_gps_map_tile_download_complete (Soup Line 971  osm_gps_map_tile_download_complete (Soup
971                      g_warning("Error: Unable to determine image file format");                      g_warning("Error: Unable to determine image file format");
972                  }                  }
973              }              }
974    
975              /* Store the tile into the cache */              /* Store the tile into the cache */
976              if (G_LIKELY (pixbuf))              if (G_LIKELY (pixbuf))
977              {              {
# Line 735  osm_gps_map_tile_download_complete (Soup Line 986  osm_gps_map_tile_download_complete (Soup
986                   * we are using it as a key in the hash table */                   * we are using it as a key in the hash table */
987                  dl->filename = NULL;                  dl->filename = NULL;
988              }              }
   
989              osm_gps_map_map_redraw_idle (map);              osm_gps_map_map_redraw_idle (map);
990          }          }
991          g_hash_table_remove(priv->tile_queue, dl->uri);          g_hash_table_remove(priv->tile_queue, dl->uri);
# Line 794  osm_gps_map_download_tile (OsmGpsMap *ma Line 1044  osm_gps_map_download_tile (OsmGpsMap *ma
1044          g_free(dl->uri);          g_free(dl->uri);
1045          g_free(dl);          g_free(dl);
1046      } else {      } else {
1047          dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x);          dl->folder = g_strdup_printf("%s%c%d%c%d%c",
1048          dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y);                              priv->cache_dir, G_DIR_SEPARATOR,
1049                                zoom, G_DIR_SEPARATOR,
1050                                x, G_DIR_SEPARATOR);
1051            dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1052                                priv->cache_dir, G_DIR_SEPARATOR,
1053                                zoom, G_DIR_SEPARATOR,
1054                                x, G_DIR_SEPARATOR,
1055                                y,
1056                                priv->image_format);
1057          dl->map = map;          dl->map = map;
1058          dl->redraw = redraw;          dl->redraw = redraw;
1059    
# Line 813  osm_gps_map_download_tile (OsmGpsMap *ma Line 1071  osm_gps_map_download_tile (OsmGpsMap *ma
1071                      if (cookie) {                      if (cookie) {
1072                          g_debug("Adding Google Cookie");                          g_debug("Adding Google Cookie");
1073                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);
   
1074                      }                      }
1075                  }                  }
1076              }              }
# Line 835  osm_gps_map_load_cached_tile (OsmGpsMap Line 1092  osm_gps_map_load_cached_tile (OsmGpsMap
1092  {  {
1093      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1094      gchar *filename;      gchar *filename;
1095      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf = NULL;
1096      OsmCachedTile *tile;      OsmCachedTile *tile;
1097    
1098      filename = g_strdup_printf("%s/%u/%u/%u.png",      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1099                                 priv->cache_dir,                  priv->cache_dir, G_DIR_SEPARATOR,
1100                                 zoom, x, y);                  zoom, G_DIR_SEPARATOR,
1101                    x, G_DIR_SEPARATOR,
1102                    y,
1103                    priv->image_format);
1104    
1105      tile = g_hash_table_lookup (priv->tile_cache, filename);      tile = g_hash_table_lookup (priv->tile_cache, filename);
1106      if (tile)      if (tile)
1107      {      {
1108          g_free (filename);          g_free (filename);
1109      }      }
1110      else if (priv->cache_dir)      else
1111      {      {
1112          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1113          if (pixbuf)          if (pixbuf)
# Line 863  osm_gps_map_load_cached_tile (OsmGpsMap Line 1123  osm_gps_map_load_cached_tile (OsmGpsMap
1123      {      {
1124          tile->redraw_cycle = priv->redraw_cycle;          tile->redraw_cycle = priv->redraw_cycle;
1125          pixbuf = g_object_ref (tile->pixbuf);          pixbuf = g_object_ref (tile->pixbuf);
1126      } else      }
         pixbuf = NULL;  
1127    
1128      return pixbuf;      return pixbuf;
1129  }  }
# Line 928  static void Line 1187  static void
1187  osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y)  osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y)
1188  {  {
1189      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1190        gchar *filename;
1191      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf;
1192    
1193      g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom);      g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom);
1194    
1195      /* try to get file from internal cache */      if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) {
1196      pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y);          osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y);
1197            return;
1198        }
1199    
1200      /* if a disk cache is being used, try to read the file from there */      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1201      if (priv->cache_dir && !pixbuf)                  priv->cache_dir, G_DIR_SEPARATOR,
1202      {                  zoom, G_DIR_SEPARATOR,
1203          gchar *filename;                  x, G_DIR_SEPARATOR,
1204          filename = g_strdup_printf("%s/%u/%u/%u.png",                  y,
1205                                     priv->cache_dir,                  priv->image_format);
                                    zoom, x, y);  
   
         pixbuf = gdk_pixbuf_new_from_file (filename, NULL);  
         if (pixbuf)  
         {  
             g_debug("Found tile %s", filename);  
         }  
1206    
1207          g_free(filename);      /* try to get file from internal cache first */
1208      }      if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y)))
1209            pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1210    
1211      if (G_LIKELY(pixbuf))      if(pixbuf)
1212      {      {
1213            g_debug("Found tile %s", filename);
1214          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);
1215          g_object_unref (pixbuf);          g_object_unref (pixbuf);
1216      }      }
# Line 984  osm_gps_map_load_tile (OsmGpsMap *map, i Line 1241  osm_gps_map_load_tile (OsmGpsMap *map, i
1241                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);
1242          }          }
1243      }      }
1244        g_free(filename);
1245  }  }
1246    
1247  static void  static void
# Line 1077  osm_gps_map_print_track (OsmGpsMap *map, Line 1335  osm_gps_map_print_track (OsmGpsMap *map,
1335    
1336      map_x0 = priv->map_x - EXTRA_BORDER;      map_x0 = priv->map_x - EXTRA_BORDER;
1337      map_y0 = priv->map_y - EXTRA_BORDER;      map_y0 = priv->map_y - EXTRA_BORDER;
   
1338      for(list = trackpoint_list; list != NULL; list = list->next)      for(list = trackpoint_list; list != NULL; list = list->next)
1339      {      {
1340          coord_t *tp = list->data;          coord_t *tp = list->data;
# Line 1132  osm_gps_map_print_tracks (OsmGpsMap *map Line 1389  osm_gps_map_print_tracks (OsmGpsMap *map
1389    
1390      if (priv->show_trip_history)      if (priv->show_trip_history)
1391          osm_gps_map_print_track (map, priv->trip_history);          osm_gps_map_print_track (map, priv->trip_history);
1392    
1393      if (priv->tracks)      if (priv->tracks)
1394      {      {
         g_debug("TRACK");  
1395          GSList* tmp = priv->tracks;          GSList* tmp = priv->tracks;
1396          while (tmp != NULL)          while (tmp != NULL)
1397          {          {
# Line 1144  osm_gps_map_print_tracks (OsmGpsMap *map Line 1401  osm_gps_map_print_tracks (OsmGpsMap *map
1401      }      }
1402  }  }
1403    
1404  static gboolean  static gboolean
1405  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)
1406  {  {
1407      return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);     return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);
1408  }  }
1409    
1410  static void  static void
1411  osm_gps_map_purge_cache (OsmGpsMap *map)  osm_gps_map_purge_cache (OsmGpsMap *map)
1412  {  {
1413      OsmGpsMapPrivate *priv = map->priv;     OsmGpsMapPrivate *priv = map->priv;
1414    
1415      if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size)     if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size)
1416          return;         return;
1417    
1418      /* run through the cache, and remove the tiles which have not been used     /* run through the cache, and remove the tiles which have not been used
1419       * during the last redraw operation */      * during the last redraw operation */
1420      g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv);     g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv);
1421  }  }
1422    
1423  static gboolean  static gboolean
# Line 1193  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1450  osm_gps_map_map_redraw (OsmGpsMap *map)
1450      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1451      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1452      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1453    #ifdef ENABLE_BALLOON
1454        osm_gps_map_draw_balloon_int(map);
1455    #endif
1456    
1457      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1458      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1224  osm_gps_map_init (OsmGpsMap *object) Line 1484  osm_gps_map_init (OsmGpsMap *object)
1484      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1485      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1486    
1487    #ifdef ENABLE_BALLOON
1488        priv->balloon.coo = g_new0(coord_t, 1);
1489        priv->balloon.valid = FALSE;
1490        priv->balloon.cb = NULL;
1491    #endif
1492    
1493    #ifdef ENABLE_OSD
1494        priv->osd = NULL;
1495    #endif
1496    
1497      priv->tracks = NULL;      priv->tracks = NULL;
1498      priv->images = NULL;      priv->images = NULL;
1499    
# Line 1236  osm_gps_map_init (OsmGpsMap *object) Line 1506  osm_gps_map_init (OsmGpsMap *object)
1506      priv->uri_format = 0;      priv->uri_format = 0;
1507      priv->the_google = FALSE;      priv->the_google = FALSE;
1508    
1509        priv->map_source = -1;
1510    
1511  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1512      //Change naumber of concurrent connections option?      //Change naumber of concurrent connections option?
1513      priv->soup_session = soup_session_async_new_with_options(      priv->soup_session = soup_session_async_new_with_options(
# Line 1289  osm_gps_map_constructor (GType gtype, gu Line 1561  osm_gps_map_constructor (GType gtype, gu
1561  {  {
1562      GObject *object;      GObject *object;
1563      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
1564        OsmGpsMap *map;
1565        const char *uri;
1566    
1567      //Always chain up to the parent constructor      //Always chain up to the parent constructor
1568      object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);      object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);
1569        map = OSM_GPS_MAP(object);
1570      priv = OSM_GPS_MAP_PRIVATE(object);      priv = OSM_GPS_MAP_PRIVATE(object);
1571    
1572        //user can specify a map source ID, or a repo URI as the map source
1573        uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);
1574        if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {
1575            g_debug("Using null source");
1576            priv->map_source = OSM_GPS_MAP_SOURCE_NULL;
1577    
1578            priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256);
1579            gdk_pixbuf_fill(priv->null_tile, 0xcccccc00);
1580        }
1581        else if (priv->map_source >= 0) {
1582            //check if the source given is valid
1583            uri = osm_gps_map_source_get_repo_uri(priv->map_source);
1584            if (uri) {
1585                g_debug("Setting map source from ID");
1586                g_free(priv->repo_uri);
1587    
1588                priv->repo_uri = g_strdup(uri);
1589                priv->image_format = g_strdup(
1590                    osm_gps_map_source_get_image_format(priv->map_source));
1591                priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source);
1592                priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source);
1593            }
1594        }
1595    
1596      if (!priv->cache_dir_is_full_path) {      if (!priv->cache_dir_is_full_path) {
1597  #ifdef G_CHECKSUM_MD5  #ifdef G_CHECKSUM_MD5
1598          char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1);          char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1);
# Line 1304  osm_gps_map_constructor (GType gtype, gu Line 1603  osm_gps_map_constructor (GType gtype, gu
1603          if (priv->cache_dir) {          if (priv->cache_dir) {
1604              char *old = priv->cache_dir;              char *old = priv->cache_dir;
1605              //the new cachedir is the given cache dir + the md5 of the repo_uri              //the new cachedir is the given cache dir + the md5 of the repo_uri
1606              priv->cache_dir = g_strdup_printf("%s/%s", old, md5);              priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5);
1607              g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);              g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);
1608              g_free(old);              g_free(old);
1609            } else {
1610                //the new cachedir is the current dir + the md5 of the repo_uri
1611                priv->cache_dir = g_strdup(md5);
1612          }          }
1613    
1614          g_free(md5);          g_free(md5);
1615      }      }
1616    
1617        inspect_map_uri(map);
1618    
1619      return object;      return object;
1620  }  }
1621    
# Line 1338  osm_gps_map_dispose (GObject *object) Line 1642  osm_gps_map_dispose (GObject *object)
1642      if(priv->pixmap)      if(priv->pixmap)
1643          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
1644    
1645        if (priv->null_tile)
1646            g_object_unref (priv->null_tile);
1647    
1648      if(priv->gc_map)      if(priv->gc_map)
1649          g_object_unref(priv->gc_map);          g_object_unref(priv->gc_map);
1650    
1651      if (priv->idle_map_redraw != 0)      if (priv->idle_map_redraw != 0)
1652          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1653    
1654        g_free(priv->gps);
1655    
1656    #ifdef ENABLE_BALLOON
1657        g_free(priv->balloon.coo);
1658    #endif
1659    
1660    #ifdef ENABLE_OSD
1661        if(priv->osd)
1662            priv->osd->free(priv->osd);
1663    
1664    #ifdef OSD_DOUBLE_BUFFER
1665        if(priv->dbuf_pixmap)
1666            g_object_unref (priv->dbuf_pixmap);
1667    #endif
1668    #endif
1669    
1670      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
1671  }  }
1672    
# Line 1355  osm_gps_map_finalize (GObject *object) Line 1678  osm_gps_map_finalize (GObject *object)
1678    
1679      g_free(priv->cache_dir);      g_free(priv->cache_dir);
1680      g_free(priv->repo_uri);      g_free(priv->repo_uri);
1681        g_free(priv->image_format);
1682    
1683      osm_gps_map_free_trip(map);      osm_gps_map_free_trip(map);
1684      osm_gps_map_free_tracks(map);      osm_gps_map_free_tracks(map);
# Line 1385  osm_gps_map_set_property (GObject *objec Line 1709  osm_gps_map_set_property (GObject *objec
1709              break;              break;
1710          case PROP_REPO_URI:          case PROP_REPO_URI:
1711              priv->repo_uri = g_value_dup_string (value);              priv->repo_uri = g_value_dup_string (value);
             inspect_map_uri(map);  
1712              break;              break;
1713          case PROP_PROXY_URI:          case PROP_PROXY_URI:
1714              if ( g_value_get_string(value) ) {              if ( g_value_get_string(value) ) {
   
1715                  priv->proxy_uri = g_value_dup_string (value);                  priv->proxy_uri = g_value_dup_string (value);
1716                  g_debug("Setting proxy server: %s", priv->proxy_uri);                  g_debug("Setting proxy server: %s", priv->proxy_uri);
1717    
1718  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1719                  GValue val = {0};                  GValue val = {0};
1720    
1721                  SoupURI* uri = soup_uri_new(priv->proxy_uri);                  SoupURI* uri = soup_uri_new(priv->proxy_uri);
1722                  g_value_init(&val, SOUP_TYPE_URI);                  g_value_init(&val, SOUP_TYPE_URI);
1723                  g_value_take_boxed(&val, uri);                  g_value_take_boxed(&val, uri);
# Line 1403  osm_gps_map_set_property (GObject *objec Line 1727  osm_gps_map_set_property (GObject *objec
1727                  SoupUri* uri = soup_uri_new(priv->proxy_uri);                  SoupUri* uri = soup_uri_new(priv->proxy_uri);
1728                  g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL);                  g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL);
1729  #endif  #endif
                 soup_uri_free(uri);  
1730              } else              } else
1731                  priv->proxy_uri = NULL;                  priv->proxy_uri = NULL;
1732    
1733              break;              break;
1734          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1735              priv->cache_dir = g_value_dup_string (value);              if ( g_value_get_string(value) )
1736                    priv->cache_dir = g_value_dup_string (value);
1737              break;              break;
1738          case PROP_TILE_CACHE_DIR_IS_FULL_PATH:          case PROP_TILE_CACHE_DIR_IS_FULL_PATH:
1739              priv->cache_dir_is_full_path = g_value_get_boolean (value);              priv->cache_dir_is_full_path = g_value_get_boolean (value);
# Line 1440  osm_gps_map_set_property (GObject *objec Line 1764  osm_gps_map_set_property (GObject *objec
1764          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1765              priv->ui_gps_point_outer_radius = g_value_get_int (value);              priv->ui_gps_point_outer_radius = g_value_get_int (value);
1766              break;              break;
1767            case PROP_MAP_SOURCE:
1768                priv->map_source = g_value_get_int (value);
1769                break;
1770            case PROP_IMAGE_FORMAT:
1771                priv->image_format = g_value_dup_string (value);
1772                break;
1773          default:          default:
1774              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1775              break;              break;
# Line 1517  osm_gps_map_get_property (GObject *objec Line 1847  osm_gps_map_get_property (GObject *objec
1847          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1848              g_value_set_int(value, priv->ui_gps_point_outer_radius);              g_value_set_int(value, priv->ui_gps_point_outer_radius);
1849              break;              break;
1850            case PROP_MAP_SOURCE:
1851                g_value_set_int(value, priv->map_source);
1852                break;
1853            case PROP_IMAGE_FORMAT:
1854                g_value_set_string(value, priv->image_format);
1855                break;
1856          default:          default:
1857              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1858              break;              break;
# Line 1524  osm_gps_map_get_property (GObject *objec Line 1860  osm_gps_map_get_property (GObject *objec
1860  }  }
1861    
1862  static gboolean  static gboolean
1863  _osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll  *event)  osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll  *event)
1864  {  {
1865      OsmGpsMap *map = OSM_GPS_MAP(widget);      OsmGpsMap *map = OSM_GPS_MAP(widget);
1866      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 1546  osm_gps_map_button_press (GtkWidget *wid Line 1882  osm_gps_map_button_press (GtkWidget *wid
1882  {  {
1883      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
1884    
1885    #ifdef ENABLE_BALLOON
1886        /* don't drag if the user clicked within the balloon */
1887        if (osm_gps_map_in_balloon(priv,
1888                       event->x + EXTRA_BORDER,
1889                       event->y + EXTRA_BORDER))
1890        {
1891            priv->drag_counter = -1;
1892            return FALSE;
1893        }
1894    #endif
1895    
1896    #ifdef ENABLE_OSD
1897        #define SCROLL_STEP 10
1898    
1899        /* pressed inside OSD control? */
1900        if(priv->osd) {
1901            osd_button_t but = priv->osd->check(event->x, event->y);
1902            if(but != OSD_NONE)
1903            {
1904                priv->drag_counter = -1;
1905    
1906                switch(but) {
1907                case OSD_UP:
1908                    priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
1909                    priv->center_coord_set = FALSE;
1910                    break;
1911    
1912                case OSD_DOWN:
1913                    priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
1914                    priv->center_coord_set = FALSE;
1915                    break;
1916    
1917                case OSD_LEFT:
1918                    priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
1919                    priv->center_coord_set = FALSE;
1920                    break;
1921    
1922                case OSD_RIGHT:
1923                    priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
1924                    priv->center_coord_set = FALSE;
1925                    break;
1926    
1927                case OSD_IN:
1928                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
1929                    break;
1930    
1931                case OSD_OUT:
1932                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
1933                    break;
1934    
1935                default:
1936                    /* all custom buttons are forwarded to the application */
1937                    if(priv->osd->cb)
1938                        priv->osd->cb(but, priv->osd->data);
1939                    break;
1940                }
1941    
1942                osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1943    
1944                return FALSE;
1945            }
1946        }
1947    #endif
1948    
1949      priv->drag_counter = 0;      priv->drag_counter = 0;
1950      priv->drag_start_mouse_x = (int) event->x;      priv->drag_start_mouse_x = (int) event->x;
1951      priv->drag_start_mouse_y = (int) event->y;      priv->drag_start_mouse_y = (int) event->y;
# Line 1560  osm_gps_map_button_release (GtkWidget *w Line 1960  osm_gps_map_button_release (GtkWidget *w
1960  {  {
1961      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
1962    
1963    #ifdef ENABLE_BALLOON
1964        /* released inside the balloon? */
1965        if (osm_gps_map_in_balloon(priv,
1966                       event->x + EXTRA_BORDER,
1967                       event->y + EXTRA_BORDER))
1968        {
1969            osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
1970                 event->x - priv->balloon.rect.x + EXTRA_BORDER,
1971                 event->y - priv->balloon.rect.y + EXTRA_BORDER);
1972        }
1973    #endif
1974    
1975      if (priv->dragging)      if (priv->dragging)
1976      {      {
1977          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1577  osm_gps_map_button_release (GtkWidget *w Line 1989  osm_gps_map_button_release (GtkWidget *w
1989    
1990      priv->drag_mouse_dx = 0;      priv->drag_mouse_dx = 0;
1991      priv->drag_mouse_dy = 0;      priv->drag_mouse_dy = 0;
1992      priv->drag_counter = 0;      priv->drag_counter = -1;
1993    
1994      return FALSE;      return FALSE;
1995  }  }
1996    
1997  static gboolean  static gboolean
1998    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);
1999    
2000    static gboolean
2001  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)
2002  {  {
2003      int x, y;      int x, y;
# Line 1602  osm_gps_map_motion_notify (GtkWidget *wi Line 2017  osm_gps_map_motion_notify (GtkWidget *wi
2017      if (!(state & GDK_BUTTON1_MASK))      if (!(state & GDK_BUTTON1_MASK))
2018          return FALSE;          return FALSE;
2019    
2020        if (priv->drag_counter < 0)
2021            return FALSE;
2022    
2023      priv->drag_counter++;      priv->drag_counter++;
2024    
2025      // we havent dragged more than 6 pixels      // we havent dragged more than 6 pixels
2026      if (priv->drag_counter < 6)      if (priv->drag_counter < 6)
2027          return FALSE;          return FALSE;
2028    
2029    #ifdef OSM_GPS_MAP_REFRESH
2030        /* reduce update frequency on maemo to keep screen update fluid */
2031        static guint32 last_time = 0;
2032    
2033        if(event->time - last_time < (1000/OSM_GPS_MAP_REFRESH)) return FALSE;
2034        last_time = event->time;
2035    #endif
2036    
2037      priv->dragging = TRUE;      priv->dragging = TRUE;
2038    
2039      if (priv->map_auto_center)      if (priv->map_auto_center)
# Line 1616  osm_gps_map_motion_notify (GtkWidget *wi Line 2042  osm_gps_map_motion_notify (GtkWidget *wi
2042      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2043      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2044    
2045      gdk_draw_drawable (      osm_gps_map_expose (widget, NULL);
2046                         widget->window,  
2047        return FALSE;
2048    }
2049    
2050    static gboolean
2051    osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event)
2052    {
2053        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2054    
2055        /* create pixmap */
2056        if (priv->pixmap)
2057            g_object_unref (priv->pixmap);
2058    
2059        priv->pixmap = gdk_pixmap_new (
2060                            widget->window,
2061                            widget->allocation.width + EXTRA_BORDER * 2,
2062                            widget->allocation.height + EXTRA_BORDER * 2,
2063                            -1);
2064    
2065    #ifdef ENABLE_OSD
2066    
2067    #ifdef OSD_DOUBLE_BUFFER
2068        if (priv->dbuf_pixmap)
2069            g_object_unref (priv->dbuf_pixmap);
2070    
2071        priv->dbuf_pixmap = gdk_pixmap_new (
2072                            widget->window,
2073                            widget->allocation.width,
2074                            widget->allocation.height,
2075                            -1);
2076    #endif
2077    
2078        /* the osd needs some references to map internal objects */
2079        if(priv->osd)
2080            priv->osd->widget = widget;
2081    #endif
2082    
2083        /* and gc, used for clipping (I think......) */
2084        if(priv->gc_map)
2085            g_object_unref(priv->gc_map);
2086    
2087        priv->gc_map = gdk_gc_new(priv->pixmap);
2088    
2089        osm_gps_map_map_redraw(OSM_GPS_MAP(widget));
2090    
2091        return FALSE;
2092    }
2093    
2094    static gboolean
2095    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event)
2096    {
2097        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2098    
2099    #if defined(ENABLE_OSD) && defined(OSD_DOUBLE_BUFFER)
2100        GdkDrawable *drawable = priv->dbuf_pixmap;
2101    #else
2102        GdkDrawable *drawable = widget->window;
2103    #endif
2104    
2105        gdk_draw_drawable (drawable,
2106                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2107                         priv->pixmap,                         priv->pixmap,
2108                         0,0,                         0,0,
2109                         priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER,                         priv->drag_mouse_dx - EXTRA_BORDER,
2110                           priv->drag_mouse_dy - EXTRA_BORDER,
2111                         -1,-1);                         -1,-1);
2112    
2113      //Paint white outside of the map if dragging. Its less      //Paint white outside of the map if dragging. Its less
2114      //ugly than painting the corrupted map      //ugly than painting the corrupted map
2115      if(priv->drag_mouse_dx>EXTRA_BORDER) {      if(priv->drag_mouse_dx>EXTRA_BORDER) {
2116          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2117                              widget->style->white_gc,                              widget->style->white_gc,
2118                              TRUE,                              TRUE,
2119                              0, 0,                              0, 0,
# Line 1637  osm_gps_map_motion_notify (GtkWidget *wi Line 2122  osm_gps_map_motion_notify (GtkWidget *wi
2122      }      }
2123      else if (-priv->drag_mouse_dx > EXTRA_BORDER)      else if (-priv->drag_mouse_dx > EXTRA_BORDER)
2124      {      {
2125          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2126                              widget->style->white_gc,                              widget->style->white_gc,
2127                              TRUE,                              TRUE,
2128                              priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,                              priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,
# Line 1647  osm_gps_map_motion_notify (GtkWidget *wi Line 2131  osm_gps_map_motion_notify (GtkWidget *wi
2131      }      }
2132    
2133      if (priv->drag_mouse_dy>EXTRA_BORDER) {      if (priv->drag_mouse_dy>EXTRA_BORDER) {
2134          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2135                              widget->style->white_gc,                              widget->style->white_gc,
2136                              TRUE,                              TRUE,
2137                              0, 0,                              0, 0,
# Line 1657  osm_gps_map_motion_notify (GtkWidget *wi Line 2140  osm_gps_map_motion_notify (GtkWidget *wi
2140      }      }
2141      else if (-priv->drag_mouse_dy > EXTRA_BORDER)      else if (-priv->drag_mouse_dy > EXTRA_BORDER)
2142      {      {
2143          gdk_draw_rectangle (          gdk_draw_rectangle (drawable,
                             widget->window,  
2144                              widget->style->white_gc,                              widget->style->white_gc,
2145                              TRUE,                              TRUE,
2146                              0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,                              0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,
# Line 1666  osm_gps_map_motion_notify (GtkWidget *wi Line 2148  osm_gps_map_motion_notify (GtkWidget *wi
2148                              -priv->drag_mouse_dy - EXTRA_BORDER);                              -priv->drag_mouse_dy - EXTRA_BORDER);
2149      }      }
2150    
2151      return FALSE;  #ifdef ENABLE_OSD
2152  }      /* draw new OSD */
2153        if(priv->osd)
2154  static gboolean          priv->osd->draw (priv->osd, drawable);
 osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event)  
 {  
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
   
     /* create pixmap */  
     if (priv->pixmap)  
         g_object_unref (priv->pixmap);  
   
     priv->pixmap = gdk_pixmap_new (  
                                    widget->window,  
                                    widget->allocation.width + EXTRA_BORDER * 2,  
                                    widget->allocation.height + EXTRA_BORDER * 2,  
                                    -1);  
   
     /* and gc, used for clipping (I think......) */  
     if(priv->gc_map)  
         g_object_unref(priv->gc_map);  
2155    
2156      priv->gc_map = gdk_gc_new(priv->pixmap);  #ifdef OSD_DOUBLE_BUFFER
2157        gdk_draw_drawable (widget->window,
     osm_gps_map_map_redraw(OSM_GPS_MAP(widget));  
   
     return FALSE;  
 }  
   
 static gboolean  
 osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event)  
 {  
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
   
     gdk_draw_drawable (  
                        widget->window,  
2158                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2159                         priv->pixmap,                         priv->dbuf_pixmap,
2160                         event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,                         0,0,0,0,-1,-1);
2161                         event->area.x, event->area.y,  #endif
                        event->area.width, event->area.height);  
2162    
2163    #endif
2164    
2165      return FALSE;      return FALSE;
2166  }  }
2167    
# Line 1730  osm_gps_map_class_init (OsmGpsMapClass * Line 2184  osm_gps_map_class_init (OsmGpsMapClass *
2184      widget_class->button_press_event = osm_gps_map_button_press;      widget_class->button_press_event = osm_gps_map_button_press;
2185      widget_class->button_release_event = osm_gps_map_button_release;      widget_class->button_release_event = osm_gps_map_button_release;
2186      widget_class->motion_notify_event = osm_gps_map_motion_notify;      widget_class->motion_notify_event = osm_gps_map_motion_notify;
2187      widget_class->scroll_event = _osm_gps_map_scroll;      widget_class->scroll_event = osm_gps_map_scroll_event;
2188    
2189      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
2190                                       PROP_AUTO_CENTER,                                       PROP_AUTO_CENTER,
# Line 1768  osm_gps_map_class_init (OsmGpsMapClass * Line 2222  osm_gps_map_class_init (OsmGpsMapClass *
2222                                       PROP_REPO_URI,                                       PROP_REPO_URI,
2223                                       g_param_spec_string ("repo-uri",                                       g_param_spec_string ("repo-uri",
2224                                                            "repo uri",                                                            "repo uri",
2225                                                            "osm repo uri",                                                            "map source tile repository uri",
2226                                                            "http://tile.openstreetmap.org/#Z/#X/#Y.png",                                                            OSM_REPO_URI,
2227                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2228    
2229      g_object_class_install_property (object_class,       g_object_class_install_property (object_class,
2230                                       PROP_PROXY_URI,                                       PROP_PROXY_URI,
2231                                       g_param_spec_string ("proxy-uri",                                       g_param_spec_string ("proxy-uri",
2232                                                            "proxy uri",                                                            "proxy uri",
# Line 1785  osm_gps_map_class_init (OsmGpsMapClass * Line 2239  osm_gps_map_class_init (OsmGpsMapClass *
2239                                       g_param_spec_string ("tile-cache",                                       g_param_spec_string ("tile-cache",
2240                                                            "tile cache",                                                            "tile cache",
2241                                                            "osm local tile cache dir",                                                            "osm local tile cache dir",
2242                                                            "/tmp/Maps",                                                            NULL,
2243                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2244    
2245      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1813  osm_gps_map_class_init (OsmGpsMapClass * Line 2267  osm_gps_map_class_init (OsmGpsMapClass *
2267                                                         "maximum zoom level",                                                         "maximum zoom level",
2268                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2269                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2270                                                         17,                                                         OSM_MAX_ZOOM,
2271                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2272    
2273      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1823  osm_gps_map_class_init (OsmGpsMapClass * Line 2277  osm_gps_map_class_init (OsmGpsMapClass *
2277                                                         "minimum zoom level",                                                         "minimum zoom level",
2278                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2279                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2280                                                         1,                                                         OSM_MIN_ZOOM,
2281                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2282    
2283      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1893  osm_gps_map_class_init (OsmGpsMapClass * Line 2347  osm_gps_map_class_init (OsmGpsMapClass *
2347                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2348                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2349                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2350                                                         5,                                                         10,
2351                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2352    
2353      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1906  osm_gps_map_class_init (OsmGpsMapClass * Line 2360  osm_gps_map_class_init (OsmGpsMapClass *
2360                                                         20,                                                         20,
2361                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2362    
2363        g_object_class_install_property (object_class,
2364                                         PROP_MAP_SOURCE,
2365                                         g_param_spec_int ("map-source",
2366                                                           "map source",
2367                                                           "map source ID",
2368                                                           -1,           /* minimum property value */
2369                                                           G_MAXINT,    /* maximum property value */
2370                                                           -1,
2371                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2372    
2373        g_object_class_install_property (object_class,
2374                                         PROP_IMAGE_FORMAT,
2375                                         g_param_spec_string ("image-format",
2376                                                              "image format",
2377                                                              "map source tile repository image format (jpg, png)",
2378                                                              OSM_IMAGE_FORMAT,
2379                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2380    }
2381    
2382    const char*
2383    osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source)
2384    {
2385        switch(source)
2386        {
2387            case OSM_GPS_MAP_SOURCE_NULL:
2388                return "None";
2389            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2390                return "OpenStreetMap";
2391            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2392                return "OpenStreetMap Renderer";
2393            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2394                return "OpenAerialMap";
2395            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2396                return "Maps-For-Free";
2397            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2398                return "Google Maps";
2399            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2400                return "Google Satellite";
2401            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2402                return "Google Hybrid";
2403            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2404                return "Virtual Earth";
2405            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2406                return "Virtual Earth Satellite";
2407            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2408                return "Virtual Earth Hybrid";
2409            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2410                return "Yahoo Maps";
2411            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2412                return "Yahoo Satellite";
2413            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2414                return "Yahoo Hybrid";
2415            default:
2416                return NULL;
2417        }
2418        return NULL;
2419    }
2420    
2421    //http://www.internettablettalk.com/forums/showthread.php?t=5209
2422    //https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup
2423    //http://www.ponies.me.uk/maps/GoogleTileUtils.java
2424    //http://www.mgmaps.com/cache/MapTileCacher.perl
2425    const char*
2426    osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source)
2427    {
2428        switch(source)
2429        {
2430            case OSM_GPS_MAP_SOURCE_NULL:
2431                return "none://";
2432            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2433                return OSM_REPO_URI;
2434            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2435                return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";
2436            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2437                return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg";
2438            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2439                return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";
2440            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2441                return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z";
2442            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2443                return "http://khm#R.google.com/kh?n=404&v=3&t=#Q";
2444            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2445                return NULL; /* No longer working  "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */
2446            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2447                return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50";
2448            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2449                return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50";
2450            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2451                return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50";
2452            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2453            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2454            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2455                /* TODO: Implement signed Y, aka U
2456                 * http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d
2457                 *  x = tilex,
2458                 *  y = (1 << (MAX_ZOOM - zoom)) - tiley - 1,
2459                 *  z = zoom - (MAX_ZOOM - 17));
2460                 */
2461                return NULL;
2462            default:
2463                return NULL;
2464        }
2465        return NULL;
2466    }
2467    
2468    const char *
2469    osm_gps_map_source_get_image_format(OsmGpsMapSource_t source)
2470    {
2471        switch(source) {
2472            case OSM_GPS_MAP_SOURCE_NULL:
2473            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2474            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2475                return "png";
2476            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2477            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2478            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2479            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2480            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2481            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2482            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2483            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2484            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2485            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2486            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2487                return "jpg";
2488            default:
2489                return "bin";
2490        }
2491        return "bin";
2492    }
2493    
2494    
2495    int
2496    osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source)
2497    {
2498        return 1;
2499    }
2500    
2501    int
2502    osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source)
2503    {
2504        switch(source) {
2505            case OSM_GPS_MAP_SOURCE_NULL:
2506                return 18;
2507            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2508                return OSM_MAX_ZOOM;
2509            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2510            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2511            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2512            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2513            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2514            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2515            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2516            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2517            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2518            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2519                return 17;
2520            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2521                return 11;
2522            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2523                return 18;
2524            default:
2525                return 17;
2526        }
2527        return 17;
2528  }  }
2529    
2530  void  void
# Line 1938  osm_gps_map_download_maps (OsmGpsMap *ma Line 2557  osm_gps_map_download_maps (OsmGpsMap *ma
2557                  for(j=y1; j<=y2; j++)                  for(j=y1; j<=y2; j++)
2558                  {                  {
2559                      // x = i, y = j                      // x = i, y = j
2560                      filename = g_strdup_printf("%s/%u/%u/%u.png", priv->cache_dir, zoom, i, j);                      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
2561                      if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS))                                      priv->cache_dir, G_DIR_SEPARATOR,
2562                                        zoom, G_DIR_SEPARATOR,
2563                                        i, G_DIR_SEPARATOR,
2564                                        j,
2565                                        priv->image_format);
2566                        if (!g_file_test(filename, G_FILE_TEST_EXISTS))
2567                      {                      {
2568                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);
2569                          num_tiles++;                          num_tiles++;
# Line 2001  int Line 2625  int
2625  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)
2626  {  {
2627      int zoom_old;      int zoom_old;
2628      double factor = 1.0;      double factor = 0.0;
2629      int width_center, height_center;      int width_center, height_center;
2630      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
2631    
# Line 2072  osm_gps_map_add_image (OsmGpsMap *map, f Line 2696  osm_gps_map_add_image (OsmGpsMap *map, f
2696          //cache w/h for speed, and add image to list          //cache w/h for speed, and add image to list
2697          im = g_new0(image_t,1);          im = g_new0(image_t,1);
2698          im->w = gdk_pixbuf_get_width(image);          im->w = gdk_pixbuf_get_width(image);
2699          im->h = gdk_pixbuf_get_width(image);          im->h = gdk_pixbuf_get_height(image);
2700          im->pt.rlat = deg2rad(latitude);          im->pt.rlat = deg2rad(latitude);
2701          im->pt.rlon = deg2rad(longitude);          im->pt.rlon = deg2rad(longitude);
2702    
# Line 2085  osm_gps_map_add_image (OsmGpsMap *map, f Line 2709  osm_gps_map_add_image (OsmGpsMap *map, f
2709      }      }
2710  }  }
2711    
2712  void  gboolean
2713  osm_gps_map_clear_images (OsmGpsMap *map)  osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image)
2714  {  {
2715      g_return_if_fail (OSM_IS_GPS_MAP (map));      OsmGpsMapPrivate *priv = map->priv;
2716        if (priv->images) {
2717      osm_gps_map_free_images(map);          GSList *list;
2718      osm_gps_map_map_redraw_idle(map);          for(list = priv->images; list != NULL; list = list->next)
2719            {
2720                image_t *im = list->data;
2721                    if (im->image == image)
2722                    {
2723                            priv->images = g_slist_remove_link(priv->images, list);
2724                            g_object_unref(im->image);
2725                            g_free(im);
2726                            osm_gps_map_map_redraw_idle(map);
2727                            return TRUE;
2728                    }
2729            }
2730        }
2731        return FALSE;
2732  }  }
2733    
2734  void  void
2735  osm_gps_map_osd_speed (OsmGpsMap *map, float speed)  osm_gps_map_clear_images (OsmGpsMap *map)
2736  {  {
     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;  
   
2737      g_return_if_fail (OSM_IS_GPS_MAP (map));      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);  
2738    
2739      color.red = (0 > 50) ? 0xffff : 0;      osm_gps_map_free_images(map);
2740      color.green = 0;      osm_gps_map_map_redraw_idle(map);
     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);  
2741  }  }
2742    
2743  void  void
# Line 2276  osm_gps_map_scroll (OsmGpsMap *map, gint Line 2861  osm_gps_map_scroll (OsmGpsMap *map, gint
2861      osm_gps_map_map_redraw_idle (map);      osm_gps_map_map_redraw_idle (map);
2862  }  }
2863    
2864    float
2865    osm_gps_map_get_scale(OsmGpsMap *map)
2866    {
2867        OsmGpsMapPrivate *priv;
2868    
2869        g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN);
2870        priv = map->priv;
2871    
2872        return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);
2873    }
2874    
2875    #ifdef ENABLE_BALLOON
2876    void
2877    osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
2878                              OsmGpsMapBalloonCallback cb, gpointer data)
2879    {
2880        OsmGpsMapPrivate *priv;
2881    
2882        /* remove and previously installed balloon */
2883        osm_gps_map_clear_balloon (map);
2884    
2885        g_return_if_fail (OSM_IS_GPS_MAP (map));
2886        priv = map->priv;
2887    
2888        priv->balloon.coo->rlat = deg2rad(latitude);
2889        priv->balloon.coo->rlon = deg2rad(longitude);
2890        priv->balloon.valid = TRUE;
2891    
2892        priv->balloon.cb = cb;
2893        priv->balloon.data = data;
2894    
2895        // this redraws the map
2896        osm_gps_map_map_redraw_idle(map);
2897    }
2898    
2899    void
2900    osm_gps_map_clear_balloon (OsmGpsMap *map)
2901    {
2902        OsmGpsMapPrivate *priv;
2903    
2904        g_return_if_fail (OSM_IS_GPS_MAP (map));
2905        priv = map->priv;
2906    
2907        priv->balloon.valid = FALSE;
2908    
2909        osm_gps_map_map_redraw_idle(map);
2910    }
2911    #endif
2912    
2913    #ifdef ENABLE_OSD
2914    
2915    void
2916    osm_gps_map_redraw (OsmGpsMap *map)
2917    {
2918        osm_gps_map_map_redraw_idle(map);
2919    }
2920    
2921    osm_gps_map_osd_t *osm_gps_map_osd_get(OsmGpsMap *map) {
2922        g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL);
2923        return map->priv->osd;
2924    }
2925    
2926    void osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd) {
2927        OsmGpsMapPrivate *priv;
2928    
2929        g_return_if_fail (OSM_IS_GPS_MAP (map));
2930    
2931        priv = map->priv;
2932        g_return_if_fail (!priv->osd);
2933    
2934        priv->osd = osd;
2935    }
2936    
2937    #endif

Legend:
Removed from v.32  
changed lines
  Added in v.75