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 123 by harbaum, Wed Sep 23 11:23:45 2009 UTC
# Line 32  Line 32 
32  #include <cairo.h>  #include <cairo.h>
33    
34  #include "osm-gps-map.h"  #include "osm-gps-map.h"
35    #include "converter.h"
36  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
37    
38  //the osd controls  //the osd controls
# Line 45  typedef struct { Line 46  typedef struct {
46  #endif  #endif
47      } controls;      } controls;
48    
49  #ifdef OSD_SCALE  #ifdef OSD_BALLOON
50      cairo_surface_t *scale;      //a balloon with additional info
51      int scale_zoom;      struct {
52            cairo_surface_t *surface;
53            int orientation, offset_x, offset_y;
54    
55            gboolean just_created;
56            float lat, lon;
57            OsmGpsMapRect_t rect;
58    
59            /* function called to have the user app draw the contents */
60            OsmGpsMapBalloonCallback cb;
61            gpointer data;
62        } balloon;
63  #endif  #endif
64    
65    #ifdef OSD_SCALE
66        struct {
67            cairo_surface_t *surface;
68            int zoom;
69        } scale;
70    #endif
71    
72  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
73      cairo_surface_t *crosshair;      struct {
74            cairo_surface_t *surface;
75            gboolean rendered;
76        } crosshair;
77    #endif
78    
79    #ifdef OSD_NAV
80        struct {
81            cairo_surface_t *surface;
82            float lat, lon;
83            char *name;
84        } nav;
85  #endif  #endif
86    
87  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
88      cairo_surface_t *coordinates;      struct {
89      float coo_lat, coo_lon;          cairo_surface_t *surface;
90            float lat, lon;
91        } coordinates;
92  #endif  #endif
93    
94  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
95      /* values to handle the "source" menu */      struct {
96      cairo_surface_t *map_source;          /* values to handle the "source" menu */
97      gboolean expanded;          cairo_surface_t *surface;
98      gint shift, dir, count;          gboolean expanded;
99      gint handler_id;          gint shift, dir, count;
100      gint width, height;          gint handler_id;
101            gint width, height;
102            gboolean rendered;
103        } source_sel;
104  #endif  #endif
105    
106  } osd_priv_t;  } osd_priv_t;
107    
108    #ifdef OSD_BALLOON
109    /* most visual effects are hardcoded by now, but may be made */
110    /* available via properties later */
111    #ifndef BALLOON_AREA_WIDTH
112    #define BALLOON_AREA_WIDTH           290
113    #endif
114    #ifndef BALLOON_AREA_HEIGHT
115    #define BALLOON_AREA_HEIGHT           75
116    #endif
117    #ifndef BALLOON_CORNER_RADIUS
118    #define BALLOON_CORNER_RADIUS         10
119    #endif
120    
121    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
122    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
123    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
124    #define BALLOON_TRANSPARENCY         0.8
125    #define POINTER_HEIGHT                20
126    #define POINTER_FOOT_WIDTH            20
127    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
128    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
129    #define BALLOON_SHADOW_TRANSPARENCY  0.2
130    
131    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
132    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
133    
134    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
135    
136    
137    /* draw the bubble shape. this is used twice, once for the shape and once */
138    /* for the shadow */
139    static void
140    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
141           gboolean bottom, int px, int py, int px0, int px1) {
142    
143        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
144        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
145                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
146        if(!bottom) {
147            /* insert top pointer */
148            cairo_line_to (cr, px1, y0);
149            cairo_line_to (cr, px, py);
150            cairo_line_to (cr, px0, y0);
151        }
152    
153        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
154        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
155                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
156        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
157        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
158                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
159        if(bottom) {
160            /* insert bottom pointer */
161            cairo_line_to (cr, px0, y1);
162            cairo_line_to (cr, px, py);
163            cairo_line_to (cr, px1, y1);
164        }
165    
166        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
167        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
168                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
169    
170        cairo_close_path (cr);
171    }
172    
173    static void
174    osd_render_balloon(osm_gps_map_osd_t *osd) {
175        osd_priv_t *priv = (osd_priv_t*)osd->priv;
176    
177        /* get zoom */
178        gint zoom;
179        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
180    
181        /* ------- convert given coordinate into screen position --------- */
182        gint xs, ys;
183        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
184                                          priv->balloon.lat, priv->balloon.lon,
185                                          &xs, &ys);
186    
187        gint x0 = 1, y0 = 1;
188    
189        /* check position of this relative to screen center to determine */
190        /* pointer direction ... */
191        int pointer_x, pointer_x0, pointer_x1;
192        int pointer_y;
193    
194        /* ... and calculate position */
195        int orientation = 0;
196        if(xs > osd->widget->allocation.width/2) {
197            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
198            pointer_x = x0 - priv->balloon.offset_x;
199            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
200            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
201            orientation |= 1;
202        } else {
203            priv->balloon.offset_x = -POINTER_OFFSET;
204            pointer_x = x0 - priv->balloon.offset_x;
205            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
206            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
207        }
208    
209        gboolean bottom = FALSE;
210        if(ys > osd->widget->allocation.height/2) {
211            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
212            pointer_y = y0 - priv->balloon.offset_y;
213            bottom = TRUE;
214            orientation |= 2;
215        } else {
216            priv->balloon.offset_y = 0;
217            pointer_y = y0 - priv->balloon.offset_y;
218            y0 += POINTER_HEIGHT;
219        }
220    
221        /* if required orientation equals current one, then don't render */
222        /* anything */
223        if(orientation == priv->balloon.orientation)
224            return;
225    
226        priv->balloon.orientation = orientation;
227    
228        /* calculate bottom/right of box */
229        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
230    
231        /* save balloon screen coordinates for later use */
232        priv->balloon.rect.x = x0 + BALLOON_BORDER;
233        priv->balloon.rect.y = y0 + BALLOON_BORDER;
234        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
235        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
236    
237        cairo_t *cr = cairo_create(priv->balloon.surface);
238        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
239        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
240        cairo_paint(cr);
241        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
242    
243        /* --------- draw shadow --------------- */
244        osm_gps_map_draw_balloon_shape (cr,
245                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
246                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
247                     bottom, pointer_x, pointer_y,
248                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
249    
250        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
251        cairo_fill_preserve (cr);
252        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
253        cairo_set_line_width (cr, 0);
254        cairo_stroke (cr);
255    
256        /* --------- draw main shape ----------- */
257        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
258                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
259    
260        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
261        cairo_fill_preserve (cr);
262        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
263        cairo_set_line_width (cr, 1);
264        cairo_stroke (cr);
265    
266        if (priv->balloon.cb) {
267            /* clip in case application tries to draw in */
268                /* exceed of the balloon */
269            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
270                             priv->balloon.rect.w, priv->balloon.rect.h);
271            cairo_clip (cr);
272            cairo_new_path (cr);  /* current path is not
273                                     consumed by cairo_clip() */
274    
275            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
276        }
277    
278        cairo_destroy(cr);
279    }
280    
281    /* return true if balloon is being displayed and if */
282    /* the given coordinate is within this balloon */
283    static gboolean
284    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
285    {
286        osd_priv_t *priv = (osd_priv_t*)osd->priv;
287    
288        if(!priv->balloon.surface)
289            return FALSE;
290    
291        gint xs, ys;
292        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
293                                          priv->balloon.lat, priv->balloon.lon,
294                                          &xs, &ys);
295    
296        xs += priv->balloon.rect.x + priv->balloon.offset_x;
297        ys += priv->balloon.rect.y + priv->balloon.offset_y;
298    
299        gboolean is_in =
300            (x > xs) && (x < xs + priv->balloon.rect.w) &&
301            (y > ys) && (y < ys + priv->balloon.rect.h);
302    
303        /* handle the fact that the balloon may have been created by the */
304        /* button down event */
305        if(!is_in && !down && !priv->balloon.just_created) {
306            /* the user actually clicked outside the balloon */
307    
308            /* close the balloon! */
309            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
310        }
311    
312        return is_in;
313    }
314    
315    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
316        g_return_if_fail (OSM_IS_GPS_MAP (map));
317    
318        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
319        g_return_if_fail (osd);
320    
321        osd_priv_t *priv = (osd_priv_t*)osd->priv;
322        g_return_if_fail (priv);
323    
324        if(priv->balloon.surface) {
325            cairo_surface_destroy(priv->balloon.surface);
326            priv->balloon.surface = NULL;
327            priv->balloon.lat = OSM_GPS_MAP_INVALID;
328            priv->balloon.lon = OSM_GPS_MAP_INVALID;
329        }
330        osm_gps_map_redraw(map);
331    }
332    
333    void
334    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
335                                  OsmGpsMapBalloonCallback cb, gpointer data) {
336        g_return_if_fail (OSM_IS_GPS_MAP (map));
337    
338        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
339        g_return_if_fail (osd);
340    
341        osd_priv_t *priv = (osd_priv_t*)osd->priv;
342        g_return_if_fail (priv);
343    
344        osm_gps_map_osd_clear_balloon (map);
345    
346        /* allocate balloon surface */
347        priv->balloon.surface =
348            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
349                                       BALLOON_W+2, BALLOON_H+2);
350    
351        priv->balloon.lat = latitude;
352        priv->balloon.lon = longitude;
353        priv->balloon.cb = cb;
354        priv->balloon.data = data;
355        priv->balloon.just_created = TRUE;
356    
357        priv->balloon.orientation = -1;
358    
359        osd_render_balloon(osd);
360    
361        osm_gps_map_redraw(map);
362    }
363    
364    #endif // OSD_BALLOON
365    
366  /* position and extent of bounding box */  /* position and extent of bounding box */
367  #ifndef OSD_X  #ifndef OSD_X
368  #define OSD_X      (10)  #define OSD_X      (10)
# Line 292  osd_check_zoom(gint x, gint y) { Line 585  osd_check_zoom(gint x, gint y) {
585  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
586    
587  /* size of usable area when expanded */  /* size of usable area when expanded */
588  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
589  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
590  #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)
591  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
592    
# Line 309  osd_check_zoom(gint x, gint y) { Line 602  osd_check_zoom(gint x, gint y) {
602  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
603  static void  static void
604  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) {
605      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
606          /* just draw the puller */          /* just draw the puller */
607          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
608          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);          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 630  osd_source_content(osm_gps_map_osd_t *os
630    
631      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
632    
633      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
634          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
635          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);
636          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 655  osd_source_content(osm_gps_map_osd_t *os
655                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
656              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
657    
658              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
659                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
660              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++) {
661                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 376  osd_source_content(osm_gps_map_osd_t *os Line 669  osd_source_content(osm_gps_map_osd_t *os
669                  if(source == i) {                  if(source == i) {
670                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
671                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
672                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
673                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
674                      cairo_fill(cr);                      cairo_fill(cr);
675    
# Line 407  osd_source_content(osm_gps_map_osd_t *os Line 700  osd_source_content(osm_gps_map_osd_t *os
700  }  }
701    
702  static void  static void
703  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
704      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
705    
706        if(priv->source_sel.rendered && !force_rerender)
707            return;
708    
709        priv->source_sel.rendered = TRUE;
710    
711  #ifndef OSD_COLOR  #ifndef OSD_COLOR
712      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
713      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 715  osd_render_source_sel(osm_gps_map_osd_t
715  #endif  #endif
716    
717      /* draw source selector */      /* draw source selector */
718      cairo_t *cr = cairo_create(priv->map_source);      cairo_t *cr = cairo_create(priv->source_sel.surface);
719      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
720      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);
721      cairo_paint(cr);      cairo_paint(cr);
# Line 458  osd_source_reallocate(osm_gps_map_osd_t Line 756  osd_source_reallocate(osm_gps_map_osd_t
756      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
757    
758      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
759      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
760    
761      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
762      if(priv->expanded) {      if(priv->source_sel.expanded) {
763          cairo_text_extents_t extents;          cairo_text_extents_t extents;
764    
765          /* determine content size */          /* determine content size */
766          cairo_t *cr = cairo_create(priv->map_source);          cairo_t *cr = cairo_create(priv->source_sel.surface);
767          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
768                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
769                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 482  osd_source_reallocate(osm_gps_map_osd_t Line 780  osd_source_reallocate(osm_gps_map_osd_t
780          }          }
781          cairo_destroy(cr);          cairo_destroy(cr);
782    
783          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
784          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
785              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
786    
787          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
788          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
789      }      }
790    
791      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
792      priv->map_source =      priv->source_sel.surface =
793          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
794    
795      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
796  }  }
797    
798  #define OSD_HZ      15  #define OSD_HZ      15
# Line 505  static gboolean osd_source_animate(gpoin Line 803  static gboolean osd_source_animate(gpoin
803      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
804      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
805      gboolean done = FALSE;      gboolean done = FALSE;
806      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
807    
808      /* shifting in */      /* shifting in */
809      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
810          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
811              priv->count = 0;              priv->source_sel.count = 0;
812              done = TRUE;              done = TRUE;
813          }          }
814      } else {      } else {
815          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
816              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
817              osd_source_reallocate(osd);              osd_source_reallocate(osd);
818    
819              priv->count = 1000;              priv->source_sel.count = 1000;
820              done = TRUE;              done = TRUE;
821          }          }
822      }      }
# Line 526  static gboolean osd_source_animate(gpoin Line 824  static gboolean osd_source_animate(gpoin
824    
825      /* 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 */
826    
827      /* nicer sinoid mapping */      /* nice sinoid mapping */
828      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;
829      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
830            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
831          m * diff;          m * diff;
832    
833        /* make sure the screen is updated */
834      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
835    
836        /* stop animation if done */
837      if(done)      if(done)
838          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
839    
840      return !done;      return !done;
841  }  }
# Line 546  osd_source_toggle(osm_gps_map_osd_t *osd Line 847  osd_source_toggle(osm_gps_map_osd_t *osd
847      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
848    
849      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
850      if(priv->handler_id)      if(priv->source_sel.handler_id)
851          return;          return;
852    
853      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
854      if(!priv->expanded) {      /* collapse animation */
855          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
856            priv->source_sel.expanded = TRUE;
857          osd_source_reallocate(osd);          osd_source_reallocate(osd);
858    
859          priv->count = 1000;          priv->source_sel.count = 1000;
860          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
861          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
862      } else {      } else {
863          priv->count =  0;          priv->source_sel.count =  0;
864          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
865          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
866            priv->source_sel.dir = +1000/OSD_HZ;
867      }      }
868    
869      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
870        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
871                                                      osd_source_animate, osd);
872  }  }
873    
874  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
875  static osd_button_t  static osd_button_t
876  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) {
877      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
878    
879      if(!priv->expanded)      if(!priv->source_sel.expanded)
880          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
881      else      else
882          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 891  osd_source_check(osm_gps_map_osd_t *osd,
891          /* really within puller shape? */          /* really within puller shape? */
892          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)) {
893              /* expand source selector */              /* expand source selector */
894              osd_source_toggle(osd);              if(down)
895                    osd_source_toggle(osd);
896    
897              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
898              /* of the OSD */              /* of the OSD */
# Line 595  osd_source_check(osm_gps_map_osd_t *osd, Line 901  osd_source_check(osm_gps_map_osd_t *osd,
901      }      }
902    
903      /* check for clicks into data area */      /* check for clicks into data area */
904      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
905          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
906          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
907              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 911  osd_source_check(osm_gps_map_osd_t *osd,
911             y > 0 &&             y > 0 &&
912             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
913    
914              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
915                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
916    
917              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
918              y /= step;              y /= step;
919              y += 1;              y += 1;
920    
921              gint old = 0;              if(down) {
922              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
923                    g_object_get(osd->widget, "map-source", &old, NULL);
924              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
925                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
926                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
927                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
928                        g_object_set(osd->widget, "map-source", y, NULL);
929                  osd_render_source_sel(osd);  
930                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
931                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
932                    }
933              }              }
934    
935              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
# Line 635  osd_source_check(osm_gps_map_osd_t *osd, Line 943  osd_source_check(osm_gps_map_osd_t *osd,
943  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
944    
945  static osd_button_t  static osd_button_t
946  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
947      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
948    
949    #ifdef OSD_BALLOON
950        if(down) {
951            /* needed to handle balloons that are created at click */
952            osd_priv_t *priv = (osd_priv_t*)osd->priv;
953            priv->balloon.just_created = FALSE;
954        }
955    #endif
956    
957  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
958      /* the source selection area is handles internally */      /* the source selection area is handles internally */
959      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
960  #endif  #endif
961    
962      x -= OSD_X;      if(but == OSD_NONE) {
963      y -= OSD_Y;          gint mx = x - OSD_X;
964            gint my = y - OSD_Y;
965      if(OSD_X < 0)  
966          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
967                mx -= (osd->widget->allocation.width - OSD_W);
968      if(OSD_Y < 0)  
969          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
970                my -= (osd->widget->allocation.height - OSD_H);
971      /* first do a rough test for the OSD area. */  
972      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
973      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
974            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
975  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
976          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
977  #endif  #endif
978            }
979    
980          if(but == OSD_NONE)          if(but == OSD_NONE)
981              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
982      }      }
983    
984    #ifdef OSD_BALLOON
985        if(but == OSD_NONE) {
986            /* check if user clicked into balloon */
987            if(osd_balloon_check(osd, down, x, y))
988                but = OSD_BG;
989        }
990    #endif
991    
992      return but;      return but;
993  }  }
994    
# Line 806  static char Line 1130  static char
1130  }  }
1131    
1132  static void  static void
1133    osd_render_text(cairo_t *cr, int x, int y, char *text) {
1134        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1135        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1136        cairo_move_to (cr, x, y);
1137        cairo_text_path (cr, text);
1138        cairo_stroke (cr);
1139    
1140        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1141        cairo_move_to (cr, x, y);
1142        cairo_show_text (cr, text);
1143    }
1144    
1145    static void
1146  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1147  {  {
1148      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
# Line 815  osd_render_coordinates(osm_gps_map_osd_t Line 1152  osd_render_coordinates(osm_gps_map_osd_t
1152      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1153    
1154      /* check if position has changed enough to require redraw */      /* check if position has changed enough to require redraw */
1155      if(!isnan(priv->coo_lat) && !isnan(priv->coo_lon))      if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1156          if((fabsf(lat - priv->coo_lat) < 1/60000) &&     /* 1/60000 == 1/1000 minute */          /* 1/60000 == 1/1000 minute */
1157             (fabsf(lon - priv->coo_lon) < 1/60000))          if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1158               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1159              return;              return;
1160    
1161      priv->coo_lat = lat;      priv->coordinates.lat = lat;
1162      priv->coo_lon = lon;      priv->coordinates.lon = lon;
1163    
1164      /* first fill with light transparency */      /* first fill with transparency */
1165      cairo_t *cr = cairo_create(priv->coordinates);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1166      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1167      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);
1168        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1169      cairo_paint(cr);      cairo_paint(cr);
1170      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1171    
# Line 841  osd_render_coordinates(osm_gps_map_osd_t Line 1180  osd_render_coordinates(osm_gps_map_osd_t
1180      cairo_text_extents_t lat_extents, lon_extents;      cairo_text_extents_t lat_extents, lon_extents;
1181      cairo_text_extents (cr, latitude, &lat_extents);      cairo_text_extents (cr, latitude, &lat_extents);
1182      cairo_text_extents (cr, longitude, &lon_extents);      cairo_text_extents (cr, longitude, &lon_extents);
1183    
1184        osd_render_text(cr,
1185                        (OSD_COORDINATES_W - lat_extents.width)/2,
1186                        OSD_COORDINATES_OFFSET - lat_extents.y_bearing,
1187                        latitude);
1188    
1189        osd_render_text(cr,
1190                        (OSD_COORDINATES_W - lon_extents.width)/2,
1191                        OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1192                        OSD_COORDINATES_FONT_SIZE,
1193                        longitude);
1194    
1195        g_free(latitude);
1196        g_free(longitude);
1197    
1198      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_destroy(cr);
1199      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);  }
1200      cairo_move_to (cr,  #endif  // OSD_COORDINATES
                    (OSD_COORDINATES_W - lat_extents.width)/2,  
                    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);  
1201    
1202      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);  #ifdef OSD_NAV
1203      cairo_move_to (cr,  #define OSD_NAV_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1204                     (OSD_COORDINATES_W - lat_extents.width)/2,  #define OSD_NAV_H  (100)
                    OSD_COORDINATES_OFFSET - lat_extents.y_bearing);  
     cairo_show_text (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_show_text (cr, longitude);  
1205    
1206    static void
1207    osd_render_nav(osm_gps_map_osd_t *osd)
1208    {
1209        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1210    
1211        if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon))
1212            return;
1213    
1214        /* first fill with transparency */
1215        cairo_t *cr = cairo_create(priv->nav.surface);
1216        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1217        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1218        cairo_paint(cr);
1219        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1220    
1221        cairo_select_font_face (cr, "Sans",
1222                                CAIRO_FONT_SLANT_NORMAL,
1223                                CAIRO_FONT_WEIGHT_BOLD);
1224        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
1225    
1226        char *latitude = osd_latitude_str(priv->nav.lat);
1227        char *longitude = osd_longitude_str(priv->nav.lon);
1228    
1229        cairo_text_extents_t lat_extents, lon_extents, name_extents;
1230        cairo_text_extents (cr, priv->nav.name, &name_extents);
1231        cairo_text_extents (cr, latitude, &lat_extents);
1232        cairo_text_extents (cr, longitude, &lon_extents);
1233    
1234        osd_render_text(cr,
1235                        (OSD_NAV_W - name_extents.width)/2,
1236                        OSD_COORDINATES_OFFSET - name_extents.y_bearing,
1237                        priv->nav.name);
1238    
1239        osd_render_text(cr,
1240                        (OSD_NAV_W - lat_extents.width)/2,
1241                        OSD_COORDINATES_OFFSET - lat_extents.y_bearing +
1242                        OSD_COORDINATES_FONT_SIZE,
1243                        latitude);
1244    
1245        osd_render_text(cr,
1246                        (OSD_NAV_W - lon_extents.width)/2,
1247                        OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1248                        2 * OSD_COORDINATES_FONT_SIZE,
1249                        longitude);
1250    
1251      g_free(latitude);      g_free(latitude);
1252      g_free(longitude);      g_free(longitude);
1253    
1254      cairo_destroy(cr);      cairo_destroy(cr);
1255  }  }
1256  #endif  // OSD_COORDINATES  
1257    void osm_gps_map_osd_clear_nav (OsmGpsMap *map) {
1258        g_return_if_fail (OSM_IS_GPS_MAP (map));
1259    
1260        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1261        g_return_if_fail (osd);
1262    
1263        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1264        g_return_if_fail (priv);
1265    
1266        if(priv->nav.surface) {
1267            cairo_surface_destroy(priv->nav.surface);
1268            priv->nav.surface = NULL;
1269            priv->nav.lat = OSM_GPS_MAP_INVALID;
1270            priv->nav.lon = OSM_GPS_MAP_INVALID;
1271            if(priv->nav.name) g_free(priv->nav.name);
1272        }
1273        osm_gps_map_redraw(map);
1274    }
1275    
1276    void
1277    osm_gps_map_osd_draw_nav (OsmGpsMap *map, float latitude, float longitude,
1278                              char *name) {
1279        g_return_if_fail (OSM_IS_GPS_MAP (map));
1280    
1281        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1282        g_return_if_fail (osd);
1283    
1284        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1285        g_return_if_fail (priv);
1286    
1287        osm_gps_map_osd_clear_nav (map);
1288    
1289        /* allocate balloon surface */
1290        priv->nav.surface =
1291            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1292                                       OSD_NAV_W+2, OSD_NAV_H+2);
1293    
1294        priv->nav.lat = latitude;
1295        priv->nav.lon = longitude;
1296        priv->nav.name = g_strdup(name);
1297    
1298        osd_render_nav(osd);
1299    
1300        osm_gps_map_redraw(map);
1301    }
1302    
1303    #endif // OSD_NAV
1304    
1305    
1306  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1307    
# Line 911  osd_render_crosshair(osm_gps_map_osd_t * Line 1341  osd_render_crosshair(osm_gps_map_osd_t *
1341  {  {
1342      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1343    
1344        if(priv->crosshair.rendered)
1345            return;
1346    
1347        priv->crosshair.rendered = TRUE;
1348    
1349      /* first fill with transparency */      /* first fill with transparency */
1350      cairo_t *cr = cairo_create(priv->crosshair);      cairo_t *cr = cairo_create(priv->crosshair.surface);
1351      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1352      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);  
1353      cairo_paint(cr);      cairo_paint(cr);
1354      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1355    
# Line 956  osd_render_scale(osm_gps_map_osd_t *osd) Line 1390  osd_render_scale(osm_gps_map_osd_t *osd)
1390      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
1391      gint zoom;      gint zoom;
1392      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1393      if(zoom == priv->scale_zoom)      if(zoom == priv->scale.zoom)
1394          return;          return;
1395    
1396      priv->scale_zoom = zoom;      priv->scale.zoom = zoom;
1397    
1398      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));
1399    
1400      /* first fill with transparency */      /* first fill with transparency */
1401      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale.surface);
1402      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1403      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);
1404      // 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 1092  osd_render_controls(osm_gps_map_osd_t *o Line 1526  osd_render_controls(osm_gps_map_osd_t *o
1526  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1527      priv->controls.gps_enabled = (osd->cb != NULL);      priv->controls.gps_enabled = (osd->cb != NULL);
1528  #endif  #endif
1529        priv->controls.rendered = TRUE;
1530    
1531  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1532      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
# Line 1176  osd_render_controls(osm_gps_map_osd_t *o Line 1611  osd_render_controls(osm_gps_map_osd_t *o
1611  static void  static void
1612  osd_render(osm_gps_map_osd_t *osd)  osd_render(osm_gps_map_osd_t *osd)
1613  {  {
1614        /* this function is actually called pretty often since the */
1615        /* OSD contents may have changed (due to a coordinate/zoom change). */
1616        /* The different OSD parts have to make sure that they don't */
1617        /* render unneccessarily often and thus waste CPU power */
1618    
1619      osd_render_controls(osd);      osd_render_controls(osd);
1620    
1621  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1622      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1623  #endif  #endif
1624    
1625  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1190  osd_render(osm_gps_map_osd_t *osd) Line 1630  osd_render(osm_gps_map_osd_t *osd)
1630      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1631  #endif  #endif
1632    
1633    #ifdef OSD_NAV
1634        osd_render_nav(osd);
1635    #endif
1636    
1637  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1638      osd_render_coordinates(osd);      osd_render_coordinates(osd);
1639  #endif  #endif
# Line 1214  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1658  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1658    
1659  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1660          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1661          priv->map_source =          priv->source_sel.surface =
1662              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1663                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1664            priv->source_sel.rendered = FALSE;
1665  #endif  #endif
1666    
1667  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1668          priv->scale =          priv->scale.surface =
1669              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1670                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W, OSD_SCALE_H);
1671          priv->scale_zoom = -1;          priv->scale.zoom = -1;
1672  #endif  #endif
1673    
1674  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1675          priv->crosshair =          priv->crosshair.surface =
1676              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1677                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1678            priv->crosshair.rendered = FALSE;
1679  #endif  #endif
1680    
1681  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1682          priv->coordinates =          priv->coordinates.surface =
1683              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1684                                         OSD_COORDINATES_W, OSD_COORDINATES_H);                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1685    
1686          priv->coo_lat = priv->coo_lon = OSM_GPS_MAP_INVALID;          priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1687  #endif  #endif
1688    
1689          /* ... and render it */          /* ... and render it */
# Line 1247  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1693  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1693      // now draw this onto the original context      // now draw this onto the original context
1694      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1695    
1696      int x, y;      gint x, y;
1697    
1698  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1699      x =  OSD_X;      x =  OSD_X;
# Line 1255  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1701  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1701      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1702      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1703    
1704      cairo_set_source_surface(cr, priv->scale, x, y);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1705      cairo_paint(cr);      cairo_paint(cr);
1706  #endif  #endif
1707    
# Line 1263  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1709  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1709      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1710      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1711    
1712      cairo_set_source_surface(cr, priv->crosshair, x, y);      cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1713      cairo_paint(cr);      cairo_paint(cr);
1714  #endif  #endif
1715    
1716    #ifdef OSD_NAV
1717        if(priv->nav.surface) {
1718            x =  OSD_X;
1719            if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1720            y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1721    
1722            cairo_set_source_surface(cr, priv->nav.surface, x, y);
1723            cairo_paint(cr);
1724        }
1725    #endif
1726    
1727  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1728      x = -OSD_X;      x = -OSD_X;
1729      y = -OSD_Y;      y = -OSD_Y;
1730      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1731      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1732    
1733      cairo_set_source_surface(cr, priv->coordinates, x, y);      cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1734      cairo_paint(cr);      cairo_paint(cr);
1735  #endif  #endif
1736    
1737    #ifdef OSD_BALLOON
1738        if(priv->balloon.surface) {
1739    
1740            /* convert given lat lon into screen coordinates */
1741            gint x, y;
1742            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1743                                          priv->balloon.lat, priv->balloon.lon,
1744                                          &x, &y);
1745    
1746            /* check if balloon needs to be rerendered */
1747            osd_render_balloon(osd);
1748    
1749            cairo_set_source_surface(cr, priv->balloon.surface,
1750                                     x + priv->balloon.offset_x,
1751                                     y + priv->balloon.offset_y);
1752            cairo_paint(cr);
1753        }
1754    #endif
1755    
1756      x = OSD_X;      x = OSD_X;
1757      if(x < 0)      if(x < 0)
1758          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 1765  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1765      cairo_paint(cr);      cairo_paint(cr);
1766    
1767  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1768      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
1769          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
1770          if(!priv->expanded)          if(!priv->source_sel.expanded)
1771              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
1772          else          else
1773              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1774      } else      } else
1775          x = priv->shift;          x = priv->source_sel.shift;
1776    
1777      y = OSD_S_Y;      y = OSD_S_Y;
1778      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
1779          if(!priv->expanded)          if(!priv->source_sel.expanded)
1780              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1781          else          else
1782              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1783      }      }
1784    
1785      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
1786      cairo_paint(cr);      cairo_paint(cr);
1787  #endif  #endif
1788    
# Line 1322  osd_free(osm_gps_map_osd_t *osd) Line 1798  osd_free(osm_gps_map_osd_t *osd)
1798           cairo_surface_destroy(priv->controls.surface);           cairo_surface_destroy(priv->controls.surface);
1799    
1800  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1801      if(priv->handler_id)      if(priv->source_sel.handler_id)
1802          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
1803    
1804      if (priv->map_source)      if (priv->source_sel.surface)
1805           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
1806  #endif  #endif
1807    
1808  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1809      if (priv->scale)      if (priv->scale.surface)
1810           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
1811  #endif  #endif
1812    
1813  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1814      if (priv->crosshair)      if (priv->crosshair.surface)
1815           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair.surface);
1816    #endif
1817    
1818    #ifdef OSD_NAV
1819        if (priv->nav.surface)
1820             cairo_surface_destroy(priv->nav.surface);
1821  #endif  #endif
1822    
1823  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1824      if (priv->coordinates)      if (priv->coordinates.surface)
1825           cairo_surface_destroy(priv->coordinates);           cairo_surface_destroy(priv->coordinates.surface);
1826    #endif
1827    
1828    #ifdef OSD_BALLOON
1829        if (priv->balloon.surface)
1830             cairo_surface_destroy(priv->balloon.surface);
1831  #endif  #endif
1832    
1833      g_free(priv);      g_free(priv);
# Line 1352  osd_busy(osm_gps_map_osd_t *osd) Line 1838  osd_busy(osm_gps_map_osd_t *osd)
1838  {  {
1839  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1840      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1841      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
1842  #else  #else
1843      return FALSE;      return FALSE;
1844  #endif  #endif
# Line 1379  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1865  osm_gps_map_osd_classic_init(OsmGpsMap *
1865  {  {
1866      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);
1867    
1868    #ifdef OSD_BALLOON
1869        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1870        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1871    #endif
1872    
1873      osd_classic.priv = priv;      osd_classic.priv = priv;
1874    
1875      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
# Line 1408  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1899  osm_gps_map_osd_check(OsmGpsMap *map, gi
1899      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1900      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1901    
1902      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1903  }  }

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