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

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

revision 85 by harbaum, Tue Aug 25 12:49:03 2009 UTC revision 86 by harbaum, Sun Aug 30 19:05:44 2009 UTC
# Line 21  Line 21 
21  #include <stdlib.h>  // abs  #include <stdlib.h>  // abs
22  #include <math.h>    // M_PI  #include <math.h>    // M_PI
23    
24    #define OSD_SOURCE_SEL
25    
26    #define OSD_Y  (-10)
27    
28  /* parameters that can be overwritten from the config file: */  /* parameters that can be overwritten from the config file: */
29  /* OSD_DIAMETER */  /* OSD_DIAMETER */
30  /* OSD_X, OSD_Y */  /* OSD_X, OSD_Y */
# Line 38  Line 42 
42  typedef struct {  typedef struct {
43      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
44      cairo_surface_t *overlay;      cairo_surface_t *overlay;
45    
46        cairo_surface_t *map_source;
47        gboolean expanded;
48        gint shift, dir, count;
49        gint handler_id;
50  } osd_priv_t;  } osd_priv_t;
51    
52  /* position and extent of bounding box */  /* position and extent of bounding box */
# Line 100  typedef struct { Line 109  typedef struct {
109    
110  /* create the cairo shape used for the zoom buttons */  /* create the cairo shape used for the zoom buttons */
111  static void  static void
112  osm_gps_map_osd_zoom_shape(cairo_t *cr, gint x, gint y)  osd_zoom_shape(cairo_t *cr, gint x, gint y)
113  {  {
114      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);      cairo_move_to (cr, x+Z_LEFT,    y+Z_TOP);
115      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);      cairo_line_to (cr, x+Z_RIGHT,   y+Z_TOP);
# Line 109  osm_gps_map_osd_zoom_shape(cairo_t *cr, Line 118  osm_gps_map_osd_zoom_shape(cairo_t *cr,
118      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);
119  }  }
120    
121    /* ------------------- color/shadow functions ----------------- */
122    
123    #ifndef OSD_COLOR
124    /* if no color has been specified we just use the gdks default colors */
125    static void
126    osd_labels(cairo_t *cr, gint width, gboolean enabled,
127                           GdkColor *fg, GdkColor *disabled) {
128        if(enabled)  gdk_cairo_set_source_color(cr, fg);
129        else         gdk_cairo_set_source_color(cr, disabled);
130        cairo_set_line_width (cr, width);
131        cairo_stroke (cr);
132    }
133    #else
134    static void
135    osd_labels(cairo_t *cr, gint width, gboolean enabled) {
136        if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);
137        else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);
138        cairo_set_line_width (cr, width);
139        cairo_stroke (cr);
140    }
141    #endif
142    
143    #ifdef OSD_SHADOW_ENABLE
144    static void
145    osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {
146        cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);
147        cairo_set_line_width (cr, width);
148        cairo_stroke (cr);
149    }
150    #endif
151    
152  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
153  /* create the cairo shape used for the dpad */  /* create the cairo shape used for the dpad */
154  static void  static void
155  osm_gps_map_osd_dpad_shape(cairo_t *cr, gint x, gint y)  osd_dpad_shape(cairo_t *cr, gint x, gint y)
156  {  {
157      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);
158  }  }
159  #endif  #endif
160    
161    #ifdef OSD_SHADOW_ENABLE
162    static void
163    osd_shape_shadow(cairo_t *cr) {
164        cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
165        cairo_fill (cr);
166        cairo_stroke (cr);
167    }
168    #endif
169    
170    #ifndef OSD_COLOR
171    /* if no color has been specified we just use the gdks default colors */
172    static void
173    osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {
174        gdk_cairo_set_source_color(cr, bg);
175        cairo_fill_preserve (cr);
176        gdk_cairo_set_source_color(cr, fg);
177        cairo_set_line_width (cr, 1);
178        cairo_stroke (cr);
179    }
180    #else
181    static void
182    osd_shape(cairo_t *cr) {
183        cairo_set_source_rgb (cr, OSD_COLOR_BG);
184        cairo_fill_preserve (cr);
185        cairo_set_source_rgb (cr, OSD_COLOR);
186        cairo_set_line_width (cr, 1);
187        cairo_stroke (cr);
188    }
189    #endif
190    
191    
192  static gboolean  static gboolean
193  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)
194  {  {
# Line 127  osm_gps_map_in_circle(gint x, gint y, gi Line 198  osm_gps_map_in_circle(gint x, gint y, gi
198  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
199  /* check whether x/y is within the dpad */  /* check whether x/y is within the dpad */
200  static osd_button_t  static osd_button_t
201  osm_gps_map_osd_check_dpad(gint x, gint y)  osd_check_dpad(gint x, gint y)
202  {  {
203      /* within entire dpad circle */      /* within entire dpad circle */
204      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))      if( osm_gps_map_in_circle(x, y, D_RAD, D_RAD, D_RAD))
# Line 162  osm_gps_map_osd_check_dpad(gint x, gint Line 233  osm_gps_map_osd_check_dpad(gint x, gint
233    
234  /* check whether x/y is within the zoom pads */  /* check whether x/y is within the zoom pads */
235  static osd_button_t  static osd_button_t
236  osm_gps_map_osd_check_zoom(gint x, gint y) {  osd_check_zoom(gint x, gint y) {
237      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {      if( x > 0 && x < OSD_W && y > Z_TOP && y < Z_BOT) {
238    
239          /* within circle around (-) label */          /* within circle around (-) label */
# Line 191  osm_gps_map_osd_check_zoom(gint x, gint Line 262  osm_gps_map_osd_check_zoom(gint x, gint
262      return OSD_NONE;      return OSD_NONE;
263  }  }
264    
265    /* place source selection at right border */
266    #define OSD_S_RAD (Z_RAD)
267    #define OSD_S_X   (-OSD_X)
268    #define OSD_S_Y   (OSD_Y)
269    #define OSD_S_PW  (2 * Z_RAD)
270    #define OSD_S_W   (OSD_S_PW)
271    #define OSD_S_PH  (2 * Z_RAD)
272    #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
273    
274    /* size of usable area when exapnded */
275    #define OSD_S_AREA_W (200)
276    #define OSD_S_AREA_H (200)
277    #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
278    #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
279    
280    /* internal value to draw the arrow on the "puller" */
281    #define OSD_S_D0  (OSD_S_RAD/2)
282    
283    static void
284    osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
285        if(!priv->expanded) {
286            /* just draw the puller */
287            cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
288            cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
289            cairo_line_to (cr, x + OSD_S_PW, y);
290        } else {
291            /* draw the puller and the area itself */
292            cairo_move_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y + OSD_S_AREA_H);
293            cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H);
294            if(OSD_S_Y > 0) {
295                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_PH);
296                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
297            } else {
298                cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_AREA_H-OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
299                cairo_line_to (cr, x + OSD_S_PW, y + OSD_S_AREA_H - OSD_S_PH);
300                cairo_line_to (cr, x + OSD_S_PW, y);
301            }
302            cairo_line_to (cr, x + OSD_S_PW + OSD_S_AREA_W, y);
303            cairo_close_path (cr);
304        }
305    }
306    
307    static void
308    osd_source_content(osd_priv_t *priv, cairo_t *cr, gint x, gint y) {
309        y += OSD_S_RAD - OSD_S_D0;
310    
311        if(!priv->expanded) {
312            /* draw the "puller" open (<) arrow */
313            cairo_move_to (cr, x + OSD_S_RAD + OSD_S_D0/2, y);
314            cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
315            cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
316        } else {
317            if(OSD_S_Y < 0)
318                y += OSD_S_AREA_H - OSD_S_PH;
319    
320            /* draw the "puller" close (>) arrow */
321            cairo_move_to (cr, x + OSD_S_RAD - OSD_S_D0/2, y);
322            cairo_rel_line_to (cr, +OSD_S_D0, +OSD_S_D0);
323            cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
324        }
325    }
326    
327    static void
328    osd_render_source_sel(osm_gps_map_osd_t *osd) {
329        osd_priv_t *priv = (osd_priv_t*)osd->priv;
330    
331    #ifndef OSD_COLOR
332        GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
333        GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
334        GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
335    #endif
336    
337        /* draw source selector */
338        cairo_t *cr = cairo_create(priv->map_source);
339        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
340        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
341        cairo_paint(cr);
342        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
343    
344    #ifdef OSD_SHADOW_ENABLE
345        osd_source_shape(priv, cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
346        osd_shape_shadow(cr);
347    #endif
348    
349        osd_source_shape(priv, cr, 1, 1);
350    #ifndef OSD_COLOR
351        osd_shape(cr, &bg, &fg);
352    #else
353        osd_shape(cr);
354    #endif
355    
356    #ifdef OSD_SHADOW_ENABLE
357        osd_source_content(priv, cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
358        osd_labels_shadow(cr, Z_RAD/3, TRUE);
359    #endif
360        osd_source_content(priv, cr, 1, 1);
361    #ifndef OSD_COLOR
362        osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
363    #else
364        osd_labels(cr, Z_RAD/3, TRUE);
365    #endif
366    
367        cairo_destroy(cr);
368    }
369    
370    static void
371    osd_source_reallocate(osm_gps_map_osd_t *osd) {
372        osd_priv_t *priv = (osd_priv_t*)osd->priv;
373    
374        /* re-allocate offscreen bitmap */
375        g_assert (priv->map_source);
376        cairo_surface_destroy(priv->map_source);
377    
378        int w = OSD_S_W, h = OSD_S_H;
379        if(priv->expanded) {
380            w = OSD_S_EXP_W;
381            h = OSD_S_EXP_H;
382        }
383    
384        priv->map_source =
385            cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
386    
387        osd_render_source_sel(osd);
388    
389    }
390    
391    #define OSD_HZ      15
392    #define OSD_TIME    1000
393    
394    static gboolean osd_source_animate(gpointer data) {
395        osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data;
396        osd_priv_t *priv = (osd_priv_t*)osd->priv;
397        int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
398        gboolean done = FALSE;
399        priv->count += priv->dir;
400    
401        /* shifting in */
402        if(priv->dir < 0) {
403            if(priv->count <= 0) {
404                priv->count = 0;
405                done = TRUE;
406            }
407        } else {
408            if(priv->count >= 1000) {
409                priv->expanded = FALSE;
410                osd_source_reallocate(osd);
411    
412                priv->count = 1000;
413                done = TRUE;
414            }
415        }
416    
417    
418        /* count runs linearly from 0 to 1000, map this nicely onto a position */
419    
420        /* simple linear mapping */
421        //    priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
422        //        (diff * priv->count)/1000;
423    
424        /* nicer sinoid mapping */
425        float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;
426        priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
427            m * diff;
428    
429        osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
430    
431        if(done)
432            priv->handler_id = 0;
433    
434        return !done;
435    }
436    
437    /* switch between expand and collapse mode of source selection */
438    static void
439    osd_source_toggle(osm_gps_map_osd_t *osd)
440    {
441        osd_priv_t *priv = (osd_priv_t*)osd->priv;
442    
443        /* ignore clicks while animation is running */
444        if(priv->handler_id)
445            return;
446    
447        /* expand immediately, collapse is handle at the end of the collapse animation */
448        if(!priv->expanded) {
449            priv->expanded = TRUE;
450            osd_source_reallocate(osd);
451    
452            priv->count = 1000;
453            priv->shift = osd->widget->allocation.width - OSD_S_W;
454            priv->dir = -1000/OSD_HZ;
455        } else {
456            priv->count =  0;
457            priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
458            priv->dir = +1000/OSD_HZ;
459        }
460    
461        priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);
462    }
463    
464    static osd_button_t
465    osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) {
466        osd_priv_t *priv = (osd_priv_t*)osd->priv;
467    
468        if(!priv->expanded)
469            x -= osd->widget->allocation.width - OSD_S_W;
470        else
471            x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
472    
473        if(OSD_S_Y > 0)
474            y -= OSD_S_Y;
475        else
476            y -= osd->widget->allocation.height - OSD_S_PH + OSD_S_Y;
477    
478        /* within square around puller? */
479        if(y > 0 && y < OSD_S_PH && x > 0 && x < OSD_S_PW) {
480            /* really within puller shape? */
481            if(x > Z_RAD || osm_gps_map_in_circle(x, y, Z_RAD, Z_RAD, Z_RAD)) {
482                /* expand source selector */
483                osd_source_toggle(osd);
484    
485                /* tell upper layers that user clicked some background element */
486                /* of the OSD */
487                return OSD_BG;
488            }
489        }
490        return OSD_NONE;
491    }
492    
493  static osd_button_t  static osd_button_t
494  osm_gps_map_osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {
495      osd_button_t but = OSD_NONE;      osd_button_t but = OSD_NONE;
496    
497    #ifdef OSD_SOURCE_SEL
498        /* the source selection area is handles internally */
499        but = osd_source_check(osd, x, y);
500        if(but != OSD_NONE)
501            return but;
502    #endif
503    
504      x -= OSD_X;      x -= OSD_X;
505      y -= OSD_Y;      y -= OSD_Y;
506    
# Line 208  osm_gps_map_osd_check(osm_gps_map_osd_t Line 514  osm_gps_map_osd_check(osm_gps_map_osd_t
514      /* this is just to avoid an unnecessary detailed test */      /* this is just to avoid an unnecessary detailed test */
515      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {      if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) {
516  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
517          but = osm_gps_map_osd_check_dpad(x, y);          but = osd_check_dpad(x, y);
518  #endif  #endif
519    
520          if(but == OSD_NONE)          if(but == OSD_NONE)
521              but = osm_gps_map_osd_check_zoom(x, y);              but = osd_check_zoom(x, y);
522      }      }
523    
524      return but;      return but;
525  }  }
526    
 #ifdef OSD_SHADOW_ENABLE  
 static void  
 osm_gps_map_osd_shape_shadow(cairo_t *cr) {  
     cairo_set_source_rgba (cr, 0, 0, 0, 0.2);  
     cairo_fill (cr);  
     cairo_stroke (cr);  
 }  
 #endif  
   
 #ifndef OSD_COLOR  
 /* if no color has been specified we just use the gdks default colors */  
 static void  
 osm_gps_map_osd_shape(cairo_t *cr, GdkColor *bg, GdkColor *fg) {  
     gdk_cairo_set_source_color(cr, bg);  
     cairo_fill_preserve (cr);  
     gdk_cairo_set_source_color(cr, fg);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
 }  
 #else  
 static void  
 osm_gps_map_osd_shape(cairo_t *cr) {  
     cairo_set_source_rgb (cr, OSD_COLOR_BG);  
     cairo_fill_preserve (cr);  
     cairo_set_source_rgb (cr, OSD_COLOR);  
     cairo_set_line_width (cr, 1);  
     cairo_stroke (cr);  
 }  
 #endif  
   
527  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
528  static void  static void
529  osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) {  osd_dpad_labels(cairo_t *cr, gint x, gint y) {
530      /* move reference to dpad center */      /* move reference to dpad center */
531      x += D_RAD;      x += D_RAD;
532      y += D_RAD;      y += D_RAD;
# Line 285  osm_gps_map_osd_dpad_labels(cairo_t *cr, Line 561  osm_gps_map_osd_dpad_labels(cairo_t *cr,
561  /* this is either drawn in the center of the dpad (if present) */  /* this is either drawn in the center of the dpad (if present) */
562  /* or in the middle of the zoom area */  /* or in the middle of the zoom area */
563  static void  static void
564  osm_gps_map_osd_dpad_gps(cairo_t *cr, gint x, gint y) {  osd_dpad_gps(cairo_t *cr, gint x, gint y) {
565      /* move reference to dpad center */      /* move reference to dpad center */
566      x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;      x += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD * 3;
567      y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;      y += (1-Z_GPS) * D_RAD + Z_GPS * Z_RAD + GPS_V0;
# Line 308  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi Line 584  osm_gps_map_osd_dpad_gps(cairo_t *cr, gi
584  #define Z_LEN  (2*Z_RAD/3)  #define Z_LEN  (2*Z_RAD/3)
585    
586  static void  static void
587  osm_gps_map_osd_zoom_labels(cairo_t *cr, gint x, gint y) {  osd_zoom_labels(cairo_t *cr, gint x, gint y) {
588      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);      cairo_move_to (cr, x + Z_LEFT  - Z_LEN, y + Z_MID);
589      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_LEFT  + Z_LEN, y + Z_MID);
590    
# Line 318  osm_gps_map_osd_zoom_labels(cairo_t *cr, Line 594  osm_gps_map_osd_zoom_labels(cairo_t *cr,
594      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
595  }  }
596    
 #ifndef OSD_COLOR  
 /* if no color has been specified we just use the gdks default colors */  
 static void  
 osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled,  
                        GdkColor *fg, GdkColor *disabled) {  
     if(enabled)  gdk_cairo_set_source_color(cr, fg);  
     else         gdk_cairo_set_source_color(cr, disabled);  
     cairo_set_line_width (cr, width);  
     cairo_stroke (cr);  
 }  
 #else  
597  static void  static void
598  osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) {  osd_render(osm_gps_map_osd_t *osd) {
     if(enabled)  cairo_set_source_rgb (cr, OSD_COLOR);  
     else         cairo_set_source_rgb (cr, OSD_COLOR_DISABLED);  
     cairo_set_line_width (cr, width);  
     cairo_stroke (cr);  
 }  
 #endif  
   
 #ifdef OSD_SHADOW_ENABLE  
 static void  
 osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width, gboolean enabled) {  
     cairo_set_source_rgba (cr, 0, 0, 0, enabled?0.3:0.15);  
     cairo_set_line_width (cr, width);  
     cairo_stroke (cr);  
 }  
 #endif  
   
 static void  
 osm_gps_map_osd_render(osm_gps_map_osd_t *osd) {  
599      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
600    
     /* first fill with transparency */  
     cairo_t *cr = cairo_create(priv->overlay);  
     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);  
     cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);  
     cairo_paint(cr);  
   
601  #ifndef OSD_COLOR  #ifndef OSD_COLOR
602      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
603      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
604      GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];      GdkColor da = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_INSENSITIVE];
605  #endif  #endif
606    
607        /* first fill with transparency */
608        cairo_t *cr = cairo_create(priv->overlay);
609        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
610        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);
611        cairo_paint(cr);
612      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
613    
614      /* --------- draw zoom and dpad shape shadow ----------- */      /* --------- draw zoom and dpad shape shadow ----------- */
     gint x = 0, y = 0;  
   
615  #ifdef OSD_SHADOW_ENABLE  #ifdef OSD_SHADOW_ENABLE
616      osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osd_zoom_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
617      osm_gps_map_osd_shape_shadow(cr);      osd_shape_shadow(cr);
618  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
619      osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW);      osd_dpad_shape(cr, 1+OSD_SHADOW, 1+OSD_SHADOW);
620      osm_gps_map_osd_shape_shadow(cr);      osd_shape_shadow(cr);
621  #endif  #endif
622  #endif  #endif
623    
624      /* --------- draw zoom and dpad shape ----------- */      /* --------- draw zoom and dpad shape ----------- */
625    
626      osm_gps_map_osd_zoom_shape(cr, x, y);      osd_zoom_shape(cr, 1, 1);
627  #ifndef OSD_COLOR  #ifndef OSD_COLOR
628      osm_gps_map_osd_shape(cr, &bg, &fg);      osd_shape(cr, &bg, &fg);
629  #else  #else
630      osm_gps_map_osd_shape(cr);      osd_shape(cr);
631  #endif  #endif
632  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
633      osm_gps_map_osd_dpad_shape(cr, x, y);      osd_dpad_shape(cr, 1, 1);
634  #ifndef OSD_COLOR  #ifndef OSD_COLOR
635      osm_gps_map_osd_shape(cr, &bg, &fg);      osd_shape(cr, &bg, &fg);
636  #else  #else
637      osm_gps_map_osd_shape(cr);      osd_shape(cr);
638  #endif  #endif
639  #endif  #endif
640    
641      /* --------- draw zoom and dpad labels --------- */      /* --------- draw zoom and dpad labels --------- */
642    
643  #ifdef OSD_SHADOW_ENABLE  #ifdef OSD_SHADOW_ENABLE
644      osm_gps_map_osd_zoom_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_zoom_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
645  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
646      osm_gps_map_osd_dpad_labels(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_dpad_labels(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
647  #endif  #endif
648      osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE);      osd_labels_shadow(cr, Z_RAD/3, TRUE);
649  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
650      osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW);      osd_dpad_gps(cr, 1+OSD_LBL_SHADOW, 1+OSD_LBL_SHADOW);
651      osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);      osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL);
652  #endif  #endif
653  #endif  #endif
654    
655      osm_gps_map_osd_zoom_labels(cr, x, y);      osd_zoom_labels(cr, 1, 1);
656  #ifndef OSD_NO_DPAD  #ifndef OSD_NO_DPAD
657      osm_gps_map_osd_dpad_labels(cr, x, y);      osd_dpad_labels(cr, 1, 1);
658  #endif  #endif
659  #ifndef OSD_COLOR  #ifndef OSD_COLOR
660      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);      osd_labels(cr, Z_RAD/3, TRUE, &fg, &da);
661  #else  #else
662      osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE);      osd_labels(cr, Z_RAD/3, TRUE);
663  #endif  #endif
664  #ifdef OSD_GPS_BUTTON  #ifdef OSD_GPS_BUTTON
665      osm_gps_map_osd_dpad_gps(cr, x, y);      osd_dpad_gps(cr, 1, 1);
666  #ifndef OSD_COLOR  #ifndef OSD_COLOR
667      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);      osd_labels(cr, Z_RAD/6, osd->cb != NULL, &fg, &da);
668  #else  #else
669      osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL);      osd_labels(cr, Z_RAD/6, osd->cb != NULL);
670  #endif  #endif
671  #endif  #endif
672    
673      cairo_destroy(cr);      cairo_destroy(cr);
674    
675        osd_render_source_sel(osd);
676  }  }
677    
678  static void  static void
679  osm_gps_map_osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)  osd_draw(osm_gps_map_osd_t *osd, GdkDrawable *drawable)
680  {  {
681      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
682    
# Line 439  osm_gps_map_osd_draw(osm_gps_map_osd_t * Line 685  osm_gps_map_osd_draw(osm_gps_map_osd_t *
685      if(!priv->overlay) {      if(!priv->overlay) {
686          /* create overlay ... */          /* create overlay ... */
687          priv->overlay =          priv->overlay =
688              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W, OSD_H);              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
689    
690            /* the initial OSD state is alway not-expanded */
691            priv->map_source =
692                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
693                                               OSD_S_W+2, OSD_S_H+2);
694    
695          /* ... and render it */          /* ... and render it */
696          osm_gps_map_osd_render(osd);          osd_render(osd);
697      }      }
698    
699      // now draw this onto the original context      // now draw this onto the original context
# Line 456  osm_gps_map_osd_draw(osm_gps_map_osd_t * Line 708  osm_gps_map_osd_draw(osm_gps_map_osd_t *
708    
709      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->overlay, x, y);
710      cairo_paint(cr);      cairo_paint(cr);
711    
712    #ifdef OSD_SOURCE_SEL
713        if(!priv->handler_id) {
714            /* the OSD source selection is not being animated */
715            if(!priv->expanded)
716                x = osd->widget->allocation.width - OSD_S_W;
717            else
718                x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
719        } else
720            x = priv->shift;
721    
722        y = OSD_S_Y;
723        if(OSD_S_Y < 0) {
724            if(!priv->expanded)
725                y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
726            else
727                y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
728        }
729    
730        cairo_set_source_surface(cr, priv->map_source, x, y);
731        cairo_paint(cr);
732    #endif
733    
734      cairo_destroy(cr);      cairo_destroy(cr);
735  }  }
736    
737  static void  static void
738  osm_gps_map_osd_free(osm_gps_map_osd_t *osd)  osd_free(osm_gps_map_osd_t *osd)
739  {  {
740      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
741    
742        if(priv->handler_id)
743            gtk_timeout_remove(priv->handler_id);
744    
745      if (priv->overlay)      if (priv->overlay)
746           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->overlay);
747    
748        if (priv->map_source)
749             cairo_surface_destroy(priv->map_source);
750    
751      g_free(priv);      g_free(priv);
752  }  }
753    
754  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
755      .draw       = osm_gps_map_osd_draw,      .draw       = osd_draw,
756      .check      = osm_gps_map_osd_check,      .check      = osd_check,
757      .render     = osm_gps_map_osd_render,      .render     = osd_render,
758      .free       = osm_gps_map_osd_free,      .free       = osd_free,
759    
760      .cb         = NULL,      .cb         = NULL,
761      .data       = NULL,      .data       = NULL,
# Line 499  osm_gps_map_osd_classic_init(OsmGpsMap * Line 780  osm_gps_map_osd_classic_init(OsmGpsMap *
780  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,  void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb,
781                                   gpointer data) {                                   gpointer data) {
782      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);      osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
   
783      g_return_if_fail (osd);      g_return_if_fail (osd);
784    
785      osd->cb = cb;      osd->cb = cb;
# Line 512  void osm_gps_map_osd_enable_gps (OsmGpsM Line 792  void osm_gps_map_osd_enable_gps (OsmGpsM
792      osm_gps_map_redraw(map);      osm_gps_map_redraw(map);
793  }  }
794  #endif  #endif
795    
796    osd_button_t
797    osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) {
798        osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);
799        g_return_val_if_fail (osd, OSD_NONE);
800    
801        return osd_check(osd, x, y);
802    }

Legend:
Removed from v.85  
changed lines
  Added in v.86