1 /* GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21
22 #include <libgimp/gimp.h>
23 #include <libgimp/gimpui.h>
24
25 #include "gimpressionist.h"
26 #include "infile.h"
27 #include "general.h"
28
29 #include "libgimp/stdplugins-intl.h"
30
31
32 #define COLORBUTTONWIDTH 30
33 #define COLORBUTTONHEIGHT 20
34
35
36 #define NUMGENERALBGRADIO 4
37
38 static GtkWidget *general_bg_radio[NUMGENERALBGRADIO];
39 static GtkWidget *general_paint_edges = NULL;
40 static GtkObject *general_dark_edge_adjust = NULL;
41 static GtkWidget *general_tileable;
42 static GtkWidget *general_drop_shadow = NULL;
43 static GtkWidget *general_color_button;
44 static GtkObject *general_shadow_adjust = NULL;
45 static GtkObject *general_shadow_depth = NULL;
46 static GtkObject *general_shadow_blur = NULL;
47 static GtkObject *dev_thresh_adjust = NULL;
48
49 static int
normalize_bg(int n)50 normalize_bg (int n)
51 {
52 return (!img_has_alpha && (n == 3)) ? 1 : n;
53 }
54
55 static void
general_bg_callback(GtkWidget * wg,void * d)56 general_bg_callback (GtkWidget *wg, void *d)
57 {
58 pcvals.general_background_type = normalize_bg (GPOINTER_TO_INT (d));
59 }
60
61 void
general_store(void)62 general_store (void)
63 {
64 pcvals.general_paint_edges = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_paint_edges));
65 pcvals.general_dark_edge = gtk_adjustment_get_value (GTK_ADJUSTMENT (general_dark_edge_adjust));
66 pcvals.general_tileable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_tileable));
67 pcvals.general_drop_shadow = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (general_drop_shadow));
68 pcvals.general_shadow_darkness = gtk_adjustment_get_value (GTK_ADJUSTMENT (general_shadow_adjust));
69 pcvals.general_shadow_depth = gtk_adjustment_get_value (GTK_ADJUSTMENT (general_shadow_depth));
70 pcvals.general_shadow_blur = gtk_adjustment_get_value (GTK_ADJUSTMENT (general_shadow_blur));
71 pcvals.devthresh = gtk_adjustment_get_value (GTK_ADJUSTMENT (dev_thresh_adjust));
72 }
73
74 int
general_bg_type_input(int in)75 general_bg_type_input (int in)
76 {
77 return CLAMP_UP_TO (in, NUMGENERALBGRADIO);
78 }
79
80 void
general_restore(void)81 general_restore (void)
82 {
83 gtk_toggle_button_set_active
84 (GTK_TOGGLE_BUTTON (general_bg_radio[normalize_bg (pcvals.general_background_type)]),
85 TRUE);
86
87 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_paint_edges),
88 pcvals.general_paint_edges);
89 gtk_adjustment_set_value (GTK_ADJUSTMENT (general_dark_edge_adjust),
90 pcvals.general_dark_edge);
91 gtk_adjustment_set_value (GTK_ADJUSTMENT (general_shadow_adjust),
92 pcvals.general_shadow_darkness);
93 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_drop_shadow),
94 pcvals.general_drop_shadow);
95 gtk_adjustment_set_value (GTK_ADJUSTMENT (general_shadow_depth),
96 pcvals.general_shadow_depth);
97 gtk_adjustment_set_value (GTK_ADJUSTMENT (general_shadow_blur),
98 pcvals.general_shadow_blur);
99 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (general_tileable),
100 pcvals.general_tileable);
101 gimp_color_button_set_color (GIMP_COLOR_BUTTON (general_color_button),
102 &pcvals.color);
103 gtk_adjustment_set_value (GTK_ADJUSTMENT (dev_thresh_adjust),
104 pcvals.devthresh);
105 }
106
107 static void
select_color(GtkWidget * widget,gpointer data)108 select_color (GtkWidget *widget, gpointer data)
109 {
110 gtk_toggle_button_set_active
111 (GTK_TOGGLE_BUTTON (general_bg_radio[BG_TYPE_SOLID]),
112 TRUE);
113 }
114
115 static GtkWidget *
create_general_button(GtkWidget * box,int idx,const gchar * label,const gchar * help_string,GSList ** radio_group)116 create_general_button (GtkWidget *box,
117 int idx,
118 const gchar *label,
119 const gchar *help_string,
120 GSList **radio_group)
121 {
122 return create_radio_button (box, idx, general_bg_callback, label,
123 help_string, radio_group, general_bg_radio);
124 }
125
126 void
create_generalpage(GtkNotebook * notebook)127 create_generalpage (GtkNotebook *notebook)
128 {
129 GtkWidget *box1, *box2, *box3, *box4, *thispage;
130 GtkWidget *label, *tmpw, *frame, *table;
131 GSList * radio_group = NULL;
132
133 label = gtk_label_new_with_mnemonic (_("_General"));
134
135 thispage = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
136 gtk_container_set_border_width (GTK_CONTAINER (thispage), 12);
137 gtk_widget_show (thispage);
138
139 frame = gimp_frame_new (_("Background"));
140 gtk_box_pack_start (GTK_BOX (thispage), frame, FALSE, FALSE, 0);
141 gtk_widget_show (frame);
142
143 box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
144 gtk_container_add (GTK_CONTAINER (frame), box3);
145 gtk_widget_show (box3);
146
147 create_general_button (box3,
148 BG_TYPE_KEEP_ORIGINAL,
149 _("Keep original"),
150 _("Preserve the original image as a background"),
151 &radio_group);
152
153 create_general_button (box3,
154 BG_TYPE_FROM_PAPER,
155 _("From paper"),
156 _("Copy the texture of the selected paper as a background"),
157 &radio_group);
158
159 box4 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
160 gtk_box_pack_start (GTK_BOX (box3), box4, FALSE, FALSE, 0);
161 gtk_widget_show (box4);
162
163 create_general_button (box4,
164 BG_TYPE_SOLID,
165 _("Solid"),
166 _("Solid colored background"),
167 &radio_group);
168
169 general_color_button = gimp_color_button_new (_("Color"),
170 COLORBUTTONWIDTH,
171 COLORBUTTONHEIGHT,
172 &pcvals.color,
173 GIMP_COLOR_AREA_FLAT);
174 g_signal_connect (general_color_button, "clicked",
175 G_CALLBACK (select_color), NULL);
176 g_signal_connect (general_color_button, "color-changed",
177 G_CALLBACK (gimp_color_button_get_color),
178 &pcvals.color);
179 gtk_box_pack_start (GTK_BOX (box4), general_color_button, FALSE, FALSE, 0);
180 gtk_widget_show (general_color_button);
181
182 tmpw = create_general_button (box3,
183 BG_TYPE_TRANSPARENT,
184 _("Transparent"),
185 _("Use a transparent background; Only the strokes painted will be visible"),
186 &radio_group);
187
188 if (!img_has_alpha)
189 gtk_widget_set_sensitive (tmpw, FALSE);
190
191 gtk_toggle_button_set_active
192 (GTK_TOGGLE_BUTTON (general_bg_radio[pcvals.general_background_type]), TRUE);
193
194 box1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
195 gtk_box_pack_start (GTK_BOX (thispage), box1, FALSE, FALSE, 0);
196 gtk_widget_show (box1);
197
198 box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
199 gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
200 gtk_widget_show (box2);
201
202 tmpw = gtk_check_button_new_with_label ( _("Paint edges"));
203 general_paint_edges = tmpw;
204 gtk_box_pack_start (GTK_BOX (box2), tmpw, FALSE, FALSE, 0);
205 gtk_widget_show (tmpw);
206 gimp_help_set_help_data (tmpw,
207 _("Selects if to place strokes all the way out to the edges of the image"),
208 NULL);
209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw),
210 pcvals.general_paint_edges);
211
212 general_tileable = tmpw = gtk_check_button_new_with_label ( _("Tileable"));
213 gtk_box_pack_start (GTK_BOX (box2), tmpw, FALSE, FALSE, 0);
214 gtk_widget_show (tmpw);
215 gimp_help_set_help_data (tmpw,
216 _("Selects if the resulting image should be seamlessly tileable"),
217 NULL);
218 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw),
219 pcvals.general_tileable);
220
221 tmpw = gtk_check_button_new_with_label ( _("Drop shadow"));
222 general_drop_shadow = tmpw;
223 gtk_box_pack_start (GTK_BOX (box2), tmpw, FALSE, FALSE, 0);
224 gtk_widget_show (tmpw);
225 gimp_help_set_help_data (tmpw,
226 _("Adds a shadow effect to each brush stroke"),
227 NULL);
228 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmpw),
229 pcvals.general_drop_shadow);
230
231 table = gtk_table_new (5, 3, FALSE);
232 gtk_table_set_col_spacings (GTK_TABLE (table), 6);
233 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
234 gtk_box_pack_start (GTK_BOX (box1), table, FALSE, FALSE, 0);
235 gtk_widget_show (table);
236
237 general_dark_edge_adjust =
238 gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
239 _("Edge darken:"),
240 150, 6, pcvals.general_dark_edge,
241 0.0, 1.0, 0.01, 0.1, 2,
242 TRUE, 0, 0,
243 _("How much to \"darken\" the edges of each brush stroke"),
244 NULL);
245
246 general_shadow_adjust =
247 gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
248 _("Shadow darken:"),
249 150, 6, pcvals.general_shadow_darkness,
250 0.0, 99.0, 0.1, 1, 2,
251 TRUE, 0, 0,
252 _("How much to \"darken\" the drop shadow"),
253 NULL);
254
255 general_shadow_depth =
256 gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
257 _("Shadow depth:"),
258 150, 6, pcvals.general_shadow_depth,
259 0, 99, 1, 5, 0,
260 TRUE, 0, 0,
261 _("The depth of the drop shadow, i.e. how far apart from the object it should be"),
262 NULL);
263
264 general_shadow_blur =
265 gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
266 _("Shadow blur:"),
267 150, 6, pcvals.general_shadow_blur,
268 0, 99, 1, 5, 0,
269 TRUE, 0, 0,
270 _("How much to blur the drop shadow"),
271 NULL);
272
273 dev_thresh_adjust =
274 gimp_scale_entry_new (GTK_TABLE (table), 0, 4,
275 _("Deviation threshold:"),
276 150, 6, pcvals.devthresh,
277 0.0, 1.0, 0.01, 0.01, 2,
278 TRUE, 0, 0,
279 _("A bailout-value for adaptive selections"),
280 NULL);
281
282 gtk_notebook_append_page_menu (notebook, thispage, label, NULL);
283 }
284