~ubuntu-branches/ubuntu/breezy/gimp/breezy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-10-04 19:04:46 UTC
  • Revision ID: james.westby@ubuntu.com-20051004190446-ukh32kwk56s4sjhu
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

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 <glib-object.h>
 
22
 
 
23
#include "paint-types.h"
 
24
 
 
25
#include "core/gimpimage-undo.h"
 
26
#include "core/gimpimage.h"
 
27
#include "core/gimpundo.h"
 
28
 
 
29
#include "gimppaintcore.h"
 
30
 
 
31
#include "gimp-intl.h"
 
32
 
 
33
 
 
34
/****************/
 
35
/*  Paint Undo  */
 
36
/****************/
 
37
 
 
38
typedef struct _PaintUndo PaintUndo;
 
39
 
 
40
struct _PaintUndo
 
41
{
 
42
  GimpPaintCore *core;
 
43
  GimpCoords     last_coords;
 
44
};
 
45
 
 
46
static gboolean undo_pop_paint  (GimpUndo            *undo,
 
47
                                 GimpUndoMode         undo_mode,
 
48
                                 GimpUndoAccumulator *accum);
 
49
static void     undo_free_paint (GimpUndo            *undo,
 
50
                                 GimpUndoMode         undo_mode);
 
51
 
 
52
gboolean
 
53
gimp_paint_core_real_push_undo (GimpPaintCore *core,
 
54
                                GimpImage     *gimage,
 
55
                                const gchar   *undo_desc)
 
56
{
 
57
  GimpUndo *new;
 
58
 
 
59
  g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
 
60
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
 
61
 
 
62
  if ((new = gimp_image_undo_push (gimage, GIMP_TYPE_UNDO,
 
63
                                   sizeof (PaintUndo),
 
64
                                   sizeof (PaintUndo),
 
65
                                   GIMP_UNDO_PAINT, undo_desc,
 
66
                                   FALSE,
 
67
                                   undo_pop_paint,
 
68
                                   undo_free_paint,
 
69
                                   NULL)))
 
70
    {
 
71
      PaintUndo *pu = new->data;
 
72
 
 
73
      pu->core        = core;
 
74
      pu->last_coords = core->start_coords;
 
75
 
 
76
      g_object_add_weak_pointer (G_OBJECT (core), (gpointer) &pu->core);
 
77
 
 
78
      return TRUE;
 
79
    }
 
80
 
 
81
  return FALSE;
 
82
}
 
83
 
 
84
static gboolean
 
85
undo_pop_paint (GimpUndo            *undo,
 
86
                GimpUndoMode         undo_mode,
 
87
                GimpUndoAccumulator *accum)
 
88
{
 
89
  PaintUndo *pu = undo->data;
 
90
 
 
91
  /*  only pop if the core still exists  */
 
92
  if (pu->core)
 
93
    {
 
94
      GimpCoords tmp_coords;
 
95
 
 
96
      tmp_coords            = pu->core->last_coords;
 
97
      pu->core->last_coords = pu->last_coords;
 
98
      pu->last_coords       = tmp_coords;
 
99
    }
 
100
 
 
101
  return TRUE;
 
102
}
 
103
 
 
104
static void
 
105
undo_free_paint (GimpUndo     *undo,
 
106
                 GimpUndoMode  undo_mode)
 
107
{
 
108
  PaintUndo *pu = undo->data;
 
109
 
 
110
  if (pu->core)
 
111
    g_object_remove_weak_pointer (G_OBJECT (pu->core), (gpointer) &pu->core);
 
112
 
 
113
  g_free (pu);
 
114
}