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

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

revision 73 by harbaum, Sun Aug 23 19:38:15 2009 UTC revision 77 by harbaum, Tue Aug 25 12:49:03 2009 UTC
# Line 22  Line 22 
22  #include <math.h>    // M_PI  #include <math.h>    // M_PI
23    
24  /* parameters that can be overwritten from the config file: */  /* parameters that can be overwritten from the config file: */
25  /* OSM_GPS_MAP_OSD_DIAMETER */  /* OSD_DIAMETER */
26    /* OSD_X, OSD_Y */
27    
28  #ifndef USE_CAIRO  #ifndef USE_CAIRO
29  #error "OSD control display lacks a non-cairo implementation!"  #error "OSD control display lacks a non-cairo implementation!"
# Line 35  Line 36 
36    
37  //the osd controls  //the osd controls
38  typedef struct {  typedef struct {
39      GdkPixmap *backup;      /* the offscreen representation of the OSD */
     gint backup_x, backup_y;  
40      cairo_surface_t *overlay;      cairo_surface_t *overlay;
41  } osd_priv_t;  } osd_priv_t;
42    
43  /* position and extent of bounding box */  /* position and extent of bounding box */
44    #ifndef OSD_X
45  #define OSD_X      (10)  #define OSD_X      (10)
46  #define OSD_Y      (10)  #endif
47    
48  #define OSD_COLOR            0.5, 0.5, 1  #ifndef OSD_Y
49  #define OSD_COLOR_DISABLED   0.8, 0.8, 0.8  #define OSD_Y      (10)
50    #endif
51    
52  /* parameters of the direction shape */  /* parameters of the direction shape */
53  #ifndef OSM_GPS_MAP_OSD_DIAMETER  #ifndef OSD_DIAMETER
54  #define D_RAD  (30)         // diameter of dpad  #define D_RAD  (30)         // diameter of dpad
55  #else  #else
56  #define D_RAD  (OSM_GPS_MAP_OSD_DIAMETER)  #define D_RAD  (OSD_DIAMETER)
57  #endif  #endif
58  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center  #define D_TIP  (4*D_RAD/5)  // distance of arrow tip from dpad center
59  #define D_LEN  (D_RAD/4)    // length of arrow  #define D_LEN  (D_RAD/4)    // length of arrow
# Line 61  typedef struct { Line 63  typedef struct {
63  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom  #define Z_STEP   (D_RAD/4)  // distance between dpad and zoom
64  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar  #define Z_RAD    (D_RAD/2)  // radius of "caps" of zoom bar
65    
66    #ifdef OSD_SHADOW_ENABLE
67  /* shadow also depends on control size */  /* shadow also depends on control size */
68  #define OSD_SHADOW (D_RAD/6)  #define OSD_SHADOW (D_RAD/6)
69    #else
70    #define OSD_SHADOW (0)
71    #endif
72    
73    /* normally the GPS button is in the center of the dpad. if there's */
74    /* no dpad it will go into the zoom area */
75    #if defined(OSD_GPS_BUTTON) && defined(OSD_NO_DPAD)
76    #define Z_GPS  1
77    #else
78    #define Z_GPS  0
79    #endif
80    
81  /* total width and height of controls incl. shadow */  /* total width and height of controls incl. shadow */
82  #define OSD_W    (2*D_RAD + OSD_SHADOW)  #define OSD_W    (2*D_RAD + OSD_SHADOW + Z_GPS * 2 * Z_RAD)
83    #if !Z_GPS
84  #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)  #define OSD_H    (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW)
85    #else
86    #define OSD_H    (2*Z_RAD + OSD_SHADOW)
87    #endif
88    
89    #ifdef OSD_SHADOW_ENABLE
90  #define OSD_LBL_SHADOW (OSD_SHADOW/2)  #define OSD_LBL_SHADOW (OSD_SHADOW/2)
91    #endif
92    
93    #define Z_TOP    ((1-Z_GPS) * (2 * D_RAD + Z_STEP))
94    
 #define Z_TOP    (2 * D_RAD + Z_STEP)  
95  #define Z_MID    (Z_TOP + Z_RAD)  #define Z_MID    (Z_TOP + Z_RAD)
96  #define Z_BOT    (Z_MID + Z_RAD)  #define Z_BOT    (Z_MID + Z_RAD)
97  #define Z_LEFT   (Z_RAD)  #define Z_LEFT   (Z_RAD)
98  #define Z_RIGHT  (2 * D_RAD - Z_RAD)  #define Z_RIGHT  (2 * D_RAD - Z_RAD + Z_GPS * 2 * Z_RAD)
99    #define Z_CENTER ((Z_RIGHT + Z_LEFT)/2)
100    
101  /* create the cairo shape used for the zoom buttons */  /* create the cairo shape used for the zoom buttons */
102  static void  static void
# Line 88  osm_gps_map_osd_zoom_shape(cairo_t *cr, Line 109  osm_gps_map_osd_zoom_shape(cairo_t *cr,
109      cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);      cairo_arc     (cr, x+Z_LEFT,    y+Z_MID, Z_RAD,  M_PI/2, -M_PI/2);
110  }  }
111    
112    #ifndef OSD_NO_DPAD
113  /* create the cairo shape used for the dpad */  /* create the cairo shape used for the dpad */
114  static void  static void
115  osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y)  osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y)
116  {  {
117      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);      cairo_arc (cr, x+D_RAD, y+D_RAD, D_RAD, 0, 2 * M_PI);
118  }  }
119    #endif
120    
121  static gboolean  static gboolean
122  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)  osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad)
# Line 101  osm_gps_map_in_circle(gint x, gint y, gi Line 124  osm_gps_map_in_circle(gint x, gint y, gi
124      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);      return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad);
125  }  }
126    
127    #ifndef OSD_NO_DPAD
128  /* check whether x/y is within the dpad */  /* check whether x/y is within the dpad */
129  static osd_button_t  static osd_button_t
130  osm_gps_map_osd_check_dpad(gint x, gint y)  osm_gps_map_osd_check_dpad(gint x, gint y)
131  {  {
132      /* within entire dpad circle */      /* within entire dpad circle */
133      if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD))      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))
134      {      {
135          /* convert into position relative to dpads centre */          /* convert into position relative to dpads centre */
136          x -= (OSD_X + D_RAD);          x -= D_RAD;
137          y -= (OSD_Y + D_RAD);          y -= D_RAD;
138    
139    #ifdef OSD_GPS_BUTTON
140          /* check for dpad center goes here! */          /* check for dpad center goes here! */
141          if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))          if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3))
142              return OSD_GPS;              return OSD_GPS;
143    #endif
144    
145          if( y < 0 && abs(x) < abs(y))          if( y < 0 && abs(x) < abs(y))
146              return OSD_UP;              return OSD_UP;
# Line 132  osm_gps_map_osd_check_dpad(gint x, gint Line 158  osm_gps_map_osd_check_dpad(gint x, gint
158      }      }
159      return OSD_NONE;      return OSD_NONE;
160  }  }
161    #endif
162    
163  /* check whether x/y is within the zoom pads */  /* check whether x/y is within the zoom pads */
164  static osd_button_t  static osd_button_t
165  osm_gps_map_osd_check_zoom(gint x, gint y) {  osm_gps_map_osd_check_zoom(gint x, gint y) {
166      if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) {      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {
167    
168          /* within circle around (-) label */          /* within circle around (-) label */
169          if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD))          if( osm_gps_map_in_circle(x, y, Z_LEFT, Z_MID, Z_RAD))
             return OSD_OUT;  
   
         /* between center of (-) button and center of entire zoom control area */  
         if(x > OSD_LEFT && x < OSD_X + D_RAD)  
170              return OSD_OUT;              return OSD_OUT;
171    
172          /* within circle around (+) label */          /* within circle around (+) label */
173          if( osm_gps_map_in_circle(x, y, OSD_X + Z_RIGHT, OSD_Y + Z_MID, Z_RAD))          if( osm_gps_map_in_circle(x, y, Z_RIGHT, Z_MID, Z_RAD))
174              return OSD_IN;              return OSD_IN;
175    
176    #if Z_GPS == 1
177            /* within square around center */
178            if( x > Z_CENTER - Z_RAD && x < Z_CENTER + Z_RAD)
179                return OSD_GPS;
180    #endif
181    
182            /* between center of (-) button and center of entire zoom control area */
183            if(x > OSD_LEFT && x < D_RAD)
184                return OSD_OUT;
185    
186          /* between center of (+) button and center of entire zoom control area */          /* between center of (+) button and center of entire zoom control area */
187          if(x < OSD_RIGHT && x > OSD_X + D_RAD)          if(x < OSD_RIGHT && x > D_RAD)
188              return OSD_IN;              return OSD_IN;
189      }      }
190    
# Line 159  osm_gps_map_osd_check_zoom(gint x, gint Line 192  osm_gps_map_osd_check_zoom(gint x, gint
192  }  }
193    
194  static osd_button_t  static osd_button_t
195  osm_gps_map_osd_check(gint x, gint y) {  osm_gps_map_osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {
196      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
197    
198        x -= OSD_X;
199        y -= OSD_Y;
200    
201        if(OSD_X < 0)
202            x -= (osd->widget->allocation.width - OSD_W);
203    
204        if(OSD_Y < 0)
205            y -= (osd->widget->allocation.height - OSD_H);
206    
207      /* first do a rough test for the OSD area. */      /* first do a rough test for the OSD area. */
208      /* this is just to avoid an unnecessary detailed test */      /* this is just to avoid an unnecessary detailed test */
209      if(x > OSD_X && x < OSD_X + OSD_W &&      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {
210         y > OSD_Y && y < OSD_Y + OSD_H) {  #ifndef OSD_NO_DPAD
211          but = osm_gps_map_osd_check_dpad(x, y);          but = osm_gps_map_osd_check_dpad(x, y);
212    #endif
213    
214          if(but == OSD_NONE)          if(but == OSD_NONE)
215              but = osm_gps_map_osd_check_zoom(x, y);              but = osm_gps_map_osd_check_zoom(x, y);
# Line 175  osm_gps_map_osd_check(gint x, gint y) { Line 218  osm_gps_map_osd_check(gint x, gint y) {
218      return but;      return but;
219  }  }
220    
221    #ifdef OSD_SHADOW_ENABLE
222  static void  static void
223  osm_gps_map_osd_shape_shadow(cairo_t *cr) {  osm_gps_map_osd_shape_shadow(cairo_t *cr) {
224      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);      cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
225      cairo_fill (cr);      cairo_fill (cr);
226      cairo_stroke (cr);      cairo_stroke (cr);
227  }  }
228    #endif
229    
230    #ifndef OSD_COLOR
231    /* if no color has been specified we just use the gdks default colors */
232    static void
233    osm_gps_map_osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {
234        gdk_cairo_set_source_color(cr, bg);
235        cairo_fill_preserve (cr);
236        gdk_cairo_set_source_color(cr, fg);
237        cairo_set_line_width (cr, 1);
238        cairo_stroke (cr);
239    }
240    #else
241  static void  static void
242  osm_gps_map_osd_shape(cairo_t *cr) {  osm_gps_map_osd_shape(cairo_t *cr) {
243      cairo_set_source_rgb (cr, 1, 1, 1);      cairo_set_source_rgb (cr, OSD_COLOR_BG);
244      cairo_fill_preserve (cr);      cairo_fill_preserve (cr);
245      cairo_set_source_rgb (cr, OSD_COLOR);      cairo_set_source_rgb (cr, OSD_COLOR);
246      cairo_set_line_width (cr, 1);      cairo_set_line_width (cr, 1);
247      cairo_stroke (cr);      cairo_stroke (cr);
248  }  }
249    #endif
250    
251    #ifndef OSD_NO_DPAD
252  static void  static void
253  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {
254      /* move reference to dpad center */      /* move reference to dpad center */
# Line 215  osm_gps_map_osd_dpad_labels(cairo_t *cr, Line 273  osm_gps_map_osd_dpad_labels(cairo_t *cr,
273          cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);          cairo_rel_line_to (cr, offset[i][2][0], offset[i][2][1]);
274      }      }
275  }  }
276    #endif
277    
278  /* draw the sattelite dish icon in the center of the dpad */  #ifdef OSD_GPS_BUTTON
279  #define GPS_V0  (D_RAD/8)  /* draw the satellite dish icon in the center of the dpad */
280    #define GPS_V0  (D_RAD/7)
281  #define GPS_V1  (D_RAD/10)  #define GPS_V1  (D_RAD/10)
282  #define GPS_V2  (D_RAD/5)  #define GPS_V2  (D_RAD/5)
283    
284  /* draw a satellite receiver dish */  /* draw a satellite receiver dish */
285    /* this is either drawn in the center of the dpad (if present) */
286    /* or in the middle of the zoom area */
287  static void  static void
288  osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {  osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {
289      /* move reference to dpad center */      /* move reference to dpad center */
290      x += D_RAD;      x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;
291      y += D_RAD + GPS_V0;      y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;
292    
293      cairo_move_to (cr, x-GPS_V0, y+GPS_V0);      cairo_move_to (cr, x-GPS_V0, y+GPS_V0);
294      cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);      cairo_rel_line_to (cr, +GPS_V0, -GPS_V0);
# Line 241  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi Line 303  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi
303      cairo_move_to (cr, x, y-GPS_V2);      cairo_move_to (cr, x, y-GPS_V2);
304      cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);      cairo_rel_line_to (cr, +GPS_V1, -GPS_V1);
305  }  }
306    #endif
307    
308  #define Z_LEN  (2*Z_RAD/3)  #define Z_LEN  (2*Z_RAD/3)
309    
# Line 255  osm_gps_map_osd_zoom_labels(cairo_t *cr, Line 318  osm_gps_map_osd_zoom_labels(cairo_t *cr,
318      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
319  }  }
320    
321    #ifndef OSD_COLOR
322    /* if no color has been specified we just use the gdks default colors */
323    static void
324    osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled,
325                           GdkColor *fg, GdkColor *disabled) {
326        if(enabled)  gdk_cairo_set_source_color(cr, fg);
327        else         gdk_cairo_set_source_color(cr, disabled);
328        cairo_set_line_width (cr, width);
329        cairo_stroke (cr);
330    }
331    #else
332  static void  static void
333  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {
334      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);      if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
# Line 262  osm_gps_map_osd_labels(cairo_t *cr, gint Line 336  osm_gps_map_osd_labels(cairo_t *cr, gint
336      cairo_set_line_width (cr, width);      cairo_set_line_width (cr, width);
337      cairo_stroke (cr);      cairo_stroke (cr);
338  }  }
339    #endif
340    
341    #ifdef OSD_SHADOW_ENABLE
342  static void  static void
343  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {  osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
344      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);      cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
345      cairo_set_line_width (cr, width);      cairo_set_line_width (cr, width);
346      cairo_stroke (cr);      cairo_stroke (cr);
347  }  }
348    #endif
349    
350  static void  static void
351  osm_gps_map_osd_render(osm_gps_map_osd_t *osd) {  osm_gps_map_osd_render(osm_gps_map_osd_t *osd) {
# Line 280  osm_gps_map_osd_render(osm_gps_map_osd_t Line 357  osm_gps_map_osd_render(osm_gps_map_osd_t
357      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);
358      cairo_paint(cr);      cairo_paint(cr);
359    
360    #ifndef OSD_COLOR
361        GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
362        GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
363        GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
364    #endif
365    
366      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
367    
368      /* --------- draw zoom and dpad shape shadow ----------- */      /* --------- draw zoom and dpad shape shadow ----------- */
369      gint x = 0, y = 0;      gint x = 0, y = 0;
370    
371    #ifdef OSD_SHADOW_ENABLE
372      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
373      osm_gps_map_osd_shape_shadow(cr);      osm_gps_map_osd_shape_shadow(cr);
374    #ifndef OSD_NO_DPAD
375      osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);
376      osm_gps_map_osd_shape_shadow(cr);      osm_gps_map_osd_shape_shadow(cr);
377    #endif
378    #endif
379    
380      /* --------- draw zoom and dpad shape ----------- */      /* --------- draw zoom and dpad shape ----------- */
381    
382      osm_gps_map_osd_zoom_shape(cr, x, y);      osm_gps_map_osd_zoom_shape(cr, x, y);
383    #ifndef OSD_COLOR
384        osm_gps_map_osd_shape(cr, &bg, &fg);
385    #else
386      osm_gps_map_osd_shape(cr);      osm_gps_map_osd_shape(cr);
387    #endif
388    #ifndef OSD_NO_DPAD
389      osm_gps_map_osd_dpad_shape(cr, x, y);      osm_gps_map_osd_dpad_shape(cr, x, y);
390    #ifndef OSD_COLOR
391        osm_gps_map_osd_shape(cr, &bg, &fg);
392    #else
393      osm_gps_map_osd_shape(cr);      osm_gps_map_osd_shape(cr);
394    #endif
395    #endif
396    
397      /* --------- draw zoom and dpad labels --------- */      /* --------- draw zoom and dpad labels --------- */
398    
399    #ifdef OSD_SHADOW_ENABLE
400      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
401    #ifndef OSD_NO_DPAD
402      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
403    #endif
404      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);
405    #ifdef OSD_GPS_BUTTON
406      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);
407      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);
408    #endif
409    #endif
410    
411      osm_gps_map_osd_zoom_labels(cr, x, y);      osm_gps_map_osd_zoom_labels(cr, x, y);
412    #ifndef OSD_NO_DPAD
413      osm_gps_map_osd_dpad_labels(cr, x, y);      osm_gps_map_osd_dpad_labels(cr, x, y);
414    #endif
415    #ifndef OSD_COLOR
416        osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
417    #else
418      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);
419    #endif
420    #ifdef OSD_GPS_BUTTON
421      osm_gps_map_osd_dpad_gps(cr, x, y);      osm_gps_map_osd_dpad_gps(cr, x, y);
422    #ifndef OSD_COLOR
423        osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);
424    #else
425      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL);      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL);
426    #endif
427    #endif
428    
429      cairo_destroy(cr);      cairo_destroy(cr);
430  }  }
431    
432  static void  static void
433  osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, gint xoffset, gint yoffset)  osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)
434  {  {
435      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
436    
     /* backup previous contents */  
     if(!priv->backup)  
         priv->backup = gdk_pixmap_new(osd->pixmap, OSD_W+2, OSD_H+2, -1);  
   
     gint x = OSD_X + xoffset;  
     gint y = OSD_Y + yoffset;  
   
     /* create backup of background */  
     gdk_draw_drawable(priv->backup,  
         osd->widget->style->fg_gc[GTK_WIDGET_STATE(osd->widget)],  
                       osd->pixmap, x-1, y-1, 0, 0, OSD_W+2, OSD_H+2);  
   
     priv->backup_x = x-1;  
     priv->backup_y = y-1;  
   
437      /* OSD itself uses some off-screen rendering, so check if the */      /* OSD itself uses some off-screen rendering, so check if the */
438      /* offscreen buffer is present and create it if not */      /* offscreen buffer is present and create it if not */
439      if(!priv->overlay) {      if(!priv->overlay) {
# Line 345  osm_gps_map_osd_draw(osm_gps_map_osd_t * Line 445  osm_gps_map_osd_draw(osm_gps_map_osd_t *
445      }      }
446    
447      // now draw this onto the original context      // now draw this onto the original context
448      cairo_t *cr = gdk_cairo_create(osd->pixmap);      cairo_t *cr = gdk_cairo_create(drawable);
449    
450        int x = OSD_X, y = OSD_Y;
451        if(OSD_X < 0)
452            x = osd->widget->allocation.width - OSD_W + OSD_X;
453    
454        if(OSD_Y < 0)
455            y = osd->widget->allocation.height - OSD_H + OSD_Y;
456    
457      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->overlay, x, y);
458      cairo_paint(cr);      cairo_paint(cr);
459      cairo_destroy(cr);      cairo_destroy(cr);
460  }  }
461    
462  static void  static void
 osm_gps_map_osd_restore (osm_gps_map_osd_t *osd)  
 {  
     osd_priv_t *priv = (osd_priv_t*)osd->priv;  
   
     /* restore backup of previous contents */  
     if(priv->backup) {  
         /* create backup of background */  
         gdk_draw_drawable(osd->pixmap,  
                           osd->widget->style->fg_gc[GTK_WIDGET_STATE(osd->widget)],  
                           priv->backup, 0, 0,  
                           priv->backup_x, priv->backup_y, OSD_W+2, OSD_H+2);  
     }  
 }  
   
 static void  
463  osm_gps_map_osd_free(osm_gps_map_osd_t *osd)  osm_gps_map_osd_free(osm_gps_map_osd_t *osd)
464  {  {
465      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
466    
     if (priv->backup)  
         g_object_unref(priv->backup);  
   
467      if (priv->overlay)      if (priv->overlay)
468           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->overlay);
469    
# Line 381  osm_gps_map_osd_free(osm_gps_map_osd_t * Line 471  osm_gps_map_osd_free(osm_gps_map_osd_t *
471  }  }
472    
473  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
     .restore    = osm_gps_map_osd_restore,  
474      .draw       = osm_gps_map_osd_draw,      .draw       = osm_gps_map_osd_draw,
475      .check      = osm_gps_map_osd_check,      .check      = osm_gps_map_osd_check,
476      .render     = osm_gps_map_osd_render,      .render     = osm_gps_map_osd_render,
# Line 404  osm_gps_map_osd_classic_init(OsmGpsMap * Line 493  osm_gps_map_osd_classic_init(OsmGpsMap *
493      osm_gps_map_register_osd(map, &osd_classic);      osm_gps_map_register_osd(map, &osd_classic);
494  }  }
495    
496    #ifdef OSD_GPS_BUTTON
497  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, gpointer data) {  /* below are osd specific functions which aren't used by osm-gps-map */
498    /* but instead are to be used by the main application */
499    void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
500                                     gpointer data) {
501      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
502    
503      g_return_if_fail (osd);      g_return_if_fail (osd);
# Line 419  void osm_gps_map_osd_enable_gps (OsmGpsM Line 511  void osm_gps_map_osd_enable_gps (OsmGpsM
511    
512      osm_gps_map_redraw(map);      osm_gps_map_redraw(map);
513  }  }
514    #endif

Legend:
Removed from v.73  
changed lines
  Added in v.77