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 113 by harbaum, Wed Sep 16 13:45:10 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            float lat, lon;
56            OsmGpsMapRect_t rect;
57    
58            /* function called to have the user app draw the contents */
59            OsmGpsMapBalloonCallback cb;
60            gpointer data;
61        } balloon;
62  #endif  #endif
63    
64    #ifdef OSD_SCALE
65        struct {
66            cairo_surface_t *surface;
67            int zoom;
68        } scale;
69    #endif
70    
71  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
72      cairo_surface_t *crosshair;      struct {
73            cairo_surface_t *surface;
74            gboolean rendered;
75        } crosshair;
76  #endif  #endif
77    
78  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
79      cairo_surface_t *coordinates;      struct {
80      float coo_lat, coo_lon;          cairo_surface_t *surface;
81            float lat, lon;
82        } coordinates;
83  #endif  #endif
84    
85  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
86      /* values to handle the "source" menu */      struct {
87      cairo_surface_t *map_source;          /* values to handle the "source" menu */
88      gboolean expanded;          cairo_surface_t *surface;
89      gint shift, dir, count;          gboolean expanded;
90      gint handler_id;          gint shift, dir, count;
91      gint width, height;          gint handler_id;
92            gint width, height;
93            gboolean rendered;
94        } source_sel;
95  #endif  #endif
96    
97  } osd_priv_t;  } osd_priv_t;
98    
99    #ifdef OSD_BALLOON
100    /* most visual effects are hardcoded by now, but may be made */
101    /* available via properties later */
102    #ifndef BALLOON_AREA_WIDTH
103    #define BALLOON_AREA_WIDTH           290
104    #endif
105    #ifndef BALLOON_AREA_HEIGHT
106    #define BALLOON_AREA_HEIGHT           75
107    #endif
108    #ifndef BALLOON_CORNER_RADIUS
109    #define BALLOON_CORNER_RADIUS         10
110    #endif
111    
112    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
113    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
114    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
115    #define BALLOON_TRANSPARENCY         0.8
116    #define POINTER_HEIGHT                20
117    #define POINTER_FOOT_WIDTH            20
118    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
119    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
120    #define BALLOON_SHADOW_TRANSPARENCY  0.2
121    
122    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
123    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
124    
125    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
126    
127    
128    /* draw the bubble shape. this is used twice, once for the shape and once */
129    /* for the shadow */
130    static void
131    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
132           gboolean bottom, int px, int py, int px0, int px1) {
133    
134        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
135        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
136                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
137        if(!bottom) {
138            /* insert top pointer */
139            cairo_line_to (cr, px1, y0);
140            cairo_line_to (cr, px, py);
141            cairo_line_to (cr, px0, y0);
142        }
143    
144        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
145        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
146                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
147        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
148        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
149                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
150        if(bottom) {
151            /* insert bottom pointer */
152            cairo_line_to (cr, px0, y1);
153            cairo_line_to (cr, px, py);
154            cairo_line_to (cr, px1, y1);
155        }
156    
157        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
158        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
159                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
160    
161        cairo_close_path (cr);
162    }
163    
164    static void
165    osd_render_balloon(osm_gps_map_osd_t *osd) {
166        osd_priv_t *priv = (osd_priv_t*)osd->priv;
167    
168        /* get zoom */
169        gint zoom;
170        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
171    
172        /* ------- convert given coordinate into screen position --------- */
173        gint xs, ys;
174        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
175                                          priv->balloon.lat, priv->balloon.lon,
176                                          &xs, &ys);
177    
178        gint x0 = 1, y0 = 1;
179    
180        /* check position of this relative to screen center to determine */
181        /* pointer direction ... */
182        int pointer_x, pointer_x0, pointer_x1;
183        int pointer_y;
184    
185        /* ... and calculate position */
186        int orientation = 0;
187        if(xs > osd->widget->allocation.width/2) {
188            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
189            pointer_x = x0 - priv->balloon.offset_x;
190            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
191            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
192            orientation |= 1;
193        } else {
194            priv->balloon.offset_x = -POINTER_OFFSET;
195            pointer_x = x0 - priv->balloon.offset_x;
196            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
197            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
198        }
199    
200        gboolean bottom = FALSE;
201        if(ys > osd->widget->allocation.height/2) {
202            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
203            pointer_y = y0 - priv->balloon.offset_y;
204            bottom = TRUE;
205            orientation |= 2;
206        } else {
207            priv->balloon.offset_y = 0;
208            pointer_y = y0 - priv->balloon.offset_y;
209            y0 += POINTER_HEIGHT;
210        }
211    
212        /* if required orientation equals current one, then don't render */
213        /* anything */
214        if(orientation == priv->balloon.orientation)
215            return;
216    
217        priv->balloon.orientation = orientation;
218    
219        /* calculate bottom/right of box */
220        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
221    
222        /* save balloon screen coordinates for later use */
223        priv->balloon.rect.x = x0 + BALLOON_BORDER;
224        priv->balloon.rect.y = y0 + BALLOON_BORDER;
225        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
226        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
227    
228        cairo_t *cr = cairo_create(priv->balloon.surface);
229        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
230        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
231        cairo_paint(cr);
232        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
233    
234        /* --------- draw shadow --------------- */
235        osm_gps_map_draw_balloon_shape (cr,
236                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
237                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
238                     bottom, pointer_x, pointer_y,
239                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
240    
241        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
242        cairo_fill_preserve (cr);
243        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
244        cairo_set_line_width (cr, 0);
245        cairo_stroke (cr);
246    
247        /* --------- draw main shape ----------- */
248        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
249                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
250    
251        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
252        cairo_fill_preserve (cr);
253        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
254        cairo_set_line_width (cr, 1);
255        cairo_stroke (cr);
256    
257        if (priv->balloon.cb) {
258            /* clip in case application tries to draw in */
259                /* exceed of the balloon */
260            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
261                             priv->balloon.rect.w, priv->balloon.rect.h);
262            cairo_clip (cr);
263            cairo_new_path (cr);  /* current path is not
264                                     consumed by cairo_clip() */
265    
266            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
267        }
268    
269        cairo_destroy(cr);
270    }
271    
272    /* return true if balloon is being displayed and if */
273    /* the given coordinate is within this balloon */
274    static gboolean
275    osd_balloon_check(osm_gps_map_osd_t *osd, gint x, gint y)
276    {
277        osd_priv_t *priv = (osd_priv_t*)osd->priv;
278    
279        if(!priv->balloon.surface)
280            return FALSE;
281    
282        gint xs, ys;
283        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
284                                          priv->balloon.lat, priv->balloon.lon,
285                                          &xs, &ys);
286    
287        xs += priv->balloon.rect.x + priv->balloon.offset_x;
288        ys += priv->balloon.rect.y + priv->balloon.offset_y;
289    
290        return (priv->balloon.surface &&
291                (x > xs) && (x < xs + priv->balloon.rect.w) &&
292                (y > ys) && (y < ys + priv->balloon.rect.h));
293    }
294    
295    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
296        g_return_if_fail (OSM_IS_GPS_MAP (map));
297    
298        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
299        g_return_if_fail (osd);
300    
301        osd_priv_t *priv = (osd_priv_t*)osd->priv;
302        g_return_if_fail (priv);
303    
304        printf("request to clear balloon\n");
305    
306        if(priv->balloon.surface) {
307            cairo_surface_destroy(priv->balloon.surface);
308            priv->balloon.surface = NULL;
309            priv->balloon.lat = OSM_GPS_MAP_INVALID;
310            priv->balloon.lon = OSM_GPS_MAP_INVALID;
311        }
312        osm_gps_map_redraw(map);
313    }
314    
315    void
316    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
317                                  OsmGpsMapBalloonCallback cb, gpointer data) {
318        g_return_if_fail (OSM_IS_GPS_MAP (map));
319    
320        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
321        g_return_if_fail (osd);
322    
323        osd_priv_t *priv = (osd_priv_t*)osd->priv;
324        g_return_if_fail (priv);
325    
326        osm_gps_map_osd_clear_balloon (map);
327    
328        printf("request to draw balloon at %f %f\n", latitude, longitude);
329    
330        /* allocate balloon surface */
331        priv->balloon.surface =
332            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
333                                       BALLOON_W+2, BALLOON_H+2);
334    
335        priv->balloon.lat = latitude;
336        priv->balloon.lon = longitude;
337        priv->balloon.cb = cb;
338        priv->balloon.data = data;
339    
340        priv->balloon.orientation = -1;
341    
342        osd_render_balloon(osd);
343    
344        osm_gps_map_redraw(map);
345    }
346    
347    #endif // OSD_BALLOON
348    
349  /* position and extent of bounding box */  /* position and extent of bounding box */
350  #ifndef OSD_X  #ifndef OSD_X
351  #define OSD_X      (10)  #define OSD_X      (10)
# Line 292  osd_check_zoom(gint x, gint y) { Line 568  osd_check_zoom(gint x, gint y) {
568  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
569    
570  /* size of usable area when expanded */  /* size of usable area when expanded */
571  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
572  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
573  #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)
574  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
575    
# Line 309  osd_check_zoom(gint x, gint y) { Line 585  osd_check_zoom(gint x, gint y) {
585  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
586  static void  static void
587  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) {
588      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
589          /* just draw the puller */          /* just draw the puller */
590          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
591          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);          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 613  osd_source_content(osm_gps_map_osd_t *os
613    
614      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
615    
616      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
617          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
618          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);
619          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 638  osd_source_content(osm_gps_map_osd_t *os
638                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
639              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
640    
641              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
642                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
643              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++) {
644                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 376  osd_source_content(osm_gps_map_osd_t *os Line 652  osd_source_content(osm_gps_map_osd_t *os
652                  if(source == i) {                  if(source == i) {
653                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
654                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
655                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
656                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
657                      cairo_fill(cr);                      cairo_fill(cr);
658    
# Line 407  osd_source_content(osm_gps_map_osd_t *os Line 683  osd_source_content(osm_gps_map_osd_t *os
683  }  }
684    
685  static void  static void
686  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
687      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
688    
689        if(priv->source_sel.rendered && !force_rerender)
690            return;
691    
692        priv->source_sel.rendered = TRUE;
693    
694  #ifndef OSD_COLOR  #ifndef OSD_COLOR
695      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
696      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 698  osd_render_source_sel(osm_gps_map_osd_t
698  #endif  #endif
699    
700      /* draw source selector */      /* draw source selector */
701      cairo_t *cr = cairo_create(priv->map_source);      cairo_t *cr = cairo_create(priv->source_sel.surface);
702      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
703      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);
704      cairo_paint(cr);      cairo_paint(cr);
# Line 458  osd_source_reallocate(osm_gps_map_osd_t Line 739  osd_source_reallocate(osm_gps_map_osd_t
739      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
740    
741      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
742      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
743    
744      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
745      if(priv->expanded) {      if(priv->source_sel.expanded) {
746          cairo_text_extents_t extents;          cairo_text_extents_t extents;
747    
748          /* determine content size */          /* determine content size */
749          cairo_t *cr = cairo_create(priv->map_source);          cairo_t *cr = cairo_create(priv->source_sel.surface);
750          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
751                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
752                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 482  osd_source_reallocate(osm_gps_map_osd_t Line 763  osd_source_reallocate(osm_gps_map_osd_t
763          }          }
764          cairo_destroy(cr);          cairo_destroy(cr);
765    
766          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
767          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
768              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
769    
770          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
771          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
772      }      }
773    
774      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
775      priv->map_source =      priv->source_sel.surface =
776          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
777    
778      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
779  }  }
780    
781  #define OSD_HZ      15  #define OSD_HZ      15
# Line 505  static gboolean osd_source_animate(gpoin Line 786  static gboolean osd_source_animate(gpoin
786      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
787      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
788      gboolean done = FALSE;      gboolean done = FALSE;
789      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
790    
791      /* shifting in */      /* shifting in */
792      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
793          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
794              priv->count = 0;              priv->source_sel.count = 0;
795              done = TRUE;              done = TRUE;
796          }          }
797      } else {      } else {
798          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
799              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
800              osd_source_reallocate(osd);              osd_source_reallocate(osd);
801    
802              priv->count = 1000;              priv->source_sel.count = 1000;
803              done = TRUE;              done = TRUE;
804          }          }
805      }      }
# Line 526  static gboolean osd_source_animate(gpoin Line 807  static gboolean osd_source_animate(gpoin
807    
808      /* 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 */
809    
810      /* nicer sinoid mapping */      /* nice sinoid mapping */
811      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;
812      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
813            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
814          m * diff;          m * diff;
815    
816        /* make sure the screen is updated */
817      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
818    
819        /* stop animation if done */
820      if(done)      if(done)
821          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
822    
823      return !done;      return !done;
824  }  }
# Line 546  osd_source_toggle(osm_gps_map_osd_t *osd Line 830  osd_source_toggle(osm_gps_map_osd_t *osd
830      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
831    
832      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
833      if(priv->handler_id)      if(priv->source_sel.handler_id)
834          return;          return;
835    
836      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
837      if(!priv->expanded) {      /* collapse animation */
838          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
839            priv->source_sel.expanded = TRUE;
840          osd_source_reallocate(osd);          osd_source_reallocate(osd);
841    
842          priv->count = 1000;          priv->source_sel.count = 1000;
843          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
844          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
845      } else {      } else {
846          priv->count =  0;          priv->source_sel.count =  0;
847          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
848          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
849            priv->source_sel.dir = +1000/OSD_HZ;
850      }      }
851    
852      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
853        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
854                                                      osd_source_animate, osd);
855  }  }
856    
857  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
# Line 571  static osd_button_t Line 859  static osd_button_t
859  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {
860      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
861    
862      if(!priv->expanded)      if(!priv->source_sel.expanded)
863          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
864      else      else
865          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 595  osd_source_check(osm_gps_map_osd_t *osd, Line 883  osd_source_check(osm_gps_map_osd_t *osd,
883      }      }
884    
885      /* check for clicks into data area */      /* check for clicks into data area */
886      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
887          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
888          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
889              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 893  osd_source_check(osm_gps_map_osd_t *osd,
893             y > 0 &&             y > 0 &&
894             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
895    
896              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
897                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
898    
899              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
# Line 620  osd_source_check(osm_gps_map_osd_t *osd, Line 908  osd_source_check(osm_gps_map_osd_t *osd,
908                 old != y) {                 old != y) {
909                  g_object_set(osd->widget, "map-source", y, NULL);                  g_object_set(osd->widget, "map-source", y, NULL);
910    
911                  osd_render_source_sel(osd);                  osd_render_source_sel(osd, TRUE);
912                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
913              }              }
914    
# Line 638  static osd_button_t Line 926  static osd_button_t
926  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {
927      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
928    
929    #ifdef OSD_BALLOON
930        /* check if user clicked into balloon */
931        if(osd_balloon_check(osd, x, y))
932            return OSD_BG;
933    #endif
934    
935  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
936      /* the source selection area is handles internally */      /* the source selection area is handles internally */
937      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, x, y);
# Line 815  osd_render_coordinates(osm_gps_map_osd_t Line 1109  osd_render_coordinates(osm_gps_map_osd_t
1109      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);      g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
1110    
1111      /* check if position has changed enough to require redraw */      /* check if position has changed enough to require redraw */
1112      if(!isnan(priv->coo_lat) && !isnan(priv->coo_lon))      if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
1113          if((fabsf(lat - priv->coo_lat) < 1/60000) &&     /* 1/60000 == 1/1000 minute */          /* 1/60000 == 1/1000 minute */
1114             (fabsf(lon - priv->coo_lon) < 1/60000))          if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
1115               (fabsf(lon - priv->coordinates.lon) < 1/60000))
1116              return;              return;
1117    
1118      priv->coo_lat = lat;      priv->coordinates.lat = lat;
1119      priv->coo_lon = lon;      priv->coordinates.lon = lon;
1120    
1121      /* first fill with light transparency */      /* first fill with transparency */
1122      cairo_t *cr = cairo_create(priv->coordinates);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1123      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1124      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);
1125        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1126      cairo_paint(cr);      cairo_paint(cr);
1127      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1128    
# Line 911  osd_render_crosshair(osm_gps_map_osd_t * Line 1207  osd_render_crosshair(osm_gps_map_osd_t *
1207  {  {
1208      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1209    
1210        if(priv->crosshair.rendered)
1211            return;
1212    
1213        priv->crosshair.rendered = TRUE;
1214    
1215      /* first fill with transparency */      /* first fill with transparency */
1216      cairo_t *cr = cairo_create(priv->crosshair);      cairo_t *cr = cairo_create(priv->crosshair.surface);
1217      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1218      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);  
1219      cairo_paint(cr);      cairo_paint(cr);
1220      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1221    
# Line 956  osd_render_scale(osm_gps_map_osd_t *osd) Line 1256  osd_render_scale(osm_gps_map_osd_t *osd)
1256      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
1257      gint zoom;      gint zoom;
1258      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
1259      if(zoom == priv->scale_zoom)      if(zoom == priv->scale.zoom)
1260          return;          return;
1261    
1262      priv->scale_zoom = zoom;      priv->scale.zoom = zoom;
1263    
1264      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));
1265    
1266      /* first fill with transparency */      /* first fill with transparency */
1267      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale.surface);
1268      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1269      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
1270      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      // 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 1392  osd_render_controls(osm_gps_map_osd_t *o
1392  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
1393      priv->controls.gps_enabled = (osd->cb != NULL);      priv->controls.gps_enabled = (osd->cb != NULL);
1394  #endif  #endif
1395        priv->controls.rendered = TRUE;
1396    
1397  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1398      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
# Line 1176  osd_render_controls(osm_gps_map_osd_t *o Line 1477  osd_render_controls(osm_gps_map_osd_t *o
1477  static void  static void
1478  osd_render(osm_gps_map_osd_t *osd)  osd_render(osm_gps_map_osd_t *osd)
1479  {  {
1480        /* this function is actually called pretty often since the */
1481        /* OSD contents may have changed (due to a coordinate/zoom change). */
1482        /* The different OSD parts have to make sure that they don't */
1483        /* render unneccessarily often and thus waste CPU power */
1484    
1485      osd_render_controls(osd);      osd_render_controls(osd);
1486    
1487  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1488      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1489  #endif  #endif
1490    
1491  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1214  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1520  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1520    
1521  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1522          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1523          priv->map_source =          priv->source_sel.surface =
1524              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1525                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1526            priv->source_sel.rendered = FALSE;
1527  #endif  #endif
1528    
1529  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1530          priv->scale =          priv->scale.surface =
1531              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1532                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W, OSD_SCALE_H);
1533          priv->scale_zoom = -1;          priv->scale.zoom = -1;
1534  #endif  #endif
1535    
1536  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1537          priv->crosshair =          priv->crosshair.surface =
1538              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1539                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1540            priv->crosshair.rendered = FALSE;
1541  #endif  #endif
1542    
1543  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1544          priv->coordinates =          priv->coordinates.surface =
1545              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1546                                         OSD_COORDINATES_W, OSD_COORDINATES_H);                                         OSD_COORDINATES_W, OSD_COORDINATES_H);
1547    
1548          priv->coo_lat = priv->coo_lon = OSM_GPS_MAP_INVALID;          priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1549  #endif  #endif
1550    
1551          /* ... and render it */          /* ... and render it */
# Line 1247  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1555  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1555      // now draw this onto the original context      // now draw this onto the original context
1556      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1557    
1558      int x, y;      gint x, y;
1559    
1560  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1561      x =  OSD_X;      x =  OSD_X;
# Line 1255  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1563  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1563      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;      if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1564      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;      if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1565    
1566      cairo_set_source_surface(cr, priv->scale, x, y);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1567      cairo_paint(cr);      cairo_paint(cr);
1568  #endif  #endif
1569    
# Line 1263  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1571  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1571      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;      x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1572      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;      y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1573    
1574      cairo_set_source_surface(cr, priv->crosshair, x, y);      cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1575      cairo_paint(cr);      cairo_paint(cr);
1576  #endif  #endif
1577    
# Line 1273  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1581  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1581      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;      if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1582      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;      if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1583    
1584      cairo_set_source_surface(cr, priv->coordinates, x, y);      cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1585      cairo_paint(cr);      cairo_paint(cr);
1586  #endif  #endif
1587    
1588    #ifdef OSD_BALLOON
1589        if(priv->balloon.surface) {
1590    
1591            /* convert given lat lon into screen coordinates */
1592            gint x, y;
1593            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1594                                          priv->balloon.lat, priv->balloon.lon,
1595                                          &x, &y);
1596    
1597            /* check if balloon needs to be rerendered */
1598            osd_render_balloon(osd);
1599    
1600            cairo_set_source_surface(cr, priv->balloon.surface,
1601                                     x + priv->balloon.offset_x,
1602                                     y + priv->balloon.offset_y);
1603            cairo_paint(cr);
1604        }
1605    #endif
1606    
1607      x = OSD_X;      x = OSD_X;
1608      if(x < 0)      if(x < 0)
1609          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 1616  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1616      cairo_paint(cr);      cairo_paint(cr);
1617    
1618  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1619      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
1620          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
1621          if(!priv->expanded)          if(!priv->source_sel.expanded)
1622              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
1623          else          else
1624              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1625      } else      } else
1626          x = priv->shift;          x = priv->source_sel.shift;
1627    
1628      y = OSD_S_Y;      y = OSD_S_Y;
1629      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
1630          if(!priv->expanded)          if(!priv->source_sel.expanded)
1631              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1632          else          else
1633              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1634      }      }
1635    
1636      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
1637      cairo_paint(cr);      cairo_paint(cr);
1638  #endif  #endif
1639    
# Line 1322  osd_free(osm_gps_map_osd_t *osd) Line 1649  osd_free(osm_gps_map_osd_t *osd)
1649           cairo_surface_destroy(priv->controls.surface);           cairo_surface_destroy(priv->controls.surface);
1650    
1651  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1652      if(priv->handler_id)      if(priv->source_sel.handler_id)
1653          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
1654    
1655      if (priv->map_source)      if (priv->source_sel.surface)
1656           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
1657  #endif  #endif
1658    
1659  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1660      if (priv->scale)      if (priv->scale.surface)
1661           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
1662  #endif  #endif
1663    
1664  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1665      if (priv->crosshair)      if (priv->crosshair.surface)
1666           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair.surface);
1667  #endif  #endif
1668    
1669  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1670      if (priv->coordinates)      if (priv->coordinates.surface)
1671           cairo_surface_destroy(priv->coordinates);           cairo_surface_destroy(priv->coordinates.surface);
1672    #endif
1673    
1674    #ifdef OSD_BALLOON
1675        if (priv->balloon.surface)
1676             cairo_surface_destroy(priv->balloon.surface);
1677  #endif  #endif
1678    
1679      g_free(priv);      g_free(priv);
# Line 1352  osd_busy(osm_gps_map_osd_t *osd) Line 1684  osd_busy(osm_gps_map_osd_t *osd)
1684  {  {
1685  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1686      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1687      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
1688  #else  #else
1689      return FALSE;      return FALSE;
1690  #endif  #endif
# Line 1379  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1711  osm_gps_map_osd_classic_init(OsmGpsMap *
1711  {  {
1712      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);      osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1);
1713    
1714    #ifdef OSD_BALLOON
1715        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1716        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1717    #endif
1718    
1719      osd_classic.priv = priv;      osd_classic.priv = priv;
1720    
1721      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);

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