Commit e9b9f1bf authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/core/Makefile.am app/core/core-types.h new undo class which handles

2007-01-29  Michael Natterer  <mitch@gimp.org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpchannelpropundo.[ch]: new undo class which handles
	CHANNEL_REPOSITION and CHANNEL_COLOR.

	* app/core/gimpimage-undo-push.c: use the new undo class and
	remove the resp. code here.


svn path=/trunk/; revision=21799
parent 0eef7855
2007-01-29 Michael Natterer <mitch@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpchannelpropundo.[ch]: new undo class which handles
CHANNEL_REPOSITION and CHANNEL_COLOR.
* 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
......@@ -76,6 +76,8 @@ libappcore_a_sources = \
gimpchannel-combine.h \
gimpchannel-select.c \
gimpchannel-select.h \
gimpchannelpropundo.c \
gimpchannelpropundo.h \
gimpchannelundo.c \
gimpchannelundo.h \
gimpcontainer.c \
......
......@@ -114,6 +114,7 @@ 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 _GimpLayerPropUndo GimpLayerPropUndo;
typedef struct _GimpUndoStack GimpUndoStack;
......
/* 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 "gimpchannel.h"
#include "gimpchannelpropundo.h"
static GObject * gimp_channel_prop_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_channel_prop_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
G_DEFINE_TYPE (GimpChannelPropUndo, gimp_channel_prop_undo, GIMP_TYPE_ITEM_UNDO)
#define parent_class gimp_channel_prop_undo_parent_class
static void
gimp_channel_prop_undo_class_init (GimpChannelPropUndoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GimpUndoClass *undo_class = GIMP_UNDO_CLASS (klass);
object_class->constructor = gimp_channel_prop_undo_constructor;
undo_class->pop = gimp_channel_prop_undo_pop;
}
static void
gimp_channel_prop_undo_init (GimpChannelPropUndo *undo)
{
}
static GObject *
gimp_channel_prop_undo_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpChannelPropUndo *channel_prop_undo;
GimpImage *image;
GimpChannel *channel;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
channel_prop_undo = GIMP_CHANNEL_PROP_UNDO (object);
g_assert (GIMP_IS_CHANNEL (GIMP_ITEM_UNDO (object)->item));
image = GIMP_UNDO (object)->image;
channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (object)->item);
channel_prop_undo->position = gimp_image_get_channel_index (image, channel);
gimp_channel_get_color (channel, &channel_prop_undo->color);
return object;
}
static void
gimp_channel_prop_undo_pop (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpChannelPropUndo *channel_prop_undo = GIMP_CHANNEL_PROP_UNDO (undo);
GimpChannel *channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
if (undo->undo_type == GIMP_UNDO_CHANNEL_REPOSITION)
{
gint position;
position = gimp_image_get_channel_index (undo->image, channel);
gimp_image_position_channel (undo->image, channel,
channel_prop_undo->position,
FALSE, NULL);
channel_prop_undo->position = position;
}
else if (undo->undo_type == GIMP_UNDO_CHANNEL_COLOR)
{
GimpRGB color;
gimp_channel_get_color (channel, &color);
gimp_channel_set_color (channel, &channel_prop_undo->color, FALSE);
channel_prop_undo->color = color;
}
else
{
g_assert_not_reached ();
}
}
/* 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_CHANNEL_PROP_UNDO_H__
#define __GIMP_CHANNEL_PROP_UNDO_H__
#include "gimpitemundo.h"
#define GIMP_TYPE_CHANNEL_PROP_UNDO (gimp_channel_prop_undo_get_type ())
#define GIMP_CHANNEL_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CHANNEL_PROP_UNDO, GimpChannelPropUndo))
#define GIMP_CHANNEL_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CHANNEL_PROP_UNDO, GimpChannelPropUndoClass))
#define GIMP_IS_CHANNEL_PROP_UNDO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CHANNEL_PROP_UNDO))
#define GIMP_IS_CHANNEL_PROP_UNDO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CHANNEL_PROP_UNDO))
#define GIMP_CHANNEL_PROP_UNDO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CHANNEL_PROP_UNDO, GimpChannelPropUndoClass))
typedef struct _GimpChannelPropUndoClass GimpChannelPropUndoClass;
struct _GimpChannelPropUndo
{
GimpItemUndo parent_instance;
gint position;
GimpRGB color;
};
struct _GimpChannelPropUndoClass
{
GimpItemUndoClass parent_class;
};
GType gimp_channel_prop_undo_get_type (void) G_GNUC_CONST;
#endif /* __GIMP_CHANNEL_PROP_UNDO_H__ */
......@@ -29,6 +29,7 @@
#include "gimp.h"
#include "gimp-parasites.h"
#include "gimpchannelpropundo.h"
#include "gimpchannelundo.h"
#include "gimpdrawableundo.h"
#include "gimpgrid.h"
......@@ -1660,19 +1661,6 @@ undo_free_channel (GimpUndo *undo,
/* Channel re-position Undo */
/******************************/
typedef struct _ChannelRepositionUndo ChannelRepositionUndo;
struct _ChannelRepositionUndo
{
gint old_position;
};
static gboolean undo_pop_channel_reposition (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_channel_reposition (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_channel_reposition (GimpImage *image,
const gchar *undo_desc,
......@@ -1684,68 +1672,25 @@ gimp_image_undo_push_channel_reposition (GimpImage *image,
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)), FALSE);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
sizeof (ChannelRepositionUndo),
sizeof (ChannelRepositionUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_CHANNEL_PROP_UNDO,
0, 0,
GIMP_UNDO_CHANNEL_REPOSITION, undo_desc,
GIMP_DIRTY_IMAGE_STRUCTURE,
undo_pop_channel_reposition,
undo_free_channel_reposition,
NULL, NULL,
"item", channel,
NULL)))
{
ChannelRepositionUndo *cru = new->data;
cru->old_position = gimp_image_get_channel_index (image, channel);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_channel_reposition (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ChannelRepositionUndo *cru = undo->data;
GimpChannel *channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
gint pos;
pos = gimp_image_get_channel_index (undo->image, channel);
gimp_image_position_channel (undo->image, channel, cru->old_position,
FALSE, NULL);
cru->old_position = pos;
return TRUE;
}
static void
undo_free_channel_reposition (GimpUndo *undo,
GimpUndoMode undo_mode)
{
g_free (undo->data);
}
/************************/
/* Channel color Undo */
/************************/
typedef struct _ChannelColorUndo ChannelColorUndo;
struct _ChannelColorUndo
{
GimpRGB old_color;
};
static gboolean undo_pop_channel_color (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_channel_color (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_image_undo_push_channel_color (GimpImage *image,
const gchar *undo_desc,
......@@ -1757,49 +1702,20 @@ gimp_image_undo_push_channel_color (GimpImage *image,
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), FALSE);
g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)), FALSE);
if ((new = gimp_image_undo_push (image, GIMP_TYPE_ITEM_UNDO,
sizeof (ChannelColorUndo),
sizeof (ChannelColorUndo),
if ((new = gimp_image_undo_push (image, GIMP_TYPE_CHANNEL_PROP_UNDO,
0, 0,
GIMP_UNDO_CHANNEL_COLOR, undo_desc,
GIMP_DIRTY_ITEM | GIMP_DIRTY_DRAWABLE,
undo_pop_channel_color,
undo_free_channel_color,
NULL, NULL,
"item", channel,
NULL)))
{
ChannelColorUndo *ccu = new->data;
gimp_channel_get_color (channel , &ccu->old_color);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_channel_color (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
ChannelColorUndo *ccu = undo->data;
GimpChannel *channel = GIMP_CHANNEL (GIMP_ITEM_UNDO (undo)->item);
GimpRGB color;
gimp_channel_get_color (channel, &color);
gimp_channel_set_color (channel, &ccu->old_color, FALSE);
ccu->old_color = color;
return TRUE;
}
static void
undo_free_channel_color (GimpUndo *undo,
GimpUndoMode undo_mode)
{
g_free (undo->data);
}
/*****************************/
/* Add/Remove Vectors Undo */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment