libgimpwidgets: port the GimpChainButton lines to cairo

A proper two-pixel line in FG color looks a lot less shabby...
This commit is contained in:
Michael Natterer 2010-10-15 10:35:28 +02:00
parent 84274e2230
commit 1de338ea9d
1 changed files with 19 additions and 24 deletions

View File

@ -373,15 +373,19 @@ gimp_chain_line_new (GimpChainPosition position,
}
static gboolean
gimp_chain_line_expose_event (GtkWidget *widget,
GdkEventExpose *event)
gimp_chain_line_expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
GimpChainLine *line = ((GimpChainLine *) widget);
GtkStyle *style = gtk_widget_get_style (widget);
GimpChainLine *line = ((GimpChainLine *) widget);
GtkAllocation allocation;
GdkPoint points[3];
GdkPoint buf;
GtkShadowType shadow;
GimpChainPosition position;
cairo_t *cr;
cr = gdk_cairo_create (gtk_widget_get_window (widget));
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
gtk_widget_get_allocation (widget, &allocation);
@ -419,7 +423,6 @@ gimp_chain_line_expose_event (GtkWidget *widget,
points[2].y = (line->which == 1 ?
allocation.y + allocation.height - 1 :
allocation.y);
shadow = GTK_SHADOW_ETCHED_IN;
break;
case GIMP_CHAIN_RIGHT:
@ -430,7 +433,6 @@ gimp_chain_line_expose_event (GtkWidget *widget,
points[2].y = (line->which == 1 ?
allocation.y + allocation.height - 1 :
allocation.y);
shadow = GTK_SHADOW_ETCHED_OUT;
break;
case GIMP_CHAIN_TOP:
@ -441,7 +443,6 @@ gimp_chain_line_expose_event (GtkWidget *widget,
allocation.x + allocation.width - 1 :
allocation.x);
points[2].y = points[1].y;
shadow = GTK_SHADOW_ETCHED_OUT;
break;
case GIMP_CHAIN_BOTTOM:
@ -452,29 +453,23 @@ gimp_chain_line_expose_event (GtkWidget *widget,
allocation.x + allocation.width - 1 :
allocation.x);
points[2].y = points[1].y;
shadow = GTK_SHADOW_ETCHED_IN;
break;
default:
return FALSE;
}
if ( ((shadow == GTK_SHADOW_ETCHED_OUT) && (line->which == -1)) ||
((shadow == GTK_SHADOW_ETCHED_IN) && (line->which == 1)) )
{
buf = points[0];
points[0] = points[2];
points[2] = buf;
}
cairo_move_to (cr, points[0].x, points[0].y);
cairo_line_to (cr, points[1].x, points[1].y);
cairo_line_to (cr, points[2].x, points[2].y);
gtk_paint_polygon (gtk_widget_get_style (widget),
gtk_widget_get_window (widget), GTK_STATE_NORMAL,
shadow,
&event->area,
widget,
"chainbutton",
points, 3,
FALSE);
cairo_set_line_width (cr, 2.0);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
cairo_stroke (cr);
cairo_destroy (cr);
return TRUE;
}