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

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

revision 105 by harbaum, Wed Sep 9 19:57:45 2009 UTC revision 111 by harbaum, Mon Sep 14 12:16:08 2009 UTC
# Line 25  Line 25 
25  /* OSD_DIAMETER */  /* OSD_DIAMETER */
26  /* OSD_X, OSD_Y */  /* OSD_X, OSD_Y */
27    
 #define OSD_CROSSHAIR  
   
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!"
30  #endif  #endif
# Line 39  Line 37 
37  //the osd controls  //the osd controls
38  typedef struct {  typedef struct {
39      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
40      cairo_surface_t *overlay;      struct {
41            cairo_surface_t *surface;
42            gboolean rendered;
43    #ifdef OSD_GPS_BUTTON
44            gboolean gps_enabled;
45    #endif
46        } controls;
47    
48  #ifdef OSD_SCALE  #ifdef OSD_SCALE
49      cairo_surface_t *scale;      struct {
50      int scale_zoom;          cairo_surface_t *surface;
51            int zoom;
52        } scale;
53  #endif  #endif
54    
55  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
56      cairo_surface_t *crosshair;      struct {
57            cairo_surface_t *surface;
58            gboolean rendered;
59        } crosshair;
60    #endif
61    
62    #ifdef OSD_COORDINATES
63        struct {
64            cairo_surface_t *surface;
65            float lat, lon;
66        } coordinates;
67  #endif  #endif
68    
69  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
70      /* values to handle the "source" menu */      struct {
71      cairo_surface_t *map_source;          /* values to handle the "source" menu */
72      gboolean expanded;          cairo_surface_t *surface;
73      gint shift, dir, count;          gboolean expanded;
74      gint handler_id;          gint shift, dir, count;
75      gint width, height;          gint handler_id;
76            gint width, height;
77            gboolean rendered;
78        } source_sel;
79  #endif  #endif
80    
81  } osd_priv_t;  } osd_priv_t;
# Line 283  osd_check_zoom(gint x, gint y) { Line 302  osd_check_zoom(gint x, gint y) {
302  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)  #define OSD_S_H   (OSD_S_PH + OSD_SHADOW)
303    
304  /* size of usable area when expanded */  /* size of usable area when expanded */
305  #define OSD_S_AREA_W (priv->width)  #define OSD_S_AREA_W (priv->source_sel.width)
306  #define OSD_S_AREA_H (priv->height)  #define OSD_S_AREA_H (priv->source_sel.height)
307  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)  #define OSD_S_EXP_W  (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW)
308  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)  #define OSD_S_EXP_H  (OSD_S_AREA_H + OSD_SHADOW)
309    
# Line 300  osd_check_zoom(gint x, gint y) { Line 319  osd_check_zoom(gint x, gint y) {
319  /* or the entire menu incl. the puller (expanded) */  /* or the entire menu incl. the puller (expanded) */
320  static void  static void
321  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) {
322      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
323          /* just draw the puller */          /* just draw the puller */
324          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);          cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH);
325          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);          cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2);
# Line 328  osd_source_content(osm_gps_map_osd_t *os Line 347  osd_source_content(osm_gps_map_osd_t *os
347    
348      int py = offset + OSD_S_RAD - OSD_S_D0;      int py = offset + OSD_S_RAD - OSD_S_D0;
349    
350      if(!priv->expanded) {      if(!priv->source_sel.expanded) {
351          /* draw the "puller" open (<) arrow */          /* draw the "puller" open (<) arrow */
352          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);          cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py);
353          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);          cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0);
# Line 353  osd_source_content(osm_gps_map_osd_t *os Line 372  osd_source_content(osm_gps_map_osd_t *os
372                                      CAIRO_FONT_WEIGHT_BOLD);                                      CAIRO_FONT_WEIGHT_BOLD);
373              cairo_set_font_size (cr, OSD_FONT_SIZE);              cairo_set_font_size (cr, OSD_FONT_SIZE);
374    
375              int i, step = (priv->height - 2*OSD_TEXT_BORDER) /              int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) /
376                  OSM_GPS_MAP_SOURCE_LAST;                  OSM_GPS_MAP_SOURCE_LAST;
377              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++) {
378                  cairo_text_extents_t extents;                  cairo_text_extents_t extents;
# Line 367  osd_source_content(osm_gps_map_osd_t *os Line 386  osd_source_content(osm_gps_map_osd_t *os
386                  if(source == i) {                  if(source == i) {
387                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,                      cairo_rectangle(cr, x - OSD_TEXT_BORDER/2,
388                                      y - OSD_TEXT_SKIP,                                      y - OSD_TEXT_SKIP,
389                                      priv->width - OSD_TEXT_BORDER,                                      priv->source_sel.width - OSD_TEXT_BORDER,
390                                      step + OSD_TEXT_SKIP);                                      step + OSD_TEXT_SKIP);
391                      cairo_fill(cr);                      cairo_fill(cr);
392    
# Line 398  osd_source_content(osm_gps_map_osd_t *os Line 417  osd_source_content(osm_gps_map_osd_t *os
417  }  }
418    
419  static void  static void
420  osd_render_source_sel(osm_gps_map_osd_t *osd) {  osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) {
421      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
422    
423        if(priv->source_sel.rendered && !force_rerender)
424            return;
425    
426        priv->source_sel.rendered = TRUE;
427    
428  #ifndef OSD_COLOR  #ifndef OSD_COLOR
429      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
430      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 408  osd_render_source_sel(osm_gps_map_osd_t Line 432  osd_render_source_sel(osm_gps_map_osd_t
432  #endif  #endif
433    
434      /* draw source selector */      /* draw source selector */
435      cairo_t *cr = cairo_create(priv->map_source);      cairo_t *cr = cairo_create(priv->source_sel.surface);
436      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
437      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);
438      cairo_paint(cr);      cairo_paint(cr);
# Line 449  osd_source_reallocate(osm_gps_map_osd_t Line 473  osd_source_reallocate(osm_gps_map_osd_t
473      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
474    
475      /* re-allocate offscreen bitmap */      /* re-allocate offscreen bitmap */
476      g_assert (priv->map_source);      g_assert (priv->source_sel.surface);
477    
478      int w = OSD_S_W, h = OSD_S_H;      int w = OSD_S_W, h = OSD_S_H;
479      if(priv->expanded) {      if(priv->source_sel.expanded) {
480          cairo_text_extents_t extents;          cairo_text_extents_t extents;
481    
482          /* determine content size */          /* determine content size */
483          cairo_t *cr = cairo_create(priv->map_source);          cairo_t *cr = cairo_create(priv->source_sel.surface);
484          cairo_select_font_face (cr, "Sans",          cairo_select_font_face (cr, "Sans",
485                                  CAIRO_FONT_SLANT_NORMAL,                                  CAIRO_FONT_SLANT_NORMAL,
486                                  CAIRO_FONT_WEIGHT_BOLD);                                  CAIRO_FONT_WEIGHT_BOLD);
# Line 473  osd_source_reallocate(osm_gps_map_osd_t Line 497  osd_source_reallocate(osm_gps_map_osd_t
497          }          }
498          cairo_destroy(cr);          cairo_destroy(cr);
499    
500          priv->width  = max_w + 2*OSD_TEXT_BORDER;          priv->source_sel.width  = max_w + 2*OSD_TEXT_BORDER;
501          priv->height = OSM_GPS_MAP_SOURCE_LAST *          priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST *
502              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;              (max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER;
503    
504          w = OSD_S_EXP_W;          w = OSD_S_EXP_W;
505          h = OSD_S_EXP_H;          h = OSD_S_EXP_H;
506      }      }
507    
508      cairo_surface_destroy(priv->map_source);      cairo_surface_destroy(priv->source_sel.surface);
509      priv->map_source =      priv->source_sel.surface =
510          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);          cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2);
511    
512      osd_render_source_sel(osd);      osd_render_source_sel(osd, TRUE);
513  }  }
514    
515  #define OSD_HZ      15  #define OSD_HZ      15
# Line 496  static gboolean osd_source_animate(gpoin Line 520  static gboolean osd_source_animate(gpoin
520      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
521      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;      int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X;
522      gboolean done = FALSE;      gboolean done = FALSE;
523      priv->count += priv->dir;      priv->source_sel.count += priv->source_sel.dir;
524    
525      /* shifting in */      /* shifting in */
526      if(priv->dir < 0) {      if(priv->source_sel.dir < 0) {
527          if(priv->count <= 0) {          if(priv->source_sel.count <= 0) {
528              priv->count = 0;              priv->source_sel.count = 0;
529              done = TRUE;              done = TRUE;
530          }          }
531      } else {      } else {
532          if(priv->count >= 1000) {          if(priv->source_sel.count >= 1000) {
533              priv->expanded = FALSE;              priv->source_sel.expanded = FALSE;
534              osd_source_reallocate(osd);              osd_source_reallocate(osd);
535    
536              priv->count = 1000;              priv->source_sel.count = 1000;
537              done = TRUE;              done = TRUE;
538          }          }
539      }      }
# Line 517  static gboolean osd_source_animate(gpoin Line 541  static gboolean osd_source_animate(gpoin
541    
542      /* 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 */
543    
544      /* nicer sinoid mapping */      /* nice sinoid mapping */
545      float m = 0.5-cos(priv->count * M_PI / 1000.0)/2;      float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2;
546      priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +      priv->source_sel.shift =
547            (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) +
548          m * diff;          m * diff;
549    
550        /* make sure the screen is updated */
551      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));      osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
552    
553        /* stop animation if done */
554      if(done)      if(done)
555          priv->handler_id = 0;          priv->source_sel.handler_id = 0;
556    
557      return !done;      return !done;
558  }  }
# Line 537  osd_source_toggle(osm_gps_map_osd_t *osd Line 564  osd_source_toggle(osm_gps_map_osd_t *osd
564      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
565    
566      /* ignore clicks while animation is running */      /* ignore clicks while animation is running */
567      if(priv->handler_id)      if(priv->source_sel.handler_id)
568          return;          return;
569    
570      /* expand immediately, collapse is handle at the end of the collapse animation */      /* expand immediately, collapse is handle at the end of the */
571      if(!priv->expanded) {      /* collapse animation */
572          priv->expanded = TRUE;      if(!priv->source_sel.expanded) {
573            priv->source_sel.expanded = TRUE;
574          osd_source_reallocate(osd);          osd_source_reallocate(osd);
575    
576          priv->count = 1000;          priv->source_sel.count = 1000;
577          priv->shift = osd->widget->allocation.width - OSD_S_W;          priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W;
578          priv->dir = -1000/OSD_HZ;          priv->source_sel.dir = -1000/OSD_HZ;
579      } else {      } else {
580          priv->count =  0;          priv->source_sel.count =  0;
581          priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          priv->source_sel.shift = osd->widget->allocation.width -
582          priv->dir = +1000/OSD_HZ;              OSD_S_EXP_W + OSD_S_X;
583            priv->source_sel.dir = +1000/OSD_HZ;
584      }      }
585    
586      priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd);      /* start timer to handle animation */
587        priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ,
588                                                      osd_source_animate, osd);
589  }  }
590    
591  /* check if the user clicked inside the source selection area */  /* check if the user clicked inside the source selection area */
# Line 562  static osd_button_t Line 593  static osd_button_t
593  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) {
594      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
595    
596      if(!priv->expanded)      if(!priv->source_sel.expanded)
597          x -= osd->widget->allocation.width - OSD_S_W;          x -= osd->widget->allocation.width - OSD_S_W;
598      else      else
599          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;          x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
# Line 586  osd_source_check(osm_gps_map_osd_t *osd, Line 617  osd_source_check(osm_gps_map_osd_t *osd,
617      }      }
618    
619      /* check for clicks into data area */      /* check for clicks into data area */
620      if(priv->expanded && !priv->handler_id) {      if(priv->source_sel.expanded && !priv->source_sel.handler_id) {
621          /* re-adjust from puller top to content top */          /* re-adjust from puller top to content top */
622          if(OSD_S_Y < 0)          if(OSD_S_Y < 0)
623              y += OSD_S_EXP_H - OSD_S_PH;              y += OSD_S_EXP_H - OSD_S_PH;
# Line 596  osd_source_check(osm_gps_map_osd_t *osd, Line 627  osd_source_check(osm_gps_map_osd_t *osd,
627             y > 0 &&             y > 0 &&
628             y < OSD_S_EXP_H) {             y < OSD_S_EXP_H) {
629    
630              int step = (priv->height - 2*OSD_TEXT_BORDER)              int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER)
631                  / OSM_GPS_MAP_SOURCE_LAST;                  / OSM_GPS_MAP_SOURCE_LAST;
632    
633              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;              y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP;
# Line 611  osd_source_check(osm_gps_map_osd_t *osd, Line 642  osd_source_check(osm_gps_map_osd_t *osd,
642                 old != y) {                 old != y) {
643                  g_object_set(osd->widget, "map-source", y, NULL);                  g_object_set(osd->widget, "map-source", y, NULL);
644    
645                  osd_render_source_sel(osd);                  osd_render_source_sel(osd, TRUE);
646                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));                  osm_gps_map_repaint(OSM_GPS_MAP(osd->widget));
647              }              }
648    
# Line 729  osd_zoom_labels(cairo_t *cr, gint x, gin Line 760  osd_zoom_labels(cairo_t *cr, gint x, gin
760      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
761  }  }
762    
763    #ifdef OSD_COORDINATES
764    
765    #ifndef OSD_COORDINATES_FONT_SIZE
766    #define OSD_COORDINATES_FONT_SIZE 12
767    #endif
768    
769    #define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6)
770    
771    #define OSD_COORDINATES_W  (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET)
772    #define OSD_COORDINATES_H  (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET)
773    
774    /* these can be overwritten with versions that support */
775    /* localization */
776    #ifndef OSD_COORDINATES_CHR_N
777    #define OSD_COORDINATES_CHR_N  "N"
778    #endif
779    #ifndef OSD_COORDINATES_CHR_S
780    #define OSD_COORDINATES_CHR_S  "S"
781    #endif
782    #ifndef OSD_COORDINATES_CHR_E
783    #define OSD_COORDINATES_CHR_E  "E"
784    #endif
785    #ifndef OSD_COORDINATES_CHR_W
786    #define OSD_COORDINATES_CHR_W  "W"
787    #endif
788    
789    
790    
791    /* this is the classic geocaching notation */
792    static char
793    *osd_latitude_str(float latitude) {
794        char *c = OSD_COORDINATES_CHR_N;
795        float integral, fractional;
796    
797        if(isnan(latitude))
798            return NULL;
799    
800        if(latitude < 0) {
801            latitude = fabs(latitude);
802            c = OSD_COORDINATES_CHR_S;
803        }
804    
805        fractional = modff(latitude, &integral);
806    
807        return g_strdup_printf("%s %02d° %06.3f'",
808                               c, (int)integral, fractional*60.0);
809    }
810    
811    static char
812    *osd_longitude_str(float longitude) {
813        char *c = OSD_COORDINATES_CHR_E;
814        float integral, fractional;
815    
816        if(isnan(longitude))
817            return NULL;
818    
819        if(longitude < 0) {
820            longitude = fabs(longitude);
821            c = OSD_COORDINATES_CHR_W;
822        }
823    
824        fractional = modff(longitude, &integral);
825    
826        return g_strdup_printf("%s %03d° %06.3f'",
827                               c, (int)integral, fractional*60.0);
828    }
829    
830    static void
831    osd_render_coordinates(osm_gps_map_osd_t *osd)
832    {
833        osd_priv_t *priv = (osd_priv_t*)osd->priv;
834    
835        /* get current map position */
836        gfloat lat, lon;
837        g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL);
838    
839        /* check if position has changed enough to require redraw */
840        if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon))
841            /* 1/60000 == 1/1000 minute */
842            if((fabsf(lat - priv->coordinates.lat) < 1/60000) &&
843               (fabsf(lon - priv->coordinates.lon) < 1/60000))
844                return;
845    
846        priv->coordinates.lat = lat;
847        priv->coordinates.lon = lon;
848    
849        /* first fill with transparency */
850        cairo_t *cr = cairo_create(priv->coordinates.surface);
851        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
852        //    cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5);
853        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
854        cairo_paint(cr);
855        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
856    
857        cairo_select_font_face (cr, "Sans",
858                                CAIRO_FONT_SLANT_NORMAL,
859                                CAIRO_FONT_WEIGHT_BOLD);
860        cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE);
861    
862        char *latitude = osd_latitude_str(lat);
863        char *longitude = osd_longitude_str(lon);
864    
865        cairo_text_extents_t lat_extents, lon_extents;
866        cairo_text_extents (cr, latitude, &lat_extents);
867        cairo_text_extents (cr, longitude, &lon_extents);
868    
869        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
870        cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6);
871        cairo_move_to (cr,
872                       (OSD_COORDINATES_W - lat_extents.width)/2,
873                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
874        cairo_text_path (cr, latitude);
875        cairo_move_to (cr,
876                       (OSD_COORDINATES_W - lon_extents.width)/2,
877                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
878                       OSD_COORDINATES_FONT_SIZE);
879        cairo_text_path (cr, longitude);
880        cairo_stroke (cr);
881    
882        cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
883        cairo_move_to (cr,
884                       (OSD_COORDINATES_W - lat_extents.width)/2,
885                       OSD_COORDINATES_OFFSET - lat_extents.y_bearing);
886        cairo_show_text (cr, latitude);
887        cairo_move_to (cr,
888                       (OSD_COORDINATES_W - lon_extents.width)/2,
889                       OSD_COORDINATES_OFFSET - lon_extents.y_bearing +
890                       OSD_COORDINATES_FONT_SIZE);
891        cairo_show_text (cr, longitude);
892    
893        g_free(latitude);
894        g_free(longitude);
895    
896        cairo_destroy(cr);
897    }
898    #endif  // OSD_COORDINATES
899    
900  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
901    
902  #ifndef OSD_CROSSHAIR_RADIUS  #ifndef OSD_CROSSHAIR_RADIUS
903  #define OSD_CROSSHAIR_RADIUS 20  #define OSD_CROSSHAIR_RADIUS 10
904  #endif  #endif
905    
906  #define OSD_CROSSHAIR_W  (OSD_CROSSHAIR_RADIUS*2)  #define OSD_CROSSHAIR_TICK  (OSD_CROSSHAIR_RADIUS/2)
907  #define OSD_CROSSHAIR_H  (OSD_CROSSHAIR_RADIUS*2)  #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4)
908    #define OSD_CROSSHAIR_W  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
909    #define OSD_CROSSHAIR_H  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
910    
911    static void
912    osd_render_crosshair_shape(cairo_t *cr) {
913        cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
914                   OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
915    
916        cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS,
917                       OSD_CROSSHAIR_H/2);
918        cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0);
919        cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS,
920                       OSD_CROSSHAIR_H/2);
921        cairo_rel_line_to (cr,  OSD_CROSSHAIR_TICK, 0);
922    
923        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
924                       OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS);
925        cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK);
926        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
927                       OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS);
928        cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
929    
930        cairo_stroke (cr);
931    }
932    
933  static void  static void
934  osd_render_crosshair(osm_gps_map_osd_t *osd)  osd_render_crosshair(osm_gps_map_osd_t *osd)
935  {  {
936      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
937    
938        if(priv->crosshair.rendered)
939            return;
940    
941        priv->crosshair.rendered = TRUE;
942    
943      /* first fill with transparency */      /* first fill with transparency */
944      cairo_t *cr = cairo_create(priv->crosshair);      cairo_t *cr = cairo_create(priv->crosshair.surface);
945      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
946      //    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
     cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);  
947      cairo_paint(cr);      cairo_paint(cr);
948      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
949    
950        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
951    
952        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
953        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2);
954        osd_render_crosshair_shape(cr);
955    
956        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
957        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4);
958        osd_render_crosshair_shape(cr);
959    
960      cairo_destroy(cr);      cairo_destroy(cr);
961  }  }
962  #endif  #endif
# Line 778  osd_render_scale(osm_gps_map_osd_t *osd) Line 984  osd_render_scale(osm_gps_map_osd_t *osd)
984      /* this only needs to be rendered if the zoom has changed */      /* this only needs to be rendered if the zoom has changed */
985      gint zoom;      gint zoom;
986      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);      g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL);
987      if(zoom == priv->scale_zoom)      if(zoom == priv->scale.zoom)
988          return;          return;
989    
990      priv->scale_zoom = zoom;      priv->scale.zoom = zoom;
991    
992      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));      float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
993    
994      /* first fill with transparency */      /* first fill with transparency */
995      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale.surface);
996      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
997      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);
998      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      // pink for testing:    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
# Line 900  osd_render_scale(osm_gps_map_osd_t *osd) Line 1106  osd_render_scale(osm_gps_map_osd_t *osd)
1106  #endif  #endif
1107    
1108  static void  static void
1109  osd_render(osm_gps_map_osd_t *osd)  osd_render_controls(osm_gps_map_osd_t *osd)
1110  {  {
1111      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
1112    
1113        if(priv->controls.rendered
1114    #ifdef OSD_GPS_BUTTON
1115           && (priv->controls.gps_enabled == (osd->cb != NULL))
1116    #endif
1117           )
1118            return;
1119    
1120    #ifdef OSD_GPS_BUTTON
1121        priv->controls.gps_enabled = (osd->cb != NULL);
1122    #endif
1123        priv->controls.rendered = TRUE;
1124    
1125  #ifndef OSD_COLOR  #ifndef OSD_COLOR
1126      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];      GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL];
1127      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];      GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL];
# Line 911  osd_render(osm_gps_map_osd_t *osd) Line 1129  osd_render(osm_gps_map_osd_t *osd)
1129  #endif  #endif
1130    
1131      /* first fill with transparency */      /* first fill with transparency */
1132      cairo_t *cr = cairo_create(priv->overlay);      cairo_t *cr = cairo_create(priv->controls.surface);
1133      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
1134      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);
1135      cairo_paint(cr);      cairo_paint(cr);
# Line 982  osd_render(osm_gps_map_osd_t *osd) Line 1200  osd_render(osm_gps_map_osd_t *osd)
1200      cairo_stroke(cr);      cairo_stroke(cr);
1201    
1202      cairo_destroy(cr);      cairo_destroy(cr);
1203    }
1204    
1205    static void
1206    osd_render(osm_gps_map_osd_t *osd)
1207    {
1208        /* this function is actually called pretty often since the */
1209        /* OSD contents may have changed (due to a coordinate/zoom change). */
1210        /* The different OSD parts have to make sure that they don't */
1211        /* render unneccessarily often and thus waste CPU power */
1212    
1213        osd_render_controls(osd);
1214    
1215  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1216      osd_render_source_sel(osd);      osd_render_source_sel(osd, FALSE);
1217  #endif  #endif
1218    
1219  #ifdef OSD_SCALE  #ifdef OSD_SCALE
# Line 994  osd_render(osm_gps_map_osd_t *osd) Line 1223  osd_render(osm_gps_map_osd_t *osd)
1223  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1224      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1225  #endif  #endif
1226    
1227    #ifdef OSD_COORDINATES
1228        osd_render_coordinates(osd);
1229    #endif
1230  }  }
1231    
1232  static void  static void
# Line 1003  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1236  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1236    
1237      /* OSD itself uses some off-screen rendering, so check if the */      /* OSD itself uses some off-screen rendering, so check if the */
1238      /* offscreen buffer is present and create it if not */      /* offscreen buffer is present and create it if not */
1239      if(!priv->overlay) {      if(!priv->controls.surface) {
1240          /* create overlay ... */          /* create overlay ... */
1241          priv->overlay =          priv->controls.surface =
1242              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);
1243    
1244            priv->controls.rendered = FALSE;
1245    #ifdef OSD_GPS_BUTTON
1246            priv->controls.gps_enabled = FALSE;
1247    #endif
1248    
1249  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1250          /* the initial OSD state is alway not-expanded */          /* the initial OSD state is alway not-expanded */
1251          priv->map_source =          priv->source_sel.surface =
1252              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1253                                             OSD_S_W+2, OSD_S_H+2);                                             OSD_S_W+2, OSD_S_H+2);
1254            priv->source_sel.rendered = FALSE;
1255  #endif  #endif
1256    
1257  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1258          priv->scale =          priv->scale.surface =
1259              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1260                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W, OSD_SCALE_H);
1261          priv->scale_zoom = -1;          priv->scale.zoom = -1;
1262  #endif  #endif
1263    
1264  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1265          priv->crosshair =          priv->crosshair.surface =
1266              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1267                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1268            priv->crosshair.rendered = FALSE;
1269    #endif
1270    
1271    #ifdef OSD_COORDINATES
1272            priv->coordinates.surface =
1273                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1274                                           OSD_COORDINATES_W, OSD_COORDINATES_H);
1275    
1276            priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID;
1277  #endif  #endif
1278    
1279          /* ... and render it */          /* ... and render it */
# Line 1035  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1283  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1283      // now draw this onto the original context      // now draw this onto the original context
1284      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1285    
1286      int x = OSD_X, y = OSD_Y;      int x, y;
     if(OSD_X < 0)  
         x = osd->widget->allocation.width - OSD_W + OSD_X;  
1287    
1288      if(OSD_Y < 0)  #ifdef OSD_SCALE
1289          y = osd->widget->allocation.height - OSD_H + OSD_Y;      x =  OSD_X;
1290        y = -OSD_Y;
1291        if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1292        if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1293    
1294      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->scale.surface, x, y);
1295        cairo_paint(cr);
1296    #endif
1297    
1298    #ifdef OSD_CROSSHAIR
1299        x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1300        y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1301    
1302        cairo_set_source_surface(cr, priv->crosshair.surface, x, y);
1303        cairo_paint(cr);
1304    #endif
1305    
1306    #ifdef OSD_COORDINATES
1307        x = -OSD_X;
1308        y = -OSD_Y;
1309        if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1310        if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1311    
1312        cairo_set_source_surface(cr, priv->coordinates.surface, x, y);
1313        cairo_paint(cr);
1314    #endif
1315    
1316        x = OSD_X;
1317        if(x < 0)
1318            x += osd->widget->allocation.width - OSD_W;
1319    
1320        y = OSD_Y;
1321        if(y < 0)
1322            y += osd->widget->allocation.height - OSD_H;
1323    
1324        cairo_set_source_surface(cr, priv->controls.surface, x, y);
1325      cairo_paint(cr);      cairo_paint(cr);
1326    
1327  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1328      if(!priv->handler_id) {      if(!priv->source_sel.handler_id) {
1329          /* the OSD source selection is not being animated */          /* the OSD source selection is not being animated */
1330          if(!priv->expanded)          if(!priv->source_sel.expanded)
1331              x = osd->widget->allocation.width - OSD_S_W;              x = osd->widget->allocation.width - OSD_S_W;
1332          else          else
1333              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;              x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X;
1334      } else      } else
1335          x = priv->shift;          x = priv->source_sel.shift;
1336    
1337      y = OSD_S_Y;      y = OSD_S_Y;
1338      if(OSD_S_Y < 0) {      if(OSD_S_Y < 0) {
1339          if(!priv->expanded)          if(!priv->source_sel.expanded)
1340              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y;
1341          else          else
1342              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;              y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y;
1343      }      }
1344    
1345      cairo_set_source_surface(cr, priv->map_source, x, y);      cairo_set_source_surface(cr, priv->source_sel.surface, x, y);
     cairo_paint(cr);  
 #endif  
   
 #ifdef OSD_SCALE  
     x =  OSD_X;  
     y = -OSD_Y;  
     if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;  
     if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;  
   
     cairo_set_source_surface(cr, priv->scale, x, y);  
     cairo_paint(cr);  
 #endif  
   
 #ifdef OSD_CROSSHAIR  
     x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;  
     y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;  
   
     cairo_set_source_surface(cr, priv->crosshair, x, y);  
1346      cairo_paint(cr);      cairo_paint(cr);
1347  #endif  #endif
1348    
# Line 1093  osd_free(osm_gps_map_osd_t *osd) Line 1354  osd_free(osm_gps_map_osd_t *osd)
1354  {  {
1355      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1356    
1357      if (priv->overlay)      if (priv->controls.surface)
1358           cairo_surface_destroy(priv->overlay);           cairo_surface_destroy(priv->controls.surface);
1359    
1360  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1361      if(priv->handler_id)      if(priv->source_sel.handler_id)
1362          gtk_timeout_remove(priv->handler_id);          gtk_timeout_remove(priv->source_sel.handler_id);
1363    
1364      if (priv->map_source)      if (priv->source_sel.surface)
1365           cairo_surface_destroy(priv->map_source);           cairo_surface_destroy(priv->source_sel.surface);
1366  #endif  #endif
1367    
1368  #ifdef OSD_SCALE  #ifdef OSD_SCALE
1369      if (priv->scale)      if (priv->scale.surface)
1370           cairo_surface_destroy(priv->scale);           cairo_surface_destroy(priv->scale.surface);
1371  #endif  #endif
1372    
1373  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1374      if (priv->crosshair)      if (priv->crosshair.surface)
1375           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair.surface);
1376    #endif
1377    
1378    #ifdef OSD_COORDINATES
1379        if (priv->coordinates.surface)
1380             cairo_surface_destroy(priv->coordinates.surface);
1381  #endif  #endif
1382    
1383      g_free(priv);      g_free(priv);
# Line 1122  osd_busy(osm_gps_map_osd_t *osd) Line 1388  osd_busy(osm_gps_map_osd_t *osd)
1388  {  {
1389  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
1390      osd_priv_t *priv = (osd_priv_t *)(osd->priv);      osd_priv_t *priv = (osd_priv_t *)(osd->priv);
1391      return (priv->handler_id != 0);      return (priv->source_sel.handler_id != 0);
1392  #else  #else
1393      return FALSE;      return FALSE;
1394  #endif  #endif

Legend:
Removed from v.105  
changed lines
  Added in v.111