1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
3  *
4  * gimpfilleditor.c
5  * Copyright (C) 2008 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 3 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, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include "config.h"
22 
23 #include <gegl.h>
24 #include <gtk/gtk.h>
25 
26 #include "libgimpbase/gimpbase.h"
27 #include "libgimpwidgets/gimpwidgets.h"
28 
29 #include "widgets-types.h"
30 
31 #include "core/gimpfilloptions.h"
32 
33 #include "gimpcolorpanel.h"
34 #include "gimpfilleditor.h"
35 #include "gimppropwidgets.h"
36 #include "gimpviewablebox.h"
37 #include "gimpwidgets-utils.h"
38 
39 #include "gimp-intl.h"
40 
41 
42 enum
43 {
44   PROP_0,
45   PROP_OPTIONS,
46   PROP_EDIT_CONTEXT
47 };
48 
49 
50 static void   gimp_fill_editor_constructed  (GObject      *object);
51 static void   gimp_fill_editor_finalize     (GObject      *object);
52 static void   gimp_fill_editor_set_property (GObject      *object,
53                                              guint         property_id,
54                                              const GValue *value,
55                                              GParamSpec   *pspec);
56 static void   gimp_fill_editor_get_property (GObject      *object,
57                                              guint         property_id,
58                                              GValue       *value,
59                                              GParamSpec   *pspec);
60 
61 
G_DEFINE_TYPE(GimpFillEditor,gimp_fill_editor,GTK_TYPE_BOX)62 G_DEFINE_TYPE (GimpFillEditor, gimp_fill_editor, GTK_TYPE_BOX)
63 
64 #define parent_class gimp_fill_editor_parent_class
65 
66 
67 static void
68 gimp_fill_editor_class_init (GimpFillEditorClass *klass)
69 {
70   GObjectClass *object_class = G_OBJECT_CLASS (klass);
71 
72   object_class->constructed  = gimp_fill_editor_constructed;
73   object_class->finalize     = gimp_fill_editor_finalize;
74   object_class->set_property = gimp_fill_editor_set_property;
75   object_class->get_property = gimp_fill_editor_get_property;
76 
77   g_object_class_install_property (object_class, PROP_OPTIONS,
78                                    g_param_spec_object ("options",
79                                                         NULL, NULL,
80                                                         GIMP_TYPE_FILL_OPTIONS,
81                                                         GIMP_PARAM_READWRITE |
82                                                         G_PARAM_CONSTRUCT_ONLY));
83 
84   g_object_class_install_property (object_class, PROP_EDIT_CONTEXT,
85                                    g_param_spec_boolean ("edit-context",
86                                                          NULL, NULL,
87                                                          FALSE,
88                                                          GIMP_PARAM_READWRITE |
89                                                          G_PARAM_CONSTRUCT_ONLY));
90 }
91 
92 static void
gimp_fill_editor_init(GimpFillEditor * editor)93 gimp_fill_editor_init (GimpFillEditor *editor)
94 {
95   gtk_orientable_set_orientation (GTK_ORIENTABLE (editor),
96                                   GTK_ORIENTATION_VERTICAL);
97 
98   gtk_box_set_spacing (GTK_BOX (editor), 6);
99 }
100 
101 static void
gimp_fill_editor_constructed(GObject * object)102 gimp_fill_editor_constructed (GObject *object)
103 {
104   GimpFillEditor *editor = GIMP_FILL_EDITOR (object);
105   GtkWidget      *box;
106   GtkWidget      *button;
107 
108   G_OBJECT_CLASS (parent_class)->constructed (object);
109 
110   gimp_assert (GIMP_IS_FILL_OPTIONS (editor->options));
111 
112   box = gimp_prop_enum_radio_box_new (G_OBJECT (editor->options), "style",
113                                       0, 0);
114   gtk_box_pack_start (GTK_BOX (editor), box, FALSE, FALSE, 0);
115   gtk_widget_show (box);
116 
117   if (editor->edit_context)
118     {
119       GtkWidget *color_button;
120       GtkWidget *pattern_box;
121 
122       color_button = gimp_prop_color_button_new (G_OBJECT (editor->options),
123                                                  "foreground",
124                                                  _("Fill Color"),
125                                                  -1, 24,
126                                                  GIMP_COLOR_AREA_SMALL_CHECKS);
127       gimp_color_panel_set_context (GIMP_COLOR_PANEL (color_button),
128                                     GIMP_CONTEXT (editor->options));
129       gimp_enum_radio_box_add (GTK_BOX (box), color_button,
130                                GIMP_FILL_STYLE_SOLID, FALSE);
131 
132       pattern_box = gimp_prop_pattern_box_new (NULL,
133                                                GIMP_CONTEXT (editor->options),
134                                                NULL, 2,
135                                                "pattern-view-type",
136                                                "pattern-view-size");
137       gimp_enum_radio_box_add (GTK_BOX (box), pattern_box,
138                                GIMP_FILL_STYLE_PATTERN, FALSE);
139     }
140 
141   button = gimp_prop_check_button_new (G_OBJECT (editor->options),
142                                        "antialias",
143                                        _("_Antialiasing"));
144   gtk_box_pack_start (GTK_BOX (editor), button, FALSE, FALSE, 0);
145   gtk_widget_show (button);
146 }
147 
148 static void
gimp_fill_editor_finalize(GObject * object)149 gimp_fill_editor_finalize (GObject *object)
150 {
151   GimpFillEditor *editor = GIMP_FILL_EDITOR (object);
152 
153   g_clear_object (&editor->options);
154 
155   G_OBJECT_CLASS (parent_class)->finalize (object);
156 }
157 
158 static void
gimp_fill_editor_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)159 gimp_fill_editor_set_property (GObject      *object,
160                                guint         property_id,
161                                const GValue *value,
162                                GParamSpec   *pspec)
163 {
164   GimpFillEditor *editor = GIMP_FILL_EDITOR (object);
165 
166   switch (property_id)
167     {
168     case PROP_OPTIONS:
169       if (editor->options)
170         g_object_unref (editor->options);
171       editor->options = g_value_dup_object (value);
172       break;
173 
174     case PROP_EDIT_CONTEXT:
175       editor->edit_context = g_value_get_boolean (value);
176       break;
177 
178     default:
179       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
180       break;
181     }
182 }
183 
184 static void
gimp_fill_editor_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)185 gimp_fill_editor_get_property (GObject    *object,
186                                guint       property_id,
187                                GValue     *value,
188                                GParamSpec *pspec)
189 {
190   GimpFillEditor *editor = GIMP_FILL_EDITOR (object);
191 
192   switch (property_id)
193     {
194     case PROP_OPTIONS:
195       g_value_set_object (value, editor->options);
196       break;
197 
198     case PROP_EDIT_CONTEXT:
199       g_value_set_boolean (value, editor->edit_context);
200       break;
201 
202     default:
203       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
204       break;
205     }
206 }
207 
208 GtkWidget *
gimp_fill_editor_new(GimpFillOptions * options,gboolean edit_context)209 gimp_fill_editor_new (GimpFillOptions *options,
210                       gboolean         edit_context)
211 {
212   g_return_val_if_fail (GIMP_IS_FILL_OPTIONS (options), NULL);
213 
214   return g_object_new (GIMP_TYPE_FILL_EDITOR,
215                        "options",      options,
216                        "edit-context", edit_context ? TRUE : FALSE,
217                        NULL);
218 }
219