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

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

revision 110 by harbaum, Sat Sep 12 20:56:35 2009 UTC revision 122 by harbaum, Mon Sep 21 13:15:25 2009 UTC
# Line 25  Line 25 
25  /* OSD_DIAMETER */  /* OSD_DIAMETER */
26  /* OSD_X, OSD_Y */  /* OSD_X, OSD_Y */
27    
28    #define OSD_NAV
29    
30  #ifndef USE_CAIRO  #ifndef USE_CAIRO
31  #error "OSD control display lacks a non-cairo implementation!"  #error "OSD control display lacks a non-cairo implementation!"
32  #endif  #endif
# Line 32  Line 34 
34  #include <cairo.h>  #include <cairo.h>
35    
36  #include "osm-gps-map.h"  #include "osm-gps-map.h"
37    #include "converter.h"
38  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
39    
40  //the osd controls  //the osd controls
# Line 45  typedef struct { Line 48  typedef struct {
48  #endif  #endif
49      } controls;      } controls;
50    
51    #ifdef OSD_BALLOON
52        //a balloon with additional info
53        struct {
54            cairo_surface_t *surface;
55            int orientation, offset_x, offset_y;
56    
57            gboolean just_created;
58            float lat, lon;
59            OsmGpsMapRect_t rect;
60    
61            /* function called to have the user app draw the contents */
62            OsmGpsMapBalloonCallback cb;
63            gpointer data;
64        } balloon;
65    #endif
66    
67  #ifdef OSD_SCALE  #ifdef OSD_SCALE
68      struct {      struct {
69          cairo_surface_t *surface;          cairo_surface_t *surface;
# Line 59  typedef struct { Line 78  typedef struct {
78      } crosshair;      } crosshair;
79  #endif  #endif
80    
81    #ifdef OSD_NAV
82        struct {
83            cairo_surface_t *surface;
84        } nav;
85    #endif
86    
87  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
88      struct {      struct {
89          cairo_surface_t *surface;          cairo_surface_t *surface;
# Line 74  typedef struct { Line 99  typedef struct {
99          gint shift, dir, count;          gint shift, dir, count;
100          gint handler_id;          gint handler_id;
101          gint width, height;          gint width, height;
102            gboolean rendered;
103      } source_sel;      } source_sel;
104  #endif  #endif
105    
106  } osd_priv_t;  } osd_priv_t;
107    
108    #ifdef OSD_BALLOON
109    /* most visual effects are hardcoded by now, but may be made */
110    /* available via properties later */
111    #ifndef BALLOON_AREA_WIDTH
112    #define BALLOON_AREA_WIDTH           290
113    #endif
114    #ifndef BALLOON_AREA_HEIGHT
115    #define BALLOON_AREA_HEIGHT           75
116    #endif
117    #ifndef BALLOON_CORNER_RADIUS
118    #define BALLOON_CORNER_RADIUS         10
119    #endif
120    
121    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
122    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
123    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
124    #define BALLOON_TRANSPARENCY         0.8
125    #define POINTER_HEIGHT                20
126    #define POINTER_FOOT_WIDTH            20
127    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
128    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
129    #define BALLOON_SHADOW_TRANSPARENCY  0.2
130    
131    #define BALLOON_W  (BALLOON_WIDTH + BALLOON_SHADOW)
132    #define BALLOON_H  (BALLOON_HEIGHT + POINTER_HEIGHT + BALLOON_SHADOW)
133    
134    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
135    
136    
137    /* draw the bubble shape. this is used twice, once for the shape and once */
138    /* for the shadow */
139    static void
140    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
141           gboolean bottom, int px, int py, int px0, int px1) {
142    
143        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
144        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
145                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
146        if(!bottom) {
147            /* insert top pointer */
148            cairo_line_to (cr, px1, y0);
149            cairo_line_to (cr, px, py);
150            cairo_line_to (cr, px0, y0);
151        }
152    
153        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
154        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
155                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
156        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
157        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
158                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
159        if(bottom) {
160            /* insert bottom pointer */
161            cairo_line_to (cr, px0, y1);
162            cairo_line_to (cr, px, py);
163            cairo_line_to (cr, px1, y1);
164        }
165    
166        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
167        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
168                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
169    
170        cairo_close_path (cr);
171    }
172    
173    static void
174    osd_render_balloon(osm_gps_map_osd_t *osd) {
175        osd_priv_t *priv = (osd_priv_t*)osd->priv;
176    
177        /* get zoom */
178        gint zoom;
179        g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
180    
181        /* ------- convert given coordinate into screen position --------- */
182        gint xs, ys;
183        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
184                                          priv->balloon.lat, priv->balloon.lon,
185                                          &xs, &ys);
186    
187        gint x0 = 1, y0 = 1;
188    
189        /* check position of this relative to screen center to determine */
190        /* pointer direction ... */
191        int pointer_x, pointer_x0, pointer_x1;
192        int pointer_y;
193    
194        /* ... and calculate position */
195        int orientation = 0;
196        if(xs > osd->widget->allocation.width/2) {
197            priv->balloon.offset_x = -BALLOON_WIDTH + POINTER_OFFSET;
198            pointer_x = x0 - priv->balloon.offset_x;
199            pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
200            pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
201            orientation |= 1;
202        } else {
203            priv->balloon.offset_x = -POINTER_OFFSET;
204            pointer_x = x0 - priv->balloon.offset_x;
205            pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
206            pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
207        }
208    
209        gboolean bottom = FALSE;
210        if(ys > osd->widget->allocation.height/2) {
211            priv->balloon.offset_y = -BALLOON_HEIGHT - POINTER_HEIGHT;
212            pointer_y = y0 - priv->balloon.offset_y;
213            bottom = TRUE;
214            orientation |= 2;
215        } else {
216            priv->balloon.offset_y = 0;
217            pointer_y = y0 - priv->balloon.offset_y;
218            y0 += POINTER_HEIGHT;
219        }
220    
221        /* if required orientation equals current one, then don't render */
222        /* anything */
223        if(orientation == priv->balloon.orientation)
224            return;
225    
226        priv->balloon.orientation = orientation;
227    
228        /* calculate bottom/right of box */
229        int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
230    
231        /* save balloon screen coordinates for later use */
232        priv->balloon.rect.x = x0 + BALLOON_BORDER;
233        priv->balloon.rect.y = y0 + BALLOON_BORDER;
234        priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
235        priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
236    
237        cairo_t *cr = cairo_create(priv->balloon.surface);
238        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
239        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
240        cairo_paint(cr);
241        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
242    
243        /* --------- draw shadow --------------- */
244        osm_gps_map_draw_balloon_shape (cr,
245                     x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
246                     x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
247                     bottom, pointer_x, pointer_y,
248                     pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
249    
250        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
251        cairo_fill_preserve (cr);
252        cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
253        cairo_set_line_width (cr, 0);
254        cairo_stroke (cr);
255    
256        /* --------- draw main shape ----------- */
257        osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
258                     bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
259    
260        cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
261        cairo_fill_preserve (cr);
262        cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
263        cairo_set_line_width (cr, 1);
264        cairo_stroke (cr);
265    
266        if (priv->balloon.cb) {
267            /* clip in case application tries to draw in */
268                /* exceed of the balloon */
269            cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
270                             priv->balloon.rect.w, priv->balloon.rect.h);
271            cairo_clip (cr);
272            cairo_new_path (cr);  /* current path is not
273                                     consumed by cairo_clip() */
274    
275            priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
276        }
277    
278        cairo_destroy(cr);
279    }
280    
281    /* return true if balloon is being displayed and if */
282    /* the given coordinate is within this balloon */
283    static gboolean
284    osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y)
285    {
286        osd_priv_t *priv = (osd_priv_t*)osd->priv;
287    
288        if(!priv->balloon.surface)
289            return FALSE;
290    
291        gint xs, ys;
292        osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
293                                          priv->balloon.lat, priv->balloon.lon,
294                                          &xs, &ys);
295    
296        xs += priv->balloon.rect.x + priv->balloon.offset_x;
297        ys += priv->balloon.rect.y + priv->balloon.offset_y;
298    
299        gboolean is_in =
300            (x > xs) && (x < xs + priv->balloon.rect.w) &&
301            (y > ys) && (y < ys + priv->balloon.rect.h);
302    
303        /* handle the fact that the balloon may have been created by the */
304        /* button down event */
305        if(!is_in && !down && !priv->balloon.just_created) {
306            /* the user actually clicked outside the balloon */
307    
308            /* close the balloon! */
309            osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget));
310        }
311    
312        return is_in;
313    }
314    
315    void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) {
316        g_return_if_fail (OSM_IS_GPS_MAP (map));
317    
318        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
319        g_return_if_fail (osd);
320    
321        osd_priv_t *priv = (osd_priv_t*)osd->priv;
322        g_return_if_fail (priv);
323    
324        if(priv->balloon.surface) {
325            cairo_surface_destroy(priv->balloon.surface);
326            priv->balloon.surface = NULL;
327            priv->balloon.lat = OSM_GPS_MAP_INVALID;
328            priv->balloon.lon = OSM_GPS_MAP_INVALID;
329        }
330        osm_gps_map_redraw(map);
331    }
332    
333    void
334    osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
335                                  OsmGpsMapBalloonCallback cb, gpointer data) {
336        g_return_if_fail (OSM_IS_GPS_MAP (map));
337    
338        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
339        g_return_if_fail (osd);
340    
341        osd_priv_t *priv = (osd_priv_t*)osd->priv;
342        g_return_if_fail (priv);
343    
344        osm_gps_map_osd_clear_balloon (map);
345    
346        /* allocate balloon surface */
347        priv->balloon.surface =
348            cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
349                                       BALLOON_W+2, BALLOON_H+2);
350    
351        priv->balloon.lat = latitude;
352        priv->balloon.lon = longitude;
353        priv->balloon.cb = cb;
354        priv->balloon.data = data;
355        priv->balloon.just_created = TRUE;
356    
357        priv->balloon.orientation = -1;
358    
359        osd_render_balloon(osd);
360    
361        osm_gps_map_redraw(map);
362    }
363    
364    #endif // OSD_BALLOON
365    
366  /* position and extent of bounding box */  /* position and extent of bounding box */
367  #ifndef OSD_X  #ifndef OSD_X
368  #define OSD_X      (10)  #define OSD_X      (10)
# Line 416  osd_source_content(osm_gps_map_osd_t *os Line 700  osd_source_content(osm_gps_map_osd_t *os
700  }  }
701    
702  static void  static void
703  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
704      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
705    
706        if(priv->source_sel.rendered && !force_rerender)
707            return;
708    
709        priv->source_sel.rendered = TRUE;
710    
711  #ifndef OSD_COLOR  #ifndef OSD_COLOR
712      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
713      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 503  osd_source_reallocate(osm_gps_map_osd_t Line 792  osd_source_reallocate(osm_gps_map_osd_t
792      priv->source_sel.surface =      priv->source_sel.surface =
793          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
794    
795      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
796  }  }
797    
798  #define OSD_HZ      15  #define OSD_HZ      15
# Line 535  static gboolean osd_source_animate(gpoin Line 824  static gboolean osd_source_animate(gpoin
824    
825      /* count runs linearly from 0 to 1000, map this nicely onto a position */      /* count runs linearly from 0 to 1000, map this nicely onto a position */
826    
827      /* nicer sinoid mapping */      /* nice sinoid mapping */
828      float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;      float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
829      priv->source_sel.shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
830            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
831          m * diff;          m * diff;
832    
833        /* make sure the screen is updated */
834      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
835    
836        /* stop animation if done */
837      if(done)      if(done)
838          priv->source_sel.handler_id = 0;          priv->source_sel.handler_id = 0;
839    
# Line 558  osd_source_toggle(osm_gps_map_osd_t *osd Line 850  osd_source_toggle(osm_gps_map_osd_t *osd
850      if(priv->source_sel.handler_id)      if(priv->source_sel.handler_id)
851          return;          return;
852    
853      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
854        /* collapse animation */
855      if(!priv->source_sel.expanded) {      if(!priv->source_sel.expanded) {
856          priv->source_sel.expanded = TRUE;          priv->source_sel.expanded = TRUE;
857          osd_source_reallocate(osd);          osd_source_reallocate(osd);
# Line 568  osd_source_toggle(osm_gps_map_osd_t *osd Line 861  osd_source_toggle(osm_gps_map_osd_t *osd
861          priv->source_sel.dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
862      } else {      } else {
863          priv->source_sel.count =  0;          priv->source_sel.count =  0;
864          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
865                OSD_S_EXP_W + OSD_S_X;
866          priv->source_sel.dir = +1000/OSD_HZ;          priv->source_sel.dir = +1000/OSD_HZ;
867      }      }
868    
869      priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
870        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
871                                                      osd_source_animate, osd);
872  }  }
873    
874  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
875  static osd_button_t  static osd_button_t
876  osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
877      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
878    
879      if(!priv->source_sel.expanded)      if(!priv->source_sel.expanded)
# Line 595  osd_source_check(osm_gps_map_osd_t *osd, Line 891  osd_source_check(osm_gps_map_osd_t *osd,
891          /* really within puller shape? */          /* really within puller shape? */
892          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {          if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
893              /* expand source selector */              /* expand source selector */
894              osd_source_toggle(osd);              if(down)
895                    osd_source_toggle(osd);
896    
897              /* tell upper layers that user clicked some background element */              /* tell upper layers that user clicked some background element */
898              /* of the OSD */              /* of the OSD */
# Line 621  osd_source_check(osm_gps_map_osd_t *osd, Line 918  osd_source_check(osm_gps_map_osd_t *osd,
918              y /= step;              y /= step;
919              y += 1;              y += 1;
920    
921              gint old = 0;              if(down) {
922              g_object_get(osd->widget, "map-source", &old, NULL);                  gint old = 0;
923                    g_object_get(osd->widget, "map-source", &old, NULL);
924              if(y > OSM_GPS_MAP_SOURCE_NULL &&  
925                 y <= OSM_GPS_MAP_SOURCE_LAST &&                  if(y > OSM_GPS_MAP_SOURCE_NULL &&
926                 old != y) {                     y <= OSM_GPS_MAP_SOURCE_LAST &&
927                  g_object_set(osd->widget, "map-source", y, NULL);                     old != y) {
928                        g_object_set(osd->widget, "map-source", y, NULL);
929                  osd_render_source_sel(osd);  
930                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                      osd_render_source_sel(osd, TRUE);
931                        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
932                    }
933              }              }
934    
935              /* return "clicked in OSD background" to prevent further */              /* return "clicked in OSD background" to prevent further */
# Line 644  osd_source_check(osm_gps_map_osd_t *osd, Line 943  osd_source_check(osm_gps_map_osd_t *osd,
943  #endif // OSD_SOURCE_SEL  #endif // OSD_SOURCE_SEL
944    
945  static osd_button_t  static osd_button_t
946  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) {
947      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
948    
949    #ifdef OSD_BALLOON
950        if(down) {
951            /* needed to handle balloons that are created at click */
952            osd_priv_t *priv = (osd_priv_t*)osd->priv;
953            priv->balloon.just_created = FALSE;
954        }
955    #endif
956    
957  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
958      /* the source selection area is handles internally */      /* the source selection area is handles internally */
959      but = osd_source_check(osd, x, y);      but = osd_source_check(osd, down, x, y);
     if(but != OSD_NONE)  
         return but;  
960  #endif  #endif
961    
962      x -= OSD_X;      if(but == OSD_NONE) {
963      y -= OSD_Y;          gint mx = x - OSD_X;
964            gint my = y - OSD_Y;
965      if(OSD_X < 0)  
966          x -= (osd->widget->allocation.width - OSD_W);          if(OSD_X < 0)
967                mx -= (osd->widget->allocation.width - OSD_W);
968      if(OSD_Y < 0)  
969          y -= (osd->widget->allocation.height - OSD_H);          if(OSD_Y < 0)
970                my -= (osd->widget->allocation.height - OSD_H);
971      /* first do a rough test for the OSD area. */  
972      /* this is just to avoid an unnecessary detailed test */          /* first do a rough test for the OSD area. */
973      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {          /* this is just to avoid an unnecessary detailed test */
974            if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) {
975  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
976          but = osd_check_dpad(x, y);              but = osd_check_dpad(mx, my);
977  #endif  #endif
978            }
979    
980          if(but == OSD_NONE)          if(but == OSD_NONE)
981              but = osd_check_zoom(x, y);              but = osd_check_zoom(mx, my);
982      }      }
983    
984    #ifdef OSD_BALLOON
985        if(but == OSD_NONE) {
986            /* check if user clicked into balloon */
987            if(osd_balloon_check(osd, down, x, y))
988                but = OSD_BG;
989        }
990    #endif
991    
992      return but;      return but;
993  }  }
994    
# Line 833  osd_render_coordinates(osm_gps_map_osd_t Line 1148  osd_render_coordinates(osm_gps_map_osd_t
1148      priv->coordinates.lat = lat;      priv->coordinates.lat = lat;
1149      priv->coordinates.lon = lon;      priv->coordinates.lon = lon;
1150    
1151      /* first fill with light transparency */      /* first fill with transparency */
1152      cairo_t *cr = cairo_create(priv->coordinates.surface);      cairo_t *cr = cairo_create(priv->coordinates.surface);
1153      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1154      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);
1155        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
1156      cairo_paint(cr);      cairo_paint(cr);
1157      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1158    
# Line 883  osd_render_coordinates(osm_gps_map_osd_t Line 1199  osd_render_coordinates(osm_gps_map_osd_t
1199  }  }
1200  #endif  // OSD_COORDINATES  #endif  // OSD_COORDINATES
1201    
1202    #ifdef OSD_NAV
1203    #define OSD_NAV_W  (100)
1204    #define OSD_NAV_H  (100)
1205    
1206    static void
1207    osd_render_nav(osm_gps_map_osd_t *osd)
1208    {
1209        osd_priv_t *priv = (osd_priv_t*)osd->priv;
1210    
1211        /* first fill with transparency */
1212        cairo_t *cr = cairo_create(priv->nav.surface);
1213        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1214        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
1215        cairo_paint(cr);
1216        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1217    
1218        cairo_destroy(cr);
1219    }
1220    
1221    #endif // OSD_NAV
1222    
1223    
1224  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1225    
1226  #ifndef OSD_CROSSHAIR_RADIUS  #ifndef OSD_CROSSHAIR_RADIUS
# Line 1191  osd_render_controls(osm_gps_map_osd_t *o Line 1529  osd_render_controls(osm_gps_map_osd_t *o
1529  static void  static void
1530  osd_render(osm_gps_map_osd_t *osd)  osd_render(osm_gps_map_osd_t *osd)
1531  {  {
1532        /* this function is actually called pretty often since the */
1533        /* OSD contents may have changed (due to a coordinate/zoom change). */
1534        /* The different OSD parts have to make sure that they don't */
1535        /* render unneccessarily often and thus waste CPU power */
1536    
1537      osd_render_controls(osd);      osd_render_controls(osd);
1538    
1539  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1540      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1541  #endif  #endif
1542    
1543  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1205  osd_render(osm_gps_map_osd_t *osd) Line 1548  osd_render(osm_gps_map_osd_t *osd)
1548      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1549  #endif  #endif
1550    
1551    #ifdef OSD_NAV
1552        osd_render_nav(osd);
1553    #endif
1554    
1555  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1556      osd_render_coordinates(osd);      osd_render_coordinates(osd);
1557  #endif  #endif
# Line 1232  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1579  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1579          priv->source_sel.surface =          priv->source_sel.surface =
1580              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1581                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1582            priv->source_sel.rendered = FALSE;
1583  #endif  #endif
1584    
1585  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 1248  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1596  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1596          priv->crosshair.rendered = FALSE;          priv->crosshair.rendered = FALSE;
1597  #endif  #endif
1598    
1599    #ifdef OSD_NAV
1600            priv->nav.surface =
1601                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1602                                           OSD_NAV_W, OSD_NAV_H);
1603    #endif
1604    
1605  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1606          priv->coordinates.surface =          priv->coordinates.surface =
1607              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
# Line 1263  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1617  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1617      // now draw this onto the original context      // now draw this onto the original context
1618      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1619    
1620      int x, y;      gint x, y;
1621    
1622  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1623      x =  OSD_X;      x =  OSD_X;
# Line 1283  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1637  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1637      cairo_paint(cr);      cairo_paint(cr);
1638  #endif  #endif
1639    
1640    #ifdef OSD_NAV
1641        x =  OSD_X;
1642        if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W;
1643        y = (osd->widget->allocation.height - OSD_NAV_H)/2;
1644    
1645        cairo_set_source_surface(cr, priv->nav.surface, x, y);
1646        cairo_paint(cr);
1647    #endif
1648    
1649  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1650      x = -OSD_X;      x = -OSD_X;
1651      y = -OSD_Y;      y = -OSD_Y;
# Line 1293  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1656  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1656      cairo_paint(cr);      cairo_paint(cr);
1657  #endif  #endif
1658    
1659    #ifdef OSD_BALLOON
1660        if(priv->balloon.surface) {
1661    
1662            /* convert given lat lon into screen coordinates */
1663            gint x, y;
1664            osm_gps_map_geographic_to_screen (OSM_GPS_MAP(osd->widget),
1665                                          priv->balloon.lat, priv->balloon.lon,
1666                                          &x, &y);
1667    
1668            /* check if balloon needs to be rerendered */
1669            osd_render_balloon(osd);
1670    
1671            cairo_set_source_surface(cr, priv->balloon.surface,
1672                                     x + priv->balloon.offset_x,
1673                                     y + priv->balloon.offset_y);
1674            cairo_paint(cr);
1675        }
1676    #endif
1677    
1678      x = OSD_X;      x = OSD_X;
1679      if(x < 0)      if(x < 0)
1680          x += osd->widget->allocation.width - OSD_W;          x += osd->widget->allocation.width - OSD_W;
# Line 1355  osd_free(osm_gps_map_osd_t *osd) Line 1737  osd_free(osm_gps_map_osd_t *osd)
1737           cairo_surface_destroy(priv->crosshair.surface);           cairo_surface_destroy(priv->crosshair.surface);
1738  #endif  #endif
1739    
1740    #ifdef OSD_NAV
1741        if (priv->nav.surface)
1742             cairo_surface_destroy(priv->nav.surface);
1743    #endif
1744    
1745  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
1746      if (priv->coordinates.surface)      if (priv->coordinates.surface)
1747           cairo_surface_destroy(priv->coordinates.surface);           cairo_surface_destroy(priv->coordinates.surface);
1748  #endif  #endif
1749    
1750    #ifdef OSD_BALLOON
1751        if (priv->balloon.surface)
1752             cairo_surface_destroy(priv->balloon.surface);
1753    #endif
1754    
1755      g_free(priv);      g_free(priv);
1756  }  }
1757    
# Line 1395  osm_gps_map_osd_classic_init(OsmGpsMap * Line 1787  osm_gps_map_osd_classic_init(OsmGpsMap *
1787  {  {
1788      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);
1789    
1790    #ifdef OSD_BALLOON
1791        priv->balloon.lat = OSM_GPS_MAP_INVALID;
1792        priv->balloon.lon = OSM_GPS_MAP_INVALID;
1793    #endif
1794    
1795      osd_classic.priv = priv;      osd_classic.priv = priv;
1796    
1797      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
# Line 1424  osm_gps_map_osd_check(OsmGpsMap *map, gi Line 1821  osm_gps_map_osd_check(OsmGpsMap *map, gi
1821      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
1822      g_return_val_if_fail (osd, OSD_NONE);      g_return_val_if_fail (osd, OSD_NONE);
1823    
1824      return osd_check(osd, x, y);      return osd_check(osd, TRUE, x, y);
1825  }  }

Legend:
Removed from v.110  
changed lines
  Added in v.122