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

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

revision 87 by harbaum, Mon Aug 31 12:01:28 2009 UTC revision 94 by harbaum, Thu Sep 3 11:04:05 2009 UTC
# Line 39  typedef struct { Line 39  typedef struct {
39      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
40      cairo_surface_t *overlay;      cairo_surface_t *overlay;
41    
42    #ifdef OSD_SOURCE_SEL
43      /* values to handle the "source" menu */      /* values to handle the "source" menu */
44      cairo_surface_t *map_source;      cairo_surface_t *map_source;
45      gboolean expanded;      gboolean expanded;
46      gint shift, dir, count;      gint shift, dir, count;
47      gint handler_id;      gint handler_id;
48      gint width, height;      gint width, height;
49    #endif
50    
51  } osd_priv_t;  } osd_priv_t;
52    
# Line 258  osd_check_zoom(gint x, gint y) { Line 260  osd_check_zoom(gint x, gint y) {
260      return OSD_NONE;      return OSD_NONE;
261  }  }
262    
263    #ifdef OSD_SOURCE_SEL
264    
265  /* place source selection at right border */  /* place source selection at right border */
266  #define OSD_S_RAD (Z_RAD)  #define OSD_S_RAD (Z_RAD)
267  #define OSD_S_X   (-OSD_X)  #define OSD_S_X   (-OSD_X)
# Line 281  osd_check_zoom(gint x, gint y) { Line 285  osd_check_zoom(gint x, gint y) {
285  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)  #define OSD_TEXT_BORDER   (OSD_FONT_SIZE/2)
286  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)  #define OSD_TEXT_SKIP     (OSD_FONT_SIZE/8)
287    
288    /* draw the shape of the source selection OSD, either only the puller (not expanded) */
289    /* or the entire menu incl. the puller (expanded) */
290  static void  static void
291  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) {
292      if(!priv->expanded) {      if(!priv->expanded) {
# Line 336  osd_source_content(osm_gps_map_osd_t *os Line 342  osd_source_content(osm_gps_map_osd_t *os
342                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
343              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
344    
345              int i, step = (priv->height - 2*OSD_TEXT_BORDER)              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /
346                  / OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
347              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++) {
348                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
349                  const char *src = osm_gps_map_source_get_friendly_name(i);                  const char *src = osm_gps_map_source_get_friendly_name(i);
# Line 425  osd_render_source_sel(osm_gps_map_osd_t Line 431  osd_render_source_sel(osm_gps_map_osd_t
431      cairo_destroy(cr);      cairo_destroy(cr);
432  }  }
433    
434    /* re-allocate the buffer used to draw the menu. This is used */
435    /* to collapse/expand the buffer */
436  static void  static void
437  osd_source_reallocate(osm_gps_map_osd_t *osd) {  osd_source_reallocate(osm_gps_map_osd_t *osd) {
438      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
# Line 450  osd_source_reallocate(osm_gps_map_osd_t Line 458  osd_source_reallocate(osm_gps_map_osd_t
458              const char *src = osm_gps_map_source_get_friendly_name(i);              const char *src = osm_gps_map_source_get_friendly_name(i);
459              cairo_text_extents (cr, src, &extents);              cairo_text_extents (cr, src, &extents);
460    
             //            printf("Source %d: %s = %f %f\n", i, src,  
             //                   extents.width, extents.height);  
   
461              if(extents.width > max_w) max_w = extents.width;              if(extents.width > max_w) max_w = extents.width;
462              if(extents.height > max_h) max_h = extents.height;              if(extents.height > max_h) max_h = extents.height;
463          }          }
# Line 503  static gboolean osd_source_animate(gpoin Line 508  static gboolean osd_source_animate(gpoin
508    
509      /* 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 */
510    
     /* simple linear mapping */  
     //    priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +  
     //        (diff * priv->count)/1000;  
   
511      /* nicer sinoid mapping */      /* nicer sinoid mapping */
512      float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;      float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;
513      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
# Line 547  osd_source_toggle(osm_gps_map_osd_t *osd Line 548  osd_source_toggle(osm_gps_map_osd_t *osd
548      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);
549  }  }
550    
551    /* check if the user clicked inside the source selection area */
552  static osd_button_t  static osd_button_t
553  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) {
554      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
# Line 573  osd_source_check(osm_gps_map_osd_t *osd, Line 575  osd_source_check(osm_gps_map_osd_t *osd,
575              return OSD_BG;              return OSD_BG;
576          }          }
577      }      }
578    
579        /* check for clicks into data area */
580        if(priv->expanded && !priv->handler_id) {
581            /* re-adjust from puller top to content top */
582            if(OSD_S_Y < 0)
583                y += OSD_S_EXP_H - OSD_S_PH;
584    
585            if(x > OSD_S_PW &&
586               x < OSD_S_PW + OSD_S_EXP_W &&
587               y > 0 &&
588               y < OSD_S_EXP_H) {
589    
590                int step = (priv->height - 2*OSD_TEXT_BORDER)
591                    / OSM_GPS_MAP_SOURCE_LAST;
592    
593                y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
594                y /= step;
595                y += 1;
596    
597                gint old = 0;
598                g_object_get(osd->widget, "map-source", &old, NULL);
599    
600                if(y > OSM_GPS_MAP_SOURCE_NULL &&
601                   y <= OSM_GPS_MAP_SOURCE_LAST &&
602                   old != y) {
603                    g_object_set(osd->widget, "map-source", y, NULL);
604    
605                    osd_render_source_sel(osd);
606                    osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
607                }
608    
609                /* return "clicked in OSD background" to prevent further */
610                /* processing by application */
611                return OSD_BG;
612            }
613        }
614    
615      return OSD_NONE;      return OSD_NONE;
616  }  }
617    #endif // OSD_SOURCE_SEL
618    
619  static osd_button_t  static osd_button_t
620  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {  osd_check(osm_gps_map_osd_t *osd, gint x, gint y) {
# Line 763  osd_render(osm_gps_map_osd_t *osd) { Line 803  osd_render(osm_gps_map_osd_t *osd) {
803    
804      cairo_destroy(cr);      cairo_destroy(cr);
805    
806    #ifdef OSD_SOURCE_SEL
807      osd_render_source_sel(osd);      osd_render_source_sel(osd);
808    #endif
809  }  }
810    
811  static void  static void
# Line 778  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 820  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
820          priv->overlay =          priv->overlay =
821              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);              cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2);
822    
823    #ifdef OSD_SOURCE_SEL
824          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
825          priv->map_source =          priv->map_source =
826              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
827                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
828    #endif
829    
830          /* ... and render it */          /* ... and render it */
831          osd_render(osd);          osd_render(osd);
# Line 830  osd_free(osm_gps_map_osd_t *osd) Line 874  osd_free(osm_gps_map_osd_t *osd)
874  {  {
875      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
876    
     if(priv->handler_id)  
         gtk_timeout_remove(priv->handler_id);  
   
877      if (priv->overlay)      if (priv->overlay)
878           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->overlay);
879    
880    #ifdef OSD_SOURCE_SEL
881        if(priv->handler_id)
882            gtk_timeout_remove(priv->handler_id);
883    
884      if (priv->map_source)      if (priv->map_source)
885           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->map_source);
886    #endif
887    
888      g_free(priv);      g_free(priv);
889  }  }
890    
 /* this is the only function that's externally visible */  
891  static gboolean  static gboolean
892  osd_busy(osm_gps_map_osd_t *osd)  osd_busy(osm_gps_map_osd_t *osd)
893  {  {
894    #ifdef OSD_SOURCE_SEL
895      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
896      return (priv->handler_id != 0);      return (priv->handler_id != 0);
897    #else
898        return FALSE;
899    #endif
900  }  }
901    
902  static osm_gps_map_osd_t osd_classic = {  static osm_gps_map_osd_t osd_classic = {
903        .widget     = NULL,
904    
905      .draw       = osd_draw,      .draw       = osd_draw,
906      .check      = osd_check,      .check      = osd_check,
907      .render     = osd_render,      .render     = osd_render,

Legend:
Removed from v.87  
changed lines
  Added in v.94