1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* gimpbrushfactoryview.c
5
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
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.
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.
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.
26
#include "libgimpwidgets/gimpwidgets.h"
28
#include "widgets-types.h"
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"
36
#include "gimpcontainerview.h"
37
#include "gimpbrushfactoryview.h"
38
#include "gimpviewrenderer.h"
40
#include "gimp-intl.h"
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);
47
static void gimp_brush_factory_view_select_item (GimpContainerEditor *editor,
48
GimpViewable *viewable);
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);
56
static GimpDataFactoryViewClass *parent_class = NULL;
60
gimp_brush_factory_view_get_type (void)
62
static GType view_type = 0;
66
static const GTypeInfo view_info =
68
sizeof (GimpBrushFactoryViewClass),
70
NULL, /* base_finalize */
71
(GClassInitFunc) gimp_brush_factory_view_class_init,
72
NULL, /* class_finalize */
73
NULL, /* class_data */
74
sizeof (GimpBrushFactoryView),
76
(GInstanceInitFunc) gimp_brush_factory_view_init,
79
view_type = g_type_register_static (GIMP_TYPE_DATA_FACTORY_VIEW,
80
"GimpBrushFactoryView",
88
gimp_brush_factory_view_class_init (GimpBrushFactoryViewClass *klass)
90
GtkObjectClass *object_class;
91
GimpContainerEditorClass *editor_class;
93
object_class = GTK_OBJECT_CLASS (klass);
94
editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
96
parent_class = g_type_class_peek_parent (klass);
98
object_class->destroy = gimp_brush_factory_view_destroy;
100
editor_class->select_item = gimp_brush_factory_view_select_item;
104
gimp_brush_factory_view_init (GimpBrushFactoryView *view)
108
table = gtk_table_new (1, 3, FALSE);
109
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
110
gtk_widget_show (table);
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,
117
_("Percentage of width of brush"),
120
view->spacing_scale = GIMP_SCALE_ENTRY_SCALE (view->spacing_adjustment);
122
g_signal_connect (view->spacing_adjustment, "value_changed",
123
G_CALLBACK (gimp_brush_factory_view_spacing_update),
126
view->spacing_changed_handler_id = 0;
130
gimp_brush_factory_view_destroy (GtkObject *object)
132
GimpBrushFactoryView *view = GIMP_BRUSH_FACTORY_VIEW (object);
133
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (object);
135
if (view->spacing_changed_handler_id)
137
GimpContainer *container;
139
container = gimp_container_view_get_container (editor->view);
141
gimp_container_remove_handler (container,
142
view->spacing_changed_handler_id);
144
view->spacing_changed_handler_id = 0;
147
GTK_OBJECT_CLASS (parent_class)->destroy (object);
151
gimp_brush_factory_view_new (GimpViewType view_type,
152
GimpDataFactory *factory,
153
GimpContext *context,
154
gboolean change_brush_spacing,
156
gint view_border_width,
157
GimpMenuFactory *menu_factory)
159
GimpBrushFactoryView *factory_view;
160
GimpContainerEditor *editor;
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,
169
factory_view = g_object_new (GIMP_TYPE_BRUSH_FACTORY_VIEW, NULL);
171
factory_view->change_brush_spacing = change_brush_spacing;
173
if (! gimp_data_factory_view_construct (GIMP_DATA_FACTORY_VIEW (factory_view),
177
view_size, view_border_width,
178
menu_factory, "<Brushes>",
182
g_object_unref (factory_view);
186
editor = GIMP_CONTAINER_EDITOR (factory_view);
189
gtk_box_pack_end (GTK_BOX (editor->view),
190
factory_view->spacing_scale->parent,
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),
198
return GTK_WIDGET (factory_view);
202
gimp_brush_factory_view_select_item (GimpContainerEditor *editor,
203
GimpViewable *viewable)
205
GimpBrushFactoryView *view = GIMP_BRUSH_FACTORY_VIEW (editor);
206
GimpContainer *container;
207
gboolean spacing_sensitive = FALSE;
209
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
210
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
212
container = gimp_container_view_get_container (editor->view);
214
if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
216
GimpBrush *brush = GIMP_BRUSH (viewable);
218
spacing_sensitive = TRUE;
220
g_signal_handlers_block_by_func (view->spacing_adjustment,
221
gimp_brush_factory_view_spacing_update,
224
gtk_adjustment_set_value (view->spacing_adjustment,
225
gimp_brush_get_spacing (brush));
227
g_signal_handlers_unblock_by_func (view->spacing_adjustment,
228
gimp_brush_factory_view_spacing_update,
232
gtk_widget_set_sensitive (view->spacing_scale, spacing_sensitive);
236
gimp_brush_factory_view_spacing_changed (GimpBrush *brush,
237
GimpBrushFactoryView *view)
239
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (view);
240
GimpContext *context;
242
context = gimp_container_view_get_context (editor->view);
244
if (brush == gimp_context_get_brush (context))
246
g_signal_handlers_block_by_func (view->spacing_adjustment,
247
gimp_brush_factory_view_spacing_update,
250
gtk_adjustment_set_value (view->spacing_adjustment,
251
gimp_brush_get_spacing (brush));
253
g_signal_handlers_unblock_by_func (view->spacing_adjustment,
254
gimp_brush_factory_view_spacing_update,
260
gimp_brush_factory_view_spacing_update (GtkAdjustment *adjustment,
261
GimpBrushFactoryView *view)
263
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (view);
264
GimpContext *context;
267
context = gimp_container_view_get_context (editor->view);
269
brush = gimp_context_get_brush (context);
271
if (brush && view->change_brush_spacing)
273
g_signal_handlers_block_by_func (brush,
274
gimp_brush_factory_view_spacing_changed,
277
gimp_brush_set_spacing (brush, adjustment->value);
279
g_signal_handlers_unblock_by_func (brush,
280
gimp_brush_factory_view_spacing_changed,