~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/paint/gimpink-undo.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#include <string.h>
22
 
 
23
 
#include <glib-object.h>
24
 
 
25
 
#include "paint-types.h"
26
 
 
27
 
#include "core/gimpimage-undo.h"
28
 
#include "core/gimpimage.h"
29
 
#include "core/gimpundo.h"
30
 
 
31
 
#include "gimpink.h"
32
 
#include "gimpink-blob.h"
33
 
#include "gimpink-undo.h"
34
 
 
35
 
 
36
 
/**************/
37
 
/*  Ink Undo  */
38
 
/**************/
39
 
 
40
 
typedef struct _InkUndo InkUndo;
41
 
 
42
 
struct _InkUndo
43
 
{
44
 
  GimpInk *ink;
45
 
 
46
 
  Blob    *last_blob;
47
 
 
48
 
  gdouble  dt_buffer[DIST_SMOOTHER_BUFFER];
49
 
  gint     dt_index;
50
 
 
51
 
  guint32  ts_buffer[TIME_SMOOTHER_BUFFER];
52
 
  gint     ts_index;
53
 
 
54
 
  gdouble  last_time;
55
 
 
56
 
  gboolean init_velocity;
57
 
};
58
 
 
59
 
 
60
 
static gboolean  undo_pop_ink  (GimpUndo            *undo,
61
 
                                GimpUndoMode         undo_mode,
62
 
                                GimpUndoAccumulator *accum);
63
 
static void      undo_free_ink (GimpUndo            *undo,
64
 
                                GimpUndoMode         undo_mode);
65
 
 
66
 
 
67
 
gboolean
68
 
gimp_ink_push_undo (GimpPaintCore *core,
69
 
                    GimpImage     *gimage,
70
 
                    const gchar   *undo_desc)
71
 
{
72
 
  GimpUndo *new;
73
 
 
74
 
  g_return_val_if_fail (GIMP_IS_INK (core), FALSE);
75
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
76
 
 
77
 
  if (! GIMP_PAINT_CORE_CLASS (g_type_class_peek_parent (GIMP_INK_GET_CLASS (core)))->push_undo (core, gimage, undo_desc))
78
 
    return FALSE;
79
 
 
80
 
  if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
81
 
                                   sizeof (InkUndo),
82
 
                                   sizeof (InkUndo),
83
 
                                   GIMP_UNDO_INK, undo_desc,
84
 
                                   FALSE,
85
 
                                   undo_pop_ink,
86
 
                                   undo_free_ink,
87
 
                                   NULL)))
88
 
    {
89
 
      GimpInk *ink      = GIMP_INK (core);
90
 
      InkUndo *ink_undo = new->data;
91
 
 
92
 
      ink_undo->ink = ink;
93
 
 
94
 
      if (ink->start_blob)
95
 
        ink_undo->last_blob = blob_duplicate (ink->start_blob);
96
 
 
97
 
      memcpy (ink_undo->dt_buffer, ink->dt_buffer,
98
 
              sizeof (ink_undo->dt_buffer));
99
 
 
100
 
      ink_undo->dt_index = ink->dt_index;
101
 
 
102
 
      memcpy (ink_undo->ts_buffer, ink->ts_buffer,
103
 
              sizeof (ink_undo->ts_buffer));
104
 
 
105
 
      ink_undo->ts_index = ink->ts_index;
106
 
 
107
 
      ink_undo->last_time = ink->last_time;
108
 
 
109
 
      ink_undo->init_velocity = ink->init_velocity;
110
 
 
111
 
      g_object_add_weak_pointer (G_OBJECT (ink), (gpointer) &ink_undo->ink);
112
 
 
113
 
      return TRUE;
114
 
    }
115
 
 
116
 
  return FALSE;
117
 
}
118
 
 
119
 
static gboolean
120
 
undo_pop_ink (GimpUndo            *undo,
121
 
              GimpUndoMode         undo_mode,
122
 
              GimpUndoAccumulator *accum)
123
 
{
124
 
  InkUndo *ink_undo = undo->data;
125
 
 
126
 
  /*  only pop if the core still exists  */
127
 
  if (ink_undo->ink)
128
 
    {
129
 
      Blob    *tmp_blob;
130
 
      gint     tmp_int;
131
 
      gdouble  tmp_double;
132
 
      guint32  tmp_int_buf[DIST_SMOOTHER_BUFFER];
133
 
      gdouble  tmp_double_buf[DIST_SMOOTHER_BUFFER];
134
 
 
135
 
      tmp_blob = ink_undo->ink->last_blob;
136
 
      ink_undo->ink->last_blob = ink_undo->last_blob;
137
 
      ink_undo->last_blob = tmp_blob;
138
 
 
139
 
      memcpy (tmp_double_buf, ink_undo->ink->dt_buffer,
140
 
              sizeof (tmp_double_buf));
141
 
      memcpy (ink_undo->ink->dt_buffer, ink_undo->dt_buffer,
142
 
              sizeof (tmp_double_buf));
143
 
      memcpy (ink_undo->dt_buffer, tmp_double_buf,
144
 
              sizeof (tmp_double_buf));
145
 
 
146
 
      tmp_int = ink_undo->ink->dt_index;
147
 
      ink_undo->ink->dt_index = ink_undo->dt_index;
148
 
      ink_undo->dt_index = tmp_int;
149
 
 
150
 
      memcpy (tmp_int_buf, ink_undo->ink->ts_buffer,
151
 
              sizeof (tmp_int_buf));
152
 
      memcpy (ink_undo->ink->ts_buffer, ink_undo->ts_buffer,
153
 
              sizeof (tmp_int_buf));
154
 
      memcpy (ink_undo->ts_buffer, tmp_int_buf,
155
 
              sizeof (tmp_int_buf));
156
 
 
157
 
      tmp_int = ink_undo->ink->ts_index;
158
 
      ink_undo->ink->ts_index = ink_undo->ts_index;
159
 
      ink_undo->ts_index = tmp_int;
160
 
 
161
 
      tmp_double = ink_undo->ink->last_time;
162
 
      ink_undo->ink->last_time = ink_undo->last_time;
163
 
      ink_undo->last_time = tmp_double;
164
 
 
165
 
      tmp_int = ink_undo->ink->init_velocity;
166
 
      ink_undo->ink->init_velocity = ink_undo->init_velocity;
167
 
      ink_undo->init_velocity = tmp_int;
168
 
    }
169
 
 
170
 
  return TRUE;
171
 
}
172
 
 
173
 
static void
174
 
undo_free_ink (GimpUndo     *undo,
175
 
               GimpUndoMode  undo_mode)
176
 
{
177
 
  InkUndo *ink_undo = undo->data;
178
 
 
179
 
  if (ink_undo->ink)
180
 
    g_object_remove_weak_pointer (G_OBJECT (ink_undo->ink),
181
 
                                  (gpointer) &ink_undo->ink);
182
 
 
183
 
  if (ink_undo->last_blob)
184
 
    g_free (ink_undo->last_blob);
185
 
 
186
 
  g_free (ink_undo);
187
 
}