--- trunk/src/osm-gps-map-osd-classic.c 2009/08/23 19:38:15 73 +++ trunk/src/osm-gps-map-osd-classic.c 2009/08/24 09:23:36 74 @@ -35,18 +35,21 @@ //the osd controls typedef struct { + /* the offscreen representation of the OSD */ + cairo_surface_t *overlay; + + /* stuff required to restore the original map content */ GdkPixmap *backup; gint backup_x, backup_y; - cairo_surface_t *overlay; + + GdkColor bg, fg, da; + } osd_priv_t; /* position and extent of bounding box */ #define OSD_X (10) #define OSD_Y (10) -#define OSD_COLOR 0.5, 0.5, 1 -#define OSD_COLOR_DISABLED 0.8, 0.8, 0.8 - /* parameters of the direction shape */ #ifndef OSM_GPS_MAP_OSD_DIAMETER #define D_RAD (30) // diameter of dpad @@ -61,14 +64,20 @@ #define Z_STEP (D_RAD/4) // distance between dpad and zoom #define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar +#ifdef OSD_SHADOW_ENABLE /* shadow also depends on control size */ #define OSD_SHADOW (D_RAD/6) +#else +#define OSD_SHADOW (0) +#endif /* total width and height of controls incl. shadow */ #define OSD_W (2*D_RAD + OSD_SHADOW) #define OSD_H (2*D_RAD + Z_STEP + 2*Z_RAD + OSD_SHADOW) +#ifdef OSD_SHADOW_ENABLE #define OSD_LBL_SHADOW (OSD_SHADOW/2) +#endif #define Z_TOP (2 * D_RAD + Z_STEP) #define Z_MID (Z_TOP + Z_RAD) @@ -175,21 +184,35 @@ return but; } +#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, 1, 1, 1); + 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 static void osm_gps_map_osd_dpad_labels(cairo_t *cr, gint x, gint y) { @@ -255,6 +278,17 @@ cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); } +#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 static void osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { if(enabled) cairo_set_source_rgb (cr, OSD_COLOR); @@ -262,13 +296,16 @@ 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) { @@ -285,31 +322,51 @@ /* --------- draw zoom and dpad shape shadow ----------- */ gint x = 0, y = 0; +#ifdef OSD_SHADOW_ENABLE osm_gps_map_osd_zoom_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); osm_gps_map_osd_shape_shadow(cr); osm_gps_map_osd_dpad_shape(cr, x + OSD_SHADOW, y + OSD_SHADOW); osm_gps_map_osd_shape_shadow(cr); +#endif /* --------- draw zoom and dpad shape ----------- */ osm_gps_map_osd_zoom_shape(cr, x, y); +#ifndef OSD_COLOR + osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); +#else osm_gps_map_osd_shape(cr); +#endif osm_gps_map_osd_dpad_shape(cr, x, y); +#ifndef OSD_COLOR + osm_gps_map_osd_shape(cr, &priv->bg, &priv->fg); +#else osm_gps_map_osd_shape(cr); +#endif /* --------- draw zoom and dpad labels --------- */ +#ifdef OSD_SHADOW_ENABLE osm_gps_map_osd_zoom_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); osm_gps_map_osd_labels_shadow(cr, Z_RAD/3, TRUE); osm_gps_map_osd_dpad_gps(cr, x + OSD_LBL_SHADOW, y + OSD_LBL_SHADOW); osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, osd->cb != NULL); +#endif osm_gps_map_osd_zoom_labels(cr, x, y); osm_gps_map_osd_dpad_labels(cr, x, y); +#ifndef OSD_COLOR + osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE, &priv->fg, &priv->da); +#else osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); +#endif osm_gps_map_osd_dpad_gps(cr, x, y); +#ifndef OSD_COLOR + osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL, &priv->fg, &priv->da); +#else osm_gps_map_osd_labels(cr, Z_RAD/6, osd->cb != NULL); +#endif cairo_destroy(cr); } @@ -401,10 +458,17 @@ osd_classic.priv = priv; + /* extract style info from the widget */ + priv->bg = GTK_WIDGET(map)->style->bg[GTK_STATE_NORMAL]; + priv->fg = GTK_WIDGET(map)->style->fg[GTK_STATE_NORMAL]; + priv->da = GTK_WIDGET(map)->style->fg[GTK_STATE_INSENSITIVE]; + osm_gps_map_register_osd(map, &osd_classic); } +/* below are osd specific functions which aren't used by osm-gps-map */ +/* but instead are to be used by the main application */ void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, gpointer data) { osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map);