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

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

revision 57 by harbaum, Sun Aug 16 19:29:01 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      coord_t *balloon;      struct {
104      gboolean balloon_valid;          coord_t *coo;
105            gboolean valid;
106            OsmGpsMapRect_t rect;
107            OsmGpsMapBalloonCallback cb;
108            gpointer data;
109        } balloon;
110    #endif
111    
112    #ifdef ENABLE_OSD
113        //the osd controls
114        struct {
115            GdkPixmap *backup;
116            cairo_surface_t *overlay;
117            gint backup_x, backup_y;
118            OsmGpsMapOsdGpsCallback cb;
119            gpointer data;
120        } osd;
121    #endif
122    
123      //additional images or tracks added to the map      //additional images or tracks added to the map
124      GSList *tracks;      GSList *tracks;
# Line 637  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  #define BALLOON_CORNER_RADIUS         20  #ifndef BALLOON_AREA_WIDTH
662  #define BALLOON_WIDTH                150  #define BALLOON_AREA_WIDTH           290
663  #define BALLOON_HEIGHT                75  #endif
664    #ifndef BALLOON_AREA_HEIGHT
665    #define BALLOON_AREA_HEIGHT           75
666    #endif
667    #ifndef BALLOON_CORNER_RADIUS
668    #define BALLOON_CORNER_RADIUS         10
669    #endif
670    
671    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
672    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
673    #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)
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 */
685  /* for the shadow */  /* for the shadow */
686  static void  static void
# Line 656  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 bottom/left pointer */          /* insert top pointer */
695          cairo_line_to (cr, px1, y0);          cairo_line_to (cr, px1, y0);
696          cairo_line_to (cr, px, py);          cairo_line_to (cr, px, py);
697          cairo_line_to (cr, px0, y0);          cairo_line_to (cr, px0, y0);
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/left pointer */          /* insert bottom pointer */
708          cairo_line_to (cr, px0, y1);          cairo_line_to (cr, px0, y1);
709          cairo_line_to (cr, px, py);          cairo_line_to (cr, px, py);
710          cairo_line_to (cr, px1, y1);          cairo_line_to (cr, px1, y1);
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  }  }
719    
 /* http://cairographics.org/samples/ */  
720  static void  static void
721  osm_gps_map_draw_balloon_int (OsmGpsMap *map)  osm_gps_map_draw_balloon_int (OsmGpsMap *map)
722  {  {
723      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
724    
725      if (priv->balloon_valid) {      if (priv->balloon.valid) {
726    
727          /* ------- convert given coordinate into screen position --------- */          /* ------- convert given coordinate into screen position --------- */
728          int x0 = lon2pixel(priv->map_zoom, priv->balloon->rlon) -          int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -
729              priv->map_x + EXTRA_BORDER;              priv->map_x + EXTRA_BORDER;
730          int y0 = lat2pixel(priv->map_zoom, priv->balloon->rlat) -          int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -
731              priv->map_y + EXTRA_BORDER;              priv->map_y + EXTRA_BORDER;
732    
733          /* check position of this relative to screen center to determine */          /* check position of this relative to screen center to determine */
# Line 721  osm_gps_map_draw_balloon_int (OsmGpsMap Line 756  osm_gps_map_draw_balloon_int (OsmGpsMap
756          /* calculate bottom/right of box */          /* calculate bottom/right of box */
757          int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;          int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
758    
759            /* save balloon screen coordinates for later use */
760            priv->balloon.rect.x = x0 + BALLOON_BORDER;
761            priv->balloon.rect.y = y0 + BALLOON_BORDER;
762            priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
763            priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
764    
765  #ifdef USE_CAIRO  #ifdef USE_CAIRO
766          cairo_t *cr = gdk_cairo_create(priv->pixmap);          cairo_t *cr = gdk_cairo_create(priv->pixmap);
767    
# Line 750  osm_gps_map_draw_balloon_int (OsmGpsMap Line 791  osm_gps_map_draw_balloon_int (OsmGpsMap
791    
792          /* ---------- draw close button --------- */          /* ---------- draw close button --------- */
793    
794          int cx = x1 - BALLOON_CORNER_RADIUS*3/4;          int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;
795          int cy = y0 + BALLOON_CORNER_RADIUS*3/4;          int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;
796          int crad = BALLOON_CORNER_RADIUS/3;          int crad = CLOSE_BUTTON_RADIUS;
797    
798          cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);          cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
799          cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);          cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
800          cairo_fill_preserve (cr);          cairo_fill_preserve (cr);
801          cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);          cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
802          cairo_set_line_width (cr, 1);          cairo_set_line_width (cr, 2);
803          cairo_stroke(cr);          cairo_stroke(cr);
804    
         int cs = crad/2;  
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 - cs, cy - cs);          cairo_move_to (cr, cx - crad/2, cy - crad/2);
809          cairo_line_to (cr, cx + cs, cy + cs);          cairo_line_to (cr, cx + crad/2, cy + crad/2);
810          cairo_stroke (cr);          cairo_stroke (cr);
811          cairo_move_to (cr, cx + cs, cy - cs);          cairo_move_to (cr, cx + crad/2, cy - crad/2);
812          cairo_line_to (cr, cx - cs, cy + cs);          cairo_line_to (cr, cx - crad/2, cy + crad/2);
813          cairo_stroke (cr);          cairo_stroke (cr);
814    
815            if (priv->balloon.cb) {
816                /* clip in case application tries to draw in */
817                /* exceed of the balloon */
818                cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
819                                 priv->balloon.rect.w, priv->balloon.rect.h);
820                cairo_clip (cr);
821                cairo_new_path (cr);  /* current path is not
822                                         consumed by cairo_clip() */
823    
824                priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
825            }
826    
827            cairo_destroy(cr);
828    
829          gtk_widget_queue_draw_area (GTK_WIDGET(map),          gtk_widget_queue_draw_area (GTK_WIDGET(map),
830                                      x0, y0, BALLOON_WIDTH,                                      x0, y0, BALLOON_WIDTH,
831                                      BALLOON_HEIGHT + POINTER_HEIGHT);                                      BALLOON_HEIGHT + POINTER_HEIGHT);
# Line 782  osm_gps_map_draw_balloon_int (OsmGpsMap Line 835  osm_gps_map_draw_balloon_int (OsmGpsMap
835      }      }
836  }  }
837    
838    /* the user clicked into the balloons main area. handle this */
839    static void
840    osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)
841    {
842        OsmGpsMapPrivate *priv = map->priv;
843    
844        if (!priv->balloon.valid)
845            return;
846    
847        /* check if the close button was clicked */
848        if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&
849            (x < priv->balloon.rect.w) &&
850            (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {
851    
852            priv->balloon.valid = FALSE;
853            osm_gps_map_map_redraw_idle(map);
854        }
855    }
856    
857    /* return true if balloon is being displayed and if */
858    /* the given coordinate is within this balloon */
859    static gboolean
860    osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)
861    {
862        return (priv->balloon.valid &&
863                (x > priv->balloon.rect.x) &&
864                (x < priv->balloon.rect.x + priv->balloon.rect.w) &&
865                (y > priv->balloon.rect.y) &&
866                (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)
872  {  {
# Line 844  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 1336  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1423  osm_gps_map_purge_cache (OsmGpsMap *map)
1423     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);
1424  }  }
1425    
1426    #ifdef ENABLE_OSD
1427    /* position and extent of bounding box */
1428    #define OSD_X      (10)
1429    #define OSD_Y      (10)
1430    
1431    #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 */
1435    #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
1441    #define D_LEN  (D_RAD/4)    // length of arrow
1442    #define D_WID  (D_LEN)      // width of arrow
1443    
1444    /* parameters of the "zoom" pad */
1445    #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    /* shadow also depends on control size */
1449    #define OSD_SHADOW (D_RAD/6)
1450    
1451    /* total width and height of controls incl. shadow */
1452    #define OSD_W    (2*D_RAD + OSD_SHADOW)
1453    #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
1454    
1455    #define OSD_LBL_SHADOW (OSD_SHADOW/2)
1456    
1457    #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            /* convert into position relative to dpads centre */
1505            x -= (OSD_X + D_RAD);
1506            y -= (OSD_Y + D_RAD);
1507    
1508            /* 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        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            /* within circle around (-) label */
1535            if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))
1536                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        /* first do a rough test for the OSD area. */
1559        /* this is just to avoid an unnecessary detailed test */
1560        if(x > OSD_X && x < OSD_X + OSD_W &&
1561           y > OSD_Y && y < OSD_Y + OSD_H) {
1562            but = osm_gps_map_osd_check_dpad(x, y);
1563    
1564            if(but == OSD_NONE)
1565                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);
1574        cairo_fill (cr);
1575        cairo_stroke (cr);
1576    }
1577    
1578    static void
1579    osm_gps_map_osd_shape(cairo_t *cr) {
1580        cairo_set_source_rgb (cr, 1, 1, 1);
1581        cairo_fill_preserve (cr);
1582        cairo_set_source_rgb (cr, OSD_COLOR);
1583        cairo_set_line_width (cr, 1);
1584        cairo_stroke (cr);
1585    }
1586    
1587    static void
1588    osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {
1589        /* move reference to dpad center */
1590        x += D_RAD;
1591        y += D_RAD;
1592    
1593        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_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);
1630        cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);
1631        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    #define Z_LEN  (2*Z_RAD/3)
1639    
1640    static void
1641    osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1642        cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1643        cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
1644    
1645        cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);
1646        cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);
1647        cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);
1648        cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1649    }
1650    
1651    static void
1652    osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {
1653        if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
1654        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
1655        cairo_set_line_width (cr, width);
1656        cairo_stroke (cr);
1657    }
1658    
1659    static void
1660    osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
1661        cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
1662        cairo_set_line_width (cr, width);
1663        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);
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
1748    #warning "OSD control display lacks a non-cairo implementation!"
1749    #endif
1750    }
1751    
1752    static void
1753    osm_gps_map_osd_restore (OsmGpsMap *map)
1754    {
1755        OsmGpsMapPrivate *priv = map->priv;
1756    
1757        /* restore backup of previous contents */
1758        if(priv->osd.backup) {
1759            /* create backup of background */
1760            gdk_draw_drawable(priv->pixmap,
1761                GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1762                          priv->osd.backup, 0, 0,
1763                          priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2);
1764        }
1765    }
1766    
1767    #endif
1768    
1769  static gboolean  static gboolean
1770  osm_gps_map_map_redraw (OsmGpsMap *map)  osm_gps_map_map_redraw (OsmGpsMap *map)
1771  {  {
# Line 1366  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
1803        osm_gps_map_osd_draw_controls(map, 0, 0);
1804    #endif
1805    
1806      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1807      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1398  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      priv->balloon = g_new0(coord_t, 1);  #ifdef ENABLE_BALLOON
1837      priv->balloon_valid = FALSE;      priv->balloon.coo = g_new0(coord_t, 1);
1838        priv->balloon.valid = FALSE;
1839        priv->balloon.cb = NULL;
1840    #endif
1841    
1842    #ifdef ENABLE_OSD
1843        priv->osd.backup = NULL;
1844        priv->osd.overlay = NULL;
1845        priv->osd.cb = NULL;
1846    #endif
1847    
1848      priv->tracks = NULL;      priv->tracks = NULL;
1849      priv->images = NULL;      priv->images = NULL;
# Line 1559  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      g_free(priv->balloon);  
2007    #ifdef ENABLE_BALLOON
2008        g_free(priv->balloon.coo);
2009    #endif
2010    
2011    #ifdef ENABLE_OSD
2012        if (priv->osd.backup)
2013            g_object_unref(priv->osd.backup);
2014    
2015        if (priv->osd.overlay)
2016             cairo_surface_destroy(priv->osd.overlay);
2017    #endif
2018    
2019      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
2020  }  }
# Line 1776  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 */
2236        if (osm_gps_map_in_balloon(priv,
2237                       event->x + EXTRA_BORDER,
2238                       event->y + EXTRA_BORDER))
2239        {
2240            priv->drag_counter = -1;
2241            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;
2299      priv->drag_start_mouse_y = (int) event->y;      priv->drag_start_mouse_y = (int) event->y;
# Line 1790  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? */
2313        if (osm_gps_map_in_balloon(priv,
2314                       event->x + EXTRA_BORDER,
2315                       event->y + EXTRA_BORDER))
2316        {
2317            osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
2318                 event->x - priv->balloon.rect.x + EXTRA_BORDER,
2319                 event->y - priv->balloon.rect.y + EXTRA_BORDER);
2320        }
2321    #endif
2322    
2323      if (priv->dragging)      if (priv->dragging)
2324      {      {
2325          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1807  osm_gps_map_button_release (GtkWidget *w Line 2337  osm_gps_map_button_release (GtkWidget *w
2337    
2338      priv->drag_mouse_dx = 0;      priv->drag_mouse_dx = 0;
2339      priv->drag_mouse_dy = 0;      priv->drag_mouse_dy = 0;
2340      priv->drag_counter = 0;      priv->drag_counter = -1;
2341    
2342      return FALSE;      return FALSE;
2343  }  }
# Line 1832  osm_gps_map_motion_notify (GtkWidget *wi Line 2362  osm_gps_map_motion_notify (GtkWidget *wi
2362      if (!(state & GDK_BUTTON1_MASK))      if (!(state & GDK_BUTTON1_MASK))
2363          return FALSE;          return FALSE;
2364    
2365        if (priv->drag_counter < 0)
2366            return FALSE;
2367    
2368      priv->drag_counter++;      priv->drag_counter++;
2369    
2370      // we havent dragged more than 6 pixels      // we havent dragged more than 6 pixels
# Line 1846  osm_gps_map_motion_notify (GtkWidget *wi Line 2379  osm_gps_map_motion_notify (GtkWidget *wi
2379      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2380      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2381    
2382    #ifdef ENABLE_OSD
2383        /* undo OSD */
2384        osm_gps_map_osd_restore (OSM_GPS_MAP(widget));
2385    
2386        /* draw new OSD */
2387        osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget),
2388                                       -priv->drag_mouse_dx,
2389                                       -priv->drag_mouse_dy);
2390    #endif
2391    
2392      gdk_draw_drawable (      gdk_draw_drawable (
2393                         widget->window,                         widget->window,
2394                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
# Line 1934  osm_gps_map_expose (GtkWidget *widget, G Line 2477  osm_gps_map_expose (GtkWidget *widget, G
2477                         widget->window,                         widget->window,
2478                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2479                         priv->pixmap,                         priv->pixmap,
2480                         event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,                         event->area.x + EXTRA_BORDER,
2481                           event->area.y + EXTRA_BORDER,
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    
# Line 2123  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 2709  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)
3260  {  {
3261      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
3262    
# Line 2720  osm_gps_map_draw_balloon (OsmGpsMap *map Line 3266  osm_gps_map_draw_balloon (OsmGpsMap *map
3266      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
3267      priv = map->priv;      priv = map->priv;
3268    
3269      priv->balloon->rlat = deg2rad(latitude);      priv->balloon.coo->rlat = deg2rad(latitude);
3270      priv->balloon->rlon = deg2rad(longitude);      priv->balloon.coo->rlon = deg2rad(longitude);
3271      priv->balloon_valid = TRUE;      priv->balloon.valid = TRUE;
3272    
3273        priv->balloon.cb = cb;
3274        priv->balloon.data = data;
3275    
3276      // this redraws the map      // this redraws the map
3277      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
# Line 2736  osm_gps_map_clear_balloon (OsmGpsMap *ma Line 3285  osm_gps_map_clear_balloon (OsmGpsMap *ma
3285      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
3286      priv = map->priv;      priv = map->priv;
3287    
3288      priv->balloon_valid = FALSE;      priv->balloon.valid = FALSE;
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.57  
changed lines
  Added in v.67