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

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

revision 61 by harbaum, Tue Aug 18 14:32:45 2009 UTC revision 75 by harbaum, Mon Aug 24 12:57:15 2009 UTC
# Line 98  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      //a balloon with additional info
103      struct {      struct {
104          coord_t *coo;          coord_t *coo;
# Line 106  struct _OsmGpsMapPrivate Line 107  struct _OsmGpsMapPrivate
107          OsmGpsMapBalloonCallback cb;          OsmGpsMapBalloonCallback cb;
108          gpointer data;          gpointer data;
109      } balloon;      } balloon;
110    #endif
111    
112  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
113      //the osd controls      //the osd controls (if present)
114      struct {      osm_gps_map_osd_t *osd;
115          GdkPixmap *backup;  #ifdef OSD_DOUBLE_BUFFER
116          gint backup_x, backup_y;      GdkPixmap *dbuf_pixmap;
   
   
         //        GdkPixbuf *pixbuf;  
     } osd;  
117  #endif  #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 653  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 652  osm_gps_map_draw_gps_point (OsmGpsMap *m
652      }      }
653  }  }
654    
655    #ifdef ENABLE_BALLOON
656  /* most visual effects are hardcoded by now, but may be made */  /* most visual effects are hardcoded by now, but may be made */
657  /* available via properties later */  /* available via properties later */
658    #ifndef BALLOON_AREA_WIDTH
659  #define BALLOON_AREA_WIDTH           290  #define BALLOON_AREA_WIDTH           290
660    #endif
661    #ifndef BALLOON_AREA_HEIGHT
662  #define BALLOON_AREA_HEIGHT           75  #define BALLOON_AREA_HEIGHT           75
663    #endif
664    #ifndef BALLOON_CORNER_RADIUS
665    #define BALLOON_CORNER_RADIUS         10
666    #endif
667    
668  #define BALLOON_CORNER_RADIUS         20  #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
 #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/4)  
669  #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)  #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
670  #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)  #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
671  #define BALLOON_TRANSPARENCY         0.8  #define BALLOON_TRANSPARENCY         0.8
672  #define POINTER_HEIGHT                20  #define POINTER_HEIGHT                20
673  #define POINTER_FOOT_WIDTH            20  #define POINTER_FOOT_WIDTH            20
674  #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)  #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
675  #define BALLOON_SHADOW                5  #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
676  #define BALLOON_SHADOW_TRANSPARENCY  0.2  #define BALLOON_SHADOW_TRANSPARENCY  0.2
677    
678  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS/3)  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
679    
680    
681  /* draw the bubble shape. this is used twice, once for the shape and once */  /* draw the bubble shape. this is used twice, once for the shape and once */
# Line 679  osm_gps_map_draw_balloon_shape (cairo_t Line 685  osm_gps_map_draw_balloon_shape (cairo_t
685         gboolean bottom, int px, int py, int px0, int px1) {         gboolean bottom, int px, int py, int px0, int px1) {
686    
687      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
688      cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);      cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
689                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
690      if(!bottom) {      if(!bottom) {
691          /* insert top pointer */          /* insert top pointer */
692          cairo_line_to (cr, px1, y0);          cairo_line_to (cr, px1, y0);
# Line 688  osm_gps_map_draw_balloon_shape (cairo_t Line 695  osm_gps_map_draw_balloon_shape (cairo_t
695      }      }
696    
697      cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);      cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
698      cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS);      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);      cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
701      cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);      cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
702                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
703      if(bottom) {      if(bottom) {
704          /* insert bottom pointer */          /* insert bottom pointer */
705          cairo_line_to (cr, px0, y1);          cairo_line_to (cr, px0, y1);
# Line 699  osm_gps_map_draw_balloon_shape (cairo_t Line 708  osm_gps_map_draw_balloon_shape (cairo_t
708      }      }
709    
710      cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);      cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
711      cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS);      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);      cairo_close_path (cr);
715  }  }
# Line 790  osm_gps_map_draw_balloon_int (OsmGpsMap Line 800  osm_gps_map_draw_balloon_int (OsmGpsMap
800          cairo_stroke(cr);          cairo_stroke(cr);
801    
802          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
803          cairo_set_line_width (cr, 3);          cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);
804          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
805          cairo_move_to (cr, cx - crad/2, cy - crad/2);          cairo_move_to (cr, cx - crad/2, cy - crad/2);
806          cairo_line_to (cr, cx + crad/2, cy + crad/2);          cairo_line_to (cr, cx + crad/2, cy + crad/2);
# Line 852  osm_gps_map_in_balloon(OsmGpsMapPrivate Line 862  osm_gps_map_in_balloon(OsmGpsMapPrivate
862              (y > priv->balloon.rect.y) &&              (y > priv->balloon.rect.y) &&
863              (y < priv->balloon.rect.y + priv->balloon.rect.h));              (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)
# Line 915  osm_gps_map_tile_download_complete (Soup Line 926  osm_gps_map_tile_download_complete (Soup
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 1407  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1420  osm_gps_map_purge_cache (OsmGpsMap *map)
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    
 #ifdef ENABLE_OSD  
 /* position and extent of bounding box */  
 #define OSD_X  (10)  
 #define OSD_Y  (10)  
 #define OSD_W  (80+5)  
 #define OSD_H  (120+5)  
   
 static void  
 osm_gps_map_draw_osd_controls (OsmGpsMap *map, gint xoffset, gint yoffset)  
 {  
     /* xyz */  
     OsmGpsMapPrivate *priv = map->priv;  
   
     /* backup previous contents */  
     if(!priv->osd.backup)  
         priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W, OSD_H, -1);  
   
     gint x = OSD_X + EXTRA_BORDER + xoffset;  
     gint y = OSD_Y + EXTRA_BORDER + yoffset;  
   
     /* create backup of background */  
     gdk_draw_drawable(priv->osd.backup,  
         GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],  
                       priv->pixmap, x, y, 0, 0, OSD_W, OSD_H);  
     priv->osd.backup_x = x;  
     priv->osd.backup_y = y;  
   
 #if 0  
     /* create pixbuf for osd */  
     if(!priv->osd.pixbuf)  
         priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,  
                                           TRUE, 8, OSD_W, OSD_H);  
     cairo_surface_t *surface =  
         cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);  
   
     /* fill with transparency */  
     {  
     cairo_t *cr = cairo_create(surface);  
     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);  
     cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);  
     cairo_paint(cr);  
     cairo_destroy(cr);  
     }  
 #endif  
   
   
 #ifdef USE_CAIRO  
     //    cairo_t *cr = cairo_create(surface);  
     cairo_t *cr = gdk_cairo_create(priv->pixmap);  
   
 #define RAD  40  
 #define TIP  35  
 #define LEN  15  
 #define WID  15  
   
     /* --------- the direction "pad" shape and shadow ----------- */  
     cairo_arc (cr, x+RAD+5, y+RAD+5, RAD, 0, 2 * M_PI);  
     cairo_set_source_rgba (cr, 0, 0, 0, 0.2);  
     cairo_fill (cr);  
     cairo_stroke (cr);  
   
     cairo_arc (cr, x+RAD, y+RAD, RAD, 0, 2 * M_PI);  
     cairo_set_source_rgb (cr, 1, 1, 1);  
     cairo_fill_preserve (cr);  
     cairo_set_source_rgb (cr, 0.6, 0.6, 1);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
   
     /* ---------- the zoom pad shape and shadow  -------------- */  
     cairo_move_to (cr, x,       y+2*RAD);  
     cairo_line_to (cr, x+2*RAD-10, y+2*RAD);  
     cairo_curve_to (cr, x+2*RAD, y+2*RAD,  
                         x+2*RAD, y+3*RAD,  
                         x+2*RAD-10, y+3*RAD);  
     cairo_close_path (cr);  
   
   
     cairo_set_source_rgba (cr, 1, 1, 1, 1.0);  
     cairo_fill (cr);  
     cairo_stroke (cr);  
   
   
     /* left arrow/triangle */  
     cairo_move_to (cr, x+RAD-TIP, y+RAD);  
     cairo_rel_line_to (cr, +LEN, -WID/2);  
     cairo_rel_line_to (cr,    0,   +WID);  
     cairo_rel_line_to (cr, -LEN, -WID/2);  
     cairo_close_path (cr);  
   
     /* right arrow/triangle */  
     cairo_move_to (cr, x+RAD+TIP, y+RAD);  
     cairo_rel_line_to (cr, -LEN, -WID/2);  
     cairo_rel_line_to (cr,    0,   +WID);  
     cairo_rel_line_to (cr, +LEN, -WID/2);  
     cairo_close_path (cr);  
   
     /* top arrow/triangle */  
     cairo_move_to (cr, x+RAD, y+RAD-TIP);  
     cairo_rel_line_to (cr, -WID/2, +LEN);  
     cairo_rel_line_to (cr,   +WID,    0);  
     cairo_rel_line_to (cr, -WID/2, -LEN);  
     cairo_close_path (cr);  
   
     /* bottom arrow/triangle */  
     cairo_move_to (cr, x+RAD, y+RAD+TIP);  
     cairo_rel_line_to (cr, -WID/2, -LEN);  
     cairo_rel_line_to (cr,   +WID,    0);  
     cairo_rel_line_to (cr, -WID/2, +LEN);  
     cairo_close_path (cr);  
   
     cairo_set_source_rgb (cr, 0.6, 0.6, 1);  
     cairo_fill_preserve (cr);  
     cairo_set_line_width (cr, 0);  
     cairo_set_source_rgba (cr, 0, 0, 0, 1);  
     cairo_stroke (cr);  
   
   
     cairo_destroy(cr);  
   
 #else  
 #warning "OSD control display lacks a non-cairo implementation!"  
 #endif  
 }  
   
 static void  
 osm_gps_map_osd_restore (OsmGpsMap *map)  
 {  
     OsmGpsMapPrivate *priv = map->priv;  
   
     /* restore backup of previous contents */  
     if(priv->osd.backup) {  
         /* create backup of background */  
         gdk_draw_drawable(priv->pixmap,  
             GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],  
                       priv->osd.backup, 0, 0,  
                       priv->osd.backup_x, priv->osd.backup_y, OSD_W, OSD_H);  
     }  
 }  
   
 #endif  
   
1423  static gboolean  static gboolean
1424  osm_gps_map_map_redraw (OsmGpsMap *map)  osm_gps_map_map_redraw (OsmGpsMap *map)
1425  {  {
# Line 1578  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);      osm_gps_map_draw_balloon_int(map);
 #ifdef ENABLE_OSD  
     osm_gps_map_draw_osd_controls(map, 0, 0);  
1455  #endif  #endif
1456    
1457      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
# Line 1613  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);      priv->balloon.coo = g_new0(coord_t, 1);
1489      priv->balloon.valid = FALSE;      priv->balloon.valid = FALSE;
1490      priv->balloon.cb = NULL;      priv->balloon.cb = NULL;
1491    #endif
1492    
1493  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1494      priv->osd.backup = NULL;      priv->osd = NULL;
1495  #endif  #endif
1496    
1497      priv->tracks = NULL;      priv->tracks = NULL;
# Line 1779  osm_gps_map_dispose (GObject *object) Line 1652  osm_gps_map_dispose (GObject *object)
1652          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1653    
1654      g_free(priv->gps);      g_free(priv->gps);
1655    
1656    #ifdef ENABLE_BALLOON
1657      g_free(priv->balloon.coo);      g_free(priv->balloon.coo);
1658    #endif
1659    
1660  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1661      if (priv->osd.backup)      if(priv->osd)
1662          g_object_unref(priv->osd.backup);          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  #endif
1669    
1670      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
# Line 2001  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 */      /* don't drag if the user clicked within the balloon */
1887      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
1888                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2009  osm_gps_map_button_press (GtkWidget *wid Line 1891  osm_gps_map_button_press (GtkWidget *wid
1891          priv->drag_counter = -1;          priv->drag_counter = -1;
1892          return FALSE;          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;
# Line 2024  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? */      /* released inside the balloon? */
1965      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
1966                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2032  osm_gps_map_button_release (GtkWidget *w Line 1969  osm_gps_map_button_release (GtkWidget *w
1969          osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),          osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
1970               event->x - priv->balloon.rect.x + EXTRA_BORDER,               event->x - priv->balloon.rect.x + EXTRA_BORDER,
1971               event->y - priv->balloon.rect.y + EXTRA_BORDER);               event->y - priv->balloon.rect.y + EXTRA_BORDER);
         return FALSE;  
1972      }      }
1973    #endif
     if (priv->drag_counter < 0)  
         return FALSE;  
1974    
1975      if (priv->dragging)      if (priv->dragging)
1976      {      {
# Line 2061  osm_gps_map_button_release (GtkWidget *w Line 1995  osm_gps_map_button_release (GtkWidget *w
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 2089  osm_gps_map_motion_notify (GtkWidget *wi Line 2026  osm_gps_map_motion_notify (GtkWidget *wi
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 2097  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        osm_gps_map_expose (widget, NULL);
2046    
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  #ifdef ENABLE_OSD
     /* undo OSD */  
     osm_gps_map_osd_restore (OSM_GPS_MAP(widget));  
2066    
2067      /* draw new OSD */  #ifdef OSD_DOUBLE_BUFFER
2068      osm_gps_map_draw_osd_controls (OSM_GPS_MAP(widget),      if (priv->dbuf_pixmap)
2069                                     -priv->drag_mouse_dx,          g_object_unref (priv->dbuf_pixmap);
2070                                     -priv->drag_mouse_dy);  
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  #endif
2104    
2105      gdk_draw_drawable (      gdk_draw_drawable (drawable,
                        widget->window,  
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 2128  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 2138  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 2148  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 2157  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);  
   
     priv->gc_map = gdk_gc_new(priv->pixmap);  
   
     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);  
2155    
2156      gdk_draw_drawable (  #ifdef OSD_DOUBLE_BUFFER
2157                         widget->window,      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,                         0,0,0,0,-1,-1);
                        event->area.y + EXTRA_BORDER,  
                        event->area.x, event->area.y,  
                        event->area.width, event->area.height);  
   
 #ifdef ENABLE_OSD_OVL  
     /* TODO: intersect with area */  
     if (priv->osd.pixbuf)  
     {  
         //        gdk_draw_drawable (widget->window,  
         //            widget->style->fg_gc[GTK_WIDGET_STATE (widget)],  
         //            priv->osd.pixbuf, 0, 0,  
         //            OSD_X, OSD_Y, OSD_W, OSD_H);  
     }  
2161  #endif  #endif
2162    
2163    #endif
2164    
2165      return FALSE;      return FALSE;
2166  }  }
2167    
# Line 2396  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 2790  osm_gps_map_clear_images (OsmGpsMap *map Line 2741  osm_gps_map_clear_images (OsmGpsMap *map
2741  }  }
2742    
2743  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  
2744  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)
2745  {  {
2746      int pixel_x, pixel_y;      int pixel_x, pixel_y;
# Line 2982  osm_gps_map_get_scale(OsmGpsMap *map) Line 2872  osm_gps_map_get_scale(OsmGpsMap *map)
2872      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);
2873  }  }
2874    
2875    #ifdef ENABLE_BALLOON
2876  void  void
2877  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
2878                            OsmGpsMapBalloonCallback cb, gpointer data)                            OsmGpsMapBalloonCallback cb, gpointer data)
# Line 3017  osm_gps_map_clear_balloon (OsmGpsMap *ma Line 2908  osm_gps_map_clear_balloon (OsmGpsMap *ma
2908    
2909      osm_gps_map_map_redraw_idle(map);      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.61  
changed lines
  Added in v.75