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

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

revision 77 by harbaum, Tue Aug 25 12:49:03 2009 UTC revision 113 by harbaum, Wed Sep 16 13:45:10 2009 UTC
# Line 19  Line 19 
19    
20  #include "config.h"  #include "config.h"
21  #include <stdlib.h>  // abs  #include <stdlib.h>  // abs
22  #include <math.h>    // M_PI  #include <math.h>    // M_PI/cos()
23    
24  /* parameters that can be overwritten from the config file: */  /* parameters that can be overwritten from the config file: */
25  /* OSD_DIAMETER */  /* OSD_DIAMETER */
# Line 32  Line 32 
32  #include <cairo.h>  #include <cairo.h>
33    
34  #include "osm-gps-map.h"  #include "osm-gps-map.h"
35    #include "converter.h"
36  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
37    
38  //the osd controls  //the osd controls
39  typedef struct {  typedef struct {
40      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
41      cairo_surface_t *overlay;      struct {
42            cairo_surface_t *surface;
43            gboolean rendered;
44    #ifdef OSD_GPS_BUTTON
45            gboolean gps_enabled;
46    #endif
47        } controls;
48    
49    #ifdef OSD_BALLOON
50        //a balloon with additional info
51        struct {
52            cairo_surface_t *surface;
53            int orientation, offset_x, offset_y;
54    
55            float lat, lon;
56            OsmGpsMapRect_t rect;
57    
58            /* function called to have the user app draw the contents */
59            OsmGpsMapBalloonCallback cb;
60            gpointer data;
61        } balloon;
62    #endif
63    
64    #ifdef OSD_SCALE
65        struct {
66            cairo_surface_t *surface;
67            int zoom;
68        } scale;
69    #endif
70    
71    #ifdef OSD_CROSSHAIR
72        struct {
73            cairo_surface_t *surface;
74            gboolean rendered;
75        } crosshair;
76    #endif
77    
78    #ifdef OSD_COORDINATES
79        struct {
80            cairo_surface_t *surface;
81            float lat, lon;
82        } coordinates;
83    #endif
84    
85    #ifdef OSD_SOURCE_SEL
86        struct {
87            /* values to handle the "source" menu */
88            cairo_surface_t *surface;
89            gboolean expanded;
90            gint shift, dir, count;
91            gint handler_id;
92            gint width, height;
93            gboolean rendered;
94        } source_sel;
95    #endif
96    
97  } osd_priv_t;  } osd_priv_t;
98    
99    #ifdef OSD_BALLOON
100    /* most visual effects are hardcoded by now, but may be made */
101    /* available via properties later */
102    #ifndef BALLOON_AREA_WIDTH
103    #define BALLOON_AREA_WIDTH           290
104    #endif
105    #ifndef BALLOON_AREA_HEIGHT
106    #define BALLOON_AREA_HEIGHT           75
107    #endif
108    #ifndef BALLOON_CORNER_RADIUS
109    #define BALLOON_CORNER_RADIUS         10
110    #endif
111    
112    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
113    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
114    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
115    #define BALLOON_TRANSPARENCY         0.8
116    #define POINTER_HEIGHT                20
117    #define POINTER_FOOT_WIDTH            20
118    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
119    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
120    #define BALLOON_SHADOW_TRANSPARENCY  0.2
121    
122    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
123    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
124    
125    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
126    
127    
128    /* draw the bubble shape. this is used twice, once for the shape and once */
129    /* for the shadow */
130    static void
131    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
132           gboolean bottom, int px, int py, int px0, int px1) {
133    
134        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
135        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
136                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
137        if(!bottom) {
138            /* insert top pointer */
139            cairo_line_to (cr, px1, y0);
140            cairo_line_to (cr, px, py);
141            cairo_line_to (cr, px0, y0);
142        }
143    
144        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
145        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
146                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
147        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
148        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
149                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
150        if(bottom) {
151            /* insert bottom pointer */
152            cairo_line_to (cr, px0, y1);
153            cairo_line_to (cr, px, py);
154            cairo_line_to (cr, px1, y1);
155        }
156    
157        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
158        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
159                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
160    
161        cairo_close_path (cr);
162    }
163    
164    static void
165    osd_render_balloon(osm_gps_map_osd_t *osd) {
166        osd_priv_t *priv = (osd_priv_t*)osd->priv;
167    
168        /* get zoom */
169        gint zoom;
170        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
171    
172        /* ------- convert given coordinate into screen position --------- */
173        gint xs, ys;
174        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
175                                          priv->balloon.lat, priv->balloon.lon,
176                                          &xs, &ys);
177    
178        gint x0 = 1, y0 = 1;
179    
180        /* check position of this relative to screen center to determine */
181        /* pointer direction ... */
182        int pointer_x, pointer_x0, pointer_x1;
183        int pointer_y;
184    
185        /* ... and calculate position */
186        int orientation = 0;
187        if(xs > osd->widget->allocation.width/2) {
188            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
189            pointer_x = x0 - priv->balloon.offset_x;
190            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
191            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
192            orientation |= 1;
193        } else {
194            priv->balloon.offset_x = -POINTER_OFFSET;
195            pointer_x = x0 - priv->balloon.offset_x;
196            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
197            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
198        }
199    
200        gboolean bottom = FALSE;
201        if(ys > osd->widget->allocation.height/2) {
202            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
203            pointer_y = y0 - priv->balloon.offset_y;
204            bottom = TRUE;
205            orientation |= 2;
206        } else {
207            priv->balloon.offset_y = 0;
208            pointer_y = y0 - priv->balloon.offset_y;
209            y0 += POINTER_HEIGHT;
210        }
211    
212        /* if required orientation equals current one, then don't render */
213        /* anything */
214        if(orientation == priv->balloon.orientation)
215            return;
216    
217        priv->balloon.orientation = orientation;
218    
219        /* calculate bottom/right of box */
220        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
221    
222        /* save balloon screen coordinates for later use */
223        priv->balloon.rect.x = x0 + BALLOON_BORDER;
224        priv->balloon.rect.y = y0 + BALLOON_BORDER;
225        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
226        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
227    
228        cairo_t *cr = cairo_create(priv->balloon.surface);
229        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
230        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
231        cairo_paint(cr);
232        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
233    
234        /* --------- draw shadow --------------- */
235        osm_gps_map_draw_balloon_shape (cr,
236                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
237                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
238                     bottom, pointer_x, pointer_y,
239                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
240    
241        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
242        cairo_fill_preserve (cr);
243        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
244        cairo_set_line_width (cr, 0);
245        cairo_stroke (cr);
246    
247        /* --------- draw main shape ----------- */
248        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
249                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
250    
251        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
252        cairo_fill_preserve (cr);
253        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
254        cairo_set_line_width (cr, 1);
255        cairo_stroke (cr);
256    
257        if (priv->balloon.cb) {
258            /* clip in case application tries to draw in */
259                /* exceed of the balloon */
260            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
261                             priv->balloon.rect.w, priv->balloon.rect.h);
262            cairo_clip (cr);
263            cairo_new_path (cr);  /* current path is not
264                                     consumed by cairo_clip() */
265    
266            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
267        }
268    
269        cairo_destroy(cr);
270    }
271    
272    /* return true if balloon is being displayed and if */
273    /* the given coordinate is within this balloon */
274    static gboolean
275    osd_balloon_check(osm_gps_map_osd_t *osd, gint x, gint y)
276    {
277        osd_priv_t *priv = (osd_priv_t*)osd->priv;
278    
279        if(!priv->balloon.surface)
280            return FALSE;
281    
282        gint xs, ys;
283        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
284                                          priv->balloon.lat, priv->balloon.lon,
285                                          &xs, &ys);
286    
287        xs += priv->balloon.rect.x + priv->balloon.offset_x;
288        ys += priv->balloon.rect.y + priv->balloon.offset_y;
289    
290        return (priv->balloon.surface &&
291                (x > xs) && (x < xs + priv->balloon.rect.w) &&
292                (y > ys) && (y < ys + priv->balloon.rect.h));
293    }
294    
295    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
296        g_return_if_fail (OSM_IS_GPS_MAP (map));
297    
298        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
299        g_return_if_fail (osd);
300    
301        osd_priv_t *priv = (osd_priv_t*)osd->priv;
302        g_return_if_fail (priv);
303    
304        printf("request to clear balloon\n");
305    
306        if(priv->balloon.surface) {
307            cairo_surface_destroy(priv->balloon.surface);
308            priv->balloon.surface = NULL;
309            priv->balloon.lat = OSM_GPS_MAP_INVALID;
310            priv->balloon.lon = OSM_GPS_MAP_INVALID;
311        }
312        osm_gps_map_redraw(map);
313    }
314    
315    void
316    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
317                                  OsmGpsMapBalloonCallback cb, gpointer data) {
318        g_return_if_fail (OSM_IS_GPS_MAP (map));
319    
320        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
321        g_return_if_fail (osd);
322    
323        osd_priv_t *priv = (osd_priv_t*)osd->priv;
324        g_return_if_fail (priv);
325    
326        osm_gps_map_osd_clear_balloon (map);
327    
328        printf("request to draw balloon at %f %f\n", latitude, longitude);
329    
330        /* allocate balloon surface */
331        priv->balloon.surface =
332            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
333                                       BALLOON_W+2, BALLOON_H+2);
334    
335        priv->balloon.lat = latitude;
336        priv->balloon.lon = longitude;
337        priv->balloon.cb = cb;
338        priv->balloon.data = data;
339    
340        priv->balloon.orientation = -1;
341    
342        osd_render_balloon(osd);
343    
344        osm_gps_map_redraw(map);
345    }
346    
347    #endif // OSD_BALLOON
348    
349  /* position and extent of bounding box */  /* position and extent of bounding box */
350  #ifndef OSD_X  #ifndef OSD_X
351  #define OSD_X      (10)  #define OSD_X      (10)
# Line 100  typedef struct { Line 406  typedef struct {
406    
407  /* create the cairo shape used for the zoom buttons */  /* create the cairo shape used for the zoom buttons */
408  static void  static void
409  osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y)  osd_zoom_shape(cairo_t *cr, gint x, gint y)
410  {  {
411      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
412      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
# Line 109  osm_gps_map_osd_zoom_shape(cairo_t *cr, Line 415  osm_gps_map_osd_zoom_shape(cairo_t *cr,
415      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);
416  }  }
417    
418    /* ------------------- color/shadow functions ----------------- */
419    
420    #ifndef OSD_COLOR
421    /* if no color has been specified we just use the gdks default colors */
422    static void
423    osd_labels(cairo_t *cr, gint width, gboolean enabled,
424                           GdkColor *fg, GdkColor *disabled) {
425        if(enabled)  gdk_cairo_set_source_color(cr, fg);
426        else         gdk_cairo_set_source_color(cr, disabled);
427        cairo_set_line_width (cr, width);
428    }
429    #else
430    static void
431    osd_labels(cairo_t *cr, gint width, gboolean enabled) {
432        if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
433        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
434        cairo_set_line_width (cr, width);
435    }
436    #endif
437    
438    #ifdef OSD_SHADOW_ENABLE
439    static void
440    osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
441        cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
442        cairo_set_line_width (cr, width);
443    }
444    #endif
445    
446  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
447  /* create the cairo shape used for the dpad */  /* create the cairo shape used for the dpad */
448  static void  static void
449  osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y)  osd_dpad_shape(cairo_t *cr, gint x, gint y)
450  {  {
451      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);
452  }  }
453  #endif  #endif
454    
455    #ifdef OSD_SHADOW_ENABLE
456    static void
457    osd_shape_shadow(cairo_t *cr) {
458        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
459        cairo_fill (cr);
460        cairo_stroke (cr);
461    }
462    #endif
463    
464    #ifndef OSD_COLOR
465    /* if no color has been specified we just use the gdks default colors */
466    static void
467    osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {
468        gdk_cairo_set_source_color(cr, bg);
469        cairo_fill_preserve (cr);
470        gdk_cairo_set_source_color(cr, fg);
471        cairo_set_line_width (cr, 1);
472        cairo_stroke (cr);
473    }
474    #else
475    static void
476    osd_shape(cairo_t *cr) {
477        cairo_set_source_rgb (cr, OSD_COLOR_BG);
478        cairo_fill_preserve (cr);
479        cairo_set_source_rgb (cr, OSD_COLOR);
480        cairo_set_line_width (cr, 1);
481        cairo_stroke (cr);
482    }
483    #endif
484    
485    
486  static gboolean  static gboolean
487  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)
488  {  {
# Line 127  osm_gps_map_in_circle(gint x, gint y, gi Line 492  osm_gps_map_in_circle(gint x, gint y, gi
492  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
493  /* check whether x/y is within the dpad */  /* check whether x/y is within the dpad */
494  static osd_button_t  static osd_button_t
495  osm_gps_map_osd_check_dpad(gint x, gint y)  osd_check_dpad(gint x, gint y)
496  {  {
497      /* within entire dpad circle */      /* within entire dpad circle */
498      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))
# Line 162  osm_gps_map_osd_check_dpad(gint x, gint Line 527  osm_gps_map_osd_check_dpad(gint x, gint
527    
528  /* check whether x/y is within the zoom pads */  /* check whether x/y is within the zoom pads */
529  static osd_button_t  static osd_button_t
530  osm_gps_map_osd_check_zoom(gint x, gint y) {  osd_check_zoom(gint x, gint y) {
531      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {
532    
533          /* within circle around (-) label */          /* within circle around (-) label */
# Line 191  osm_gps_map_osd_check_zoom(gint x, gint Line 556  osm_gps_map_osd_check_zoom(gint x, gint
556      return OSD_NONE;      return OSD_NONE;
557  }  }
558    
559    #ifdef OSD_SOURCE_SEL
560    
561    /* place source selection at right border */
562    #define OSD_S_RAD (Z_RAD)
563    #define OSD_S_X   (-OSD_X)
564    #define OSD_S_Y   (OSD_Y)
565    #define OSD_S_PW  (2 * Z_RAD)
566    #define OSD_S_W   (OSD_S_PW)
567    #define OSD_S_PH  (2 * Z_RAD)
568    #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
569    
570    /* size of usable area when expanded */
571    #define OSD_S_AREA_W (priv->source_sel.width)
572    #define OSD_S_AREA_H (priv->source_sel.height)
573    #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
574    #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
575    
576    /* internal value to draw the arrow on the "puller" */
577    #define OSD_S_D0  (OSD_S_RAD/2)
578    #ifndef OSD_FONT_SIZE
579    #define OSD_FONT_SIZE 16.0
580    #endif
581    #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)
582    #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)
583    
584    /* draw the shape of the source selection OSD, either only the puller (not expanded) */
585    /* or the entire menu incl. the puller (expanded) */
586    static void
587    osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
588        if(!priv->source_sel.expanded) {
589            /* just draw the puller */
590            cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
591            cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
592            cairo_line_to (cr, x + OSD_S_PW, y);
593        } else {
594            /* draw the puller and the area itself */
595            cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H);
596            cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H);
597            if(OSD_S_Y > 0) {
598                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH);
599                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
600            } else {
601                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
602                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH);
603                cairo_line_to (cr, x + OSD_S_PW, y);
604            }
605            cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y);
606            cairo_close_path (cr);
607        }
608    }
609    
610    static void
611    osd_source_content(osm_gps_map_osd_t *osd, cairo_t *cr, gint offset) {
612        osd_priv_t *priv = (osd_priv_t*)osd->priv;
613    
614        int py = offset + OSD_S_RAD - OSD_S_D0;
615    
616        if(!priv->source_sel.expanded) {
617            /* draw the "puller" open (<) arrow */
618            cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);
619            cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
620            cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
621        } else {
622            if(OSD_S_Y < 0)
623                py += OSD_S_AREA_H - OSD_S_PH;
624    
625            /* draw the "puller" close (>) arrow */
626            cairo_move_to (cr, offset + OSD_S_RAD - OSD_S_D0/2, py);
627            cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
628            cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
629            cairo_stroke(cr);
630    
631            /* don't draw a shadow for the text content */
632            if(offset == 1) {
633                gint source;
634                g_object_get(osd->widget, "map-source", &source, NULL);
635    
636                cairo_select_font_face (cr, "Sans",
637                                        CAIRO_FONT_SLANT_NORMAL,
638                                        CAIRO_FONT_WEIGHT_BOLD);
639                cairo_set_font_size (cr, OSD_FONT_SIZE);
640    
641                int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
642                    OSM_GPS_MAP_SOURCE_LAST;
643                for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
644                    cairo_text_extents_t extents;
645                    const char *src = osm_gps_map_source_get_friendly_name(i);
646                    cairo_text_extents (cr, src, &extents);
647    
648                    int x = offset + OSD_S_PW + OSD_TEXT_BORDER;
649                    int y = offset + step * (i-1) + OSD_TEXT_BORDER;
650    
651                    /* draw filled rectangle if selected */
652                    if(source == i) {
653                        cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
654                                        y - OSD_TEXT_SKIP,
655                                        priv->source_sel.width - OSD_TEXT_BORDER,
656                                        step + OSD_TEXT_SKIP);
657                        cairo_fill(cr);
658    
659                        /* temprarily draw with background color */
660    #ifndef OSD_COLOR
661                        GdkColor bg = osd->widget->style->bg[GTK_STATE_NORMAL];
662                        gdk_cairo_set_source_color(cr, &bg);
663    #else
664                        cairo_set_source_rgb (cr, OSD_COLOR_BG);
665    #endif
666                    }
667    
668                    cairo_move_to (cr, x, y + OSD_TEXT_SKIP - extents.y_bearing);
669                    cairo_show_text (cr, src);
670    
671                    /* restore color */
672                    if(source == i) {
673    #ifndef OSD_COLOR
674                        GdkColor fg = osd->widget->style->fg[GTK_STATE_NORMAL];
675                        gdk_cairo_set_source_color(cr, &fg);
676    #else
677                        cairo_set_source_rgb (cr, OSD_COLOR);
678    #endif
679                    }
680                }
681            }
682        }
683    }
684    
685    static void
686    osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
687        osd_priv_t *priv = (osd_priv_t*)osd->priv;
688    
689        if(priv->source_sel.rendered && !force_rerender)
690            return;
691    
692        priv->source_sel.rendered = TRUE;
693    
694    #ifndef OSD_COLOR
695        GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
696        GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
697        GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
698    #endif
699    
700        /* draw source selector */
701        cairo_t *cr = cairo_create(priv->source_sel.surface);
702        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
703        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
704        cairo_paint(cr);
705        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
706    
707    #ifdef OSD_SHADOW_ENABLE
708        osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
709        osd_shape_shadow(cr);
710    #endif
711    
712        osd_source_shape(priv, cr, 1, 1);
713    #ifndef OSD_COLOR
714        osd_shape(cr, &bg, &fg);
715    #else
716        osd_shape(cr);
717    #endif
718    
719    #ifdef OSD_SHADOW_ENABLE
720        osd_labels_shadow(cr, Z_RAD/3, TRUE);
721        osd_source_content(osd, cr, 1+OSD_LBL_SHADOW);
722        cairo_stroke (cr);
723    #endif
724    #ifndef OSD_COLOR
725        osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
726    #else
727        osd_labels(cr, Z_RAD/3, TRUE);
728    #endif
729        osd_source_content(osd, cr, 1);
730        cairo_stroke (cr);
731    
732        cairo_destroy(cr);
733    }
734    
735    /* re-allocate the buffer used to draw the menu. This is used */
736    /* to collapse/expand the buffer */
737    static void
738    osd_source_reallocate(osm_gps_map_osd_t *osd) {
739        osd_priv_t *priv = (osd_priv_t*)osd->priv;
740    
741        /* re-allocate offscreen bitmap */
742        g_assert (priv->source_sel.surface);
743    
744        int w = OSD_S_W, h = OSD_S_H;
745        if(priv->source_sel.expanded) {
746            cairo_text_extents_t extents;
747    
748            /* determine content size */
749            cairo_t *cr = cairo_create(priv->source_sel.surface);
750            cairo_select_font_face (cr, "Sans",
751                                    CAIRO_FONT_SLANT_NORMAL,
752                                    CAIRO_FONT_WEIGHT_BOLD);
753            cairo_set_font_size (cr, OSD_FONT_SIZE);
754    
755            /* calculate menu size */
756            int i, max_h = 0, max_w = 0;
757            for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
758                const char *src = osm_gps_map_source_get_friendly_name(i);
759                cairo_text_extents (cr, src, &extents);
760    
761                if(extents.width > max_w) max_w = extents.width;
762                if(extents.height > max_h) max_h = extents.height;
763            }
764            cairo_destroy(cr);
765    
766            priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
767            priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
768                (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
769    
770            w = OSD_S_EXP_W;
771            h = OSD_S_EXP_H;
772        }
773    
774        cairo_surface_destroy(priv->source_sel.surface);
775        priv->source_sel.surface =
776            cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
777    
778        osd_render_source_sel(osd, TRUE);
779    }
780    
781    #define OSD_HZ      15
782    #define OSD_TIME    500
783    
784    static gboolean osd_source_animate(gpointer data) {
785        osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;
786        osd_priv_t *priv = (osd_priv_t*)osd->priv;
787        int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
788        gboolean done = FALSE;
789        priv->source_sel.count += priv->source_sel.dir;
790    
791        /* shifting in */
792        if(priv->source_sel.dir < 0) {
793            if(priv->source_sel.count <= 0) {
794                priv->source_sel.count = 0;
795                done = TRUE;
796            }
797        } else {
798            if(priv->source_sel.count >= 1000) {
799                priv->source_sel.expanded = FALSE;
800                osd_source_reallocate(osd);
801    
802                priv->source_sel.count = 1000;
803                done = TRUE;
804            }
805        }
806    
807    
808        /* count runs linearly from 0 to 1000, map this nicely onto a position */
809    
810        /* nice sinoid mapping */
811        float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
812        priv->source_sel.shift =
813            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
814            m * diff;
815    
816        /* make sure the screen is updated */
817        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
818    
819        /* stop animation if done */
820        if(done)
821            priv->source_sel.handler_id = 0;
822    
823        return !done;
824    }
825    
826    /* switch between expand and collapse mode of source selection */
827    static void
828    osd_source_toggle(osm_gps_map_osd_t *osd)
829    {
830        osd_priv_t *priv = (osd_priv_t*)osd->priv;
831    
832        /* ignore clicks while animation is running */
833        if(priv->source_sel.handler_id)
834            return;
835    
836        /* expand immediately, collapse is handle at the end of the */
837        /* collapse animation */
838        if(!priv->source_sel.expanded) {
839            priv->source_sel.expanded = TRUE;
840            osd_source_reallocate(osd);
841    
842            priv->source_sel.count = 1000;
843            priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
844            priv->source_sel.dir = -1000/OSD_HZ;
845        } else {
846            priv->source_sel.count =  0;
847            priv->source_sel.shift = osd->widget->allocation.width -
848                OSD_S_EXP_W + OSD_S_X;
849            priv->source_sel.dir = +1000/OSD_HZ;
850        }
851    
852        /* start timer to handle animation */
853        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
854                                                      osd_source_animate, osd);
855    }
856    
857    /* check if the user clicked inside the source selection area */
858    static osd_button_t
859    osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {
860        osd_priv_t *priv = (osd_priv_t*)osd->priv;
861    
862        if(!priv->source_sel.expanded)
863            x -= osd->widget->allocation.width - OSD_S_W;
864        else
865            x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
866    
867        if(OSD_S_Y > 0)
868            y -= OSD_S_Y;
869        else
870            y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y;
871    
872        /* within square around puller? */
873        if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) {
874            /* really within puller shape? */
875            if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
876                /* expand source selector */
877                osd_source_toggle(osd);
878    
879                /* tell upper layers that user clicked some background element */
880                /* of the OSD */
881                return OSD_BG;
882            }
883        }
884    
885        /* check for clicks into data area */
886        if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
887            /* re-adjust from puller top to content top */
888            if(OSD_S_Y < 0)
889                y += OSD_S_EXP_H - OSD_S_PH;
890    
891            if(x > OSD_S_PW &&
892               x < OSD_S_PW + OSD_S_EXP_W &&
893               y > 0 &&
894               y < OSD_S_EXP_H) {
895    
896                int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
897                    / OSM_GPS_MAP_SOURCE_LAST;
898    
899                y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
900                y /= step;
901                y += 1;
902    
903                gint old = 0;
904                g_object_get(osd->widget, "map-source", &old, NULL);
905    
906                if(y > OSM_GPS_MAP_SOURCE_NULL &&
907                   y <= OSM_GPS_MAP_SOURCE_LAST &&
908                   old != y) {
909                    g_object_set(osd->widget, "map-source", y, NULL);
910    
911                    osd_render_source_sel(osd, TRUE);
912                    osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
913                }
914    
915                /* return "clicked in OSD background" to prevent further */
916                /* processing by application */
917                return OSD_BG;
918            }
919        }
920    
921        return OSD_NONE;
922    }
923    #endif // OSD_SOURCE_SEL
924    
925  static osd_button_t  static osd_button_t
926  osm_gps_map_osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {
927      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
928    
929    #ifdef OSD_BALLOON
930        /* check if user clicked into balloon */
931        if(osd_balloon_check(osd, x, y))
932            return OSD_BG;
933    #endif
934    
935    #ifdef OSD_SOURCE_SEL
936        /* the source selection area is handles internally */
937        but = osd_source_check(osd, x, y);
938        if(but != OSD_NONE)
939            return but;
940    #endif
941    
942      x -= OSD_X;      x -= OSD_X;
943      y -= OSD_Y;      y -= OSD_Y;
944    
# Line 208  osm_gps_map_osd_check(osm_gps_map_osd_t Line 952  osm_gps_map_osd_check(osm_gps_map_osd_t
952      /* this is just to avoid an unnecessary detailed test */      /* this is just to avoid an unnecessary detailed test */
953      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {
954  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
955          but = osm_gps_map_osd_check_dpad(x, y);          but = osd_check_dpad(x, y);
956  #endif  #endif
957    
958          if(but == OSD_NONE)          if(but == OSD_NONE)
959              but = osm_gps_map_osd_check_zoom(x, y);              but = osd_check_zoom(x, y);
960      }      }
961    
962      return but;      return but;
963  }  }
964    
 #ifdef OSD_SHADOW_ENABLE  
 static void  
 osm_gps_map_osd_shape_shadow(cairo_t *cr) {  
     cairo_set_source_rgba (cr, 0, 0, 0, 0.2);  
     cairo_fill (cr);  
     cairo_stroke (cr);  
 }  
 #endif  
   
 #ifndef OSD_COLOR  
 /* if no color has been specified we just use the gdks default colors */  
 static void  
 osm_gps_map_osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {  
     gdk_cairo_set_source_color(cr, bg);  
     cairo_fill_preserve (cr);  
     gdk_cairo_set_source_color(cr, fg);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
 }  
 #else  
 static void  
 osm_gps_map_osd_shape(cairo_t *cr) {  
     cairo_set_source_rgb (cr, OSD_COLOR_BG);  
     cairo_fill_preserve (cr);  
     cairo_set_source_rgb (cr, OSD_COLOR);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
 }  
 #endif  
   
965  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
966  static void  static void
967  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {  osd_dpad_labels(cairo_t *cr, gint x, gint y) {
968      /* move reference to dpad center */      /* move reference to dpad center */
969      x += D_RAD;      x += D_RAD;
970      y += D_RAD;      y += D_RAD;
# Line 285  osm_gps_map_osd_dpad_labels(cairo_t *cr, Line 999  osm_gps_map_osd_dpad_labels(cairo_t *cr,
999  /* this is either drawn in the center of the dpad (if present) */  /* this is either drawn in the center of the dpad (if present) */
1000  /* or in the middle of the zoom area */  /* or in the middle of the zoom area */
1001  static void  static void
1002  osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {  osd_dpad_gps(cairo_t *cr, gint x, gint y) {
1003      /* move reference to dpad center */      /* move reference to dpad center */
1004      x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;      x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;
1005      y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;      y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;
# Line 308  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi Line 1022  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi
1022  #define Z_LEN  (2*Z_RAD/3)  #define Z_LEN  (2*Z_RAD/3)
1023    
1024  static void  static void
1025  osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {  osd_zoom_labels(cairo_t *cr, gint x, gint y) {
1026      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
1027      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
1028    
# Line 318  osm_gps_map_osd_zoom_labels(cairo_t *cr, Line 1032  osm_gps_map_osd_zoom_labels(cairo_t *cr,
1032      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
1033  }  }
1034    
1035  #ifndef OSD_COLOR  #ifdef OSD_COORDINATES
1036  /* if no color has been specified we just use the gdks default colors */  
1037  static void  #ifndef OSD_COORDINATES_FONT_SIZE
1038  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled,  #define OSD_COORDINATES_FONT_SIZE 12
1039                         GdkColor *fg, GdkColor *disabled) {  #endif
1040      if(enabled)  gdk_cairo_set_source_color(cr, fg);  
1041      else         gdk_cairo_set_source_color(cr, disabled);  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1042      cairo_set_line_width (cr, width);  
1043      cairo_stroke (cr);  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1044    #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)
1045    
1046    /* these can be overwritten with versions that support */
1047    /* localization */
1048    #ifndef OSD_COORDINATES_CHR_N
1049    #define OSD_COORDINATES_CHR_N  "N"
1050    #endif
1051    #ifndef OSD_COORDINATES_CHR_S
1052    #define OSD_COORDINATES_CHR_S  "S"
1053    #endif
1054    #ifndef OSD_COORDINATES_CHR_E
1055    #define OSD_COORDINATES_CHR_E  "E"
1056    #endif
1057    #ifndef OSD_COORDINATES_CHR_W
1058    #define OSD_COORDINATES_CHR_W  "W"
1059    #endif
1060    
1061    
1062    
1063    /* this is the classic geocaching notation */
1064    static char
1065    *osd_latitude_str(float latitude) {
1066        char *c = OSD_COORDINATES_CHR_N;
1067        float integral, fractional;
1068    
1069        if(isnan(latitude))
1070            return NULL;
1071    
1072        if(latitude < 0) {
1073            latitude = fabs(latitude);
1074            c = OSD_COORDINATES_CHR_S;
1075        }
1076    
1077        fractional = modff(latitude, &integral);
1078    
1079        return g_strdup_printf("%s %02d° %06.3f'",
1080                               c, (int)integral, fractional*60.0);
1081  }  }
1082  #else  
1083    static char
1084    *osd_longitude_str(float longitude) {
1085        char *c = OSD_COORDINATES_CHR_E;
1086        float integral, fractional;
1087    
1088        if(isnan(longitude))
1089            return NULL;
1090    
1091        if(longitude < 0) {
1092            longitude = fabs(longitude);
1093            c = OSD_COORDINATES_CHR_W;
1094        }
1095    
1096        fractional = modff(longitude, &integral);
1097    
1098        return g_strdup_printf("%s %03d° %06.3f'",
1099                               c, (int)integral, fractional*60.0);
1100    }
1101    
1102  static void  static void
1103  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {  osd_render_coordinates(osm_gps_map_osd_t *osd)
1104      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);  {
1105      else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1106      cairo_set_line_width (cr, width);  
1107        /* get current map position */
1108        gfloat lat, lon;
1109        g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1110    
1111        /* check if position has changed enough to require redraw */
1112        if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1113            /* 1/60000 == 1/1000 minute */
1114            if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1115               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1116                return;
1117    
1118        priv->coordinates.lat = lat;
1119        priv->coordinates.lon = lon;
1120    
1121        /* first fill with transparency */
1122        cairo_t *cr = cairo_create(priv->coordinates.surface);
1123        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1124        //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
1125        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1126        cairo_paint(cr);
1127        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1128    
1129        cairo_select_font_face (cr, "Sans",
1130                                CAIRO_FONT_SLANT_NORMAL,
1131                                CAIRO_FONT_WEIGHT_BOLD);
1132        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1133    
1134        char *latitude = osd_latitude_str(lat);
1135        char *longitude = osd_longitude_str(lon);
1136    
1137        cairo_text_extents_t lat_extents, lon_extents;
1138        cairo_text_extents (cr, latitude, &lat_extents);
1139        cairo_text_extents (cr, longitude, &lon_extents);
1140    
1141        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1142        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1143        cairo_move_to (cr,
1144                       (OSD_COORDINATES_W - lat_extents.width)/2,
1145                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1146        cairo_text_path (cr, latitude);
1147        cairo_move_to (cr,
1148                       (OSD_COORDINATES_W - lon_extents.width)/2,
1149                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1150                       OSD_COORDINATES_FONT_SIZE);
1151        cairo_text_path (cr, longitude);
1152      cairo_stroke (cr);      cairo_stroke (cr);
1153    
1154        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1155        cairo_move_to (cr,
1156                       (OSD_COORDINATES_W - lat_extents.width)/2,
1157                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1158        cairo_show_text (cr, latitude);
1159        cairo_move_to (cr,
1160                       (OSD_COORDINATES_W - lon_extents.width)/2,
1161                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1162                       OSD_COORDINATES_FONT_SIZE);
1163        cairo_show_text (cr, longitude);
1164    
1165        g_free(latitude);
1166        g_free(longitude);
1167    
1168        cairo_destroy(cr);
1169  }  }
1170    #endif  // OSD_COORDINATES
1171    
1172    #ifdef OSD_CROSSHAIR
1173    
1174    #ifndef OSD_CROSSHAIR_RADIUS
1175    #define OSD_CROSSHAIR_RADIUS 10
1176  #endif  #endif
1177    
1178  #ifdef OSD_SHADOW_ENABLE  #define OSD_CROSSHAIR_TICK  (OSD_CROSSHAIR_RADIUS/2)
1179  static void  #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4)
1180  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {  #define OSD_CROSSHAIR_W  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
1181      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);  #define OSD_CROSSHAIR_H  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
1182      cairo_set_line_width (cr, width);  
1183    static void
1184    osd_render_crosshair_shape(cairo_t *cr) {
1185        cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
1186                   OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
1187    
1188        cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS,
1189                       OSD_CROSSHAIR_H/2);
1190        cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0);
1191        cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS,
1192                       OSD_CROSSHAIR_H/2);
1193        cairo_rel_line_to (cr,  OSD_CROSSHAIR_TICK, 0);
1194    
1195        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1196                       OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS);
1197        cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK);
1198        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
1199                       OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS);
1200        cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
1201    
1202      cairo_stroke (cr);      cairo_stroke (cr);
1203  }  }
1204    
1205    static void
1206    osd_render_crosshair(osm_gps_map_osd_t *osd)
1207    {
1208        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1209    
1210        if(priv->crosshair.rendered)
1211            return;
1212    
1213        priv->crosshair.rendered = TRUE;
1214    
1215        /* first fill with transparency */
1216        cairo_t *cr = cairo_create(priv->crosshair.surface);
1217        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1218        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1219        cairo_paint(cr);
1220        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1221    
1222        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1223    
1224        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
1225        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2);
1226        osd_render_crosshair_shape(cr);
1227    
1228        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
1229        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4);
1230        osd_render_crosshair_shape(cr);
1231    
1232        cairo_destroy(cr);
1233    }
1234  #endif  #endif
1235    
1236    #ifdef OSD_SCALE
1237    
1238    #ifndef OSD_SCALE_FONT_SIZE
1239    #define OSD_SCALE_FONT_SIZE 12
1240    #endif
1241    #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)
1242    #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)
1243    
1244    /* various parameters used to create the scale */
1245    #define OSD_SCALE_H2   (OSD_SCALE_H/2)
1246    #define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3)
1247    #define OSD_SCALE_M    (OSD_SCALE_H2 - OSD_SCALE_TICK)
1248    #define OSD_SCALE_I    (OSD_SCALE_H2 + OSD_SCALE_TICK)
1249    #define OSD_SCALE_FD   (OSD_SCALE_FONT_SIZE/4)
1250    
1251  static void  static void
1252  osm_gps_map_osd_render(osm_gps_map_osd_t *osd) {  osd_render_scale(osm_gps_map_osd_t *osd)
1253    {
1254      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1255    
1256        /* this only needs to be rendered if the zoom has changed */
1257        gint zoom;
1258        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1259        if(zoom == priv->scale.zoom)
1260            return;
1261    
1262        priv->scale.zoom = zoom;
1263    
1264        float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
1265    
1266      /* first fill with transparency */      /* first fill with transparency */
1267      cairo_t *cr = cairo_create(priv->overlay);      cairo_t *cr = cairo_create(priv->scale.surface);
1268      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1269      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1270        // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1271      cairo_paint(cr);      cairo_paint(cr);
1272        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1273    
1274        /* determine the size of the scale width in meters */
1275        float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix;
1276    
1277        /* scale this to useful values */
1278        int exp = logf(width)*M_LOG10E;
1279        int mant = width/pow(10,exp);
1280        int width_metric = mant * pow(10,exp);
1281        char *dist_str = NULL;
1282        if(width_metric<1000)
1283            dist_str = g_strdup_printf("%u m", width_metric);
1284        else
1285            dist_str = g_strdup_printf("%u km", width_metric/1000);
1286        width_metric /= m_per_pix;
1287    
1288        /* and now the hard part: scale for useful imperial values :-( */
1289        /* try to convert to feet, 1ft == 0.3048 m */
1290        width /= 0.3048;
1291        float imp_scale = 0.3048;
1292        char *dist_imp_unit = "ft";
1293    
1294        if(width >= 100) {
1295            /* 1yd == 3 feet */
1296            width /= 3.0;
1297            imp_scale *= 3.0;
1298            dist_imp_unit = "yd";
1299    
1300            if(width >= 1760.0) {
1301                /* 1mi == 1760 yd */
1302                width /= 1760.0;
1303                imp_scale *= 1760.0;
1304                dist_imp_unit = "mi";
1305            }
1306        }
1307    
1308        /* also convert this to full tens/hundreds */
1309        exp = logf(width)*M_LOG10E;
1310        mant = width/pow(10,exp);
1311        int width_imp = mant * pow(10,exp);
1312        char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit);
1313    
1314        /* convert back to pixels */
1315        width_imp *= imp_scale;
1316        width_imp /= m_per_pix;
1317    
1318        cairo_select_font_face (cr, "Sans",
1319                                CAIRO_FONT_SLANT_NORMAL,
1320                                CAIRO_FONT_WEIGHT_BOLD);
1321        cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE);
1322        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
1323    
1324        cairo_text_extents_t extents;
1325        cairo_text_extents (cr, dist_str, &extents);
1326    
1327        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1328        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1329        cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1330        cairo_text_path (cr, dist_str);
1331        cairo_stroke (cr);
1332        cairo_move_to (cr, 2*OSD_SCALE_FD,
1333                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1334        cairo_text_path (cr, dist_str_imp);
1335        cairo_stroke (cr);
1336    
1337        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1338        cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD);
1339        cairo_show_text (cr, dist_str);
1340        cairo_move_to (cr, 2*OSD_SCALE_FD,
1341                       OSD_SCALE_H2+OSD_SCALE_FD + extents.height);
1342        cairo_show_text (cr, dist_str_imp);
1343    
1344        g_free(dist_str);
1345        g_free(dist_str_imp);
1346    
1347        /* draw white line */
1348        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
1349        cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
1350        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3);
1351        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1352        cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1353        cairo_rel_line_to (cr, width_metric, 0);
1354        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1355        cairo_stroke(cr);
1356        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1357        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1358        cairo_rel_line_to (cr, width_imp, 0);
1359        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1360        cairo_stroke(cr);
1361    
1362        /* draw black line */
1363        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
1364        cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6);
1365        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M);
1366        cairo_rel_line_to (cr, 0,  OSD_SCALE_TICK);
1367        cairo_rel_line_to (cr, width_metric, 0);
1368        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1369        cairo_stroke(cr);
1370        cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I);
1371        cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK);
1372        cairo_rel_line_to (cr, width_imp, 0);
1373        cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK);
1374        cairo_stroke(cr);
1375    
1376        cairo_destroy(cr);
1377    }
1378    #endif
1379    
1380    static void
1381    osd_render_controls(osm_gps_map_osd_t *osd)
1382    {
1383        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1384    
1385        if(priv->controls.rendered
1386    #ifdef OSD_GPS_BUTTON
1387           && (priv->controls.gps_enabled == (osd->cb != NULL))
1388    #endif
1389           )
1390            return;
1391    
1392    #ifdef OSD_GPS_BUTTON
1393        priv->controls.gps_enabled = (osd->cb != NULL);
1394    #endif
1395        priv->controls.rendered = TRUE;
1396    
1397  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1398      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
# Line 363  osm_gps_map_osd_render(osm_gps_map_osd_t Line 1400  osm_gps_map_osd_render(osm_gps_map_osd_t
1400      GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];      GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
1401  #endif  #endif
1402    
1403        /* first fill with transparency */
1404        cairo_t *cr = cairo_create(priv->controls.surface);
1405        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1406        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1407        cairo_paint(cr);
1408      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1409    
1410      /* --------- draw zoom and dpad shape shadow ----------- */      /* --------- draw zoom and dpad shape shadow ----------- */
     gint x = 0, y = 0;  
   
1411  #ifdef OSD_SHADOW_ENABLE  #ifdef OSD_SHADOW_ENABLE
1412      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
1413      osm_gps_map_osd_shape_shadow(cr);      osd_shape_shadow(cr);
1414  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
1415      osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
1416      osm_gps_map_osd_shape_shadow(cr);      osd_shape_shadow(cr);
1417  #endif  #endif
1418  #endif  #endif
1419    
1420      /* --------- draw zoom and dpad shape ----------- */      /* --------- draw zoom and dpad shape ----------- */
1421    
1422      osm_gps_map_osd_zoom_shape(cr, x, y);      osd_zoom_shape(cr, 1, 1);
1423  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1424      osm_gps_map_osd_shape(cr, &bg, &fg);      osd_shape(cr, &bg, &fg);
1425  #else  #else
1426      osm_gps_map_osd_shape(cr);      osd_shape(cr);
1427  #endif  #endif
1428  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
1429      osm_gps_map_osd_dpad_shape(cr, x, y);      osd_dpad_shape(cr, 1, 1);
1430  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1431      osm_gps_map_osd_shape(cr, &bg, &fg);      osd_shape(cr, &bg, &fg);
1432  #else  #else
1433      osm_gps_map_osd_shape(cr);      osd_shape(cr);
1434  #endif  #endif
1435  #endif  #endif
1436    
1437      /* --------- draw zoom and dpad labels --------- */      /* --------- draw zoom and dpad labels --------- */
1438    
1439  #ifdef OSD_SHADOW_ENABLE  #ifdef OSD_SHADOW_ENABLE
1440      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_labels_shadow(cr, Z_RAD/3, TRUE);
1441        osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1442  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
1443      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1444  #endif  #endif
1445      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);      cairo_stroke(cr);
1446  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1447      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);
1448      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);      osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
1449        cairo_stroke(cr);
1450  #endif  #endif
1451  #endif  #endif
1452    
     osm_gps_map_osd_zoom_labels(cr, x, y);  
 #ifndef OSD_NO_DPAD  
     osm_gps_map_osd_dpad_labels(cr, x, y);  
 #endif  
1453  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1454      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);      osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
1455  #else  #else
1456      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);      osd_labels(cr, Z_RAD/3, TRUE);
1457  #endif  #endif
1458  #ifdef OSD_GPS_BUTTON      osd_zoom_labels(cr, 1, 1);
1459      osm_gps_map_osd_dpad_gps(cr, x, y);  #ifndef OSD_NO_DPAD
1460        osd_dpad_labels(cr, 1, 1);
1461    #endif
1462        cairo_stroke(cr);
1463    
1464  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1465      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);      osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);
1466  #else  #else
1467      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL);      osd_labels(cr, Z_RAD/6, osd->cb != NULL);
1468  #endif  #endif
1469    #ifdef OSD_GPS_BUTTON
1470        osd_dpad_gps(cr, 1, 1);
1471  #endif  #endif
1472        cairo_stroke(cr);
1473    
1474      cairo_destroy(cr);      cairo_destroy(cr);
1475  }  }
1476    
1477  static void  static void
1478  osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)  osd_render(osm_gps_map_osd_t *osd)
1479    {
1480        /* this function is actually called pretty often since the */
1481        /* OSD contents may have changed (due to a coordinate/zoom change). */
1482        /* The different OSD parts have to make sure that they don't */
1483        /* render unneccessarily often and thus waste CPU power */
1484    
1485        osd_render_controls(osd);
1486    
1487    #ifdef OSD_SOURCE_SEL
1488        osd_render_source_sel(osd, FALSE);
1489    #endif
1490    
1491    #ifdef OSD_SCALE
1492        osd_render_scale(osd);
1493    #endif
1494    
1495    #ifdef OSD_CROSSHAIR
1496        osd_render_crosshair(osd);
1497    #endif
1498    
1499    #ifdef OSD_COORDINATES
1500        osd_render_coordinates(osd);
1501    #endif
1502    }
1503    
1504    static void
1505    osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)
1506  {  {
1507      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1508    
1509      /* OSD itself uses some off-screen rendering, so check if the */      /* OSD itself uses some off-screen rendering, so check if the */
1510      /* offscreen buffer is present and create it if not */      /* offscreen buffer is present and create it if not */
1511      if(!priv->overlay) {      if(!priv->controls.surface) {
1512          /* create overlay ... */          /* create overlay ... */
1513          priv->overlay =          priv->controls.surface =
1514              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
1515    
1516            priv->controls.rendered = FALSE;
1517    #ifdef OSD_GPS_BUTTON
1518            priv->controls.gps_enabled = FALSE;
1519    #endif
1520    
1521    #ifdef OSD_SOURCE_SEL
1522            /* the initial OSD state is alway not-expanded */
1523            priv->source_sel.surface =
1524                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1525                                               OSD_S_W+2, OSD_S_H+2);
1526            priv->source_sel.rendered = FALSE;
1527    #endif
1528    
1529    #ifdef OSD_SCALE
1530            priv->scale.surface =
1531                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1532                                           OSD_SCALE_W, OSD_SCALE_H);
1533            priv->scale.zoom = -1;
1534    #endif
1535    
1536    #ifdef OSD_CROSSHAIR
1537            priv->crosshair.surface =
1538                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1539                                           OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1540            priv->crosshair.rendered = FALSE;
1541    #endif
1542    
1543    #ifdef OSD_COORDINATES
1544            priv->coordinates.surface =
1545                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1546                                           OSD_COORDINATES_W, OSD_COORDINATES_H);
1547    
1548            priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1549    #endif
1550    
1551          /* ... and render it */          /* ... and render it */
1552          osm_gps_map_osd_render(osd);          osd_render(osd);
1553      }      }
1554    
1555      // now draw this onto the original context      // now draw this onto the original context
1556      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1557    
1558      int x = OSD_X, y = OSD_Y;      gint x, y;
     if(OSD_X < 0)  
         x = osd->widget->allocation.width - OSD_W + OSD_X;  
1559    
1560      if(OSD_Y < 0)  #ifdef OSD_SCALE
1561          y = osd->widget->allocation.height - OSD_H + OSD_Y;      x =  OSD_X;
1562        y = -OSD_Y;
1563        if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1564        if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1565    
1566        cairo_set_source_surface(cr, priv->scale.surface, x, y);
1567        cairo_paint(cr);
1568    #endif
1569    
1570    #ifdef OSD_CROSSHAIR
1571        x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1572        y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1573    
1574        cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1575        cairo_paint(cr);
1576    #endif
1577    
1578    #ifdef OSD_COORDINATES
1579        x = -OSD_X;
1580        y = -OSD_Y;
1581        if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1582        if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1583    
1584        cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1585        cairo_paint(cr);
1586    #endif
1587    
1588    #ifdef OSD_BALLOON
1589        if(priv->balloon.surface) {
1590    
1591            /* convert given lat lon into screen coordinates */
1592            gint x, y;
1593            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1594                                          priv->balloon.lat, priv->balloon.lon,
1595                                          &x, &y);
1596    
1597            /* check if balloon needs to be rerendered */
1598            osd_render_balloon(osd);
1599    
1600            cairo_set_source_surface(cr, priv->balloon.surface,
1601                                     x + priv->balloon.offset_x,
1602                                     y + priv->balloon.offset_y);
1603            cairo_paint(cr);
1604        }
1605    #endif
1606    
1607        x = OSD_X;
1608        if(x < 0)
1609            x += osd->widget->allocation.width - OSD_W;
1610    
1611        y = OSD_Y;
1612        if(y < 0)
1613            y += osd->widget->allocation.height - OSD_H;
1614    
1615        cairo_set_source_surface(cr, priv->controls.surface, x, y);
1616        cairo_paint(cr);
1617    
1618    #ifdef OSD_SOURCE_SEL
1619        if(!priv->source_sel.handler_id) {
1620            /* the OSD source selection is not being animated */
1621            if(!priv->source_sel.expanded)
1622                x = osd->widget->allocation.width - OSD_S_W;
1623            else
1624                x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1625        } else
1626            x = priv->source_sel.shift;
1627    
1628        y = OSD_S_Y;
1629        if(OSD_S_Y < 0) {
1630            if(!priv->source_sel.expanded)
1631                y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1632            else
1633                y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1634        }
1635    
1636      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
1637      cairo_paint(cr);      cairo_paint(cr);
1638    #endif
1639    
1640      cairo_destroy(cr);      cairo_destroy(cr);
1641  }  }
1642    
1643  static void  static void
1644  osm_gps_map_osd_free(osm_gps_map_osd_t *osd)  osd_free(osm_gps_map_osd_t *osd)
1645  {  {
1646      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1647    
1648      if (priv->overlay)      if (priv->controls.surface)
1649           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->controls.surface);
1650    
1651    #ifdef OSD_SOURCE_SEL
1652        if(priv->source_sel.handler_id)
1653            gtk_timeout_remove(priv->source_sel.handler_id);
1654    
1655        if (priv->source_sel.surface)
1656             cairo_surface_destroy(priv->source_sel.surface);
1657    #endif
1658    
1659    #ifdef OSD_SCALE
1660        if (priv->scale.surface)
1661             cairo_surface_destroy(priv->scale.surface);
1662    #endif
1663    
1664    #ifdef OSD_CROSSHAIR
1665        if (priv->crosshair.surface)
1666             cairo_surface_destroy(priv->crosshair.surface);
1667    #endif
1668    
1669    #ifdef OSD_COORDINATES
1670        if (priv->coordinates.surface)
1671             cairo_surface_destroy(priv->coordinates.surface);
1672    #endif
1673    
1674    #ifdef OSD_BALLOON
1675        if (priv->balloon.surface)
1676             cairo_surface_destroy(priv->balloon.surface);
1677    #endif
1678    
1679      g_free(priv);      g_free(priv);
1680  }  }
1681    
1682    static gboolean
1683    osd_busy(osm_gps_map_osd_t *osd)
1684    {
1685    #ifdef OSD_SOURCE_SEL
1686        osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1687        return (priv->source_sel.handler_id != 0);
1688    #else
1689        return FALSE;
1690    #endif
1691    }
1692    
1693  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
1694      .draw       = osm_gps_map_osd_draw,      .widget     = NULL,
1695      .check      = osm_gps_map_osd_check,  
1696      .render     = osm_gps_map_osd_render,      .draw       = osd_draw,
1697      .free       = osm_gps_map_osd_free,      .check      = osd_check,
1698        .render     = osd_render,
1699        .free       = osd_free,
1700        .busy       = osd_busy,
1701    
1702      .cb         = NULL,      .cb         = NULL,
1703      .data       = NULL,      .data       = NULL,
# Line 488  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1711  osm_gps_map_osd_classic_init(OsmGpsMap *
1711  {  {
1712      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);
1713    
1714    #ifdef OSD_BALLOON
1715        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1716        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1717    #endif
1718    
1719      osd_classic.priv = priv;      osd_classic.priv = priv;
1720    
1721      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
# Line 499  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1727  osm_gps_map_osd_classic_init(OsmGpsMap *
1727  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
1728                                   gpointer data) {                                   gpointer data) {
1729      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
   
1730      g_return_if_fail (osd);      g_return_if_fail (osd);
1731    
1732      osd->cb = cb;      osd->cb = cb;
# Line 512  void osm_gps_map_osd_enable_gps (OsmGpsM Line 1739  void osm_gps_map_osd_enable_gps (OsmGpsM
1739      osm_gps_map_redraw(map);      osm_gps_map_redraw(map);
1740  }  }
1741  #endif  #endif
1742    
1743    osd_button_t
1744    osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {
1745        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1746        g_return_val_if_fail (osd, OSD_NONE);
1747    
1748        return osd_check(osd, x, y);
1749    }

Legend:
Removed from v.77  
changed lines
  Added in v.113