1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* The GIMP -- an 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 <gtk/gtk.h>
#include "tools-types.h"
#include "base/tile-manager.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage.h"
#include "core/gimpundo.h"
#include "gimptoolcontrol.h"
#include "gimptransformtool.h"
#include "gimptransformtool-undo.h"
#include "tool_manager.h"
#include "gimp-intl.h"
/********************/
/* Transform Undo */
/********************/
typedef struct _TransformUndo TransformUndo;
struct _TransformUndo
{
gint tool_ID;
GType tool_type;
TransInfo trans_info;
TileManager *original;
};
static gboolean undo_pop_transform (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_transform (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_transform_tool_push_undo (GimpImage *gimage,
const gchar *undo_desc,
gint tool_ID,
GType tool_type,
gdouble *trans_info,
TileManager *original)
{
GimpUndo *new;
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
sizeof (TransformUndo),
sizeof (TransformUndo),
GIMP_UNDO_TRANSFORM, undo_desc,
FALSE,
undo_pop_transform,
undo_free_transform,
NULL)))
{
TransformUndo *tu = new->data;
gint i;
tu->tool_ID = tool_ID;
tu->tool_type = tool_type;
for (i = 0; i < TRAN_INFO_SIZE; i++)
tu->trans_info[i] = trans_info[i];
if (original)
tu->original = tile_manager_ref (original);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_transform (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
GimpTool *active_tool;
active_tool = tool_manager_get_active (undo->gimage->gimp);
if (GIMP_IS_TRANSFORM_TOOL (active_tool))
{
GimpTransformTool *tt = GIMP_TRANSFORM_TOOL (active_tool);
TransformUndo *tu = undo->data;
/* only pop if the active tool is the tool that pushed this undo */
if (tu->tool_ID == active_tool->ID)
{
TileManager *temp;
gdouble d;
gint i;
/* swap the transformation information arrays */
for (i = 0; i < TRAN_INFO_SIZE; i++)
{
d = tu->trans_info[i];
tu->trans_info[i] = tt->trans_info[i];
tt->trans_info[i] = d;
}
/* swap the original buffer--the source buffer for repeated transforms
*/
temp = tu->original;
tu->original = tt->original;
tt->original = temp;
/* If we're re-implementing the first transform, reactivate tool */
if (undo_mode == GIMP_UNDO_MODE_REDO && tt->original)
{
gimp_tool_control_activate (active_tool->control);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tt));
}
}
}
return TRUE;
}
static void
undo_free_transform (GimpUndo *undo,
GimpUndoMode undo_mode)
{
TransformUndo * tu = undo->data;
if (tu->original)
tile_manager_unref (tu->original);
g_free (tu);
}
|