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

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

revision 56 by harbaum, Fri Aug 14 12:19:45 2009 UTC revision 66 by harbaum, Wed Aug 19 20:03:28 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
103        struct {
104            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            OsmGpsMapOsdGpsCallback cb;
118            gpointer data;
119        } osd;
120    #endif
121    
122      //additional images or tracks added to the map      //additional images or tracks added to the map
123      GSList *tracks;      GSList *tracks;
124      GSList *images;      GSList *images;
# Line 631  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 652  osm_gps_map_draw_gps_point (OsmGpsMap *m
652                                      (mr*2)+lw+lw);                                      (mr*2)+lw+lw);
653  #endif  #endif
654      }      }
655    }
656    
657    #ifdef ENABLE_BALLOON
658    /* most visual effects are hardcoded by now, but may be made */
659    /* available via properties later */
660    #ifndef BALLOON_AREA_WIDTH
661    #define BALLOON_AREA_WIDTH           290
662    #endif
663    #ifndef BALLOON_AREA_HEIGHT
664    #define BALLOON_AREA_HEIGHT           75
665    #endif
666    #ifndef BALLOON_CORNER_RADIUS
667    #define BALLOON_CORNER_RADIUS         10
668    #endif
669    
670    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
671    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
672    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
673    #define BALLOON_TRANSPARENCY         0.8
674    #define POINTER_HEIGHT                20
675    #define POINTER_FOOT_WIDTH            20
676    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
677    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
678    #define BALLOON_SHADOW_TRANSPARENCY  0.2
679    
680    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
681    
682    
683    /* draw the bubble shape. this is used twice, once for the shape and once */
684    /* for the shadow */
685    static void
686    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
687           gboolean bottom, int px, int py, int px0, int px1) {
688    
689        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
690        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
691                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
692        if(!bottom) {
693            /* insert top pointer */
694            cairo_line_to (cr, px1, y0);
695            cairo_line_to (cr, px, py);
696            cairo_line_to (cr, px0, y0);
697        }
698    
699        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
700        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
701                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
702        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
703        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
704                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
705        if(bottom) {
706            /* insert bottom pointer */
707            cairo_line_to (cr, px0, y1);
708            cairo_line_to (cr, px, py);
709            cairo_line_to (cr, px1, y1);
710        }
711    
712        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
713        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
714                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
715    
716        cairo_close_path (cr);
717  }  }
718    
 /* http://cairographics.org/samples/ */  
719  static void  static void
720  osm_gps_map_draw_balloon (OsmGpsMap *map)  osm_gps_map_draw_balloon_int (OsmGpsMap *map)
721  {  {
722      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
723    
724      /* xyz */      if (priv->balloon.valid) {
 #define X 100  
 #define Y 100  
 #define RADIUS 20  
 #define WIDTH  150  
 #define HEIGHT 75  
 #define TRANSPARENCY  0.7  
 #define PIN_HEIGHT 20  
 #define PIN_FOOT_WIDTH 20  
 #define PIN_X  (X + EXTRA_BORDER)  
 #define PIN_X0 (X + EXTRA_BORDER + RADIUS + PIN_FOOT_WIDTH)  
 #define PIN_X1 (X + EXTRA_BORDER + RADIUS)  
 #define PIN_Y  (Y + EXTRA_BORDER + HEIGHT + PIN_HEIGHT)  
   
 #ifdef USE_CAIRO  
     cairo_t *cr = gdk_cairo_create(priv->pixmap);  
725    
726      int x0 = X + EXTRA_BORDER, y0 = Y + EXTRA_BORDER;          /* ------- convert given coordinate into screen position --------- */
727      int x1 = x0 + WIDTH, y1 = y0 + HEIGHT;          int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -
728                priv->map_x + EXTRA_BORDER;
729            int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -
730                priv->map_y + EXTRA_BORDER;
731    
732      cairo_move_to (cr, x0, y0 + RADIUS);          /* check position of this relative to screen center to determine */
733      cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + RADIUS, y0);          /* pointer direction ... */
734      cairo_line_to (cr, x1 - RADIUS, y0);          int pointer_x = x0, pointer_x0, pointer_x1;
735      cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + RADIUS);          int pointer_y = y0;
     cairo_line_to (cr, x1 , y1 - RADIUS);  
     cairo_curve_to (cr, x1, y1, x1, y1, x1 - RADIUS, y1);  
   
     /* insert pin */  
     cairo_line_to (cr, PIN_X0, y1);  
     cairo_line_to (cr, PIN_X, PIN_Y);  
     cairo_line_to (cr, PIN_X1, y1);  
   
736    
737      cairo_line_to (cr, x0 + RADIUS, y1);          /* ... and calculate position */
738      cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - RADIUS);          if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) {
739                x0 -= BALLOON_WIDTH - POINTER_OFFSET;
740                pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
741                pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
742            } else {
743                x0 -= POINTER_OFFSET;
744                pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
745                pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
746            }
747    
748            gboolean bottom = FALSE;
749            if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) {
750                bottom = TRUE;
751                y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;
752            } else
753                y0 += POINTER_HEIGHT;
754    
755            /* calculate bottom/right of box */
756            int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
757    
758            /* save balloon screen coordinates for later use */
759            priv->balloon.rect.x = x0 + BALLOON_BORDER;
760            priv->balloon.rect.y = y0 + BALLOON_BORDER;
761            priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
762            priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
763    
764      cairo_close_path (cr);  #ifdef USE_CAIRO
765      cairo_set_source_rgba (cr, 1, 1, 1, TRANSPARENCY);          cairo_t *cr = gdk_cairo_create(priv->pixmap);
766      cairo_fill_preserve (cr);  
767      cairo_set_source_rgba (cr, 0, 0, 0, TRANSPARENCY);          /* --------- draw shadow --------------- */
768      cairo_set_line_width (cr, 1);          osm_gps_map_draw_balloon_shape (cr,
769      cairo_stroke (cr);                      x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
770                        x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
771      gtk_widget_queue_draw_area (GTK_WIDGET(map),                      bottom, pointer_x, pointer_y,
772                                  x0,                      pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
773                                  y0,  
774                                  WIDTH,          cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
775                                  HEIGHT + PIN_HEIGHT);          cairo_fill_preserve (cr);
776            cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
777            cairo_set_line_width (cr, 0);
778            cairo_stroke (cr);
779    
780            /* --------- draw main shape ----------- */
781            osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
782                        bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
783    
784            cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
785            cairo_fill_preserve (cr);
786            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
787            cairo_set_line_width (cr, 1);
788            cairo_stroke (cr);
789    
790    
791            /* ---------- draw close button --------- */
792    
793            int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;
794            int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;
795            int crad = CLOSE_BUTTON_RADIUS;
796    
797            cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
798            cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
799            cairo_fill_preserve (cr);
800            cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
801            cairo_set_line_width (cr, 2);
802            cairo_stroke(cr);
803    
804            cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
805            cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);
806            cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
807            cairo_move_to (cr, cx - crad/2, cy - crad/2);
808            cairo_line_to (cr, cx + crad/2, cy + crad/2);
809            cairo_stroke (cr);
810            cairo_move_to (cr, cx + crad/2, cy - crad/2);
811            cairo_line_to (cr, cx - crad/2, cy + crad/2);
812            cairo_stroke (cr);
813    
814            if (priv->balloon.cb) {
815                /* clip in case application tries to draw in */
816                /* exceed of the balloon */
817                cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
818                                 priv->balloon.rect.w, priv->balloon.rect.h);
819                cairo_clip (cr);
820                cairo_new_path (cr);  /* current path is not
821                                         consumed by cairo_clip() */
822    
823                priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
824            }
825    
826            cairo_destroy(cr);
827    
828            gtk_widget_queue_draw_area (GTK_WIDGET(map),
829                                        x0, y0, BALLOON_WIDTH,
830                                        BALLOON_HEIGHT + POINTER_HEIGHT);
831    #else
832    #warning "Balloon display lacks a non-cairo implementation!"
833  #endif  #endif
834        }
835    }
836    
837    /* the user clicked into the balloons main area. handle this */
838    static void
839    osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)
840    {
841        OsmGpsMapPrivate *priv = map->priv;
842    
843        if (!priv->balloon.valid)
844            return;
845    
846        /* check if the close button was clicked */
847        if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&
848            (x < priv->balloon.rect.w) &&
849            (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {
850    
851            priv->balloon.valid = FALSE;
852            osm_gps_map_map_redraw_idle(map);
853        }
854  }  }
855    
856    /* return true if balloon is being displayed and if */
857    /* the given coordinate is within this balloon */
858    static gboolean
859    osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)
860    {
861        return (priv->balloon.valid &&
862                (x > priv->balloon.rect.x) &&
863                (x < priv->balloon.rect.x + priv->balloon.rect.w) &&
864                (y > priv->balloon.rect.y) &&
865                (y < priv->balloon.rect.y + priv->balloon.rect.h));
866    }
867    #endif // ENABLE_BALLOON
868    
869  static void  static void
870  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)
871  {  {
# Line 752  osm_gps_map_tile_download_complete (Soup Line 928  osm_gps_map_tile_download_complete (Soup
928              }              }
929              else              else
930              {              {
931                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
932                              dl->folder);
933                    perror("perror:");
934              }              }
935          }          }
936    
# Line 1244  osm_gps_map_purge_cache (OsmGpsMap *map) Line 1422  osm_gps_map_purge_cache (OsmGpsMap *map)
1422     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);
1423  }  }
1424    
1425    #ifdef ENABLE_OSD
1426    /* position and extent of bounding box */
1427    #define OSD_X      (10)
1428    #define OSD_Y      (10)
1429    
1430    #define OSD_COLOR            0.5, 0.5, 1
1431    #define OSD_COLOR_DISABLED   0.8, 0.8, 0.8
1432    
1433    /* parameters of the direction shape */
1434    #ifndef OSM_GPS_MAP_OSD_DIAMETER
1435    #define D_RAD  (30)         // diameter of dpad
1436    #else
1437    #define D_RAD  (OSM_GPS_MAP_OSD_DIAMETER)
1438    #endif
1439    #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center
1440    #define D_LEN  (D_RAD/4)    // length of arrow
1441    #define D_WID  (D_LEN)      // width of arrow
1442    
1443    /* parameters of the "zoom" pad */
1444    #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom
1445    #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
1446    
1447    /* shadow also depends on control size */
1448    #define OSD_SHADOW (D_RAD/6)
1449    
1450    /* total width and height of controls incl. shadow */
1451    #define OSD_W    (2*D_RAD + OSD_SHADOW)
1452    #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
1453    
1454    #define OSD_LBL_SHADOW (OSD_SHADOW/2)
1455    
1456    #define Z_TOP    (2 * D_RAD + Z_STEP)
1457    #define Z_MID    (Z_TOP + Z_RAD)
1458    #define Z_BOT    (Z_MID + Z_RAD)
1459    #define Z_LEFT   (Z_RAD)
1460    #define Z_RIGHT  (2 * D_RAD - Z_RAD)
1461    
1462    /* create the cairo shape used for the zoom buttons */
1463    static void
1464    osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) {
1465        cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
1466        cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
1467        cairo_arc     (cr, x+Z_RIGHT,   y+Z_MID, Z_RAD, -M_PI/2,  M_PI/2);
1468        cairo_line_to (cr, x+Z_LEFT,    y+Z_BOT);
1469        cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);
1470    }
1471    
1472    /* create the cairo shape used for the dpad */
1473    static void
1474    osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) {
1475        cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
1476    }
1477    
1478    typedef enum {
1479        OSD_NONE = 0,
1480        OSD_BG,
1481        OSD_UP,
1482        OSD_DOWN,
1483        OSD_LEFT,
1484        OSD_RIGHT,
1485        OSD_IN,
1486        OSD_OUT,
1487        OSD_GPS
1488    } osd_button_t;
1489    
1490    static gboolean
1491    osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
1492    {
1493        return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
1494    }
1495    
1496    /* check whether x/y is within the dpad */
1497    static osd_button_t
1498    osm_gps_map_osd_check_dpad(gint x, gint y)
1499    {
1500        /* within entire dpad circle */
1501        if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD))
1502        {
1503            /* convert into position relative to dpads centre */
1504            x -= (OSD_X + D_RAD);
1505            y -= (OSD_Y + D_RAD);
1506    
1507            /* check for dpad center goes here! */
1508            if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))
1509                return OSD_GPS;
1510    
1511            if( y < 0 && abs(x) < abs(y))
1512                return OSD_UP;
1513    
1514            if( y > 0 && abs(x) < abs(y))
1515                return OSD_DOWN;
1516    
1517            if( x < 0 && abs(y) < abs(x))
1518                return OSD_LEFT;
1519    
1520            if( x > 0 && abs(y) < abs(x))
1521                return OSD_RIGHT;
1522    
1523            return OSD_BG;
1524        }
1525        return OSD_NONE;
1526    }
1527    
1528    /* check whether x/y is within the zoom pads */
1529    static osd_button_t
1530    osm_gps_map_osd_check_zoom(gint x, gint y) {
1531        if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) {
1532    
1533            /* within circle around (-) label */
1534            if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))
1535                return OSD_OUT;
1536    
1537            /* between center of (-) button and center of entire zoom control area */
1538            if(x > OSD_LEFT && x < OSD_X + D_RAD)
1539                return OSD_OUT;
1540    
1541            /* within circle around (+) label */
1542            if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD))
1543                return OSD_IN;
1544    
1545            /* between center of (+) button and center of entire zoom control area */
1546            if(x < OSD_RIGHT && x > OSD_X + D_RAD)
1547                return OSD_IN;
1548        }
1549    
1550        return OSD_NONE;
1551    }
1552    
1553    static osd_button_t
1554    osm_gps_map_osd_check(gint x, gint y) {
1555        osd_button_t but = OSD_NONE;
1556    
1557        /* first do a rough test for the OSD area. */
1558        /* this is just to avoid an unnecessary detailed test */
1559        if(x > OSD_X && x < OSD_X + OSD_W &&
1560           y > OSD_Y && y < OSD_Y + OSD_H) {
1561            but = osm_gps_map_osd_check_dpad(x, y);
1562    
1563            if(but == OSD_NONE)
1564                but = osm_gps_map_osd_check_zoom(x, y);
1565        }
1566    
1567        return but;
1568    }
1569    
1570    static void
1571    osm_gps_map_osd_shape_shadow(cairo_t *cr) {
1572        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
1573        cairo_fill (cr);
1574        cairo_stroke (cr);
1575    }
1576    
1577    static void
1578    osm_gps_map_osd_shape(cairo_t *cr) {
1579        cairo_set_source_rgb (cr, 1, 1, 1);
1580        cairo_fill_preserve (cr);
1581        cairo_set_source_rgb (cr, OSD_COLOR);
1582        cairo_set_line_width (cr, 1);
1583        cairo_stroke (cr);
1584    }
1585    
1586    static void
1587    osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {
1588        /* move reference to dpad center */
1589        x += D_RAD;
1590        y += D_RAD;
1591    
1592        const static gint offset[][3][2] = {
1593            /* left arrow/triangle */
1594            { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } },
1595            /* right arrow/triangle */
1596            { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } },
1597            /* top arrow/triangle */
1598            { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } },
1599            /* bottom arrow/triangle */
1600            { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } }
1601        };
1602    
1603        int i;
1604        for(i=0;i<4;i++) {
1605            cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]);
1606            cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]);
1607            cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);
1608        }
1609    }
1610    
1611    /* draw the sattelite dish icon in the center of the dpad */
1612    #define GPS_V0  (D_RAD/8)
1613    #define GPS_V1  (D_RAD/10)
1614    #define GPS_V2  (D_RAD/5)
1615    
1616    /* draw a satellite receiver dish */
1617    static void
1618    osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {
1619        /* move reference to dpad center */
1620        x += D_RAD;
1621        y += D_RAD + GPS_V0;
1622    
1623        cairo_move_to (cr, x-GPS_V0, y+GPS_V0);
1624        cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);
1625        cairo_rel_line_to (cr, +GPS_V0, +GPS_V0);
1626        cairo_close_path (cr);
1627    
1628        cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);
1629        cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);
1630        cairo_close_path (cr);
1631    
1632        x += GPS_V1;
1633        cairo_move_to (cr, x, y-GPS_V2);
1634        cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);
1635    }
1636    
1637    #define Z_LEN  (2*Z_RAD/3)
1638    
1639    static void
1640    osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1641        cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1642        cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
1643    
1644        cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);
1645        cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);
1646        cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);
1647        cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1648    }
1649    
1650    static void
1651    osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {
1652        if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
1653        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
1654        cairo_set_line_width (cr, width);
1655        cairo_stroke (cr);
1656    }
1657    
1658    static void
1659    osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
1660        cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
1661        cairo_set_line_width (cr, width);
1662        cairo_stroke (cr);
1663    }
1664    
1665    static void
1666    osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)
1667    {
1668        OsmGpsMapPrivate *priv = map->priv;
1669    
1670        /* backup previous contents */
1671        if(!priv->osd.backup)
1672            priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);
1673    
1674        gint x = OSD_X + EXTRA_BORDER + xoffset;
1675        gint y = OSD_Y + EXTRA_BORDER + yoffset;
1676    
1677        /* create backup of background */
1678        gdk_draw_drawable(priv->osd.backup,
1679            GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1680                          priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);
1681        priv->osd.backup_x = x-1;
1682        priv->osd.backup_y = y-1;
1683    
1684    #if 0
1685        /* create pixbuf for osd */
1686        if(!priv->osd.pixbuf)
1687            priv->osd.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
1688                                              TRUE, 8, OSD_W, OSD_H);
1689        cairo_surface_t *surface =
1690            cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);
1691    
1692        /* fill with transparency */
1693        {
1694        cairo_t *cr = cairo_create(surface);
1695        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1696        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1697        cairo_paint(cr);
1698        cairo_destroy(cr);
1699        }
1700    #endif
1701    
1702    
1703    #ifdef USE_CAIRO
1704        //    cairo_t *cr = cairo_create(surface);
1705        cairo_t *cr = gdk_cairo_create(priv->pixmap);
1706    
1707        /* --------- draw zoom and dpad shape shadow ----------- */
1708    
1709        osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1710        osm_gps_map_osd_shape_shadow(cr);
1711        osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
1712        osm_gps_map_osd_shape_shadow(cr);
1713    
1714        /* --------- draw zoom and dpad shape ----------- */
1715    
1716        osm_gps_map_osd_zoom_shape(cr, x, y);
1717        osm_gps_map_osd_shape(cr);
1718        osm_gps_map_osd_dpad_shape(cr, x, y);
1719        osm_gps_map_osd_shape(cr);
1720    
1721        /* --------- draw zoom and dpad labels --------- */
1722    
1723        osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1724        osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1725        osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);
1726        osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
1727        osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL);
1728    
1729        osm_gps_map_osd_zoom_labels(cr, x, y);
1730        osm_gps_map_osd_dpad_labels(cr, x, y);
1731        osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);
1732        osm_gps_map_osd_dpad_gps(cr, x, y);
1733        osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL);
1734    
1735        cairo_destroy(cr);
1736    
1737    #else
1738    #warning "OSD control display lacks a non-cairo implementation!"
1739    #endif
1740    }
1741    
1742    static void
1743    osm_gps_map_osd_restore (OsmGpsMap *map)
1744    {
1745        OsmGpsMapPrivate *priv = map->priv;
1746    
1747        /* restore backup of previous contents */
1748        if(priv->osd.backup) {
1749            /* create backup of background */
1750            gdk_draw_drawable(priv->pixmap,
1751                GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],
1752                          priv->osd.backup, 0, 0,
1753                          priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2);
1754        }
1755    }
1756    
1757    #endif
1758    
1759  static gboolean  static gboolean
1760  osm_gps_map_map_redraw (OsmGpsMap *map)  osm_gps_map_map_redraw (OsmGpsMap *map)
1761  {  {
# Line 1274  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1786  osm_gps_map_map_redraw (OsmGpsMap *map)
1786      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1787      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1788      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1789    #ifdef ENABLE_BALLOON
1790      osm_gps_map_draw_balloon(map);      osm_gps_map_draw_balloon_int(map);
1791    #endif
1792    #ifdef ENABLE_OSD
1793        osm_gps_map_osd_draw_controls(map, 0, 0);
1794    #endif
1795    
1796      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1797      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1307  osm_gps_map_init (OsmGpsMap *object) Line 1823  osm_gps_map_init (OsmGpsMap *object)
1823      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1824      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1825    
1826    #ifdef ENABLE_BALLOON
1827        priv->balloon.coo = g_new0(coord_t, 1);
1828        priv->balloon.valid = FALSE;
1829        priv->balloon.cb = NULL;
1830    #endif
1831    
1832    #ifdef ENABLE_OSD
1833        priv->osd.backup = NULL;
1834        priv->osd.cb = NULL;
1835    #endif
1836    
1837      priv->tracks = NULL;      priv->tracks = NULL;
1838      priv->images = NULL;      priv->images = NULL;
1839    
# Line 1464  osm_gps_map_dispose (GObject *object) Line 1991  osm_gps_map_dispose (GObject *object)
1991      if (priv->idle_map_redraw != 0)      if (priv->idle_map_redraw != 0)
1992          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1993    
1994        g_free(priv->gps);
1995    
1996    #ifdef ENABLE_BALLOON
1997        g_free(priv->balloon.coo);
1998    #endif
1999    
2000    #ifdef ENABLE_OSD
2001        if (priv->osd.backup)
2002            g_object_unref(priv->osd.backup);
2003    #endif
2004    
2005      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
2006  }  }
2007    
# Line 1679  osm_gps_map_button_press (GtkWidget *wid Line 2217  osm_gps_map_button_press (GtkWidget *wid
2217  {  {
2218      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2219    
2220    #ifdef ENABLE_BALLOON
2221        /* don't drag if the user clicked within the balloon */
2222        if (osm_gps_map_in_balloon(priv,
2223                       event->x + EXTRA_BORDER,
2224                       event->y + EXTRA_BORDER))
2225        {
2226            priv->drag_counter = -1;
2227            return FALSE;
2228        }
2229    #endif
2230    
2231    #ifdef ENABLE_OSD
2232        #define SCROLL_STEP 10
2233    
2234        /* pressed inside OSD control? */
2235        osd_button_t but = osm_gps_map_osd_check(event->x, event->y);
2236        if(but != OSD_NONE)
2237        {
2238            priv->drag_counter = -1;
2239    
2240            switch(but) {
2241            case OSD_GPS:
2242                priv->osd.cb(priv->osd.data);
2243                break;
2244    
2245            case OSD_UP:
2246                priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2247                priv->center_coord_set = FALSE;
2248                break;
2249    
2250            case OSD_DOWN:
2251                priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;
2252                priv->center_coord_set = FALSE;
2253                break;
2254    
2255            case OSD_LEFT:
2256                priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2257                priv->center_coord_set = FALSE;
2258                break;
2259    
2260            case OSD_RIGHT:
2261                priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;
2262                priv->center_coord_set = FALSE;
2263                break;
2264    
2265            case OSD_IN:
2266                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
2267                break;
2268    
2269            case OSD_OUT:
2270                osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
2271                break;
2272    
2273            default:
2274                break;
2275            }
2276    
2277            osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
2278    
2279            return FALSE;
2280        }
2281    #endif
2282    
2283      priv->drag_counter = 0;      priv->drag_counter = 0;
2284      priv->drag_start_mouse_x = (int) event->x;      priv->drag_start_mouse_x = (int) event->x;
2285      priv->drag_start_mouse_y = (int) event->y;      priv->drag_start_mouse_y = (int) event->y;
# Line 1693  osm_gps_map_button_release (GtkWidget *w Line 2294  osm_gps_map_button_release (GtkWidget *w
2294  {  {
2295      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2296    
2297    #ifdef ENABLE_BALLOON
2298        /* released inside the balloon? */
2299        if (osm_gps_map_in_balloon(priv,
2300                       event->x + EXTRA_BORDER,
2301                       event->y + EXTRA_BORDER))
2302        {
2303            osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
2304                 event->x - priv->balloon.rect.x + EXTRA_BORDER,
2305                 event->y - priv->balloon.rect.y + EXTRA_BORDER);
2306        }
2307    #endif
2308    
2309      if (priv->dragging)      if (priv->dragging)
2310      {      {
2311          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1710  osm_gps_map_button_release (GtkWidget *w Line 2323  osm_gps_map_button_release (GtkWidget *w
2323    
2324      priv->drag_mouse_dx = 0;      priv->drag_mouse_dx = 0;
2325      priv->drag_mouse_dy = 0;      priv->drag_mouse_dy = 0;
2326      priv->drag_counter = 0;      priv->drag_counter = -1;
2327    
2328      return FALSE;      return FALSE;
2329  }  }
# Line 1735  osm_gps_map_motion_notify (GtkWidget *wi Line 2348  osm_gps_map_motion_notify (GtkWidget *wi
2348      if (!(state & GDK_BUTTON1_MASK))      if (!(state & GDK_BUTTON1_MASK))
2349          return FALSE;          return FALSE;
2350    
2351        if (priv->drag_counter < 0)
2352            return FALSE;
2353    
2354      priv->drag_counter++;      priv->drag_counter++;
2355    
2356      // we havent dragged more than 6 pixels      // we havent dragged more than 6 pixels
# Line 1749  osm_gps_map_motion_notify (GtkWidget *wi Line 2365  osm_gps_map_motion_notify (GtkWidget *wi
2365      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2366      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2367    
2368    #ifdef ENABLE_OSD
2369        /* undo OSD */
2370        osm_gps_map_osd_restore (OSM_GPS_MAP(widget));
2371    
2372        /* draw new OSD */
2373        osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget),
2374                                       -priv->drag_mouse_dx,
2375                                       -priv->drag_mouse_dy);
2376    #endif
2377    
2378      gdk_draw_drawable (      gdk_draw_drawable (
2379                         widget->window,                         widget->window,
2380                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
# Line 1837  osm_gps_map_expose (GtkWidget *widget, G Line 2463  osm_gps_map_expose (GtkWidget *widget, G
2463                         widget->window,                         widget->window,
2464                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2465                         priv->pixmap,                         priv->pixmap,
2466                         event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,                         event->area.x + EXTRA_BORDER,
2467                           event->area.y + EXTRA_BORDER,
2468                         event->area.x, event->area.y,                         event->area.x, event->area.y,
2469                         event->area.width, event->area.height);                         event->area.width, event->area.height);
2470    
2471    #ifdef ENABLE_OSD_OVL
2472        /* TODO: intersect with area */
2473        if (priv->osd.pixbuf)
2474        {
2475            //        gdk_draw_drawable (widget->window,
2476            //            widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2477            //            priv->osd.pixbuf, 0, 0,
2478            //            OSD_X, OSD_Y, OSD_W, OSD_H);
2479        }
2480    #endif
2481    
2482      return FALSE;      return FALSE;
2483  }  }
2484    
# Line 2026  osm_gps_map_class_init (OsmGpsMapClass * Line 2664  osm_gps_map_class_init (OsmGpsMapClass *
2664                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2665                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2666                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2667                                                         5,                                                         10,
2668                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2669    
2670      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 2612  osm_gps_map_get_scale(OsmGpsMap *map) Line 3250  osm_gps_map_get_scale(OsmGpsMap *map)
3250      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);
3251  }  }
3252    
3253    #ifdef ENABLE_BALLOON
3254    void
3255    osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
3256                              OsmGpsMapBalloonCallback cb, gpointer data)
3257    {
3258        OsmGpsMapPrivate *priv;
3259    
3260        /* remove and previously installed balloon */
3261        osm_gps_map_clear_balloon (map);
3262    
3263        g_return_if_fail (OSM_IS_GPS_MAP (map));
3264        priv = map->priv;
3265    
3266        priv->balloon.coo->rlat = deg2rad(latitude);
3267        priv->balloon.coo->rlon = deg2rad(longitude);
3268        priv->balloon.valid = TRUE;
3269    
3270        priv->balloon.cb = cb;
3271        priv->balloon.data = data;
3272    
3273        // this redraws the map
3274        osm_gps_map_map_redraw_idle(map);
3275    }
3276    
3277    void
3278    osm_gps_map_clear_balloon (OsmGpsMap *map)
3279    {
3280        OsmGpsMapPrivate *priv;
3281    
3282        g_return_if_fail (OSM_IS_GPS_MAP (map));
3283        priv = map->priv;
3284    
3285        priv->balloon.valid = FALSE;
3286    
3287        osm_gps_map_map_redraw_idle(map);
3288    }
3289    #endif
3290    
3291    #ifdef ENABLE_OSD
3292    void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) {
3293        OsmGpsMapPrivate *priv;
3294    
3295        g_return_if_fail (OSM_IS_GPS_MAP (map));
3296        priv = map->priv;
3297    
3298        priv->osd.cb = cb;
3299        priv->osd.data = data;
3300    
3301        osm_gps_map_map_redraw_idle(map);
3302    }
3303    #endif

Legend:
Removed from v.56  
changed lines
  Added in v.66