libgimp: port GimpGradientSelectButton drawing to cairo

This commit is contained in:
Michael Natterer
2010-07-30 16:20:45 +02:00
parent 208096bc7c
commit 1a893ce0b4

View File

@ -104,9 +104,9 @@ static void gimp_gradient_select_preview_size_allocate
(GtkWidget *widget, (GtkWidget *widget,
GtkAllocation *allocation, GtkAllocation *allocation,
GimpGradientSelectButton *button); GimpGradientSelectButton *button);
static void gimp_gradient_select_preview_expose (GtkWidget *preview, static gboolean gimp_gradient_select_preview_expose (GtkWidget *preview,
GdkEventExpose *event, GdkEventExpose *event,
GimpGradientSelectButton *button); GimpGradientSelectButton *button);
static void gimp_gradient_select_drag_data_received (GimpGradientSelectButton *button, static void gimp_gradient_select_drag_data_received (GimpGradientSelectButton *button,
GdkDragContext *context, GdkDragContext *context,
@ -479,78 +479,73 @@ gimp_gradient_select_preview_size_allocate (GtkWidget *widget,
} }
} }
static void static gboolean
gimp_gradient_select_preview_expose (GtkWidget *widget, gimp_gradient_select_preview_expose (GtkWidget *widget,
GdkEventExpose *event, GdkEventExpose *event,
GimpGradientSelectButton *button) GimpGradientSelectButton *button)
{ {
const gdouble *src;
guchar *p0;
guchar *p1;
guchar *even;
guchar *odd;
gint width;
gint x, y;
GimpGradientSelectButtonPrivate *priv; GimpGradientSelectButtonPrivate *priv;
GtkAllocation allocation;
cairo_t *cr;
cairo_pattern_t *pattern;
cairo_surface_t *surface;
const gdouble *src;
guchar *dest;
gint width;
gint x;
priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button); priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (button);
src = priv->gradient_data; src = priv->gradient_data;
if (! src) if (! src)
return; return FALSE;
gtk_widget_get_allocation (widget, &allocation);
cr = gdk_cairo_create (event->window);
gdk_cairo_region (cr, event->region);
cairo_clip (cr);
pattern = gimp_cairo_checkerboard_create (cr, GIMP_CHECK_SIZE_SM, NULL, NULL);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
cairo_paint (cr);
width = priv->n_samples / 4; width = priv->n_samples / 4;
p0 = even = g_malloc (width * 3); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, 1);
p1 = odd = g_malloc (width * 3);
for (x = 0; x < width; x++) for (x = 0, dest = cairo_image_surface_get_data (surface);
x < width;
x++, src += 4, dest += 4)
{ {
gdouble r, g, b, a; GimpRGB color;
gdouble c0, c1; guchar r, g, b, a;
r = src[x * 4 + 0]; gimp_rgba_set (&color, src[0], src[1], src[2], src[3]);
g = src[x * 4 + 1]; gimp_rgba_get_uchar (&color, &r, &g, &b, &a);
b = src[x * 4 + 2];
a = src[x * 4 + 3];
if ((x / GIMP_CHECK_SIZE_SM) & 1) GIMP_CAIRO_ARGB32_SET_PIXEL(dest, r, g, b, a);
{
c0 = GIMP_CHECK_LIGHT;
c1 = GIMP_CHECK_DARK;
}
else
{
c0 = GIMP_CHECK_DARK;
c1 = GIMP_CHECK_LIGHT;
}
*p0++ = (c0 + (r - c0) * a) * 255.0;
*p0++ = (c0 + (g - c0) * a) * 255.0;
*p0++ = (c0 + (b - c0) * a) * 255.0;
*p1++ = (c1 + (r - c1) * a) * 255.0;
*p1++ = (c1 + (g - c1) * a) * 255.0;
*p1++ = (c1 + (b - c1) * a) * 255.0;
} }
for (y = event->area.y; y < event->area.y + event->area.height; y++) cairo_surface_mark_dirty (surface);
{
GtkStyle *style = gtk_widget_get_style (widget);
guchar *buf = ((y / GIMP_CHECK_SIZE_SM) & 1) ? odd : even;
gdk_draw_rgb_image_dithalign (gtk_widget_get_window (widget), pattern = cairo_pattern_create_for_surface (surface);
style->fg_gc[gtk_widget_get_state (widget)], cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
event->area.x, y, cairo_surface_destroy (surface);
event->area.width, 1,
GDK_RGB_DITHER_MAX,
buf + event->area.x * 3,
width * 3,
- event->area.x, - y);
}
g_free (odd); cairo_scale (cr, (gdouble) allocation.width / (gdouble) width, 1.0);
g_free (even);
cairo_set_source (cr, pattern);
cairo_pattern_destroy (pattern);
cairo_paint (cr);
cairo_destroy (cr);
return FALSE;
} }
static void static void