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

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

revision 102 by harbaum, Tue Sep 8 19:08:37 2009 UTC revision 131 by harbaum, Wed Sep 30 19:14:56 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: */
26  /* OSD_DIAMETER */  /* OSD_DIAMETER */
27  /* OSD_X, OSD_Y */  /* OSD_X, OSD_Y */
28    
 #define OSD_SCALE  
   
 #define OSD_SCALE_W  120  
 #define OSD_SCALE_H   20  
   
29  #ifndef USE_CAIRO  #ifndef USE_CAIRO
30  #error "OSD control display lacks a non-cairo implementation!"  #error "OSD control display lacks a non-cairo implementation!"
31  #endif  #endif
# Line 37  Line 33 
33  #include <cairo.h>  #include <cairo.h>
34    
35  #include "osm-gps-map.h"  #include "osm-gps-map.h"
36    #include "converter.h"
37  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
38    
39  //the osd controls  //the osd controls
40  typedef struct {  typedef struct {
41      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
42      cairo_surface_t *overlay;      struct {
43            cairo_surface_t *surface;
44            gboolean rendered;
45    #ifdef OSD_GPS_BUTTON
46            gboolean gps_enabled;
47    #endif
48        } controls;
49    
50    #ifdef OSD_BALLOON
51        //a balloon with additional info
52        struct {
53            cairo_surface_t *surface;
54            int orientation, offset_x, offset_y;
55    
56            gboolean just_created;
57            float lat, lon;
58            OsmGpsMapRect_t rect;
59    
60            /* function called to have the user app draw the contents */
61            OsmGpsMapBalloonCallback cb;
62            gpointer data;
63        } balloon;
64    #endif
65    
66  #ifdef OSD_SCALE  #ifdef OSD_SCALE
67      cairo_surface_t *scale;      struct {
68            cairo_surface_t *surface;
69            int zoom;
70        } scale;
71    #endif
72    
73    #ifdef OSD_CROSSHAIR
74        struct {
75            cairo_surface_t *surface;
76            gboolean rendered;
77        } crosshair;
78    #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
89        struct {
90            cairo_surface_t *surface;
91            float lat, lon;
92        } coordinates;
93  #endif  #endif
94    
95  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
96      /* values to handle the "source" menu */      struct {
97      cairo_surface_t *map_source;          /* values to handle the "source" menu */
98      gboolean expanded;          cairo_surface_t *surface;
99      gint shift, dir, count;          gboolean expanded;
100      gint handler_id;          gint shift, dir, count;
101      gint width, height;          gint handler_id;
102            gint width, height;
103            gboolean rendered;
104        } source_sel;
105  #endif  #endif
106    
107  } osd_priv_t;  } osd_priv_t;
108    
109    #ifdef OSD_BALLOON
110    /* most visual effects are hardcoded by now, but may be made */
111    /* available via properties later */
112    #ifndef BALLOON_AREA_WIDTH
113    #define BALLOON_AREA_WIDTH           290
114    #endif
115    #ifndef BALLOON_AREA_HEIGHT
116    #define BALLOON_AREA_HEIGHT           75
117    #endif
118    #ifndef BALLOON_CORNER_RADIUS
119    #define BALLOON_CORNER_RADIUS         10
120    #endif
121    
122    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
123    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
124    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
125    #define BALLOON_TRANSPARENCY         0.8
126    #define POINTER_HEIGHT                20
127    #define POINTER_FOOT_WIDTH            20
128    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
129    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
130    #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)
136    
137    
138    /* draw the bubble shape. this is used twice, once for the shape and once */
139    /* for the shadow */
140    static void
141    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
142           gboolean bottom, int px, int py, int px0, int px1) {
143    
144        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
145        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
146                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
147        if(!bottom) {
148            /* insert top pointer */
149            cairo_line_to (cr, px1, y0);
150            cairo_line_to (cr, px, py);
151            cairo_line_to (cr, px0, y0);
152        }
153    
154        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
155        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
156                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
157        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
158        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
159                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
160        if(bottom) {
161            /* insert bottom pointer */
162            cairo_line_to (cr, px0, y1);
163            cairo_line_to (cr, px, py);
164            cairo_line_to (cr, px1, y1);
165        }
166    
167        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
168        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
169                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
170    
171        cairo_close_path (cr);
172    }
173    
174    static void
175    osd_render_balloon(osm_gps_map_osd_t *osd) {
176        osd_priv_t *priv = (osd_priv_t*)osd->priv;
177    
178        /* get zoom */
179        gint zoom;
180        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
181    
182        /* ------- convert given coordinate into screen position --------- */
183        gint xs, ys;
184        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
185                                          priv->balloon.lat, priv->balloon.lon,
186                                          &xs, &ys);
187    
188        gint x0 = 1, y0 = 1;
189    
190        /* check position of this relative to screen center to determine */
191        /* pointer direction ... */
192        int pointer_x, pointer_x0, pointer_x1;
193        int pointer_y;
194    
195        /* ... and calculate position */
196        int orientation = 0;
197        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);
201            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
202            orientation |= 1;
203        } else {
204            priv->balloon.offset_x = -POINTER_OFFSET;
205            pointer_x = x0 - priv->balloon.offset_x;
206            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
207            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
208        }
209    
210        gboolean bottom = FALSE;
211        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;
215            orientation |= 2;
216        } else {
217            priv->balloon.offset_y = 0;
218            pointer_y = y0 - priv->balloon.offset_y;
219            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 */
230        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
231    
232        /* save balloon screen coordinates for later use */
233        priv->balloon.rect.x = x0 + BALLOON_BORDER;
234        priv->balloon.rect.y = y0 + BALLOON_BORDER;
235        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
236        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
237    
238        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 --------------- */
245        osm_gps_map_draw_balloon_shape (cr,
246                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
247                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
248                     bottom, pointer_x, pointer_y,
249                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
250    
251        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
252        cairo_fill_preserve (cr);
253        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
254        cairo_set_line_width (cr, 0);
255        cairo_stroke (cr);
256    
257        /* --------- draw main shape ----------- */
258        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
259                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
260    
261        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
262        cairo_fill_preserve (cr);
263        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
264        cairo_set_line_width (cr, 1);
265        cairo_stroke (cr);
266    
267        if (priv->balloon.cb) {
268            /* clip in case application tries to draw in */
269                /* exceed of the balloon */
270            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
271                             priv->balloon.rect.w, priv->balloon.rect.h);
272            cairo_clip (cr);
273            cairo_new_path (cr);  /* current path is not
274                                     consumed by cairo_clip() */
275    
276            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
277        }
278    
279        cairo_destroy(cr);
280    }
281    
282    /* return true if balloon is being displayed and if */
283    /* the given coordinate is within this balloon */
284    static gboolean
285    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
286    {
287        osd_priv_t *priv = (osd_priv_t*)osd->priv;
288    
289        if(!priv->balloon.surface)
290            return FALSE;
291    
292        gint xs, ys;
293        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
294                                          priv->balloon.lat, priv->balloon.lon,
295                                          &xs, &ys);
296    
297        xs += priv->balloon.rect.x + priv->balloon.offset_x;
298        ys += priv->balloon.rect.y + priv->balloon.offset_y;
299    
300        gboolean is_in =
301            (x > xs) && (x < xs + priv->balloon.rect.w) &&
302            (y > ys) && (y < ys + priv->balloon.rect.h);
303    
304        /* 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            /* close the balloon! */
310            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));
318    
319        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
320        g_return_if_fail (osd);
321    
322        osd_priv_t *priv = (osd_priv_t*)osd->priv;
323        g_return_if_fail (priv);
324    
325        if(priv->balloon.surface) {
326            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
335    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
336                                  OsmGpsMapBalloonCallback cb, gpointer data) {
337        g_return_if_fail (OSM_IS_GPS_MAP (map));
338    
339        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
340        g_return_if_fail (osd);
341    
342        osd_priv_t *priv = (osd_priv_t*)osd->priv;
343        g_return_if_fail (priv);
344    
345        osm_gps_map_osd_clear_balloon (map);
346    
347        /* allocate balloon surface */
348        priv->balloon.surface =
349            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
366    
367  /* position and extent of bounding box */  /* position and extent of bounding box */
368  #ifndef OSD_X  #ifndef OSD_X
369  #define OSD_X      (10)  #define OSD_X      (10)
# Line 281  osd_check_zoom(gint x, gint y) { Line 586  osd_check_zoom(gint x, gint y) {
586  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
587    
588  /* size of usable area when expanded */  /* size of usable area when expanded */
589  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
590  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
591  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
592  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
593    
# Line 298  osd_check_zoom(gint x, gint y) { Line 603  osd_check_zoom(gint x, gint y) {
603  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
604  static void  static void
605  osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {  osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
606      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
607          /* just draw the puller */          /* just draw the puller */
608          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
609          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
# Line 326  osd_source_content(osm_gps_map_osd_t *os Line 631  osd_source_content(osm_gps_map_osd_t *os
631    
632      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
633    
634      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
635          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
636          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);
637          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
# Line 351  osd_source_content(osm_gps_map_osd_t *os Line 656  osd_source_content(osm_gps_map_osd_t *os
656                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
657              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
658    
659              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
660                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
661              for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {              for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
662                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 365  osd_source_content(osm_gps_map_osd_t *os Line 670  osd_source_content(osm_gps_map_osd_t *os
670                  if(source == i) {                  if(source == i) {
671                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
672                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
673                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
674                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
675                      cairo_fill(cr);                      cairo_fill(cr);
676    
# Line 396  osd_source_content(osm_gps_map_osd_t *os Line 701  osd_source_content(osm_gps_map_osd_t *os
701  }  }
702    
703  static void  static void
704  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
705      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
706    
707        if(priv->source_sel.rendered && !force_rerender)
708            return;
709    
710        priv->source_sel.rendered = TRUE;
711    
712  #ifndef OSD_COLOR  #ifndef OSD_COLOR
713      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
714      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 406  osd_render_source_sel(osm_gps_map_osd_t Line 716  osd_render_source_sel(osm_gps_map_osd_t
716  #endif  #endif
717    
718      /* draw source selector */      /* draw source selector */
719      cairo_t *cr = cairo_create(priv->map_source);      cairo_t *cr = cairo_create(priv->source_sel.surface);
720      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
721      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
722      cairo_paint(cr);      cairo_paint(cr);
# Line 447  osd_source_reallocate(osm_gps_map_osd_t Line 757  osd_source_reallocate(osm_gps_map_osd_t
757      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
758    
759      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
760      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
761    
762      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
763      if(priv->expanded) {      if(priv->source_sel.expanded) {
764          cairo_text_extents_t extents;          cairo_text_extents_t extents;
765    
766          /* determine content size */          /* determine content size */
767          cairo_t *cr = cairo_create(priv->map_source);          cairo_t *cr = cairo_create(priv->source_sel.surface);
768          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
769                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
770                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 471  osd_source_reallocate(osm_gps_map_osd_t Line 781  osd_source_reallocate(osm_gps_map_osd_t
781          }          }
782          cairo_destroy(cr);          cairo_destroy(cr);
783    
784          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
785          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
786              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
787    
788          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
789          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
790      }      }
791    
792      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
793      priv->map_source =      priv->source_sel.surface =
794          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
795    
796      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
797  }  }
798    
799  #define OSD_HZ      15  #define OSD_HZ      15
# Line 494  static gboolean osd_source_animate(gpoin Line 804  static gboolean osd_source_animate(gpoin
804      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
805      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
806      gboolean done = FALSE;      gboolean done = FALSE;
807      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
808    
809      /* shifting in */      /* shifting in */
810      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
811          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
812              priv->count = 0;              priv->source_sel.count = 0;
813              done = TRUE;              done = TRUE;
814          }          }
815      } else {      } else {
816          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
817              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
818              osd_source_reallocate(osd);              osd_source_reallocate(osd);
819    
820              priv->count = 1000;              priv->source_sel.count = 1000;
821              done = TRUE;              done = TRUE;
822          }          }
823      }      }
# Line 515  static gboolean osd_source_animate(gpoin Line 825  static gboolean osd_source_animate(gpoin
825    
826      /* count runs linearly from 0 to 1000, map this nicely onto a position */      /* count runs linearly from 0 to 1000, map this nicely onto a position */
827    
828      /* nicer sinoid mapping */      /* nice sinoid mapping */
829      float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;      float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
830      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
831            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
832          m * diff;          m * diff;
833    
834        /* make sure the screen is updated */
835      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
836    
837        /* stop animation if done */
838      if(done)      if(done)
839          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
840    
841      return !done;      return !done;
842  }  }
# Line 535  osd_source_toggle(osm_gps_map_osd_t *osd Line 848  osd_source_toggle(osm_gps_map_osd_t *osd
848      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
849    
850      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
851      if(priv->handler_id)      if(priv->source_sel.handler_id)
852          return;          return;
853    
854      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
855      if(!priv->expanded) {      /* collapse animation */
856          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
857            priv->source_sel.expanded = TRUE;
858          osd_source_reallocate(osd);          osd_source_reallocate(osd);
859    
860          priv->count = 1000;          priv->source_sel.count = 1000;
861          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
862          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
863      } else {      } else {
864          priv->count =  0;          priv->source_sel.count =  0;
865          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
866          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
867            priv->source_sel.dir = +1000/OSD_HZ;
868      }      }
869    
870      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
871        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
872                                                      osd_source_animate, osd);
873  }  }
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->expanded)      if(!priv->source_sel.expanded)
881          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
882      else      else
883          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
# Line 575  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 584  osd_source_check(osm_gps_map_osd_t *osd, Line 902  osd_source_check(osm_gps_map_osd_t *osd,
902      }      }
903    
904      /* check for clicks into data area */      /* check for clicks into data area */
905      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
906          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
907          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
908              y += OSD_S_EXP_H - OSD_S_PH;              y += OSD_S_EXP_H - OSD_S_PH;
# Line 594  osd_source_check(osm_gps_map_osd_t *osd, Line 912  osd_source_check(osm_gps_map_osd_t *osd,
912             y > 0 &&             y > 0 &&
913             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
914    
915              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
916                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
917    
918              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
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);  
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 624  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 727  osd_zoom_labels(cairo_t *cr, gint x, gin Line 1063  osd_zoom_labels(cairo_t *cr, gint x, gin
1063      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1064  }  }
1065    
1066  static char *  #ifdef OSD_COORDINATES
1067  dist_str_metric(int dist)  
1068    #ifndef OSD_COORDINATES_FONT_SIZE
1069    #define OSD_COORDINATES_FONT_SIZE 12
1070    #endif
1071    
1072    #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1073    
1074    #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1075    #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET+OSD_COORDINATES_FONT_SIZE/4)
1076    
1077    /* these can be overwritten with versions that support */
1078    /* localization */
1079    #ifndef OSD_COORDINATES_CHR_N
1080    #define OSD_COORDINATES_CHR_N  "N"
1081    #endif
1082    #ifndef OSD_COORDINATES_CHR_S
1083    #define OSD_COORDINATES_CHR_S  "S"
1084    #endif
1085    #ifndef OSD_COORDINATES_CHR_E
1086    #define OSD_COORDINATES_CHR_E  "E"
1087    #endif
1088    #ifndef OSD_COORDINATES_CHR_W
1089    #define OSD_COORDINATES_CHR_W  "W"
1090    #endif
1091    
1092    
1093    
1094    /* this is the classic geocaching notation */
1095    static char
1096    *osd_latitude_str(float latitude) {
1097        char *c = OSD_COORDINATES_CHR_N;
1098        float integral, fractional;
1099    
1100        if(isnan(latitude))
1101            return NULL;
1102    
1103        if(latitude < 0) {
1104            latitude = fabs(latitude);
1105            c = OSD_COORDINATES_CHR_S;
1106        }
1107    
1108        fractional = modff(latitude, &integral);
1109    
1110        return g_strdup_printf("%s %02d° %06.3f'",
1111                               c, (int)integral, fractional*60.0);
1112    }
1113    
1114    static char
1115    *osd_longitude_str(float longitude) {
1116        char *c = OSD_COORDINATES_CHR_E;
1117        float integral, fractional;
1118    
1119        if(isnan(longitude))
1120            return NULL;
1121    
1122        if(longitude < 0) {
1123            longitude = fabs(longitude);
1124            c = OSD_COORDINATES_CHR_W;
1125        }
1126    
1127        fractional = modff(longitude, &integral);
1128    
1129        return g_strdup_printf("%s %03d° %06.3f'",
1130                               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
1165    osd_render_coordinates(osm_gps_map_osd_t *osd)
1166    {
1167        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1168    
1169        /* get current map position */
1170        gfloat lat, lon;
1171        g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1172    
1173        /* check if position has changed enough to require redraw */
1174        if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1175            /* 1/60000 == 1/1000 minute */
1176            if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1177               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1178                return;
1179    
1180        priv->coordinates.lat = lat;
1181        priv->coordinates.lon = lon;
1182    
1183        /* first fill with transparency */
1184        cairo_t *cr = cairo_create(priv->coordinates.surface);
1185        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1186        //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
1187        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1188        cairo_paint(cr);
1189        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1190    
1191        cairo_select_font_face (cr, "Sans",
1192                                CAIRO_FONT_SLANT_NORMAL,
1193                                CAIRO_FONT_WEIGHT_BOLD);
1194        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1195    
1196        char *latitude = osd_latitude_str(lat);
1197        char *longitude = osd_longitude_str(lon);
1198    
1199        int y = OSD_COORDINATES_OFFSET;
1200        y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude);
1201        y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude);
1202    
1203        g_free(latitude);
1204        g_free(longitude);
1205    
1206        cairo_destroy(cr);
1207    }
1208    #endif  // OSD_COORDINATES
1209    
1210    #ifdef OSD_NAV
1211    #define OSD_NAV_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1212    #define OSD_NAV_H  (150)
1213    
1214    static void
1215    osd_render_nav(osm_gps_map_osd_t *osd)
1216    {
1217        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1218    
1219        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);
1243        g_free(longitude);
1244    
1245        /* draw the compass */
1246        int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2;
1247        if(radius > OSD_NAV_W/2)
1248            radius = OSD_NAV_W/2;
1249    
1250        int x = OSD_NAV_W/2+1;
1251        y += radius;
1252    
1253        cairo_stroke (cr);
1254    
1255        /* draw background */
1256        cairo_arc(cr, x, y, radius, 0,  2*M_PI);
1257        cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
1258        cairo_fill_preserve (cr);
1259        cairo_set_source_rgb (cr, 0, 0, 0);
1260        cairo_set_line_width (cr, 1);
1261        cairo_stroke (cr);
1262    
1263        /* draw pointer */
1264    #define ARROW_WIDTH     0.3
1265    #define ARROW_LENGTH    0.7
1266    
1267        float arot = deg2rad(45);
1268    
1269        cairo_move_to(cr,
1270                      x + radius *  ARROW_LENGTH *  sin(arot),
1271                      y + radius *  ARROW_LENGTH * -cos(arot));
1272    
1273        cairo_line_to(cr,
1274                      x + radius * -ARROW_LENGTH *  sin(arot+ARROW_WIDTH),
1275                      y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH));
1276    
1277        cairo_line_to(cr,
1278                      x + radius * -0.5 * ARROW_LENGTH *  sin(arot),
1279                      y + radius * -0.5 * ARROW_LENGTH * -cos(arot));
1280    
1281        cairo_line_to(cr,
1282                      x + radius * -ARROW_LENGTH *  sin(arot-ARROW_WIDTH),
1283                      y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH));
1284    
1285        cairo_close_path(cr);
1286        cairo_set_source_rgb (cr, 0, 0, 0);
1287        cairo_fill (cr);
1288    
1289        y += radius + OSD_COORDINATES_FONT_SIZE/4;
1290        y = osd_render_centered_text(cr, y, OSD_NAV_W, "xx,xx km");
1291    
1292        cairo_destroy(cr);
1293    }
1294    
1295    void osm_gps_map_osd_clear_nav (OsmGpsMap *map) {
1296        g_return_if_fail (OSM_IS_GPS_MAP (map));
1297    
1298        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1299        g_return_if_fail (osd);
1300    
1301        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1302        g_return_if_fail (priv);
1303    
1304        if(priv->nav.surface) {
1305            cairo_surface_destroy(priv->nav.surface);
1306            priv->nav.surface = NULL;
1307            priv->nav.lat = OSM_GPS_MAP_INVALID;
1308            priv->nav.lon = OSM_GPS_MAP_INVALID;
1309            if(priv->nav.name) g_free(priv->nav.name);
1310        }
1311        osm_gps_map_redraw(map);
1312    }
1313    
1314    void
1315    osm_gps_map_osd_draw_nav (OsmGpsMap *map, float latitude, float longitude,
1316                              char *name) {
1317        g_return_if_fail (OSM_IS_GPS_MAP (map));
1318    
1319        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1320        g_return_if_fail (osd);
1321    
1322        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1323        g_return_if_fail (priv);
1324    
1325        osm_gps_map_osd_clear_nav (map);
1326    
1327        /* allocate balloon surface */
1328        priv->nav.surface =
1329            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1330                                       OSD_NAV_W+2, OSD_NAV_H+2);
1331    
1332        priv->nav.lat = latitude;
1333        priv->nav.lon = longitude;
1334        priv->nav.name = g_strdup(name);
1335    
1336        osd_render_nav(osd);
1337    
1338        osm_gps_map_redraw(map);
1339    }
1340    
1341    #endif // OSD_NAV
1342    
1343    
1344    #ifdef OSD_CROSSHAIR
1345    
1346    #ifndef OSD_CROSSHAIR_RADIUS
1347    #define OSD_CROSSHAIR_RADIUS 10
1348    #endif
1349    
1350    #define OSD_CROSSHAIR_TICK  (OSD_CROSSHAIR_RADIUS/2)
1351    #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4)
1352    #define OSD_CROSSHAIR_W  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
1353    #define OSD_CROSSHAIR_H  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
1354    
1355    static void
1356    osd_render_crosshair_shape(cairo_t *cr) {
1357        cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
1358                   OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
1359    
1360        cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS,
1361                       OSD_CROSSHAIR_H/2);
1362        cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0);
1363        cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS,
1364                       OSD_CROSSHAIR_H/2);
1365        cairo_rel_line_to (cr,  OSD_CROSSHAIR_TICK, 0);
1366    
1367        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1368                       OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS);
1369        cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK);
1370        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1371                       OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS);
1372        cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
1373    
1374        cairo_stroke (cr);
1375    }
1376    
1377    static void
1378    osd_render_crosshair(osm_gps_map_osd_t *osd)
1379  {  {
1380      if(dist<1000)      osd_priv_t *priv = (osd_priv_t*)osd->priv;
         return g_strdup_printf("%u m",  dist);  
1381    
1382      return g_strdup_printf("%u km", dist/1000);      if(priv->crosshair.rendered)
1383            return;
1384    
1385        priv->crosshair.rendered = TRUE;
1386    
1387        /* first fill with transparency */
1388        cairo_t *cr = cairo_create(priv->crosshair.surface);
1389        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1390        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1391        cairo_paint(cr);
1392        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1393    
1394        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1395    
1396        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
1397        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2);
1398        osd_render_crosshair_shape(cr);
1399    
1400        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
1401        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4);
1402        osd_render_crosshair_shape(cr);
1403    
1404        cairo_destroy(cr);
1405  }  }
1406    #endif
1407    
1408    #ifdef OSD_SCALE
1409    
1410    #ifndef OSD_SCALE_FONT_SIZE
1411  #define OSD_SCALE_FONT_SIZE 12  #define OSD_SCALE_FONT_SIZE 12
1412    #endif
1413    #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)
1414    #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)
1415    
1416    /* various parameters used to create the scale */
1417    #define OSD_SCALE_H2   (OSD_SCALE_H/2)
1418    #define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3)
1419    #define OSD_SCALE_M    (OSD_SCALE_H2 - OSD_SCALE_TICK)
1420    #define OSD_SCALE_I    (OSD_SCALE_H2 + OSD_SCALE_TICK)
1421    #define OSD_SCALE_FD   (OSD_SCALE_FONT_SIZE/4)
1422    
1423  static void  static void
1424  osd_render_scale(osm_gps_map_osd_t *osd)  osd_render_scale(osm_gps_map_osd_t *osd)
1425  {  {
1426      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1427    
1428        /* this only needs to be rendered if the zoom has changed */
1429        gint zoom;
1430        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1431        if(zoom == priv->scale.zoom)
1432            return;
1433    
1434        priv->scale.zoom = zoom;
1435    
1436      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
1437    
1438      /* first fill with transparency */      /* first fill with transparency */
1439      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale.surface);
1440      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1441      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1442      //    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1443      cairo_paint(cr);      cairo_paint(cr);
1444      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1445    
1446      /* determine the size of the scale width in meters */      /* determine the size of the scale width in meters */
1447      float width = (OSD_SCALE_W-2) * m_per_pix;      float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix;
     printf("%d pixels is %f m\n", OSD_SCALE_W-2, width);  
1448    
1449      /* scale this to useful values */      /* scale this to useful values */
1450      int exp = logf(width)*M_LOG10E;      int exp = logf(width)*M_LOG10E;
1451      int mant = width/pow(10,exp);      int mant = width/pow(10,exp);
1452      int width_metric = mant * pow(10,exp);      int width_metric = mant * pow(10,exp);
1453      char *dist_str = dist_str_metric(width_metric);      char *dist_str = NULL;
1454        if(width_metric<1000)
1455            dist_str = g_strdup_printf("%u m", width_metric);
1456        else
1457            dist_str = g_strdup_printf("%u km", width_metric/1000);
1458      width_metric /= m_per_pix;      width_metric /= m_per_pix;
1459    
1460      /* and now the hard part: scale for useful imperial values :-( */      /* and now the hard part: scale for useful imperial values :-( */
# Line 783  osd_render_scale(osm_gps_map_osd_t *osd) Line 1477  osd_render_scale(osm_gps_map_osd_t *osd)
1477          }          }
1478      }      }
1479    
1480      printf("this is %f %s\n", width, dist_imp_unit);      /* also convert this to full tens/hundreds */
1481      printf("this is %f pixels\n", width * imp_scale / m_per_pix);      exp = logf(width)*M_LOG10E;
1482        mant = width/pow(10,exp);
1483        int width_imp = mant * pow(10,exp);
1484        char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit);
1485    
1486        /* convert back to pixels */
1487        width_imp *= imp_scale;
1488        width_imp /= m_per_pix;
1489    
1490      cairo_select_font_face (cr, "Sans",      cairo_select_font_face (cr, "Sans",
1491                              CAIRO_FONT_SLANT_NORMAL,                              CAIRO_FONT_SLANT_NORMAL,
# Line 796  osd_render_scale(osm_gps_map_osd_t *osd) Line 1497  osd_render_scale(osm_gps_map_osd_t *osd)
1497      cairo_text_extents (cr, dist_str, &extents);      cairo_text_extents (cr, dist_str, &extents);
1498    
1499      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1500      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE);      cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1501        cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1502      cairo_text_path (cr, dist_str);      cairo_text_path (cr, dist_str);
1503      cairo_set_line_width (cr, 2);      cairo_stroke (cr);
1504        cairo_move_to (cr, 2*OSD_SCALE_FD,
1505                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1506        cairo_text_path (cr, dist_str_imp);
1507      cairo_stroke (cr);      cairo_stroke (cr);
1508    
1509      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1510      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE);      cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1511      cairo_show_text (cr, dist_str);      cairo_show_text (cr, dist_str);
1512        cairo_move_to (cr, 2*OSD_SCALE_FD,
1513                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1514        cairo_show_text (cr, dist_str_imp);
1515    
1516        g_free(dist_str);
1517        g_free(dist_str_imp);
1518    
1519      /* draw white line */      /* draw white line */
1520      cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);      cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1521      cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);      cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
1522      cairo_set_line_width (cr, 4);      cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3);
1523      cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3);      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1524      cairo_rel_line_to (cr, 0,  2*OSD_SCALE_FONT_SIZE/3);      cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1525      cairo_rel_line_to (cr, width_metric, 0);      cairo_rel_line_to (cr, width_metric, 0);
1526      cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3);      cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1527        cairo_stroke(cr);
1528        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1529        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1530        cairo_rel_line_to (cr, width_imp, 0);
1531        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1532      cairo_stroke(cr);      cairo_stroke(cr);
1533    
1534      /* draw black line */      /* draw black line */
1535      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
1536      cairo_set_line_width (cr, 2);      cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1537      cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3);      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1538      cairo_rel_line_to (cr, 0,  2*OSD_SCALE_FONT_SIZE/3);      cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1539      cairo_rel_line_to (cr, width_metric, 0);      cairo_rel_line_to (cr, width_metric, 0);
1540      cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3);      cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1541        cairo_stroke(cr);
1542        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1543        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1544        cairo_rel_line_to (cr, width_imp, 0);
1545        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1546      cairo_stroke(cr);      cairo_stroke(cr);
   
     /* xyz */  
1547    
1548      cairo_destroy(cr);      cairo_destroy(cr);
1549  }  }
1550    #endif
1551    
1552  static void  static void
1553  osd_render(osm_gps_map_osd_t *osd)  osd_render_controls(osm_gps_map_osd_t *osd)
1554  {  {
1555      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1556    
1557        if(priv->controls.rendered
1558    #ifdef OSD_GPS_BUTTON
1559           && (priv->controls.gps_enabled == (osd->cb != NULL))
1560    #endif
1561           )
1562            return;
1563    
1564    #ifdef OSD_GPS_BUTTON
1565        priv->controls.gps_enabled = (osd->cb != NULL);
1566    #endif
1567        priv->controls.rendered = TRUE;
1568    
1569  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1570      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
1571      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 841  osd_render(osm_gps_map_osd_t *osd) Line 1573  osd_render(osm_gps_map_osd_t *osd)
1573  #endif  #endif
1574    
1575      /* first fill with transparency */      /* first fill with transparency */
1576      cairo_t *cr = cairo_create(priv->overlay);      cairo_t *cr = cairo_create(priv->controls.surface);
1577      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1578      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1579      cairo_paint(cr);      cairo_paint(cr);
# Line 912  osd_render(osm_gps_map_osd_t *osd) Line 1644  osd_render(osm_gps_map_osd_t *osd)
1644      cairo_stroke(cr);      cairo_stroke(cr);
1645    
1646      cairo_destroy(cr);      cairo_destroy(cr);
1647    }
1648    
1649    static void
1650    osd_render(osm_gps_map_osd_t *osd)
1651    {
1652        /* this function is actually called pretty often since the */
1653        /* OSD contents may have changed (due to a coordinate/zoom change). */
1654        /* The different OSD parts have to make sure that they don't */
1655        /* render unneccessarily often and thus waste CPU power */
1656    
1657        osd_render_controls(osd);
1658    
1659  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1660      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1661  #endif  #endif
1662    
1663  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1664      osd_render_scale(osd);      osd_render_scale(osd);
1665  #endif  #endif
1666    
1667    #ifdef OSD_CROSSHAIR
1668        osd_render_crosshair(osd);
1669    #endif
1670    
1671    #ifdef OSD_NAV
1672        osd_render_nav(osd);
1673    #endif
1674    
1675    #ifdef OSD_COORDINATES
1676        osd_render_coordinates(osd);
1677    #endif
1678  }  }
1679    
1680  static void  static void
# Line 929  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1684  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1684    
1685      /* OSD itself uses some off-screen rendering, so check if the */      /* OSD itself uses some off-screen rendering, so check if the */
1686      /* offscreen buffer is present and create it if not */      /* offscreen buffer is present and create it if not */
1687      if(!priv->overlay) {      if(!priv->controls.surface) {
1688          /* create overlay ... */          /* create overlay ... */
1689          priv->overlay =          priv->controls.surface =
1690              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
1691    
1692            priv->controls.rendered = FALSE;
1693    #ifdef OSD_GPS_BUTTON
1694            priv->controls.gps_enabled = FALSE;
1695    #endif
1696    
1697  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1698          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1699          priv->map_source =          priv->source_sel.surface =
1700              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1701                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1702            priv->source_sel.rendered = FALSE;
1703  #endif  #endif
1704    
1705  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1706          priv->scale =          priv->scale.surface =
1707                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1708                                           OSD_SCALE_W, OSD_SCALE_H);
1709            priv->scale.zoom = -1;
1710    #endif
1711    
1712    #ifdef OSD_CROSSHAIR
1713            priv->crosshair.surface =
1714                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1715                                           OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1716            priv->crosshair.rendered = FALSE;
1717    #endif
1718    
1719    #ifdef OSD_COORDINATES
1720            priv->coordinates.surface =
1721              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1722                                         OSD_SCALE_W+2, OSD_SCALE_H+2);                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1723    
1724            priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1725  #endif  #endif
1726    
1727          /* ... and render it */          /* ... and render it */
# Line 954  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1731  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1731      // now draw this onto the original context      // now draw this onto the original context
1732      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1733    
1734      int x = OSD_X, y = OSD_Y;      gint x, y;
1735      if(OSD_X < 0)  
1736          x = osd->widget->allocation.width - OSD_W + OSD_X;  #ifdef OSD_SCALE
1737        x =  OSD_X;
1738        y = -OSD_Y;
1739        if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1740        if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1741    
1742        cairo_set_source_surface(cr, priv->scale.surface, x, y);
1743        cairo_paint(cr);
1744    #endif
1745    
1746    #ifdef OSD_CROSSHAIR
1747        x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1748        y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1749    
1750        cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1751        cairo_paint(cr);
1752    #endif
1753    
1754    #ifdef OSD_NAV
1755        if(priv->nav.surface) {
1756            x =  OSD_X;
1757            if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1758            y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1759    
1760            cairo_set_source_surface(cr, priv->nav.surface, x, y);
1761            cairo_paint(cr);
1762        }
1763    #endif
1764    
1765    #ifdef OSD_COORDINATES
1766        x = -OSD_X;
1767        y = -OSD_Y;
1768        if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1769        if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1770    
1771        cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1772        cairo_paint(cr);
1773    #endif
1774    
1775    #ifdef OSD_BALLOON
1776        if(priv->balloon.surface) {
1777    
1778            /* convert given lat lon into screen coordinates */
1779            gint x, y;
1780            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1781                                          priv->balloon.lat, priv->balloon.lon,
1782                                          &x, &y);
1783    
1784            /* check if balloon needs to be rerendered */
1785            osd_render_balloon(osd);
1786    
1787            cairo_set_source_surface(cr, priv->balloon.surface,
1788                                     x + priv->balloon.offset_x,
1789                                     y + priv->balloon.offset_y);
1790            cairo_paint(cr);
1791        }
1792    #endif
1793    
1794      if(OSD_Y < 0)      x = OSD_X;
1795          y = osd->widget->allocation.height - OSD_H + OSD_Y;      if(x < 0)
1796            x += osd->widget->allocation.width - OSD_W;
1797    
1798        y = OSD_Y;
1799        if(y < 0)
1800            y += osd->widget->allocation.height - OSD_H;
1801    
1802      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->controls.surface, x, y);
1803      cairo_paint(cr);      cairo_paint(cr);
1804    
1805  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1806      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
1807          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
1808          if(!priv->expanded)          if(!priv->source_sel.expanded)
1809              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
1810          else          else
1811              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1812      } else      } else
1813          x = priv->shift;          x = priv->source_sel.shift;
1814    
1815      y = OSD_S_Y;      y = OSD_S_Y;
1816      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
1817          if(!priv->expanded)          if(!priv->source_sel.expanded)
1818              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1819          else          else
1820              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1821      }      }
1822    
1823      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
     cairo_paint(cr);  
 #endif  
   
 #ifdef OSD_SCALE  
     x =  OSD_X;  
     y = -OSD_Y;  
     if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;  
     if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;  
   
     cairo_set_source_surface(cr, priv->scale, x, y);  
1824      cairo_paint(cr);      cairo_paint(cr);
1825  #endif  #endif
1826    
# Line 1004  osd_free(osm_gps_map_osd_t *osd) Line 1832  osd_free(osm_gps_map_osd_t *osd)
1832  {  {
1833      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1834    
1835      if (priv->overlay)      if (priv->controls.surface)
1836           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->controls.surface);
1837    
1838  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1839      if(priv->handler_id)      if(priv->source_sel.handler_id)
1840          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
1841    
1842      if (priv->map_source)      if (priv->source_sel.surface)
1843           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
1844  #endif  #endif
1845    
1846  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1847      if (priv->scale)      if (priv->scale.surface)
1848           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
1849    #endif
1850    
1851    #ifdef OSD_CROSSHAIR
1852        if (priv->crosshair.surface)
1853             cairo_surface_destroy(priv->crosshair.surface);
1854    #endif
1855    
1856    #ifdef OSD_NAV
1857        if (priv->nav.surface)
1858             cairo_surface_destroy(priv->nav.surface);
1859    #endif
1860    
1861    #ifdef OSD_COORDINATES
1862        if (priv->coordinates.surface)
1863             cairo_surface_destroy(priv->coordinates.surface);
1864    #endif
1865    
1866    #ifdef OSD_BALLOON
1867        if (priv->balloon.surface)
1868             cairo_surface_destroy(priv->balloon.surface);
1869  #endif  #endif
1870    
1871      g_free(priv);      g_free(priv);
# Line 1028  osd_busy(osm_gps_map_osd_t *osd) Line 1876  osd_busy(osm_gps_map_osd_t *osd)
1876  {  {
1877  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1878      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1879      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
1880  #else  #else
1881      return FALSE;      return FALSE;
1882  #endif  #endif
# Line 1055  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1903  osm_gps_map_osd_classic_init(OsmGpsMap *
1903  {  {
1904      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);
1905    
1906    #ifdef OSD_BALLOON
1907        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1908        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1909    #endif
1910    
1911      osd_classic.priv = priv;      osd_classic.priv = priv;
1912    
1913      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
# Line 1084  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1937  osm_gps_map_osd_check(OsmGpsMap *map, gi
1937      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1938      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1939    
1940      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1941  }  }

Legend:
Removed from v.102  
changed lines
  Added in v.131