static void gimp_drawable_undo_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (object); switch (property_id) { case PROP_BUFFER: g_value_set_object (value, drawable_undo->buffer); break; case PROP_X: g_value_set_int (value, drawable_undo->x); break; case PROP_Y: g_value_set_int (value, drawable_undo->y); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void gimp_drawable_undo_constructed (GObject *object) { GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (object); G_OBJECT_CLASS (parent_class)->constructed (object); g_assert (GIMP_IS_DRAWABLE (GIMP_ITEM_UNDO (object)->item)); g_assert (drawable_undo->buffer != NULL); }
static gint64 gimp_drawable_undo_get_memsize (GimpObject *object, gint64 *gui_size) { GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (object); gint64 memsize = 0; memsize += gimp_gegl_buffer_get_memsize (drawable_undo->buffer); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size); }
static void gimp_drawable_undo_pop (GimpUndo *undo, GimpUndoMode undo_mode, GimpUndoAccumulator *accum) { GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (undo); GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); gimp_drawable_swap_pixels (GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item), drawable_undo->buffer, drawable_undo->x, drawable_undo->y); }
gboolean gimp_edit_fade (GimpImage *image, GimpContext *context) { GimpDrawableUndo *undo; g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE); undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image)); if (undo && undo->applied_buffer) { GimpDrawable *drawable; GeglBuffer *buffer; drawable = GIMP_DRAWABLE (GIMP_ITEM_UNDO (undo)->item); g_object_ref (undo); buffer = g_object_ref (undo->applied_buffer); gimp_image_undo (image); gimp_drawable_apply_buffer (drawable, buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (undo->buffer), gegl_buffer_get_height (undo->buffer)), TRUE, gimp_object_get_name (undo), gimp_context_get_opacity (context), gimp_context_get_paint_mode (context), GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COLOR_SPACE_AUTO, GIMP_LAYER_COMPOSITE_AUTO, NULL, undo->x, undo->y); g_object_unref (buffer); g_object_unref (undo); return TRUE; } return FALSE; }
static void gimp_drawable_undo_free (GimpUndo *undo, GimpUndoMode undo_mode) { GimpDrawableUndo *drawable_undo = GIMP_DRAWABLE_UNDO (undo); if (drawable_undo->buffer) { g_object_unref (drawable_undo->buffer); drawable_undo->buffer = NULL; } if (drawable_undo->applied_buffer) { g_object_unref (drawable_undo->applied_buffer); drawable_undo->applied_buffer = NULL; } GIMP_UNDO_CLASS (parent_class)->free (undo, undo_mode); }
void gimp_drawable_real_apply_region (GimpDrawable *drawable, PixelRegion *src2PR, gboolean push_undo, const gchar *undo_desc, gdouble opacity, GimpLayerModeEffects mode, TileManager *src1_tiles, PixelRegion *destPR, gint x, gint y) { GimpItem *item = GIMP_ITEM (drawable); GimpImage *image = gimp_item_get_image (item); GimpChannel *mask = gimp_image_get_mask (image); gint x1, y1, x2, y2; gint offset_x, offset_y; PixelRegion src1PR, my_destPR; CombinationMode operation; gboolean active_components[MAX_CHANNELS]; /* don't apply the mask to itself and don't apply an empty mask */ if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask)) mask = NULL; /* configure the active channel array */ gimp_drawable_get_active_components (drawable, active_components); /* determine what sort of operation is being attempted and * if it's actually legal... */ operation = gimp_image_get_combination_mode (gimp_drawable_type (drawable), src2PR->bytes); if (operation == -1) { g_warning ("%s: illegal parameters.", G_STRFUNC); return; } /* get the layer offsets */ gimp_item_get_offset (item, &offset_x, &offset_y); /* make sure the image application coordinates are within drawable bounds */ x1 = CLAMP (x, 0, gimp_item_get_width (item)); y1 = CLAMP (y, 0, gimp_item_get_height (item)); x2 = CLAMP (x + src2PR->w, 0, gimp_item_get_width (item)); y2 = CLAMP (y + src2PR->h, 0, gimp_item_get_height (item)); if (mask) { GimpItem *mask_item = GIMP_ITEM (mask); /* make sure coordinates are in mask bounds ... * we need to add the layer offset to transform coords * into the mask coordinate system */ x1 = CLAMP (x1, -offset_x, gimp_item_get_width (mask_item) - offset_x); y1 = CLAMP (y1, -offset_y, gimp_item_get_height (mask_item) - offset_y); x2 = CLAMP (x2, -offset_x, gimp_item_get_width (mask_item) - offset_x); y2 = CLAMP (y2, -offset_y, gimp_item_get_height (mask_item) - offset_y); } /* If the calling procedure specified an undo step... */ if (push_undo) { GimpDrawableUndo *undo; gimp_drawable_push_undo (drawable, undo_desc, x1, y1, x2 - x1, y2 - y1, NULL, FALSE); undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image)); if (undo) { PixelRegion tmp_srcPR; PixelRegion tmp_destPR; undo->paint_mode = mode; undo->opacity = opacity; undo->src2_tiles = tile_manager_new (x2 - x1, y2 - y1, src2PR->bytes); tmp_srcPR = *src2PR; pixel_region_resize (&tmp_srcPR, src2PR->x + (x1 - x), src2PR->y + (y1 - y), x2 - x1, y2 - y1); pixel_region_init (&tmp_destPR, undo->src2_tiles, 0, 0, x2 - x1, y2 - y1, TRUE); copy_region (&tmp_srcPR, &tmp_destPR); } } /* configure the pixel regions */ /* check if an alternative to using the drawable's data as src1 was * provided... */ if (src1_tiles) { pixel_region_init (&src1PR, src1_tiles, x1, y1, x2 - x1, y2 - y1, FALSE); } else { pixel_region_init (&src1PR, gimp_drawable_get_tiles (drawable), x1, y1, x2 - x1, y2 - y1, FALSE); } /* check if an alternative to using the drawable's data as dest was * provided... */ if (!destPR) { pixel_region_init (&my_destPR, gimp_drawable_get_tiles (drawable), x1, y1, x2 - x1, y2 - y1, TRUE); destPR = &my_destPR; } pixel_region_resize (src2PR, src2PR->x + (x1 - x), src2PR->y + (y1 - y), x2 - x1, y2 - y1); if (mask) { PixelRegion maskPR; pixel_region_init (&maskPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)), x1 + offset_x, y1 + offset_y, x2 - x1, y2 - y1, FALSE); combine_regions (&src1PR, src2PR, destPR, &maskPR, NULL, opacity * 255.999, mode, active_components, operation); } else { combine_regions (&src1PR, src2PR, destPR, NULL, NULL, opacity * 255.999, mode, active_components, operation); } }
void edit_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpDisplay *display = action_data_get_display (data); GimpDrawable *drawable = NULL; gchar *undo_name = NULL; gchar *redo_name = NULL; gchar *fade_name = NULL; gboolean writable = FALSE; gboolean children = FALSE; gboolean undo_enabled = FALSE; gboolean fade_enabled = FALSE; if (image) { drawable = gimp_image_get_active_drawable (image); if (drawable) { writable = ! gimp_item_is_content_locked (GIMP_ITEM (drawable)); if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) children = TRUE; } undo_enabled = gimp_image_undo_is_enabled (image); if (undo_enabled) { GimpUndoStack *undo_stack = gimp_image_get_undo_stack (image); GimpUndoStack *redo_stack = gimp_image_get_redo_stack (image); GimpUndo *undo = gimp_undo_stack_peek (undo_stack); GimpUndo *redo = gimp_undo_stack_peek (redo_stack); const gchar *tool_undo = NULL; const gchar *tool_redo = NULL; if (display) { tool_undo = tool_manager_get_undo_desc_active (image->gimp, display); tool_redo = tool_manager_get_redo_desc_active (image->gimp, display); } if (tool_undo) undo_name = g_strdup_printf (_("_Undo %s"), tool_undo); else if (undo) undo_name = g_strdup_printf (_("_Undo %s"), gimp_object_get_name (undo)); if (tool_redo) redo_name = g_strdup_printf (_("_Redo %s"), tool_redo); else if (redo) redo_name = g_strdup_printf (_("_Redo %s"), gimp_object_get_name (redo)); undo = gimp_image_undo_get_fadeable (image); if (GIMP_IS_DRAWABLE_UNDO (undo) && GIMP_DRAWABLE_UNDO (undo)->applied_buffer) { fade_enabled = TRUE; } if (fade_enabled) { fade_name = g_strdup_printf (_("_Fade %s..."), gimp_object_get_name (undo)); } } } #define SET_LABEL(action,label) \ gimp_action_group_set_action_label (group, action, (label)) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) SET_LABEL ("edit-undo", undo_name ? undo_name : _("_Undo")); SET_LABEL ("edit-redo", redo_name ? redo_name : _("_Redo")); SET_LABEL ("edit-fade", fade_name ? fade_name : _("_Fade...")); SET_SENSITIVE ("edit-undo", undo_enabled && undo_name); SET_SENSITIVE ("edit-redo", undo_enabled && redo_name); SET_SENSITIVE ("edit-strong-undo", undo_enabled && undo_name); SET_SENSITIVE ("edit-strong-redo", undo_enabled && redo_name); SET_SENSITIVE ("edit-undo-clear", undo_enabled && (undo_name || redo_name)); SET_SENSITIVE ("edit-fade", fade_enabled && fade_name); g_free (undo_name); g_free (redo_name); g_free (fade_name); SET_SENSITIVE ("edit-cut", writable && !children); SET_SENSITIVE ("edit-copy", drawable); SET_SENSITIVE ("edit-copy-visible", image); SET_SENSITIVE ("edit-paste", !image || (!drawable || (writable && !children))); SET_SENSITIVE ("edit-paste-as-new-layer", image); SET_SENSITIVE ("edit-paste-into", image && (!drawable || (writable && !children))); SET_SENSITIVE ("edit-named-cut", writable && !children); SET_SENSITIVE ("edit-named-copy", drawable); SET_SENSITIVE ("edit-named-copy-visible", drawable); SET_SENSITIVE ("edit-named-paste", TRUE); SET_SENSITIVE ("edit-clear", writable && !children); SET_SENSITIVE ("edit-fill-fg", writable && !children); SET_SENSITIVE ("edit-fill-bg", writable && !children); SET_SENSITIVE ("edit-fill-pattern", writable && !children); #undef SET_LABEL #undef SET_SENSITIVE }
void gimp_drawable_real_apply_buffer (GimpDrawable *drawable, GeglBuffer *buffer, const GeglRectangle *buffer_region, gboolean push_undo, const gchar *undo_desc, gdouble opacity, GimpLayerModeEffects mode, GeglBuffer *base_buffer, gint base_x, gint base_y) { GimpItem *item = GIMP_ITEM (drawable); GimpImage *image = gimp_item_get_image (item); GimpChannel *mask = gimp_image_get_mask (image); GeglBuffer *mask_buffer = NULL; GeglNode *apply; GimpComponentMask affect; gint x, y, width, height; gint offset_x, offset_y; /* don't apply the mask to itself and don't apply an empty mask */ if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask)) mask = NULL; if (! base_buffer) base_buffer = gimp_drawable_get_buffer (drawable); /* get the layer offsets */ gimp_item_get_offset (item, &offset_x, &offset_y); /* make sure the image application coordinates are within drawable bounds */ gimp_rectangle_intersect (base_x, base_y, buffer_region->width, buffer_region->height, 0, 0, gimp_item_get_width (item), gimp_item_get_height (item), &x, &y, &width, &height); if (mask) { GimpItem *mask_item = GIMP_ITEM (mask); /* make sure coordinates are in mask bounds ... * we need to add the layer offset to transform coords * into the mask coordinate system */ gimp_rectangle_intersect (x, y, width, height, -offset_x, -offset_y, gimp_item_get_width (mask_item), gimp_item_get_height (mask_item), &x, &y, &width, &height); } if (push_undo) { GimpDrawableUndo *undo; gimp_drawable_push_undo (drawable, undo_desc, NULL, x, y, width, height); undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image)); if (undo) { undo->paint_mode = mode; undo->opacity = opacity; undo->applied_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height), gegl_buffer_get_format (buffer)); gegl_buffer_copy (buffer, GEGL_RECTANGLE (buffer_region->x + (x - base_x), buffer_region->y + (y - base_y), width, height), undo->applied_buffer, GEGL_RECTANGLE (0, 0, width, height)); } } if (mask) mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)); affect = gimp_drawable_get_active_mask (drawable); apply = gimp_gegl_create_apply_buffer_node (buffer, base_x - buffer_region->x, base_y - buffer_region->y, 0, 0, 0, 0, mask_buffer, -offset_x, -offset_y, opacity, mode, affect); gimp_gegl_apply_operation (base_buffer, NULL, NULL, apply, gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (x, y, width, height)); g_object_unref (apply); }
FadeDialog *private; GimpDrawableUndo *undo; GimpDrawable *drawable; GimpItem *item; GtkWidget *dialog; GtkWidget *main_vbox; GtkWidget *table; GtkWidget *menu; gchar *title; gint table_row = 0; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL); undo = GIMP_DRAWABLE_UNDO (gimp_image_undo_get_fadeable (image)); if (! (undo && undo->src2_tiles)) return NULL; item = GIMP_ITEM_UNDO (undo)->item; drawable = GIMP_DRAWABLE (item); private = g_slice_new0 (FadeDialog); private->image = image; private->drawable = drawable; private->context = gimp_context_new (image->gimp, "fade-dialog", NULL); private->applied = FALSE; private->orig_paint_mode = undo->paint_mode;