diff options
Diffstat (limited to 'src/widgets/gradient-image.cpp')
| -rw-r--r-- | src/widgets/gradient-image.cpp | 143 |
1 files changed, 25 insertions, 118 deletions
diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp index 11d2d528a..c4b7216c6 100644 --- a/src/widgets/gradient-image.cpp +++ b/src/widgets/gradient-image.cpp @@ -14,8 +14,7 @@ #include <libnr/nr-pixblock-pattern.h> #include "macros.h" -#include "../display/nr-plain-stuff.h" -#include "../display/nr-plain-stuff-gdk.h" +#include "display/cairo-utils.h" #include "gradient-image.h" #include "sp-gradient.h" #include "sp-gradient-fns.h" @@ -29,10 +28,7 @@ static void sp_gradient_image_class_init (SPGradientImageClass *klass); static void sp_gradient_image_init (SPGradientImage *image); static void sp_gradient_image_destroy (GtkObject *object); -static void sp_gradient_image_realize (GtkWidget *widget); -static void sp_gradient_image_unrealize (GtkWidget *widget); static void sp_gradient_image_size_request (GtkWidget *widget, GtkRequisition *requisition); -static void sp_gradient_image_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static gint sp_gradient_image_expose (GtkWidget *widget, GdkEventExpose *event); static void sp_gradient_image_gradient_release (SPObject *, SPGradientImage *im); @@ -76,10 +72,7 @@ sp_gradient_image_class_init (SPGradientImageClass *klass) object_class->destroy = sp_gradient_image_destroy; - widget_class->realize = sp_gradient_image_realize; - widget_class->unrealize = sp_gradient_image_unrealize; widget_class->size_request = sp_gradient_image_size_request; - widget_class->size_allocate = sp_gradient_image_size_allocate; widget_class->expose_event = sp_gradient_image_expose; } @@ -89,7 +82,6 @@ sp_gradient_image_init (SPGradientImage *image) GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW); image->gradient = NULL; - image->px = NULL; new (&image->release_connection) sigc::connection(); new (&image->modified_connection) sigc::connection(); @@ -116,104 +108,39 @@ sp_gradient_image_destroy (GtkObject *object) } static void -sp_gradient_image_realize (GtkWidget *widget) -{ - SPGradientImage *image; - - image = SP_GRADIENT_IMAGE (widget); - - if (((GtkWidgetClass *) parent_class)->realize) - (* ((GtkWidgetClass *) parent_class)->realize) (widget); - - g_assert (!image->px); - image->px = g_new (guchar, 3 * VBLOCK * widget->allocation.width); - sp_gradient_image_update (image); -} - -static void -sp_gradient_image_unrealize (GtkWidget *widget) -{ - SPGradientImage *image; - - image = SP_GRADIENT_IMAGE (widget); - - if (((GtkWidgetClass *) parent_class)->unrealize) - (* ((GtkWidgetClass *) parent_class)->unrealize) (widget); - - g_assert (image->px); - g_free (image->px); - image->px = NULL; -} - -static void sp_gradient_image_size_request (GtkWidget *widget, GtkRequisition *requisition) { - SPGradientImage *slider; - - slider = SP_GRADIENT_IMAGE (widget); - requisition->width = 64; requisition->height = 12; } -static void -sp_gradient_image_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - SPGradientImage *image; - - image = SP_GRADIENT_IMAGE (widget); - - widget->allocation = *allocation; - - if (GTK_WIDGET_REALIZED (widget)) { - g_free (image->px); - image->px = g_new (guchar, 3 * VBLOCK * allocation->width); - } - - sp_gradient_image_update (image); -} - static gint sp_gradient_image_expose (GtkWidget *widget, GdkEventExpose *event) { - SPGradientImage *image; - - image = SP_GRADIENT_IMAGE (widget); - - if (GTK_WIDGET_DRAWABLE (widget)) { - gint x0, y0, x1, y1; - x0 = MAX (event->area.x, widget->allocation.x); - y0 = MAX (event->area.y, widget->allocation.y); - x1 = MIN (event->area.x + event->area.width, widget->allocation.x + widget->allocation.width); - y1 = MIN (event->area.y + event->area.height, widget->allocation.y + widget->allocation.height); - if ((x1 > x0) && (y1 > y0)) { - if (image->px) { - if (image->gradient) { - gint y; - guchar *p; - p = image->px + 3 * (x0 - widget->allocation.x); - for (y = y0; y < y1; y += VBLOCK) { - gdk_draw_rgb_image (widget->window, widget->style->black_gc, - x0, y, - (x1 - x0), MIN (VBLOCK, y1 - y), - GDK_RGB_DITHER_MAX, - p, widget->allocation.width * 3); - } - } else { - nr_gdk_draw_gray_garbage (widget->window, widget->style->black_gc, - x0, y0, - x1 - x0, y1 - y0); - } - } else { - gdk_draw_rectangle (widget->window, widget->style->black_gc, - x0, y0, - (x1 - x0), (y1 - x0), - TRUE); - } - } - } - - return TRUE; + SPGradientImage *image = SP_GRADIENT_IMAGE (widget); + SPGradient *gr = image->gradient; + + cairo_t *ct = gdk_cairo_create(widget->window); + + cairo_rectangle(ct, event->area.x, event->area.y, + event->area.width, event->area.height); + cairo_clip(ct); + cairo_translate(ct, widget->allocation.x, widget->allocation.y); + + cairo_pattern_t *check = ink_cairo_pattern_create_checkerboard(); + cairo_set_source(ct, check); + cairo_paint(ct); + cairo_pattern_destroy(check); + + if (gr) { + cairo_pattern_t *p = sp_gradient_create_preview_pattern(gr, widget->allocation.width); + cairo_set_source(ct, p); + cairo_paint(ct); + cairo_pattern_destroy(p); + } + cairo_destroy(ct); + + return TRUE; } GtkWidget * @@ -268,26 +195,6 @@ sp_gradient_image_gradient_modified (SPObject *, guint /*flags*/, SPGradientImag static void sp_gradient_image_update (SPGradientImage *image) { - GtkAllocation *allocation; - - if (!image->px) return; - - allocation = &((GtkWidget *) image)->allocation; - - if (image->gradient) { - nr_render_checkerboard_rgb (image->px, allocation->width, VBLOCK, 3 * allocation->width, 0, 0); - sp_gradient_render_vector_block_rgb (image->gradient, - image->px, allocation->width, VBLOCK, 3 * allocation->width, - 0, allocation->width, TRUE); - } else { - NRPixBlock pb; - nr_pixblock_setup_extern (&pb, NR_PIXBLOCK_MODE_R8G8B8, - 0, 0, allocation->width, VBLOCK, - image->px, 3 * allocation->width, TRUE, FALSE); - nr_pixblock_render_gray_noise (&pb, NULL); - nr_pixblock_release (&pb); - } - if (GTK_WIDGET_DRAWABLE (image)) { gtk_widget_queue_draw (GTK_WIDGET (image)); } |
