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

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

revision 108 by harbaum, Fri Sep 11 19:20:55 2009 UTC revision 202 by harbaum, Sat Nov 21 20:13:13 2009 UTC
# Line 19  Line 19 
19    
20  #include "config.h"  #include "config.h"
21  #include <stdlib.h>  // abs  #include <stdlib.h>  // abs
22    #include <string.h>
23  #include <math.h>    // M_PI/cos()  #include <math.h>    // M_PI/cos()
24    
25  /* parameters that can be overwritten from the config file: */  /* parameters that can be overwritten from the config file: */
# Line 32  Line 33 
33  #include <cairo.h>  #include <cairo.h>
34    
35  #include "osm-gps-map.h"  #include "osm-gps-map.h"
36    #include "converter.h"
37  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
38    
39  //the osd controls  //the osd controls
# Line 45  typedef struct { Line 47  typedef struct {
47  #endif  #endif
48      } controls;      } controls;
49    
50  #ifdef OSD_SCALE  #ifdef OSD_BALLOON
51      cairo_surface_t *scale;      //a balloon with additional info
52      int scale_zoom;      struct {
53            cairo_surface_t *surface;
54            int orientation, offset_x, offset_y;
55    
56            gboolean just_created;
57            float lat, lon;
58            OsmGpsMapRect_t rect;
59    
60            /* function called to have the user app draw the contents */
61            OsmGpsMapBalloonCallback cb;
62            gpointer data;
63        } balloon;
64  #endif  #endif
65    
66    #ifdef OSD_SCALE
67        struct {
68            cairo_surface_t *surface;
69            int zoom;
70        } scale;
71    #endif
72    
73  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
74      cairo_surface_t *crosshair;      struct {
75            cairo_surface_t *surface;
76            gboolean rendered;
77        } crosshair;
78    #endif
79    
80    #ifdef OSD_NAV
81        struct {
82            cairo_surface_t *surface;
83            float lat, lon;
84            char *name;
85            gboolean imperial;    // display distance imperial/metric
86        } nav;
87  #endif  #endif
88    
89  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
90      cairo_surface_t *coordinates;      struct {
91      float coo_lat, coo_lon;          cairo_surface_t *surface;
92            float lat, lon;
93        } coordinates;
94  #endif  #endif
95    
96  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
97      /* values to handle the "source" menu */      struct {
98      cairo_surface_t *map_source;          /* values to handle the "source" menu */
99      gboolean expanded;          cairo_surface_t *surface;
100      gint shift, dir, count;          gboolean expanded;
101      gint handler_id;          gint shift, dir, count;
102      gint width, height;          gint handler_id;
103            gint width, height;
104            gboolean rendered;
105        } source_sel;
106  #endif  #endif
107    
108  } osd_priv_t;  } osd_priv_t;
109    
110    #ifdef OSD_BALLOON
111    /* most visual effects are hardcoded by now, but may be made */
112    /* available via properties later */
113    #ifndef BALLOON_AREA_WIDTH
114    #define BALLOON_AREA_WIDTH           290
115    #endif
116    #ifndef BALLOON_AREA_HEIGHT
117    #define BALLOON_AREA_HEIGHT           75
118    #endif
119    #ifndef BALLOON_CORNER_RADIUS
120    #define BALLOON_CORNER_RADIUS         10
121    #endif
122    
123    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
124    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
125    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
126    #define BALLOON_TRANSPARENCY         0.8
127    #define POINTER_HEIGHT                20
128    #define POINTER_FOOT_WIDTH            20
129    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
130    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
131    #define BALLOON_SHADOW_TRANSPARENCY  0.2
132    
133    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
134    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
135    
136    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
137    
138    #if 0
139    #define FIN   printf("entering function %s\n", __func__);
140    #define FOUT  printf("leaving function %s\n", __func__);
141    #else
142    #define FIN   ;
143    #define FOUT  ;
144    #endif
145    
146    /* draw the bubble shape. this is used twice, once for the shape and once */
147    /* for the shadow */
148    static void
149    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
150           gboolean bottom, int px, int py, int px0, int px1) {
151    
152        FIN;
153    
154        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
155        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
156                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
157        if(!bottom) {
158            /* insert top pointer */
159            cairo_line_to (cr, px1, y0);
160            cairo_line_to (cr, px, py);
161            cairo_line_to (cr, px0, y0);
162        }
163    
164        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
165        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
166                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
167        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
168        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
169                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
170        if(bottom) {
171            /* insert bottom pointer */
172            cairo_line_to (cr, px0, y1);
173            cairo_line_to (cr, px, py);
174            cairo_line_to (cr, px1, y1);
175        }
176    
177        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
178        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
179                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
180    
181        cairo_close_path (cr);
182    
183        FOUT;
184    }
185    
186    static void
187    osd_render_balloon(osm_gps_map_osd_t *osd) {
188        FIN;
189    
190        osd_priv_t *priv = (osd_priv_t*)osd->priv;
191    
192        if(!priv->balloon.surface)
193            return;
194    
195        /* get zoom */
196        gint zoom;
197        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
198    
199        /* ------- convert given coordinate into screen position --------- */
200        gint xs, ys;
201        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
202                                          priv->balloon.lat, priv->balloon.lon,
203                                          &xs, &ys);
204    
205        gint x0 = 1, y0 = 1;
206    
207        /* check position of this relative to screen center to determine */
208        /* pointer direction ... */
209        int pointer_x, pointer_x0, pointer_x1;
210        int pointer_y;
211    
212        /* ... and calculate position */
213        int orientation = 0;
214        if(xs > osd->widget->allocation.width/2) {
215            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
216            pointer_x = x0 - priv->balloon.offset_x;
217            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
218            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
219            orientation |= 1;
220        } else {
221            priv->balloon.offset_x = -POINTER_OFFSET;
222            pointer_x = x0 - priv->balloon.offset_x;
223            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
224            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
225        }
226    
227        gboolean bottom = FALSE;
228        if(ys > osd->widget->allocation.height/2) {
229            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
230            pointer_y = y0 - priv->balloon.offset_y;
231            bottom = TRUE;
232            orientation |= 2;
233        } else {
234            priv->balloon.offset_y = 0;
235            pointer_y = y0 - priv->balloon.offset_y;
236            y0 += POINTER_HEIGHT;
237        }
238    
239        /* if required orientation equals current one, then don't render */
240        /* anything */
241        if(orientation == priv->balloon.orientation)
242            return;
243    
244        priv->balloon.orientation = orientation;
245    
246        /* calculate bottom/right of box */
247        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
248    
249        /* save balloon screen coordinates for later use */
250        priv->balloon.rect.x = x0 + BALLOON_BORDER;
251        priv->balloon.rect.y = y0 + BALLOON_BORDER;
252        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
253        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
254    
255        g_assert(priv->balloon.surface);
256        cairo_t *cr = cairo_create(priv->balloon.surface);
257        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
258        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
259        cairo_paint(cr);
260        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
261    
262        /* --------- draw shadow --------------- */
263        osm_gps_map_draw_balloon_shape (cr,
264                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
265                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
266                     bottom, pointer_x, pointer_y,
267                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
268    
269        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
270        cairo_fill_preserve (cr);
271        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
272        cairo_set_line_width (cr, 0);
273        cairo_stroke (cr);
274    
275        /* --------- draw main shape ----------- */
276        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
277                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
278    
279        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
280        cairo_fill_preserve (cr);
281        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
282        cairo_set_line_width (cr, 1);
283        cairo_stroke (cr);
284    
285        if (priv->balloon.cb) {
286            osm_gps_map_balloon_event_t event;
287    
288            /* clip in case application tries to draw in */
289                /* exceed of the balloon */
290            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
291                             priv->balloon.rect.w, priv->balloon.rect.h);
292            cairo_clip (cr);
293            cairo_new_path (cr);  /* current path is not consumed by cairo_clip */
294    
295            /* request the application to draw the balloon contents */
296            event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW;
297            event.data.draw.rect = &priv->balloon.rect;
298            event.data.draw.cr = cr;
299    
300            priv->balloon.cb(&event, priv->balloon.data);
301        }
302    
303        cairo_destroy(cr);
304    
305        FOUT;
306    }
307    
308    /* return true if balloon is being displayed and if */
309    /* the given coordinate is within this balloon */
310    static gboolean
311    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y)
312    {
313        FIN;
314    
315        osd_priv_t *priv = (osd_priv_t*)osd->priv;
316    
317        if(!priv->balloon.surface)
318            return FALSE;
319    
320        gint xs, ys;
321        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
322                                          priv->balloon.lat, priv->balloon.lon,
323                                          &xs, &ys);
324    
325        xs += priv->balloon.rect.x + priv->balloon.offset_x;
326        ys += priv->balloon.rect.y + priv->balloon.offset_y;
327    
328        gboolean is_in =
329            (x > xs) && (x < xs + priv->balloon.rect.w) &&
330            (y > ys) && (y < ys + priv->balloon.rect.h);
331    
332        /* is this a real click or is the application just checking for something? */
333        if(click) {
334    
335            /* handle the fact that the balloon may have been created by the */
336            /* button down event */
337            if(!is_in && !down && !priv->balloon.just_created) {
338                /* the user actually clicked outside the balloon */
339    
340                /* close the balloon! */
341                osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
342    
343                /* and inform application about this */
344                if(priv->balloon.cb) {
345                    osm_gps_map_balloon_event_t event;
346                    event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED;
347                    priv->balloon.cb(&event, priv->balloon.data);
348                }
349    
350            }
351    
352            if(is_in && priv->balloon.cb) {
353                osm_gps_map_balloon_event_t event;
354    
355                /* notify application of click */
356                event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK;
357                event.data.click.x = x - xs;
358                event.data.click.y = y - ys;
359                event.data.click.down = down;
360    
361                priv->balloon.cb(&event, priv->balloon.data);
362            }
363        }
364        FOUT;
365        return is_in;
366    }
367    
368    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
369        FIN;
370    
371        g_return_if_fail (OSM_IS_GPS_MAP (map));
372    
373        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
374        g_return_if_fail (osd);
375    
376        osd_priv_t *priv = (osd_priv_t*)osd->priv;
377        g_return_if_fail (priv);
378    
379        if(priv->balloon.surface) {
380            cairo_surface_destroy(priv->balloon.surface);
381            priv->balloon.surface = NULL;
382            priv->balloon.lat = OSM_GPS_MAP_INVALID;
383            priv->balloon.lon = OSM_GPS_MAP_INVALID;
384        }
385        osm_gps_map_redraw(map);
386        FOUT;
387    }
388    
389    void
390    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
391                                  OsmGpsMapBalloonCallback cb, gpointer data) {
392        FIN;
393        g_return_if_fail (OSM_IS_GPS_MAP (map));
394    
395        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
396        g_return_if_fail (osd);
397    
398        osd_priv_t *priv = (osd_priv_t*)osd->priv;
399        g_return_if_fail (priv);
400    
401        osm_gps_map_osd_clear_balloon (map);
402    
403        /* allocate balloon surface */
404        priv->balloon.surface =
405            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
406                                       BALLOON_W+2, BALLOON_H+2);
407    
408        priv->balloon.lat = latitude;
409        priv->balloon.lon = longitude;
410        priv->balloon.cb = cb;
411        priv->balloon.data = data;
412        priv->balloon.just_created = TRUE;
413    
414        priv->balloon.orientation = -1;
415    
416        osd_render_balloon(osd);
417    
418        osm_gps_map_redraw(map);
419        FOUT;
420    }
421    
422    #endif // OSD_BALLOON
423    
424  /* position and extent of bounding box */  /* position and extent of bounding box */
425  #ifndef OSD_X  #ifndef OSD_X
426  #define OSD_X      (10)  #define OSD_X      (10)
# Line 210  osd_shape(cairo_t *cr) { Line 561  osd_shape(cairo_t *cr) {
561  static gboolean  static gboolean
562  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)
563  {  {
564        FIN;
565      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
566  }  }
567    
# Line 292  osd_check_zoom(gint x, gint y) { Line 644  osd_check_zoom(gint x, gint y) {
644  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
645    
646  /* size of usable area when expanded */  /* size of usable area when expanded */
647  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
648  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
649  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
650  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
651    
652  /* internal value to draw the arrow on the "puller" */  /* internal value to draw the arrow on the "puller" */
653  #define OSD_S_D0  (OSD_S_RAD/2)  #define OSD_S_D0  (OSD_S_RAD/2)
654  #ifndef OSD_FONT_SIZE  #ifndef OSD_FONT_SIZE
655  #define OSD_FONT_SIZE 16.0  #define OSD_FONT_SIZE (16.0)
656  #endif  #endif
657  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)
658  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)
# Line 309  osd_check_zoom(gint x, gint y) { Line 661  osd_check_zoom(gint x, gint y) {
661  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
662  static void  static void
663  osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {  osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
664      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
665          /* just draw the puller */          /* just draw the puller */
666          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
667          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
# Line 337  osd_source_content(osm_gps_map_osd_t *os Line 689  osd_source_content(osm_gps_map_osd_t *os
689    
690      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
691    
692      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
693          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
694          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);
695          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
# Line 362  osd_source_content(osm_gps_map_osd_t *os Line 714  osd_source_content(osm_gps_map_osd_t *os
714                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
715              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
716    
717              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
718                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
719              for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {              for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) {
720                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 376  osd_source_content(osm_gps_map_osd_t *os Line 728  osd_source_content(osm_gps_map_osd_t *os
728                  if(source == i) {                  if(source == i) {
729                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
730                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
731                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
732                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
733                      cairo_fill(cr);                      cairo_fill(cr);
734    
# Line 407  osd_source_content(osm_gps_map_osd_t *os Line 759  osd_source_content(osm_gps_map_osd_t *os
759  }  }
760    
761  static void  static void
762  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
763        FIN;
764    
765      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
766    
767        if(!priv->source_sel.surface ||
768           (priv->source_sel.rendered && !force_rerender))
769            return;
770    
771        priv->source_sel.rendered = TRUE;
772    
773  #ifndef OSD_COLOR  #ifndef OSD_COLOR
774      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
775      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 417  osd_render_source_sel(osm_gps_map_osd_t Line 777  osd_render_source_sel(osm_gps_map_osd_t
777  #endif  #endif
778    
779      /* draw source selector */      /* draw source selector */
780      cairo_t *cr = cairo_create(priv->map_source);      g_assert(priv->source_sel.surface);
781        cairo_t *cr = cairo_create(priv->source_sel.surface);
782      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
783      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);
784      cairo_paint(cr);      cairo_paint(cr);
# Line 449  osd_render_source_sel(osm_gps_map_osd_t Line 810  osd_render_source_sel(osm_gps_map_osd_t
810      cairo_stroke (cr);      cairo_stroke (cr);
811    
812      cairo_destroy(cr);      cairo_destroy(cr);
813        FOUT;
814  }  }
815    
816  /* re-allocate the buffer used to draw the menu. This is used */  /* re-allocate the buffer used to draw the menu. This is used */
817  /* to collapse/expand the buffer */  /* to collapse/expand the buffer */
818  static void  static void
819  osd_source_reallocate(osm_gps_map_osd_t *osd) {  osd_source_reallocate(osm_gps_map_osd_t *osd) {
820        FIN;
821      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
822    
823      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
824      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
825    
826      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
827      if(priv->expanded) {      if(priv->source_sel.expanded) {
828          cairo_text_extents_t extents;          cairo_text_extents_t extents;
829    
830          /* determine content size */          /* determine content size */
831          cairo_t *cr = cairo_create(priv->map_source);          g_assert(priv->source_sel.surface);
832            cairo_t *cr = cairo_create(priv->source_sel.surface);
833          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
834                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
835                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 482  osd_source_reallocate(osm_gps_map_osd_t Line 846  osd_source_reallocate(osm_gps_map_osd_t
846          }          }
847          cairo_destroy(cr);          cairo_destroy(cr);
848    
849          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
850          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
851              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
852    
853          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
854          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
855      }      }
856    
857      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
858      priv->map_source =      priv->source_sel.surface =
859          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
860    
861      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
862        FOUT;
863  }  }
864    
865  #define OSD_HZ      15  #define OSD_HZ      15
866  #define OSD_TIME    500  #define OSD_TIME    500
867    
868  static gboolean osd_source_animate(gpointer data) {  static gboolean osd_source_animate(gpointer data) {
869        FIN;
870      osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;      osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;
871      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
872      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
873      gboolean done = FALSE;      gboolean done = FALSE;
874      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
875    
876      /* shifting in */      /* shifting in */
877      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
878          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
879              priv->count = 0;              priv->source_sel.count = 0;
880              done = TRUE;              done = TRUE;
881          }          }
882      } else {      } else {
883          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
884              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
885              osd_source_reallocate(osd);              osd_source_reallocate(osd);
886    
887              priv->count = 1000;              priv->source_sel.count = 1000;
888              done = TRUE;              done = TRUE;
889          }          }
890      }      }
# Line 526  static gboolean osd_source_animate(gpoin Line 892  static gboolean osd_source_animate(gpoin
892    
893      /* count runs linearly from 0 to 1000, map this nicely onto a position */      /* count runs linearly from 0 to 1000, map this nicely onto a position */
894    
895      /* nicer sinoid mapping */      /* nice sinoid mapping */
896      float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;      float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
897      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
898            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
899          m * diff;          m * diff;
900    
901        /* make sure the screen is updated */
902      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
903    
904        /* stop animation if done */
905      if(done)      if(done)
906          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
907    
908        FOUT;
909      return !done;      return !done;
910  }  }
911    
# Line 543  static gboolean osd_source_animate(gpoin Line 913  static gboolean osd_source_animate(gpoin
913  static void  static void
914  osd_source_toggle(osm_gps_map_osd_t *osd)  osd_source_toggle(osm_gps_map_osd_t *osd)
915  {  {
916        FIN;
917      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
918    
919      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
920      if(priv->handler_id)      if(priv->source_sel.handler_id)
921          return;          return;
922    
923      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
924      if(!priv->expanded) {      /* collapse animation */
925          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
926            priv->source_sel.expanded = TRUE;
927          osd_source_reallocate(osd);          osd_source_reallocate(osd);
928    
929          priv->count = 1000;          priv->source_sel.count = 1000;
930          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
931          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
932      } else {      } else {
933          priv->count =  0;          priv->source_sel.count =  0;
934          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
935          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
936            priv->source_sel.dir = +1000/OSD_HZ;
937      }      }
938    
939      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
940        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
941                                                      osd_source_animate, osd);
942        FOUT;
943  }  }
944    
945  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
946  static osd_button_t  static osd_button_t
947  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
948        FIN;
949      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
950    
951      if(!priv->expanded)      if(!priv->source_sel.expanded)
952          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
953      else      else
954          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
# Line 586  osd_source_check(osm_gps_map_osd_t *osd, Line 963  osd_source_check(osm_gps_map_osd_t *osd,
963          /* really within puller shape? */          /* really within puller shape? */
964          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
965              /* expand source selector */              /* expand source selector */
966              osd_source_toggle(osd);              if(down)
967                    osd_source_toggle(osd);
968    
969              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
970              /* of the OSD */              /* of the OSD */
# Line 595  osd_source_check(osm_gps_map_osd_t *osd, Line 973  osd_source_check(osm_gps_map_osd_t *osd,
973      }      }
974    
975      /* check for clicks into data area */      /* check for clicks into data area */
976      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
977          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
978          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
979              y += OSD_S_EXP_H - OSD_S_PH;              y += OSD_S_EXP_H - OSD_S_PH;
# Line 605  osd_source_check(osm_gps_map_osd_t *osd, Line 983  osd_source_check(osm_gps_map_osd_t *osd,
983             y > 0 &&             y > 0 &&
984             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
985    
986              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
987                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
988    
989              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
990              y /= step;              y /= step;
991              y += 1;              y += 1;
992    
993              gint old = 0;              if(down) {
994              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
995                    g_object_get(osd->widget, "map-source", &old, NULL);
996              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
997                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
998                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
999                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
1000                        g_object_set(osd->widget, "map-source", y, NULL);
1001                  osd_render_source_sel(osd);  
1002                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
1003                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
1004                    }
1005              }              }
1006    
1007              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
1008              /* processing by application */              /* processing by application */
1009              return OSD_BG;              return OSD_BG;
1010          }          }
1011      }      }
1012    
1013        FOUT;
1014      return OSD_NONE;      return OSD_NONE;
1015  }  }
1016  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
1017    
 static osd_button_t  
 osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  
     osd_button_t but = OSD_NONE;  
   
 #ifdef OSD_SOURCE_SEL  
     /* the source selection area is handles internally */  
     but = osd_source_check(osd, x, y);  
     if(but != OSD_NONE)  
         return but;  
 #endif  
   
     x -= OSD_X;  
     y -= OSD_Y;  
   
     if(OSD_X < 0)  
         x -= (osd->widget->allocation.width - OSD_W);  
   
     if(OSD_Y < 0)  
         y -= (osd->widget->allocation.height - OSD_H);  
   
     /* first do a rough test for the OSD area. */  
     /* this is just to avoid an unnecessary detailed test */  
     if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {  
 #ifndef OSD_NO_DPAD  
         but = osd_check_dpad(x, y);  
 #endif  
   
         if(but == OSD_NONE)  
             but = osd_check_zoom(x, y);  
     }  
   
     return but;  
 }  
   
1018  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
1019  static void  static void
1020  osd_dpad_labels(cairo_t *cr, gint x, gint y) {  osd_dpad_labels(cairo_t *cr, gint x, gint y) {
# Line 741  osd_zoom_labels(cairo_t *cr, gint x, gin Line 1088  osd_zoom_labels(cairo_t *cr, gint x, gin
1088  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1089    
1090  #ifndef OSD_COORDINATES_FONT_SIZE  #ifndef OSD_COORDINATES_FONT_SIZE
1091  #define OSD_COORDINATES_FONT_SIZE 12  #define OSD_COORDINATES_FONT_SIZE (12.0)
1092  #endif  #endif
1093    
1094  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1095    
1096  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)  #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1097  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET+OSD_COORDINATES_FONT_SIZE/4)
1098    
1099  /* these can be overwritten with versions that support */  /* these can be overwritten with versions that support */
1100  /* localization */  /* localization */
# Line 805  static char Line 1152  static char
1152                             c, (int)integral, fractional*60.0);                             c, (int)integral, fractional*60.0);
1153  }  }
1154    
1155    /* render a string at the given screen position */
1156    static int
1157    osd_render_centered_text(cairo_t *cr, int y, int width, char *text) {
1158        FIN;
1159    
1160        if(!text) return y;
1161    
1162        char *p = g_malloc(strlen(text)+4);  // space for "...\n"
1163        strcpy(p, text);
1164    
1165        cairo_text_extents_t extents;
1166        memset(&extents, 0, sizeof(cairo_text_extents_t));
1167        cairo_text_extents (cr, p, &extents);
1168        g_assert(extents.width != 0.0);
1169    
1170        /* check if text needs to be truncated */
1171        int trunc_at = strlen(text);
1172        while(extents.width > width) {
1173    
1174            /* cut off all utf8 multibyte remains so the actual */
1175            /* truncation only deals with one byte */
1176            while((p[trunc_at-1] & 0xc0) == 0x80) {
1177                trunc_at--;
1178                g_assert(trunc_at > 0);
1179            }
1180    
1181            trunc_at--;
1182            g_assert(trunc_at > 0);
1183    
1184            strcpy(p+trunc_at, "...");
1185            cairo_text_extents (cr, p, &extents);
1186        }
1187    
1188        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1189        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1190        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1191        cairo_text_path (cr, p);
1192        cairo_stroke (cr);
1193    
1194        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1195        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1196        cairo_show_text (cr, p);
1197    
1198        g_free(p);
1199    
1200        /* skip + 1/5 line */
1201        FOUT;
1202        return y + 6*OSD_COORDINATES_FONT_SIZE/5;
1203    }
1204    
1205  static void  static void
1206  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1207  {  {
1208        FIN;
1209      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1210    
1211        if(!priv->coordinates.surface)
1212            return;
1213    
1214      /* get current map position */      /* get current map position */
1215      gfloat lat, lon;      gfloat lat, lon;
1216      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1217    
1218      /* check if position has changed enough to require redraw */      /* check if position has changed enough to require redraw */
1219      if(!isnan(priv->coo_lat) && !isnan(priv->coo_lon))      if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1220          if((fabsf(lat - priv->coo_lat) < 1/60000) &&     /* 1/60000 == 1/1000 minute */          /* 1/60000 == 1/1000 minute */
1221             (fabsf(lon - priv->coo_lon) < 1/60000))          if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1222               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1223              return;              return;
1224    
1225      priv->coo_lat = lat;      priv->coordinates.lat = lat;
1226      priv->coo_lon = lon;      priv->coordinates.lon = lon;
1227    
1228        /* first fill with transparency */
1229    
1230      /* first fill with light transparency */      g_assert(priv->coordinates.surface);
1231      cairo_t *cr = cairo_create(priv->coordinates);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1232      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1233      cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);      //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
1234        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1235      cairo_paint(cr);      cairo_paint(cr);
1236      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1237    
# Line 838  osd_render_coordinates(osm_gps_map_osd_t Line 1243  osd_render_coordinates(osm_gps_map_osd_t
1243      char *latitude = osd_latitude_str(lat);      char *latitude = osd_latitude_str(lat);
1244      char *longitude = osd_longitude_str(lon);      char *longitude = osd_longitude_str(lon);
1245    
1246      cairo_text_extents_t lat_extents, lon_extents;      int y = OSD_COORDINATES_OFFSET;
1247      cairo_text_extents (cr, latitude, &lat_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude);
1248      cairo_text_extents (cr, longitude, &lon_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude);
1249    
1250        g_free(latitude);
1251        g_free(longitude);
1252    
1253      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_destroy(cr);
1254      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);      FOUT;
1255      cairo_move_to (cr,  }
1256                     (OSD_COORDINATES_W - lat_extents.width)/2,  #endif  // OSD_COORDINATES
                    OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
     cairo_text_path (cr, latitude);  
     cairo_move_to (cr,  
                    (OSD_COORDINATES_W - lon_extents.width)/2,  
                    OSD_COORDINATES_OFFSET - lon_extents.y_bearing +  
                    OSD_COORDINATES_FONT_SIZE);  
     cairo_text_path (cr, longitude);  
     cairo_stroke (cr);  
1257    
1258      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);  #ifdef OSD_NAV
1259      cairo_move_to (cr,  #define OSD_NAV_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1260                     (OSD_COORDINATES_W - lat_extents.width)/2,  #define OSD_NAV_H  (11*OSD_COORDINATES_FONT_SIZE)
1261                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
1262      cairo_show_text (cr, latitude);  /* http://mathforum.org/library/drmath/view/55417.html */
1263      cairo_move_to (cr,  static float get_bearing(float lat1, float lon1, float lat2, float lon2) {
1264                     (OSD_COORDINATES_W - lon_extents.width)/2,    return atan2( sin(lon2 - lon1) * cos(lat2),
1265                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +                  cos(lat1) * sin(lat2) -
1266                     OSD_COORDINATES_FONT_SIZE);                  sin(lat1) * cos(lat2) * cos(lon2 - lon1));
1267      cairo_show_text (cr, longitude);  }
1268    
1269    /* http://mathforum.org/library/drmath/view/51722.html */
1270    static float get_distance(float lat1, float lon1, float lat2, float lon2) {
1271      float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) +
1272                       sin(lat1) * sin(lat2));
1273    
1274      //  return(aob * 3959.0);   /* great circle radius in miles */
1275    
1276      return(aob * 6371000.0);     /* great circle radius in meters */
1277    }
1278    
1279    static void
1280    osd_render_nav(osm_gps_map_osd_t *osd)
1281    {
1282        FIN;
1283        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1284    
1285        if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon))
1286            return;
1287    
1288        /* first fill with transparency */
1289        g_assert(priv->nav.surface);
1290        cairo_t *cr = cairo_create(priv->nav.surface);
1291        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1292        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1293        cairo_paint(cr);
1294        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1295    
1296        cairo_select_font_face (cr, "Sans",
1297                                CAIRO_FONT_SLANT_NORMAL,
1298                                CAIRO_FONT_WEIGHT_BOLD);
1299        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1300    
1301        char *latitude = osd_latitude_str(priv->nav.lat);
1302        char *longitude = osd_longitude_str(priv->nav.lon);
1303    
1304        int y = OSD_COORDINATES_OFFSET;
1305        y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name);
1306        y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude);
1307        y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude);
1308    
1309      g_free(latitude);      g_free(latitude);
1310      g_free(longitude);      g_free(longitude);
1311    
1312        /* draw the compass */
1313        int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2;
1314        if(radius > OSD_NAV_W/2)
1315            radius = OSD_NAV_W/2;
1316    
1317        int x = OSD_NAV_W/2+1;
1318        y += radius;
1319    
1320        cairo_stroke (cr);
1321    
1322        /* draw background */
1323        cairo_arc(cr, x, y, radius, 0,  2*M_PI);
1324        cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
1325        cairo_fill_preserve (cr);
1326        cairo_set_source_rgb (cr, 0, 0, 0);
1327        cairo_set_line_width (cr, 1);
1328        cairo_stroke (cr);
1329    
1330        /* draw pointer */
1331    #define ARROW_WIDTH     0.3
1332    #define ARROW_LENGTH    0.7
1333    
1334        coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget));
1335        if(gps) {
1336            float arot = get_bearing(gps->rlat, gps->rlon,
1337                         deg2rad(priv->nav.lat), deg2rad(priv->nav.lon));
1338    
1339            cairo_move_to(cr,
1340                          x + radius *  ARROW_LENGTH *  sin(arot),
1341                          y + radius *  ARROW_LENGTH * -cos(arot));
1342    
1343            cairo_line_to(cr,
1344                          x + radius * -ARROW_LENGTH *  sin(arot+ARROW_WIDTH),
1345                          y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH));
1346    
1347            cairo_line_to(cr,
1348                          x + radius * -0.5 * ARROW_LENGTH *  sin(arot),
1349                          y + radius * -0.5 * ARROW_LENGTH * -cos(arot));
1350    
1351            cairo_line_to(cr,
1352                          x + radius * -ARROW_LENGTH *  sin(arot-ARROW_WIDTH),
1353                          y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH));
1354    
1355            cairo_close_path(cr);
1356            cairo_set_source_rgb (cr, 0, 0, 0);
1357            cairo_fill (cr);
1358    
1359            y += radius + OSD_COORDINATES_FONT_SIZE/4;
1360    
1361            float dist = get_distance(gps->rlat, gps->rlon,
1362                            deg2rad(priv->nav.lat), deg2rad(priv->nav.lon));
1363    
1364            char *dist_str = NULL;
1365            if(!priv->nav.imperial) {
1366                /* metric is easy ... */
1367                if(dist<1000)
1368                    dist_str = g_strdup_printf("%u m", (int)dist);
1369                else
1370                    dist_str = g_strdup_printf("%.1f km", dist/1000);
1371            } else {
1372                /* and now the hard part: scale for useful imperial values :-( */
1373                /* try to convert to feet, 1ft == 0.3048 m */
1374    
1375                if(dist/(3*0.3048) >= 1760.0)      /* more than 1760 yard? */
1376                    dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0));
1377                else if(dist/0.3048 >= 100)        /* more than 100 feet? */
1378                    dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3));
1379                else
1380                    dist_str = g_strdup_printf("%.0f ft", dist/0.3048);
1381            }
1382    
1383            y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str);
1384            g_free(dist_str);
1385        }
1386    
1387      cairo_destroy(cr);      cairo_destroy(cr);
1388        FOUT;
1389  }  }
1390  #endif  // OSD_COORDINATES  
1391    /* check if the user clicked inside the source selection area */
1392    static osd_button_t
1393    osd_nav_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
1394        FIN;
1395        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1396    
1397        if(!priv->nav.surface || down)
1398            return OSD_NONE;
1399    
1400        x -= OSD_X;
1401        if(OSD_X < 0)
1402            x -= (osd->widget->allocation.width - OSD_NAV_W);
1403    
1404        y -= (osd->widget->allocation.height - OSD_NAV_H)/2;
1405    
1406        if(x >= 0 && y >= 0 && x <= OSD_NAV_W && y <= OSD_NAV_H) {
1407            osm_gps_map_set_center(OSM_GPS_MAP(osd->widget),
1408                                   priv->nav.lat, priv->nav.lon);
1409        }
1410    
1411        FOUT;
1412        return OSD_NONE;
1413    }
1414    
1415    void osm_gps_map_osd_clear_nav (OsmGpsMap *map) {
1416        FIN;
1417        g_return_if_fail (OSM_IS_GPS_MAP (map));
1418    
1419        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1420        g_return_if_fail (osd);
1421    
1422        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1423        g_return_if_fail (priv);
1424    
1425        if(priv->nav.surface) {
1426            cairo_surface_destroy(priv->nav.surface);
1427            priv->nav.surface = NULL;
1428            priv->nav.lat = OSM_GPS_MAP_INVALID;
1429            priv->nav.lon = OSM_GPS_MAP_INVALID;
1430            if(priv->nav.name) g_free(priv->nav.name);
1431        }
1432        osm_gps_map_redraw(map);
1433        FOUT;
1434    }
1435    
1436    void
1437    osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial,
1438                              float latitude, float longitude, char *name) {
1439        FIN;
1440        g_return_if_fail (OSM_IS_GPS_MAP (map));
1441    
1442        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1443        g_return_if_fail (osd);
1444    
1445        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1446        g_return_if_fail (priv);
1447    
1448        osm_gps_map_osd_clear_nav (map);
1449    
1450        /* allocate balloon surface */
1451        priv->nav.surface =
1452            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1453                                       OSD_NAV_W+2, OSD_NAV_H+2);
1454    
1455        priv->nav.lat = latitude;
1456        priv->nav.lon = longitude;
1457        priv->nav.name = g_strdup(name);
1458        priv->nav.imperial = imperial;
1459    
1460        osd_render_nav(osd);
1461    
1462        osm_gps_map_redraw(map);
1463        FOUT;
1464    }
1465    
1466    #endif // OSD_NAV
1467    
1468    static osd_button_t
1469    osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) {
1470        FIN;
1471        osd_button_t but = OSD_NONE;
1472    
1473    #ifdef OSD_BALLOON
1474        if(down) {
1475            /* needed to handle balloons that are created at click */
1476            osd_priv_t *priv = (osd_priv_t*)osd->priv;
1477            priv->balloon.just_created = FALSE;
1478        }
1479    #endif
1480    
1481    #ifdef OSD_SOURCE_SEL
1482        /* the source selection area is handles internally */
1483        but = osd_source_check(osd, down, x, y);
1484    #endif
1485    
1486    #ifdef OSD_NAV
1487        if(but == OSD_NONE) {
1488            /* the source selection area is handles internally */
1489            but = osd_nav_check(osd, down, x, y);
1490        }
1491    #endif
1492    
1493        if(but == OSD_NONE) {
1494            gint mx = x - OSD_X;
1495            gint my = y - OSD_Y;
1496    
1497            if(OSD_X < 0)
1498                mx -= (osd->widget->allocation.width - OSD_W);
1499    
1500            if(OSD_Y < 0)
1501                my -= (osd->widget->allocation.height - OSD_H);
1502    
1503            /* first do a rough test for the OSD area. */
1504            /* this is just to avoid an unnecessary detailed test */
1505            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
1506    #ifndef OSD_NO_DPAD
1507                but = osd_check_dpad(mx, my);
1508    #endif
1509            }
1510    
1511            if(but == OSD_NONE)
1512                but = osd_check_zoom(mx, my);
1513        }
1514    
1515    #ifdef OSD_BALLOON
1516        if(but == OSD_NONE) {
1517            /* check if user clicked into balloon */
1518            if(osd_balloon_check(osd, click, down, x, y))
1519                but = OSD_BG;
1520        }
1521    #endif
1522    
1523        FOUT;
1524        return but;
1525    }
1526    
1527    
1528  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1529    
# Line 886  osd_render_coordinates(osm_gps_map_osd_t Line 1538  osd_render_coordinates(osm_gps_map_osd_t
1538    
1539  static void  static void
1540  osd_render_crosshair_shape(cairo_t *cr) {  osd_render_crosshair_shape(cairo_t *cr) {
1541        FIN;
1542      cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,      cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
1543                 OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);                 OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
1544    
# Line 904  osd_render_crosshair_shape(cairo_t *cr) Line 1557  osd_render_crosshair_shape(cairo_t *cr)
1557      cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);      cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
1558    
1559      cairo_stroke (cr);      cairo_stroke (cr);
1560        FOUT;
1561  }  }
1562    
1563  static void  static void
1564  osd_render_crosshair(osm_gps_map_osd_t *osd)  osd_render_crosshair(osm_gps_map_osd_t *osd)
1565  {  {
1566        FIN;
1567      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1568    
1569        if(!priv->crosshair.surface || priv->crosshair.rendered)
1570            return;
1571    
1572        priv->crosshair.rendered = TRUE;
1573    
1574      /* first fill with transparency */      /* first fill with transparency */
1575      cairo_t *cr = cairo_create(priv->crosshair);      g_assert(priv->crosshair.surface);
1576        cairo_t *cr = cairo_create(priv->crosshair.surface);
1577      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1578      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
     //    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);  
1579      cairo_paint(cr);      cairo_paint(cr);
1580      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1581    
# Line 930  osd_render_crosshair(osm_gps_map_osd_t * Line 1590  osd_render_crosshair(osm_gps_map_osd_t *
1590      osd_render_crosshair_shape(cr);      osd_render_crosshair_shape(cr);
1591    
1592      cairo_destroy(cr);      cairo_destroy(cr);
1593        FOUT;
1594  }  }
1595  #endif  #endif
1596    
1597  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1598    
1599  #ifndef OSD_SCALE_FONT_SIZE  #ifndef OSD_SCALE_FONT_SIZE
1600  #define OSD_SCALE_FONT_SIZE 12  #define OSD_SCALE_FONT_SIZE (12.0)
1601  #endif  #endif
1602  #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)  #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)
1603  #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)  #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)
# Line 951  osd_render_crosshair(osm_gps_map_osd_t * Line 1612  osd_render_crosshair(osm_gps_map_osd_t *
1612  static void  static void
1613  osd_render_scale(osm_gps_map_osd_t *osd)  osd_render_scale(osm_gps_map_osd_t *osd)
1614  {  {
1615        FIN;
1616      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1617    
1618        if(!priv->scale.surface)
1619            return;
1620    
1621      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
1622      gint zoom;      gint zoom;
1623      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1624      if(zoom == priv->scale_zoom)      if(zoom == priv->scale.zoom)
1625          return;          return;
1626    
1627      priv->scale_zoom = zoom;      priv->scale.zoom = zoom;
1628    
1629      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
1630    
1631      /* first fill with transparency */      /* first fill with transparency */
1632      cairo_t *cr = cairo_create(priv->scale);      g_assert(priv->scale.surface);
1633        cairo_t *cr = cairo_create(priv->scale.surface);
1634      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1635      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);
1636      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
# Line 1074  osd_render_scale(osm_gps_map_osd_t *osd) Line 1740  osd_render_scale(osm_gps_map_osd_t *osd)
1740      cairo_stroke(cr);      cairo_stroke(cr);
1741    
1742      cairo_destroy(cr);      cairo_destroy(cr);
1743        FOUT;
1744  }  }
1745  #endif  #endif
1746    
1747  static void  static void
1748  osd_render_controls(osm_gps_map_osd_t *osd)  osd_render_controls(osm_gps_map_osd_t *osd)
1749  {  {
1750        FIN;
1751      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1752    
1753        if(!priv->controls.surface)
1754            return;
1755    
1756      if(priv->controls.rendered      if(priv->controls.rendered
1757  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1758         && (priv->controls.gps_enabled == (osd->cb != NULL))         && (priv->controls.gps_enabled == (osd->cb != NULL))
# Line 1092  osd_render_controls(osm_gps_map_osd_t *o Line 1763  osd_render_controls(osm_gps_map_osd_t *o
1763  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1764      priv->controls.gps_enabled = (osd->cb != NULL);      priv->controls.gps_enabled = (osd->cb != NULL);
1765  #endif  #endif
1766        priv->controls.rendered = TRUE;
1767    
1768  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1769      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
# Line 1100  osd_render_controls(osm_gps_map_osd_t *o Line 1772  osd_render_controls(osm_gps_map_osd_t *o
1772  #endif  #endif
1773    
1774      /* first fill with transparency */      /* first fill with transparency */
1775        g_assert(priv->controls.surface);
1776      cairo_t *cr = cairo_create(priv->controls.surface);      cairo_t *cr = cairo_create(priv->controls.surface);
1777      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1778      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);
# Line 1176  osd_render_controls(osm_gps_map_osd_t *o Line 1849  osd_render_controls(osm_gps_map_osd_t *o
1849  static void  static void
1850  osd_render(osm_gps_map_osd_t *osd)  osd_render(osm_gps_map_osd_t *osd)
1851  {  {
1852        /* this function is actually called pretty often since the */
1853        /* OSD contents may have changed (due to a coordinate/zoom change). */
1854        /* The different OSD parts have to make sure that they don't */
1855        /* render unneccessarily often and thus waste CPU power */
1856    
1857      osd_render_controls(osd);      osd_render_controls(osd);
1858    
1859  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1860      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1861  #endif  #endif
1862    
1863  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1190  osd_render(osm_gps_map_osd_t *osd) Line 1868  osd_render(osm_gps_map_osd_t *osd)
1868      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1869  #endif  #endif
1870    
1871    #ifdef OSD_NAV
1872        osd_render_nav(osd);
1873    #endif
1874    
1875  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1876      osd_render_coordinates(osd);      osd_render_coordinates(osd);
1877  #endif  #endif
# Line 1214  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1896  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1896    
1897  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1898          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1899          priv->map_source =          priv->source_sel.surface =
1900              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1901                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1902            priv->source_sel.rendered = FALSE;
1903  #endif  #endif
1904    
1905  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1906          priv->scale =          priv->scale.surface =
1907              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1908                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W, OSD_SCALE_H);
1909          priv->scale_zoom = -1;          priv->scale.zoom = -1;
1910  #endif  #endif
1911    
1912  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1913          priv->crosshair =          priv->crosshair.surface =
1914              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1915                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1916            priv->crosshair.rendered = FALSE;
1917  #endif  #endif
1918    
1919  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1920          priv->coordinates =          priv->coordinates.surface =
1921              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1922                                         OSD_COORDINATES_W, OSD_COORDINATES_H);                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1923    
1924          priv->coo_lat = priv->coo_lon = OSM_GPS_MAP_INVALID;          priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1925  #endif  #endif
1926    
1927          /* ... and render it */          /* ... and render it */
# Line 1247  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1931  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1931      // now draw this onto the original context      // now draw this onto the original context
1932      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1933    
1934      int x, y;      gint x, y;
1935    
1936  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1937      x =  OSD_X;      x =  OSD_X;
# Line 1255  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1939  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1939      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1940      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1941    
1942      cairo_set_source_surface(cr, priv->scale, x, y);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1943      cairo_paint(cr);      cairo_paint(cr);
1944  #endif  #endif
1945    
# Line 1263  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1947  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1947      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1948      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1949    
1950      cairo_set_source_surface(cr, priv->crosshair, x, y);      cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1951      cairo_paint(cr);      cairo_paint(cr);
1952  #endif  #endif
1953    
1954    #ifdef OSD_NAV
1955        if(priv->nav.surface) {
1956            x =  OSD_X;
1957            if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1958            y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1959    
1960            cairo_set_source_surface(cr, priv->nav.surface, x, y);
1961            cairo_paint(cr);
1962        }
1963    #endif
1964    
1965  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1966      x = -OSD_X;      x = -OSD_X;
1967      y = -OSD_Y;      y = -OSD_Y;
1968      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1969      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1970    
1971      cairo_set_source_surface(cr, priv->coordinates, x, y);      cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1972      cairo_paint(cr);      cairo_paint(cr);
1973  #endif  #endif
1974    
1975    #ifdef OSD_BALLOON
1976        if(priv->balloon.surface) {
1977    
1978            /* convert given lat lon into screen coordinates */
1979            gint x, y;
1980            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1981                                          priv->balloon.lat, priv->balloon.lon,
1982                                          &x, &y);
1983    
1984            /* check if balloon needs to be rerendered */
1985            osd_render_balloon(osd);
1986    
1987            cairo_set_source_surface(cr, priv->balloon.surface,
1988                                     x + priv->balloon.offset_x,
1989                                     y + priv->balloon.offset_y);
1990            cairo_paint(cr);
1991        }
1992    #endif
1993    
1994      x = OSD_X;      x = OSD_X;
1995      if(x < 0)      if(x < 0)
1996          x += osd->widget->allocation.width - OSD_W;          x += osd->widget->allocation.width - OSD_W;
# Line 1289  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 2003  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
2003      cairo_paint(cr);      cairo_paint(cr);
2004    
2005  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
2006      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
2007          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
2008          if(!priv->expanded)          if(!priv->source_sel.expanded)
2009              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
2010          else          else
2011              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
2012      } else      } else
2013          x = priv->shift;          x = priv->source_sel.shift;
2014    
2015      y = OSD_S_Y;      y = OSD_S_Y;
2016      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
2017          if(!priv->expanded)          if(!priv->source_sel.expanded)
2018              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
2019          else          else
2020              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
2021      }      }
2022    
2023      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
2024      cairo_paint(cr);      cairo_paint(cr);
2025  #endif  #endif
2026    
2027      cairo_destroy(cr);      cairo_destroy(cr);
2028        FOUT;
2029  }  }
2030    
2031  static void  static void
2032  osd_free(osm_gps_map_osd_t *osd)  osd_free(osm_gps_map_osd_t *osd)
2033  {  {
2034        FIN;
2035      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
2036    
2037      if (priv->controls.surface)      if (priv->controls.surface)
2038           cairo_surface_destroy(priv->controls.surface);           cairo_surface_destroy(priv->controls.surface);
2039    
2040  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
2041      if(priv->handler_id)      if(priv->source_sel.handler_id)
2042          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
2043    
2044      if (priv->map_source)      if (priv->source_sel.surface)
2045           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
2046  #endif  #endif
2047    
2048  #ifdef OSD_SCALE  #ifdef OSD_SCALE
2049      if (priv->scale)      if (priv->scale.surface)
2050           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
2051  #endif  #endif
2052    
2053  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
2054      if (priv->crosshair)      if (priv->crosshair.surface)
2055           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair.surface);
2056    #endif
2057    
2058    #ifdef OSD_NAV
2059        if (priv->nav.surface)
2060             cairo_surface_destroy(priv->nav.surface);
2061  #endif  #endif
2062    
2063  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
2064      if (priv->coordinates)      if (priv->coordinates.surface)
2065           cairo_surface_destroy(priv->coordinates);           cairo_surface_destroy(priv->coordinates.surface);
2066    #endif
2067    
2068    #ifdef OSD_BALLOON
2069        if (priv->balloon.surface)
2070             cairo_surface_destroy(priv->balloon.surface);
2071  #endif  #endif
2072    
2073      g_free(priv);      g_free(priv);
2074        FOUT;
2075  }  }
2076    
2077  static gboolean  static gboolean
2078  osd_busy(osm_gps_map_osd_t *osd)  osd_busy(osm_gps_map_osd_t *osd)
2079  {  {
2080        FIN;
2081  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
2082      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
2083      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
2084  #else  #else
2085      return FALSE;      return FALSE;
2086  #endif  #endif
2087  }  }
2088    
2089    static osd_button_t
2090    osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
2091        FIN;
2092        return osd_check_int(osd, TRUE, down, x, y);
2093    }
2094    
2095  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
2096      .widget     = NULL,      .widget     = NULL,
2097    
# Line 1377  static osm_gps_map_osd_t osd_classic = { Line 2111  static osm_gps_map_osd_t osd_classic = {
2111  void  void
2112  osm_gps_map_osd_classic_init(OsmGpsMap *map)  osm_gps_map_osd_classic_init(OsmGpsMap *map)
2113  {  {
2114        FIN;
2115      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);
2116    
2117    #ifdef OSD_BALLOON
2118        priv->balloon.lat = OSM_GPS_MAP_INVALID;
2119        priv->balloon.lon = OSM_GPS_MAP_INVALID;
2120    #endif
2121    
2122      osd_classic.priv = priv;      osd_classic.priv = priv;
2123    
2124      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
2125        FOUT;
2126  }  }
2127    
2128  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
# Line 1389  osm_gps_map_osd_classic_init(OsmGpsMap * Line 2130  osm_gps_map_osd_classic_init(OsmGpsMap *
2130  /* but instead are to be used by the main application */  /* but instead are to be used by the main application */
2131  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
2132                                   gpointer data) {                                   gpointer data) {
2133        FIN;
2134      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
2135      g_return_if_fail (osd);      g_return_if_fail (osd);
2136    
# Line 1400  void osm_gps_map_osd_enable_gps (OsmGpsM Line 2142  void osm_gps_map_osd_enable_gps (OsmGpsM
2142      osd->render(osd);      osd->render(osd);
2143    
2144      osm_gps_map_redraw(map);      osm_gps_map_redraw(map);
2145        FOUT;
2146  }  }
2147  #endif  #endif
2148    
2149  osd_button_t  osd_button_t
2150  osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {  osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {
2151        FIN;
2152      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
2153      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
2154    
2155      return osd_check(osd, x, y);      return osd_check_int(osd, FALSE, TRUE, x, y);
2156  }  }

Legend:
Removed from v.108  
changed lines
  Added in v.202