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

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

revision 63 by harbaum, Wed Aug 19 12:35:25 2009 UTC revision 69 by harbaum, Thu Aug 20 18:54:06 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
114      struct {      struct {
115          GdkPixmap *backup;          GdkPixmap *backup;
116            cairo_surface_t *overlay;
117          gint backup_x, backup_y;          gint backup_x, backup_y;
118          //        GdkPixbuf *pixbuf;          OsmGpsMapOsdGpsCallback cb;
119            gpointer data;
120      } osd;      } osd;
121  #endif  #endif
122    
# Line 651  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 655  osm_gps_map_draw_gps_point (OsmGpsMap *m
655      }      }
656  }  }
657    
658    #ifdef ENABLE_BALLOON
659  /* most visual effects are hardcoded by now, but may be made */  /* most visual effects are hardcoded by now, but may be made */
660  /* available via properties later */  /* available via properties later */
661    #ifndef BALLOON_AREA_WIDTH
662  #define BALLOON_AREA_WIDTH           290  #define BALLOON_AREA_WIDTH           290
663    #endif
664    #ifndef BALLOON_AREA_HEIGHT
665  #define BALLOON_AREA_HEIGHT           75  #define BALLOON_AREA_HEIGHT           75
666    #endif
667    #ifndef BALLOON_CORNER_RADIUS
668    #define BALLOON_CORNER_RADIUS         10
669    #endif
670    
671  #define BALLOON_CORNER_RADIUS         20  #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
 #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/4)  
672  #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)  #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
673  #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)  #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
674  #define BALLOON_TRANSPARENCY         0.8  #define BALLOON_TRANSPARENCY         0.8
675  #define POINTER_HEIGHT                20  #define POINTER_HEIGHT                20
676  #define POINTER_FOOT_WIDTH            20  #define POINTER_FOOT_WIDTH            20
677  #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)  #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
678  #define BALLOON_SHADOW                5  #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
679  #define BALLOON_SHADOW_TRANSPARENCY  0.2  #define BALLOON_SHADOW_TRANSPARENCY  0.2
680    
681  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS/3)  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
682    
683    
684  /* 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 677  osm_gps_map_draw_balloon_shape (cairo_t Line 688  osm_gps_map_draw_balloon_shape (cairo_t
688         gboolean bottom, int px, int py, int px0, int px1) {         gboolean bottom, int px, int py, int px0, int px1) {
689    
690      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
691      cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);      cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
692                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
693      if(!bottom) {      if(!bottom) {
694          /* insert top pointer */          /* insert top pointer */
695          cairo_line_to (cr, px1, y0);          cairo_line_to (cr, px1, y0);
# Line 686  osm_gps_map_draw_balloon_shape (cairo_t Line 698  osm_gps_map_draw_balloon_shape (cairo_t
698      }      }
699    
700      cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);      cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
701      cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS);      cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
702                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
703      cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);      cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
704      cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);      cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
705                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
706      if(bottom) {      if(bottom) {
707          /* insert bottom pointer */          /* insert bottom pointer */
708          cairo_line_to (cr, px0, y1);          cairo_line_to (cr, px0, y1);
# Line 697  osm_gps_map_draw_balloon_shape (cairo_t Line 711  osm_gps_map_draw_balloon_shape (cairo_t
711      }      }
712    
713      cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);      cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
714      cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS);      cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
715                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
716    
717      cairo_close_path (cr);      cairo_close_path (cr);
718  }  }
# Line 788  osm_gps_map_draw_balloon_int (OsmGpsMap Line 803  osm_gps_map_draw_balloon_int (OsmGpsMap
803          cairo_stroke(cr);          cairo_stroke(cr);
804    
805          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
806          cairo_set_line_width (cr, 3);          cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);
807          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
808          cairo_move_to (cr, cx - crad/2, cy - crad/2);          cairo_move_to (cr, cx - crad/2, cy - crad/2);
809          cairo_line_to (cr, cx + crad/2, cy + crad/2);          cairo_line_to (cr, cx + crad/2, cy + crad/2);
# Line 850  osm_gps_map_in_balloon(OsmGpsMapPrivate Line 865  osm_gps_map_in_balloon(OsmGpsMapPrivate
865              (y > priv->balloon.rect.y) &&              (y > priv->balloon.rect.y) &&
866              (y < priv->balloon.rect.y + priv->balloon.rect.h));              (y < priv->balloon.rect.y + priv->balloon.rect.h));
867  }  }
868    #endif // ENABLE_BALLOON
869    
870  static void  static void
871  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 1412  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1428  osm_gps_map_purge_cache (OsmGpsMap *map)
1428  #define OSD_X      (10)  #define OSD_X      (10)
1429  #define OSD_Y      (10)  #define OSD_Y      (10)
1430    
1431  #define OSD_COLOR  0.5, 0.5, 1  #define OSD_COLOR            0.5, 0.5, 1
1432    #define OSD_COLOR_DISABLED   0.8, 0.8, 0.8
1433    
1434  /* parameters of the direction shape */  /* parameters of the direction shape */
1435  #define D_RAD  (20)         // diameter of dpad  #ifndef OSM_GPS_MAP_OSD_DIAMETER
1436    #define D_RAD  (30)         // diameter of dpad
1437    #else
1438    #define D_RAD  (OSM_GPS_MAP_OSD_DIAMETER)
1439    #endif
1440  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center
1441  #define D_LEN  (D_RAD/4)    // length of arrow  #define D_LEN  (D_RAD/4)    // length of arrow
1442  #define D_WID  (D_LEN)      // width of arrow  #define D_WID  (D_LEN)      // width of arrow
1443    
1444  /* parameters of the "zoom" pad */  /* parameters of the "zoom" pad */
1445  #define Z_STEP   (-D_RAD/8) // distance between dpad and zoom  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom
1446  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
1447    
1448  /* shadow also depends on control size */  /* shadow also depends on control size */
1449  #define OSD_SHADOW (D_RAD/8)  #define OSD_SHADOW (D_RAD/6)
1450    
1451  /* total width and height of controls incl. shadow */  /* total width and height of controls incl. shadow */
1452  #define OSD_W    (2*D_RAD + OSD_SHADOW)  #define OSD_W    (2*D_RAD + OSD_SHADOW)
# Line 1455  osm_gps_map_osd_dpad_shape(cairo_t *cr, Line 1476  osm_gps_map_osd_dpad_shape(cairo_t *cr,
1476      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
1477  }  }
1478    
 typedef enum {  
     OSD_NONE = 0,  
     OSD_BG,  
     OSD_UP,  
     OSD_DOWN,  
     OSD_LEFT,  
     OSD_RIGHT,  
     OSD_IN,  
     OSD_OUT,  
     OSD_GPS  
 } osd_button_t;  
   
1479  static gboolean  static gboolean
1480  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
1481  {  {
# Line 1485  osm_gps_map_osd_check_dpad(gint x, gint Line 1494  osm_gps_map_osd_check_dpad(gint x, gint
1494          y -= (OSD_Y + D_RAD);          y -= (OSD_Y + D_RAD);
1495    
1496          /* check for dpad center goes here! */          /* check for dpad center goes here! */
1497          if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD/3))          if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))
1498              return OSD_GPS;              return OSD_GPS;
1499    
1500          if( y < 0 && abs(x) < abs(y))          if( y < 0 && abs(x) < abs(y))
# Line 1508  osm_gps_map_osd_check_dpad(gint x, gint Line 1517  osm_gps_map_osd_check_dpad(gint x, gint
1517  /* check whether x/y is within the zoom pads */  /* check whether x/y is within the zoom pads */
1518  static osd_button_t  static osd_button_t
1519  osm_gps_map_osd_check_zoom(gint x, gint y) {  osm_gps_map_osd_check_zoom(gint x, gint y) {
1520      if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < Z_BOT) {      if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) {
1521    
1522          /* within circle around (-) label */          /* within circle around (-) label */
1523          if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))          if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))
# Line 1530  osm_gps_map_osd_check_zoom(gint x, gint Line 1539  osm_gps_map_osd_check_zoom(gint x, gint
1539      return OSD_NONE;      return OSD_NONE;
1540  }  }
1541    
1542  static osd_button_t  osd_button_t
1543  osm_gps_map_osd_check(gint x, gint y) {  osm_gps_map_osd_check(gint x, gint y) {
1544      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
1545    
# Line 1538  osm_gps_map_osd_check(gint x, gint y) { Line 1547  osm_gps_map_osd_check(gint x, gint y) {
1547      /* this is just to avoid an unnecessary detailed test */      /* this is just to avoid an unnecessary detailed test */
1548      if(x > OSD_X && x < OSD_X + OSD_W &&      if(x > OSD_X && x < OSD_X + OSD_W &&
1549         y > OSD_Y && y < OSD_Y + OSD_H) {         y > OSD_Y && y < OSD_Y + OSD_H) {
   
1550          but = osm_gps_map_osd_check_dpad(x, y);          but = osm_gps_map_osd_check_dpad(x, y);
1551    
1552          if(but == OSD_NONE)          if(but == OSD_NONE)
# Line 1629  osm_gps_map_osd_zoom_labels(cairo_t *cr, Line 1637  osm_gps_map_osd_zoom_labels(cairo_t *cr,
1637  }  }
1638    
1639  static void  static void
1640  osm_gps_map_osd_labels(cairo_t *cr, gint width) {  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {
1641      cairo_set_source_rgb (cr, OSD_COLOR);      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
1642        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
1643      cairo_set_line_width (cr, width);      cairo_set_line_width (cr, width);
1644      cairo_stroke (cr);      cairo_stroke (cr);
1645  }  }
1646    
1647  static void  static void
1648  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width) {  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
1649      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
1650      cairo_set_line_width (cr, width);      cairo_set_line_width (cr, width);
1651      cairo_stroke (cr);      cairo_stroke (cr);
1652  }  }
1653    
1654  static void  static void
1655  osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)  osm_gps_map_osd_render(OsmGpsMapPrivate *priv) {
 {  
     OsmGpsMapPrivate *priv = map->priv;  
   
     /* backup previous contents */  
     if(!priv->osd.backup)  
         priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -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-1, y-1, 0, 0, OSD_W+2, OSD_H+2);  
     priv->osd.backup_x = x-1;  
     priv->osd.backup_y = y-1;  
1656    
1657  #if 0      /* first fill with transparency */
1658      /* create pixbuf for osd */      cairo_t *cr = cairo_create(priv->osd.overlay);
     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);  
1659      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1660      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1661      cairo_paint(cr);      cairo_paint(cr);
     cairo_destroy(cr);  
     }  
 #endif  
   
1662    
1663  #ifdef USE_CAIRO      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
     //    cairo_t *cr = cairo_create(surface);  
     cairo_t *cr = gdk_cairo_create(priv->pixmap);  
1664    
1665      /* --------- draw zoom and dpad shape shadow ----------- */      /* --------- draw zoom and dpad shape shadow ----------- */
1666        gint x = 0, y = 0;
1667    
1668      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1669      osm_gps_map_osd_shape_shadow(cr);      osm_gps_map_osd_shape_shadow(cr);
# Line 1702  osm_gps_map_osd_draw_controls (OsmGpsMap Line 1681  osm_gps_map_osd_draw_controls (OsmGpsMap
1681    
1682      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1683      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1684      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3);      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);
1685      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1686      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6);      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL);
1687    
1688      osm_gps_map_osd_zoom_labels(cr, x, y);      osm_gps_map_osd_zoom_labels(cr, x, y);
1689      osm_gps_map_osd_dpad_labels(cr, x, y);      osm_gps_map_osd_dpad_labels(cr, x, y);
1690      osm_gps_map_osd_labels(cr, Z_RAD/3);      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);
1691      osm_gps_map_osd_dpad_gps(cr, x, y);      osm_gps_map_osd_dpad_gps(cr, x, y);
1692      osm_gps_map_osd_labels(cr, Z_RAD/6);      osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL);
1693    
1694      cairo_destroy(cr);      cairo_destroy(cr);
1695    }
1696    
1697    static void
1698    osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)
1699    {
1700        OsmGpsMapPrivate *priv = map->priv;
1701    
1702        /* backup previous contents */
1703        if(!priv->osd.backup)
1704            priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);
1705    
1706        gint x = OSD_X + EXTRA_BORDER + xoffset;
1707        gint y = OSD_Y + EXTRA_BORDER + yoffset;
1708    
1709        /* create backup of background */
1710        gdk_draw_drawable(priv->osd.backup,
1711            GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1712                          priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);
1713    
1714        priv->osd.backup_x = x-1;
1715        priv->osd.backup_y = y-1;
1716    
1717    
1718    #ifdef USE_CAIRO
1719        /* OSD itself uses some off-screen rendering, so check if the */
1720        /* offscreen buffer is present and create it if not */
1721        if(!priv->osd.overlay) {
1722            /* create overlay ... */
1723            priv->osd.overlay =
1724                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);
1725            /* ... and render it */
1726            osm_gps_map_osd_render(priv);
1727        }
1728    
1729        // now draw this onto the original context
1730        cairo_t *cr = gdk_cairo_create(priv->pixmap);
1731        cairo_set_source_surface(cr, priv->osd.overlay, x, y);
1732        cairo_paint(cr);
1733        cairo_destroy(cr);
1734    
1735  #else  #else
1736  #warning "OSD control display lacks a non-cairo implementation!"  #warning "OSD control display lacks a non-cairo implementation!"
1737  #endif  #endif
# Line 1766  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1784  osm_gps_map_map_redraw (OsmGpsMap *map)
1784      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1785      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1786      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1787    #ifdef ENABLE_BALLOON
1788      osm_gps_map_draw_balloon_int(map);      osm_gps_map_draw_balloon_int(map);
1789    #endif
1790  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1791      osm_gps_map_osd_draw_controls(map, 0, 0);      osm_gps_map_osd_draw_controls(map, 0, 0);
1792  #endif  #endif
# Line 1801  osm_gps_map_init (OsmGpsMap *object) Line 1821  osm_gps_map_init (OsmGpsMap *object)
1821      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1822      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1823    
1824    #ifdef ENABLE_BALLOON
1825      priv->balloon.coo = g_new0(coord_t, 1);      priv->balloon.coo = g_new0(coord_t, 1);
1826      priv->balloon.valid = FALSE;      priv->balloon.valid = FALSE;
1827      priv->balloon.cb = NULL;      priv->balloon.cb = NULL;
1828    #endif
1829    
1830  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1831      priv->osd.backup = NULL;      priv->osd.backup = NULL;
1832        priv->osd.overlay = NULL;
1833        priv->osd.cb = NULL;
1834  #endif  #endif
1835    
1836      priv->tracks = NULL;      priv->tracks = NULL;
# Line 1967  osm_gps_map_dispose (GObject *object) Line 1991  osm_gps_map_dispose (GObject *object)
1991          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1992    
1993      g_free(priv->gps);      g_free(priv->gps);
1994    
1995    #ifdef ENABLE_BALLOON
1996      g_free(priv->balloon.coo);      g_free(priv->balloon.coo);
1997    #endif
1998    
1999  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
2000      if (priv->osd.backup)      if (priv->osd.backup)
2001          g_object_unref(priv->osd.backup);          g_object_unref(priv->osd.backup);
2002    
2003        if (priv->osd.overlay)
2004             cairo_surface_destroy(priv->osd.overlay);
2005  #endif  #endif
2006    
2007      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
# Line 2189  osm_gps_map_button_press (GtkWidget *wid Line 2219  osm_gps_map_button_press (GtkWidget *wid
2219  {  {
2220      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2221    
2222    #ifdef ENABLE_BALLOON
2223      /* don't drag if the user clicked within the balloon */      /* don't drag if the user clicked within the balloon */
2224      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
2225                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2197  osm_gps_map_button_press (GtkWidget *wid Line 2228  osm_gps_map_button_press (GtkWidget *wid
2228          priv->drag_counter = -1;          priv->drag_counter = -1;
2229          return FALSE;          return FALSE;
2230      }      }
   
 #ifdef ENABLE_OSD  
     /* also don't drag on clicks into the control OSD */  
     if(osm_gps_map_osd_check(event->x, event->y) != OSD_NONE)  
     {  
         priv->drag_counter = -1;  
         return FALSE;  
     }  
2231  #endif  #endif
2232    
     priv->drag_counter = 0;  
     priv->drag_start_mouse_x = (int) event->x;  
     priv->drag_start_mouse_y = (int) event->y;  
     priv->drag_start_map_x = priv->map_x;  
     priv->drag_start_map_y = priv->map_y;  
   
     return FALSE;  
 }  
   
 static gboolean  
 osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event)  
 {  
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
   
2233  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
2234      /* released inside OSD control? */      #define SCROLL_STEP 10
2235    
2236        /* pressed inside OSD control? */
2237      osd_button_t but = osm_gps_map_osd_check(event->x, event->y);      osd_button_t but = osm_gps_map_osd_check(event->x, event->y);
2238      if(but != OSD_NONE)      if(but != OSD_NONE)
2239      {      {
2240            priv->drag_counter = -1;
2241    
2242          switch(but) {          switch(but) {
2243            case OSD_GPS:
2244                priv->osd.cb(priv->osd.data);
2245                break;
2246    
2247          case OSD_UP:          case OSD_UP:
2248              priv->map_y -= GTK_WIDGET(widget)->allocation.height/4;              priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2249              priv->center_coord_set = FALSE;              priv->center_coord_set = FALSE;
2250              break;              break;
2251    
2252          case OSD_DOWN:          case OSD_DOWN:
2253              priv->map_y += GTK_WIDGET(widget)->allocation.height/4;              priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2254              priv->center_coord_set = FALSE;              priv->center_coord_set = FALSE;
2255              break;              break;
2256    
2257          case OSD_LEFT:          case OSD_LEFT:
2258              priv->map_x -= GTK_WIDGET(widget)->allocation.width/4;              priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2259              priv->center_coord_set = FALSE;              priv->center_coord_set = FALSE;
2260              break;              break;
2261    
2262          case OSD_RIGHT:          case OSD_RIGHT:
2263              priv->map_x += GTK_WIDGET(widget)->allocation.width/4;              priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2264              priv->center_coord_set = FALSE;              priv->center_coord_set = FALSE;
2265              break;              break;
2266    
# Line 2265  osm_gps_map_button_release (GtkWidget *w Line 2282  osm_gps_map_button_release (GtkWidget *w
2282      }      }
2283  #endif  #endif
2284    
2285        priv->drag_counter = 0;
2286        priv->drag_start_mouse_x = (int) event->x;
2287        priv->drag_start_mouse_y = (int) event->y;
2288        priv->drag_start_map_x = priv->map_x;
2289        priv->drag_start_map_y = priv->map_y;
2290    
2291        return FALSE;
2292    }
2293    
2294    static gboolean
2295    osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event)
2296    {
2297        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2298    
2299    #ifdef ENABLE_BALLOON
2300      /* released inside the balloon? */      /* released inside the balloon? */
2301      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
2302                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2274  osm_gps_map_button_release (GtkWidget *w Line 2306  osm_gps_map_button_release (GtkWidget *w
2306               event->x - priv->balloon.rect.x + EXTRA_BORDER,               event->x - priv->balloon.rect.x + EXTRA_BORDER,
2307               event->y - priv->balloon.rect.y + EXTRA_BORDER);               event->y - priv->balloon.rect.y + EXTRA_BORDER);
2308      }      }
2309    #endif
2310    
2311      if (priv->dragging)      if (priv->dragging)
2312      {      {
# Line 2298  osm_gps_map_button_release (GtkWidget *w Line 2331  osm_gps_map_button_release (GtkWidget *w
2331  }  }
2332    
2333  static gboolean  static gboolean
2334    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);
2335    
2336    static gboolean
2337  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)
2338  {  {
2339      int x, y;      int x, y;
# Line 2326  osm_gps_map_motion_notify (GtkWidget *wi Line 2362  osm_gps_map_motion_notify (GtkWidget *wi
2362      if (priv->drag_counter < 6)      if (priv->drag_counter < 6)
2363          return FALSE;          return FALSE;
2364    
2365    #ifdef USE_MAEMO
2366        /* reduce update frequency on maemo to keep screen update fluid */
2367        static guint32 last_time = 0;
2368    
2369        if(event->time - last_time < 100) return FALSE;
2370        last_time = event->time;
2371    #endif
2372    
2373      priv->dragging = TRUE;      priv->dragging = TRUE;
2374    
2375      if (priv->map_auto_center)      if (priv->map_auto_center)
# Line 2344  osm_gps_map_motion_notify (GtkWidget *wi Line 2388  osm_gps_map_motion_notify (GtkWidget *wi
2388                                     -priv->drag_mouse_dy);                                     -priv->drag_mouse_dy);
2389  #endif  #endif
2390    
2391        osm_gps_map_expose (widget, NULL);
2392    
2393    
2394        return FALSE;
2395    }
2396    
2397    static gboolean
2398    osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event)
2399    {
2400        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2401    
2402        /* create pixmap */
2403        if (priv->pixmap)
2404            g_object_unref (priv->pixmap);
2405    
2406        priv->pixmap = gdk_pixmap_new (
2407                                       widget->window,
2408                                       widget->allocation.width + EXTRA_BORDER * 2,
2409                                       widget->allocation.height + EXTRA_BORDER * 2,
2410                                       -1);
2411    
2412        /* and gc, used for clipping (I think......) */
2413        if(priv->gc_map)
2414            g_object_unref(priv->gc_map);
2415    
2416        priv->gc_map = gdk_gc_new(priv->pixmap);
2417    
2418        osm_gps_map_map_redraw(OSM_GPS_MAP(widget));
2419    
2420        return FALSE;
2421    }
2422    
2423    static gboolean
2424    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event)
2425    {
2426        OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2427    
2428      gdk_draw_drawable (      gdk_draw_drawable (
2429                         widget->window,                         widget->window,
2430                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2431                         priv->pixmap,                         priv->pixmap,
2432                         0,0,                         0,0,
2433                         priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER,                         priv->drag_mouse_dx - EXTRA_BORDER,
2434                           priv->drag_mouse_dy - EXTRA_BORDER,
2435                         -1,-1);                         -1,-1);
2436    
2437      //Paint white outside of the map if dragging. Its less      //Paint white outside of the map if dragging. Its less
# Line 2393  osm_gps_map_motion_notify (GtkWidget *wi Line 2475  osm_gps_map_motion_notify (GtkWidget *wi
2475                              widget->allocation.width,                              widget->allocation.width,
2476                              -priv->drag_mouse_dy - EXTRA_BORDER);                              -priv->drag_mouse_dy - EXTRA_BORDER);
2477      }      }
2478    #if 0
2479      return FALSE;      if(!priv->dragging)
2480  }          gdk_draw_drawable (
   
 static gboolean  
 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);  
   
     gdk_draw_drawable (  
2481                         widget->window,                         widget->window,
2482                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2483                         priv->pixmap,                         priv->pixmap,
# Line 2436  osm_gps_map_expose (GtkWidget *widget, G Line 2485  osm_gps_map_expose (GtkWidget *widget, G
2485                         event->area.y + EXTRA_BORDER,                         event->area.y + EXTRA_BORDER,
2486                         event->area.x, event->area.y,                         event->area.x, event->area.y,
2487                         event->area.width, event->area.height);                         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);  
     }  
2488  #endif  #endif
   
2489      return FALSE;      return FALSE;
2490  }  }
2491    
# Line 2633  osm_gps_map_class_init (OsmGpsMapClass * Line 2671  osm_gps_map_class_init (OsmGpsMapClass *
2671                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2672                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2673                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2674                                                         5,                                                         10,
2675                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2676    
2677      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 3219  osm_gps_map_get_scale(OsmGpsMap *map) Line 3257  osm_gps_map_get_scale(OsmGpsMap *map)
3257      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);
3258  }  }
3259    
3260    #ifdef ENABLE_BALLOON
3261  void  void
3262  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
3263                            OsmGpsMapBalloonCallback cb, gpointer data)                            OsmGpsMapBalloonCallback cb, gpointer data)
# Line 3254  osm_gps_map_clear_balloon (OsmGpsMap *ma Line 3293  osm_gps_map_clear_balloon (OsmGpsMap *ma
3293    
3294      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
3295  }  }
3296    #endif
3297    
3298    #ifdef ENABLE_OSD
3299    void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) {
3300        OsmGpsMapPrivate *priv;
3301    
3302        g_return_if_fail (OSM_IS_GPS_MAP (map));
3303        priv = map->priv;
3304    
3305        priv->osd.cb = cb;
3306        priv->osd.data = data;
3307    
3308        /* this may have changed the state of the gps button */
3309        /* we thus re-render the overlay */
3310        osm_gps_map_osd_render(priv);
3311    
3312        osm_gps_map_map_redraw_idle(map);
3313    }
3314    #endif

Legend:
Removed from v.63  
changed lines
  Added in v.69