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

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

revision 111 by harbaum, Mon Sep 14 12:16:08 2009 UTC revision 150 by harbaum, Thu Oct 29 20:25:11 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_BALLOON
51        //a balloon with additional info
52        struct {
53            cairo_surface_t *surface;
54            int orientation, offset_x, offset_y;
55    
56            gboolean just_created;
57            float lat, lon;
58            OsmGpsMapRect_t rect;
59    
60            /* function called to have the user app draw the contents */
61            OsmGpsMapBalloonCallback cb;
62            gpointer data;
63        } balloon;
64    #endif
65    
66  #ifdef OSD_SCALE  #ifdef OSD_SCALE
67      struct {      struct {
68          cairo_surface_t *surface;          cairo_surface_t *surface;
# Line 59  typedef struct { Line 77  typedef struct {
77      } crosshair;      } crosshair;
78  #endif  #endif
79    
80    #ifdef OSD_NAV
81        struct {
82            cairo_surface_t *surface;
83            float lat, lon;
84            char *name;
85            gboolean imperial;    // display distance imperial/metric
86        } nav;
87    #endif
88    
89  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
90      struct {      struct {
91          cairo_surface_t *surface;          cairo_surface_t *surface;
# Line 80  typedef struct { Line 107  typedef struct {
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        cairo_t *cr = cairo_create(priv->balloon.surface);
256        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
257        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
258        cairo_paint(cr);
259        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
260    
261        /* --------- draw shadow --------------- */
262        osm_gps_map_draw_balloon_shape (cr,
263                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
264                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
265                     bottom, pointer_x, pointer_y,
266                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
267    
268        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
269        cairo_fill_preserve (cr);
270        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
271        cairo_set_line_width (cr, 0);
272        cairo_stroke (cr);
273    
274        /* --------- draw main shape ----------- */
275        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
276                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
277    
278        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
279        cairo_fill_preserve (cr);
280        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
281        cairo_set_line_width (cr, 1);
282        cairo_stroke (cr);
283    
284        if (priv->balloon.cb) {
285            osm_gps_map_balloon_event_t event;
286    
287            /* clip in case application tries to draw in */
288                /* exceed of the balloon */
289            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
290                             priv->balloon.rect.w, priv->balloon.rect.h);
291            cairo_clip (cr);
292            cairo_new_path (cr);  /* current path is not consumed by cairo_clip */
293    
294            /* request the application to draw the balloon contents */
295            event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW;
296            event.data.draw.rect = &priv->balloon.rect;
297            event.data.draw.cr = cr;
298    
299            priv->balloon.cb(&event, priv->balloon.data);
300        }
301    
302        cairo_destroy(cr);
303    
304        FOUT;
305    }
306    
307    /* return true if balloon is being displayed and if */
308    /* the given coordinate is within this balloon */
309    static gboolean
310    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y)
311    {
312        FIN;
313    
314        osd_priv_t *priv = (osd_priv_t*)osd->priv;
315    
316        if(!priv->balloon.surface)
317            return FALSE;
318    
319        gint xs, ys;
320        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
321                                          priv->balloon.lat, priv->balloon.lon,
322                                          &xs, &ys);
323    
324        xs += priv->balloon.rect.x + priv->balloon.offset_x;
325        ys += priv->balloon.rect.y + priv->balloon.offset_y;
326    
327        gboolean is_in =
328            (x > xs) && (x < xs + priv->balloon.rect.w) &&
329            (y > ys) && (y < ys + priv->balloon.rect.h);
330    
331        /* is this a real click or is the application just checking for something? */
332        if(click) {
333    
334            /* handle the fact that the balloon may have been created by the */
335            /* button down event */
336            if(!is_in && !down && !priv->balloon.just_created) {
337                /* the user actually clicked outside the balloon */
338    
339                /* close the balloon! */
340                osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
341    
342                /* and inform application about this */
343                if(priv->balloon.cb) {
344                    osm_gps_map_balloon_event_t event;
345                    event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED;
346                    priv->balloon.cb(&event, priv->balloon.data);
347                }
348    
349            }
350    
351            if(is_in && priv->balloon.cb) {
352                osm_gps_map_balloon_event_t event;
353    
354                /* notify application of click */
355                event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK;
356                event.data.click.x = x - xs;
357                event.data.click.y = y - ys;
358                event.data.click.down = down;
359    
360                priv->balloon.cb(&event, priv->balloon.data);
361            }
362        }
363        FOUT;
364        return is_in;
365    }
366    
367    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
368        FIN;
369    
370        g_return_if_fail (OSM_IS_GPS_MAP (map));
371    
372        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
373        g_return_if_fail (osd);
374    
375        osd_priv_t *priv = (osd_priv_t*)osd->priv;
376        g_return_if_fail (priv);
377    
378        if(priv->balloon.surface) {
379            cairo_surface_destroy(priv->balloon.surface);
380            priv->balloon.surface = NULL;
381            priv->balloon.lat = OSM_GPS_MAP_INVALID;
382            priv->balloon.lon = OSM_GPS_MAP_INVALID;
383        }
384        osm_gps_map_redraw(map);
385        FOUT;
386    }
387    
388    void
389    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
390                                  OsmGpsMapBalloonCallback cb, gpointer data) {
391        FIN;
392        g_return_if_fail (OSM_IS_GPS_MAP (map));
393    
394        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
395        g_return_if_fail (osd);
396    
397        osd_priv_t *priv = (osd_priv_t*)osd->priv;
398        g_return_if_fail (priv);
399    
400        osm_gps_map_osd_clear_balloon (map);
401    
402        /* allocate balloon surface */
403        priv->balloon.surface =
404            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
405                                       BALLOON_W+2, BALLOON_H+2);
406    
407        priv->balloon.lat = latitude;
408        priv->balloon.lon = longitude;
409        priv->balloon.cb = cb;
410        priv->balloon.data = data;
411        priv->balloon.just_created = TRUE;
412    
413        priv->balloon.orientation = -1;
414    
415        osd_render_balloon(osd);
416    
417        osm_gps_map_redraw(map);
418        FOUT;
419    }
420    
421    #endif // OSD_BALLOON
422    
423  /* position and extent of bounding box */  /* position and extent of bounding box */
424  #ifndef OSD_X  #ifndef OSD_X
425  #define OSD_X      (10)  #define OSD_X      (10)
# Line 220  osd_shape(cairo_t *cr) { Line 560  osd_shape(cairo_t *cr) {
560  static gboolean  static gboolean
561  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)
562  {  {
563        FIN;
564      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
565  }  }
566    
# Line 310  osd_check_zoom(gint x, gint y) { Line 651  osd_check_zoom(gint x, gint y) {
651  /* internal value to draw the arrow on the "puller" */  /* internal value to draw the arrow on the "puller" */
652  #define OSD_S_D0  (OSD_S_RAD/2)  #define OSD_S_D0  (OSD_S_RAD/2)
653  #ifndef OSD_FONT_SIZE  #ifndef OSD_FONT_SIZE
654  #define OSD_FONT_SIZE 16.0  #define OSD_FONT_SIZE (16.0)
655  #endif  #endif
656  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)
657  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)
# Line 418  osd_source_content(osm_gps_map_osd_t *os Line 759  osd_source_content(osm_gps_map_osd_t *os
759    
760  static void  static void
761  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
762        FIN;
763    
764      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
765    
766      if(priv->source_sel.rendered && !force_rerender)      if(!priv->source_sel.surface ||
767           (priv->source_sel.rendered && !force_rerender))
768          return;          return;
769    
770      priv->source_sel.rendered = TRUE;      priv->source_sel.rendered = TRUE;
# Line 464  osd_render_source_sel(osm_gps_map_osd_t Line 808  osd_render_source_sel(osm_gps_map_osd_t
808      cairo_stroke (cr);      cairo_stroke (cr);
809    
810      cairo_destroy(cr);      cairo_destroy(cr);
811        FOUT;
812  }  }
813    
814  /* re-allocate the buffer used to draw the menu. This is used */  /* re-allocate the buffer used to draw the menu. This is used */
815  /* to collapse/expand the buffer */  /* to collapse/expand the buffer */
816  static void  static void
817  osd_source_reallocate(osm_gps_map_osd_t *osd) {  osd_source_reallocate(osm_gps_map_osd_t *osd) {
818        FIN;
819      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
820    
821      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
# Line 510  osd_source_reallocate(osm_gps_map_osd_t Line 856  osd_source_reallocate(osm_gps_map_osd_t
856          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
857    
858      osd_render_source_sel(osd, TRUE);      osd_render_source_sel(osd, TRUE);
859        FOUT;
860  }  }
861    
862  #define OSD_HZ      15  #define OSD_HZ      15
863  #define OSD_TIME    500  #define OSD_TIME    500
864    
865  static gboolean osd_source_animate(gpointer data) {  static gboolean osd_source_animate(gpointer data) {
866        FIN;
867      osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;      osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;
868      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
869      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
# Line 554  static gboolean osd_source_animate(gpoin Line 902  static gboolean osd_source_animate(gpoin
902      if(done)      if(done)
903          priv->source_sel.handler_id = 0;          priv->source_sel.handler_id = 0;
904    
905        FOUT;
906      return !done;      return !done;
907  }  }
908    
# Line 561  static gboolean osd_source_animate(gpoin Line 910  static gboolean osd_source_animate(gpoin
910  static void  static void
911  osd_source_toggle(osm_gps_map_osd_t *osd)  osd_source_toggle(osm_gps_map_osd_t *osd)
912  {  {
913        FIN;
914      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
915    
916      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
# Line 586  osd_source_toggle(osm_gps_map_osd_t *osd Line 936  osd_source_toggle(osm_gps_map_osd_t *osd
936      /* start timer to handle animation */      /* start timer to handle animation */
937      priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,      priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
938                                                    osd_source_animate, osd);                                                    osd_source_animate, osd);
939        FOUT;
940  }  }
941    
942  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
943  static osd_button_t  static osd_button_t
944  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) {
945        FIN;
946      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
947    
948      if(!priv->source_sel.expanded)      if(!priv->source_sel.expanded)
# Line 608  osd_source_check(osm_gps_map_osd_t *osd, Line 960  osd_source_check(osm_gps_map_osd_t *osd,
960          /* really within puller shape? */          /* really within puller shape? */
961          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)) {
962              /* expand source selector */              /* expand source selector */
963              osd_source_toggle(osd);              if(down)
964                    osd_source_toggle(osd);
965    
966              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
967              /* of the OSD */              /* of the OSD */
# Line 634  osd_source_check(osm_gps_map_osd_t *osd, Line 987  osd_source_check(osm_gps_map_osd_t *osd,
987              y /= step;              y /= step;
988              y += 1;              y += 1;
989    
990              gint old = 0;              if(down) {
991              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
992                    g_object_get(osd->widget, "map-source", &old, NULL);
993              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
994                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
995                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
996                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
997                        g_object_set(osd->widget, "map-source", y, NULL);
998                  osd_render_source_sel(osd, TRUE);  
999                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
1000                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
1001                    }
1002              }              }
1003    
1004              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
1005              /* processing by application */              /* processing by application */
1006              return OSD_BG;              return OSD_BG;
1007          }          }
1008      }      }
1009    
1010        FOUT;
1011      return OSD_NONE;      return OSD_NONE;
1012  }  }
1013  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
1014    
1015  static osd_button_t  static osd_button_t
1016  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) {
1017        FIN;
1018      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
1019    
1020    #ifdef OSD_BALLOON
1021        if(down) {
1022            /* needed to handle balloons that are created at click */
1023            osd_priv_t *priv = (osd_priv_t*)osd->priv;
1024            priv->balloon.just_created = FALSE;
1025        }
1026    #endif
1027    
1028  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1029      /* the source selection area is handles internally */      /* the source selection area is handles internally */
1030      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
1031  #endif  #endif
1032    
1033      x -= OSD_X;      if(but == OSD_NONE) {
1034      y -= OSD_Y;          gint mx = x - OSD_X;
1035            gint my = y - OSD_Y;
1036      if(OSD_X < 0)  
1037          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
1038                mx -= (osd->widget->allocation.width - OSD_W);
1039      if(OSD_Y < 0)  
1040          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
1041                my -= (osd->widget->allocation.height - OSD_H);
1042      /* first do a rough test for the OSD area. */  
1043      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
1044      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
1045            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
1046  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
1047          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
1048  #endif  #endif
1049            }
1050    
1051          if(but == OSD_NONE)          if(but == OSD_NONE)
1052              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
1053      }      }
1054    
1055    #ifdef OSD_BALLOON
1056        if(but == OSD_NONE) {
1057            /* check if user clicked into balloon */
1058            if(osd_balloon_check(osd, click, down, x, y))
1059                but = OSD_BG;
1060        }
1061    #endif
1062    
1063        FOUT;
1064      return but;      return but;
1065  }  }
1066    
# Line 763  osd_zoom_labels(cairo_t *cr, gint x, gin Line 1137  osd_zoom_labels(cairo_t *cr, gint x, gin
1137  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1138    
1139  #ifndef OSD_COORDINATES_FONT_SIZE  #ifndef OSD_COORDINATES_FONT_SIZE
1140  #define OSD_COORDINATES_FONT_SIZE 12  #define OSD_COORDINATES_FONT_SIZE (12.0)
1141  #endif  #endif
1142    
1143  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1144    
1145  #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)
1146  #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)
1147    
1148  /* these can be overwritten with versions that support */  /* these can be overwritten with versions that support */
1149  /* localization */  /* localization */
# Line 827  static char Line 1201  static char
1201                             c, (int)integral, fractional*60.0);                             c, (int)integral, fractional*60.0);
1202  }  }
1203    
1204    /* render a string at the given screen position */
1205    static int
1206    osd_render_centered_text(cairo_t *cr, int y, int width, char *text) {
1207        FIN;
1208    
1209        if(!text) return y;
1210    
1211        char *p = g_malloc(strlen(text)+4);  // space for "...\n"
1212        strcpy(p, text);
1213    
1214        cairo_text_extents_t extents;
1215        cairo_text_extents (cr, p, &extents);
1216        g_assert(extents.width != 0.0);
1217    
1218        /* check if text needs to be truncated */
1219        int trunc_at = strlen(text)-1;
1220        while(extents.width > width) {
1221            g_assert(trunc_at > 0);
1222    
1223            trunc_at--;
1224            strcpy(p+trunc_at, "...");
1225            cairo_text_extents (cr, p, &extents);
1226        }
1227    
1228        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1229        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1230        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1231        cairo_text_path (cr, p);
1232        cairo_stroke (cr);
1233    
1234        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1235        cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing);
1236        cairo_show_text (cr, p);
1237    
1238        g_free(p);
1239    
1240        /* skip + 1/5 line */
1241        FOUT;
1242        return y + 6*OSD_COORDINATES_FONT_SIZE/5;
1243    }
1244    
1245  static void  static void
1246  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1247  {  {
1248        FIN;
1249      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1250    
1251        if(!priv->coordinates.surface)
1252            return;
1253    
1254      /* get current map position */      /* get current map position */
1255      gfloat lat, lon;      gfloat lat, lon;
1256      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
# Line 847  osd_render_coordinates(osm_gps_map_osd_t Line 1266  osd_render_coordinates(osm_gps_map_osd_t
1266      priv->coordinates.lon = lon;      priv->coordinates.lon = lon;
1267    
1268      /* first fill with transparency */      /* first fill with transparency */
1269    
1270      cairo_t *cr = cairo_create(priv->coordinates.surface);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1271      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1272      //    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);
# Line 862  osd_render_coordinates(osm_gps_map_osd_t Line 1282  osd_render_coordinates(osm_gps_map_osd_t
1282      char *latitude = osd_latitude_str(lat);      char *latitude = osd_latitude_str(lat);
1283      char *longitude = osd_longitude_str(lon);      char *longitude = osd_longitude_str(lon);
1284    
1285      cairo_text_extents_t lat_extents, lon_extents;      int y = OSD_COORDINATES_OFFSET;
1286      cairo_text_extents (cr, latitude, &lat_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude);
1287      cairo_text_extents (cr, longitude, &lon_extents);      y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude);
1288    
1289        g_free(latitude);
1290        g_free(longitude);
1291    
1292      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_destroy(cr);
1293      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);      FOUT;
1294      cairo_move_to (cr,  }
1295                     (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);  
1296    
1297      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);  #ifdef OSD_NAV
1298      cairo_move_to (cr,  #define OSD_NAV_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1299                     (OSD_COORDINATES_W - lat_extents.width)/2,  #define OSD_NAV_H  (11*OSD_COORDINATES_FONT_SIZE)
1300                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
1301      cairo_show_text (cr, latitude);  /* http://mathforum.org/library/drmath/view/55417.html */
1302      cairo_move_to (cr,  static float get_bearing(float lat1, float lon1, float lat2, float lon2) {
1303                     (OSD_COORDINATES_W - lon_extents.width)/2,    return atan2( sin(lon2 - lon1) * cos(lat2),
1304                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +                  cos(lat1) * sin(lat2) -
1305                     OSD_COORDINATES_FONT_SIZE);                  sin(lat1) * cos(lat2) * cos(lon2 - lon1));
1306      cairo_show_text (cr, longitude);  }
1307    
1308    /* http://mathforum.org/library/drmath/view/51722.html */
1309    static float get_distance(float lat1, float lon1, float lat2, float lon2) {
1310      float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) +
1311                       sin(lat1) * sin(lat2));
1312    
1313      //  return(aob * 3959.0);   /* great circle radius in miles */
1314    
1315      return(aob * 6371000.0);     /* great circle radius in meters */
1316    }
1317    
1318    static void
1319    osd_render_nav(osm_gps_map_osd_t *osd)
1320    {
1321        FIN;
1322        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1323    
1324        if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon))
1325            return;
1326    
1327        /* first fill with transparency */
1328        cairo_t *cr = cairo_create(priv->nav.surface);
1329        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1330        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1331        cairo_paint(cr);
1332        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1333    
1334        cairo_select_font_face (cr, "Sans",
1335                                CAIRO_FONT_SLANT_NORMAL,
1336                                CAIRO_FONT_WEIGHT_BOLD);
1337        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1338    
1339        char *latitude = osd_latitude_str(priv->nav.lat);
1340        char *longitude = osd_longitude_str(priv->nav.lon);
1341    
1342        int y = OSD_COORDINATES_OFFSET;
1343        y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name);
1344        y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude);
1345        y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude);
1346    
1347      g_free(latitude);      g_free(latitude);
1348      g_free(longitude);      g_free(longitude);
1349    
1350        /* draw the compass */
1351        int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2;
1352        if(radius > OSD_NAV_W/2)
1353            radius = OSD_NAV_W/2;
1354    
1355        int x = OSD_NAV_W/2+1;
1356        y += radius;
1357    
1358        cairo_stroke (cr);
1359    
1360        /* draw background */
1361        cairo_arc(cr, x, y, radius, 0,  2*M_PI);
1362        cairo_set_source_rgba (cr, 1, 1, 1, 0.5);
1363        cairo_fill_preserve (cr);
1364        cairo_set_source_rgb (cr, 0, 0, 0);
1365        cairo_set_line_width (cr, 1);
1366        cairo_stroke (cr);
1367    
1368        /* draw pointer */
1369    #define ARROW_WIDTH     0.3
1370    #define ARROW_LENGTH    0.7
1371    
1372        coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget));
1373        if(gps) {
1374            float arot = get_bearing(gps->rlat, gps->rlon,
1375                         deg2rad(priv->nav.lat), deg2rad(priv->nav.lon));
1376    
1377            cairo_move_to(cr,
1378                          x + radius *  ARROW_LENGTH *  sin(arot),
1379                          y + radius *  ARROW_LENGTH * -cos(arot));
1380    
1381            cairo_line_to(cr,
1382                          x + radius * -ARROW_LENGTH *  sin(arot+ARROW_WIDTH),
1383                          y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH));
1384    
1385            cairo_line_to(cr,
1386                          x + radius * -0.5 * ARROW_LENGTH *  sin(arot),
1387                          y + radius * -0.5 * ARROW_LENGTH * -cos(arot));
1388    
1389            cairo_line_to(cr,
1390                          x + radius * -ARROW_LENGTH *  sin(arot-ARROW_WIDTH),
1391                          y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH));
1392    
1393            cairo_close_path(cr);
1394            cairo_set_source_rgb (cr, 0, 0, 0);
1395            cairo_fill (cr);
1396    
1397            y += radius + OSD_COORDINATES_FONT_SIZE/4;
1398    
1399            float dist = get_distance(gps->rlat, gps->rlon,
1400                            deg2rad(priv->nav.lat), deg2rad(priv->nav.lon));
1401    
1402            char *dist_str = NULL;
1403            if(!priv->nav.imperial) {
1404                /* metric is easy ... */
1405                if(dist<1000)
1406                    dist_str = g_strdup_printf("%u m", (int)dist);
1407                else
1408                    dist_str = g_strdup_printf("%.1f km", dist/1000);
1409            } else {
1410                /* and now the hard part: scale for useful imperial values :-( */
1411                /* try to convert to feet, 1ft == 0.3048 m */
1412    
1413                if(dist/(3*0.3048) >= 1760.0)      /* more than 1760 yard? */
1414                    dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0));
1415                else if(dist/0.3048 >= 100)        /* more than 100 feet? */
1416                    dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3));
1417                else
1418                    dist_str = g_strdup_printf("%.0f ft", dist/0.3048);
1419            }
1420    
1421            y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str);
1422            g_free(dist_str);
1423        }
1424    
1425      cairo_destroy(cr);      cairo_destroy(cr);
1426        FOUT;
1427  }  }
1428  #endif  // OSD_COORDINATES  
1429    void osm_gps_map_osd_clear_nav (OsmGpsMap *map) {
1430        FIN;
1431        g_return_if_fail (OSM_IS_GPS_MAP (map));
1432    
1433        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1434        g_return_if_fail (osd);
1435    
1436        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1437        g_return_if_fail (priv);
1438    
1439        if(priv->nav.surface) {
1440            cairo_surface_destroy(priv->nav.surface);
1441            priv->nav.surface = NULL;
1442            priv->nav.lat = OSM_GPS_MAP_INVALID;
1443            priv->nav.lon = OSM_GPS_MAP_INVALID;
1444            if(priv->nav.name) g_free(priv->nav.name);
1445        }
1446        osm_gps_map_redraw(map);
1447        FOUT;
1448    }
1449    
1450    void
1451    osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial,
1452                              float latitude, float longitude, char *name) {
1453        FIN;
1454        g_return_if_fail (OSM_IS_GPS_MAP (map));
1455    
1456        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1457        g_return_if_fail (osd);
1458    
1459        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1460        g_return_if_fail (priv);
1461    
1462        osm_gps_map_osd_clear_nav (map);
1463    
1464        /* allocate balloon surface */
1465        priv->nav.surface =
1466            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1467                                       OSD_NAV_W+2, OSD_NAV_H+2);
1468    
1469        priv->nav.lat = latitude;
1470        priv->nav.lon = longitude;
1471        priv->nav.name = g_strdup(name);
1472        priv->nav.imperial = imperial;
1473    
1474        osd_render_nav(osd);
1475    
1476        osm_gps_map_redraw(map);
1477        FOUT;
1478    }
1479    
1480    #endif // OSD_NAV
1481    
1482    
1483  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1484    
# Line 910  osd_render_coordinates(osm_gps_map_osd_t Line 1493  osd_render_coordinates(osm_gps_map_osd_t
1493    
1494  static void  static void
1495  osd_render_crosshair_shape(cairo_t *cr) {  osd_render_crosshair_shape(cairo_t *cr) {
1496        FIN;
1497      cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,      cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
1498                 OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);                 OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
1499    
# Line 928  osd_render_crosshair_shape(cairo_t *cr) Line 1512  osd_render_crosshair_shape(cairo_t *cr)
1512      cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);      cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
1513    
1514      cairo_stroke (cr);      cairo_stroke (cr);
1515        FOUT;
1516  }  }
1517    
1518  static void  static void
1519  osd_render_crosshair(osm_gps_map_osd_t *osd)  osd_render_crosshair(osm_gps_map_osd_t *osd)
1520  {  {
1521        FIN;
1522      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1523    
1524      if(priv->crosshair.rendered)      if(!priv->crosshair.surface || priv->crosshair.rendered)
1525          return;          return;
1526    
1527      priv->crosshair.rendered = TRUE;      priv->crosshair.rendered = TRUE;
# Line 958  osd_render_crosshair(osm_gps_map_osd_t * Line 1544  osd_render_crosshair(osm_gps_map_osd_t *
1544      osd_render_crosshair_shape(cr);      osd_render_crosshair_shape(cr);
1545    
1546      cairo_destroy(cr);      cairo_destroy(cr);
1547        FOUT;
1548  }  }
1549  #endif  #endif
1550    
1551  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1552    
1553  #ifndef OSD_SCALE_FONT_SIZE  #ifndef OSD_SCALE_FONT_SIZE
1554  #define OSD_SCALE_FONT_SIZE 12  #define OSD_SCALE_FONT_SIZE (12.0)
1555  #endif  #endif
1556  #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)  #define OSD_SCALE_W   (10*OSD_SCALE_FONT_SIZE)
1557  #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)  #define OSD_SCALE_H   (5*OSD_SCALE_FONT_SIZE/2)
# Line 979  osd_render_crosshair(osm_gps_map_osd_t * Line 1566  osd_render_crosshair(osm_gps_map_osd_t *
1566  static void  static void
1567  osd_render_scale(osm_gps_map_osd_t *osd)  osd_render_scale(osm_gps_map_osd_t *osd)
1568  {  {
1569        FIN;
1570      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1571    
1572        if(!priv->scale.surface)
1573            return;
1574    
1575      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
1576      gint zoom;      gint zoom;
1577      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
# Line 1102  osd_render_scale(osm_gps_map_osd_t *osd) Line 1693  osd_render_scale(osm_gps_map_osd_t *osd)
1693      cairo_stroke(cr);      cairo_stroke(cr);
1694    
1695      cairo_destroy(cr);      cairo_destroy(cr);
1696        FOUT;
1697  }  }
1698  #endif  #endif
1699    
1700  static void  static void
1701  osd_render_controls(osm_gps_map_osd_t *osd)  osd_render_controls(osm_gps_map_osd_t *osd)
1702  {  {
1703        FIN;
1704      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1705    
1706        if(!priv->controls.surface)
1707            return;
1708    
1709      if(priv->controls.rendered      if(priv->controls.rendered
1710  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1711         && (priv->controls.gps_enabled == (osd->cb != NULL))         && (priv->controls.gps_enabled == (osd->cb != NULL))
# Line 1224  osd_render(osm_gps_map_osd_t *osd) Line 1820  osd_render(osm_gps_map_osd_t *osd)
1820      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1821  #endif  #endif
1822    
1823    #ifdef OSD_NAV
1824        osd_render_nav(osd);
1825    #endif
1826    
1827  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1828      osd_render_coordinates(osd);      osd_render_coordinates(osd);
1829  #endif  #endif
# Line 1283  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1883  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1883      // now draw this onto the original context      // now draw this onto the original context
1884      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1885    
1886      int x, y;      gint x, y;
1887    
1888  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1889      x =  OSD_X;      x =  OSD_X;
# Line 1303  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1903  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1903      cairo_paint(cr);      cairo_paint(cr);
1904  #endif  #endif
1905    
1906    #ifdef OSD_NAV
1907        if(priv->nav.surface) {
1908            x =  OSD_X;
1909            if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1910            y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1911    
1912            cairo_set_source_surface(cr, priv->nav.surface, x, y);
1913            cairo_paint(cr);
1914        }
1915    #endif
1916    
1917  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1918      x = -OSD_X;      x = -OSD_X;
1919      y = -OSD_Y;      y = -OSD_Y;
# Line 1313  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1924  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1924      cairo_paint(cr);      cairo_paint(cr);
1925  #endif  #endif
1926    
1927    #ifdef OSD_BALLOON
1928        if(priv->balloon.surface) {
1929    
1930            /* convert given lat lon into screen coordinates */
1931            gint x, y;
1932            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1933                                          priv->balloon.lat, priv->balloon.lon,
1934                                          &x, &y);
1935    
1936            /* check if balloon needs to be rerendered */
1937            osd_render_balloon(osd);
1938    
1939            cairo_set_source_surface(cr, priv->balloon.surface,
1940                                     x + priv->balloon.offset_x,
1941                                     y + priv->balloon.offset_y);
1942            cairo_paint(cr);
1943        }
1944    #endif
1945    
1946      x = OSD_X;      x = OSD_X;
1947      if(x < 0)      if(x < 0)
1948          x += osd->widget->allocation.width - OSD_W;          x += osd->widget->allocation.width - OSD_W;
# Line 1347  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1977  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1977  #endif  #endif
1978    
1979      cairo_destroy(cr);      cairo_destroy(cr);
1980        FOUT;
1981  }  }
1982    
1983  static void  static void
1984  osd_free(osm_gps_map_osd_t *osd)  osd_free(osm_gps_map_osd_t *osd)
1985  {  {
1986        FIN;
1987      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1988    
1989      if (priv->controls.surface)      if (priv->controls.surface)
# Line 1375  osd_free(osm_gps_map_osd_t *osd) Line 2007  osd_free(osm_gps_map_osd_t *osd)
2007           cairo_surface_destroy(priv->crosshair.surface);           cairo_surface_destroy(priv->crosshair.surface);
2008  #endif  #endif
2009    
2010    #ifdef OSD_NAV
2011        if (priv->nav.surface)
2012             cairo_surface_destroy(priv->nav.surface);
2013    #endif
2014    
2015  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
2016      if (priv->coordinates.surface)      if (priv->coordinates.surface)
2017           cairo_surface_destroy(priv->coordinates.surface);           cairo_surface_destroy(priv->coordinates.surface);
2018  #endif  #endif
2019    
2020    #ifdef OSD_BALLOON
2021        if (priv->balloon.surface)
2022             cairo_surface_destroy(priv->balloon.surface);
2023    #endif
2024    
2025      g_free(priv);      g_free(priv);
2026        FOUT;
2027  }  }
2028    
2029  static gboolean  static gboolean
2030  osd_busy(osm_gps_map_osd_t *osd)  osd_busy(osm_gps_map_osd_t *osd)
2031  {  {
2032        FIN;
2033  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
2034      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
2035      return (priv->source_sel.handler_id != 0);      return (priv->source_sel.handler_id != 0);
# Line 1394  osd_busy(osm_gps_map_osd_t *osd) Line 2038  osd_busy(osm_gps_map_osd_t *osd)
2038  #endif  #endif
2039  }  }
2040    
2041    static osd_button_t
2042    osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
2043        FIN;
2044        return osd_check_int(osd, TRUE, down, x, y);
2045    }
2046    
2047  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
2048      .widget     = NULL,      .widget     = NULL,
2049    
# Line 1413  static osm_gps_map_osd_t osd_classic = { Line 2063  static osm_gps_map_osd_t osd_classic = {
2063  void  void
2064  osm_gps_map_osd_classic_init(OsmGpsMap *map)  osm_gps_map_osd_classic_init(OsmGpsMap *map)
2065  {  {
2066        FIN;
2067      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);
2068    
2069    #ifdef OSD_BALLOON
2070        priv->balloon.lat = OSM_GPS_MAP_INVALID;
2071        priv->balloon.lon = OSM_GPS_MAP_INVALID;
2072    #endif
2073    
2074      osd_classic.priv = priv;      osd_classic.priv = priv;
2075    
2076      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
2077        FOUT;
2078  }  }
2079    
2080  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
# Line 1425  osm_gps_map_osd_classic_init(OsmGpsMap * Line 2082  osm_gps_map_osd_classic_init(OsmGpsMap *
2082  /* but instead are to be used by the main application */  /* but instead are to be used by the main application */
2083  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
2084                                   gpointer data) {                                   gpointer data) {
2085        FIN;
2086      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
2087      g_return_if_fail (osd);      g_return_if_fail (osd);
2088    
# Line 1436  void osm_gps_map_osd_enable_gps (OsmGpsM Line 2094  void osm_gps_map_osd_enable_gps (OsmGpsM
2094      osd->render(osd);      osd->render(osd);
2095    
2096      osm_gps_map_redraw(map);      osm_gps_map_redraw(map);
2097        FOUT;
2098  }  }
2099  #endif  #endif
2100    
2101  osd_button_t  osd_button_t
2102  osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {  osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {
2103        FIN;
2104      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
2105      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
2106    
2107      return osd_check(osd, x, y);      return osd_check_int(osd, FALSE, TRUE, x, y);
2108  }  }

Legend:
Removed from v.111  
changed lines
  Added in v.150