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 65 by harbaum, Wed Aug 19 14:21:14 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            gint backup_x, backup_y;
117            //        GdkPixbuf *pixbuf;
118        } osd;
119    #endif
120    
121      //additional images or tracks added to the map      //additional images or tracks added to the map
122      GSList *tracks;      GSList *tracks;
# Line 637  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 653  osm_gps_map_draw_gps_point (OsmGpsMap *m
653      }      }
654  }  }
655    
656    #ifdef ENABLE_BALLOON
657  /* most visual effects are hardcoded by now, but may be made */  /* most visual effects are hardcoded by now, but may be made */
658  /* available via properties later */  /* available via properties later */
659    #ifndef BALLOON_AREA_WIDTH
660    #define BALLOON_AREA_WIDTH           290
661    #endif
662    #ifndef BALLOON_AREA_HEIGHT
663    #define BALLOON_AREA_HEIGHT           75
664    #endif
665    #ifndef BALLOON_CORNER_RADIUS
666  #define BALLOON_CORNER_RADIUS         20  #define BALLOON_CORNER_RADIUS         20
667  #define BALLOON_WIDTH                150  #endif
668  #define BALLOON_HEIGHT                75  
669    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/4)
670    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
671    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
672  #define BALLOON_TRANSPARENCY         0.8  #define BALLOON_TRANSPARENCY         0.8
673  #define POINTER_HEIGHT                20  #define POINTER_HEIGHT                20
674  #define POINTER_FOOT_WIDTH            20  #define POINTER_FOOT_WIDTH            20
# Line 649  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 676  osm_gps_map_draw_gps_point (OsmGpsMap *m
676  #define BALLOON_SHADOW                5  #define BALLOON_SHADOW                5
677  #define BALLOON_SHADOW_TRANSPARENCY  0.2  #define BALLOON_SHADOW_TRANSPARENCY  0.2
678    
679    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS/3)
680    
681    
682  /* 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 */
683  /* for the shadow */  /* for the shadow */
684  static void  static void
# Line 658  osm_gps_map_draw_balloon_shape (cairo_t Line 688  osm_gps_map_draw_balloon_shape (cairo_t
688      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);      cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
689      cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);      cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0);
690      if(!bottom) {      if(!bottom) {
691          /* insert bottom/left pointer */          /* insert top pointer */
692          cairo_line_to (cr, px1, y0);          cairo_line_to (cr, px1, y0);
693          cairo_line_to (cr, px, py);          cairo_line_to (cr, px, py);
694          cairo_line_to (cr, px0, y0);          cairo_line_to (cr, px0, y0);
# Line 669  osm_gps_map_draw_balloon_shape (cairo_t Line 699  osm_gps_map_draw_balloon_shape (cairo_t
699      cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);      cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
700      cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);      cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1);
701      if(bottom) {      if(bottom) {
702          /* insert bottom/left pointer */          /* insert bottom pointer */
703          cairo_line_to (cr, px0, y1);          cairo_line_to (cr, px0, y1);
704          cairo_line_to (cr, px, py);          cairo_line_to (cr, px, py);
705          cairo_line_to (cr, px1, y1);          cairo_line_to (cr, px1, y1);
# Line 681  osm_gps_map_draw_balloon_shape (cairo_t Line 711  osm_gps_map_draw_balloon_shape (cairo_t
711      cairo_close_path (cr);      cairo_close_path (cr);
712  }  }
713    
 /* http://cairographics.org/samples/ */  
714  static void  static void
715  osm_gps_map_draw_balloon_int (OsmGpsMap *map)  osm_gps_map_draw_balloon_int (OsmGpsMap *map)
716  {  {
717      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
718    
719      if (priv->balloon_valid) {      if (priv->balloon.valid) {
720    
721          /* ------- convert given coordinate into screen position --------- */          /* ------- convert given coordinate into screen position --------- */
722          int x0 = lon2pixel(priv->map_zoom, priv->balloon->rlon) -          int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -
723              priv->map_x + EXTRA_BORDER;              priv->map_x + EXTRA_BORDER;
724          int y0 = lat2pixel(priv->map_zoom, priv->balloon->rlat) -          int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -
725              priv->map_y + EXTRA_BORDER;              priv->map_y + EXTRA_BORDER;
726    
727          /* 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 750  osm_gps_map_draw_balloon_int (OsmGpsMap
750          /* calculate bottom/right of box */          /* calculate bottom/right of box */
751          int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;          int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
752    
753            /* save balloon screen coordinates for later use */
754            priv->balloon.rect.x = x0 + BALLOON_BORDER;
755            priv->balloon.rect.y = y0 + BALLOON_BORDER;
756            priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
757            priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
758    
759  #ifdef USE_CAIRO  #ifdef USE_CAIRO
760          cairo_t *cr = gdk_cairo_create(priv->pixmap);          cairo_t *cr = gdk_cairo_create(priv->pixmap);
761    
# Line 750  osm_gps_map_draw_balloon_int (OsmGpsMap Line 785  osm_gps_map_draw_balloon_int (OsmGpsMap
785    
786          /* ---------- draw close button --------- */          /* ---------- draw close button --------- */
787    
788          int cx = x1 - BALLOON_CORNER_RADIUS*3/4;          int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;
789          int cy = y0 + BALLOON_CORNER_RADIUS*3/4;          int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;
790          int crad = BALLOON_CORNER_RADIUS/3;          int crad = CLOSE_BUTTON_RADIUS;
791    
792          cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);          cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
793          cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);          cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
794          cairo_fill_preserve (cr);          cairo_fill_preserve (cr);
795          cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);          cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
796          cairo_set_line_width (cr, 1);          cairo_set_line_width (cr, 2);
797          cairo_stroke(cr);          cairo_stroke(cr);
798    
         int cs = crad/2;  
799          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);          cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
800          cairo_set_line_width (cr, 3);          cairo_set_line_width (cr, 3);
801          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);          cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
802          cairo_move_to (cr, cx - cs, cy - cs);          cairo_move_to (cr, cx - crad/2, cy - crad/2);
803          cairo_line_to (cr, cx + cs, cy + cs);          cairo_line_to (cr, cx + crad/2, cy + crad/2);
804          cairo_stroke (cr);          cairo_stroke (cr);
805          cairo_move_to (cr, cx + cs, cy - cs);          cairo_move_to (cr, cx + crad/2, cy - crad/2);
806          cairo_line_to (cr, cx - cs, cy + cs);          cairo_line_to (cr, cx - crad/2, cy + crad/2);
807          cairo_stroke (cr);          cairo_stroke (cr);
808    
809            if (priv->balloon.cb) {
810                /* clip in case application tries to draw in */
811                /* exceed of the balloon */
812                cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
813                                 priv->balloon.rect.w, priv->balloon.rect.h);
814                cairo_clip (cr);
815                cairo_new_path (cr);  /* current path is not
816                                         consumed by cairo_clip() */
817    
818                priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
819            }
820    
821            cairo_destroy(cr);
822    
823          gtk_widget_queue_draw_area (GTK_WIDGET(map),          gtk_widget_queue_draw_area (GTK_WIDGET(map),
824                                      x0, y0, BALLOON_WIDTH,                                      x0, y0, BALLOON_WIDTH,
825                                      BALLOON_HEIGHT + POINTER_HEIGHT);                                      BALLOON_HEIGHT + POINTER_HEIGHT);
# Line 782  osm_gps_map_draw_balloon_int (OsmGpsMap Line 829  osm_gps_map_draw_balloon_int (OsmGpsMap
829      }      }
830  }  }
831    
832    /* the user clicked into the balloons main area. handle this */
833    static void
834    osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)
835    {
836        OsmGpsMapPrivate *priv = map->priv;
837    
838        if (!priv->balloon.valid)
839            return;
840    
841        /* check if the close button was clicked */
842        if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&
843            (x < priv->balloon.rect.w) &&
844            (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {
845    
846            priv->balloon.valid = FALSE;
847            osm_gps_map_map_redraw_idle(map);
848        }
849    }
850    
851    /* return true if balloon is being displayed and if */
852    /* the given coordinate is within this balloon */
853    static gboolean
854    osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)
855    {
856        return (priv->balloon.valid &&
857                (x > priv->balloon.rect.x) &&
858                (x < priv->balloon.rect.x + priv->balloon.rect.w) &&
859                (y > priv->balloon.rect.y) &&
860                (y < priv->balloon.rect.y + priv->balloon.rect.h));
861    }
862    #endif // ENABLE_BALLOON
863    
864  static void  static void
865  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)
866  {  {
# Line 844  osm_gps_map_tile_download_complete (Soup Line 923  osm_gps_map_tile_download_complete (Soup
923              }              }
924              else              else
925              {              {
926                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
927                              dl->folder);
928                    perror("perror:");
929              }              }
930          }          }
931    
# Line 1336  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1417  osm_gps_map_purge_cache (OsmGpsMap *map)
1417     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);
1418  }  }
1419    
1420    #ifdef ENABLE_OSD
1421    /* position and extent of bounding box */
1422    #define OSD_X      (10)
1423    #define OSD_Y      (10)
1424    
1425    #define OSD_COLOR  0.5, 0.5, 1
1426    
1427    /* parameters of the direction shape */
1428    #define D_RAD  (20)         // diameter of dpad
1429    #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center
1430    #define D_LEN  (D_RAD/4)    // length of arrow
1431    #define D_WID  (D_LEN)      // width of arrow
1432    
1433    /* parameters of the "zoom" pad */
1434    #define Z_STEP   (-D_RAD/8) // distance between dpad and zoom
1435    #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
1436    
1437    /* shadow also depends on control size */
1438    #define OSD_SHADOW (D_RAD/8)
1439    
1440    /* total width and height of controls incl. shadow */
1441    #define OSD_W    (2*D_RAD + OSD_SHADOW)
1442    #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
1443    
1444    #define OSD_LBL_SHADOW (OSD_SHADOW/2)
1445    
1446    #define Z_TOP    (2 * D_RAD + Z_STEP)
1447    #define Z_MID    (Z_TOP + Z_RAD)
1448    #define Z_BOT    (Z_MID + Z_RAD)
1449    #define Z_LEFT   (Z_RAD)
1450    #define Z_RIGHT  (2 * D_RAD - Z_RAD)
1451    
1452    /* create the cairo shape used for the zoom buttons */
1453    static void
1454    osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) {
1455        cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
1456        cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
1457        cairo_arc     (cr, x+Z_RIGHT,   y+Z_MID, Z_RAD, -M_PI/2,  M_PI/2);
1458        cairo_line_to (cr, x+Z_LEFT,    y+Z_BOT);
1459        cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);
1460    }
1461    
1462    /* create the cairo shape used for the dpad */
1463    static void
1464    osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) {
1465        cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
1466    }
1467    
1468    typedef enum {
1469        OSD_NONE = 0,
1470        OSD_BG,
1471        OSD_UP,
1472        OSD_DOWN,
1473        OSD_LEFT,
1474        OSD_RIGHT,
1475        OSD_IN,
1476        OSD_OUT,
1477        OSD_GPS
1478    } osd_button_t;
1479    
1480    static gboolean
1481    osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
1482    {
1483        return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
1484    }
1485    
1486    /* check whether x/y is within the dpad */
1487    static osd_button_t
1488    osm_gps_map_osd_check_dpad(gint x, gint y)
1489    {
1490        /* within entire dpad circle */
1491        if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD))
1492        {
1493            /* convert into position relative to dpads centre */
1494            x -= (OSD_X + D_RAD);
1495            y -= (OSD_Y + D_RAD);
1496    
1497            /* check for dpad center goes here! */
1498            if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD/3))
1499                return OSD_GPS;
1500    
1501            if( y < 0 && abs(x) < abs(y))
1502                return OSD_UP;
1503    
1504            if( y > 0 && abs(x) < abs(y))
1505                return OSD_DOWN;
1506    
1507            if( x < 0 && abs(y) < abs(x))
1508                return OSD_LEFT;
1509    
1510            if( x > 0 && abs(y) < abs(x))
1511                return OSD_RIGHT;
1512    
1513            return OSD_BG;
1514        }
1515        return OSD_NONE;
1516    }
1517    
1518    /* check whether x/y is within the zoom pads */
1519    static osd_button_t
1520    osm_gps_map_osd_check_zoom(gint x, gint y) {
1521        if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < Z_BOT) {
1522    
1523            /* within circle around (-) label */
1524            if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))
1525                return OSD_OUT;
1526    
1527            /* between center of (-) button and center of entire zoom control area */
1528            if(x > OSD_LEFT && x < OSD_X + D_RAD)
1529                return OSD_OUT;
1530    
1531            /* within circle around (+) label */
1532            if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD))
1533                return OSD_IN;
1534    
1535            /* between center of (+) button and center of entire zoom control area */
1536            if(x < OSD_RIGHT && x > OSD_X + D_RAD)
1537                return OSD_IN;
1538        }
1539    
1540        return OSD_NONE;
1541    }
1542    
1543    static osd_button_t
1544    osm_gps_map_osd_check(gint x, gint y) {
1545        osd_button_t but = OSD_NONE;
1546    
1547        /* first do a rough test for the OSD area. */
1548        /* this is just to avoid an unnecessary detailed test */
1549        if(x > OSD_X && x < OSD_X + OSD_W &&
1550           y > OSD_Y && y < OSD_Y + OSD_H) {
1551    
1552            but = osm_gps_map_osd_check_dpad(x, y);
1553    
1554            if(but == OSD_NONE)
1555                but = osm_gps_map_osd_check_zoom(x, y);
1556        }
1557    
1558        return but;
1559    }
1560    
1561    static void
1562    osm_gps_map_osd_shape_shadow(cairo_t *cr) {
1563        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
1564        cairo_fill (cr);
1565        cairo_stroke (cr);
1566    }
1567    
1568    static void
1569    osm_gps_map_osd_shape(cairo_t *cr) {
1570        cairo_set_source_rgb (cr, 1, 1, 1);
1571        cairo_fill_preserve (cr);
1572        cairo_set_source_rgb (cr, OSD_COLOR);
1573        cairo_set_line_width (cr, 1);
1574        cairo_stroke (cr);
1575    }
1576    
1577    static void
1578    osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {
1579        /* move reference to dpad center */
1580        x += D_RAD;
1581        y += D_RAD;
1582    
1583        const static gint offset[][3][2] = {
1584            /* left arrow/triangle */
1585            { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } },
1586            /* right arrow/triangle */
1587            { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } },
1588            /* top arrow/triangle */
1589            { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } },
1590            /* bottom arrow/triangle */
1591            { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } }
1592        };
1593    
1594        int i;
1595        for(i=0;i<4;i++) {
1596            cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]);
1597            cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]);
1598            cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);
1599        }
1600    }
1601    
1602    /* draw the sattelite dish icon in the center of the dpad */
1603    #define GPS_V0  (D_RAD/8)
1604    #define GPS_V1  (D_RAD/10)
1605    #define GPS_V2  (D_RAD/5)
1606    
1607    /* draw a satellite receiver dish */
1608    static void
1609    osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {
1610        /* move reference to dpad center */
1611        x += D_RAD;
1612        y += D_RAD + GPS_V0;
1613    
1614        cairo_move_to (cr, x-GPS_V0, y+GPS_V0);
1615        cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);
1616        cairo_rel_line_to (cr, +GPS_V0, +GPS_V0);
1617        cairo_close_path (cr);
1618    
1619        cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);
1620        cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);
1621        cairo_close_path (cr);
1622    
1623        x += GPS_V1;
1624        cairo_move_to (cr, x, y-GPS_V2);
1625        cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);
1626    }
1627    
1628    #define Z_LEN  (2*Z_RAD/3)
1629    
1630    static void
1631    osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1632        cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1633        cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
1634    
1635        cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);
1636        cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);
1637        cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);
1638        cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1639    }
1640    
1641    static void
1642    osm_gps_map_osd_labels(cairo_t *cr, gint width) {
1643        cairo_set_source_rgb (cr, OSD_COLOR);
1644        cairo_set_line_width (cr, width);
1645        cairo_stroke (cr);
1646    }
1647    
1648    static void
1649    osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width) {
1650        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
1651        cairo_set_line_width (cr, width);
1652        cairo_stroke (cr);
1653    }
1654    
1655    static void
1656    osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)
1657    {
1658        OsmGpsMapPrivate *priv = map->priv;
1659    
1660        /* backup previous contents */
1661        if(!priv->osd.backup)
1662            priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);
1663    
1664        gint x = OSD_X + EXTRA_BORDER + xoffset;
1665        gint y = OSD_Y + EXTRA_BORDER + yoffset;
1666    
1667        /* create backup of background */
1668        gdk_draw_drawable(priv->osd.backup,
1669            GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1670                          priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);
1671        priv->osd.backup_x = x-1;
1672        priv->osd.backup_y = y-1;
1673    
1674    #if 0
1675        /* create pixbuf for osd */
1676        if(!priv->osd.pixbuf)
1677            priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
1678                                              TRUE, 8, OSD_W, OSD_H);
1679        cairo_surface_t *surface =
1680            cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);
1681    
1682        /* fill with transparency */
1683        {
1684        cairo_t *cr = cairo_create(surface);
1685        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1686        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1687        cairo_paint(cr);
1688        cairo_destroy(cr);
1689        }
1690    #endif
1691    
1692    
1693    #ifdef USE_CAIRO
1694        //    cairo_t *cr = cairo_create(surface);
1695        cairo_t *cr = gdk_cairo_create(priv->pixmap);
1696    
1697        /* --------- draw zoom and dpad shape shadow ----------- */
1698    
1699        osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1700        osm_gps_map_osd_shape_shadow(cr);
1701        osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1702        osm_gps_map_osd_shape_shadow(cr);
1703    
1704        /* --------- draw zoom and dpad shape ----------- */
1705    
1706        osm_gps_map_osd_zoom_shape(cr, x, y);
1707        osm_gps_map_osd_shape(cr);
1708        osm_gps_map_osd_dpad_shape(cr, x, y);
1709        osm_gps_map_osd_shape(cr);
1710    
1711        /* --------- draw zoom and dpad labels --------- */
1712    
1713        osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1714        osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1715        osm_gps_map_osd_labels_shadow(cr, Z_RAD/3);
1716        osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1717        osm_gps_map_osd_labels_shadow(cr, Z_RAD/6);
1718    
1719        osm_gps_map_osd_zoom_labels(cr, x, y);
1720        osm_gps_map_osd_dpad_labels(cr, x, y);
1721        osm_gps_map_osd_labels(cr, Z_RAD/3);
1722        osm_gps_map_osd_dpad_gps(cr, x, y);
1723        osm_gps_map_osd_labels(cr, Z_RAD/6);
1724    
1725        cairo_destroy(cr);
1726    
1727    #else
1728    #warning "OSD control display lacks a non-cairo implementation!"
1729    #endif
1730    }
1731    
1732    static void
1733    osm_gps_map_osd_restore (OsmGpsMap *map)
1734    {
1735        OsmGpsMapPrivate *priv = map->priv;
1736    
1737        /* restore backup of previous contents */
1738        if(priv->osd.backup) {
1739            /* create backup of background */
1740            gdk_draw_drawable(priv->pixmap,
1741                GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1742                          priv->osd.backup, 0, 0,
1743                          priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2);
1744        }
1745    }
1746    
1747    #endif
1748    
1749  static gboolean  static gboolean
1750  osm_gps_map_map_redraw (OsmGpsMap *map)  osm_gps_map_map_redraw (OsmGpsMap *map)
1751  {  {
# Line 1366  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1776  osm_gps_map_map_redraw (OsmGpsMap *map)
1776      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1777      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1778      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1779    #ifdef ENABLE_BALLOON
1780      osm_gps_map_draw_balloon_int(map);      osm_gps_map_draw_balloon_int(map);
1781    #endif
1782    #ifdef ENABLE_OSD
1783        osm_gps_map_osd_draw_controls(map, 0, 0);
1784    #endif
1785    
1786      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1787      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1398  osm_gps_map_init (OsmGpsMap *object) Line 1813  osm_gps_map_init (OsmGpsMap *object)
1813      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1814      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1815    
1816      priv->balloon = g_new0(coord_t, 1);  #ifdef ENABLE_BALLOON
1817      priv->balloon_valid = FALSE;      priv->balloon.coo = g_new0(coord_t, 1);
1818        priv->balloon.valid = FALSE;
1819        priv->balloon.cb = NULL;
1820    #endif
1821    
1822    #ifdef ENABLE_OSD
1823        priv->osd.backup = NULL;
1824    #endif
1825    
1826      priv->tracks = NULL;      priv->tracks = NULL;
1827      priv->images = NULL;      priv->images = NULL;
# Line 1559  osm_gps_map_dispose (GObject *object) Line 1981  osm_gps_map_dispose (GObject *object)
1981          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1982    
1983      g_free(priv->gps);      g_free(priv->gps);
1984      g_free(priv->balloon);  
1985    #ifdef ENABLE_BALLOON
1986        g_free(priv->balloon.coo);
1987    #endif
1988    
1989    #ifdef ENABLE_OSD
1990        if (priv->osd.backup)
1991            g_object_unref(priv->osd.backup);
1992    #endif
1993    
1994      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
1995  }  }
# Line 1776  osm_gps_map_button_press (GtkWidget *wid Line 2206  osm_gps_map_button_press (GtkWidget *wid
2206  {  {
2207      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2208    
2209    #ifdef ENABLE_BALLOON
2210        /* don't drag if the user clicked within the balloon */
2211        if (osm_gps_map_in_balloon(priv,
2212                       event->x + EXTRA_BORDER,
2213                       event->y + EXTRA_BORDER))
2214        {
2215            priv->drag_counter = -1;
2216            return FALSE;
2217        }
2218    #endif
2219    
2220    #ifdef ENABLE_OSD
2221        /* also don't drag on clicks into the control OSD */
2222        if(osm_gps_map_osd_check(event->x, event->y) != OSD_NONE)
2223        {
2224            priv->drag_counter = -1;
2225            return FALSE;
2226        }
2227    #endif
2228    
2229      priv->drag_counter = 0;      priv->drag_counter = 0;
2230      priv->drag_start_mouse_x = (int) event->x;      priv->drag_start_mouse_x = (int) event->x;
2231      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 2240  osm_gps_map_button_release (GtkWidget *w
2240  {  {
2241      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2242    
2243    #ifdef ENABLE_OSD
2244        /* released inside OSD control? */
2245        osd_button_t but = osm_gps_map_osd_check(event->x, event->y);
2246        if(but != OSD_NONE)
2247        {
2248            switch(but) {
2249            case OSD_UP:
2250                priv->map_y -= GTK_WIDGET(widget)->allocation.height/4;
2251                priv->center_coord_set = FALSE;
2252                break;
2253    
2254            case OSD_DOWN:
2255                priv->map_y += GTK_WIDGET(widget)->allocation.height/4;
2256                priv->center_coord_set = FALSE;
2257                break;
2258    
2259            case OSD_LEFT:
2260                priv->map_x -= GTK_WIDGET(widget)->allocation.width/4;
2261                priv->center_coord_set = FALSE;
2262                break;
2263    
2264            case OSD_RIGHT:
2265                priv->map_x += GTK_WIDGET(widget)->allocation.width/4;
2266                priv->center_coord_set = FALSE;
2267                break;
2268    
2269            case OSD_IN:
2270                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
2271                break;
2272    
2273            case OSD_OUT:
2274                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
2275                break;
2276    
2277            default:
2278                break;
2279            }
2280    
2281            osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
2282    
2283            return FALSE;
2284        }
2285    #endif
2286    
2287    #ifdef ENABLE_BALLOON
2288        /* released inside the balloon? */
2289        if (osm_gps_map_in_balloon(priv,
2290                       event->x + EXTRA_BORDER,
2291                       event->y + EXTRA_BORDER))
2292        {
2293            osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
2294                 event->x - priv->balloon.rect.x + EXTRA_BORDER,
2295                 event->y - priv->balloon.rect.y + EXTRA_BORDER);
2296        }
2297    #endif
2298    
2299      if (priv->dragging)      if (priv->dragging)
2300      {      {
2301          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1807  osm_gps_map_button_release (GtkWidget *w Line 2313  osm_gps_map_button_release (GtkWidget *w
2313    
2314      priv->drag_mouse_dx = 0;      priv->drag_mouse_dx = 0;
2315      priv->drag_mouse_dy = 0;      priv->drag_mouse_dy = 0;
2316      priv->drag_counter = 0;      priv->drag_counter = -1;
2317    
2318      return FALSE;      return FALSE;
2319  }  }
# Line 1832  osm_gps_map_motion_notify (GtkWidget *wi Line 2338  osm_gps_map_motion_notify (GtkWidget *wi
2338      if (!(state & GDK_BUTTON1_MASK))      if (!(state & GDK_BUTTON1_MASK))
2339          return FALSE;          return FALSE;
2340    
2341        if (priv->drag_counter < 0)
2342            return FALSE;
2343    
2344      priv->drag_counter++;      priv->drag_counter++;
2345    
2346      // we havent dragged more than 6 pixels      // we havent dragged more than 6 pixels
# Line 1846  osm_gps_map_motion_notify (GtkWidget *wi Line 2355  osm_gps_map_motion_notify (GtkWidget *wi
2355      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2356      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2357    
2358    #ifdef ENABLE_OSD
2359        /* undo OSD */
2360        osm_gps_map_osd_restore (OSM_GPS_MAP(widget));
2361    
2362        /* draw new OSD */
2363        osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget),
2364                                       -priv->drag_mouse_dx,
2365                                       -priv->drag_mouse_dy);
2366    #endif
2367    
2368      gdk_draw_drawable (      gdk_draw_drawable (
2369                         widget->window,                         widget->window,
2370                         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 2453  osm_gps_map_expose (GtkWidget *widget, G
2453                         widget->window,                         widget->window,
2454                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2455                         priv->pixmap,                         priv->pixmap,
2456                         event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,                         event->area.x + EXTRA_BORDER,
2457                           event->area.y + EXTRA_BORDER,
2458                         event->area.x, event->area.y,                         event->area.x, event->area.y,
2459                         event->area.width, event->area.height);                         event->area.width, event->area.height);
2460    
2461    #ifdef ENABLE_OSD_OVL
2462        /* TODO: intersect with area */
2463        if (priv->osd.pixbuf)
2464        {
2465            //        gdk_draw_drawable (widget->window,
2466            //            widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2467            //            priv->osd.pixbuf, 0, 0,
2468            //            OSD_X, OSD_Y, OSD_W, OSD_H);
2469        }
2470    #endif
2471    
2472      return FALSE;      return FALSE;
2473  }  }
2474    
# Line 2709  osm_gps_map_get_scale(OsmGpsMap *map) Line 3240  osm_gps_map_get_scale(OsmGpsMap *map)
3240      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);
3241  }  }
3242    
3243    #ifdef ENABLE_BALLOON
3244  void  void
3245  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude)  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
3246                              OsmGpsMapBalloonCallback cb, gpointer data)
3247  {  {
3248      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
3249    
# Line 2720  osm_gps_map_draw_balloon (OsmGpsMap *map Line 3253  osm_gps_map_draw_balloon (OsmGpsMap *map
3253      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
3254      priv = map->priv;      priv = map->priv;
3255    
3256      priv->balloon->rlat = deg2rad(latitude);      priv->balloon.coo->rlat = deg2rad(latitude);
3257      priv->balloon->rlon = deg2rad(longitude);      priv->balloon.coo->rlon = deg2rad(longitude);
3258      priv->balloon_valid = TRUE;      priv->balloon.valid = TRUE;
3259    
3260        priv->balloon.cb = cb;
3261        priv->balloon.data = data;
3262    
3263      // this redraws the map      // this redraws the map
3264      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
# Line 2736  osm_gps_map_clear_balloon (OsmGpsMap *ma Line 3272  osm_gps_map_clear_balloon (OsmGpsMap *ma
3272      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
3273      priv = map->priv;      priv = map->priv;
3274    
3275      priv->balloon_valid = FALSE;      priv->balloon.valid = FALSE;
3276    
3277      osm_gps_map_map_redraw_idle(map);      osm_gps_map_map_redraw_idle(map);
3278  }  }
3279    #endif

Legend:
Removed from v.57  
changed lines
  Added in v.65