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

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

revision 107 by harbaum, Fri Sep 11 12:16:50 2009 UTC revision 120 by harbaum, Sat Sep 19 19:19:42 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
39  typedef struct {  typedef struct {
40      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
41      cairo_surface_t *overlay;      struct {
42            cairo_surface_t *surface;
43            gboolean rendered;
44    #ifdef OSD_GPS_BUTTON
45            gboolean gps_enabled;
46    #endif
47        } controls;
48    
49  #ifdef OSD_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  #endif
78    
79  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
80      cairo_surface_t *coordinates;      struct {
81            cairo_surface_t *surface;
82            float lat, lon;
83        } coordinates;
84  #endif  #endif
85    
86  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
87      /* values to handle the "source" menu */      struct {
88      cairo_surface_t *map_source;          /* values to handle the "source" menu */
89      gboolean expanded;          cairo_surface_t *surface;
90      gint shift, dir, count;          gboolean expanded;
91      gint handler_id;          gint shift, dir, count;
92      gint width, height;          gint handler_id;
93            gint width, height;
94            gboolean rendered;
95        } source_sel;
96  #endif  #endif
97    
98  } osd_priv_t;  } osd_priv_t;
99    
100    #ifdef OSD_BALLOON
101    /* most visual effects are hardcoded by now, but may be made */
102    /* available via properties later */
103    #ifndef BALLOON_AREA_WIDTH
104    #define BALLOON_AREA_WIDTH           290
105    #endif
106    #ifndef BALLOON_AREA_HEIGHT
107    #define BALLOON_AREA_HEIGHT           75
108    #endif
109    #ifndef BALLOON_CORNER_RADIUS
110    #define BALLOON_CORNER_RADIUS         10
111    #endif
112    
113    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
114    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
115    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
116    #define BALLOON_TRANSPARENCY         0.8
117    #define POINTER_HEIGHT                20
118    #define POINTER_FOOT_WIDTH            20
119    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
120    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
121    #define BALLOON_SHADOW_TRANSPARENCY  0.2
122    
123    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
124    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
125    
126    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
127    
128    
129    /* draw the bubble shape. this is used twice, once for the shape and once */
130    /* for the shadow */
131    static void
132    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
133           gboolean bottom, int px, int py, int px0, int px1) {
134    
135        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
136        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
137                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
138        if(!bottom) {
139            /* insert top pointer */
140            cairo_line_to (cr, px1, y0);
141            cairo_line_to (cr, px, py);
142            cairo_line_to (cr, px0, y0);
143        }
144    
145        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
146        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
147                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
148        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
149        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
150                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
151        if(bottom) {
152            /* insert bottom pointer */
153            cairo_line_to (cr, px0, y1);
154            cairo_line_to (cr, px, py);
155            cairo_line_to (cr, px1, y1);
156        }
157    
158        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
159        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
160                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
161    
162        cairo_close_path (cr);
163    }
164    
165    static void
166    osd_render_balloon(osm_gps_map_osd_t *osd) {
167        osd_priv_t *priv = (osd_priv_t*)osd->priv;
168    
169        /* get zoom */
170        gint zoom;
171        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
172    
173        /* ------- convert given coordinate into screen position --------- */
174        gint xs, ys;
175        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
176                                          priv->balloon.lat, priv->balloon.lon,
177                                          &xs, &ys);
178    
179        gint x0 = 1, y0 = 1;
180    
181        /* check position of this relative to screen center to determine */
182        /* pointer direction ... */
183        int pointer_x, pointer_x0, pointer_x1;
184        int pointer_y;
185    
186        /* ... and calculate position */
187        int orientation = 0;
188        if(xs > osd->widget->allocation.width/2) {
189            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
190            pointer_x = x0 - priv->balloon.offset_x;
191            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
192            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
193            orientation |= 1;
194        } else {
195            priv->balloon.offset_x = -POINTER_OFFSET;
196            pointer_x = x0 - priv->balloon.offset_x;
197            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
198            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
199        }
200    
201        gboolean bottom = FALSE;
202        if(ys > osd->widget->allocation.height/2) {
203            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
204            pointer_y = y0 - priv->balloon.offset_y;
205            bottom = TRUE;
206            orientation |= 2;
207        } else {
208            priv->balloon.offset_y = 0;
209            pointer_y = y0 - priv->balloon.offset_y;
210            y0 += POINTER_HEIGHT;
211        }
212    
213        /* if required orientation equals current one, then don't render */
214        /* anything */
215        if(orientation == priv->balloon.orientation)
216            return;
217    
218        priv->balloon.orientation = orientation;
219    
220        /* calculate bottom/right of box */
221        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
222    
223        /* save balloon screen coordinates for later use */
224        priv->balloon.rect.x = x0 + BALLOON_BORDER;
225        priv->balloon.rect.y = y0 + BALLOON_BORDER;
226        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
227        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
228    
229        cairo_t *cr = cairo_create(priv->balloon.surface);
230        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
231        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
232        cairo_paint(cr);
233        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
234    
235        /* --------- draw shadow --------------- */
236        osm_gps_map_draw_balloon_shape (cr,
237                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
238                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
239                     bottom, pointer_x, pointer_y,
240                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
241    
242        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
243        cairo_fill_preserve (cr);
244        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
245        cairo_set_line_width (cr, 0);
246        cairo_stroke (cr);
247    
248        /* --------- draw main shape ----------- */
249        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
250                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
251    
252        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
253        cairo_fill_preserve (cr);
254        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
255        cairo_set_line_width (cr, 1);
256        cairo_stroke (cr);
257    
258        if (priv->balloon.cb) {
259            /* clip in case application tries to draw in */
260                /* exceed of the balloon */
261            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
262                             priv->balloon.rect.w, priv->balloon.rect.h);
263            cairo_clip (cr);
264            cairo_new_path (cr);  /* current path is not
265                                     consumed by cairo_clip() */
266    
267            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
268        }
269    
270        cairo_destroy(cr);
271    }
272    
273    /* return true if balloon is being displayed and if */
274    /* the given coordinate is within this balloon */
275    static gboolean
276    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
277    {
278        osd_priv_t *priv = (osd_priv_t*)osd->priv;
279    
280        if(!priv->balloon.surface)
281            return FALSE;
282    
283        gint xs, ys;
284        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
285                                          priv->balloon.lat, priv->balloon.lon,
286                                          &xs, &ys);
287    
288        printf("click at %d/%d\n", x, y);
289    
290        xs += priv->balloon.rect.x + priv->balloon.offset_x;
291        ys += priv->balloon.rect.y + priv->balloon.offset_y;
292    
293        printf("balloon at %d/%d/%d/%d\n",
294               xs, ys,
295               xs + priv->balloon.rect.w,
296               ys + priv->balloon.rect.h);
297    
298        gboolean is_in =
299            (x > xs) && (x < xs + priv->balloon.rect.w) &&
300            (y > ys) && (y < ys + priv->balloon.rect.h);
301    
302        /* handle the fact that the balloon may have been created by the */
303        /* button down event */
304        if(!is_in && !down && !priv->balloon.just_created) {
305            /* the user actually clicked outside the balloon */
306    
307            /* close the balloon! */
308            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
309        }
310    
311        return is_in;
312    }
313    
314    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
315        g_return_if_fail (OSM_IS_GPS_MAP (map));
316    
317        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
318        g_return_if_fail (osd);
319    
320        osd_priv_t *priv = (osd_priv_t*)osd->priv;
321        g_return_if_fail (priv);
322    
323        if(priv->balloon.surface) {
324            cairo_surface_destroy(priv->balloon.surface);
325            priv->balloon.surface = NULL;
326            priv->balloon.lat = OSM_GPS_MAP_INVALID;
327            priv->balloon.lon = OSM_GPS_MAP_INVALID;
328        }
329        osm_gps_map_redraw(map);
330    }
331    
332    void
333    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
334                                  OsmGpsMapBalloonCallback cb, gpointer data) {
335        g_return_if_fail (OSM_IS_GPS_MAP (map));
336    
337        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
338        g_return_if_fail (osd);
339    
340        osd_priv_t *priv = (osd_priv_t*)osd->priv;
341        g_return_if_fail (priv);
342    
343        osm_gps_map_osd_clear_balloon (map);
344    
345        /* allocate balloon surface */
346        priv->balloon.surface =
347            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
348                                       BALLOON_W+2, BALLOON_H+2);
349    
350        priv->balloon.lat = latitude;
351        priv->balloon.lon = longitude;
352        priv->balloon.cb = cb;
353        priv->balloon.data = data;
354        priv->balloon.just_created = TRUE;
355    
356        priv->balloon.orientation = -1;
357    
358        osd_render_balloon(osd);
359    
360        osm_gps_map_redraw(map);
361    }
362    
363    #endif // OSD_BALLOON
364    
365  /* position and extent of bounding box */  /* position and extent of bounding box */
366  #ifndef OSD_X  #ifndef OSD_X
367  #define OSD_X      (10)  #define OSD_X      (10)
# Line 285  osd_check_zoom(gint x, gint y) { Line 584  osd_check_zoom(gint x, gint y) {
584  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
585    
586  /* size of usable area when expanded */  /* size of usable area when expanded */
587  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
588  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
589  #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)
590  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
591    
# Line 302  osd_check_zoom(gint x, gint y) { Line 601  osd_check_zoom(gint x, gint y) {
601  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
602  static void  static void
603  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) {
604      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
605          /* just draw the puller */          /* just draw the puller */
606          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
607          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 330  osd_source_content(osm_gps_map_osd_t *os Line 629  osd_source_content(osm_gps_map_osd_t *os
629    
630      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
631    
632      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
633          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
634          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);
635          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
# Line 355  osd_source_content(osm_gps_map_osd_t *os Line 654  osd_source_content(osm_gps_map_osd_t *os
654                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
655              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
656    
657              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
658                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
659              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++) {
660                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 369  osd_source_content(osm_gps_map_osd_t *os Line 668  osd_source_content(osm_gps_map_osd_t *os
668                  if(source == i) {                  if(source == i) {
669                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
670                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
671                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
672                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
673                      cairo_fill(cr);                      cairo_fill(cr);
674    
# Line 400  osd_source_content(osm_gps_map_osd_t *os Line 699  osd_source_content(osm_gps_map_osd_t *os
699  }  }
700    
701  static void  static void
702  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
703      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
704    
705        if(priv->source_sel.rendered && !force_rerender)
706            return;
707    
708        priv->source_sel.rendered = TRUE;
709    
710  #ifndef OSD_COLOR  #ifndef OSD_COLOR
711      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
712      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 410  osd_render_source_sel(osm_gps_map_osd_t Line 714  osd_render_source_sel(osm_gps_map_osd_t
714  #endif  #endif
715    
716      /* draw source selector */      /* draw source selector */
717      cairo_t *cr = cairo_create(priv->map_source);      cairo_t *cr = cairo_create(priv->source_sel.surface);
718      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
719      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);
720      cairo_paint(cr);      cairo_paint(cr);
# Line 451  osd_source_reallocate(osm_gps_map_osd_t Line 755  osd_source_reallocate(osm_gps_map_osd_t
755      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
756    
757      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
758      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
759    
760      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
761      if(priv->expanded) {      if(priv->source_sel.expanded) {
762          cairo_text_extents_t extents;          cairo_text_extents_t extents;
763    
764          /* determine content size */          /* determine content size */
765          cairo_t *cr = cairo_create(priv->map_source);          cairo_t *cr = cairo_create(priv->source_sel.surface);
766          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
767                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
768                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 475  osd_source_reallocate(osm_gps_map_osd_t Line 779  osd_source_reallocate(osm_gps_map_osd_t
779          }          }
780          cairo_destroy(cr);          cairo_destroy(cr);
781    
782          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
783          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
784              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
785    
786          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
787          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
788      }      }
789    
790      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
791      priv->map_source =      priv->source_sel.surface =
792          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
793    
794      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
795  }  }
796    
797  #define OSD_HZ      15  #define OSD_HZ      15
# Line 498  static gboolean osd_source_animate(gpoin Line 802  static gboolean osd_source_animate(gpoin
802      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
803      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
804      gboolean done = FALSE;      gboolean done = FALSE;
805      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
806    
807      /* shifting in */      /* shifting in */
808      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
809          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
810              priv->count = 0;              priv->source_sel.count = 0;
811              done = TRUE;              done = TRUE;
812          }          }
813      } else {      } else {
814          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
815              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
816              osd_source_reallocate(osd);              osd_source_reallocate(osd);
817    
818              priv->count = 1000;              priv->source_sel.count = 1000;
819              done = TRUE;              done = TRUE;
820          }          }
821      }      }
# Line 519  static gboolean osd_source_animate(gpoin Line 823  static gboolean osd_source_animate(gpoin
823    
824      /* 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 */
825    
826      /* nicer sinoid mapping */      /* nice sinoid mapping */
827      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;
828      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
829            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
830          m * diff;          m * diff;
831    
832        /* make sure the screen is updated */
833      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
834    
835        /* stop animation if done */
836      if(done)      if(done)
837          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
838    
839      return !done;      return !done;
840  }  }
# Line 539  osd_source_toggle(osm_gps_map_osd_t *osd Line 846  osd_source_toggle(osm_gps_map_osd_t *osd
846      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
847    
848      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
849      if(priv->handler_id)      if(priv->source_sel.handler_id)
850          return;          return;
851    
852      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
853      if(!priv->expanded) {      /* collapse animation */
854          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
855            priv->source_sel.expanded = TRUE;
856          osd_source_reallocate(osd);          osd_source_reallocate(osd);
857    
858          priv->count = 1000;          priv->source_sel.count = 1000;
859          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
860          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
861      } else {      } else {
862          priv->count =  0;          priv->source_sel.count =  0;
863          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
864          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
865            priv->source_sel.dir = +1000/OSD_HZ;
866      }      }
867    
868      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
869        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
870                                                      osd_source_animate, osd);
871  }  }
872    
873  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
874  static osd_button_t  static osd_button_t
875  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) {
876      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
877    
878      if(!priv->expanded)      if(!priv->source_sel.expanded)
879          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
880      else      else
881          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 579  osd_source_check(osm_gps_map_osd_t *osd, Line 890  osd_source_check(osm_gps_map_osd_t *osd,
890          /* really within puller shape? */          /* really within puller shape? */
891          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)) {
892              /* expand source selector */              /* expand source selector */
893              osd_source_toggle(osd);              if(down)
894                    osd_source_toggle(osd);
895    
896              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
897              /* of the OSD */              /* of the OSD */
# Line 588  osd_source_check(osm_gps_map_osd_t *osd, Line 900  osd_source_check(osm_gps_map_osd_t *osd,
900      }      }
901    
902      /* check for clicks into data area */      /* check for clicks into data area */
903      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
904          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
905          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
906              y += OSD_S_EXP_H - OSD_S_PH;              y += OSD_S_EXP_H - OSD_S_PH;
# Line 598  osd_source_check(osm_gps_map_osd_t *osd, Line 910  osd_source_check(osm_gps_map_osd_t *osd,
910             y > 0 &&             y > 0 &&
911             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
912    
913              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
914                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
915    
916              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
917              y /= step;              y /= step;
918              y += 1;              y += 1;
919    
920              gint old = 0;              if(down) {
921              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
922                    g_object_get(osd->widget, "map-source", &old, NULL);
923              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
924                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
925                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
926                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
927                        g_object_set(osd->widget, "map-source", y, NULL);
928                  osd_render_source_sel(osd);  
929                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
930                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
931                    }
932              }              }
933    
934              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
# Line 628  osd_source_check(osm_gps_map_osd_t *osd, Line 942  osd_source_check(osm_gps_map_osd_t *osd,
942  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
943    
944  static osd_button_t  static osd_button_t
945  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) {
946      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
947    
948    #ifdef OSD_BALLOON
949        if(down) {
950            /* needed to handle balloons that are created at click */
951            osd_priv_t *priv = (osd_priv_t*)osd->priv;
952            priv->balloon.just_created = FALSE;
953        }
954    #endif
955    
956  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
957      /* the source selection area is handles internally */      /* the source selection area is handles internally */
958      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
959  #endif  #endif
960    
961      x -= OSD_X;      if(but == OSD_NONE) {
962      y -= OSD_Y;          gint mx = x - OSD_X;
963            gint my = y - OSD_Y;
964      if(OSD_X < 0)  
965          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
966                mx -= (osd->widget->allocation.width - OSD_W);
967      if(OSD_Y < 0)  
968          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
969                my -= (osd->widget->allocation.height - OSD_H);
970      /* first do a rough test for the OSD area. */  
971      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
972      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
973            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
974  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
975          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
976  #endif  #endif
977            }
978    
979          if(but == OSD_NONE)          if(but == OSD_NONE)
980              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
981      }      }
982    
983    #ifdef OSD_BALLOON
984        if(but == OSD_NONE) {
985            /* check if user clicked into balloon */
986            if(osd_balloon_check(osd, down, x, y))
987                but = OSD_BG;
988        }
989    #endif
990    
991      return but;      return but;
992  }  }
993    
# Line 737  osd_zoom_labels(cairo_t *cr, gint x, gin Line 1067  osd_zoom_labels(cairo_t *cr, gint x, gin
1067  #define OSD_COORDINATES_FONT_SIZE 12  #define OSD_COORDINATES_FONT_SIZE 12
1068  #endif  #endif
1069    
1070  #define OSD_COORDINATES_W  (9*OSD_COORDINATES_FONT_SIZE)  #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
1071  #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE)  
1072    #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
1073    #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)
1074    
1075  /* these can be overwritten with versions that support */  /* these can be overwritten with versions that support */
1076  /* localization */  /* localization */
# Line 796  static char Line 1128  static char
1128                             c, (int)integral, fractional*60.0);                             c, (int)integral, fractional*60.0);
1129  }  }
1130    
 #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)  
   
1131  static void  static void
1132  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
1133  {  {
# Line 807  osd_render_coordinates(osm_gps_map_osd_t Line 1137  osd_render_coordinates(osm_gps_map_osd_t
1137      gfloat lat, lon;      gfloat lat, lon;
1138      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1139    
1140        /* check if position has changed enough to require redraw */
1141        if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1142            /* 1/60000 == 1/1000 minute */
1143            if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1144               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1145                return;
1146    
1147        priv->coordinates.lat = lat;
1148        priv->coordinates.lon = lon;
1149    
1150      /* first fill with transparency */      /* first fill with transparency */
1151      cairo_t *cr = cairo_create(priv->coordinates);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1152      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1153      //    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);      //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
1154      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1155      cairo_paint(cr);      cairo_paint(cr);
1156      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1157    
# Line 829  osd_render_coordinates(osm_gps_map_osd_t Line 1169  osd_render_coordinates(osm_gps_map_osd_t
1169    
1170      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
1171      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);      cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
1172      cairo_move_to (cr,      cairo_move_to (cr,
1173                     OSD_COORDINATES_OFFSET - lat_extents.x_bearing,                     (OSD_COORDINATES_W - lat_extents.width)/2,
1174                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1175      cairo_text_path (cr, latitude);      cairo_text_path (cr, latitude);
1176      cairo_move_to (cr,      cairo_move_to (cr,
1177                     OSD_COORDINATES_OFFSET - lon_extents.x_bearing,                     (OSD_COORDINATES_W - lon_extents.width)/2,
1178                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1179                     OSD_COORDINATES_FONT_SIZE);                     OSD_COORDINATES_FONT_SIZE);
1180      cairo_text_path (cr, longitude);      cairo_text_path (cr, longitude);
# Line 842  osd_render_coordinates(osm_gps_map_osd_t Line 1182  osd_render_coordinates(osm_gps_map_osd_t
1182    
1183      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
1184      cairo_move_to (cr,      cairo_move_to (cr,
1185                     OSD_COORDINATES_OFFSET - lat_extents.x_bearing,                     (OSD_COORDINATES_W - lat_extents.width)/2,
1186                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);                     OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
1187      cairo_show_text (cr, latitude);      cairo_show_text (cr, latitude);
1188      cairo_move_to (cr,      cairo_move_to (cr,
1189                     OSD_COORDINATES_OFFSET - lon_extents.x_bearing,                     (OSD_COORDINATES_W - lon_extents.width)/2,
1190                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +                     OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
1191                     OSD_COORDINATES_FONT_SIZE);                     OSD_COORDINATES_FONT_SIZE);
1192      cairo_show_text (cr, longitude);      cairo_show_text (cr, longitude);
# Line 896  osd_render_crosshair(osm_gps_map_osd_t * Line 1236  osd_render_crosshair(osm_gps_map_osd_t *
1236  {  {
1237      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1238    
1239        if(priv->crosshair.rendered)
1240            return;
1241    
1242        priv->crosshair.rendered = TRUE;
1243    
1244      /* first fill with transparency */      /* first fill with transparency */
1245      cairo_t *cr = cairo_create(priv->crosshair);      cairo_t *cr = cairo_create(priv->crosshair.surface);
1246      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1247      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);  
1248      cairo_paint(cr);      cairo_paint(cr);
1249      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1250    
# Line 941  osd_render_scale(osm_gps_map_osd_t *osd) Line 1285  osd_render_scale(osm_gps_map_osd_t *osd)
1285      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
1286      gint zoom;      gint zoom;
1287      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1288      if(zoom == priv->scale_zoom)      if(zoom == priv->scale.zoom)
1289          return;          return;
1290    
1291      priv->scale_zoom = zoom;      priv->scale.zoom = zoom;
1292    
1293      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));
1294    
1295      /* first fill with transparency */      /* first fill with transparency */
1296      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale.surface);
1297      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1298      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);
1299      // 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 1063  osd_render_scale(osm_gps_map_osd_t *osd) Line 1407  osd_render_scale(osm_gps_map_osd_t *osd)
1407  #endif  #endif
1408    
1409  static void  static void
1410  osd_render(osm_gps_map_osd_t *osd)  osd_render_controls(osm_gps_map_osd_t *osd)
1411  {  {
1412      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1413    
1414        if(priv->controls.rendered
1415    #ifdef OSD_GPS_BUTTON
1416           && (priv->controls.gps_enabled == (osd->cb != NULL))
1417    #endif
1418           )
1419            return;
1420    
1421    #ifdef OSD_GPS_BUTTON
1422        priv->controls.gps_enabled = (osd->cb != NULL);
1423    #endif
1424        priv->controls.rendered = TRUE;
1425    
1426  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1427      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
1428      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 1074  osd_render(osm_gps_map_osd_t *osd) Line 1430  osd_render(osm_gps_map_osd_t *osd)
1430  #endif  #endif
1431    
1432      /* first fill with transparency */      /* first fill with transparency */
1433      cairo_t *cr = cairo_create(priv->overlay);      cairo_t *cr = cairo_create(priv->controls.surface);
1434      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1435      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);
1436      cairo_paint(cr);      cairo_paint(cr);
# Line 1145  osd_render(osm_gps_map_osd_t *osd) Line 1501  osd_render(osm_gps_map_osd_t *osd)
1501      cairo_stroke(cr);      cairo_stroke(cr);
1502    
1503      cairo_destroy(cr);      cairo_destroy(cr);
1504    }
1505    
1506    static void
1507    osd_render(osm_gps_map_osd_t *osd)
1508    {
1509        /* this function is actually called pretty often since the */
1510        /* OSD contents may have changed (due to a coordinate/zoom change). */
1511        /* The different OSD parts have to make sure that they don't */
1512        /* render unneccessarily often and thus waste CPU power */
1513    
1514        osd_render_controls(osd);
1515    
1516  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1517      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1518  #endif  #endif
1519    
1520  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1170  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1537  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1537    
1538      /* OSD itself uses some off-screen rendering, so check if the */      /* OSD itself uses some off-screen rendering, so check if the */
1539      /* offscreen buffer is present and create it if not */      /* offscreen buffer is present and create it if not */
1540      if(!priv->overlay) {      if(!priv->controls.surface) {
1541          /* create overlay ... */          /* create overlay ... */
1542          priv->overlay =          priv->controls.surface =
1543              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
1544    
1545            priv->controls.rendered = FALSE;
1546    #ifdef OSD_GPS_BUTTON
1547            priv->controls.gps_enabled = FALSE;
1548    #endif
1549    
1550  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1551          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1552          priv->map_source =          priv->source_sel.surface =
1553              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1554                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1555            priv->source_sel.rendered = FALSE;
1556  #endif  #endif
1557    
1558  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1559          priv->scale =          priv->scale.surface =
1560              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1561                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W, OSD_SCALE_H);
1562          priv->scale_zoom = -1;          priv->scale.zoom = -1;
1563  #endif  #endif
1564    
1565  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1566          priv->crosshair =          priv->crosshair.surface =
1567              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1568                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1569            priv->crosshair.rendered = FALSE;
1570  #endif  #endif
1571    
1572  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1573          priv->coordinates =          priv->coordinates.surface =
1574              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1575                                         OSD_COORDINATES_W, OSD_COORDINATES_H);                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1576    
1577            priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1578  #endif  #endif
1579    
1580          /* ... and render it */          /* ... and render it */
# Line 1208  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1584  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1584      // now draw this onto the original context      // now draw this onto the original context
1585      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1586    
1587      int x, y;      gint x, y;
1588    
1589  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1590      x =  OSD_X;      x =  OSD_X;
# Line 1216  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1592  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1592      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1593      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1594    
1595      cairo_set_source_surface(cr, priv->scale, x, y);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1596      cairo_paint(cr);      cairo_paint(cr);
1597  #endif  #endif
1598    
# Line 1224  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1600  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1600      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1601      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1602    
1603      cairo_set_source_surface(cr, priv->crosshair, x, y);      cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1604      cairo_paint(cr);      cairo_paint(cr);
1605  #endif  #endif
1606    
# Line 1234  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1610  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1610      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1611      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1612    
1613      cairo_set_source_surface(cr, priv->coordinates, x, y);      cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1614      cairo_paint(cr);      cairo_paint(cr);
1615  #endif  #endif
1616    
1617    #ifdef OSD_BALLOON
1618        if(priv->balloon.surface) {
1619    
1620            /* convert given lat lon into screen coordinates */
1621            gint x, y;
1622            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1623                                          priv->balloon.lat, priv->balloon.lon,
1624                                          &x, &y);
1625    
1626            /* check if balloon needs to be rerendered */
1627            osd_render_balloon(osd);
1628    
1629            cairo_set_source_surface(cr, priv->balloon.surface,
1630                                     x + priv->balloon.offset_x,
1631                                     y + priv->balloon.offset_y);
1632            cairo_paint(cr);
1633        }
1634    #endif
1635    
1636      x = OSD_X;      x = OSD_X;
1637      if(x < 0)      if(x < 0)
1638          x += osd->widget->allocation.width - OSD_W;          x += osd->widget->allocation.width - OSD_W;
# Line 1246  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1641  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1641      if(y < 0)      if(y < 0)
1642          y += osd->widget->allocation.height - OSD_H;          y += osd->widget->allocation.height - OSD_H;
1643    
1644      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->controls.surface, x, y);
1645      cairo_paint(cr);      cairo_paint(cr);
1646    
1647  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1648      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
1649          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
1650          if(!priv->expanded)          if(!priv->source_sel.expanded)
1651              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
1652          else          else
1653              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1654      } else      } else
1655          x = priv->shift;          x = priv->source_sel.shift;
1656    
1657      y = OSD_S_Y;      y = OSD_S_Y;
1658      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
1659          if(!priv->expanded)          if(!priv->source_sel.expanded)
1660              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1661          else          else
1662              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1663      }      }
1664    
1665      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
1666      cairo_paint(cr);      cairo_paint(cr);
1667  #endif  #endif
1668    
# Line 1279  osd_free(osm_gps_map_osd_t *osd) Line 1674  osd_free(osm_gps_map_osd_t *osd)
1674  {  {
1675      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1676    
1677      if (priv->overlay)      if (priv->controls.surface)
1678           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->controls.surface);
1679    
1680  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1681      if(priv->handler_id)      if(priv->source_sel.handler_id)
1682          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
1683    
1684      if (priv->map_source)      if (priv->source_sel.surface)
1685           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
1686  #endif  #endif
1687    
1688  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1689      if (priv->scale)      if (priv->scale.surface)
1690           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
1691  #endif  #endif
1692    
1693  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1694      if (priv->crosshair)      if (priv->crosshair.surface)
1695           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair.surface);
1696  #endif  #endif
1697    
1698  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1699      if (priv->coordinates)      if (priv->coordinates.surface)
1700           cairo_surface_destroy(priv->coordinates);           cairo_surface_destroy(priv->coordinates.surface);
1701    #endif
1702    
1703    #ifdef OSD_BALLOON
1704        if (priv->balloon.surface)
1705             cairo_surface_destroy(priv->balloon.surface);
1706  #endif  #endif
1707    
1708      g_free(priv);      g_free(priv);
# Line 1313  osd_busy(osm_gps_map_osd_t *osd) Line 1713  osd_busy(osm_gps_map_osd_t *osd)
1713  {  {
1714  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1715      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1716      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
1717  #else  #else
1718      return FALSE;      return FALSE;
1719  #endif  #endif
# Line 1340  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1740  osm_gps_map_osd_classic_init(OsmGpsMap *
1740  {  {
1741      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);
1742    
1743    #ifdef OSD_BALLOON
1744        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1745        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1746    #endif
1747    
1748      osd_classic.priv = priv;      osd_classic.priv = priv;
1749    
1750      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
# Line 1369  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1774  osm_gps_map_osd_check(OsmGpsMap *map, gi
1774      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1775      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1776    
1777      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1778  }  }

Legend:
Removed from v.107  
changed lines
  Added in v.120