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

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

revision 112 by harbaum, Tue Sep 15 13:52:04 2009 UTC revision 124 by harbaum, Thu Sep 24 14:09:53 2009 UTC
# Line 19  Line 19 
19    
20  #include "config.h"  #include "config.h"
21  #include <stdlib.h>  // abs  #include <stdlib.h>  // abs
22    #include <string.h>
23  #include <math.h>    // M_PI/cos()  #include <math.h>    // M_PI/cos()
24    
25  /* parameters that can be overwritten from the config file: */  /* parameters that can be overwritten from the config file: */
# Line 50  typedef struct { Line 51  typedef struct {
51      //a balloon with additional info      //a balloon with additional info
52      struct {      struct {
53          cairo_surface_t *surface;          cairo_surface_t *surface;
54            int orientation, offset_x, offset_y;
55    
56            gboolean just_created;
57          float lat, lon;          float lat, lon;
         gboolean valid;  
58          OsmGpsMapRect_t rect;          OsmGpsMapRect_t rect;
59    
60          /* function called to have the user app draw the contents */          /* function called to have the user app draw the contents */
# Line 75  typedef struct { Line 77  typedef struct {
77      } crosshair;      } crosshair;
78  #endif  #endif
79    
80    #ifdef OSD_NAV
81        struct {
82            cairo_surface_t *surface;
83            float lat, lon;
84            char *name;
85        } nav;
86    #endif
87    
88  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
89      struct {      struct {
90          cairo_surface_t *surface;          cairo_surface_t *surface;
# Line 119  typedef struct { Line 129  typedef struct {
129  #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)  #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
130  #define BALLOON_SHADOW_TRANSPARENCY  0.2  #define BALLOON_SHADOW_TRANSPARENCY  0.2
131    
132    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
133    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
134    
135  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)  #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
136    
137    
# Line 158  osm_gps_map_draw_balloon_shape (cairo_t Line 171  osm_gps_map_draw_balloon_shape (cairo_t
171      cairo_close_path (cr);      cairo_close_path (cr);
172  }  }
173    
 /* xyz */  
   
174  static void  static void
175  osd_render_balloon(osm_gps_map_osd_t *osd) {  osd_render_balloon(osm_gps_map_osd_t *osd) {
176      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
# Line 169  osd_render_balloon(osm_gps_map_osd_t *os Line 180  osd_render_balloon(osm_gps_map_osd_t *os
180      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
181    
182      /* ------- convert given coordinate into screen position --------- */      /* ------- convert given coordinate into screen position --------- */
183      gint x0, y0;      gint xs, ys;
184      osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),      osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
185                                        priv->balloon.lat, priv->balloon.lon,                                        priv->balloon.lat, priv->balloon.lon,
186                                        &x0, &y0);                                        &xs, &ys);
187    
188        gint x0 = 1, y0 = 1;
189    
190      /* check position of this relative to screen center to determine */      /* check position of this relative to screen center to determine */
191      /* pointer direction ... */      /* pointer direction ... */
192      int pointer_x = x0, pointer_x0, pointer_x1;      int pointer_x, pointer_x0, pointer_x1;
193      int pointer_y = y0;      int pointer_y;
194    
195      /* ... and calculate position */      /* ... and calculate position */
196      if(x0 > osd->widget->allocation.width/2) {      int orientation = 0;
197          x0 += POINTER_OFFSET;      if(xs > osd->widget->allocation.width/2) {
198            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
199            pointer_x = x0 - priv->balloon.offset_x;
200          pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);          pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
201          pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;          pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
202            orientation |= 1;
203      } else {      } else {
204          x0 -= POINTER_OFFSET;          priv->balloon.offset_x = -POINTER_OFFSET;
205            pointer_x = x0 - priv->balloon.offset_x;
206          pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);          pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
207          pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;          pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
208      }      }
209    
210      gboolean bottom = FALSE;      gboolean bottom = FALSE;
211      if(y0 > osd->widget->allocation.height/2) {      if(ys > osd->widget->allocation.height/2) {
212            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
213            pointer_y = y0 - priv->balloon.offset_y;
214          bottom = TRUE;          bottom = TRUE;
215          y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;          orientation |= 2;
216      } else      } else {
217            priv->balloon.offset_y = 0;
218            pointer_y = y0 - priv->balloon.offset_y;
219          y0 += POINTER_HEIGHT;          y0 += POINTER_HEIGHT;
220        }
221    
222        /* if required orientation equals current one, then don't render */
223        /* anything */
224        if(orientation == priv->balloon.orientation)
225            return;
226    
227        priv->balloon.orientation = orientation;
228    
229      /* calculate bottom/right of box */      /* calculate bottom/right of box */
230      int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;      int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
231    
# Line 207  osd_render_balloon(osm_gps_map_osd_t *os Line 236  osd_render_balloon(osm_gps_map_osd_t *os
236      priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;      priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
237    
238      cairo_t *cr = cairo_create(priv->balloon.surface);      cairo_t *cr = cairo_create(priv->balloon.surface);
239        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
240        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
241        cairo_paint(cr);
242        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
243    
244      /* --------- draw shadow --------------- */      /* --------- draw shadow --------------- */
245      osm_gps_map_draw_balloon_shape (cr,      osm_gps_map_draw_balloon_shape (cr,
# Line 231  osd_render_balloon(osm_gps_map_osd_t *os Line 264  osd_render_balloon(osm_gps_map_osd_t *os
264      cairo_set_line_width (cr, 1);      cairo_set_line_width (cr, 1);
265      cairo_stroke (cr);      cairo_stroke (cr);
266    
   
     /* ---------- draw close button --------- */  
   
     int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;  
     int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;  
     int crad = CLOSE_BUTTON_RADIUS;  
   
     cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);  
     cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);  
     cairo_fill_preserve (cr);  
     cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);  
     cairo_set_line_width (cr, 2);  
     cairo_stroke(cr);  
   
     cairo_set_source_rgba (cr, 1, 1, 1, 1.0);  
     cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);  
     cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);  
     cairo_move_to (cr, cx - crad/2, cy - crad/2);  
     cairo_line_to (cr, cx + crad/2, cy + crad/2);  
     cairo_stroke (cr);  
     cairo_move_to (cr, cx + crad/2, cy - crad/2);  
     cairo_line_to (cr, cx - crad/2, cy + crad/2);  
     cairo_stroke (cr);  
   
267      if (priv->balloon.cb) {      if (priv->balloon.cb) {
268          /* clip in case application tries to draw in */          /* clip in case application tries to draw in */
269              /* exceed of the balloon */              /* exceed of the balloon */
# Line 266  osd_render_balloon(osm_gps_map_osd_t *os Line 275  osd_render_balloon(osm_gps_map_osd_t *os
275    
276          priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);          priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
277      }      }
   
     cairo_destroy(cr);  
 }  
   
 #if 0  
 /* the user clicked into the balloons main area. handle this */  
 static void  
 osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)  
 {  
     OsmGpsMapPrivate *priv = map->priv;  
   
     if (!priv->balloon.valid)  
         return;  
   
     /* check if the close button was clicked */  
     if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&  
         (x < priv->balloon.rect.w) &&  
         (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {  
278    
279          priv->balloon.valid = FALSE;      cairo_destroy(cr);
         osm_gps_map_map_redraw_idle(map);  
     }  
280  }  }
281    
282  /* return true if balloon is being displayed and if */  /* return true if balloon is being displayed and if */
283  /* the given coordinate is within this balloon */  /* the given coordinate is within this balloon */
284  static gboolean  static gboolean
285  osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)  osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
286  {  {
287      return (priv->balloon.valid &&      osd_priv_t *priv = (osd_priv_t*)osd->priv;
             (x > priv->balloon.rect.x) &&  
             (x < priv->balloon.rect.x + priv->balloon.rect.w) &&  
             (y > priv->balloon.rect.y) &&  
             (y < priv->balloon.rect.y + priv->balloon.rect.h));  
 }  
288    
289  #if 0      if(!priv->balloon.surface)
     /* don't drag if the user clicked within the balloon */  
     if (osm_gps_map_in_balloon(priv,  
                    event->x + EXTRA_BORDER,  
                    event->y + EXTRA_BORDER))  
     {  
         priv->drag_counter = -1;  
290          return FALSE;          return FALSE;
     }  
291    
292  #ifdef ENABLE_BALLOON      gint xs, ys;
293      /* released inside the balloon? */      osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
294      if (osm_gps_map_in_balloon(priv,                                        priv->balloon.lat, priv->balloon.lon,
295                     event->x + EXTRA_BORDER,                                        &xs, &ys);
                    event->y + EXTRA_BORDER))  
     {  
         osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),  
              event->x - priv->balloon.rect.x + EXTRA_BORDER,  
              event->y - priv->balloon.rect.y + EXTRA_BORDER);  
     }  
 #endif  
296    
297  #endif      xs += priv->balloon.rect.x + priv->balloon.offset_x;
298        ys += priv->balloon.rect.y + priv->balloon.offset_y;
299    
300  void      gboolean is_in =
301  osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,          (x > xs) && (x < xs + priv->balloon.rect.w) &&
302                            OsmGpsMapBalloonCallback cb, gpointer data)          (y > ys) && (y < ys + priv->balloon.rect.h);
303  {  
304      OsmGpsMapPrivate *priv;      /* handle the fact that the balloon may have been created by the */
305        /* button down event */
306        if(!is_in && !down && !priv->balloon.just_created) {
307            /* the user actually clicked outside the balloon */
308    
309      /* remove and previously installed balloon */          /* close the balloon! */
310      osm_gps_map_clear_balloon (map);          osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
311        }
312    
313        return is_in;
314    }
315    
316    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
317      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
     priv = map->priv;  
318    
319      priv->balloon.lat = latitude;      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
320      priv->balloon.lon = longitude;      g_return_if_fail (osd);
     priv->balloon.valid = TRUE;  
321    
322      priv->balloon.cb = cb;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
323      priv->balloon.data = data;      g_return_if_fail (priv);
324    
325      // this redraws the map      if(priv->balloon.surface) {
326      osm_gps_map_map_redraw_idle(map);          cairo_surface_destroy(priv->balloon.surface);
327            priv->balloon.surface = NULL;
328            priv->balloon.lat = OSM_GPS_MAP_INVALID;
329            priv->balloon.lon = OSM_GPS_MAP_INVALID;
330        }
331        osm_gps_map_redraw(map);
332  }  }
333    
334  void  void
335  osm_gps_map_clear_balloon (OsmGpsMap *map)  osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
336  {                                OsmGpsMapBalloonCallback cb, gpointer data) {
     OsmGpsMapPrivate *priv;  
   
337      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
     priv = map->priv;  
338    
339      priv->balloon.valid = FALSE;      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
340        g_return_if_fail (osd);
     osm_gps_map_map_redraw_idle(map);  
 }  
 #endif  
341    
342  void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {      osd_priv_t *priv = (osd_priv_t*)osd->priv;
343      printf("request to clear balloon\n");      g_return_if_fail (priv);
 }  
344    
345  void      osm_gps_map_osd_clear_balloon (map);
346  osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  
347                                OsmGpsMapBalloonCallback cb, gpointer data)      /* allocate balloon surface */
348  {      priv->balloon.surface =
349      printf("request to draw balloon at %f %f\n", latitude, longitude);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
350                                       BALLOON_W+2, BALLOON_H+2);
351    
352        priv->balloon.lat = latitude;
353        priv->balloon.lon = longitude;
354        priv->balloon.cb = cb;
355        priv->balloon.data = data;
356        priv->balloon.just_created = TRUE;
357    
358        priv->balloon.orientation = -1;
359    
360        osd_render_balloon(osd);
361    
362        osm_gps_map_redraw(map);
363  }  }
364    
365  #endif // OSD_BALLOON  #endif // OSD_BALLOON
# Line 886  osd_source_toggle(osm_gps_map_osd_t *osd Line 874  osd_source_toggle(osm_gps_map_osd_t *osd
874    
875  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
876  static osd_button_t  static osd_button_t
877  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
878      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
879    
880      if(!priv->source_sel.expanded)      if(!priv->source_sel.expanded)
# Line 904  osd_source_check(osm_gps_map_osd_t *osd, Line 892  osd_source_check(osm_gps_map_osd_t *osd,
892          /* really within puller shape? */          /* really within puller shape? */
893          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
894              /* expand source selector */              /* expand source selector */
895              osd_source_toggle(osd);              if(down)
896                    osd_source_toggle(osd);
897    
898              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
899              /* of the OSD */              /* of the OSD */
# Line 930  osd_source_check(osm_gps_map_osd_t *osd, Line 919  osd_source_check(osm_gps_map_osd_t *osd,
919              y /= step;              y /= step;
920              y += 1;              y += 1;
921    
922              gint old = 0;              if(down) {
923              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
924                    g_object_get(osd->widget, "map-source", &old, NULL);
925              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
926                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
927                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
928                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
929                        g_object_set(osd->widget, "map-source", y, NULL);
930                  osd_render_source_sel(osd, TRUE);  
931                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
932                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
933                    }
934              }              }
935    
936              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
# Line 953  osd_source_check(osm_gps_map_osd_t *osd, Line 944  osd_source_check(osm_gps_map_osd_t *osd,
944  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
945    
946  static osd_button_t  static osd_button_t
947  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
948      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
949    
950    #ifdef OSD_BALLOON
951        if(down) {
952            /* needed to handle balloons that are created at click */
953            osd_priv_t *priv = (osd_priv_t*)osd->priv;
954            priv->balloon.just_created = FALSE;
955        }
956    #endif
957    
958  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
959      /* the source selection area is handles internally */      /* the source selection area is handles internally */
960      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
961  #endif  #endif
962    
963      x -= OSD_X;      if(but == OSD_NONE) {
964      y -= OSD_Y;          gint mx = x - OSD_X;
965            gint my = y - OSD_Y;
966      if(OSD_X < 0)  
967          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
968                mx -= (osd->widget->allocation.width - OSD_W);
969      if(OSD_Y < 0)  
970          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
971                my -= (osd->widget->allocation.height - OSD_H);
972      /* first do a rough test for the OSD area. */  
973      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
974      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
975            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
976  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
977          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
978  #endif  #endif
979            }
980    
981          if(but == OSD_NONE)          if(but == OSD_NONE)
982              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
983      }      }
984    
985    #ifdef OSD_BALLOON
986        if(but == OSD_NONE) {
987            /* check if user clicked into balloon */
988            if(osd_balloon_check(osd, down, x, y))
989                but = OSD_BG;
990        }
991    #endif
992    
993      return but;      return but;
994  }  }
995    
# Line 1065  osd_zoom_labels(cairo_t *cr, gint x, gin Line 1072  osd_zoom_labels(cairo_t *cr, gint x, gin
1072  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1073    
1074  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1075  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1076    
1077  /* these can be overwritten with versions that support */  /* these can be overwritten with versions that support */
1078  /* localization */  /* localization */
# Line 1123  static char Line 1130  static char
1130                             c, (int)integral, fractional*60.0);                             c, (int)integral, fractional*60.0);
1131  }  }
1132    
1133    /* render a string at the given screen position */
1134    static int
1135    osd_render_centered_text(cairo_t *cr, int y, int width, char *text) {
1136        char *p = g_strdup(text);
1137        cairo_text_extents_t extents;
1138        cairo_text_extents (cr, p, &extents);
1139    
1140        /* check if text needs to be truncated */
1141        int len = strlen(text)-2;
1142        while(extents.width > width) {
1143            len--;
1144            strcpy(p+len, "...");
1145            cairo_text_extents (cr, p, &extents);
1146        }
1147    
1148        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1149        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1150        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1151        cairo_text_path (cr, p);
1152        cairo_stroke (cr);
1153    
1154        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1155        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1156        cairo_show_text (cr, p);
1157    
1158        g_free(p);
1159    
1160        /* skip + 1/4 line */
1161        return y + 5*OSD_COORDINATES_FONT_SIZE/4;
1162    }
1163    
1164  static void  static void
1165  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1166  {  {
# Line 1158  osd_render_coordinates(osm_gps_map_osd_t Line 1196  osd_render_coordinates(osm_gps_map_osd_t
1196      char *latitude = osd_latitude_str(lat);      char *latitude = osd_latitude_str(lat);
1197      char *longitude = osd_longitude_str(lon);      char *longitude = osd_longitude_str(lon);
1198    
1199      cairo_text_extents_t lat_extents, lon_extents;      int y = OSD_COORDINATES_OFFSET;
1200      cairo_text_extents (cr, latitude, &lat_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude);
1201      cairo_text_extents (cr, longitude, &lon_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude);
1202    
1203        g_free(latitude);
1204        g_free(longitude);
1205    
1206      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_destroy(cr);
1207      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);  }
1208      cairo_move_to (cr,  #endif  // OSD_COORDINATES
                    (OSD_COORDINATES_W - lat_extents.width)/2,  
                    OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
     cairo_text_path (cr, latitude);  
     cairo_move_to (cr,  
                    (OSD_COORDINATES_W - lon_extents.width)/2,  
                    OSD_COORDINATES_OFFSET - lon_extents.y_bearing +  
                    OSD_COORDINATES_FONT_SIZE);  
     cairo_text_path (cr, longitude);  
     cairo_stroke (cr);  
1209    
1210      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);  #ifdef OSD_NAV
1211      cairo_move_to (cr,  #define OSD_NAV_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1212                     (OSD_COORDINATES_W - lat_extents.width)/2,  #define OSD_NAV_H  (100)
1213                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
1214      cairo_show_text (cr, latitude);  static void
1215      cairo_move_to (cr,  osd_render_nav(osm_gps_map_osd_t *osd)
1216                     (OSD_COORDINATES_W - lon_extents.width)/2,  {
1217                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1218                     OSD_COORDINATES_FONT_SIZE);  
1219      cairo_show_text (cr, longitude);      if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon))
1220            return;
1221    
1222        /* first fill with transparency */
1223        cairo_t *cr = cairo_create(priv->nav.surface);
1224        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1225        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1226        cairo_paint(cr);
1227        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1228    
1229        cairo_select_font_face (cr, "Sans",
1230                                CAIRO_FONT_SLANT_NORMAL,
1231                                CAIRO_FONT_WEIGHT_BOLD);
1232        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1233    
1234        char *latitude = osd_latitude_str(priv->nav.lat);
1235        char *longitude = osd_longitude_str(priv->nav.lon);
1236    
1237        int y = OSD_COORDINATES_OFFSET;
1238        y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name);
1239        y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude);
1240        y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude);
1241    
1242      g_free(latitude);      g_free(latitude);
1243      g_free(longitude);      g_free(longitude);
1244    
1245      cairo_destroy(cr);      cairo_destroy(cr);
1246  }  }
1247  #endif  // OSD_COORDINATES  
1248    void osm_gps_map_osd_clear_nav (OsmGpsMap *map) {
1249        g_return_if_fail (OSM_IS_GPS_MAP (map));
1250    
1251        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1252        g_return_if_fail (osd);
1253    
1254        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1255        g_return_if_fail (priv);
1256    
1257        if(priv->nav.surface) {
1258            cairo_surface_destroy(priv->nav.surface);
1259            priv->nav.surface = NULL;
1260            priv->nav.lat = OSM_GPS_MAP_INVALID;
1261            priv->nav.lon = OSM_GPS_MAP_INVALID;
1262            if(priv->nav.name) g_free(priv->nav.name);
1263        }
1264        osm_gps_map_redraw(map);
1265    }
1266    
1267    void
1268    osm_gps_map_osd_draw_nav (OsmGpsMap *map, float latitude, float longitude,
1269                              char *name) {
1270        g_return_if_fail (OSM_IS_GPS_MAP (map));
1271    
1272        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1273        g_return_if_fail (osd);
1274    
1275        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1276        g_return_if_fail (priv);
1277    
1278        osm_gps_map_osd_clear_nav (map);
1279    
1280        /* allocate balloon surface */
1281        priv->nav.surface =
1282            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1283                                       OSD_NAV_W+2, OSD_NAV_H+2);
1284    
1285        priv->nav.lat = latitude;
1286        priv->nav.lon = longitude;
1287        priv->nav.name = g_strdup(name);
1288    
1289        osd_render_nav(osd);
1290    
1291        osm_gps_map_redraw(map);
1292    }
1293    
1294    #endif // OSD_NAV
1295    
1296    
1297  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1298    
# Line 1520  osd_render(osm_gps_map_osd_t *osd) Line 1621  osd_render(osm_gps_map_osd_t *osd)
1621      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1622  #endif  #endif
1623    
1624    #ifdef OSD_NAV
1625        osd_render_nav(osd);
1626    #endif
1627    
1628  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1629      osd_render_coordinates(osd);      osd_render_coordinates(osd);
1630  #endif  #endif
# Line 1579  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1684  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1684      // now draw this onto the original context      // now draw this onto the original context
1685      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1686    
1687      int x, y;      gint x, y;
1688    
1689  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1690      x =  OSD_X;      x =  OSD_X;
# Line 1599  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1704  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1704      cairo_paint(cr);      cairo_paint(cr);
1705  #endif  #endif
1706    
1707    #ifdef OSD_NAV
1708        if(priv->nav.surface) {
1709            x =  OSD_X;
1710            if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1711            y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1712    
1713            cairo_set_source_surface(cr, priv->nav.surface, x, y);
1714            cairo_paint(cr);
1715        }
1716    #endif
1717    
1718  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1719      x = -OSD_X;      x = -OSD_X;
1720      y = -OSD_Y;      y = -OSD_Y;
# Line 1609  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1725  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1725      cairo_paint(cr);      cairo_paint(cr);
1726  #endif  #endif
1727    
1728    #ifdef OSD_BALLOON
1729        if(priv->balloon.surface) {
1730    
1731            /* convert given lat lon into screen coordinates */
1732            gint x, y;
1733            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1734                                          priv->balloon.lat, priv->balloon.lon,
1735                                          &x, &y);
1736    
1737            /* check if balloon needs to be rerendered */
1738            osd_render_balloon(osd);
1739    
1740            cairo_set_source_surface(cr, priv->balloon.surface,
1741                                     x + priv->balloon.offset_x,
1742                                     y + priv->balloon.offset_y);
1743            cairo_paint(cr);
1744        }
1745    #endif
1746    
1747      x = OSD_X;      x = OSD_X;
1748      if(x < 0)      if(x < 0)
1749          x += osd->widget->allocation.width - OSD_W;          x += osd->widget->allocation.width - OSD_W;
# Line 1671  osd_free(osm_gps_map_osd_t *osd) Line 1806  osd_free(osm_gps_map_osd_t *osd)
1806           cairo_surface_destroy(priv->crosshair.surface);           cairo_surface_destroy(priv->crosshair.surface);
1807  #endif  #endif
1808    
1809    #ifdef OSD_NAV
1810        if (priv->nav.surface)
1811             cairo_surface_destroy(priv->nav.surface);
1812    #endif
1813    
1814  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1815      if (priv->coordinates.surface)      if (priv->coordinates.surface)
1816           cairo_surface_destroy(priv->coordinates.surface);           cairo_surface_destroy(priv->coordinates.surface);
# Line 1750  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1890  osm_gps_map_osd_check(OsmGpsMap *map, gi
1890      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1891      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1892    
1893      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1894  }  }

Legend:
Removed from v.112  
changed lines
  Added in v.124