~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimpbrushfactoryview.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

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
 * gimpbrushfactoryview.c
 
5
 * Copyright (C) 2001 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 <gtk/gtk.h>
 
25
 
 
26
#include "libgimpwidgets/gimpwidgets.h"
 
27
 
 
28
#include "widgets-types.h"
 
29
 
 
30
#include "core/gimpcontainer.h"
 
31
#include "core/gimpcontext.h"
 
32
#include "core/gimpbrush.h"
 
33
#include "core/gimpbrushgenerated.h"
 
34
#include "core/gimpdatafactory.h"
 
35
 
 
36
#include "gimpcontainerview.h"
 
37
#include "gimpbrushfactoryview.h"
 
38
#include "gimpviewrenderer.h"
 
39
 
 
40
#include "gimp-intl.h"
 
41
 
 
42
 
 
43
static void   gimp_brush_factory_view_class_init (GimpBrushFactoryViewClass *klass);
 
44
static void   gimp_brush_factory_view_init       (GimpBrushFactoryView      *view);
 
45
static void   gimp_brush_factory_view_destroy    (GtkObject                *object);
 
46
 
 
47
static void   gimp_brush_factory_view_select_item     (GimpContainerEditor  *editor,
 
48
                                                       GimpViewable         *viewable);
 
49
 
 
50
static void   gimp_brush_factory_view_spacing_changed (GimpBrush            *brush,
 
51
                                                       GimpBrushFactoryView *view);
 
52
static void   gimp_brush_factory_view_spacing_update  (GtkAdjustment        *adjustment,
 
53
                                                       GimpBrushFactoryView *view);
 
54
 
 
55
 
 
56
static GimpDataFactoryViewClass *parent_class = NULL;
 
57
 
 
58
 
 
59
GType
 
60
gimp_brush_factory_view_get_type (void)
 
61
{
 
62
  static GType view_type = 0;
 
63
 
 
64
  if (! view_type)
 
65
    {
 
66
      static const GTypeInfo view_info =
 
67
      {
 
68
        sizeof (GimpBrushFactoryViewClass),
 
69
        NULL,           /* base_init */
 
70
        NULL,           /* base_finalize */
 
71
        (GClassInitFunc) gimp_brush_factory_view_class_init,
 
72
        NULL,           /* class_finalize */
 
73
        NULL,           /* class_data */
 
74
        sizeof (GimpBrushFactoryView),
 
75
        0,              /* n_preallocs */
 
76
        (GInstanceInitFunc) gimp_brush_factory_view_init,
 
77
      };
 
78
 
 
79
      view_type = g_type_register_static (GIMP_TYPE_DATA_FACTORY_VIEW,
 
80
                                          "GimpBrushFactoryView",
 
81
                                          &view_info, 0);
 
82
    }
 
83
 
 
84
  return view_type;
 
85
}
 
86
 
 
87
static void
 
88
gimp_brush_factory_view_class_init (GimpBrushFactoryViewClass *klass)
 
89
{
 
90
  GtkObjectClass           *object_class;
 
91
  GimpContainerEditorClass *editor_class;
 
92
 
 
93
  object_class = GTK_OBJECT_CLASS (klass);
 
94
  editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
 
95
 
 
96
  parent_class = g_type_class_peek_parent (klass);
 
97
 
 
98
  object_class->destroy     = gimp_brush_factory_view_destroy;
 
99
 
 
100
  editor_class->select_item = gimp_brush_factory_view_select_item;
 
101
}
 
102
 
 
103
static void
 
104
gimp_brush_factory_view_init (GimpBrushFactoryView *view)
 
105
{
 
106
  GtkWidget *table;
 
107
 
 
108
  table = gtk_table_new (1, 3, FALSE);
 
109
  gtk_table_set_col_spacings (GTK_TABLE (table), 2);
 
110
  gtk_widget_show (table);
 
111
 
 
112
  view->spacing_adjustment =
 
113
    GTK_ADJUSTMENT (gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
 
114
                                          _("Spacing:"), -1, -1,
 
115
                                          0.0, 1.0, 200.0, 1.0, 10.0, 1,
 
116
                                          FALSE, 1.0, 5000.0,
 
117
                                          _("Percentage of width of brush"),
 
118
                                          NULL));
 
119
 
 
120
  view->spacing_scale = GIMP_SCALE_ENTRY_SCALE (view->spacing_adjustment);
 
121
 
 
122
  g_signal_connect (view->spacing_adjustment, "value_changed",
 
123
                    G_CALLBACK (gimp_brush_factory_view_spacing_update),
 
124
                    view);
 
125
 
 
126
  view->spacing_changed_handler_id = 0;
 
127
}
 
128
 
 
129
static void
 
130
gimp_brush_factory_view_destroy (GtkObject *object)
 
131
{
 
132
  GimpBrushFactoryView *view   = GIMP_BRUSH_FACTORY_VIEW (object);
 
133
  GimpContainerEditor  *editor = GIMP_CONTAINER_EDITOR (object);
 
134
 
 
135
  if (view->spacing_changed_handler_id)
 
136
    {
 
137
      GimpContainer *container;
 
138
 
 
139
      container = gimp_container_view_get_container (editor->view);
 
140
 
 
141
      gimp_container_remove_handler (container,
 
142
                                     view->spacing_changed_handler_id);
 
143
 
 
144
      view->spacing_changed_handler_id = 0;
 
145
    }
 
146
 
 
147
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
148
}
 
149
 
 
150
GtkWidget *
 
151
gimp_brush_factory_view_new (GimpViewType     view_type,
 
152
                             GimpDataFactory *factory,
 
153
                             GimpContext     *context,
 
154
                             gboolean         change_brush_spacing,
 
155
                             gint             view_size,
 
156
                             gint             view_border_width,
 
157
                             GimpMenuFactory *menu_factory)
 
158
{
 
159
  GimpBrushFactoryView *factory_view;
 
160
  GimpContainerEditor  *editor;
 
161
 
 
162
  g_return_val_if_fail (GIMP_IS_DATA_FACTORY (factory), NULL);
 
163
  g_return_val_if_fail (view_size > 0 &&
 
164
                        view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
 
165
  g_return_val_if_fail (view_border_width >= 0 &&
 
166
                        view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
 
167
                        NULL);
 
168
 
 
169
  factory_view = g_object_new (GIMP_TYPE_BRUSH_FACTORY_VIEW, NULL);
 
170
 
 
171
  factory_view->change_brush_spacing = change_brush_spacing;
 
172
 
 
173
  if (! gimp_data_factory_view_construct (GIMP_DATA_FACTORY_VIEW (factory_view),
 
174
                                          view_type,
 
175
                                          factory,
 
176
                                          context,
 
177
                                          view_size, view_border_width,
 
178
                                          menu_factory, "<Brushes>",
 
179
                                          "/brushes-popup",
 
180
                                          "brushes"))
 
181
    {
 
182
      g_object_unref (factory_view);
 
183
      return NULL;
 
184
    }
 
185
 
 
186
  editor = GIMP_CONTAINER_EDITOR (factory_view);
 
187
 
 
188
  /*  eek  */
 
189
  gtk_box_pack_end (GTK_BOX (editor->view),
 
190
                    factory_view->spacing_scale->parent,
 
191
                    FALSE, FALSE, 0);
 
192
 
 
193
  factory_view->spacing_changed_handler_id =
 
194
    gimp_container_add_handler (factory->container, "spacing_changed",
 
195
                                G_CALLBACK (gimp_brush_factory_view_spacing_changed),
 
196
                                factory_view);
 
197
 
 
198
  return GTK_WIDGET (factory_view);
 
199
}
 
200
 
 
201
static void
 
202
gimp_brush_factory_view_select_item (GimpContainerEditor *editor,
 
203
                                     GimpViewable        *viewable)
 
204
{
 
205
  GimpBrushFactoryView *view = GIMP_BRUSH_FACTORY_VIEW (editor);
 
206
  GimpContainer        *container;
 
207
  gboolean              spacing_sensitive = FALSE;
 
208
 
 
209
  if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
 
210
    GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
 
211
 
 
212
  container = gimp_container_view_get_container (editor->view);
 
213
 
 
214
  if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
 
215
    {
 
216
      GimpBrush *brush = GIMP_BRUSH (viewable);
 
217
 
 
218
      spacing_sensitive = TRUE;
 
219
 
 
220
      g_signal_handlers_block_by_func (view->spacing_adjustment,
 
221
                                       gimp_brush_factory_view_spacing_update,
 
222
                                       view);
 
223
 
 
224
      gtk_adjustment_set_value (view->spacing_adjustment,
 
225
                                gimp_brush_get_spacing (brush));
 
226
 
 
227
      g_signal_handlers_unblock_by_func (view->spacing_adjustment,
 
228
                                         gimp_brush_factory_view_spacing_update,
 
229
                                         view);
 
230
    }
 
231
 
 
232
  gtk_widget_set_sensitive (view->spacing_scale, spacing_sensitive);
 
233
}
 
234
 
 
235
static void
 
236
gimp_brush_factory_view_spacing_changed (GimpBrush            *brush,
 
237
                                         GimpBrushFactoryView *view)
 
238
{
 
239
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (view);
 
240
  GimpContext         *context;
 
241
 
 
242
  context = gimp_container_view_get_context (editor->view);
 
243
 
 
244
  if (brush == gimp_context_get_brush (context))
 
245
    {
 
246
      g_signal_handlers_block_by_func (view->spacing_adjustment,
 
247
                                       gimp_brush_factory_view_spacing_update,
 
248
                                       view);
 
249
 
 
250
      gtk_adjustment_set_value (view->spacing_adjustment,
 
251
                                gimp_brush_get_spacing (brush));
 
252
 
 
253
      g_signal_handlers_unblock_by_func (view->spacing_adjustment,
 
254
                                         gimp_brush_factory_view_spacing_update,
 
255
                                         view);
 
256
    }
 
257
}
 
258
 
 
259
static void
 
260
gimp_brush_factory_view_spacing_update (GtkAdjustment        *adjustment,
 
261
                                        GimpBrushFactoryView *view)
 
262
{
 
263
  GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (view);
 
264
  GimpContext         *context;
 
265
  GimpBrush           *brush;
 
266
 
 
267
  context = gimp_container_view_get_context (editor->view);
 
268
 
 
269
  brush = gimp_context_get_brush (context);
 
270
 
 
271
  if (brush && view->change_brush_spacing)
 
272
    {
 
273
      g_signal_handlers_block_by_func (brush,
 
274
                                       gimp_brush_factory_view_spacing_changed,
 
275
                                       view);
 
276
 
 
277
      gimp_brush_set_spacing (brush, adjustment->value);
 
278
 
 
279
      g_signal_handlers_unblock_by_func (brush,
 
280
                                         gimp_brush_factory_view_spacing_changed,
 
281
                                         view);
 
282
    }
 
283
}