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 106 by harbaum, Thu Sep 10 13:06:16 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 36  Line 34 
34  #include "osm-gps-map.h"  #include "osm-gps-map.h"
35  #include "osm-gps-map-osd-classic.h"  #include "osm-gps-map-osd-classic.h"
36    
37    #define OSD_COORDINATES
38    
39  //the osd controls  //the osd controls
40  typedef struct {  typedef struct {
41      /* the offscreen representation of the OSD */      /* the offscreen representation of the OSD */
# Line 50  typedef struct { Line 50  typedef struct {
50      cairo_surface_t *crosshair;      cairo_surface_t *crosshair;
51  #endif  #endif
52    
53    #ifdef OSD_COORDINATES
54        cairo_surface_t *coordinates;
55    #endif
56    
57  #ifdef OSD_SOURCE_SEL  #ifdef OSD_SOURCE_SEL
58      /* values to handle the "source" menu */      /* values to handle the "source" menu */
59      cairo_surface_t *map_source;      cairo_surface_t *map_source;
# Line 729  osd_zoom_labels(cairo_t *cr, gint x, gin Line 733  osd_zoom_labels(cairo_t *cr, gint x, gin
733      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
734  }  }
735    
736    #ifdef OSD_COORDINATES
737    #define OSD_COORDINATES_W  100
738    #define OSD_COORDINATES_H   50
739    
740    static void
741    osd_render_coordinates(osm_gps_map_osd_t *osd)
742    {
743        osd_priv_t *priv = (osd_priv_t*)osd->priv;
744    
745        /* first fill with transparency */
746        cairo_t *cr = cairo_create(priv->coordinates);
747        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
748        //    cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
749        cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
750        cairo_paint(cr);
751        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
752    
753        cairo_destroy(cr);
754    }
755    #endif  // OSD_COORDINATES
756    
757  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
758    
759  #ifndef OSD_CROSSHAIR_RADIUS  #ifndef OSD_CROSSHAIR_RADIUS
760  #define OSD_CROSSHAIR_RADIUS 20  #define OSD_CROSSHAIR_RADIUS 10
761  #endif  #endif
762    
763  #define OSD_CROSSHAIR_W  (OSD_CROSSHAIR_RADIUS*2)  #define OSD_CROSSHAIR_TICK  (OSD_CROSSHAIR_RADIUS/2)
764  #define OSD_CROSSHAIR_H  (OSD_CROSSHAIR_RADIUS*2)  #define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4)
765    #define OSD_CROSSHAIR_W  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
766    #define OSD_CROSSHAIR_H  ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2)
767    
768    static void
769    osd_render_crosshair_shape(cairo_t *cr) {
770        cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2,
771                   OSD_CROSSHAIR_RADIUS, 0,  2*M_PI);
772    
773        cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS,
774                       OSD_CROSSHAIR_H/2);
775        cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0);
776        cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS,
777                       OSD_CROSSHAIR_H/2);
778        cairo_rel_line_to (cr,  OSD_CROSSHAIR_TICK, 0);
779    
780        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
781                       OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS);
782        cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK);
783        cairo_move_to (cr, OSD_CROSSHAIR_W/2,
784                       OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS);
785        cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK);
786    
787        cairo_stroke (cr);
788    }
789    
790  static void  static void
791  osd_render_crosshair(osm_gps_map_osd_t *osd)  osd_render_crosshair(osm_gps_map_osd_t *osd)
# Line 746  osd_render_crosshair(osm_gps_map_osd_t * Line 795  osd_render_crosshair(osm_gps_map_osd_t *
795      /* first fill with transparency */      /* first fill with transparency */
796      cairo_t *cr = cairo_create(priv->crosshair);      cairo_t *cr = cairo_create(priv->crosshair);
797      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
798      //    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);
799      cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);      //    cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2);
800      cairo_paint(cr);      cairo_paint(cr);
801      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
802    
803        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
804    
805        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
806        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2);
807        osd_render_crosshair_shape(cr);
808    
809        cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
810        cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4);
811        osd_render_crosshair_shape(cr);
812    
813      cairo_destroy(cr);      cairo_destroy(cr);
814  }  }
815  #endif  #endif
# Line 994  osd_render(osm_gps_map_osd_t *osd) Line 1053  osd_render(osm_gps_map_osd_t *osd)
1053  #ifdef OSD_CROSSHAIR  #ifdef OSD_CROSSHAIR
1054      osd_render_crosshair(osd);      osd_render_crosshair(osd);
1055  #endif  #endif
1056    
1057    #ifdef OSD_COORDINATES
1058        osd_render_coordinates(osd);
1059    #endif
1060  }  }
1061    
1062  static void  static void
# Line 1028  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1091  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1091                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);                                         OSD_CROSSHAIR_W, OSD_CROSSHAIR_H);
1092  #endif  #endif
1093    
1094    #ifdef OSD_COORDINATES
1095            priv->coordinates =
1096                cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
1097                                           OSD_COORDINATES_W, OSD_COORDINATES_H);
1098    #endif
1099    
1100          /* ... and render it */          /* ... and render it */
1101          osd_render(osd);          osd_render(osd);
1102      }      }
# Line 1035  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1104  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1104      // now draw this onto the original context      // now draw this onto the original context
1105      cairo_t *cr = gdk_cairo_create(drawable);      cairo_t *cr = gdk_cairo_create(drawable);
1106    
1107      int x = OSD_X, y = OSD_Y;      int x, y;
     if(OSD_X < 0)  
         x = osd->widget->allocation.width - OSD_W + OSD_X;  
1108    
1109      if(OSD_Y < 0)  #ifdef OSD_SCALE
1110          y = osd->widget->allocation.height - OSD_H + OSD_Y;      x =  OSD_X;
1111        y = -OSD_Y;
1112        if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W;
1113        if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H;
1114    
1115        cairo_set_source_surface(cr, priv->scale, x, y);
1116        cairo_paint(cr);
1117    #endif
1118    
1119    #ifdef OSD_CROSSHAIR
1120        x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2;
1121        y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2;
1122    
1123        cairo_set_source_surface(cr, priv->crosshair, x, y);
1124        cairo_paint(cr);
1125    #endif
1126    
1127    #ifdef OSD_COORDINATES
1128        x = -OSD_X;
1129        y = -OSD_Y;
1130        if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W;
1131        if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H;
1132    
1133        cairo_set_source_surface(cr, priv->coordinates, x, y);
1134        cairo_paint(cr);
1135    #endif
1136    
1137        x = OSD_X;
1138        if(x < 0)
1139            x += osd->widget->allocation.width - OSD_W;
1140    
1141        y = OSD_Y;
1142        if(y < 0)
1143            y += osd->widget->allocation.height - OSD_H;
1144    
1145      cairo_set_source_surface(cr, priv->overlay, x, y);      cairo_set_source_surface(cr, priv->overlay, x, y);
1146      cairo_paint(cr);      cairo_paint(cr);
# Line 1067  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 1167  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
1167      cairo_paint(cr);      cairo_paint(cr);
1168  #endif  #endif
1169    
 #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);  
     cairo_paint(cr);  
 #endif  
   
1170      cairo_destroy(cr);      cairo_destroy(cr);
1171  }  }
1172    
# Line 1114  osd_free(osm_gps_map_osd_t *osd) Line 1196  osd_free(osm_gps_map_osd_t *osd)
1196           cairo_surface_destroy(priv->crosshair);           cairo_surface_destroy(priv->crosshair);
1197  #endif  #endif
1198    
1199    #ifdef OSD_COORDINATES
1200        if (priv->coordinates)
1201             cairo_surface_destroy(priv->coordinates);
1202    #endif
1203    
1204      g_free(priv);      g_free(priv);
1205  }  }
1206    

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