Commit d4177c88 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

added GIMP_UNDO_INK.

2005-01-14  Michael Natterer  <mitch@gimp.org>

	* app/core/core-enums.[ch] (enum GimpUndoType): added GIMP_UNDO_INK.

	* app/paint/gimppaintcore.[ch]: added virtual function
	GimpPaintCore::push_undo() and call it.

	* app/paint/gimppaintcore-undo.[ch]: made it the default
	implementation.

	* app/paint/gimpink-blob.[ch]: added blob_duplicate().

	* app/paint/gimpink.[ch]: added a "start_blob" (just like
	GimpPaintCore::start_coords) which gets set whenever we start a
	new stroke or line. Removed ink->lastx and ink->lasty because
	they are the same as paint_core->last_coords.

	* app/paint/Makefile.am
	* app/paint/gimpink-undo.[ch]: new files implementing an
	undo step for ink which restores the last blob used along
	with the whole ink state. Fixes bug #163670.
parent e551a9a3
2005-01-14 Michael Natterer <mitch@gimp.org>
* app/core/core-enums.[ch] (enum GimpUndoType): added GIMP_UNDO_INK.
* app/paint/gimppaintcore.[ch]: added virtual function
GimpPaintCore::push_undo() and call it.
* app/paint/gimppaintcore-undo.[ch]: made it the default
implementation.
* app/paint/gimpink-blob.[ch]: added blob_duplicate().
* app/paint/gimpink.[ch]: added a "start_blob" (just like
GimpPaintCore::start_coords) which gets set whenever we start a
new stroke or line. Removed ink->lastx and ink->lasty because
they are the same as paint_core->last_coords.
* app/paint/Makefile.am
* app/paint/gimpink-undo.[ch]: new files implementing an
undo step for ink which restores the last blob used along
with the whole ink state. Fixes bug #163670.
2005-01-14 Michael Natterer <mitch@gimp.org>
* app/actions/buffers-commands.[ch]
......
......@@ -1017,6 +1017,7 @@ gimp_undo_type_get_type (void)
{ GIMP_UNDO_FS_RELAX, "GIMP_UNDO_FS_RELAX", "fs-relax" },
{ GIMP_UNDO_TRANSFORM, "GIMP_UNDO_TRANSFORM", "transform" },
{ GIMP_UNDO_PAINT, "GIMP_UNDO_PAINT", "paint" },
{ GIMP_UNDO_INK, "GIMP_UNDO_INK", "ink" },
{ GIMP_UNDO_PARASITE_ATTACH, "GIMP_UNDO_PARASITE_ATTACH", "parasite-attach" },
{ GIMP_UNDO_PARASITE_REMOVE, "GIMP_UNDO_PARASITE_REMOVE", "parasite-remove" },
{ GIMP_UNDO_CANT, "GIMP_UNDO_CANT", "cant" },
......@@ -1097,6 +1098,7 @@ gimp_undo_type_get_type (void)
{ GIMP_UNDO_FS_RELAX, N_("FS relax"), NULL },
{ GIMP_UNDO_TRANSFORM, N_("Transform"), NULL },
{ GIMP_UNDO_PAINT, N_("Paint"), NULL },
{ GIMP_UNDO_INK, N_("Ink"), NULL },
{ GIMP_UNDO_PARASITE_ATTACH, N_("Attach parasite"), NULL },
{ GIMP_UNDO_PARASITE_REMOVE, N_("Remove parasite"), NULL },
{ GIMP_UNDO_CANT, N_("EEK: can't undo"), NULL },
......
......@@ -509,6 +509,7 @@ typedef enum /*< pdb-skip >*/
GIMP_UNDO_FS_RELAX, /*< desc="FS relax" >*/
GIMP_UNDO_TRANSFORM, /*< desc="Transform" >*/
GIMP_UNDO_PAINT, /*< desc="Paint" >*/
GIMP_UNDO_INK, /*< desc="Ink" >*/
GIMP_UNDO_PARASITE_ATTACH, /*< desc="Attach parasite" >*/
GIMP_UNDO_PARASITE_REMOVE, /*< desc="Remove parasite" >*/
......
......@@ -47,6 +47,8 @@ libapppaint_a_sources = \
gimpink.h \
gimpink-blob.c \
gimpink-blob.h \
gimpink-undo.c \
gimpink-undo.h \
gimpinkoptions.c \
gimpinkoptions.h \
gimppaintcore.c \
......
......@@ -448,6 +448,14 @@ blob_convex_union (Blob *b1,
return result;
}
Blob *
blob_duplicate (Blob *b)
{
g_return_val_if_fail (b != NULL, NULL);
return g_memdup (b, sizeof (Blob) + sizeof (BlobSpan) * (b->height - 1));
}
#if 0
void
blob_dump (Blob *b)
......
......@@ -84,6 +84,7 @@ void blob_bounds (Blob *b,
gint *height);
Blob * blob_convex_union (Blob *b1,
Blob *b2);
Blob * blob_duplicate (Blob *b);
#endif /* __GIMP_INK_BLOB_H__ */
/* 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 <string.h>
#include <glib-object.h>
#include "paint-types.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage.h"
#include "core/gimpundo.h"
#include "gimpink.h"
#include "gimpink-blob.h"
#include "gimpink-undo.h"
#include "gimp-intl.h"
/**************/
/* Ink Undo */
/**************/
typedef struct _InkUndo InkUndo;
struct _InkUndo
{
GimpInk *ink;
Blob *last_blob;
gdouble dt_buffer[DIST_SMOOTHER_BUFFER];
gint dt_index;
guint32 ts_buffer[TIME_SMOOTHER_BUFFER];
gint ts_index;
gdouble last_time;
gboolean init_velocity;
};
static gboolean undo_pop_ink (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum);
static void undo_free_ink (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_ink_push_undo (GimpPaintCore *core,
GimpImage *gimage,
const gchar *undo_desc)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_INK (core), FALSE);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
if (! GIMP_PAINT_CORE_CLASS (g_type_class_peek_parent (GIMP_INK_GET_CLASS (core)))->push_undo (core, gimage, undo_desc))
return FALSE;
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
sizeof (InkUndo),
sizeof (InkUndo),
GIMP_UNDO_INK, undo_desc,
FALSE,
undo_pop_ink,
undo_free_ink,
NULL)))
{
GimpInk *ink = GIMP_INK (core);
InkUndo *ink_undo = new->data;
ink_undo->ink = ink;
if (ink->start_blob)
ink_undo->last_blob = blob_duplicate (ink->start_blob);
memcpy (ink_undo->dt_buffer, ink->dt_buffer,
sizeof (ink_undo->dt_buffer));
ink_undo->dt_index = ink->dt_index;
memcpy (ink_undo->ts_buffer, ink->ts_buffer,
sizeof (ink_undo->ts_buffer));
ink_undo->ts_index = ink->ts_index;
ink_undo->last_time = ink->last_time;
ink_undo->init_velocity = ink->init_velocity;
g_object_add_weak_pointer (G_OBJECT (ink), (gpointer) &ink_undo->ink);
return TRUE;
}
return FALSE;
}
static gboolean
undo_pop_ink (GimpUndo *undo,
GimpUndoMode undo_mode,
GimpUndoAccumulator *accum)
{
InkUndo *ink_undo = undo->data;
/* only pop if the core still exists */
if (ink_undo->ink)
{
Blob *tmp_blob;
gint tmp_int;
gdouble tmp_double;
guint32 tmp_int_buf[DIST_SMOOTHER_BUFFER];
gdouble tmp_double_buf[DIST_SMOOTHER_BUFFER];
tmp_blob = ink_undo->ink->last_blob;
ink_undo->ink->last_blob = ink_undo->last_blob;
ink_undo->last_blob = tmp_blob;
memcpy (tmp_double_buf, ink_undo->ink->dt_buffer,
sizeof (tmp_double_buf));
memcpy (ink_undo->ink->dt_buffer, ink_undo->dt_buffer,
sizeof (tmp_double_buf));
memcpy (ink_undo->dt_buffer, tmp_double_buf,
sizeof (tmp_double_buf));
tmp_int = ink_undo->ink->dt_index;
ink_undo->ink->dt_index = ink_undo->dt_index;
ink_undo->dt_index = tmp_int;
memcpy (tmp_int_buf, ink_undo->ink->ts_buffer,
sizeof (tmp_int_buf));
memcpy (ink_undo->ink->ts_buffer, ink_undo->ts_buffer,
sizeof (tmp_int_buf));
memcpy (ink_undo->ts_buffer, tmp_int_buf,
sizeof (tmp_int_buf));
tmp_int = ink_undo->ink->ts_index;
ink_undo->ink->ts_index = ink_undo->ts_index;
ink_undo->ts_index = tmp_int;
tmp_double = ink_undo->ink->last_time;
ink_undo->ink->last_time = ink_undo->last_time;
ink_undo->last_time = tmp_double;
tmp_int = ink_undo->ink->init_velocity;
ink_undo->ink->init_velocity = ink_undo->init_velocity;
ink_undo->init_velocity = tmp_int;
}
return TRUE;
}
static void
undo_free_ink (GimpUndo *undo,
GimpUndoMode undo_mode)
{
InkUndo *ink_undo = undo->data;
if (ink_undo->ink)
g_object_remove_weak_pointer (G_OBJECT (ink_undo->ink),
(gpointer) &ink_undo->ink);
if (ink_undo->last_blob)
g_free (ink_undo->last_blob);
g_free (ink_undo);
}
/* 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.
*/
#ifndef __GIMP_INK_UNDO_H__
#define __GIMP_INK_UNDO_H__
gboolean gimp_ink_push_undo (GimpPaintCore *core,
GimpImage *gimage,
const gchar *undo_desc);
#endif /* __GIMP_INK_UNDO_H__ */
......@@ -37,6 +37,7 @@
#include "gimpinkoptions.h"
#include "gimpink.h"
#include "gimpink-blob.h"
#include "gimpink-undo.h"
#include "gimp-intl.h"
......@@ -141,6 +142,7 @@ gimp_ink_class_init (GimpInkClass *klass)
paint_core_class->paint = gimp_ink_paint;
paint_core_class->get_paint_area = gimp_ink_get_paint_area;
paint_core_class->push_undo = gimp_ink_push_undo;
}
static void
......@@ -153,6 +155,12 @@ gimp_ink_finalize (GObject *object)
{
GimpInk *ink = GIMP_INK (object);
if (ink->start_blob)
{
g_free (ink->start_blob);
ink->start_blob = NULL;
}
if (ink->last_blob)
{
g_free (ink->last_blob);
......@@ -174,13 +182,31 @@ gimp_ink_paint (GimpPaintCore *paint_core,
switch (paint_state)
{
case GIMP_PAINT_STATE_INIT:
if (ink->last_blob &&
paint_core->cur_coords.x == paint_core->last_coords.x &&
if (paint_core->cur_coords.x == paint_core->last_coords.x &&
paint_core->cur_coords.y == paint_core->last_coords.y)
{
/* start with a new blob if we're not interpolating */
g_free (ink->last_blob);
ink->last_blob = NULL;
/* start with new blobs if we're not interpolating */
if (ink->start_blob)
{
g_free (ink->start_blob);
ink->start_blob = NULL;
}
if (ink->last_blob)
{
g_free (ink->last_blob);
ink->last_blob = NULL;
}
}
else if (ink->last_blob)
{
/* save the start blob of the line for undo otherwise */
if (ink->start_blob)
g_free (ink->start_blob);
ink->start_blob = blob_duplicate (ink->last_blob);
}
break;
......@@ -207,7 +233,7 @@ gimp_ink_get_paint_area (GimpPaintCore *paint_core,
bytes = gimp_drawable_bytes_with_alpha (drawable);
blob_bounds (ink->blob, &x, &y, &width, &height);
blob_bounds (ink->cur_blob, &x, &y, &width, &height);
dwidth = gimp_item_width (GIMP_ITEM (drawable));
dheight = gimp_item_height (GIMP_ITEM (drawable));
......@@ -256,15 +282,17 @@ gimp_ink_motion (GimpPaintCore *paint_core,
paint_core->cur_coords.ytilt,
10.0);
if (ink->start_blob)
g_free (ink->start_blob);
ink->start_blob = blob_duplicate (ink->last_blob);
time_smoother_init (ink, time);
ink->last_time = time;
dist_smoother_init (ink, 0.0);
ink->init_velocity = TRUE;
ink->lastx = paint_core->cur_coords.x;
ink->lasty = paint_core->cur_coords.y;
blob_to_render = ink->last_blob;
}
else
......@@ -288,10 +316,10 @@ gimp_ink_motion (GimpPaintCore *paint_core,
if (thistime == lasttime)
thistime = lasttime + 1;
dist = sqrt ((ink->lastx - paint_core->cur_coords.x) *
(ink->lastx - paint_core->cur_coords.x) +
(ink->lasty - paint_core->cur_coords.y) *
(ink->lasty - paint_core->cur_coords.y));
dist = sqrt ((paint_core->last_coords.x - paint_core->cur_coords.x) *
(paint_core->last_coords.x - paint_core->cur_coords.x) +
(paint_core->last_coords.y - paint_core->cur_coords.y) *
(paint_core->last_coords.y - paint_core->cur_coords.y));
if (ink->init_velocity)
{
......@@ -304,9 +332,6 @@ gimp_ink_motion (GimpPaintCore *paint_core,
dist = dist_smoother_result (ink);
}
ink->lastx = paint_core->cur_coords.x;
ink->lasty = paint_core->cur_coords.y;
velocity = 10.0 * sqrt ((dist) / (gdouble) (thistime - lasttime));
blob = ink_pen_ellipse (options,
......@@ -325,9 +350,10 @@ gimp_ink_motion (GimpPaintCore *paint_core,
}
/* Get the the buffer */
ink->blob = blob_to_render;
ink->cur_blob = blob_to_render;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
ink->cur_blob = NULL;
if (! area)
return;
......
......@@ -43,7 +43,9 @@ struct _GimpInk
{
GimpPaintCore parent_instance;
Blob *blob; /* current blob */
Blob *start_blob; /* starting blob (for undo) */
Blob *cur_blob; /* current blob */
Blob *last_blob; /* blob for last cursor position */
/* circular distance history buffer */
......@@ -54,8 +56,7 @@ struct _GimpInk
guint32 ts_buffer[TIME_SMOOTHER_BUFFER];
gint ts_index;
guint32 last_time; /* previous time of a motion event */
gdouble lastx, lasty; /* previous position of a motion event */
guint32 last_time; /* previous time of a motion event */
gboolean init_velocity;
};
......
......@@ -50,14 +50,14 @@ static void undo_free_paint (GimpUndo *undo,
GimpUndoMode undo_mode);
gboolean
gimp_paint_core_push_undo (GimpImage *gimage,
const gchar *undo_desc,
GimpPaintCore *core)
gimp_paint_core_real_push_undo (GimpPaintCore *core,
GimpImage *gimage,
const gchar *undo_desc)
{
GimpUndo *new;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
sizeof (PaintUndo),
......
......@@ -20,9 +20,9 @@
#define __GIMP_PAINT_CORE_UNDO_H__
gboolean gimp_paint_core_push_undo (GimpImage *gimage,
const gchar *undo_desc,
GimpPaintCore *core);
gboolean gimp_paint_core_real_push_undo (GimpPaintCore *core,
GimpImage *gimage,
const gchar *undo_desc);
#endif /* __GIMP_PAINT_CORE_UNDO_H__ */
......@@ -138,6 +138,7 @@ gimp_paint_core_class_init (GimpPaintCoreClass *klass)
klass->post_paint = gimp_paint_core_real_post_paint;
klass->interpolate = gimp_paint_core_real_interpolate;
klass->get_paint_area = gimp_paint_core_real_get_paint_area;
klass->push_undo = gimp_paint_core_real_push_undo;
}
static void
......@@ -343,7 +344,7 @@ gimp_paint_core_finish (GimpPaintCore *core,
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_PAINT,
paint_info ? paint_info->blurb : _("Paint"));
gimp_paint_core_push_undo (gimage, NULL, core);
GIMP_PAINT_CORE_GET_CLASS (core)->push_undo (core, gimage, NULL);
gimp_drawable_push_undo (drawable, NULL,
core->x1, core->y1,
......
......@@ -96,6 +96,10 @@ struct _GimpPaintCoreClass
TempBuf * (* get_paint_area) (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options);
gboolean (* push_undo) (GimpPaintCore *core,
GimpImage *gimage,
const gchar *undo_desc);
};
......
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