GtkWidget * sp_gradient_image_new (SPGradient *gradient) { SPGradientImage *image = SP_GRADIENT_IMAGE(g_object_new(SP_TYPE_GRADIENT_IMAGE, NULL)); sp_gradient_image_set_gradient (image, gradient); return GTK_WIDGET(image); }
static void sp_gradient_image_size_request (GtkWidget *widget, GtkRequisition *requisition) { SPGradientImage *slider; slider = SP_GRADIENT_IMAGE (widget); requisition->width = 64; requisition->height = 16; }
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_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_destroy (GtkObject *object) { SPGradientImage *image; image = SP_GRADIENT_IMAGE (object); if (image->gradient) { sp_signal_disconnect_by_data (image->gradient, image); image->gradient = NULL; } if (((GtkObjectClass *) (parent_class))->destroy) (* ((GtkObjectClass *) (parent_class))->destroy) (object); }
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; }
static gboolean sp_gradient_image_draw(GtkWidget *widget, cairo_t *ct) { SPGradientImage *image = SP_GRADIENT_IMAGE(widget); SPGradient *gr = image->gradient; GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); 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, allocation.width); cairo_set_source(ct, p); cairo_paint(ct); cairo_pattern_destroy(p); } return TRUE; }
static void sp_gradient_image_destroy(GtkObject *object) #endif { SPGradientImage *image = SP_GRADIENT_IMAGE (object); if (image->gradient) { image->release_connection.disconnect(); image->modified_connection.disconnect(); image->gradient = NULL; } image->release_connection.~connection(); image->modified_connection.~connection(); #if GTK_CHECK_VERSION(3,0,0) if (parent_class->destroy) (* (parent_class)->destroy) (object); #else if ((GTK_OBJECT_CLASS(parent_class))->destroy) (* (GTK_OBJECT_CLASS(parent_class))->destroy) (object); #endif }