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

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

revision 70 by harbaum, Thu Aug 20 19:17:23 2009 UTC revision 122 by harbaum, Mon Sep 21 13:15:25 2009 UTC
# Line 1  Line 1 
1    /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */
2    /* vim:set et sw=4 ts=4 cino=t0,(0: */
3  /*  /*
4   * Copyright (C) Till Harbaum 2009 <till@harbaum.org>   * Copyright (C) Till Harbaum 2009 <till@harbaum.org>
5   *   *
# Line 15  Line 17 
17   * with this program.  If not, see <http://www.gnu.org/licenses/>.   * with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */   */
19    
20  #include "config.h"  #include "config.h"
21    #include <stdlib.h>  // abs
22    #include <math.h>    // M_PI/cos()
23    
24    /* parameters that can be overwritten from the config file: */
25    /* OSD_DIAMETER */
26    /* OSD_X, OSD_Y */
27    
28  #ifdef USE_CAIRO  #define OSD_NAV
29  #include <cairo.h>  
30    #ifndef USE_CAIRO
31    #error "OSD control display lacks a non-cairo implementation!"
32  #endif  #endif
33    
34    #include <cairo.h>
35    
36    #include "osm-gps-map.h"
37    #include "converter.h"
38    #include "osm-gps-map-osd-classic.h"
39    
40  //the osd controls  //the osd controls
41  typedef struct {  typedef struct {
42      GdkPixmap *backup;      /* the offscreen representation of the OSD */
43      cairo_surface_t *overlay;      struct {
44      gint backup_x, backup_y;          cairo_surface_t *surface;
45      OsmGpsMapOsdGpsCallback cb;          gboolean rendered;
46      gpointer data;  #ifdef OSD_GPS_BUTTON
47            gboolean gps_enabled;
48    #endif
49        } controls;
50    
51    #ifdef OSD_BALLOON
52        //a balloon with additional info
53        struct {
54            cairo_surface_t *surface;
55            int orientation, offset_x, offset_y;
56    
57            gboolean just_created;
58            float lat, lon;
59            OsmGpsMapRect_t rect;
60    
61            /* function called to have the user app draw the contents */
62            OsmGpsMapBalloonCallback cb;
63            gpointer data;
64        } balloon;
65    #endif
66    
67    #ifdef OSD_SCALE
68        struct {
69            cairo_surface_t *surface;
70            int zoom;
71        } scale;
72    #endif
73    
74    #ifdef OSD_CROSSHAIR
75        struct {
76            cairo_surface_t *surface;
77            gboolean rendered;
78        } crosshair;
79    #endif
80    
81    #ifdef OSD_NAV
82        struct {
83            cairo_surface_t *surface;
84        } nav;
85    #endif
86    
87    #ifdef OSD_COORDINATES
88        struct {
89            cairo_surface_t *surface;
90            float lat, lon;
91        } coordinates;
92    #endif
93    
94    #ifdef OSD_SOURCE_SEL
95        struct {
96            /* values to handle the "source" menu */
97            cairo_surface_t *surface;
98            gboolean expanded;
99            gint shift, dir, count;
100            gint handler_id;
101            gint width, height;
102            gboolean rendered;
103        } source_sel;
104    #endif
105    
106  } osd_priv_t;  } osd_priv_t;
107    
108  typedef struct {  #ifdef OSD_BALLOON
109    /* most visual effects are hardcoded by now, but may be made */
110    /* available via properties later */
111    #ifndef BALLOON_AREA_WIDTH
112    #define BALLOON_AREA_WIDTH           290
113    #endif
114    #ifndef BALLOON_AREA_HEIGHT
115    #define BALLOON_AREA_HEIGHT           75
116    #endif
117    #ifndef BALLOON_CORNER_RADIUS
118    #define BALLOON_CORNER_RADIUS         10
119    #endif
120    
121    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
122    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
123    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
124    #define BALLOON_TRANSPARENCY         0.8
125    #define POINTER_HEIGHT                20
126    #define POINTER_FOOT_WIDTH            20
127    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
128    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
129    #define BALLOON_SHADOW_TRANSPARENCY  0.2
130    
131    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
132    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
133    
134    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
135    
136    
137    /* draw the bubble shape. this is used twice, once for the shape and once */
138    /* for the shadow */
139    static void
140    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
141           gboolean bottom, int px, int py, int px0, int px1) {
142    
143        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
144        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
145                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
146        if(!bottom) {
147            /* insert top pointer */
148            cairo_line_to (cr, px1, y0);
149            cairo_line_to (cr, px, py);
150            cairo_line_to (cr, px0, y0);
151        }
152    
153        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
154        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
155                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
156        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
157        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
158                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
159        if(bottom) {
160            /* insert bottom pointer */
161            cairo_line_to (cr, px0, y1);
162            cairo_line_to (cr, px, py);
163            cairo_line_to (cr, px1, y1);
164        }
165    
166        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
167        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
168                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
169    
170        cairo_close_path (cr);
171    }
172    
173    static void
174    osd_render_balloon(osm_gps_map_osd_t *osd) {
175        osd_priv_t *priv = (osd_priv_t*)osd->priv;
176    
177        /* get zoom */
178        gint zoom;
179        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
180    
181        /* ------- convert given coordinate into screen position --------- */
182        gint xs, ys;
183        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
184                                          priv->balloon.lat, priv->balloon.lon,
185                                          &xs, &ys);
186    
187        gint x0 = 1, y0 = 1;
188    
189        /* check position of this relative to screen center to determine */
190        /* pointer direction ... */
191        int pointer_x, pointer_x0, pointer_x1;
192        int pointer_y;
193    
194        /* ... and calculate position */
195        int orientation = 0;
196        if(xs > osd->widget->allocation.width/2) {
197            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
198            pointer_x = x0 - priv->balloon.offset_x;
199            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
200            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
201            orientation |= 1;
202        } else {
203            priv->balloon.offset_x = -POINTER_OFFSET;
204            pointer_x = x0 - priv->balloon.offset_x;
205            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
206            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
207        }
208    
209        gboolean bottom = FALSE;
210        if(ys > osd->widget->allocation.height/2) {
211            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
212            pointer_y = y0 - priv->balloon.offset_y;
213            bottom = TRUE;
214            orientation |= 2;
215        } else {
216            priv->balloon.offset_y = 0;
217            pointer_y = y0 - priv->balloon.offset_y;
218            y0 += POINTER_HEIGHT;
219        }
220    
221        /* if required orientation equals current one, then don't render */
222        /* anything */
223        if(orientation == priv->balloon.orientation)
224            return;
225    
226        priv->balloon.orientation = orientation;
227    
228        /* calculate bottom/right of box */
229        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
230    
231        /* save balloon screen coordinates for later use */
232        priv->balloon.rect.x = x0 + BALLOON_BORDER;
233        priv->balloon.rect.y = y0 + BALLOON_BORDER;
234        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
235        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
236    
237        cairo_t *cr = cairo_create(priv->balloon.surface);
238        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
239        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
240        cairo_paint(cr);
241        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
242    
243        /* --------- draw shadow --------------- */
244        osm_gps_map_draw_balloon_shape (cr,
245                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
246                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
247                     bottom, pointer_x, pointer_y,
248                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
249    
250        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
251        cairo_fill_preserve (cr);
252        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
253        cairo_set_line_width (cr, 0);
254        cairo_stroke (cr);
255    
256        /* --------- draw main shape ----------- */
257        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
258                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
259    
260        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
261        cairo_fill_preserve (cr);
262        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
263        cairo_set_line_width (cr, 1);
264        cairo_stroke (cr);
265    
266        if (priv->balloon.cb) {
267            /* clip in case application tries to draw in */
268                /* exceed of the balloon */
269            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
270                             priv->balloon.rect.w, priv->balloon.rect.h);
271            cairo_clip (cr);
272            cairo_new_path (cr);  /* current path is not
273                                     consumed by cairo_clip() */
274    
275            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
276        }
277    
278        cairo_destroy(cr);
279    }
280    
281    /* return true if balloon is being displayed and if */
282    /* the given coordinate is within this balloon */
283    static gboolean
284    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
285    {
286        osd_priv_t *priv = (osd_priv_t*)osd->priv;
287    
288        if(!priv->balloon.surface)
289            return FALSE;
290    
291        gint xs, ys;
292        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
293                                          priv->balloon.lat, priv->balloon.lon,
294                                          &xs, &ys);
295    
296        xs += priv->balloon.rect.x + priv->balloon.offset_x;
297        ys += priv->balloon.rect.y + priv->balloon.offset_y;
298    
299        gboolean is_in =
300            (x > xs) && (x < xs + priv->balloon.rect.w) &&
301            (y > ys) && (y < ys + priv->balloon.rect.h);
302    
303        /* handle the fact that the balloon may have been created by the */
304        /* button down event */
305        if(!is_in && !down && !priv->balloon.just_created) {
306            /* the user actually clicked outside the balloon */
307    
308            /* close the balloon! */
309            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
310        }
311    
312        return is_in;
313    }
314    
315      gpointer priv;  void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
316  } osm_gps_map_osd_t;      g_return_if_fail (OSM_IS_GPS_MAP (map));
317    
318        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
319        g_return_if_fail (osd);
320    
321        osd_priv_t *priv = (osd_priv_t*)osd->priv;
322        g_return_if_fail (priv);
323    
324        if(priv->balloon.surface) {
325            cairo_surface_destroy(priv->balloon.surface);
326            priv->balloon.surface = NULL;
327            priv->balloon.lat = OSM_GPS_MAP_INVALID;
328            priv->balloon.lon = OSM_GPS_MAP_INVALID;
329        }
330        osm_gps_map_redraw(map);
331    }
332    
333    void
334    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
335                                  OsmGpsMapBalloonCallback cb, gpointer data) {
336        g_return_if_fail (OSM_IS_GPS_MAP (map));
337    
338        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
339        g_return_if_fail (osd);
340    
341        osd_priv_t *priv = (osd_priv_t*)osd->priv;
342        g_return_if_fail (priv);
343    
344        osm_gps_map_osd_clear_balloon (map);
345    
346        /* allocate balloon surface */
347        priv->balloon.surface =
348            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
349                                       BALLOON_W+2, BALLOON_H+2);
350    
351        priv->balloon.lat = latitude;
352        priv->balloon.lon = longitude;
353        priv->balloon.cb = cb;
354        priv->balloon.data = data;
355        priv->balloon.just_created = TRUE;
356    
357        priv->balloon.orientation = -1;
358    
359        osd_render_balloon(osd);
360    
361        osm_gps_map_redraw(map);
362    }
363    
364    #endif // OSD_BALLOON
365    
366  /* position and extent of bounding box */  /* position and extent of bounding box */
367    #ifndef OSD_X
368  #define OSD_X      (10)  #define OSD_X      (10)
369  #define OSD_Y      (10)  #endif
370    
371  #define OSD_COLOR            0.5, 0.5, 1  #ifndef OSD_Y
372  #define OSD_COLOR_DISABLED   0.8, 0.8, 0.8  #define OSD_Y      (10)
373    #endif
374    
375  /* parameters of the direction shape */  /* parameters of the direction shape */
376  #ifndef OSM_GPS_MAP_OSD_DIAMETER  #ifndef OSD_DIAMETER
377  #define D_RAD  (30)         // diameter of dpad  #define D_RAD  (30)         // diameter of dpad
378  #else  #else
379  #define D_RAD  (OSM_GPS_MAP_OSD_DIAMETER)  #define D_RAD  (OSD_DIAMETER)
380  #endif  #endif
381  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center
382  #define D_LEN  (D_RAD/4)    // length of arrow  #define D_LEN  (D_RAD/4)    // length of arrow
# Line 59  typedef struct { Line 386  typedef struct {
386  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom
387  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
388    
389    #ifdef OSD_SHADOW_ENABLE
390  /* shadow also depends on control size */  /* shadow also depends on control size */
391  #define OSD_SHADOW (D_RAD/6)  #define OSD_SHADOW (D_RAD/6)
392    #else
393    #define OSD_SHADOW (0)
394    #endif
395    
396    /* normally the GPS button is in the center of the dpad. if there's */
397    /* no dpad it will go into the zoom area */
398    #if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD)
399    #define Z_GPS  1
400    #else
401    #define Z_GPS  0
402    #endif
403    
404  /* total width and height of controls incl. shadow */  /* total width and height of controls incl. shadow */
405  #define OSD_W    (2*D_RAD + OSD_SHADOW)  #define OSD_W    (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD)
406    #if !Z_GPS
407  #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)  #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
408    #else
409    #define OSD_H    (2*Z_RAD + OSD_SHADOW)
410    #endif
411    
412    #ifdef OSD_SHADOW_ENABLE
413  #define OSD_LBL_SHADOW (OSD_SHADOW/2)  #define OSD_LBL_SHADOW (OSD_SHADOW/2)
414    #endif
415    
416    #define Z_TOP    ((1-Z_GPS) * (2 * D_RAD + Z_STEP))
417    
 #define Z_TOP    (2 * D_RAD + Z_STEP)  
418  #define Z_MID    (Z_TOP + Z_RAD)  #define Z_MID    (Z_TOP + Z_RAD)
419  #define Z_BOT    (Z_MID + Z_RAD)  #define Z_BOT    (Z_MID + Z_RAD)
420  #define Z_LEFT   (Z_RAD)  #define Z_LEFT   (Z_RAD)
421  #define Z_RIGHT  (2 * D_RAD - Z_RAD)  #define Z_RIGHT  (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD)
422    #define Z_CENTER ((Z_RIGHT + Z_LEFT)/2)
423    
424  /* create the cairo shape used for the zoom buttons */  /* create the cairo shape used for the zoom buttons */
425  static void  static void
426  osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y) {  osd_zoom_shape(cairo_t *cr, gint x, gint y)
427    {
428      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
429      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
430      cairo_arc     (cr, x+Z_RIGHT,   y+Z_MID, Z_RAD, -M_PI/2,  M_PI/2);      cairo_arc     (cr, x+Z_RIGHT,   y+Z_MID, Z_RAD, -M_PI/2,  M_PI/2);
# Line 84  osm_gps_map_osd_zoom_shape(cairo_t *cr, Line 432  osm_gps_map_osd_zoom_shape(cairo_t *cr,
432      cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);      cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);
433  }  }
434    
435    /* ------------------- color/shadow functions ----------------- */
436    
437    #ifndef OSD_COLOR
438    /* if no color has been specified we just use the gdks default colors */
439    static void
440    osd_labels(cairo_t *cr, gint width, gboolean enabled,
441                           GdkColor *fg, GdkColor *disabled) {
442        if(enabled)  gdk_cairo_set_source_color(cr, fg);
443        else         gdk_cairo_set_source_color(cr, disabled);
444        cairo_set_line_width (cr, width);
445    }
446    #else
447    static void
448    osd_labels(cairo_t *cr, gint width, gboolean enabled) {
449        if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
450        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
451        cairo_set_line_width (cr, width);
452    }
453    #endif
454    
455    #ifdef OSD_SHADOW_ENABLE
456    static void
457    osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
458        cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
459        cairo_set_line_width (cr, width);
460    }
461    #endif
462    
463    #ifndef OSD_NO_DPAD
464  /* create the cairo shape used for the dpad */  /* create the cairo shape used for the dpad */
465  static void  static void
466  osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y) {  osd_dpad_shape(cairo_t *cr, gint x, gint y)
467    {
468      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
469  }  }
470    #endif
471    
472    #ifdef OSD_SHADOW_ENABLE
473    static void
474    osd_shape_shadow(cairo_t *cr) {
475        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
476        cairo_fill (cr);
477        cairo_stroke (cr);
478    }
479    #endif
480    
481    #ifndef OSD_COLOR
482    /* if no color has been specified we just use the gdks default colors */
483    static void
484    osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {
485        gdk_cairo_set_source_color(cr, bg);
486        cairo_fill_preserve (cr);
487        gdk_cairo_set_source_color(cr, fg);
488        cairo_set_line_width (cr, 1);
489        cairo_stroke (cr);
490    }
491    #else
492    static void
493    osd_shape(cairo_t *cr) {
494        cairo_set_source_rgb (cr, OSD_COLOR_BG);
495        cairo_fill_preserve (cr);
496        cairo_set_source_rgb (cr, OSD_COLOR);
497        cairo_set_line_width (cr, 1);
498        cairo_stroke (cr);
499    }
500    #endif
501    
 typedef enum {  
     OSD_NONE = 0,  
     OSD_BG,  
     OSD_UP,  
     OSD_DOWN,  
     OSD_LEFT,  
     OSD_RIGHT,  
     OSD_IN,  
     OSD_OUT,  
     OSD_GPS  
 } osd_button_t;  
502    
503  static gboolean  static gboolean
504  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
# Line 108  osm_gps_map_in_circle(gint x, gint y, gi Line 506  osm_gps_map_in_circle(gint x, gint y, gi
506      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
507  }  }
508    
509    #ifndef OSD_NO_DPAD
510  /* check whether x/y is within the dpad */  /* check whether x/y is within the dpad */
511  static osd_button_t  static osd_button_t
512  osm_gps_map_osd_check_dpad(gint x, gint y)  osd_check_dpad(gint x, gint y)
513  {  {
514      /* within entire dpad circle */      /* within entire dpad circle */
515      if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD))      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))
516      {      {
517          /* convert into position relative to dpads centre */          /* convert into position relative to dpads centre */
518          x -= (OSD_X + D_RAD);          x -= D_RAD;
519          y -= (OSD_Y + D_RAD);          y -= D_RAD;
520    
521    #ifdef OSD_GPS_BUTTON
522          /* check for dpad center goes here! */          /* check for dpad center goes here! */
523          if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))          if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))
524              return OSD_GPS;              return OSD_GPS;
525    #endif
526    
527          if( y < 0 && abs(x) < abs(y))          if( y < 0 && abs(x) < abs(y))
528              return OSD_UP;              return OSD_UP;
# Line 139  osm_gps_map_osd_check_dpad(gint x, gint Line 540  osm_gps_map_osd_check_dpad(gint x, gint
540      }      }
541      return OSD_NONE;      return OSD_NONE;
542  }  }
543    #endif
544    
545  /* check whether x/y is within the zoom pads */  /* check whether x/y is within the zoom pads */
546  static osd_button_t  static osd_button_t
547  osm_gps_map_osd_check_zoom(gint x, gint y) {  osd_check_zoom(gint x, gint y) {
548      if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) {      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {
549    
550          /* within circle around (-) label */          /* within circle around (-) label */
551          if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))          if( osm_gps_map_in_circle(x, y, Z_LEFT, Z_MID, Z_RAD))
             return OSD_OUT;  
   
         /* between center of (-) button and center of entire zoom control area */  
         if(x > OSD_LEFT && x < OSD_X + D_RAD)  
552              return OSD_OUT;              return OSD_OUT;
553    
554          /* within circle around (+) label */          /* within circle around (+) label */
555          if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD))          if( osm_gps_map_in_circle(x, y, Z_RIGHT, Z_MID, Z_RAD))
556              return OSD_IN;              return OSD_IN;
557    
558    #if Z_GPS == 1
559            /* within square around center */
560            if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD)
561                return OSD_GPS;
562    #endif
563    
564            /* between center of (-) button and center of entire zoom control area */
565            if(x > OSD_LEFT && x < D_RAD)
566                return OSD_OUT;
567    
568          /* between center of (+) button and center of entire zoom control area */          /* between center of (+) button and center of entire zoom control area */
569          if(x < OSD_RIGHT && x > OSD_X + D_RAD)          if(x < OSD_RIGHT && x > D_RAD)
570              return OSD_IN;              return OSD_IN;
571      }      }
572    
573      return OSD_NONE;      return OSD_NONE;
574  }  }
575    
576  static osd_button_t  #ifdef OSD_SOURCE_SEL
 osm_gps_map_osd_check(gint x, gint y) {  
     osd_button_t but = OSD_NONE;  
577    
578      /* first do a rough test for the OSD area. */  /* place source selection at right border */
579      /* this is just to avoid an unnecessary detailed test */  #define OSD_S_RAD (Z_RAD)
580      if(x > OSD_X && x < OSD_X + OSD_W &&  #define OSD_S_X   (-OSD_X)
581         y > OSD_Y && y < OSD_Y + OSD_H) {  #define OSD_S_Y   (OSD_Y)
582          but = osm_gps_map_osd_check_dpad(x, y);  #define OSD_S_PW  (2 * Z_RAD)
583    #define OSD_S_W   (OSD_S_PW)
584    #define OSD_S_PH  (2 * Z_RAD)
585    #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
586    
587    /* size of usable area when expanded */
588    #define OSD_S_AREA_W (priv->source_sel.width)
589    #define OSD_S_AREA_H (priv->source_sel.height)
590    #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
591    #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
592    
593    /* internal value to draw the arrow on the "puller" */
594    #define OSD_S_D0  (OSD_S_RAD/2)
595    #ifndef OSD_FONT_SIZE
596    #define OSD_FONT_SIZE 16.0
597    #endif
598    #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)
599    #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)
600    
601          if(but == OSD_NONE)  /* draw the shape of the source selection OSD, either only the puller (not expanded) */
602              but = osm_gps_map_osd_check_zoom(x, y);  /* or the entire menu incl. the puller (expanded) */
603    static void
604    osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
605        if(!priv->source_sel.expanded) {
606            /* just draw the puller */
607            cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
608            cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
609            cairo_line_to (cr, x + OSD_S_PW, y);
610        } else {
611            /* draw the puller and the area itself */
612            cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H);
613            cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H);
614            if(OSD_S_Y > 0) {
615                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH);
616                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
617            } else {
618                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
619                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH);
620                cairo_line_to (cr, x + OSD_S_PW, y);
621            }
622            cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y);
623            cairo_close_path (cr);
624      }      }
   
     return but;  
625  }  }
626    
627  static void  static void
628  osm_gps_map_osd_shape_shadow(cairo_t *cr) {  osd_source_content(osm_gps_map_osd_t *osd, cairo_t *cr, gint offset) {
629      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     cairo_fill (cr);  
     cairo_stroke (cr);  
 }  
630    
631  static void      int py = offset + OSD_S_RAD - OSD_S_D0;
 osm_gps_map_osd_shape(cairo_t *cr) {  
     cairo_set_source_rgb (cr, 1, 1, 1);  
     cairo_fill_preserve (cr);  
     cairo_set_source_rgb (cr, OSD_COLOR);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
 }  
632    
633  static void      if(!priv->source_sel.expanded) {
634  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {          /* draw the "puller" open (<) arrow */
635      /* move reference to dpad center */          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);
636      x += D_RAD;          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
637      y += D_RAD;          cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
638        } else {
639            if(OSD_S_Y < 0)
640                py += OSD_S_AREA_H - OSD_S_PH;
641    
642            /* draw the "puller" close (>) arrow */
643            cairo_move_to (cr, offset + OSD_S_RAD - OSD_S_D0/2, py);
644            cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
645            cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
646            cairo_stroke(cr);
647    
648            /* don't draw a shadow for the text content */
649            if(offset == 1) {
650                gint source;
651                g_object_get(osd->widget, "map-source", &source, NULL);
652    
653                cairo_select_font_face (cr, "Sans",
654                                        CAIRO_FONT_SLANT_NORMAL,
655                                        CAIRO_FONT_WEIGHT_BOLD);
656                cairo_set_font_size (cr, OSD_FONT_SIZE);
657    
658                int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
659                    OSM_GPS_MAP_SOURCE_LAST;
660                for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
661                    cairo_text_extents_t extents;
662                    const char *src = osm_gps_map_source_get_friendly_name(i);
663                    cairo_text_extents (cr, src, &extents);
664    
665                    int x = offset + OSD_S_PW + OSD_TEXT_BORDER;
666                    int y = offset + step * (i-1) + OSD_TEXT_BORDER;
667    
668                    /* draw filled rectangle if selected */
669                    if(source == i) {
670                        cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
671                                        y - OSD_TEXT_SKIP,
672                                        priv->source_sel.width - OSD_TEXT_BORDER,
673                                        step + OSD_TEXT_SKIP);
674                        cairo_fill(cr);
675    
676                        /* temprarily draw with background color */
677    #ifndef OSD_COLOR
678                        GdkColor bg = osd->widget->style->bg[GTK_STATE_NORMAL];
679                        gdk_cairo_set_source_color(cr, &bg);
680    #else
681                        cairo_set_source_rgb (cr, OSD_COLOR_BG);
682    #endif
683                    }
684    
685      const static gint offset[][3][2] = {                  cairo_move_to (cr, x, y + OSD_TEXT_SKIP - extents.y_bearing);
686          /* left arrow/triangle */                  cairo_show_text (cr, src);
         { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } },  
         /* right arrow/triangle */  
         { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } },  
         /* top arrow/triangle */  
         { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } },  
         /* bottom arrow/triangle */  
         { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } }  
     };  
687    
688      int i;                  /* restore color */
689      for(i=0;i<4;i++) {                  if(source == i) {
690          cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]);  #ifndef OSD_COLOR
691          cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]);                      GdkColor fg = osd->widget->style->fg[GTK_STATE_NORMAL];
692          cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);                      gdk_cairo_set_source_color(cr, &fg);
693    #else
694                        cairo_set_source_rgb (cr, OSD_COLOR);
695    #endif
696                    }
697                }
698            }
699      }      }
700  }  }
701    
 /* draw the sattelite dish icon in the center of the dpad */  
 #define GPS_V0  (D_RAD/8)  
 #define GPS_V1  (D_RAD/10)  
 #define GPS_V2  (D_RAD/5)  
   
 /* draw a satellite receiver dish */  
702  static void  static void
703  osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
704      /* move reference to dpad center */      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     x += D_RAD;  
     y += D_RAD + GPS_V0;  
705    
706      cairo_move_to (cr, x-GPS_V0, y+GPS_V0);      if(priv->source_sel.rendered && !force_rerender)
707      cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);          return;
     cairo_rel_line_to (cr, +GPS_V0, +GPS_V0);  
     cairo_close_path (cr);  
708    
709      cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);      priv->source_sel.rendered = TRUE;
     cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);  
     cairo_close_path (cr);  
710    
711      x += GPS_V1;  #ifndef OSD_COLOR
712      cairo_move_to (cr, x, y-GPS_V2);      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
713      cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
714  }      GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
715    #endif
716    
717  #define Z_LEN  (2*Z_RAD/3)      /* draw source selector */
718        cairo_t *cr = cairo_create(priv->source_sel.surface);
719        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
720        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
721        cairo_paint(cr);
722        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
723    
724  static void  #ifdef OSD_SHADOW_ENABLE
725  osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {      osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
726      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);      osd_shape_shadow(cr);
727      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);  #endif
728    
729      cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);      osd_source_shape(priv, cr, 1, 1);
730      cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);  #ifndef OSD_COLOR
731      cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);      osd_shape(cr, &bg, &fg);
732      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);  #else
733  }      osd_shape(cr);
734    #endif
735    
736  static void  #ifdef OSD_SHADOW_ENABLE
737  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {      osd_labels_shadow(cr, Z_RAD/3, TRUE);
738      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);      osd_source_content(osd, cr, 1+OSD_LBL_SHADOW);
     else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);  
     cairo_set_line_width (cr, width);  
739      cairo_stroke (cr);      cairo_stroke (cr);
740  }  #endif
741    #ifndef OSD_COLOR
742  static void      osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
743  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {  #else
744      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);      osd_labels(cr, Z_RAD/3, TRUE);
745      cairo_set_line_width (cr, width);  #endif
746        osd_source_content(osd, cr, 1);
747      cairo_stroke (cr);      cairo_stroke (cr);
748    
749        cairo_destroy(cr);
750  }  }
751    
752    /* re-allocate the buffer used to draw the menu. This is used */
753    /* to collapse/expand the buffer */
754  static void  static void
755  osm_gps_map_osd_render(OsmGpsMapPrivate *priv) {  osd_source_reallocate(osm_gps_map_osd_t *osd) {
756        osd_priv_t *priv = (osd_priv_t*)osd->priv;
757    
758      /* first fill with transparency */      /* re-allocate offscreen bitmap */
759      cairo_t *cr = cairo_create(priv->osd.overlay);      g_assert (priv->source_sel.surface);
     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);  
     cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);  
     cairo_paint(cr);  
760    
761      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      int w = OSD_S_W, h = OSD_S_H;
762        if(priv->source_sel.expanded) {
763            cairo_text_extents_t extents;
764    
765            /* determine content size */
766            cairo_t *cr = cairo_create(priv->source_sel.surface);
767            cairo_select_font_face (cr, "Sans",
768                                    CAIRO_FONT_SLANT_NORMAL,
769                                    CAIRO_FONT_WEIGHT_BOLD);
770            cairo_set_font_size (cr, OSD_FONT_SIZE);
771    
772            /* calculate menu size */
773            int i, max_h = 0, max_w = 0;
774            for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
775                const char *src = osm_gps_map_source_get_friendly_name(i);
776                cairo_text_extents (cr, src, &extents);
777    
778      /* --------- draw zoom and dpad shape shadow ----------- */              if(extents.width > max_w) max_w = extents.width;
779      gint x = 0, y = 0;              if(extents.height > max_h) max_h = extents.height;
780            }
781            cairo_destroy(cr);
782    
783            priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
784            priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
785                (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
786    
787            w = OSD_S_EXP_W;
788            h = OSD_S_EXP_H;
789        }
790    
791        cairo_surface_destroy(priv->source_sel.surface);
792        priv->source_sel.surface =
793            cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
794    
795        osd_render_source_sel(osd, TRUE);
796    }
797    
798    #define OSD_HZ      15
799    #define OSD_TIME    500
800    
801    static gboolean osd_source_animate(gpointer data) {
802        osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;
803        osd_priv_t *priv = (osd_priv_t*)osd->priv;
804        int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
805        gboolean done = FALSE;
806        priv->source_sel.count += priv->source_sel.dir;
807    
808        /* shifting in */
809        if(priv->source_sel.dir < 0) {
810            if(priv->source_sel.count <= 0) {
811                priv->source_sel.count = 0;
812                done = TRUE;
813            }
814        } else {
815            if(priv->source_sel.count >= 1000) {
816                priv->source_sel.expanded = FALSE;
817                osd_source_reallocate(osd);
818    
819      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);              priv->source_sel.count = 1000;
820      osm_gps_map_osd_shape_shadow(cr);              done = TRUE;
821      osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);          }
822      osm_gps_map_osd_shape_shadow(cr);      }
823    
     /* --------- draw zoom and dpad shape ----------- */  
824    
825      osm_gps_map_osd_zoom_shape(cr, x, y);      /* count runs linearly from 0 to 1000, map this nicely onto a position */
     osm_gps_map_osd_shape(cr);  
     osm_gps_map_osd_dpad_shape(cr, x, y);  
     osm_gps_map_osd_shape(cr);  
826    
827      /* --------- draw zoom and dpad labels --------- */      /* nice sinoid mapping */
828        float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
829        priv->source_sel.shift =
830            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
831            m * diff;
832    
833      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      /* make sure the screen is updated */
834      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
835      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);  
836      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      /* stop animation if done */
837      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL);      if(done)
838            priv->source_sel.handler_id = 0;
839      osm_gps_map_osd_zoom_labels(cr, x, y);  
840      osm_gps_map_osd_dpad_labels(cr, x, y);      return !done;
     osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);  
     osm_gps_map_osd_dpad_gps(cr, x, y);  
     osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL);  
   
     cairo_destroy(cr);  
841  }  }
842    
843    /* switch between expand and collapse mode of source selection */
844  static void  static void
845  osm_gps_map_osd_draw_controls (OsmGpsMap *map, gint xoffset, gint yoffset)  osd_source_toggle(osm_gps_map_osd_t *osd)
846  {  {
847      OsmGpsMapPrivate *priv = map->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
848    
849      /* backup previous contents */      /* ignore clicks while animation is running */
850      if(!priv->osd.backup)      if(priv->source_sel.handler_id)
851          priv->osd.backup = gdk_pixmap_new(priv->pixmap, OSD_W+2, OSD_H+2, -1);          return;
   
     gint x = OSD_X + EXTRA_BORDER + xoffset;  
     gint y = OSD_Y + EXTRA_BORDER + yoffset;  
852    
853      /* create backup of background */      /* expand immediately, collapse is handle at the end of the */
854      gdk_draw_drawable(priv->osd.backup,      /* collapse animation */
855          GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],      if(!priv->source_sel.expanded) {
856                        priv->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);          priv->source_sel.expanded = TRUE;
857            osd_source_reallocate(osd);
858    
859            priv->source_sel.count = 1000;
860            priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
861            priv->source_sel.dir = -1000/OSD_HZ;
862        } else {
863            priv->source_sel.count =  0;
864            priv->source_sel.shift = osd->widget->allocation.width -
865                OSD_S_EXP_W + OSD_S_X;
866            priv->source_sel.dir = +1000/OSD_HZ;
867        }
868    
869        /* start timer to handle animation */
870        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
871                                                      osd_source_animate, osd);
872    }
873    
874      priv->osd.backup_x = x-1;  /* check if the user clicked inside the source selection area */
875      priv->osd.backup_y = y-1;  static osd_button_t
876    osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
877        osd_priv_t *priv = (osd_priv_t*)osd->priv;
878    
879        if(!priv->source_sel.expanded)
880            x -= osd->widget->allocation.width - OSD_S_W;
881        else
882            x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
883    
884  #ifdef USE_CAIRO      if(OSD_S_Y > 0)
885      /* OSD itself uses some off-screen rendering, so check if the */          y -= OSD_S_Y;
886      /* offscreen buffer is present and create it if not */      else
887      if(!priv->osd.overlay) {          y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y;
888          /* create overlay ... */  
889          priv->osd.overlay =      /* within square around puller? */
890              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);      if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) {
891          /* ... and render it */          /* really within puller shape? */
892          osm_gps_map_osd_render(priv);          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
893                /* expand source selector */
894                if(down)
895                    osd_source_toggle(osd);
896    
897                /* tell upper layers that user clicked some background element */
898                /* of the OSD */
899                return OSD_BG;
900            }
901      }      }
902    
903      // now draw this onto the original context      /* check for clicks into data area */
904      cairo_t *cr = gdk_cairo_create(priv->pixmap);      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
905      cairo_set_source_surface(cr, priv->osd.overlay, x, y);          /* re-adjust from puller top to content top */
906      cairo_paint(cr);          if(OSD_S_Y < 0)
907      cairo_destroy(cr);              y += OSD_S_EXP_H - OSD_S_PH;
908    
909            if(x > OSD_S_PW &&
910               x < OSD_S_PW + OSD_S_EXP_W &&
911               y > 0 &&
912               y < OSD_S_EXP_H) {
913    
914                int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
915                    / OSM_GPS_MAP_SOURCE_LAST;
916    
917                y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
918                y /= step;
919                y += 1;
920    
921                if(down) {
922                    gint old = 0;
923                    g_object_get(osd->widget, "map-source", &old, NULL);
924    
925                    if(y > OSM_GPS_MAP_SOURCE_NULL &&
926                       y <= OSM_GPS_MAP_SOURCE_LAST &&
927                       old != y) {
928                        g_object_set(osd->widget, "map-source", y, NULL);
929    
930                        osd_render_source_sel(osd, TRUE);
931                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
932                    }
933                }
934    
935  #else              /* return "clicked in OSD background" to prevent further */
936  #warning "OSD control display lacks a non-cairo implementation!"              /* processing by application */
937  #endif              return OSD_BG;
938            }
939        }
940    
941        return OSD_NONE;
942  }  }
943    #endif // OSD_SOURCE_SEL
944    
945  static void  static osd_button_t
946  osm_gps_map_osd_restore (OsmGpsMap *map)  osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
947  {      osd_button_t but = OSD_NONE;
     OsmGpsMapPrivate *priv = map->priv;  
948    
949      /* restore backup of previous contents */  #ifdef OSD_BALLOON
950      if(priv->osd.backup) {      if(down) {
951          /* create backup of background */          /* needed to handle balloons that are created at click */
952          gdk_draw_drawable(priv->pixmap,          osd_priv_t *priv = (osd_priv_t*)osd->priv;
953              GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(GTK_WIDGET(map))],          priv->balloon.just_created = FALSE;
                       priv->osd.backup, 0, 0,  
                       priv->osd.backup_x, priv->osd.backup_y, OSD_W+2, OSD_H+2);  
954      }      }
 }  
   
955  #endif  #endif
956    
957  static gboolean  #ifdef OSD_SOURCE_SEL
958  osm_gps_map_map_redraw (OsmGpsMap *map)      /* the source selection area is handles internally */
959  {      but = osd_source_check(osd, down, x, y);
960      OsmGpsMapPrivate *priv = map->priv;  #endif
961    
962      priv->idle_map_redraw = 0;      if(but == OSD_NONE) {
963            gint mx = x - OSD_X;
964      /* the motion_notify handler uses priv->pixmap to redraw the area; if we          gint my = y - OSD_Y;
965       * change it while we are dragging, we will end up showing it in the wrong  
966       * place. This could be fixed by carefully recompute the coordinates, but          if(OSD_X < 0)
967       * for now it's easier just to disable redrawing the map while dragging */              mx -= (osd->widget->allocation.width - OSD_W);
968      if (priv->dragging)  
969          return FALSE;          if(OSD_Y < 0)
970                my -= (osd->widget->allocation.height - OSD_H);
971      priv->redraw_cycle++;  
972            /* first do a rough test for the OSD area. */
973            /* this is just to avoid an unnecessary detailed test */
974            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
975    #ifndef OSD_NO_DPAD
976                but = osd_check_dpad(mx, my);
977    #endif
978            }
979    
980      /* draw white background to initialise pixmap */          if(but == OSD_NONE)
981      gdk_draw_rectangle (              but = osd_check_zoom(mx, my);
982                          priv->pixmap,      }
                         GTK_WIDGET(map)->style->white_gc,  
                         TRUE,  
                         0, 0,  
                         GTK_WIDGET(map)->allocation.width + EXTRA_BORDER * 2,  
                         GTK_WIDGET(map)->allocation.height + EXTRA_BORDER * 2);  
   
     osm_gps_map_fill_tiles_pixel(map);  
   
     osm_gps_map_print_tracks(map);  
     osm_gps_map_draw_gps_point(map);  
     osm_gps_map_print_images(map);  
 #ifdef ENABLE_BALLOON  
     osm_gps_map_draw_balloon_int(map);  
 #endif  
 #ifdef ENABLE_OSD  
     osm_gps_map_osd_draw_controls(map, 0, 0);  
 #endif  
   
     //osm_gps_map_osd_speed(map, 1.5);  
     osm_gps_map_purge_cache(map);  
     gtk_widget_queue_draw (GTK_WIDGET (map));  
983    
984      return FALSE;  #ifdef OSD_BALLOON
985        if(but == OSD_NONE) {
986            /* check if user clicked into balloon */
987            if(osd_balloon_check(osd, down, x, y))
988                but = OSD_BG;
989        }
990    #endif
991    
992        return but;
993  }  }
994    
995    #ifndef OSD_NO_DPAD
996  static void  static void
997  osm_gps_map_map_redraw_idle (OsmGpsMap *map)  osd_dpad_labels(cairo_t *cr, gint x, gint y) {
998  {      /* move reference to dpad center */
999      OsmGpsMapPrivate *priv = map->priv;      x += D_RAD;
1000        y += D_RAD;
1001    
1002      if (priv->idle_map_redraw == 0)      const static gint offset[][3][2] = {
1003          priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map);          /* left arrow/triangle */
1004  }          { { -D_TIP+D_LEN, -D_WID }, { -D_LEN, D_WID }, { +D_LEN, D_WID } },
1005            /* right arrow/triangle */
1006            { { +D_TIP-D_LEN, -D_WID }, { +D_LEN, D_WID }, { -D_LEN, D_WID } },
1007            /* top arrow/triangle */
1008            { { -D_WID, -D_TIP+D_LEN }, { D_WID, -D_LEN }, { D_WID, +D_LEN } },
1009            /* bottom arrow/triangle */
1010            { { -D_WID, +D_TIP-D_LEN }, { D_WID, +D_LEN }, { D_WID, -D_LEN } }
1011        };
1012    
1013  static void      int i;
1014  osm_gps_map_init (OsmGpsMap *object)      for(i=0;i<4;i++) {
1015  {          cairo_move_to (cr, x + offset[i][0][0], y + offset[i][0][1]);
1016      OsmGpsMapPrivate *priv;          cairo_rel_line_to (cr, offset[i][1][0], offset[i][1][1]);
1017            cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);
1018        }
1019    }
1020    #endif
1021    
1022      priv = G_TYPE_INSTANCE_GET_PRIVATE (object, OSM_TYPE_GPS_MAP, OsmGpsMapPrivate);  #ifdef OSD_GPS_BUTTON
1023      object->priv = priv;  /* draw the satellite dish icon in the center of the dpad */
1024    #define GPS_V0  (D_RAD/7)
1025    #define GPS_V1  (D_RAD/10)
1026    #define GPS_V2  (D_RAD/5)
1027    
1028      priv->pixmap = NULL;  /* draw a satellite receiver dish */
1029    /* this is either drawn in the center of the dpad (if present) */
1030    /* or in the middle of the zoom area */
1031    static void
1032    osd_dpad_gps(cairo_t *cr, gint x, gint y) {
1033        /* move reference to dpad center */
1034        x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;
1035        y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;
1036    
1037      priv->trip_history = NULL;      cairo_move_to (cr, x-GPS_V0, y+GPS_V0);
1038      priv->gps = g_new0(coord_t, 1);      cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);
1039      priv->gps_valid = FALSE;      cairo_rel_line_to (cr, +GPS_V0, +GPS_V0);
1040        cairo_close_path (cr);
1041    
1042  #ifdef ENABLE_BALLOON      cairo_move_to (cr, x+GPS_V1-GPS_V2, y-2*GPS_V2);
1043      priv->balloon.coo = g_new0(coord_t, 1);      cairo_curve_to (cr, x-GPS_V2, y, x+GPS_V1, y+GPS_V1, x+GPS_V1+GPS_V2, y);
1044      priv->balloon.valid = FALSE;      cairo_close_path (cr);
     priv->balloon.cb = NULL;  
 #endif  
1045    
1046  #ifdef ENABLE_OSD      x += GPS_V1;
1047      priv->osd.backup = NULL;      cairo_move_to (cr, x, y-GPS_V2);
1048      priv->osd.overlay = NULL;      cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);
1049      priv->osd.cb = NULL;  }
1050  #endif  #endif
1051    
1052      priv->tracks = NULL;  #define Z_LEN  (2*Z_RAD/3)
     priv->images = NULL;  
1053    
1054      priv->drag_counter = 0;  static void
1055      priv->drag_mouse_dx = 0;  osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1056      priv->drag_mouse_dy = 0;      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1057      priv->drag_start_mouse_x = 0;      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
     priv->drag_start_mouse_y = 0;  
1058    
1059      priv->uri_format = 0;      cairo_move_to (cr, x + Z_RIGHT,         y + Z_MID - Z_LEN);
1060      priv->the_google = FALSE;      cairo_line_to (cr, x + Z_RIGHT,         y + Z_MID + Z_LEN);
1061        cairo_move_to (cr, x + Z_RIGHT - Z_LEN, y + Z_MID);
1062        cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1063    }
1064    
1065      priv->map_source = -1;  #ifdef OSD_COORDINATES
1066    
1067  #ifndef LIBSOUP22  #ifndef OSD_COORDINATES_FONT_SIZE
1068      //Change naumber of concurrent connections option?  #define OSD_COORDINATES_FONT_SIZE 12
     priv->soup_session = soup_session_async_new_with_options(  
                                                              SOUP_SESSION_USER_AGENT,  
                                                              "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11",  
                                                              NULL);  
 #else  
     /* libsoup-2.2 seems not to be able to set the user agent */  
     priv->soup_session = soup_session_async_new();  
1069  #endif  #endif
1070    
1071      //Hash table which maps tile d/l URIs to SoupMessage requests  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
     priv->tile_queue = g_hash_table_new (g_str_hash, g_str_equal);  
   
     //Some mapping providers (Google) have varying degrees of tiles at multiple  
     //zoom levels  
     priv->missing_tiles = g_hash_table_new (g_str_hash, g_str_equal);  
1072    
1073      /* memory cache for most recently used tiles */  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1074      priv->tile_cache = g_hash_table_new_full (g_str_hash, g_str_equal,  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)
                                               g_free, (GDestroyNotify)cached_tile_free);  
     priv->max_tile_cache_size = 20;  
1075    
1076      gtk_widget_add_events (GTK_WIDGET (object),  /* these can be overwritten with versions that support */
1077                             GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |  /* localization */
1078                             GDK_POINTER_MOTION_MASK |  #ifndef OSD_COORDINATES_CHR_N
1079                             GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);  #define OSD_COORDINATES_CHR_N  "N"
1080      GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS);  #endif
1081    #ifndef OSD_COORDINATES_CHR_S
1082      g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL);  #define OSD_COORDINATES_CHR_S  "S"
1083  }  #endif
1084    #ifndef OSD_COORDINATES_CHR_E
1085    #define OSD_COORDINATES_CHR_E  "E"
1086    #endif
1087    #ifndef OSD_COORDINATES_CHR_W
1088    #define OSD_COORDINATES_CHR_W  "W"
1089    #endif
1090    
 #ifndef G_CHECKSUM_MD5  
 /* simple hash algorithm hack if md5 is not present */  
 static char *simple_hash(char *str) {  
     union {  
         char str[4];  
         gulong val;  
     } hash = { .val = 0x55555555 };  
1091    
     while(*str) {  
         hash.str[(int)str & 3] ^= *str;  
         str++;  
     }  
     return g_strdup_printf("%08lX", hash.val);  
 }  
 #endif  
1092    
1093  static GObject *  /* this is the classic geocaching notation */
1094  osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties)  static char
1095  {  *osd_latitude_str(float latitude) {
1096      GObject *object;      char *c = OSD_COORDINATES_CHR_N;
1097      OsmGpsMapPrivate *priv;      float integral, fractional;
1098      OsmGpsMap *map;  
1099      const char *uri;      if(isnan(latitude))
1100            return NULL;
1101      //Always chain up to the parent constructor  
1102      object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);      if(latitude < 0) {
1103      map = OSM_GPS_MAP(object);          latitude = fabs(latitude);
1104      priv = OSM_GPS_MAP_PRIVATE(object);          c = OSD_COORDINATES_CHR_S;
   
     //user can specify a map source ID, or a repo URI as the map source  
     uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);  
     if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {  
         g_debug("Using null source");  
         priv->map_source = OSM_GPS_MAP_SOURCE_NULL;  
   
         priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256);  
         gdk_pixbuf_fill(priv->null_tile, 0xcccccc00);  
     }  
     else if (priv->map_source >= 0) {  
         //check if the source given is valid  
         uri = osm_gps_map_source_get_repo_uri(priv->map_source);  
         if (uri) {  
             g_debug("Setting map source from ID");  
             g_free(priv->repo_uri);  
   
             priv->repo_uri = g_strdup(uri);  
             priv->image_format = g_strdup(  
                 osm_gps_map_source_get_image_format(priv->map_source));  
             priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source);  
             priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source);  
         }  
1105      }      }
1106    
1107      if (!priv->cache_dir_is_full_path) {      fractional = modff(latitude, &integral);
1108  #ifdef G_CHECKSUM_MD5  
1109          char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1);      return g_strdup_printf("%s %02d° %06.3f'",
1110  #else                             c, (int)integral, fractional*60.0);
1111          char *md5 = simple_hash(priv->repo_uri);  }
 #endif  
   
         if (priv->cache_dir) {  
             char *old = priv->cache_dir;  
             //the new cachedir is the given cache dir + the md5 of the repo_uri  
             priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, md5);  
             g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);  
             g_free(old);  
         } else {  
             //the new cachedir is the current dir + the md5 of the repo_uri  
             priv->cache_dir = g_strdup(md5);  
         }  
1112    
1113          g_free(md5);  static char
1114    *osd_longitude_str(float longitude) {
1115        char *c = OSD_COORDINATES_CHR_E;
1116        float integral, fractional;
1117    
1118        if(isnan(longitude))
1119            return NULL;
1120    
1121        if(longitude < 0) {
1122            longitude = fabs(longitude);
1123            c = OSD_COORDINATES_CHR_W;
1124      }      }
1125    
1126      inspect_map_uri(map);      fractional = modff(longitude, &integral);
1127    
1128      return object;      return g_strdup_printf("%s %03d° %06.3f'",
1129                               c, (int)integral, fractional*60.0);
1130  }  }
1131    
1132  static void  static void
1133  osm_gps_map_dispose (GObject *object)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1134  {  {
1135      OsmGpsMap *map = OSM_GPS_MAP(object);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     OsmGpsMapPrivate *priv = map->priv;  
   
     if (priv->is_disposed)  
         return;  
   
     priv->is_disposed = TRUE;  
   
     soup_session_abort(priv->soup_session);  
     g_object_unref(priv->soup_session);  
   
     g_hash_table_destroy(priv->tile_queue);  
     g_hash_table_destroy(priv->missing_tiles);  
     g_hash_table_destroy(priv->tile_cache);  
1136    
1137      osm_gps_map_free_images(map);      /* get current map position */
1138        gfloat lat, lon;
1139        g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1140    
1141        /* check if position has changed enough to require redraw */
1142        if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1143            /* 1/60000 == 1/1000 minute */
1144            if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1145               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1146                return;
1147    
1148      if(priv->pixmap)      priv->coordinates.lat = lat;
1149          g_object_unref (priv->pixmap);      priv->coordinates.lon = lon;
1150    
1151      if (priv->null_tile)      /* first fill with transparency */
1152          g_object_unref (priv->null_tile);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1153        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1154      if(priv->gc_map)      //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
1155          g_object_unref(priv->gc_map);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1156        cairo_paint(cr);
1157      if (priv->idle_map_redraw != 0)      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
         g_source_remove (priv->idle_map_redraw);  
1158    
1159      g_free(priv->gps);      cairo_select_font_face (cr, "Sans",
1160                                CAIRO_FONT_SLANT_NORMAL,
1161                                CAIRO_FONT_WEIGHT_BOLD);
1162        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1163    
1164  #ifdef ENABLE_BALLOON      char *latitude = osd_latitude_str(lat);
1165      g_free(priv->balloon.coo);      char *longitude = osd_longitude_str(lon);
1166  #endif  
1167        cairo_text_extents_t lat_extents, lon_extents;
1168        cairo_text_extents (cr, latitude, &lat_extents);
1169        cairo_text_extents (cr, longitude, &lon_extents);
1170    
1171        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1172        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1173        cairo_move_to (cr,
1174                       (OSD_COORDINATES_W - lat_extents.width)/2,
1175                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1176        cairo_text_path (cr, latitude);
1177        cairo_move_to (cr,
1178                       (OSD_COORDINATES_W - lon_extents.width)/2,
1179                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1180                       OSD_COORDINATES_FONT_SIZE);
1181        cairo_text_path (cr, longitude);
1182        cairo_stroke (cr);
1183    
1184  #ifdef ENABLE_OSD      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1185      if (priv->osd.backup)      cairo_move_to (cr,
1186          g_object_unref(priv->osd.backup);                     (OSD_COORDINATES_W - lat_extents.width)/2,
1187                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1188        cairo_show_text (cr, latitude);
1189        cairo_move_to (cr,
1190                       (OSD_COORDINATES_W - lon_extents.width)/2,
1191                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1192                       OSD_COORDINATES_FONT_SIZE);
1193        cairo_show_text (cr, longitude);
1194    
1195      if (priv->osd.overlay)      g_free(latitude);
1196           cairo_surface_destroy(priv->osd.overlay);      g_free(longitude);
 #endif  
1197    
1198      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      cairo_destroy(cr);
1199  }  }
1200    #endif  // OSD_COORDINATES
1201    
1202    #ifdef OSD_NAV
1203    #define OSD_NAV_W  (100)
1204    #define OSD_NAV_H  (100)
1205    
1206  static void  static void
1207  osm_gps_map_finalize (GObject *object)  osd_render_nav(osm_gps_map_osd_t *osd)
1208  {  {
1209      OsmGpsMap *map = OSM_GPS_MAP(object);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     OsmGpsMapPrivate *priv = map->priv;  
1210    
1211      g_free(priv->cache_dir);      /* first fill with transparency */
1212      g_free(priv->repo_uri);      cairo_t *cr = cairo_create(priv->nav.surface);
1213      g_free(priv->image_format);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1214        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1215      osm_gps_map_free_trip(map);      cairo_paint(cr);
1216      osm_gps_map_free_tracks(map);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1217    
1218      G_OBJECT_CLASS (osm_gps_map_parent_class)->finalize (object);      cairo_destroy(cr);
1219  }  }
1220    
1221  static void  #endif // OSD_NAV
 osm_gps_map_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)  
 {  
     g_return_if_fail (OSM_IS_GPS_MAP (object));  
     OsmGpsMap *map = OSM_GPS_MAP(object);  
     OsmGpsMapPrivate *priv = map->priv;  
1222    
     switch (prop_id)  
     {  
         case PROP_AUTO_CENTER:  
             priv->map_auto_center = g_value_get_boolean (value);  
             break;  
         case PROP_RECORD_TRIP_HISTORY:  
             priv->record_trip_history = g_value_get_boolean (value);  
             break;  
         case PROP_SHOW_TRIP_HISTORY:  
             priv->show_trip_history = g_value_get_boolean (value);  
             break;  
         case PROP_AUTO_DOWNLOAD:  
             priv->map_auto_download = g_value_get_boolean (value);  
             break;  
         case PROP_REPO_URI:  
             priv->repo_uri = g_value_dup_string (value);  
             break;  
         case PROP_PROXY_URI:  
             if ( g_value_get_string(value) ) {  
                 priv->proxy_uri = g_value_dup_string (value);  
                 g_debug("Setting proxy server: %s", priv->proxy_uri);  
   
 #ifndef LIBSOUP22  
                 GValue val = {0};  
   
                 SoupURI* uri = soup_uri_new(priv->proxy_uri);  
                 g_value_init(&val, SOUP_TYPE_URI);  
                 g_value_take_boxed(&val, uri);  
1223    
1224                  g_object_set_property(G_OBJECT(priv->soup_session),SOUP_SESSION_PROXY_URI,&val);  #ifdef OSD_CROSSHAIR
1225  #else  
1226                  SoupUri* uri = soup_uri_new(priv->proxy_uri);  #ifndef OSD_CROSSHAIR_RADIUS
1227                  g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL);  #define OSD_CROSSHAIR_RADIUS 10
1228  #endif  #endif
             } else  
                 priv->proxy_uri = NULL;  
1229    
1230              break;  #define OSD_CROSSHAIR_TICK  (OSD_CROSSHAIR_RADIUS/2)
1231          case PROP_TILE_CACHE_DIR:  #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4)
1232              if ( g_value_get_string(value) )  #define OSD_CROSSHAIR_W  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
1233                  priv->cache_dir = g_value_dup_string (value);  #define OSD_CROSSHAIR_H  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
             break;  
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             priv->cache_dir_is_full_path = g_value_get_boolean (value);  
             break;  
         case PROP_ZOOM:  
             priv->map_zoom = g_value_get_int (value);  
             break;  
         case PROP_MAX_ZOOM:  
             priv->max_zoom = g_value_get_int (value);  
             break;  
         case PROP_MIN_ZOOM:  
             priv->min_zoom = g_value_get_int (value);  
             break;  
         case PROP_MAP_X:  
             priv->map_x = g_value_get_int (value);  
             priv->center_coord_set = FALSE;  
             break;  
         case PROP_MAP_Y:  
             priv->map_y = g_value_get_int (value);  
             priv->center_coord_set = FALSE;  
             break;  
         case PROP_GPS_TRACK_WIDTH:  
             priv->ui_gps_track_width = g_value_get_int (value);  
             break;  
         case PROP_GPS_POINT_R1:  
             priv->ui_gps_point_inner_radius = g_value_get_int (value);  
             break;  
         case PROP_GPS_POINT_R2:  
             priv->ui_gps_point_outer_radius = g_value_get_int (value);  
             break;  
         case PROP_MAP_SOURCE:  
             priv->map_source = g_value_get_int (value);  
             break;  
         case PROP_IMAGE_FORMAT:  
             priv->image_format = g_value_dup_string (value);  
             break;  
         default:  
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);  
             break;  
     }  
 }  
1234    
1235  static void  static void
1236  osm_gps_map_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)  osd_render_crosshair_shape(cairo_t *cr) {
1237  {      cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
1238      g_return_if_fail (OSM_IS_GPS_MAP (object));                 OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
1239      float lat,lon;  
1240      OsmGpsMap *map = OSM_GPS_MAP(object);      cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS,
1241      OsmGpsMapPrivate *priv = map->priv;                     OSD_CROSSHAIR_H/2);
1242        cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0);
1243        cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS,
1244                       OSD_CROSSHAIR_H/2);
1245        cairo_rel_line_to (cr,  OSD_CROSSHAIR_TICK, 0);
1246    
1247        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1248                       OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS);
1249        cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK);
1250        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1251                       OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS);
1252        cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
1253    
1254      switch (prop_id)      cairo_stroke (cr);
     {  
         case PROP_AUTO_CENTER:  
             g_value_set_boolean(value, priv->map_auto_center);  
             break;  
         case PROP_RECORD_TRIP_HISTORY:  
             g_value_set_boolean(value, priv->record_trip_history);  
             break;  
         case PROP_SHOW_TRIP_HISTORY:  
             g_value_set_boolean(value, priv->show_trip_history);  
             break;  
         case PROP_AUTO_DOWNLOAD:  
             g_value_set_boolean(value, priv->map_auto_download);  
             break;  
         case PROP_REPO_URI:  
             g_value_set_string(value, priv->repo_uri);  
             break;  
         case PROP_PROXY_URI:  
             g_value_set_string(value, priv->proxy_uri);  
             break;  
         case PROP_TILE_CACHE_DIR:  
             g_value_set_string(value, priv->cache_dir);  
             break;  
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             g_value_set_boolean(value, priv->cache_dir_is_full_path);  
             break;  
         case PROP_ZOOM:  
             g_value_set_int(value, priv->map_zoom);  
             break;  
         case PROP_MAX_ZOOM:  
             g_value_set_int(value, priv->max_zoom);  
             break;  
         case PROP_MIN_ZOOM:  
             g_value_set_int(value, priv->min_zoom);  
             break;  
         case PROP_LATITUDE:  
             lat = pixel2lat(priv->map_zoom,  
                             priv->map_y + (GTK_WIDGET(map)->allocation.height / 2));  
             g_value_set_float(value, rad2deg(lat));  
             break;  
         case PROP_LONGITUDE:  
             lon = pixel2lon(priv->map_zoom,  
                             priv->map_x + (GTK_WIDGET(map)->allocation.width / 2));  
             g_value_set_float(value, rad2deg(lon));  
             break;  
         case PROP_MAP_X:  
             g_value_set_int(value, priv->map_x);  
             break;  
         case PROP_MAP_Y:  
             g_value_set_int(value, priv->map_y);  
             break;  
         case PROP_TILES_QUEUED:  
             g_value_set_int(value, g_hash_table_size(priv->tile_queue));  
             break;  
         case PROP_GPS_TRACK_WIDTH:  
             g_value_set_int(value, priv->ui_gps_track_width);  
             break;  
         case PROP_GPS_POINT_R1:  
             g_value_set_int(value, priv->ui_gps_point_inner_radius);  
             break;  
         case PROP_GPS_POINT_R2:  
             g_value_set_int(value, priv->ui_gps_point_outer_radius);  
             break;  
         case PROP_MAP_SOURCE:  
             g_value_set_int(value, priv->map_source);  
             break;  
         case PROP_IMAGE_FORMAT:  
             g_value_set_string(value, priv->image_format);  
             break;  
         default:  
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);  
             break;  
     }  
1255  }  }
1256    
1257  static gboolean  static void
1258  osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll  *event)  osd_render_crosshair(osm_gps_map_osd_t *osd)
1259  {  {
1260      OsmGpsMap *map = OSM_GPS_MAP(widget);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     OsmGpsMapPrivate *priv = map->priv;  
1261    
1262      if (event->direction == GDK_SCROLL_UP)      if(priv->crosshair.rendered)
1263      {          return;
         osm_gps_map_set_zoom(map, priv->map_zoom+1);  
     }  
     else  
     {  
         osm_gps_map_set_zoom(map, priv->map_zoom-1);  
     }  
   
     return FALSE;  
 }  
   
 static gboolean  
 osm_gps_map_button_press (GtkWidget *widget, GdkEventButton *event)  
 {  
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
1264    
1265  #ifdef ENABLE_BALLOON      priv->crosshair.rendered = TRUE;
     /* 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;  
         return FALSE;  
     }  
 #endif  
1266    
1267  #ifdef ENABLE_OSD      /* first fill with transparency */
1268      #define SCROLL_STEP 10      cairo_t *cr = cairo_create(priv->crosshair.surface);
1269        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1270        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1271        cairo_paint(cr);
1272        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1273    
1274      /* pressed inside OSD control? */      cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1275      osd_button_t but = osm_gps_map_osd_check(event->x, event->y);  
1276      if(but != OSD_NONE)      cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
1277      {      cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2);
1278          priv->drag_counter = -1;      osd_render_crosshair_shape(cr);
1279    
1280        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
1281        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4);
1282        osd_render_crosshair_shape(cr);
1283    
1284          switch(but) {      cairo_destroy(cr);
1285          case OSD_GPS:  }
1286              priv->osd.cb(priv->osd.data);  #endif
             break;  
   
         case OSD_UP:  
             priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;  
             priv->center_coord_set = FALSE;  
             break;  
   
         case OSD_DOWN:  
             priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP;  
             priv->center_coord_set = FALSE;  
             break;  
   
         case OSD_LEFT:  
             priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;  
             priv->center_coord_set = FALSE;  
             break;  
   
         case OSD_RIGHT:  
             priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP;  
             priv->center_coord_set = FALSE;  
             break;  
   
         case OSD_IN:  
             osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);  
             break;  
   
         case OSD_OUT:  
             osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);  
             break;  
1287    
1288          default:  #ifdef OSD_SCALE
             break;  
         }  
1289    
1290          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));  #ifndef OSD_SCALE_FONT_SIZE
1291    #define OSD_SCALE_FONT_SIZE 12
         return FALSE;  
     }  
1292  #endif  #endif
1293    #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)
1294    #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)
1295    
1296      priv->drag_counter = 0;  /* various parameters used to create the scale */
1297      priv->drag_start_mouse_x = (int) event->x;  #define OSD_SCALE_H2   (OSD_SCALE_H/2)
1298      priv->drag_start_mouse_y = (int) event->y;  #define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3)
1299      priv->drag_start_map_x = priv->map_x;  #define OSD_SCALE_M    (OSD_SCALE_H2 - OSD_SCALE_TICK)
1300      priv->drag_start_map_y = priv->map_y;  #define OSD_SCALE_I    (OSD_SCALE_H2 + OSD_SCALE_TICK)
1301    #define OSD_SCALE_FD   (OSD_SCALE_FONT_SIZE/4)
1302    
1303      return FALSE;  static void
1304  }  osd_render_scale(osm_gps_map_osd_t *osd)
   
 static gboolean  
 osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event)  
1305  {  {
1306      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
   
 #ifdef ENABLE_BALLOON  
     /* released inside the balloon? */  
     if (osm_gps_map_in_balloon(priv,  
                    event->x + EXTRA_BORDER,  
                    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  
1307    
1308      if (priv->dragging)      /* this only needs to be rendered if the zoom has changed */
1309      {      gint zoom;
1310          priv->dragging = FALSE;      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1311        if(zoom == priv->scale.zoom)
1312            return;
1313    
1314          priv->map_x = priv->drag_start_map_x;      priv->scale.zoom = zoom;
         priv->map_y = priv->drag_start_map_y;  
1315    
1316          priv->map_x += (priv->drag_start_mouse_x - (int) event->x);      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
         priv->map_y += (priv->drag_start_mouse_y - (int) event->y);  
1317    
1318          priv->center_coord_set = FALSE;      /* first fill with transparency */
1319        cairo_t *cr = cairo_create(priv->scale.surface);
1320        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1321        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1322        // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1323        cairo_paint(cr);
1324        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1325    
1326          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));      /* determine the size of the scale width in meters */
1327        float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix;
1328    
1329        /* scale this to useful values */
1330        int exp = logf(width)*M_LOG10E;
1331        int mant = width/pow(10,exp);
1332        int width_metric = mant * pow(10,exp);
1333        char *dist_str = NULL;
1334        if(width_metric<1000)
1335            dist_str = g_strdup_printf("%u m", width_metric);
1336        else
1337            dist_str = g_strdup_printf("%u km", width_metric/1000);
1338        width_metric /= m_per_pix;
1339    
1340        /* and now the hard part: scale for useful imperial values :-( */
1341        /* try to convert to feet, 1ft == 0.3048 m */
1342        width /= 0.3048;
1343        float imp_scale = 0.3048;
1344        char *dist_imp_unit = "ft";
1345    
1346        if(width >= 100) {
1347            /* 1yd == 3 feet */
1348            width /= 3.0;
1349            imp_scale *= 3.0;
1350            dist_imp_unit = "yd";
1351    
1352            if(width >= 1760.0) {
1353                /* 1mi == 1760 yd */
1354                width /= 1760.0;
1355                imp_scale *= 1760.0;
1356                dist_imp_unit = "mi";
1357            }
1358      }      }
1359    
1360      priv->drag_mouse_dx = 0;      /* also convert this to full tens/hundreds */
1361      priv->drag_mouse_dy = 0;      exp = logf(width)*M_LOG10E;
1362      priv->drag_counter = -1;      mant = width/pow(10,exp);
1363        int width_imp = mant * pow(10,exp);
1364        char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit);
1365    
1366        /* convert back to pixels */
1367        width_imp *= imp_scale;
1368        width_imp /= m_per_pix;
1369    
1370        cairo_select_font_face (cr, "Sans",
1371                                CAIRO_FONT_SLANT_NORMAL,
1372                                CAIRO_FONT_WEIGHT_BOLD);
1373        cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE);
1374        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
1375    
1376        cairo_text_extents_t extents;
1377        cairo_text_extents (cr, dist_str, &extents);
1378    
1379        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1380        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1381        cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1382        cairo_text_path (cr, dist_str);
1383        cairo_stroke (cr);
1384        cairo_move_to (cr, 2*OSD_SCALE_FD,
1385                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1386        cairo_text_path (cr, dist_str_imp);
1387        cairo_stroke (cr);
1388    
1389      return FALSE;      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1390  }      cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1391        cairo_show_text (cr, dist_str);
1392        cairo_move_to (cr, 2*OSD_SCALE_FD,
1393                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1394        cairo_show_text (cr, dist_str_imp);
1395    
1396        g_free(dist_str);
1397        g_free(dist_str_imp);
1398    
1399        /* draw white line */
1400        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1401        cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
1402        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3);
1403        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1404        cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1405        cairo_rel_line_to (cr, width_metric, 0);
1406        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1407        cairo_stroke(cr);
1408        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1409        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1410        cairo_rel_line_to (cr, width_imp, 0);
1411        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1412        cairo_stroke(cr);
1413    
1414        /* draw black line */
1415        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
1416        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1417        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1418        cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1419        cairo_rel_line_to (cr, width_metric, 0);
1420        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1421        cairo_stroke(cr);
1422        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1423        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1424        cairo_rel_line_to (cr, width_imp, 0);
1425        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1426        cairo_stroke(cr);
1427    
1428  static gboolean      cairo_destroy(cr);
1429  osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);  }
1430    #endif
1431    
1432  static gboolean  static void
1433  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osd_render_controls(osm_gps_map_osd_t *osd)
1434  {  {
1435      int x, y;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     GdkModifierType state;  
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
1436    
1437      if (event->is_hint)      if(priv->controls.rendered
1438          gdk_window_get_pointer (event->window, &x, &y, &state);  #ifdef OSD_GPS_BUTTON
1439      else         && (priv->controls.gps_enabled == (osd->cb != NULL))
1440      {  #endif
1441          x = event->x;         )
1442          y = event->y;          return;
         state = event->state;  
     }  
   
     // are we being dragged  
     if (!(state & GDK_BUTTON1_MASK))  
         return FALSE;  
   
     if (priv->drag_counter < 0)  
         return FALSE;  
1443    
1444      priv->drag_counter++;  #ifdef OSD_GPS_BUTTON
1445        priv->controls.gps_enabled = (osd->cb != NULL);
1446    #endif
1447        priv->controls.rendered = TRUE;
1448    
1449      // we havent dragged more than 6 pixels  #ifndef OSD_COLOR
1450      if (priv->drag_counter < 6)      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
1451          return FALSE;      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
1452        GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
1453    #endif
1454    
1455  #ifdef USE_MAEMO      /* first fill with transparency */
1456      /* reduce update frequency on maemo to keep screen update fluid */      cairo_t *cr = cairo_create(priv->controls.surface);
1457      static guint32 last_time = 0;      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1458        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1459        cairo_paint(cr);
1460        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1461    
1462      if(event->time - last_time < 100) return FALSE;      /* --------- draw zoom and dpad shape shadow ----------- */
1463      last_time = event->time;  #ifdef OSD_SHADOW_ENABLE
1464        osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
1465        osd_shape_shadow(cr);
1466    #ifndef OSD_NO_DPAD
1467        osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
1468        osd_shape_shadow(cr);
1469    #endif
1470  #endif  #endif
1471    
1472      priv->dragging = TRUE;      /* --------- draw zoom and dpad shape ----------- */
   
     if (priv->map_auto_center)  
         g_object_set(G_OBJECT(widget), "auto-center", FALSE, NULL);  
1473    
1474      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      osd_zoom_shape(cr, 1, 1);
1475      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;  #ifndef OSD_COLOR
1476        osd_shape(cr, &bg, &fg);
1477    #else
1478        osd_shape(cr);
1479    #endif
1480    #ifndef OSD_NO_DPAD
1481        osd_dpad_shape(cr, 1, 1);
1482    #ifndef OSD_COLOR
1483        osd_shape(cr, &bg, &fg);
1484    #else
1485        osd_shape(cr);
1486    #endif
1487    #endif
1488    
1489  #ifdef ENABLE_OSD      /* --------- draw zoom and dpad labels --------- */
     /* undo OSD */  
     osm_gps_map_osd_restore (OSM_GPS_MAP(widget));  
1490    
1491      /* draw new OSD */  #ifdef OSD_SHADOW_ENABLE
1492      osm_gps_map_osd_draw_controls (OSM_GPS_MAP(widget),      osd_labels_shadow(cr, Z_RAD/3, TRUE);
1493                                     -priv->drag_mouse_dx,      osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1494                                     -priv->drag_mouse_dy);  #ifndef OSD_NO_DPAD
1495        osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1496    #endif
1497        cairo_stroke(cr);
1498    #ifdef OSD_GPS_BUTTON
1499        osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);
1500        osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1501        cairo_stroke(cr);
1502    #endif
1503  #endif  #endif
1504    
1505      osm_gps_map_expose (widget, NULL);  #ifndef OSD_COLOR
1506        osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
1507    #else
1508        osd_labels(cr, Z_RAD/3, TRUE);
1509    #endif
1510        osd_zoom_labels(cr, 1, 1);
1511    #ifndef OSD_NO_DPAD
1512        osd_dpad_labels(cr, 1, 1);
1513    #endif
1514        cairo_stroke(cr);
1515    
1516      return FALSE;  #ifndef OSD_COLOR
1517        osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);
1518    #else
1519        osd_labels(cr, Z_RAD/6, osd->cb != NULL);
1520    #endif
1521    #ifdef OSD_GPS_BUTTON
1522        osd_dpad_gps(cr, 1, 1);
1523    #endif
1524        cairo_stroke(cr);
1525    
1526        cairo_destroy(cr);
1527  }  }
1528    
1529  static gboolean  static void
1530  osm_gps_map_configure (GtkWidget *widget, GdkEventConfigure *event)  osd_render(osm_gps_map_osd_t *osd)
1531  {  {
1532      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      /* this function is actually called pretty often since the */
1533        /* OSD contents may have changed (due to a coordinate/zoom change). */
1534        /* The different OSD parts have to make sure that they don't */
1535        /* render unneccessarily often and thus waste CPU power */
1536    
1537      /* create pixmap */      osd_render_controls(osd);
     if (priv->pixmap)  
         g_object_unref (priv->pixmap);  
1538    
1539      priv->pixmap = gdk_pixmap_new (  #ifdef OSD_SOURCE_SEL
1540                                     widget->window,      osd_render_source_sel(osd, FALSE);
1541                                     widget->allocation.width + EXTRA_BORDER * 2,  #endif
                                    widget->allocation.height + EXTRA_BORDER * 2,  
                                    -1);  
   
     /* and gc, used for clipping (I think......) */  
     if(priv->gc_map)  
         g_object_unref(priv->gc_map);  
   
     priv->gc_map = gdk_gc_new(priv->pixmap);  
1542    
1543      osm_gps_map_map_redraw(OSM_GPS_MAP(widget));  #ifdef OSD_SCALE
1544        osd_render_scale(osd);
1545    #endif
1546    
1547      return FALSE;  #ifdef OSD_CROSSHAIR
1548  }      osd_render_crosshair(osd);
1549    #endif
1550    
1551  static gboolean  #ifdef OSD_NAV
1552  osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event)      osd_render_nav(osd);
1553  {  #endif
     OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);  
1554    
1555      gdk_draw_drawable (  #ifdef OSD_COORDINATES
1556                         widget->window,      osd_render_coordinates(osd);
                        widget->style->fg_gc[GTK_WIDGET_STATE (widget)],  
                        priv->pixmap,  
                        0,0,  
                        priv->drag_mouse_dx - EXTRA_BORDER,  
                        priv->drag_mouse_dy - EXTRA_BORDER,  
                        -1,-1);  
   
     //Paint white outside of the map if dragging. Its less  
     //ugly than painting the corrupted map  
     if(priv->drag_mouse_dx>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
     else if (-priv->drag_mouse_dx > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,  
                             -priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
   
     if (priv->drag_mouse_dy>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             widget->allocation.width,  
                             priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
     else if (-priv->drag_mouse_dy > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,  
                             widget->allocation.width,  
                             -priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
 #if 0  
     if(!priv->dragging)  
         gdk_draw_drawable (  
                        widget->window,  
                        widget->style->fg_gc[GTK_WIDGET_STATE (widget)],  
                        priv->pixmap,  
                        event->area.x + EXTRA_BORDER,  
                        event->area.y + EXTRA_BORDER,  
                        event->area.x, event->area.y,  
                        event->area.width, event->area.height);  
1557  #endif  #endif
     return FALSE;  
1558  }  }
1559    
1560  static void  static void
1561  osm_gps_map_class_init (OsmGpsMapClass *klass)  osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)
1562  {  {
1563      GObjectClass* object_class = G_OBJECT_CLASS (klass);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);  
   
     g_type_class_add_private (klass, sizeof (OsmGpsMapPrivate));  
1564    
1565      object_class->dispose = osm_gps_map_dispose;      /* OSD itself uses some off-screen rendering, so check if the */
1566      object_class->finalize = osm_gps_map_finalize;      /* offscreen buffer is present and create it if not */
1567      object_class->constructor = osm_gps_map_constructor;      if(!priv->controls.surface) {
1568      object_class->set_property = osm_gps_map_set_property;          /* create overlay ... */
1569      object_class->get_property = osm_gps_map_get_property;          priv->controls.surface =
1570                cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
     widget_class->expose_event = osm_gps_map_expose;  
     widget_class->configure_event = osm_gps_map_configure;  
     widget_class->button_press_event = osm_gps_map_button_press;  
     widget_class->button_release_event = osm_gps_map_button_release;  
     widget_class->motion_notify_event = osm_gps_map_motion_notify;  
     widget_class->scroll_event = osm_gps_map_scroll_event;  
   
     g_object_class_install_property (object_class,  
                                      PROP_AUTO_CENTER,  
                                      g_param_spec_boolean ("auto-center",  
                                                            "auto center",  
                                                            "map auto center",  
                                                            TRUE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_RECORD_TRIP_HISTORY,  
                                      g_param_spec_boolean ("record-trip-history",  
                                                            "record trip history",  
                                                            "should all gps points be recorded in a trip history",  
                                                            TRUE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_SHOW_TRIP_HISTORY,  
                                      g_param_spec_boolean ("show-trip-history",  
                                                            "show trip history",  
                                                            "should the recorded trip history be shown on the map",  
                                                            TRUE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_AUTO_DOWNLOAD,  
                                      g_param_spec_boolean ("auto-download",  
                                                            "auto download",  
                                                            "map auto download",  
                                                            TRUE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_REPO_URI,  
                                      g_param_spec_string ("repo-uri",  
                                                           "repo uri",  
                                                           "map source tile repository uri",  
                                                           OSM_REPO_URI,  
                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
      g_object_class_install_property (object_class,  
                                      PROP_PROXY_URI,  
                                      g_param_spec_string ("proxy-uri",  
                                                           "proxy uri",  
                                                           "http proxy uri on NULL",  
                                                           NULL,  
                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_TILE_CACHE_DIR,  
                                      g_param_spec_string ("tile-cache",  
                                                           "tile cache",  
                                                           "osm local tile cache dir",  
                                                           NULL,  
                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_TILE_CACHE_DIR_IS_FULL_PATH,  
                                      g_param_spec_boolean ("tile-cache-is-full-path",  
                                                            "tile cache is full path",  
                                                            "if true, the path passed to tile-cache is interpreted as the full cache path",  
                                                            FALSE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_ZOOM,  
                                      g_param_spec_int ("zoom",  
                                                        "zoom",  
                                                        "zoom level",  
                                                        MIN_ZOOM, /* minimum property value */  
                                                        MAX_ZOOM, /* maximum property value */  
                                                        3,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_MAX_ZOOM,  
                                      g_param_spec_int ("max-zoom",  
                                                        "max zoom",  
                                                        "maximum zoom level",  
                                                        MIN_ZOOM, /* minimum property value */  
                                                        MAX_ZOOM, /* maximum property value */  
                                                        OSM_MAX_ZOOM,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_MIN_ZOOM,  
                                      g_param_spec_int ("min-zoom",  
                                                        "min zoom",  
                                                        "minimum zoom level",  
                                                        MIN_ZOOM, /* minimum property value */  
                                                        MAX_ZOOM, /* maximum property value */  
                                                        OSM_MIN_ZOOM,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_LATITUDE,  
                                      g_param_spec_float ("latitude",  
                                                          "latitude",  
                                                          "latitude in degrees",  
                                                          -90.0, /* minimum property value */  
                                                          90.0, /* maximum property value */  
                                                          0,  
                                                          G_PARAM_READABLE));  
   
     g_object_class_install_property (object_class,  
                                      PROP_LONGITUDE,  
                                      g_param_spec_float ("longitude",  
                                                          "longitude",  
                                                          "longitude in degrees",  
                                                          -180.0, /* minimum property value */  
                                                          180.0, /* maximum property value */  
                                                          0,  
                                                          G_PARAM_READABLE));  
   
     g_object_class_install_property (object_class,  
                                      PROP_MAP_X,  
                                      g_param_spec_int ("map-x",  
                                                        "map-x",  
                                                        "initial map x location",  
                                                        G_MININT, /* minimum property value */  
                                                        G_MAXINT, /* maximum property value */  
                                                        890,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_MAP_Y,  
                                      g_param_spec_int ("map-y",  
                                                        "map-y",  
                                                        "initial map y location",  
                                                        G_MININT, /* minimum property value */  
                                                        G_MAXINT, /* maximum property value */  
                                                        515,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_TILES_QUEUED,  
                                      g_param_spec_int ("tiles-queued",  
                                                        "tiles-queued",  
                                                        "number of tiles currently waiting to download",  
                                                        G_MININT, /* minimum property value */  
                                                        G_MAXINT, /* maximum property value */  
                                                        0,  
                                                        G_PARAM_READABLE));  
   
     g_object_class_install_property (object_class,  
                                      PROP_GPS_TRACK_WIDTH,  
                                      g_param_spec_int ("gps-track-width",  
                                                        "gps-track-width",  
                                                        "width of the lines drawn for the gps track",  
                                                        1,           /* minimum property value */  
                                                        G_MAXINT,    /* maximum property value */  
                                                        4,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_GPS_POINT_R1,  
                                      g_param_spec_int ("gps-track-point-radius",  
                                                        "gps-track-point-radius",  
                                                        "radius of the gps point inner circle",  
                                                        0,           /* minimum property value */  
                                                        G_MAXINT,    /* maximum property value */  
                                                        10,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_GPS_POINT_R2,  
                                      g_param_spec_int ("gps-track-highlight-radius",  
                                                        "gps-track-highlight-radius",  
                                                        "radius of the gps point highlight circle",  
                                                        0,           /* minimum property value */  
                                                        G_MAXINT,    /* maximum property value */  
                                                        20,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));  
   
     g_object_class_install_property (object_class,  
                                      PROP_MAP_SOURCE,  
                                      g_param_spec_int ("map-source",  
                                                        "map source",  
                                                        "map source ID",  
                                                        -1,           /* minimum property value */  
                                                        G_MAXINT,    /* maximum property value */  
                                                        -1,  
                                                        G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
                                      PROP_IMAGE_FORMAT,  
                                      g_param_spec_string ("image-format",  
                                                           "image format",  
                                                           "map source tile repository image format (jpg, png)",  
                                                           OSM_IMAGE_FORMAT,  
                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
 }  
   
 const char*  
 osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source)  
 {  
     switch(source)  
     {  
         case OSM_GPS_MAP_SOURCE_NULL:  
             return "None";  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:  
             return "OpenStreetMap";  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:  
             return "OpenStreetMap Renderer";  
         case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:  
             return "OpenAerialMap";  
         case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:  
             return "Maps-For-Free";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:  
             return "Google Maps";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:  
             return "Google Satellite";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:  
             return "Google Hybrid";  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:  
             return "Virtual Earth";  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:  
             return "Virtual Earth Satellite";  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:  
             return "Virtual Earth Hybrid";  
         case OSM_GPS_MAP_SOURCE_YAHOO_STREET:  
             return "Yahoo Maps";  
         case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:  
             return "Yahoo Satellite";  
         case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:  
             return "Yahoo Hybrid";  
         default:  
             return NULL;  
     }  
     return NULL;  
 }  
   
 //http://www.internettablettalk.com/forums/showthread.php?t=5209  
 //https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup  
 //http://www.ponies.me.uk/maps/GoogleTileUtils.java  
 //http://www.mgmaps.com/cache/MapTileCacher.perl  
 const char*  
 osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source)  
 {  
     switch(source)  
     {  
         case OSM_GPS_MAP_SOURCE_NULL:  
             return "none://";  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:  
             return OSM_REPO_URI;  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:  
             return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";  
         case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:  
             return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg";  
         case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:  
             return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:  
             return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:  
             return "http://khm#R.google.com/kh?n=404&v=3&t=#Q";  
         case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:  
             return NULL; /* No longer working  "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:  
             return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50";  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:  
             return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50";  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:  
             return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50";  
         case OSM_GPS_MAP_SOURCE_YAHOO_STREET:  
         case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:  
         case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:  
             /* TODO: Implement signed Y, aka U  
              * http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d  
              *  x = tilex,  
              *  y = (1 << (MAX_ZOOM - zoom)) - tiley - 1,  
              *  z = zoom - (MAX_ZOOM - 17));  
              */  
             return NULL;  
         default:  
             return NULL;  
     }  
     return NULL;  
 }  
   
 const char *  
 osm_gps_map_source_get_image_format(OsmGpsMapSource_t source)  
 {  
     switch(source) {  
         case OSM_GPS_MAP_SOURCE_NULL:  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:  
             return "png";  
         case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:  
         case OSM_GPS_MAP_SOURCE_YAHOO_STREET:  
         case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:  
         case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:  
         case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:  
             return "jpg";  
         default:  
             return "bin";  
     }  
     return "bin";  
 }  
1571    
1572            priv->controls.rendered = FALSE;
1573    #ifdef OSD_GPS_BUTTON
1574            priv->controls.gps_enabled = FALSE;
1575    #endif
1576    
1577  int  #ifdef OSD_SOURCE_SEL
1578  osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source)          /* the initial OSD state is alway not-expanded */
1579  {          priv->source_sel.surface =
1580      return 1;              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1581  }                                             OSD_S_W+2, OSD_S_H+2);
1582            priv->source_sel.rendered = FALSE;
1583    #endif
1584    
1585  int  #ifdef OSD_SCALE
1586  osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source)          priv->scale.surface =
1587  {              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1588      switch(source) {                                         OSD_SCALE_W, OSD_SCALE_H);
1589          case OSM_GPS_MAP_SOURCE_NULL:          priv->scale.zoom = -1;
1590              return 18;  #endif
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:  
             return OSM_MAX_ZOOM;  
         case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:  
         case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:  
         case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:  
         case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:  
         case OSM_GPS_MAP_SOURCE_YAHOO_STREET:  
         case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:  
         case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:  
             return 17;  
         case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:  
             return 11;  
         case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:  
             return 18;  
         default:  
             return 17;  
     }  
     return 17;  
 }  
1591    
1592  void  #ifdef OSD_CROSSHAIR
1593  osm_gps_map_download_maps (OsmGpsMap *map, coord_t *pt1, coord_t *pt2, int zoom_start, int zoom_end)          priv->crosshair.surface =
1594  {              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1595      int i,j,zoom,num_tiles;                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1596      OsmGpsMapPrivate *priv = map->priv;          priv->crosshair.rendered = FALSE;
1597    #endif
1598    
1599      if (pt1 && pt2)  #ifdef OSD_NAV
1600      {          priv->nav.surface =
1601          gchar *filename;              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1602          num_tiles = 0;                                         OSD_NAV_W, OSD_NAV_H);
1603          zoom_end = CLAMP(zoom_end, priv->min_zoom, priv->max_zoom);  #endif
         g_debug("Download maps: z:%d->%d",zoom_start, zoom_end);  
   
         for(zoom=zoom_start; zoom<=zoom_end; zoom++)  
         {  
             int x1,y1,x2,y2;  
   
             x1 = (int)floor((float)lon2pixel(zoom, pt1->rlon) / (float)TILESIZE);  
             y1 = (int)floor((float)lat2pixel(zoom, pt1->rlat) / (float)TILESIZE);  
   
             x2 = (int)floor((float)lon2pixel(zoom, pt2->rlon) / (float)TILESIZE);  
             y2 = (int)floor((float)lat2pixel(zoom, pt2->rlat) / (float)TILESIZE);  
   
             // loop x1-x2  
             for(i=x1; i<=x2; i++)  
             {  
                 // loop y1 - y2  
                 for(j=y1; j<=y2; j++)  
                 {  
                     // x = i, y = j  
                     filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",  
                                     priv->cache_dir, G_DIR_SEPARATOR,  
                                     zoom, G_DIR_SEPARATOR,  
                                     i, G_DIR_SEPARATOR,  
                                     j,  
                                     priv->image_format);  
                     if (!g_file_test(filename, G_FILE_TEST_EXISTS))  
                     {  
                         osm_gps_map_download_tile(map, zoom, i, j, FALSE);  
                         num_tiles++;  
                     }  
                     g_free(filename);  
                 }  
             }  
             g_debug("DL @Z:%d = %d tiles",zoom,num_tiles);  
         }  
     }  
 }  
1604    
1605  void  #ifdef OSD_COORDINATES
1606  osm_gps_map_get_bbox (OsmGpsMap *map, coord_t *pt1, coord_t *pt2)          priv->coordinates.surface =
1607  {              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1608      OsmGpsMapPrivate *priv = map->priv;                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1609    
1610      if (pt1 && pt2) {          priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1611          pt1->rlat = pixel2lat(priv->map_zoom, priv->map_y);  #endif
         pt1->rlon = pixel2lon(priv->map_zoom, priv->map_x);  
         pt2->rlat = pixel2lat(priv->map_zoom, priv->map_y + GTK_WIDGET(map)->allocation.height);  
         pt2->rlon = pixel2lon(priv->map_zoom, priv->map_x + GTK_WIDGET(map)->allocation.width);  
1612    
1613          g_debug("BBOX: %f %f %f %f", pt1->rlat, pt1->rlon, pt2->rlat, pt2->rlon);          /* ... and render it */
1614            osd_render(osd);
1615      }      }
 }  
   
 void  
 osm_gps_map_set_mapcenter (OsmGpsMap *map, float latitude, float longitude, int zoom)  
 {  
     osm_gps_map_set_center (map, latitude, longitude);  
     osm_gps_map_set_zoom (map, zoom);  
 }  
   
 void  
 osm_gps_map_set_center (OsmGpsMap *map, float latitude, float longitude)  
 {  
     int pixel_x, pixel_y;  
     OsmGpsMapPrivate *priv;  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
1616    
1617      priv->center_rlat = deg2rad(latitude);      // now draw this onto the original context
1618      priv->center_rlon = deg2rad(longitude);      cairo_t *cr = gdk_cairo_create(drawable);
     priv->center_coord_set = TRUE;  
1619    
1620      // pixel_x,y, offsets      gint x, y;
     pixel_x = lon2pixel(priv->map_zoom, priv->center_rlon);  
     pixel_y = lat2pixel(priv->map_zoom, priv->center_rlat);  
1621    
1622      priv->map_x = pixel_x - GTK_WIDGET(map)->allocation.width/2;  #ifdef OSD_SCALE
1623      priv->map_y = pixel_y - GTK_WIDGET(map)->allocation.height/2;      x =  OSD_X;
1624        y = -OSD_Y;
1625        if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1626        if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1627    
1628      osm_gps_map_map_redraw_idle(map);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1629  }      cairo_paint(cr);
1630    #endif
1631    
1632  int  #ifdef OSD_CROSSHAIR
1633  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1634  {      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
     int zoom_old;  
     double factor = 0.0;  
     int width_center, height_center;  
     OsmGpsMapPrivate *priv;  
1635    
1636      g_return_val_if_fail (OSM_IS_GPS_MAP (map), 0);      cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1637      priv = map->priv;      cairo_paint(cr);
1638    #endif
1639    
1640      if (zoom != priv->map_zoom)  #ifdef OSD_NAV
1641      {      x =  OSD_X;
1642          width_center  = GTK_WIDGET(map)->allocation.width / 2;      if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1643          height_center = GTK_WIDGET(map)->allocation.height / 2;      y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1644    
1645          zoom_old = priv->map_zoom;      cairo_set_source_surface(cr, priv->nav.surface, x, y);
1646          //constrain zoom min_zoom -> max_zoom      cairo_paint(cr);
1647          priv->map_zoom = CLAMP(zoom, priv->min_zoom, priv->max_zoom);  #endif
   
         if (priv->center_coord_set)  
         {  
             priv->map_x = lon2pixel(priv->map_zoom, priv->center_rlon) - width_center;  
             priv->map_y = lat2pixel(priv->map_zoom, priv->center_rlat) - height_center;  
         }  
         else  
         {  
             factor = exp(priv->map_zoom * M_LN2)/exp(zoom_old * M_LN2);  
             priv->map_x = ((priv->map_x + width_center) * factor) - width_center;  
             priv->map_y = ((priv->map_y + height_center) * factor) - height_center;  
         }  
1648    
1649          g_debug("Zoom changed from %d to %d factor:%f x:%d",  #ifdef OSD_COORDINATES
1650                  zoom_old, priv->map_zoom, factor, priv->map_x);      x = -OSD_X;
1651        y = -OSD_Y;
1652        if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1653        if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1654    
1655          osm_gps_map_map_redraw_idle(map);      cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1656      }      cairo_paint(cr);
1657      return priv->map_zoom;  #endif
 }  
1658    
1659  void  #ifdef OSD_BALLOON
1660  osm_gps_map_add_track (OsmGpsMap *map, GSList *track)      if(priv->balloon.surface) {
1661  {  
1662      OsmGpsMapPrivate *priv;          /* convert given lat lon into screen coordinates */
1663            gint x, y;
1664            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1665                                          priv->balloon.lat, priv->balloon.lon,
1666                                          &x, &y);
1667    
1668      g_return_if_fail (OSM_IS_GPS_MAP (map));          /* check if balloon needs to be rerendered */
1669      priv = map->priv;          osd_render_balloon(osd);
1670    
1671      if (track) {          cairo_set_source_surface(cr, priv->balloon.surface,
1672          priv->tracks = g_slist_append(priv->tracks, track);                                   x + priv->balloon.offset_x,
1673          osm_gps_map_map_redraw_idle(map);                                   y + priv->balloon.offset_y);
1674            cairo_paint(cr);
1675      }      }
1676  }  #endif
   
 void  
 osm_gps_map_clear_tracks (OsmGpsMap *map)  
 {  
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
   
     osm_gps_map_free_tracks(map);  
     osm_gps_map_map_redraw_idle(map);  
 }  
   
 void  
 osm_gps_map_add_image (OsmGpsMap *map, float latitude, float longitude, GdkPixbuf *image)  
 {  
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
   
     if (image) {  
         OsmGpsMapPrivate *priv = map->priv;  
         image_t *im;  
   
         //cache w/h for speed, and add image to list  
         im = g_new0(image_t,1);  
         im->w = gdk_pixbuf_get_width(image);  
         im->h = gdk_pixbuf_get_height(image);  
         im->pt.rlat = deg2rad(latitude);  
         im->pt.rlon = deg2rad(longitude);  
1677    
1678          g_object_ref(image);      x = OSD_X;
1679          im->image = image;      if(x < 0)
1680            x += osd->widget->allocation.width - OSD_W;
1681    
1682          priv->images = g_slist_append(priv->images, im);      y = OSD_Y;
1683        if(y < 0)
1684            y += osd->widget->allocation.height - OSD_H;
1685    
1686          osm_gps_map_map_redraw_idle(map);      cairo_set_source_surface(cr, priv->controls.surface, x, y);
1687      }      cairo_paint(cr);
 }  
1688    
1689  gboolean  #ifdef OSD_SOURCE_SEL
1690  osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image)      if(!priv->source_sel.handler_id) {
1691  {          /* the OSD source selection is not being animated */
1692      OsmGpsMapPrivate *priv = map->priv;          if(!priv->source_sel.expanded)
1693      if (priv->images) {              x = osd->widget->allocation.width - OSD_S_W;
1694          GSList *list;          else
1695          for(list = priv->images; list != NULL; list = list->next)              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1696          {      } else
1697              image_t *im = list->data;          x = priv->source_sel.shift;
1698                  if (im->image == image)  
1699                  {      y = OSD_S_Y;
1700                          priv->images = g_slist_remove_link(priv->images, list);      if(OSD_S_Y < 0) {
1701                          g_object_unref(im->image);          if(!priv->source_sel.expanded)
1702                          g_free(im);              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1703                          osm_gps_map_map_redraw_idle(map);          else
1704                          return TRUE;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
                 }  
         }  
1705      }      }
     return FALSE;  
 }  
1706    
1707  void      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
1708  osm_gps_map_clear_images (OsmGpsMap *map)      cairo_paint(cr);
1709  {  #endif
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
1710    
1711      osm_gps_map_free_images(map);      cairo_destroy(cr);
     osm_gps_map_map_redraw_idle(map);  
1712  }  }
1713    
1714  void  static void
1715  osm_gps_map_osd_speed (OsmGpsMap *map, float speed)  osd_free(osm_gps_map_osd_t *osd)
1716  {  {
1717      OsmGpsMapPrivate *priv;      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1718    
1719      PangoContext        *context = NULL;      if (priv->controls.surface)
1720      PangoLayout     *layout  = NULL;           cairo_surface_destroy(priv->controls.surface);
     PangoFontDescription    *desc    = NULL;  
   
     GdkColor color;  
     GdkGC *gc;  
   
     gchar *buffer;  
     //static int x = 10, y = 10;  
     static int width = 0, height = 0;  
1721    
1722      g_return_if_fail (OSM_IS_GPS_MAP (map));  #ifdef OSD_SOURCE_SEL
1723      priv = map->priv;      if(priv->source_sel.handler_id)
1724            gtk_timeout_remove(priv->source_sel.handler_id);
     buffer = g_strdup_printf("%.0f", speed);  
   
     /* pango initialisation */  
     context = gtk_widget_get_pango_context (GTK_WIDGET(map));  
     layout  = pango_layout_new (context);  
     desc    = pango_font_description_new();  
   
     pango_font_description_set_size (desc, 40 * PANGO_SCALE);  
     pango_layout_set_font_description (layout, desc);  
     pango_layout_set_text (layout, buffer, strlen(buffer));  
   
     gc = gdk_gc_new (GTK_WIDGET(map)->window);  
   
     color.red = (0 > 50) ? 0xffff : 0;  
     color.green = 0;  
     color.blue = 0;  
   
     gdk_gc_set_rgb_fg_color (gc, &color);  
   
     /* faster / less flicker alternative:*/  
     gdk_draw_drawable (  
                        GTK_WIDGET(map)->window,  
                        GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(map)],  
                        priv->pixmap,  
                        0,0,  
                        0,0,  
                        width+10,width+10);  
   
     gdk_draw_layout(GTK_WIDGET(map)->window,  
                     gc,  
                     0, 0,  
                     layout);  
   
     /* set width and height */  
     pango_layout_get_pixel_size(layout, &width, &height);  
   
     g_free(buffer);  
     pango_font_description_free (desc);  
     g_object_unref (layout);  
     g_object_unref (gc);  
 }  
   
 void  
 osm_gps_map_draw_gps (OsmGpsMap *map, float latitude, float longitude, float heading)  
 {  
     int pixel_x, pixel_y;  
     OsmGpsMapPrivate *priv;  
1725    
1726      g_return_if_fail (OSM_IS_GPS_MAP (map));      if (priv->source_sel.surface)
1727      priv = map->priv;           cairo_surface_destroy(priv->source_sel.surface);
1728    #endif
1729    
1730      priv->gps->rlat = deg2rad(latitude);  #ifdef OSD_SCALE
1731      priv->gps->rlon = deg2rad(longitude);      if (priv->scale.surface)
1732      priv->gps_valid = TRUE;           cairo_surface_destroy(priv->scale.surface);
1733    #endif
     // pixel_x,y, offsets  
     pixel_x = lon2pixel(priv->map_zoom, priv->gps->rlon);  
     pixel_y = lat2pixel(priv->map_zoom, priv->gps->rlat);  
   
     //If trip marker add to list of gps points.  
     if (priv->record_trip_history) {  
         coord_t *tp = g_new0(coord_t,1);  
         tp->rlat = priv->gps->rlat;  
         tp->rlon = priv->gps->rlon;  
         priv->trip_history = g_slist_append(priv->trip_history, tp);  
     }  
   
     // dont draw anything if we are dragging  
     if (priv->dragging) {  
         g_debug("Dragging");  
         return;  
     }  
1734    
1735      //Automatically center the map if the track approaches the edge  #ifdef OSD_CROSSHAIR
1736      if(priv->map_auto_center)   {      if (priv->crosshair.surface)
1737          int x = pixel_x - priv->map_x;           cairo_surface_destroy(priv->crosshair.surface);
1738          int y = pixel_y - priv->map_y;  #endif
         int width = GTK_WIDGET(map)->allocation.width;  
         int height = GTK_WIDGET(map)->allocation.height;  
         if( x < (width/2 - width/8)     || x > (width/2 + width/8)  ||  
             y < (height/2 - height/8)   || y > (height/2 + height/8)) {  
   
             priv->map_x = pixel_x - GTK_WIDGET(map)->allocation.width/2;  
             priv->map_y = pixel_y - GTK_WIDGET(map)->allocation.height/2;  
             priv->center_coord_set = FALSE;  
         }  
     }  
1739    
1740      // this redraws the map (including the gps track, and adjusts the  #ifdef OSD_NAV
1741      // map center if it was changed      if (priv->nav.surface)
1742      osm_gps_map_map_redraw_idle(map);           cairo_surface_destroy(priv->nav.surface);
1743  }  #endif
1744    
1745  void  #ifdef OSD_COORDINATES
1746  osm_gps_map_clear_gps (OsmGpsMap *map)      if (priv->coordinates.surface)
1747  {           cairo_surface_destroy(priv->coordinates.surface);
1748      osm_gps_map_free_trip(map);  #endif
     osm_gps_map_map_redraw_idle(map);  
 }  
1749    
1750  coord_t  #ifdef OSD_BALLOON
1751  osm_gps_map_get_co_ordinates (OsmGpsMap *map, int pixel_x, int pixel_y)      if (priv->balloon.surface)
1752  {           cairo_surface_destroy(priv->balloon.surface);
1753      coord_t coord;  #endif
     OsmGpsMapPrivate *priv = map->priv;  
1754    
1755      coord.rlat = pixel2lat(priv->map_zoom, priv->map_y + pixel_y);      g_free(priv);
     coord.rlon = pixel2lon(priv->map_zoom, priv->map_x + pixel_x);  
     return coord;  
1756  }  }
1757    
1758  GtkWidget *  static gboolean
1759  osm_gps_map_new (void)  osd_busy(osm_gps_map_osd_t *osd)
1760  {  {
1761      return g_object_new (OSM_TYPE_GPS_MAP, NULL);  #ifdef OSD_SOURCE_SEL
1762        osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1763        return (priv->source_sel.handler_id != 0);
1764    #else
1765        return FALSE;
1766    #endif
1767  }  }
1768    
1769  void  static osm_gps_map_osd_t osd_classic = {
1770  osm_gps_map_screen_to_geographic (OsmGpsMap *map, gint pixel_x, gint pixel_y,      .widget     = NULL,
                                   gfloat *latitude, gfloat *longitude)  
 {  
     OsmGpsMapPrivate *priv;  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
1771    
1772      if (latitude)      .draw       = osd_draw,
1773          *latitude = rad2deg(pixel2lat(priv->map_zoom, priv->map_y + pixel_y));      .check      = osd_check,
1774      if (longitude)      .render     = osd_render,
1775          *longitude = rad2deg(pixel2lon(priv->map_zoom, priv->map_x + pixel_x));      .free       = osd_free,
1776  }      .busy       = osd_busy,
   
 void  
 osm_gps_map_geographic_to_screen (OsmGpsMap *map,  
                                   gfloat latitude, gfloat longitude,  
                                   gint *pixel_x, gint *pixel_y)  
 {  
     OsmGpsMapPrivate *priv;  
1777    
1778      g_return_if_fail (OSM_IS_GPS_MAP (map));      .cb         = NULL,
1779      priv = map->priv;      .data       = NULL,
1780    
1781      if (pixel_x)      .priv       = NULL
1782          *pixel_x = lon2pixel(priv->map_zoom, deg2rad(longitude)) - priv->map_x;  };
     if (pixel_y)  
         *pixel_y = lat2pixel(priv->map_zoom, deg2rad(latitude)) - priv->map_y;  
 }  
1783    
1784    /* this is the only function that's externally visible */
1785  void  void
1786  osm_gps_map_scroll (OsmGpsMap *map, gint dx, gint dy)  osm_gps_map_osd_classic_init(OsmGpsMap *map)
 {  
     OsmGpsMapPrivate *priv;  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
   
     priv->center_coord_set = FALSE;  
     priv->map_x += dx;  
     priv->map_y += dy;  
   
     osm_gps_map_map_redraw_idle (map);  
 }  
   
 float  
 osm_gps_map_get_scale(OsmGpsMap *map)  
 {  
     OsmGpsMapPrivate *priv;  
   
     g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN);  
     priv = map->priv;  
   
     return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);  
 }  
   
 #ifdef ENABLE_BALLOON  
 void  
 osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,  
                           OsmGpsMapBalloonCallback cb, gpointer data)  
1787  {  {
1788      OsmGpsMapPrivate *priv;      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);
   
     /* remove and previously installed balloon */  
     osm_gps_map_clear_balloon (map);  
   
     g_return_if_fail (OSM_IS_GPS_MAP (map));  
     priv = map->priv;  
   
     priv->balloon.coo->rlat = deg2rad(latitude);  
     priv->balloon.coo->rlon = deg2rad(longitude);  
     priv->balloon.valid = TRUE;  
   
     priv->balloon.cb = cb;  
     priv->balloon.data = data;  
   
     // this redraws the map  
     osm_gps_map_map_redraw_idle(map);  
 }  
1789    
1790  void  #ifdef OSD_BALLOON
1791  osm_gps_map_clear_balloon (OsmGpsMap *map)      priv->balloon.lat = OSM_GPS_MAP_INVALID;
1792  {      priv->balloon.lon = OSM_GPS_MAP_INVALID;
1793      OsmGpsMapPrivate *priv;  #endif
1794    
1795      g_return_if_fail (OSM_IS_GPS_MAP (map));      osd_classic.priv = priv;
     priv = map->priv;  
1796    
1797      priv->balloon.valid = FALSE;      osm_gps_map_register_osd(map, &osd_classic);
   
     osm_gps_map_map_redraw_idle(map);  
1798  }  }
 #endif  
1799    
1800  #ifdef ENABLE_OSD  #ifdef OSD_GPS_BUTTON
1801  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) {  /* below are osd specific functions which aren't used by osm-gps-map */
1802      OsmGpsMapPrivate *priv;  /* but instead are to be used by the main application */
1803    void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
1804      g_return_if_fail (OSM_IS_GPS_MAP (map));                                   gpointer data) {
1805      priv = map->priv;      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1806        g_return_if_fail (osd);
1807    
1808      priv->osd.cb = cb;      osd->cb = cb;
1809      priv->osd.data = data;      osd->data = data;
1810    
1811      /* this may have changed the state of the gps button */      /* this may have changed the state of the gps button */
1812      /* we thus re-render the overlay */      /* we thus re-render the overlay */
1813      osm_gps_map_osd_render(priv);      osd->render(osd);
1814    
1815      osm_gps_map_map_redraw_idle(map);      osm_gps_map_redraw(map);
1816  }  }
1817  #endif  #endif
1818    
1819    osd_button_t
1820    osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {
1821        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1822        g_return_val_if_fail (osd, OSD_NONE);
1823    
1824        return osd_check(osd, TRUE, x, y);
1825    }

Legend:
Removed from v.70  
changed lines
  Added in v.122