diff options
Diffstat (limited to 'src/widgets/gradient-image.cpp')
| -rw-r--r-- | src/widgets/gradient-image.cpp | 183 |
1 files changed, 43 insertions, 140 deletions
diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp index 11d2d528a..3e5f15499 100644 --- a/src/widgets/gradient-image.cpp +++ b/src/widgets/gradient-image.cpp @@ -12,10 +12,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#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 +27,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); @@ -41,24 +36,22 @@ static void sp_gradient_image_update (SPGradientImage *img); static GtkWidgetClass *parent_class; -GtkType +GType sp_gradient_image_get_type (void) { - //TODO: switch to GObject - // GtkType and such calls were deprecated a while back with the - // introduction of GObject as a separate layer, with GType instead. --JonCruz - - static GtkType type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo info = { - (gchar*) "SPGradientImage", - sizeof (SPGradientImage), + GTypeInfo info = { sizeof (SPGradientImageClass), - (GtkClassInitFunc) sp_gradient_image_class_init, - (GtkObjectInitFunc) sp_gradient_image_init, - NULL, NULL, NULL + NULL, NULL, + (GClassInitFunc) sp_gradient_image_class_init, + NULL, NULL, + sizeof (SPGradientImage), + 0, + (GInstanceInitFunc) sp_gradient_image_init, + NULL }; - type = gtk_type_unique (GTK_TYPE_WIDGET, &info); + type = g_type_register_static (GTK_TYPE_WIDGET, "SPGradientImage", &info, (GTypeFlags)0); } return type; } @@ -72,24 +65,20 @@ sp_gradient_image_class_init (SPGradientImageClass *klass) object_class = (GtkObjectClass *) klass; widget_class = (GtkWidgetClass *) klass; - parent_class = (GtkWidgetClass*)gtk_type_class (GTK_TYPE_WIDGET); + parent_class = (GtkWidgetClass*)g_type_class_peek_parent (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; } static void sp_gradient_image_init (SPGradientImage *image) { - GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW); + gtk_widget_set_has_window (GTK_WIDGET(image), FALSE); image->gradient = NULL; - image->px = NULL; new (&image->release_connection) sigc::connection(); new (&image->modified_connection) sigc::connection(); @@ -115,105 +104,39 @@ sp_gradient_image_destroy (GtkObject *object) (* ((GtkObjectClass *) (parent_class))->destroy) (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) +static void sp_gradient_image_size_request(GtkWidget * /*widget*/, GtkRequisition *requisition) { - 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); + requisition->width = 64; + requisition->height = 12; } 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 * @@ -221,7 +144,7 @@ sp_gradient_image_new (SPGradient *gradient) { SPGradientImage *image; - image = (SPGradientImage*)gtk_type_new (SP_TYPE_GRADIENT_IMAGE); + image = (SPGradientImage*)g_object_new (SP_TYPE_GRADIENT_IMAGE, NULL); sp_gradient_image_set_gradient (image, gradient); @@ -268,27 +191,7 @@ 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)) { + if (gtk_widget_is_drawable (GTK_WIDGET(image))) { gtk_widget_queue_draw (GTK_WIDGET (image)); } } |
