From a7c0058c6228d6eb4ea409a9d0f66c50fde746d5 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 31 Jan 2007 18:50:39 +0000 Subject: [PATCH] app/core/Makefile.am app/core/core-types.h new undo class for 2007-01-31 Michael Natterer * app/core/Makefile.am * app/core/core-types.h * app/core/gimplayermaskpropundo.[ch]: new undo class for GIMP_UNDO_LAYER_MASK_APPLY and GIMP_UNDO_LAYER_MASK_SHOW. * app/core/gimpimage-undo-push.c: use it here. svn path=/trunk/; revision=21823 --- ChangeLog | 9 +++ app/core/Makefile.am | 2 + app/core/core-types.h | 31 ++++---- app/core/gimpimage-undo-push.c | 118 ++++++---------------------- app/core/gimplayermaskpropundo.c | 129 +++++++++++++++++++++++++++++++ app/core/gimplayermaskpropundo.h | 53 +++++++++++++ 6 files changed, 231 insertions(+), 111 deletions(-) create mode 100644 app/core/gimplayermaskpropundo.c create mode 100644 app/core/gimplayermaskpropundo.h diff --git a/ChangeLog b/ChangeLog index 92fcae8c31..6ad16a8039 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-01-31 Michael Natterer + + * app/core/Makefile.am + * app/core/core-types.h + * app/core/gimplayermaskpropundo.[ch]: new undo class for + GIMP_UNDO_LAYER_MASK_APPLY and GIMP_UNDO_LAYER_MASK_SHOW. + + * app/core/gimpimage-undo-push.c: use it here. + 2007-01-31 Michael Natterer * app/core/Makefile.am diff --git a/app/core/Makefile.am b/app/core/Makefile.am index 52cbb012aa..1212712f34 100644 --- a/app/core/Makefile.am +++ b/app/core/Makefile.am @@ -212,6 +212,8 @@ libappcore_a_sources = \ gimplayer-floating-sel.h \ gimplayermask.c \ gimplayermask.h \ + gimplayermaskpropundo.c \ + gimplayermaskpropundo.h \ gimplayermaskundo.c \ gimplayermaskundo.h \ gimplayerpropundo.c \ diff --git a/app/core/core-types.h b/app/core/core-types.h index d121fdad3f..468edb02a4 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -109,21 +109,22 @@ typedef struct _GimpLayerMask GimpLayerMask; /* undo objects */ -typedef struct _GimpUndo GimpUndo; -typedef struct _GimpImageUndo GimpImageUndo; -typedef struct _GimpItemUndo GimpItemUndo; -typedef struct _GimpItemPropUndo GimpItemPropUndo; -typedef struct _GimpChannelUndo GimpChannelUndo; -typedef struct _GimpChannelPropUndo GimpChannelPropUndo; -typedef struct _GimpDrawableUndo GimpDrawableUndo; -typedef struct _GimpLayerMaskUndo GimpLayerMaskUndo; -typedef struct _GimpLayerUndo GimpLayerUndo; -typedef struct _GimpLayerPropUndo GimpLayerPropUndo; -typedef struct _GimpMaskUndo GimpMaskUndo; -typedef struct _GimpGuideUndo GimpGuideUndo; -typedef struct _GimpSamplePointUndo GimpSamplePointUndo; -typedef struct _GimpUndoStack GimpUndoStack; -typedef struct _GimpUndoAccumulator GimpUndoAccumulator; +typedef struct _GimpUndo GimpUndo; +typedef struct _GimpImageUndo GimpImageUndo; +typedef struct _GimpItemUndo GimpItemUndo; +typedef struct _GimpItemPropUndo GimpItemPropUndo; +typedef struct _GimpChannelUndo GimpChannelUndo; +typedef struct _GimpChannelPropUndo GimpChannelPropUndo; +typedef struct _GimpDrawableUndo GimpDrawableUndo; +typedef struct _GimpLayerMaskUndo GimpLayerMaskUndo; +typedef struct _GimpLayerMaskPropUndo GimpLayerMaskPropUndo; +typedef struct _GimpLayerUndo GimpLayerUndo; +typedef struct _GimpLayerPropUndo GimpLayerPropUndo; +typedef struct _GimpMaskUndo GimpMaskUndo; +typedef struct _GimpGuideUndo GimpGuideUndo; +typedef struct _GimpSamplePointUndo GimpSamplePointUndo; +typedef struct _GimpUndoStack GimpUndoStack; +typedef struct _GimpUndoAccumulator GimpUndoAccumulator; /* misc objects */ diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index bc59358d3e..d7e50d105a 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -43,6 +43,7 @@ #include "gimplayer.h" #include "gimplayer-floating-sel.h" #include "gimplayermask.h" +#include "gimplayermaskpropundo.h" #include "gimplayermaskundo.h" #include "gimplayerpropundo.h" #include "gimplayerundo.h" @@ -656,35 +657,26 @@ gimp_image_undo_push_layer_mask_remove (GimpImage *image, } -/******************************/ -/* Layer Mask Property Undo */ -/******************************/ - -typedef struct _LayerMaskPropertyUndo LayerMaskPropertyUndo; - -struct _LayerMaskPropertyUndo -{ - gboolean old_apply; - gboolean old_show; -}; - -static GimpUndo * undo_push_layer_mask_properties (GimpImage *image, - GimpUndoType undo_type, - const gchar *undo_desc, - GimpLayerMask *mask); -static gboolean undo_pop_layer_mask_properties (GimpUndo *undo, - GimpUndoMode undo_mode, - GimpUndoAccumulator *accum); -static void undo_free_layer_mask_properties (GimpUndo *undo, - GimpUndoMode undo_mode); +/*******************************/ +/* Layer Mask Property Undos */ +/*******************************/ GimpUndo * gimp_image_undo_push_layer_mask_apply (GimpImage *image, const gchar *undo_desc, GimpLayerMask *mask) { - return undo_push_layer_mask_properties (image, GIMP_UNDO_LAYER_MASK_APPLY, - undo_desc, mask); + g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); + g_return_val_if_fail (GIMP_IS_LAYER_MASK (mask), NULL); + g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (mask)), NULL); + + return gimp_image_undo_push (image, GIMP_TYPE_LAYER_MASK_PROP_UNDO, + 0, 0, + GIMP_UNDO_LAYER_MASK_APPLY, undo_desc, + GIMP_DIRTY_ITEM_META, + NULL, NULL, + "item", mask, + NULL); } GimpUndo * @@ -692,83 +684,17 @@ gimp_image_undo_push_layer_mask_show (GimpImage *image, const gchar *undo_desc, GimpLayerMask *mask) { - return undo_push_layer_mask_properties (image, GIMP_UNDO_LAYER_MASK_SHOW, - undo_desc, mask); -} - -static GimpUndo * -undo_push_layer_mask_properties (GimpImage *image, - GimpUndoType undo_type, - const gchar *undo_desc, - GimpLayerMask *mask) -{ - GimpUndo *new; - gint64 size; - g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_LAYER_MASK (mask), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (mask)), NULL); - size = sizeof (LayerMaskPropertyUndo); - - if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO, - size, sizeof (LayerMaskPropertyUndo), - undo_type, undo_desc, - GIMP_DIRTY_ITEM_META, - undo_pop_layer_mask_properties, - undo_free_layer_mask_properties, - "item", mask, - NULL))) - { - LayerMaskPropertyUndo *lmp_undo = new->data; - - lmp_undo->old_apply = gimp_layer_mask_get_apply (mask); - lmp_undo->old_show = gimp_layer_mask_get_show (mask); - - return new; - } - - return NULL; -} - -static gboolean -undo_pop_layer_mask_properties (GimpUndo *undo, - GimpUndoMode undo_mode, - GimpUndoAccumulator *accum) -{ - LayerMaskPropertyUndo *lmp_undo = undo->data; - GimpLayerMask *mask; - gboolean val; - - mask = GIMP_LAYER_MASK (GIMP_ITEM_UNDO (undo)->item); - - switch (undo->undo_type) - { - case GIMP_UNDO_LAYER_MASK_APPLY: - val = gimp_layer_mask_get_apply (mask); - gimp_layer_mask_set_apply (mask, lmp_undo->old_apply, FALSE); - lmp_undo->old_apply = val; - break; - - case GIMP_UNDO_LAYER_MASK_SHOW: - val = gimp_layer_mask_get_show (mask); - gimp_layer_mask_set_show (mask, lmp_undo->old_show, FALSE); - lmp_undo->old_show = val; - break; - - default: - g_return_val_if_reached (FALSE); - break; - } - - return TRUE; -} - -static void -undo_free_layer_mask_properties (GimpUndo *undo, - GimpUndoMode undo_mode) -{ - g_free (undo->data); + return gimp_image_undo_push (image, GIMP_TYPE_LAYER_MASK_PROP_UNDO, + 0, 0, + GIMP_UNDO_LAYER_MASK_SHOW, undo_desc, + GIMP_DIRTY_ITEM_META, + NULL, NULL, + "item", mask, + NULL); } diff --git a/app/core/gimplayermaskpropundo.c b/app/core/gimplayermaskpropundo.c new file mode 100644 index 0000000000..c4bf6bc5a0 --- /dev/null +++ b/app/core/gimplayermaskpropundo.c @@ -0,0 +1,129 @@ +/* Gimp - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "core-types.h" + +#include "gimplayermask.h" +#include "gimplayermaskpropundo.h" + + +static GObject * gimp_layer_mask_prop_undo_constructor (GType type, + guint n_params, + GObjectConstructParam *params); + +static void gimp_layer_mask_prop_undo_pop (GimpUndo *undo, + GimpUndoMode undo_mode, + GimpUndoAccumulator *accum); + + +G_DEFINE_TYPE (GimpLayerMaskPropUndo, gimp_layer_mask_prop_undo, + GIMP_TYPE_ITEM_UNDO) + +#define parent_class gimp_layer_mask_prop_undo_parent_class + + +static void +gimp_layer_mask_prop_undo_class_init (GimpLayerMaskPropUndoClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass); + + object_class->constructor = gimp_layer_mask_prop_undo_constructor; + + undo_class->pop = gimp_layer_mask_prop_undo_pop; +} + +static void +gimp_layer_mask_prop_undo_init (GimpLayerMaskPropUndo *undo) +{ +} + +static GObject * +gimp_layer_mask_prop_undo_constructor (GType type, + guint n_params, + GObjectConstructParam *params) +{ + GObject *object; + GimpLayerMaskPropUndo *layer_mask_prop_undo; + GimpLayerMask *layer_mask; + + object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params); + + layer_mask_prop_undo = GIMP_LAYER_MASK_PROP_UNDO (object); + + g_assert (GIMP_IS_LAYER_MASK (GIMP_ITEM_UNDO (object)->item)); + + layer_mask = GIMP_LAYER_MASK (GIMP_ITEM_UNDO (object)->item); + + switch (GIMP_UNDO (object)->undo_type) + { + case GIMP_UNDO_LAYER_MASK_APPLY: + layer_mask_prop_undo->apply = gimp_layer_mask_get_apply (layer_mask); + break; + + case GIMP_UNDO_LAYER_MASK_SHOW: + layer_mask_prop_undo->show = gimp_layer_mask_get_show (layer_mask); + break; + + default: + g_assert_not_reached (); + } + + return object; +} + +static void +gimp_layer_mask_prop_undo_pop (GimpUndo *undo, + GimpUndoMode undo_mode, + GimpUndoAccumulator *accum) +{ + GimpLayerMaskPropUndo *layer_mask_prop_undo = GIMP_LAYER_MASK_PROP_UNDO (undo); + GimpLayerMask *layer_mask = GIMP_LAYER_MASK (GIMP_ITEM_UNDO (undo)->item); + + GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum); + + switch (undo->undo_type) + { + case GIMP_UNDO_LAYER_MASK_APPLY: + { + gboolean apply; + + apply = gimp_layer_mask_get_apply (layer_mask); + gimp_layer_mask_set_apply (layer_mask, layer_mask_prop_undo->apply, FALSE); + layer_mask_prop_undo->apply = apply; + } + break; + + case GIMP_UNDO_LAYER_MASK_SHOW: + { + gboolean show; + + show = gimp_layer_mask_get_show (layer_mask); + gimp_layer_mask_set_show (layer_mask, layer_mask_prop_undo->show, FALSE); + layer_mask_prop_undo->show = show; + } + break; + + default: + g_assert_not_reached (); + } +} diff --git a/app/core/gimplayermaskpropundo.h b/app/core/gimplayermaskpropundo.h new file mode 100644 index 0000000000..369194f816 --- /dev/null +++ b/app/core/gimplayermaskpropundo.h @@ -0,0 +1,53 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_LAYER_MASK_PROP_UNDO_H__ +#define __GIMP_LAYER_MASK_PROP_UNDO_H__ + + +#include "gimpitemundo.h" + + +#define GIMP_TYPE_LAYER_MASK_PROP_UNDO (gimp_layer_mask_prop_undo_get_type ()) +#define GIMP_LAYER_MASK_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_LAYER_MASK_PROP_UNDO, GimpLayerMaskPropUndo)) +#define GIMP_LAYER_MASK_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_LAYER_MASK_PROP_UNDO, GimpLayerMaskPropUndoClass)) +#define GIMP_IS_LAYER_MASK_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_LAYER_MASK_PROP_UNDO)) +#define GIMP_IS_LAYER_MASK_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_LAYER_MASK_PROP_UNDO)) +#define GIMP_LAYER_MASK_PROP_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_LAYER_MASK_PROP_UNDO, GimpLayerMaskPropUndoClass)) + + +typedef struct _GimpLayerMaskPropUndoClass GimpLayerMaskPropUndoClass; + +struct _GimpLayerMaskPropUndo +{ + GimpItemUndo parent_instance; + + gboolean apply; + gboolean show; +}; + +struct _GimpLayerMaskPropUndoClass +{ + GimpItemUndoClass parent_class; +}; + + +GType gimp_layer_mask_prop_undo_get_type (void) G_GNUC_CONST; + + +#endif /* __GIMP_LAYER_MASK_PROP_UNDO_H__ */