mirror of https://github.com/GNOME/gimp.git
app/core/Makefile.am app/core/core-types.h new undo class which handles
2007-01-28 Michael Natterer <mitch@gimp.org> * app/core/Makefile.am * app/core/core-types.h * app/core/gimplayerpropundo.[ch]: new undo class which handles LAYER_REPOSITION, LAYER_MODE, LAYER_OPACITY and LAYER_LOCK_ALPHA. * app/core/gimpimage-undo-push.c: use the new undo class and remove the resp. code here. svn path=/trunk/; revision=21791
This commit is contained in:
parent
60370072fd
commit
125a001976
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-01-28 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/Makefile.am
|
||||
* app/core/core-types.h
|
||||
* app/core/gimplayerpropundo.[ch]: new undo class which handles
|
||||
LAYER_REPOSITION, LAYER_MODE, LAYER_OPACITY and LAYER_LOCK_ALPHA.
|
||||
|
||||
* app/core/gimpimage-undo-push.c: use the new undo class and
|
||||
remove the resp. code here.
|
||||
|
||||
2007-01-28 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/Makefile.am
|
||||
|
|
|
@ -208,6 +208,8 @@ libappcore_a_sources = \
|
|||
gimplayer-floating-sel.h \
|
||||
gimplayermask.c \
|
||||
gimplayermask.h \
|
||||
gimplayerpropundo.c \
|
||||
gimplayerpropundo.h \
|
||||
gimplist.c \
|
||||
gimplist.h \
|
||||
gimpobject.c \
|
||||
|
|
|
@ -115,6 +115,7 @@ typedef struct _GimpItemUndo GimpItemUndo;
|
|||
typedef struct _GimpItemPropUndo GimpItemPropUndo;
|
||||
typedef struct _GimpChannelUndo GimpChannelUndo;
|
||||
typedef struct _GimpDrawableUndo GimpDrawableUndo;
|
||||
typedef struct _GimpLayerPropUndo GimpLayerPropUndo;
|
||||
typedef struct _GimpUndoStack GimpUndoStack;
|
||||
typedef struct _GimpUndoAccumulator GimpUndoAccumulator;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "gimplayer.h"
|
||||
#include "gimplayer-floating-sel.h"
|
||||
#include "gimplayermask.h"
|
||||
#include "gimplayerpropundo.h"
|
||||
#include "gimplist.h"
|
||||
#include "gimpparasitelist.h"
|
||||
#include "gimpselection.h"
|
||||
|
@ -1021,19 +1022,6 @@ undo_free_layer (GimpUndo *undo,
|
|||
/* Layer re-position Undo */
|
||||
/***************************/
|
||||
|
||||
typedef struct _LayerRepositionUndo LayerRepositionUndo;
|
||||
|
||||
struct _LayerRepositionUndo
|
||||
{
|
||||
gint old_position;
|
||||
};
|
||||
|
||||
static gboolean undo_pop_layer_reposition (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
static void undo_free_layer_reposition (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode);
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_reposition (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
|
@ -1045,107 +1033,29 @@ gimp_image_undo_push_layer_reposition (GimpImage *image,
|
|||
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
||||
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)), FALSE);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
|
||||
sizeof (LayerRepositionUndo),
|
||||
sizeof (LayerRepositionUndo),
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_LAYER_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_LAYER_REPOSITION, undo_desc,
|
||||
GIMP_DIRTY_IMAGE_STRUCTURE,
|
||||
undo_pop_layer_reposition,
|
||||
undo_free_layer_reposition,
|
||||
NULL, NULL,
|
||||
"item", layer,
|
||||
NULL)))
|
||||
{
|
||||
LayerRepositionUndo *lru = new->data;
|
||||
|
||||
lru->old_position = gimp_image_get_layer_index (image, layer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
undo_pop_layer_reposition (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum)
|
||||
{
|
||||
LayerRepositionUndo *lru = undo->data;
|
||||
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
|
||||
gint pos;
|
||||
|
||||
/* what's the layer's current index? */
|
||||
pos = gimp_image_get_layer_index (undo->image, layer);
|
||||
gimp_image_position_layer (undo->image, layer, lru->old_position,
|
||||
FALSE, NULL);
|
||||
lru->old_position = pos;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
undo_free_layer_reposition (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode)
|
||||
{
|
||||
g_free (undo->data);
|
||||
}
|
||||
|
||||
|
||||
/***************************/
|
||||
/* Layer properties Undo */
|
||||
/***************************/
|
||||
|
||||
typedef struct _LayerPropertiesUndo LayerPropertiesUndo;
|
||||
|
||||
struct _LayerPropertiesUndo
|
||||
{
|
||||
GimpLayerModeEffects old_mode;
|
||||
gdouble old_opacity;
|
||||
gboolean old_lock_alpha;
|
||||
};
|
||||
|
||||
static gboolean undo_push_layer_properties (GimpImage *image,
|
||||
GimpUndoType undo_type,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer);
|
||||
static gboolean undo_pop_layer_properties (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
static void undo_free_layer_properties (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode);
|
||||
/*********************/
|
||||
/* Layer Mode Undo */
|
||||
/*********************/
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_mode (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
return undo_push_layer_properties (image, GIMP_UNDO_LAYER_MODE,
|
||||
undo_desc, layer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_opacity (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
return undo_push_layer_properties (image, GIMP_UNDO_LAYER_OPACITY,
|
||||
undo_desc, layer);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_lock_alpha (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
return undo_push_layer_properties (image, GIMP_UNDO_LAYER_LOCK_ALPHA,
|
||||
undo_desc, layer);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
undo_push_layer_properties (GimpImage *image,
|
||||
GimpUndoType undo_type,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
GimpUndo *new;
|
||||
|
||||
|
@ -1153,81 +1063,78 @@ undo_push_layer_properties (GimpImage *image,
|
|||
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
||||
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)), FALSE);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
|
||||
sizeof (LayerPropertiesUndo),
|
||||
sizeof (LayerPropertiesUndo),
|
||||
undo_type, undo_desc,
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_LAYER_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_LAYER_MODE, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
undo_pop_layer_properties,
|
||||
undo_free_layer_properties,
|
||||
NULL, NULL,
|
||||
"item", layer,
|
||||
NULL)))
|
||||
{
|
||||
LayerPropertiesUndo *lpu = new->data;
|
||||
|
||||
lpu->old_mode = gimp_layer_get_mode (layer);
|
||||
lpu->old_opacity = gimp_layer_get_opacity (layer);
|
||||
lpu->old_lock_alpha = gimp_layer_get_lock_alpha (layer);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
undo_pop_layer_properties (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum)
|
||||
|
||||
/************************/
|
||||
/* Layer Opacity Undo */
|
||||
/************************/
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_opacity (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
LayerPropertiesUndo *lpu = undo->data;
|
||||
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
|
||||
GimpUndo *new;
|
||||
|
||||
switch (undo->undo_type)
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
||||
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
||||
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)), FALSE);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_LAYER_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_LAYER_OPACITY, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
NULL, NULL,
|
||||
"item", layer,
|
||||
NULL)))
|
||||
{
|
||||
case GIMP_UNDO_LAYER_MODE:
|
||||
{
|
||||
GimpLayerModeEffects mode;
|
||||
|
||||
mode = gimp_layer_get_mode (layer);
|
||||
gimp_layer_set_mode (layer, lpu->old_mode, FALSE);
|
||||
lpu->old_mode = mode;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_LAYER_OPACITY:
|
||||
{
|
||||
gdouble opacity;
|
||||
|
||||
opacity = gimp_layer_get_opacity (layer);
|
||||
gimp_layer_set_opacity (layer, lpu->old_opacity, FALSE);
|
||||
lpu->old_opacity = opacity;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_UNDO_LAYER_LOCK_ALPHA:
|
||||
{
|
||||
gboolean lock_alpha;
|
||||
|
||||
lock_alpha = gimp_layer_get_lock_alpha (layer);
|
||||
gimp_layer_set_lock_alpha (layer, lpu->old_lock_alpha, FALSE);
|
||||
lpu->old_lock_alpha = lock_alpha;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_val_if_reached (FALSE);
|
||||
break;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
undo_free_layer_properties (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode)
|
||||
|
||||
/***************************/
|
||||
/* Layer Lock Alpha Undo */
|
||||
/***************************/
|
||||
|
||||
gboolean
|
||||
gimp_image_undo_push_layer_lock_alpha (GimpImage *image,
|
||||
const gchar *undo_desc,
|
||||
GimpLayer *layer)
|
||||
{
|
||||
g_free (undo->data);
|
||||
GimpUndo *new;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
||||
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
|
||||
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)), FALSE);
|
||||
|
||||
if ((new = gimp_image_undo_push (image, GIMP_TYPE_LAYER_PROP_UNDO,
|
||||
0, 0,
|
||||
GIMP_UNDO_LAYER_LOCK_ALPHA, undo_desc,
|
||||
GIMP_DIRTY_ITEM_META,
|
||||
NULL, NULL,
|
||||
"item", layer,
|
||||
NULL)))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
/* 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 <glib-object.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "gimpimage.h"
|
||||
#include "gimplayer.h"
|
||||
#include "gimplayerpropundo.h"
|
||||
|
||||
|
||||
static GObject * gimp_layer_prop_undo_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params);
|
||||
|
||||
static void gimp_layer_prop_undo_pop (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpLayerPropUndo, gimp_layer_prop_undo, GIMP_TYPE_ITEM_UNDO)
|
||||
|
||||
#define parent_class gimp_layer_prop_undo_parent_class
|
||||
|
||||
|
||||
static void
|
||||
gimp_layer_prop_undo_class_init (GimpLayerPropUndoClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
|
||||
|
||||
object_class->constructor = gimp_layer_prop_undo_constructor;
|
||||
|
||||
undo_class->pop = gimp_layer_prop_undo_pop;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_layer_prop_undo_init (GimpLayerPropUndo *undo)
|
||||
{
|
||||
}
|
||||
|
||||
static GObject *
|
||||
gimp_layer_prop_undo_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params)
|
||||
{
|
||||
GObject *object;
|
||||
GimpLayerPropUndo *layer_prop_undo;
|
||||
GimpImage *image;
|
||||
GimpLayer *layer;
|
||||
|
||||
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
||||
|
||||
layer_prop_undo = GIMP_LAYER_PROP_UNDO (object);
|
||||
|
||||
g_assert (GIMP_IS_LAYER (GIMP_ITEM_UNDO (object)->item));
|
||||
|
||||
image = GIMP_UNDO (object)->image;
|
||||
layer = GIMP_LAYER (GIMP_ITEM_UNDO (object)->item);
|
||||
|
||||
layer_prop_undo->position = gimp_image_get_layer_index (image, layer);
|
||||
layer_prop_undo->mode = gimp_layer_get_mode (layer);
|
||||
layer_prop_undo->opacity = gimp_layer_get_opacity (layer);
|
||||
layer_prop_undo->lock_alpha = gimp_layer_get_lock_alpha (layer);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_layer_prop_undo_pop (GimpUndo *undo,
|
||||
GimpUndoMode undo_mode,
|
||||
GimpUndoAccumulator *accum)
|
||||
{
|
||||
GimpLayerPropUndo *layer_prop_undo = GIMP_LAYER_PROP_UNDO (undo);
|
||||
GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (undo)->item);
|
||||
|
||||
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
|
||||
|
||||
if (undo->undo_type == GIMP_UNDO_LAYER_REPOSITION)
|
||||
{
|
||||
gint position;
|
||||
|
||||
position = gimp_image_get_layer_index (undo->image, layer);
|
||||
gimp_image_position_layer (undo->image, layer,
|
||||
layer_prop_undo->position,
|
||||
FALSE, NULL);
|
||||
layer_prop_undo->position = position;
|
||||
}
|
||||
else if (undo->undo_type == GIMP_UNDO_LAYER_MODE)
|
||||
{
|
||||
GimpLayerModeEffects mode;
|
||||
|
||||
mode = gimp_layer_get_mode (layer);
|
||||
gimp_layer_set_mode (layer, layer_prop_undo->mode, FALSE);
|
||||
layer_prop_undo->mode = mode;
|
||||
}
|
||||
else if (undo->undo_type == GIMP_UNDO_LAYER_OPACITY)
|
||||
{
|
||||
gdouble opacity;
|
||||
|
||||
opacity = gimp_layer_get_opacity (layer);
|
||||
gimp_layer_set_opacity (layer, layer_prop_undo->opacity, FALSE);
|
||||
layer_prop_undo->opacity = opacity;
|
||||
}
|
||||
else if (undo->undo_type == GIMP_UNDO_LAYER_LOCK_ALPHA)
|
||||
{
|
||||
gboolean lock_alpha;
|
||||
|
||||
lock_alpha = gimp_layer_get_lock_alpha (layer);
|
||||
gimp_layer_set_lock_alpha (layer, layer_prop_undo->lock_alpha, FALSE);
|
||||
layer_prop_undo->lock_alpha = lock_alpha;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/* 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_PROP_UNDO_H__
|
||||
#define __GIMP_LAYER_PROP_UNDO_H__
|
||||
|
||||
|
||||
#include "gimpitemundo.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_LAYER_PROP_UNDO (gimp_layer_prop_undo_get_type ())
|
||||
#define GIMP_LAYER_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_LAYER_PROP_UNDO, GimpLayerPropUndo))
|
||||
#define GIMP_LAYER_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_LAYER_PROP_UNDO, GimpLayerPropUndoClass))
|
||||
#define GIMP_IS_LAYER_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_LAYER_PROP_UNDO))
|
||||
#define GIMP_IS_LAYER_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_LAYER_PROP_UNDO))
|
||||
#define GIMP_LAYER_PROP_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_LAYER_PROP_UNDO, GimpLayerPropUndoClass))
|
||||
|
||||
|
||||
typedef struct _GimpLayerPropUndoClass GimpLayerPropUndoClass;
|
||||
|
||||
struct _GimpLayerPropUndo
|
||||
{
|
||||
GimpItemUndo parent_instance;
|
||||
|
||||
gint position;
|
||||
GimpLayerModeEffects mode;
|
||||
gdouble opacity;
|
||||
gboolean lock_alpha;
|
||||
};
|
||||
|
||||
struct _GimpLayerPropUndoClass
|
||||
{
|
||||
GimpItemUndoClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GType gimp_layer_prop_undo_get_type (void) G_GNUC_CONST;
|
||||
|
||||
|
||||
#endif /* __GIMP_LAYER_PROP_UNDO_H__ */
|
Loading…
Reference in New Issue