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

« back to all changes in this revision

Viewing changes to app/core/gimppatternclipboard.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
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimppatternclipboard.c
 
5
 * Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
 
 
26
#include "core-types.h"
 
27
 
 
28
#include "base/temp-buf.h"
 
29
#include "base/pixel-region.h"
 
30
 
 
31
#include "paint-funcs/paint-funcs.h"
 
32
 
 
33
#include "gimp.h"
 
34
#include "gimpbuffer.h"
 
35
#include "gimppatternclipboard.h"
 
36
#include "gimpimage.h"
 
37
#include "gimppickable.h"
 
38
 
 
39
#include "gimp-intl.h"
 
40
 
 
41
 
 
42
enum
 
43
{
 
44
  PROP_0,
 
45
  PROP_GIMP
 
46
};
 
47
 
 
48
 
 
49
/*  local function prototypes  */
 
50
 
 
51
static GObject  * gimp_pattern_clipboard_constructor  (GType         type,
 
52
                                                       guint         n_params,
 
53
                                                       GObjectConstructParam *params);
 
54
static void       gimp_pattern_clipboard_set_property (GObject      *object,
 
55
                                                       guint         property_id,
 
56
                                                       const GValue *value,
 
57
                                                       GParamSpec   *pspec);
 
58
static void       gimp_pattern_clipboard_get_property (GObject      *object,
 
59
                                                       guint         property_id,
 
60
                                                       GValue       *value,
 
61
                                                       GParamSpec   *pspec);
 
62
#if 0
 
63
static GimpData * gimp_pattern_clipboard_duplicate    (GimpData     *data);
 
64
#endif
 
65
 
 
66
static void     gimp_pattern_clipboard_buffer_changed (Gimp         *gimp,
 
67
                                                       GimpPattern  *pattern);
 
68
 
 
69
 
 
70
G_DEFINE_TYPE (GimpPatternClipboard, gimp_pattern_clipboard, GIMP_TYPE_PATTERN)
 
71
 
 
72
#define parent_class gimp_pattern_clipboard_parent_class
 
73
 
 
74
 
 
75
static void
 
76
gimp_pattern_clipboard_class_init (GimpPatternClipboardClass *klass)
 
77
{
 
78
  GObjectClass  *object_class = G_OBJECT_CLASS (klass);
 
79
#if 0
 
80
  GimpDataClass *data_class   = GIMP_DATA_CLASS (klass);
 
81
#endif
 
82
 
 
83
  object_class->constructor  = gimp_pattern_clipboard_constructor;
 
84
  object_class->set_property = gimp_pattern_clipboard_set_property;
 
85
  object_class->get_property = gimp_pattern_clipboard_get_property;
 
86
 
 
87
#if 0
 
88
  data_class->duplicate      = gimp_pattern_clipboard_duplicate;
 
89
#endif
 
90
 
 
91
  g_object_class_install_property (object_class, PROP_GIMP,
 
92
                                   g_param_spec_object ("gimp", NULL, NULL,
 
93
                                                        GIMP_TYPE_GIMP,
 
94
                                                        GIMP_PARAM_READWRITE |
 
95
                                                        G_PARAM_CONSTRUCT_ONLY));
 
96
}
 
97
 
 
98
static void
 
99
gimp_pattern_clipboard_init (GimpPatternClipboard *pattern)
 
100
{
 
101
  pattern->gimp = NULL;
 
102
}
 
103
 
 
104
static GObject *
 
105
gimp_pattern_clipboard_constructor (GType                  type,
 
106
                                    guint                  n_params,
 
107
                                    GObjectConstructParam *params)
 
108
{
 
109
  GObject              *object;
 
110
  GimpPatternClipboard *pattern;
 
111
 
 
112
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
113
 
 
114
  pattern = GIMP_PATTERN_CLIPBOARD (object);
 
115
 
 
116
  g_assert (GIMP_IS_GIMP (pattern->gimp));
 
117
 
 
118
  g_signal_connect_object (pattern->gimp, "buffer-changed",
 
119
                           G_CALLBACK (gimp_pattern_clipboard_buffer_changed),
 
120
                           pattern, 0);
 
121
 
 
122
  gimp_pattern_clipboard_buffer_changed (pattern->gimp, GIMP_PATTERN (pattern));
 
123
 
 
124
  return object;
 
125
}
 
126
 
 
127
static void
 
128
gimp_pattern_clipboard_set_property (GObject      *object,
 
129
                                     guint         property_id,
 
130
                                     const GValue *value,
 
131
                                     GParamSpec   *pspec)
 
132
{
 
133
  GimpPatternClipboard *pattern = GIMP_PATTERN_CLIPBOARD (object);
 
134
 
 
135
  switch (property_id)
 
136
    {
 
137
    case PROP_GIMP:
 
138
      pattern->gimp = g_value_get_object (value);
 
139
      break;
 
140
    default:
 
141
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
142
      break;
 
143
    }
 
144
}
 
145
 
 
146
static void
 
147
gimp_pattern_clipboard_get_property (GObject    *object,
 
148
                                     guint       property_id,
 
149
                                     GValue     *value,
 
150
                                     GParamSpec *pspec)
 
151
{
 
152
  GimpPatternClipboard *pattern = GIMP_PATTERN_CLIPBOARD (object);
 
153
 
 
154
  switch (property_id)
 
155
    {
 
156
    case PROP_GIMP:
 
157
      g_value_set_object (value, pattern->gimp);
 
158
      break;
 
159
    default:
 
160
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
161
      break;
 
162
    }
 
163
}
 
164
 
 
165
#if 0
 
166
static GimpData *
 
167
gimp_pattern_clipboard_duplicate (GimpData *data)
 
168
{
 
169
  GimpPatternClipboard *pattern = GIMP_PATTERN_CLIPBOARD (data);
 
170
 
 
171
  return gimp_pattern_clipboard_new (pattern->gimp);
 
172
}
 
173
#endif
 
174
 
 
175
GimpData *
 
176
gimp_pattern_clipboard_new (Gimp *gimp)
 
177
{
 
178
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
179
 
 
180
  return g_object_new (GIMP_TYPE_PATTERN_CLIPBOARD,
 
181
                       "name", _("Clipboard"),
 
182
                       "gimp", gimp,
 
183
                       NULL);
 
184
}
 
185
 
 
186
 
 
187
/*  private functions  */
 
188
 
 
189
static void
 
190
gimp_pattern_clipboard_buffer_changed (Gimp        *gimp,
 
191
                                       GimpPattern *pattern)
 
192
{
 
193
  if (pattern->mask)
 
194
    {
 
195
      temp_buf_free (pattern->mask);
 
196
      pattern->mask = NULL;
 
197
    }
 
198
 
 
199
  if (gimp->global_buffer)
 
200
    {
 
201
      gint         width;
 
202
      gint         height;
 
203
      gint         bytes;
 
204
      PixelRegion  bufferPR;
 
205
      PixelRegion  maskPR;
 
206
 
 
207
      width  = MIN (gimp_buffer_get_width  (gimp->global_buffer), 512);
 
208
      height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512);
 
209
      bytes  = gimp_buffer_get_bytes (gimp->global_buffer);
 
210
 
 
211
      pattern->mask = temp_buf_new (width, height, bytes, 0, 0, NULL);
 
212
 
 
213
      pixel_region_init (&bufferPR, gimp->global_buffer->tiles,
 
214
                         0, 0, width, height, FALSE);
 
215
      pixel_region_init_temp_buf (&maskPR, pattern->mask,
 
216
                                  0, 0, width, height);
 
217
 
 
218
      copy_region (&bufferPR, &maskPR);
 
219
    }
 
220
  else
 
221
    {
 
222
      guchar color[3] = { 255, 255, 255 };
 
223
 
 
224
      pattern->mask = temp_buf_new (16, 16, 3, 0, 0, color);
 
225
    }
 
226
 
 
227
  gimp_data_dirty (GIMP_DATA (pattern));
 
228
}