[gimp] app: port GimpColorBar drawing to cairo
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: port GimpColorBar drawing to cairo
- Date: Fri, 30 Jul 2010 12:59:14 +0000 (UTC)
commit 208096bc7cc498195839eeb53d23a32f560af05e
Author: Michael Natterer <mitch gimp org>
Date: Fri Jul 30 14:58:55 2010 +0200
app: port GimpColorBar drawing to cairo
app/widgets/gimpcolorbar.c | 86 +++++++++++++++++++++++---------------------
1 files changed, 45 insertions(+), 41 deletions(-)
---
diff --git a/app/widgets/gimpcolorbar.c b/app/widgets/gimpcolorbar.c
index 92e7dd8..516573e 100644
--- a/app/widgets/gimpcolorbar.c
+++ b/app/widgets/gimpcolorbar.c
@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
+#include "libgimpwidgets/gimpwidgets.h"
+
#include "libgimpmath/gimpmath.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
@@ -153,14 +155,20 @@ static gboolean
gimp_color_bar_expose (GtkWidget *widget,
GdkEventExpose *event)
{
- GimpColorBar *bar = GIMP_COLOR_BAR (widget);
- GtkStyle *style = gtk_widget_get_style (widget);
- GtkAllocation allocation;
- guchar *buf;
- guchar *b;
- gint x, y;
- gint width, height;
- gint i, j;
+ GimpColorBar *bar = GIMP_COLOR_BAR (widget);
+ cairo_t *cr;
+ GtkAllocation allocation;
+ cairo_surface_t *surface;
+ cairo_pattern_t *pattern;
+ guchar *b;
+ gint x, y;
+ gint width, height;
+ gint i;
+
+ cr = gdk_cairo_create (event->window);
+
+ gdk_cairo_region (cr, event->region);
+ cairo_clip (cr);
gtk_widget_get_allocation (widget, &allocation);
@@ -172,46 +180,42 @@ gimp_color_bar_expose (GtkWidget *widget,
if (width < 1 || height < 1)
return TRUE;
- buf = g_alloca (width * height * 3);
+ cairo_translate (cr, allocation.x + x, allocation.y + y);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_clip (cr);
- switch (bar->orientation)
- {
- case GTK_ORIENTATION_HORIZONTAL:
- for (i = 0, b = buf; i < width; i++, b += 3)
- {
- const guchar *src = bar->buf + 3 * ((i * 256) / width);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 1);
- b[0] = src[0];
- b[1] = src[1];
- b[2] = src[2];
- }
+ for (i = 0, b = cairo_image_surface_get_data (surface);
+ i < 256;
+ i++, b += 4)
+ {
+ const guchar *src = bar->buf + 3 * i;
- for (i = 1; i < height; i++)
- memcpy (buf + i * width * 3, buf, width * 3);
+ GIMP_CAIRO_RGB24_SET_PIXEL(b, src[0], src[1], src[2]);
+ }
- break;
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT);
+ cairo_surface_destroy (surface);
- case GTK_ORIENTATION_VERTICAL:
- for (i = 0, b = buf; i < height; i++, b += 3 * width)
- {
- const guchar *src = bar->buf + 3 * (255 - ((i * 256) / height));
- guchar *dest = b;
-
- for (j = 0; j < width; j++, dest += 3)
- {
- dest[0] = src[0];
- dest[1] = src[1];
- dest[2] = src[2];
- }
- }
- break;
+ if (bar->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ cairo_scale (cr, (gdouble) width / 256.0, 1.0);
+ }
+ else
+ {
+ cairo_translate (cr, 0, height);
+ cairo_scale (cr, 1.0, (gdouble) height / 256.0);
+ cairo_rotate (cr, - G_PI / 2);
}
- gdk_draw_rgb_image (gtk_widget_get_window (widget), style->black_gc,
- allocation.x + x, allocation.y + y,
- width, height,
- GDK_RGB_DITHER_NORMAL,
- buf, 3 * width);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]