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 67 by harbaum, Thu Aug 20 07:09:29 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            OsmGpsMapOsdGpsCallback cb;
119            gpointer data;
         //        GdkPixbuf *pixbuf;  
120      } osd;      } osd;
121  #endif  #endif
122    
# Line 653  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 679  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 688  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 699  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 790  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 852  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 915  osm_gps_map_tile_download_complete (Soup Line 929  osm_gps_map_tile_download_complete (Soup
929              }              }
930              else              else
931              {              {
932                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
933                              dl->folder);
934                    perror("perror:");
935              }              }
936          }          }
937    
# Line 1409  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1425  osm_gps_map_purge_cache (OsmGpsMap *map)
1425    
1426  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1427  /* position and extent of bounding box */  /* position and extent of bounding box */
1428  #define OSD_X  (10)  #define OSD_X      (10)
1429  #define OSD_Y  (10)  #define OSD_Y      (10)
 #define OSD_W  (80+5)  
 #define OSD_H  (120+5)  
1430    
1431  static void  #define OSD_COLOR            0.5, 0.5, 1
1432  osm_gps_map_draw_osd_controls (OsmGpsMap *map, gint xoffset, gint yoffset)  #define OSD_COLOR_DISABLED   0.8, 0.8, 0.8
 {  
     /* xyz */  
     OsmGpsMapPrivate *priv = map->priv;  
1433    
1434      /* backup previous contents */  /* parameters of the direction shape */
1435      if(!priv->osd.backup)  #ifndef OSM_GPS_MAP_OSD_DIAMETER
1436          priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W, OSD_H, -1);  #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
1441    #define D_LEN  (D_RAD/4)    // length of arrow
1442    #define D_WID  (D_LEN)      // width of arrow
1443    
1444      gint x = OSD_X + EXTRA_BORDER + xoffset;  /* parameters of the "zoom" pad */
1445      gint y = OSD_Y + EXTRA_BORDER + yoffset;  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom
1446    #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
1447    
1448      /* create backup of background */  /* shadow also depends on control size */
1449      gdk_draw_drawable(priv->osd.backup,  #define OSD_SHADOW (D_RAD/6)
1450          GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],  
1451                        priv->pixmap, x, y, 0, 0, OSD_W, OSD_H);  /* total width and height of controls incl. shadow */
1452      priv->osd.backup_x = x;  #define OSD_W    (2*D_RAD + OSD_SHADOW)
1453      priv->osd.backup_y = y;  #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
1454    
1455  #if 0  #define OSD_LBL_SHADOW (OSD_SHADOW/2)
     /* 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);  
1456    
1457      /* fill with transparency */  #define Z_TOP    (2 * D_RAD + Z_STEP)
1458    #define Z_MID    (Z_TOP + Z_RAD)
1459    #define Z_BOT    (Z_MID + Z_RAD)
1460    #define Z_LEFT   (Z_RAD)
1461    #define Z_RIGHT  (2 * D_RAD - Z_RAD)
1462    
1463    /* create the cairo shape used for the zoom buttons */
1464    static void
1465    osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) {
1466        cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
1467        cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
1468        cairo_arc     (cr, x+Z_RIGHT,   y+Z_MID, Z_RAD, -M_PI/2,  M_PI/2);
1469        cairo_line_to (cr, x+Z_LEFT,    y+Z_BOT);
1470        cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);
1471    }
1472    
1473    /* create the cairo shape used for the dpad */
1474    static void
1475    osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) {
1476        cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
1477    }
1478    
1479    typedef enum {
1480        OSD_NONE = 0,
1481        OSD_BG,
1482        OSD_UP,
1483        OSD_DOWN,
1484        OSD_LEFT,
1485        OSD_RIGHT,
1486        OSD_IN,
1487        OSD_OUT,
1488        OSD_GPS
1489    } osd_button_t;
1490    
1491    static gboolean
1492    osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
1493    {
1494        return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
1495    }
1496    
1497    /* check whether x/y is within the dpad */
1498    static osd_button_t
1499    osm_gps_map_osd_check_dpad(gint x, gint y)
1500    {
1501        /* within entire dpad circle */
1502        if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD))
1503      {      {
1504      cairo_t *cr = cairo_create(surface);          /* convert into position relative to dpads centre */
1505      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);          x -= (OSD_X + D_RAD);
1506      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);          y -= (OSD_Y + D_RAD);
1507      cairo_paint(cr);  
1508      cairo_destroy(cr);          /* check for dpad center goes here! */
1509            if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))
1510                return OSD_GPS;
1511    
1512            if( y < 0 && abs(x) < abs(y))
1513                return OSD_UP;
1514    
1515            if( y > 0 && abs(x) < abs(y))
1516                return OSD_DOWN;
1517    
1518            if( x < 0 && abs(y) < abs(x))
1519                return OSD_LEFT;
1520    
1521            if( x > 0 && abs(y) < abs(x))
1522                return OSD_RIGHT;
1523    
1524            return OSD_BG;
1525      }      }
1526  #endif      return OSD_NONE;
1527    }
1528    
1529    /* check whether x/y is within the zoom pads */
1530    static osd_button_t
1531    osm_gps_map_osd_check_zoom(gint x, gint y) {
1532        if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) {
1533    
1534  #ifdef USE_CAIRO          /* within circle around (-) label */
1535      //    cairo_t *cr = cairo_create(surface);          if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))
1536      cairo_t *cr = gdk_cairo_create(priv->pixmap);              return OSD_OUT;
1537    
1538            /* between center of (-) button and center of entire zoom control area */
1539            if(x > OSD_LEFT && x < OSD_X + D_RAD)
1540                return OSD_OUT;
1541    
1542            /* within circle around (+) label */
1543            if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD))
1544                return OSD_IN;
1545    
1546            /* between center of (+) button and center of entire zoom control area */
1547            if(x < OSD_RIGHT && x > OSD_X + D_RAD)
1548                return OSD_IN;
1549        }
1550    
1551        return OSD_NONE;
1552    }
1553    
1554    static osd_button_t
1555    osm_gps_map_osd_check(gint x, gint y) {
1556        osd_button_t but = OSD_NONE;
1557    
1558  #define RAD  40      /* first do a rough test for the OSD area. */
1559  #define TIP  35      /* this is just to avoid an unnecessary detailed test */
1560  #define LEN  15      if(x > OSD_X && x < OSD_X + OSD_W &&
1561  #define WID  15         y > OSD_Y && y < OSD_Y + OSD_H) {
1562            but = osm_gps_map_osd_check_dpad(x, y);
1563    
1564      /* --------- the direction "pad" shape and shadow ----------- */          if(but == OSD_NONE)
1565      cairo_arc (cr, x+RAD+5, y+RAD+5, RAD, 0, 2 * M_PI);              but = osm_gps_map_osd_check_zoom(x, y);
1566        }
1567    
1568        return but;
1569    }
1570    
1571    static void
1572    osm_gps_map_osd_shape_shadow(cairo_t *cr) {
1573      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
1574      cairo_fill (cr);      cairo_fill (cr);
1575      cairo_stroke (cr);      cairo_stroke (cr);
1576    }
1577      cairo_arc (cr, x+RAD, y+RAD, RAD, 0, 2 * M_PI);  
1578    static void
1579    osm_gps_map_osd_shape(cairo_t *cr) {
1580      cairo_set_source_rgb (cr, 1, 1, 1);      cairo_set_source_rgb (cr, 1, 1, 1);
1581      cairo_fill_preserve (cr);      cairo_fill_preserve (cr);
1582      cairo_set_source_rgb (cr, 0.6, 0.6, 1);      cairo_set_source_rgb (cr, OSD_COLOR);
1583      cairo_set_line_width (cr, 1);      cairo_set_line_width (cr, 1);
1584      cairo_stroke (cr);      cairo_stroke (cr);
1585    }
1586    
1587      /* ---------- the zoom pad shape and shadow  -------------- */  static void
1588      cairo_move_to (cr, x,       y+2*RAD);  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {
1589      cairo_line_to (cr, x+2*RAD-10, y+2*RAD);      /* move reference to dpad center */
1590      cairo_curve_to (cr, x+2*RAD, y+2*RAD,      x += D_RAD;
1591                          x+2*RAD, y+3*RAD,      y += D_RAD;
1592                          x+2*RAD-10, y+3*RAD);  
1593      cairo_close_path (cr);      const static gint offset[][3][2] = {
1594            /* left arrow/triangle */
1595            { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } },
1596            /* right arrow/triangle */
1597            { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } },
1598            /* top arrow/triangle */
1599            { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } },
1600            /* bottom arrow/triangle */
1601            { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } }
1602        };
1603    
1604        int i;
1605        for(i=0;i<4;i++) {
1606            cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]);
1607            cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]);
1608            cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);
1609        }
1610    }
1611    
1612    /* draw the sattelite dish icon in the center of the dpad */
1613    #define GPS_V0  (D_RAD/8)
1614    #define GPS_V1  (D_RAD/10)
1615    #define GPS_V2  (D_RAD/5)
1616    
1617    /* draw a satellite receiver dish */
1618    static void
1619    osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {
1620        /* move reference to dpad center */
1621        x += D_RAD;
1622        y += D_RAD + GPS_V0;
1623    
1624        cairo_move_to (cr, x-GPS_V0, y+GPS_V0);
1625        cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);
1626        cairo_rel_line_to (cr, +GPS_V0, +GPS_V0);
1627        cairo_close_path (cr);
1628    
1629      cairo_set_source_rgba (cr, 1, 1, 1, 1.0);      cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);
1630      cairo_fill (cr);      cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);
1631      cairo_stroke (cr);      cairo_close_path (cr);
1632    
1633        x += GPS_V1;
1634        cairo_move_to (cr, x, y-GPS_V2);
1635        cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);
1636    }
1637    
1638      /* left arrow/triangle */  #define Z_LEN  (2*Z_RAD/3)
     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);  
1639    
1640      /* right arrow/triangle */  static void
1641      cairo_move_to (cr, x+RAD+TIP, y+RAD);  osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1642      cairo_rel_line_to (cr, -LEN, -WID/2);      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1643      cairo_rel_line_to (cr,    0,   +WID);      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
     cairo_rel_line_to (cr, +LEN, -WID/2);  
     cairo_close_path (cr);  
1644    
1645      /* top arrow/triangle */      cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);
1646      cairo_move_to (cr, x+RAD, y+RAD-TIP);      cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);
1647      cairo_rel_line_to (cr, -WID/2, +LEN);      cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);
1648      cairo_rel_line_to (cr,   +WID,    0);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1649      cairo_rel_line_to (cr, -WID/2, -LEN);  }
     cairo_close_path (cr);  
1650    
1651      /* bottom arrow/triangle */  static void
1652      cairo_move_to (cr, x+RAD, y+RAD+TIP);  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {
1653      cairo_rel_line_to (cr, -WID/2, -LEN);      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
1654      cairo_rel_line_to (cr,   +WID,    0);      else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
1655      cairo_rel_line_to (cr, -WID/2, +LEN);      cairo_set_line_width (cr, width);
1656      cairo_close_path (cr);      cairo_stroke (cr);
1657    }
1658    
1659      cairo_set_source_rgb (cr, 0.6, 0.6, 1);  static void
1660      cairo_fill_preserve (cr);  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
1661      cairo_set_line_width (cr, 0);      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
1662      cairo_set_source_rgba (cr, 0, 0, 0, 1);      cairo_set_line_width (cr, width);
1663      cairo_stroke (cr);      cairo_stroke (cr);
1664    }
1665    
1666    static void
1667    osm_gps_map_osd_render(OsmGpsMapPrivate *priv) {
1668    
1669        /* first fill with transparency */
1670        cairo_t *cr = cairo_create(priv->osd.overlay);
1671        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1672        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1673        cairo_paint(cr);
1674    
1675        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1676    
1677        /* --------- draw zoom and dpad shape shadow ----------- */
1678        gint x = 0, y = 0;
1679    
1680        osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1681        osm_gps_map_osd_shape_shadow(cr);
1682        osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1683        osm_gps_map_osd_shape_shadow(cr);
1684    
1685        /* --------- draw zoom and dpad shape ----------- */
1686    
1687        osm_gps_map_osd_zoom_shape(cr, x, y);
1688        osm_gps_map_osd_shape(cr);
1689        osm_gps_map_osd_dpad_shape(cr, x, y);
1690        osm_gps_map_osd_shape(cr);
1691    
1692        /* --------- draw zoom and dpad labels --------- */
1693    
1694        osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1695        osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1696        osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);
1697        osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1698        osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL);
1699    
1700        osm_gps_map_osd_zoom_labels(cr, x, y);
1701        osm_gps_map_osd_dpad_labels(cr, x, y);
1702        osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);
1703        osm_gps_map_osd_dpad_gps(cr, x, y);
1704        osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL);
1705    
1706      cairo_destroy(cr);      cairo_destroy(cr);
1707    }
1708    
1709    static void
1710    osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)
1711    {
1712        OsmGpsMapPrivate *priv = map->priv;
1713    
1714        /* backup previous contents */
1715        if(!priv->osd.backup)
1716            priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);
1717    
1718        gint x = OSD_X + EXTRA_BORDER + xoffset;
1719        gint y = OSD_Y + EXTRA_BORDER + yoffset;
1720    
1721        /* create backup of background */
1722        gdk_draw_drawable(priv->osd.backup,
1723            GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1724                          priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);
1725    
1726        priv->osd.backup_x = x-1;
1727        priv->osd.backup_y = y-1;
1728    
1729    
1730    #ifdef USE_CAIRO
1731        /* OSD itself uses some off-screen rendering, so check if the */
1732        /* offscreen buffer is present and create it if not */
1733        if(!priv->osd.overlay) {
1734            /* create overlay ... */
1735            priv->osd.overlay =
1736                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);
1737            /* ... and render it */
1738            osm_gps_map_osd_render(priv);
1739        }
1740    
1741        // now draw this onto the original context
1742        cairo_t *cr = gdk_cairo_create(priv->pixmap);
1743        cairo_set_source_surface(cr, priv->osd.overlay, x, y);
1744        cairo_paint(cr);
1745        cairo_destroy(cr);
1746    
1747  #else  #else
1748  #warning "OSD control display lacks a non-cairo implementation!"  #warning "OSD control display lacks a non-cairo implementation!"
1749  #endif  #endif
# Line 1542  osm_gps_map_osd_restore (OsmGpsMap *map) Line 1760  osm_gps_map_osd_restore (OsmGpsMap *map)
1760          gdk_draw_drawable(priv->pixmap,          gdk_draw_drawable(priv->pixmap,
1761              GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],              GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1762                        priv->osd.backup, 0, 0,                        priv->osd.backup, 0, 0,
1763                        priv->osd.backup_x, priv->osd.backup_y, OSD_W, OSD_H);                        priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2);
1764      }      }
1765  }  }
1766    
# Line 1578  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1796  osm_gps_map_map_redraw (OsmGpsMap *map)
1796      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1797      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1798      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1799    #ifdef ENABLE_BALLOON
1800      osm_gps_map_draw_balloon_int(map);      osm_gps_map_draw_balloon_int(map);
1801    #endif
1802  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1803      osm_gps_map_draw_osd_controls(map, 0, 0);      osm_gps_map_osd_draw_controls(map, 0, 0);
1804  #endif  #endif
1805    
1806      //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 1833  osm_gps_map_init (OsmGpsMap *object)
1833      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1834      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1835    
1836    #ifdef ENABLE_BALLOON
1837      priv->balloon.coo = g_new0(coord_t, 1);      priv->balloon.coo = g_new0(coord_t, 1);
1838      priv->balloon.valid = FALSE;      priv->balloon.valid = FALSE;
1839      priv->balloon.cb = NULL;      priv->balloon.cb = NULL;
1840    #endif
1841    
1842  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
1843      priv->osd.backup = NULL;      priv->osd.backup = NULL;
1844        priv->osd.overlay = NULL;
1845        priv->osd.cb = NULL;
1846  #endif  #endif
1847    
1848      priv->tracks = NULL;      priv->tracks = NULL;
# Line 1779  osm_gps_map_dispose (GObject *object) Line 2003  osm_gps_map_dispose (GObject *object)
2003          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
2004    
2005      g_free(priv->gps);      g_free(priv->gps);
2006    
2007    #ifdef ENABLE_BALLOON
2008      g_free(priv->balloon.coo);      g_free(priv->balloon.coo);
2009    #endif
2010    
2011  #ifdef ENABLE_OSD  #ifdef ENABLE_OSD
2012      if (priv->osd.backup)      if (priv->osd.backup)
2013          g_object_unref(priv->osd.backup);          g_object_unref(priv->osd.backup);
2014    
2015        if (priv->osd.overlay)
2016             cairo_surface_destroy(priv->osd.overlay);
2017  #endif  #endif
2018    
2019      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 2231  osm_gps_map_button_press (GtkWidget *wid
2231  {  {
2232      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2233    
2234    #ifdef ENABLE_BALLOON
2235      /* don't drag if the user clicked within the balloon */      /* don't drag if the user clicked within the balloon */
2236      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
2237                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2009  osm_gps_map_button_press (GtkWidget *wid Line 2240  osm_gps_map_button_press (GtkWidget *wid
2240          priv->drag_counter = -1;          priv->drag_counter = -1;
2241          return FALSE;          return FALSE;
2242      }      }
2243    #endif
2244    
2245    #ifdef ENABLE_OSD
2246        #define SCROLL_STEP 10
2247    
2248        /* pressed inside OSD control? */
2249        osd_button_t but = osm_gps_map_osd_check(event->x, event->y);
2250        if(but != OSD_NONE)
2251        {
2252            priv->drag_counter = -1;
2253    
2254            switch(but) {
2255            case OSD_GPS:
2256                priv->osd.cb(priv->osd.data);
2257                break;
2258    
2259            case OSD_UP:
2260                priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2261                priv->center_coord_set = FALSE;
2262                break;
2263    
2264            case OSD_DOWN:
2265                priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2266                priv->center_coord_set = FALSE;
2267                break;
2268    
2269            case OSD_LEFT:
2270                priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2271                priv->center_coord_set = FALSE;
2272                break;
2273    
2274            case OSD_RIGHT:
2275                priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2276                priv->center_coord_set = FALSE;
2277                break;
2278    
2279            case OSD_IN:
2280                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
2281                break;
2282    
2283            case OSD_OUT:
2284                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
2285                break;
2286    
2287            default:
2288                break;
2289            }
2290    
2291            osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
2292    
2293            return FALSE;
2294        }
2295    #endif
2296    
2297      priv->drag_counter = 0;      priv->drag_counter = 0;
2298      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 2308  osm_gps_map_button_release (GtkWidget *w
2308  {  {
2309      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2310    
2311    #ifdef ENABLE_BALLOON
2312      /* released inside the balloon? */      /* released inside the balloon? */
2313      if (osm_gps_map_in_balloon(priv,      if (osm_gps_map_in_balloon(priv,
2314                     event->x + EXTRA_BORDER,                     event->x + EXTRA_BORDER,
# Line 2032  osm_gps_map_button_release (GtkWidget *w Line 2317  osm_gps_map_button_release (GtkWidget *w
2317          osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),          osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
2318               event->x - priv->balloon.rect.x + EXTRA_BORDER,               event->x - priv->balloon.rect.x + EXTRA_BORDER,
2319               event->y - priv->balloon.rect.y + EXTRA_BORDER);               event->y - priv->balloon.rect.y + EXTRA_BORDER);
         return FALSE;  
2320      }      }
2321    #endif
     if (priv->drag_counter < 0)  
         return FALSE;  
2322    
2323      if (priv->dragging)      if (priv->dragging)
2324      {      {
# Line 2102  osm_gps_map_motion_notify (GtkWidget *wi Line 2384  osm_gps_map_motion_notify (GtkWidget *wi
2384      osm_gps_map_osd_restore (OSM_GPS_MAP(widget));      osm_gps_map_osd_restore (OSM_GPS_MAP(widget));
2385    
2386      /* draw new OSD */      /* draw new OSD */
2387      osm_gps_map_draw_osd_controls (OSM_GPS_MAP(widget),      osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget),
2388                                     -priv->drag_mouse_dx,                                     -priv->drag_mouse_dx,
2389                                     -priv->drag_mouse_dy);                                     -priv->drag_mouse_dy);
2390  #endif  #endif
# Line 2200  osm_gps_map_expose (GtkWidget *widget, G Line 2482  osm_gps_map_expose (GtkWidget *widget, G
2482                         event->area.x, event->area.y,                         event->area.x, event->area.y,
2483                         event->area.width, event->area.height);                         event->area.width, event->area.height);
2484    
 #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);  
     }  
 #endif  
   
2485      return FALSE;      return FALSE;
2486  }  }
2487    
# Line 2396  osm_gps_map_class_init (OsmGpsMapClass * Line 2667  osm_gps_map_class_init (OsmGpsMapClass *
2667                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2668                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2669                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2670                                                         5,                                                         10,
2671                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2672    
2673      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 2982  osm_gps_map_get_scale(OsmGpsMap *map) Line 3253  osm_gps_map_get_scale(OsmGpsMap *map)
3253      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);
3254  }  }
3255    
3256    #ifdef ENABLE_BALLOON
3257  void  void
3258  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
3259                            OsmGpsMapBalloonCallback cb, gpointer data)                            OsmGpsMapBalloonCallback cb, gpointer data)
# Line 3017  osm_gps_map_clear_balloon (OsmGpsMap *ma Line 3289  osm_gps_map_clear_balloon (OsmGpsMap *ma
3289    
3290      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
3291  }  }
3292    #endif
3293    
3294    #ifdef ENABLE_OSD
3295    void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) {
3296        OsmGpsMapPrivate *priv;
3297    
3298        g_return_if_fail (OSM_IS_GPS_MAP (map));
3299        priv = map->priv;
3300    
3301        priv->osd.cb = cb;
3302        priv->osd.data = data;
3303    
3304        /* this may have changed the state of the gps button */
3305        /* we thus re-render the overlay */
3306        osm_gps_map_osd_render(priv);
3307    
3308        osm_gps_map_map_redraw_idle(map);
3309    }
3310    #endif

Legend:
Removed from v.61  
changed lines
  Added in v.67