--- trunk/src/osm-gps-map.c 2009/08/19 14:21:14 65 +++ trunk/src/osm-gps-map.c 2009/08/19 20:03:28 66 @@ -114,7 +114,8 @@ struct { GdkPixmap *backup; gint backup_x, backup_y; - // GdkPixbuf *pixbuf; + OsmGpsMapOsdGpsCallback cb; + gpointer data; } osd; #endif @@ -663,20 +664,20 @@ #define BALLOON_AREA_HEIGHT 75 #endif #ifndef BALLOON_CORNER_RADIUS -#define BALLOON_CORNER_RADIUS 20 +#define BALLOON_CORNER_RADIUS 10 #endif -#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/4) +#define BALLOON_BORDER (BALLOON_CORNER_RADIUS/2) #define BALLOON_WIDTH (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER) #define BALLOON_HEIGHT (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER) #define BALLOON_TRANSPARENCY 0.8 #define POINTER_HEIGHT 20 #define POINTER_FOOT_WIDTH 20 #define POINTER_OFFSET (BALLOON_CORNER_RADIUS*3/4) -#define BALLOON_SHADOW 5 +#define BALLOON_SHADOW (BALLOON_CORNER_RADIUS/2) #define BALLOON_SHADOW_TRANSPARENCY 0.2 -#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS/3) +#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) /* draw the bubble shape. this is used twice, once for the shape and once */ @@ -686,7 +687,8 @@ gboolean bottom, int px, int py, int px0, int px1) { cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); - cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + BALLOON_CORNER_RADIUS, y0); + cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, + BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); if(!bottom) { /* insert top pointer */ cairo_line_to (cr, px1, y0); @@ -695,9 +697,11 @@ } cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + BALLOON_CORNER_RADIUS); + cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, + BALLOON_CORNER_RADIUS, -M_PI/2, 0); cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS); - cairo_curve_to (cr, x1, y1, x1, y1, x1 - BALLOON_CORNER_RADIUS, y1); + cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, + BALLOON_CORNER_RADIUS, 0, M_PI/2); if(bottom) { /* insert bottom pointer */ cairo_line_to (cr, px0, y1); @@ -706,7 +710,8 @@ } cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, y1 - BALLOON_CORNER_RADIUS); + cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS, + BALLOON_CORNER_RADIUS, M_PI/2, M_PI); cairo_close_path (cr); } @@ -797,7 +802,7 @@ cairo_stroke(cr); cairo_set_source_rgba (cr, 1, 1, 1, 1.0); - cairo_set_line_width (cr, 3); + cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3); cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); cairo_move_to (cr, cx - crad/2, cy - crad/2); cairo_line_to (cr, cx + crad/2, cy + crad/2); @@ -1422,20 +1427,25 @@ #define OSD_X (10) #define OSD_Y (10) -#define OSD_COLOR 0.5, 0.5, 1 +#define OSD_COLOR 0.5, 0.5, 1 +#define OSD_COLOR_DISABLED 0.8, 0.8, 0.8 /* parameters of the direction shape */ -#define D_RAD (20) // diameter of dpad +#ifndef OSM_GPS_MAP_OSD_DIAMETER +#define D_RAD (30) // diameter of dpad +#else +#define D_RAD (OSM_GPS_MAP_OSD_DIAMETER) +#endif #define D_TIP (4*D_RAD/5) // distance of arrow tip from dpad center #define D_LEN (D_RAD/4) // length of arrow #define D_WID (D_LEN) // width of arrow /* parameters of the "zoom" pad */ -#define Z_STEP (-D_RAD/8) // distance between dpad and zoom +#define Z_STEP (D_RAD/4) // distance between dpad and zoom #define Z_RAD (D_RAD/2) // radius of "caps" of zoom bar /* shadow also depends on control size */ -#define OSD_SHADOW (D_RAD/8) +#define OSD_SHADOW (D_RAD/6) /* total width and height of controls incl. shadow */ #define OSD_W (2*D_RAD + OSD_SHADOW) @@ -1495,7 +1505,7 @@ y -= (OSD_Y + D_RAD); /* check for dpad center goes here! */ - if( osm_gps_map_in_circle(x, y, OSD_X + D_RAD, OSD_Y + D_RAD, D_RAD/3)) + if( osm_gps_map_in_circle(x, y, 0, 0, D_RAD/3)) return OSD_GPS; if( y < 0 && abs(x) < abs(y)) @@ -1518,7 +1528,7 @@ /* check whether x/y is within the zoom pads */ static osd_button_t osm_gps_map_osd_check_zoom(gint x, gint y) { - if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < Z_BOT) { + if( x > OSD_X && x < (OSD_X + OSD_W) && y > Z_TOP && y < (OSD_Y+Z_BOT)) { /* within circle around (-) label */ if( osm_gps_map_in_circle(x, y, OSD_X + Z_LEFT, OSD_Y + Z_MID, Z_RAD)) @@ -1548,7 +1558,6 @@ /* this is just to avoid an unnecessary detailed test */ if(x > OSD_X && x < OSD_X + OSD_W && y > OSD_Y && y < OSD_Y + OSD_H) { - but = osm_gps_map_osd_check_dpad(x, y); if(but == OSD_NONE) @@ -1639,15 +1648,16 @@ } static void -osm_gps_map_osd_labels(cairo_t *cr, gint width) { - cairo_set_source_rgb (cr, OSD_COLOR); +osm_gps_map_osd_labels(cairo_t *cr, gint width, gboolean enabled) { + 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); } static void -osm_gps_map_osd_labels_shadow(cairo_t *cr, gint width) { - cairo_set_source_rgba (cr, 0, 0, 0, 0.2); +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); } @@ -1712,15 +1722,15 @@ 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); + 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); + osm_gps_map_osd_labels_shadow(cr, Z_RAD/6, priv->osd.cb != NULL); osm_gps_map_osd_zoom_labels(cr, x, y); osm_gps_map_osd_dpad_labels(cr, x, y); - osm_gps_map_osd_labels(cr, Z_RAD/3); + osm_gps_map_osd_labels(cr, Z_RAD/3, TRUE); osm_gps_map_osd_dpad_gps(cr, x, y); - osm_gps_map_osd_labels(cr, Z_RAD/6); + osm_gps_map_osd_labels(cr, Z_RAD/6, priv->osd.cb != NULL); cairo_destroy(cr); @@ -1821,6 +1831,7 @@ #ifdef ENABLE_OSD priv->osd.backup = NULL; + priv->osd.cb = NULL; #endif priv->tracks = NULL; @@ -2218,51 +2229,36 @@ #endif #ifdef ENABLE_OSD - /* also don't drag on clicks into the control OSD */ - if(osm_gps_map_osd_check(event->x, event->y) != OSD_NONE) - { - priv->drag_counter = -1; - return FALSE; - } -#endif + #define SCROLL_STEP 10 - priv->drag_counter = 0; - priv->drag_start_mouse_x = (int) event->x; - priv->drag_start_mouse_y = (int) event->y; - priv->drag_start_map_x = priv->map_x; - priv->drag_start_map_y = priv->map_y; - - return FALSE; -} - -static gboolean -osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event) -{ - OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); - -#ifdef ENABLE_OSD - /* released inside OSD control? */ + /* pressed inside OSD control? */ osd_button_t but = osm_gps_map_osd_check(event->x, event->y); if(but != OSD_NONE) { + priv->drag_counter = -1; + switch(but) { + case OSD_GPS: + priv->osd.cb(priv->osd.data); + break; + case OSD_UP: - priv->map_y -= GTK_WIDGET(widget)->allocation.height/4; + priv->map_y -= GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; priv->center_coord_set = FALSE; break; case OSD_DOWN: - priv->map_y += GTK_WIDGET(widget)->allocation.height/4; + priv->map_y += GTK_WIDGET(widget)->allocation.height/SCROLL_STEP; priv->center_coord_set = FALSE; break; case OSD_LEFT: - priv->map_x -= GTK_WIDGET(widget)->allocation.width/4; + priv->map_x -= GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; priv->center_coord_set = FALSE; break; case OSD_RIGHT: - priv->map_x += GTK_WIDGET(widget)->allocation.width/4; + priv->map_x += GTK_WIDGET(widget)->allocation.width/SCROLL_STEP; priv->center_coord_set = FALSE; break; @@ -2284,6 +2280,20 @@ } #endif + priv->drag_counter = 0; + priv->drag_start_mouse_x = (int) event->x; + priv->drag_start_mouse_y = (int) event->y; + priv->drag_start_map_x = priv->map_x; + priv->drag_start_map_y = priv->map_y; + + return FALSE; +} + +static gboolean +osm_gps_map_button_release (GtkWidget *widget, GdkEventButton *event) +{ + OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget); + #ifdef ENABLE_BALLOON /* released inside the balloon? */ if (osm_gps_map_in_balloon(priv, @@ -2654,7 +2664,7 @@ "radius of the gps point inner circle", 0, /* minimum property value */ G_MAXINT, /* maximum property value */ - 5, + 10, G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, @@ -3277,3 +3287,17 @@ osm_gps_map_map_redraw_idle(map); } #endif + +#ifdef ENABLE_OSD +void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdGpsCallback cb, gpointer data) { + OsmGpsMapPrivate *priv; + + g_return_if_fail (OSM_IS_GPS_MAP (map)); + priv = map->priv; + + priv->osd.cb = cb; + priv->osd.data = data; + + osm_gps_map_map_redraw_idle(map); +} +#endif