1 /*
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * This is a plug-in for GIMP.
5 *
6 * Generates images containing vector type drawings.
7 *
8 * Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 *
23 */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include <libgimp/gimp.h>
31 #include <libgimp/gimpui.h>
32
33 #include "libgimp/stdplugins-intl.h"
34
35 #include "gfig.h"
36 #include "gfig-dobject.h"
37 #include "gfig-style.h"
38
39
40 static void gfig_read_parameter_string (gchar **text,
41 gint nitems,
42 const gchar *name,
43 gchar **style_entry);
44
45 static void gfig_read_parameter_int (gchar **text,
46 gint nitems,
47 const gchar *name,
48 gint *style_entry);
49
50 static void gfig_read_parameter_double (gchar **text,
51 gint nitems,
52 const gchar *name,
53 gdouble *style_entry);
54
55 static void gfig_read_parameter_gimp_rgb (gchar **text,
56 gint nitems,
57 const gchar *name,
58 GimpRGB *style_entry);
59
60 static void
gfig_read_parameter_string(gchar ** text,gint nitems,const gchar * name,gchar ** style_entry)61 gfig_read_parameter_string (gchar **text,
62 gint nitems,
63 const gchar *name,
64 gchar **style_entry)
65 {
66 gint n = 0;
67 gchar *ptr;
68 gchar *tmpstr;
69
70 *style_entry = NULL;
71
72 while (n < nitems)
73 {
74 ptr = strchr (text[n], ':');
75 if (ptr)
76 {
77 tmpstr = g_strndup (text[n], ptr - text[n]);
78 ptr++;
79 if (!strcmp (tmpstr, name))
80 {
81 *style_entry = g_strdup (g_strchug (ptr));
82 g_free (tmpstr);
83 return;
84 }
85 g_free (tmpstr);
86 }
87 ++n;
88 }
89
90 g_message ("Parameter '%s' not found", name);
91 }
92
93
94 static void
gfig_read_parameter_int(gchar ** text,gint nitems,const gchar * name,gint * style_entry)95 gfig_read_parameter_int (gchar **text,
96 gint nitems,
97 const gchar *name,
98 gint *style_entry)
99 {
100 gint n = 0;
101 gchar *ptr;
102 gchar *tmpstr;
103
104 *style_entry = 0;
105
106 while (n < nitems)
107 {
108 ptr = strchr (text[n], ':');
109 if (ptr)
110 {
111 tmpstr = g_strndup (text[n], ptr - text[n]);
112 ptr++;
113 if (!strcmp (tmpstr, name))
114 {
115 *style_entry = atoi (g_strchug (ptr));
116 g_free (tmpstr);
117 return;
118 }
119 g_free (tmpstr);
120 }
121 ++n;
122 }
123 }
124
125 static void
gfig_read_parameter_double(gchar ** text,gint nitems,const gchar * name,gdouble * style_entry)126 gfig_read_parameter_double (gchar **text,
127 gint nitems,
128 const gchar *name,
129 gdouble *style_entry)
130 {
131 gint n = 0;
132 gchar *ptr;
133 gchar *endptr;
134 gchar *tmpstr;
135
136 *style_entry = 0.;
137
138 while (n < nitems)
139 {
140 ptr = strchr (text[n], ':');
141 if (ptr)
142 {
143 tmpstr = g_strndup (text[n], ptr - text[n]);
144 ptr++;
145 if (!strcmp (tmpstr, name))
146 {
147 *style_entry = g_ascii_strtod (g_strchug (ptr), &endptr);
148 g_free (tmpstr);
149 return;
150 }
151 g_free (tmpstr);
152 }
153 ++n;
154 }
155 }
156
157 static void
gfig_read_parameter_gimp_rgb(gchar ** text,gint nitems,const gchar * name,GimpRGB * style_entry)158 gfig_read_parameter_gimp_rgb (gchar **text,
159 gint nitems,
160 const gchar *name,
161 GimpRGB *style_entry)
162 {
163 gint n = 0;
164 gchar *ptr;
165 gchar *tmpstr;
166 gchar *endptr;
167 gchar fmt_str[32];
168 gchar colorstr_r[G_ASCII_DTOSTR_BUF_SIZE];
169 gchar colorstr_g[G_ASCII_DTOSTR_BUF_SIZE];
170 gchar colorstr_b[G_ASCII_DTOSTR_BUF_SIZE];
171 gchar colorstr_a[G_ASCII_DTOSTR_BUF_SIZE];
172
173 style_entry->r = style_entry->g = style_entry->b = style_entry->a = 0.;
174
175 snprintf (fmt_str, sizeof (fmt_str),
176 "%%%" G_GSIZE_FORMAT "s"
177 " %%%" G_GSIZE_FORMAT "s"
178 " %%%" G_GSIZE_FORMAT "s"
179 " %%%" G_GSIZE_FORMAT "s",
180 sizeof (colorstr_r) - 1, sizeof (colorstr_g) - 1,
181 sizeof (colorstr_b) - 1, sizeof (colorstr_a) - 1);
182
183 while (n < nitems)
184 {
185 ptr = strchr (text[n], ':');
186 if (ptr)
187 {
188 tmpstr = g_strndup (text[n], ptr - text[n]);
189 ptr++;
190 if (!strcmp (tmpstr, name))
191 {
192 sscanf (ptr, fmt_str,
193 colorstr_r, colorstr_g, colorstr_b, colorstr_a);
194 style_entry->r = g_ascii_strtod (colorstr_r, &endptr);
195 style_entry->g = g_ascii_strtod (colorstr_g, &endptr);
196 style_entry->b = g_ascii_strtod (colorstr_b, &endptr);
197 style_entry->a = g_ascii_strtod (colorstr_a, &endptr);
198 g_free (tmpstr);
199 return;
200 }
201 g_free (tmpstr);
202 }
203 ++n;
204 }
205 }
206
207 #define MAX_STYLE_TEXT_ENTRIES 100
208
209 gboolean
gfig_load_style(Style * style,FILE * fp)210 gfig_load_style (Style *style,
211 FILE *fp)
212 {
213 gulong offset;
214 gchar load_buf2[MAX_LOAD_LINE];
215 gchar *style_text[MAX_STYLE_TEXT_ENTRIES];
216 gint nitems = 0;
217 gint value;
218 gint k;
219 gchar name[100];
220
221 offset = ftell (fp);
222
223 get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
224 /* nuke final > and preserve spaces in name */
225 if (1 != sscanf (load_buf2, "<Style %99[^>]>", name))
226 {
227 /* no style data, copy default style and fail silently */
228 gfig_style_copy (style, &gfig_context->default_style, "default style");
229 fseek (fp, offset, SEEK_SET);
230 return TRUE;
231 }
232
233 if (gfig_context->debug_styles)
234 g_printerr ("Loading style '%s' -- ", name);
235
236 style->name = g_strdup (name);
237
238 while (TRUE)
239 {
240 get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
241 if (!strcmp (load_buf2, "</Style>") || feof (fp))
242 break;
243
244 style_text[nitems] = g_strdup (load_buf2);
245 nitems++;
246
247 if (nitems >= MAX_STYLE_TEXT_ENTRIES)
248 break;
249 }
250
251 if (feof (fp) || (nitems >= MAX_STYLE_TEXT_ENTRIES))
252 {
253 g_message ("Error reading style data");
254 return TRUE;
255 }
256
257 gfig_read_parameter_string (style_text, nitems, "BrushName",
258 &style->brush_name);
259
260 if (style->brush_name == NULL)
261 g_message ("Error loading style: got NULL for brush name.");
262
263 gfig_read_parameter_string (style_text, nitems, "Pattern", &style->pattern);
264 gfig_read_parameter_string (style_text, nitems, "Gradient", &style->gradient);
265
266 gfig_read_parameter_gimp_rgb (style_text, nitems, "Foreground",
267 &style->foreground);
268 gfig_read_parameter_gimp_rgb (style_text, nitems, "Background",
269 &style->background);
270
271 gfig_read_parameter_int (style_text, nitems, "FillType", &value);
272 style->fill_type = value;
273
274 gfig_read_parameter_int (style_text, nitems, "PaintType", &value);
275 style->paint_type = value;
276
277 gfig_read_parameter_double (style_text, nitems, "FillOpacity",
278 &style->fill_opacity);
279
280 for (k = 0; k < nitems; k++)
281 {
282 g_free (style_text[k]);
283 }
284
285 if (gfig_context->debug_styles)
286 g_printerr ("done\n");
287
288 return FALSE;
289 }
290
291
292 gboolean
gfig_skip_style(Style * style,FILE * fp)293 gfig_skip_style (Style *style,
294 FILE *fp)
295 {
296 gulong offset;
297 gchar load_buf2[MAX_LOAD_LINE];
298
299 offset = ftell (fp);
300
301 get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
302 if (strncmp (load_buf2, "<Style ", 7))
303 {
304 /* no style data */
305 fseek (fp, offset, SEEK_SET);
306 return TRUE;
307 }
308
309 while (TRUE)
310 {
311 get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
312 if (!strcmp (load_buf2, "</Style>") || feof (fp))
313 break;
314 }
315
316 if (feof (fp))
317 {
318 g_message ("Error trying to skip style data");
319 return TRUE;
320 }
321
322 return FALSE;
323 }
324
325 /*
326 * FIXME: need to make this load a list of styles if there are more than one.
327 */
328 gboolean
gfig_load_styles(GFigObj * gfig,FILE * fp)329 gfig_load_styles (GFigObj *gfig,
330 FILE *fp)
331 {
332 if (gfig_context->debug_styles)
333 g_printerr ("Loading global styles -- ");
334
335 /* currently we only have the default style */
336 gfig_load_style (&gfig_context->default_style, fp);
337
338 if (gfig_context->debug_styles)
339 g_printerr ("done\n");
340
341 return FALSE;
342 }
343
344 void
gfig_save_style(Style * style,GString * string)345 gfig_save_style (Style *style,
346 GString *string)
347 {
348 gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
349 gchar buffer_r[G_ASCII_DTOSTR_BUF_SIZE];
350 gchar buffer_g[G_ASCII_DTOSTR_BUF_SIZE];
351 gchar buffer_b[G_ASCII_DTOSTR_BUF_SIZE];
352 gchar buffer_a[G_ASCII_DTOSTR_BUF_SIZE];
353 gint blen = G_ASCII_DTOSTR_BUF_SIZE;
354
355 if (gfig_context->debug_styles)
356 g_printerr ("Saving style %s, brush name '%s'\n", style->name, style->brush_name);
357
358 g_string_append_printf (string, "<Style %s>\n", style->name);
359 g_string_append_printf (string, "BrushName: %s\n", style->brush_name);
360 if (!style->brush_name)
361 g_message ("Error saving style %s: saving NULL for brush name", style->name);
362
363 g_string_append_printf (string, "PaintType: %d\n", style->paint_type);
364
365 g_string_append_printf (string, "FillType: %d\n", style->fill_type);
366
367 g_string_append_printf (string, "FillOpacity: %s\n",
368 g_ascii_dtostr (buffer, blen, style->fill_opacity));
369
370 g_string_append_printf (string, "Pattern: %s\n", style->pattern);
371
372 g_string_append_printf (string, "Gradient: %s\n", style->gradient);
373
374 g_string_append_printf (string, "Foreground: %s %s %s %s\n",
375 g_ascii_dtostr (buffer_r, blen, style->foreground.r),
376 g_ascii_dtostr (buffer_g, blen, style->foreground.g),
377 g_ascii_dtostr (buffer_b, blen, style->foreground.b),
378 g_ascii_dtostr (buffer_a, blen, style->foreground.a));
379
380 g_string_append_printf (string, "Background: %s %s %s %s\n",
381 g_ascii_dtostr (buffer_r, blen, style->background.r),
382 g_ascii_dtostr (buffer_g, blen, style->background.g),
383 g_ascii_dtostr (buffer_b, blen, style->background.b),
384 g_ascii_dtostr (buffer_a, blen, style->background.a));
385
386 g_string_append_printf (string, "</Style>\n");
387 }
388
389 void
gfig_style_save_as_attributes(Style * style,GString * string)390 gfig_style_save_as_attributes (Style *style,
391 GString *string)
392 {
393 gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
394 gchar buffer_r[G_ASCII_DTOSTR_BUF_SIZE];
395 gchar buffer_g[G_ASCII_DTOSTR_BUF_SIZE];
396 gchar buffer_b[G_ASCII_DTOSTR_BUF_SIZE];
397 gchar buffer_a[G_ASCII_DTOSTR_BUF_SIZE];
398 gint blen = G_ASCII_DTOSTR_BUF_SIZE;
399
400 if (gfig_context->debug_styles)
401 g_printerr ("Saving style %s as attributes\n", style->name);
402 g_string_append_printf (string, "BrushName=\"%s\" ", style->brush_name);
403
404 g_string_append_printf (string, "Foreground=\"%s %s %s %s\" ",
405 g_ascii_dtostr (buffer_r, blen, style->foreground.r),
406 g_ascii_dtostr (buffer_g, blen, style->foreground.g),
407 g_ascii_dtostr (buffer_b, blen, style->foreground.b),
408 g_ascii_dtostr (buffer_a, blen, style->foreground.a));
409
410 g_string_append_printf (string, "Background=\"%s %s %s %s\" ",
411 g_ascii_dtostr (buffer_r, blen, style->background.r),
412 g_ascii_dtostr (buffer_g, blen, style->background.g),
413 g_ascii_dtostr (buffer_b, blen, style->background.b),
414 g_ascii_dtostr (buffer_a, blen, style->background.a));
415
416 g_string_append_printf (string, "FillType=%d ", style->fill_type);
417
418 g_string_append_printf (string, "PaintType=%d ", style->paint_type);
419
420 g_string_append_printf (string, "FillOpacity=%s ",
421 g_ascii_dtostr (buffer, blen, style->fill_opacity));
422
423
424 }
425
426 void
gfig_save_styles(GString * string)427 gfig_save_styles (GString *string)
428 {
429 if (gfig_context->debug_styles)
430 g_printerr ("Saving global styles.\n");
431
432 gfig_save_style (&gfig_context->default_style, string);
433 }
434
435 /*
436 * set_foreground_callback() is the callback for the Foreground color select
437 * widget. It reads the color from the widget, and applies this color to the
438 * current style. It then produces a repaint (which will be suppressed if
439 * gfig_context->enable_repaint is FALSE).
440 */
441 void
set_foreground_callback(GimpColorButton * button,gpointer data)442 set_foreground_callback (GimpColorButton *button,
443 gpointer data)
444 {
445 GimpRGB color2;
446 Style *current_style;
447
448 if (gfig_context->debug_styles)
449 g_printerr ("Setting foreground color from color selector\n");
450
451 current_style = gfig_context_get_current_style ();
452
453 gimp_color_button_get_color (button, &color2);
454
455 gimp_rgba_set (¤t_style->foreground,
456 color2.r, color2.g, color2.b, color2.a);
457
458 gfig_paint_callback ();
459 }
460
461 void
set_background_callback(GimpColorButton * button,gpointer data)462 set_background_callback (GimpColorButton *button,
463 gpointer data)
464 {
465 GimpRGB color2;
466 Style *current_style;
467
468 if (gfig_context->debug_styles)
469 g_printerr ("Setting background color from color selector\n");
470
471 current_style = gfig_context_get_current_style ();
472
473 gimp_color_button_get_color (button, &color2);
474 gimp_rgba_set (¤t_style->background,
475 color2.r, color2.g, color2.b, color2.a);
476
477 gfig_paint_callback ();
478 }
479
480 void
set_paint_type_callback(GtkToggleButton * toggle,gpointer data)481 set_paint_type_callback (GtkToggleButton *toggle,
482 gpointer data)
483 {
484 gboolean paint_type;
485 Style *current_style;
486
487 current_style = gfig_context_get_current_style ();
488 paint_type = gtk_toggle_button_get_active (toggle);
489 current_style->paint_type = paint_type;
490 gfig_paint_callback ();
491
492 gtk_widget_set_sensitive (GTK_WIDGET (data), paint_type);
493 }
494
495 /*
496 * gfig_brush_changed_callback() is the callback for the brush
497 * selector widget. It reads the brush name from the widget, and
498 * applies this to the current style, as well as the gfig_context->bdesc
499 * values. It then produces a repaint (which will be suppressed if
500 * gfig_context->enable_repaint is FALSE).
501 */
502 void
gfig_brush_changed_callback(GimpBrushSelectButton * button,const gchar * brush_name,gdouble opacity,gint spacing,GimpLayerMode paint_mode,gint width,gint height,const guchar * mask_data,gboolean dialog_closing,gpointer user_data)503 gfig_brush_changed_callback (GimpBrushSelectButton *button,
504 const gchar *brush_name,
505 gdouble opacity,
506 gint spacing,
507 GimpLayerMode paint_mode,
508 gint width,
509 gint height,
510 const guchar *mask_data,
511 gboolean dialog_closing,
512 gpointer user_data)
513 {
514 Style *current_style;
515
516 current_style = gfig_context_get_current_style ();
517 current_style->brush_name = g_strdup (brush_name);
518
519 /* this will soon be unneeded. How soon? */
520 gfig_context->bdesc.name = g_strdup (brush_name);
521 gfig_context->bdesc.width = width;
522 gfig_context->bdesc.height = height;
523 gimp_context_set_brush (brush_name);
524 gimp_context_set_brush_default_size ();
525
526 gfig_paint_callback ();
527 }
528
529 void
gfig_pattern_changed_callback(GimpPatternSelectButton * button,const gchar * pattern_name,gint width,gint height,gint bpp,const guchar * mask_data,gboolean dialog_closing,gpointer user_data)530 gfig_pattern_changed_callback (GimpPatternSelectButton *button,
531 const gchar *pattern_name,
532 gint width,
533 gint height,
534 gint bpp,
535 const guchar *mask_data,
536 gboolean dialog_closing,
537 gpointer user_data)
538 {
539 Style *current_style;
540
541 current_style = gfig_context_get_current_style ();
542 current_style->pattern = g_strdup (pattern_name);
543
544 gfig_paint_callback ();
545 }
546
547 void
gfig_gradient_changed_callback(GimpGradientSelectButton * button,const gchar * gradient_name,gint width,const gdouble * grad_data,gboolean dialog_closing,gpointer user_data)548 gfig_gradient_changed_callback (GimpGradientSelectButton *button,
549 const gchar *gradient_name,
550 gint width,
551 const gdouble *grad_data,
552 gboolean dialog_closing,
553 gpointer user_data)
554 {
555 Style *current_style;
556
557 current_style = gfig_context_get_current_style ();
558 current_style->gradient = g_strdup (gradient_name);
559
560 gfig_paint_callback ();
561 }
562
563 void
gfig_rgba_copy(GimpRGB * color1,GimpRGB * color2)564 gfig_rgba_copy (GimpRGB *color1,
565 GimpRGB *color2)
566 {
567 color1->r = color2->r;
568 color1->g = color2->g;
569 color1->b = color2->b;
570 color1->a = color2->a;
571 }
572
573 void
gfig_style_copy(Style * style1,Style * style0,const gchar * name)574 gfig_style_copy (Style *style1,
575 Style *style0,
576 const gchar *name)
577 {
578 if (name)
579 style1->name = g_strdup (name);
580 else
581 g_message ("Error: name is NULL in gfig_style_copy.");
582
583 if (gfig_context->debug_styles)
584 g_printerr ("Copying style %s as style %s\n", style0->name, name);
585
586 gfig_rgba_copy (&style1->foreground, &style0->foreground);
587 gfig_rgba_copy (&style1->background, &style0->background);
588
589 if (!style0->brush_name)
590 g_message ("Error copying style %s: brush name is NULL.", style0->name);
591
592 style1->brush_name = g_strdup (style0->brush_name);
593 style1->gradient = g_strdup (style0->gradient);
594 style1->pattern = g_strdup (style0->pattern);
595 style1->fill_type = style0->fill_type;
596 style1->fill_opacity = style0->fill_opacity;
597 style1->paint_type = style0->paint_type;
598 }
599
600 /*
601 * gfig_style_apply() applies the settings from the specified style to
602 * the GIMP core. It does not change any widgets, and does not cause
603 * a repaint.
604 */
605 void
gfig_style_apply(Style * style)606 gfig_style_apply (Style *style)
607 {
608 if (gfig_context->debug_styles)
609 g_printerr ("Applying style '%s' -- ", style->name);
610
611 gimp_context_set_foreground (&style->foreground);
612
613 gimp_context_set_background (&style->background);
614
615 if (! gimp_context_set_brush (style->brush_name))
616 g_message ("Style apply: Failed to set brush to '%s' in style '%s'",
617 style->brush_name, style->name);
618
619 gimp_context_set_brush_default_size ();
620
621 gimp_context_set_pattern (style->pattern);
622
623 gimp_context_set_gradient (style->gradient);
624
625 if (gfig_context->debug_styles)
626 g_printerr ("done.\n");
627 }
628
629 /*
630 * gfig_read_gimp_style() reads the style settings from the Gimp core,
631 * and applies them to the specified style, giving that style the
632 * specified name. This is mainly useful as a way of initializing
633 * a style. The function does not cause a repaint.
634 */
635 void
gfig_read_gimp_style(Style * style,const gchar * name)636 gfig_read_gimp_style (Style *style,
637 const gchar *name)
638 {
639 gint dummy;
640
641 if (!name)
642 g_message ("Error: name is NULL in gfig_read_gimp_style.");
643
644 if (gfig_context->debug_styles)
645 g_printerr ("Reading Gimp settings as style %s\n", name);
646 style->name = g_strdup (name);
647
648 gimp_context_get_foreground (&style->foreground);
649 gimp_context_get_background (&style->background);
650
651 style->brush_name = gimp_context_get_brush ();
652 gimp_brush_get_info (style->brush_name,
653 &style->brush_width, &style->brush_height,
654 &dummy, &dummy);
655 gimp_brush_get_spacing (style->brush_name, &style->brush_spacing);
656
657 style->gradient = gimp_context_get_gradient ();
658 style->pattern = gimp_context_get_pattern ();
659
660 style->fill_opacity = 100.;
661
662 gfig_context->bdesc.name = style->brush_name;
663 gfig_context->bdesc.width = style->brush_width;
664 gfig_context->bdesc.height = style->brush_height;
665 }
666
667 /*
668 * gfig_style_set_content_from_style() sets all of the style control widgets
669 * to values from the specified style. This in turn sets the Gimp core's
670 * values to the same things. Repainting is suppressed while this happens,
671 * so calling this function will not produce a repaint.
672 *
673 */
674 void
gfig_style_set_context_from_style(Style * style)675 gfig_style_set_context_from_style (Style *style)
676 {
677 gboolean enable_repaint;
678
679 if (gfig_context->debug_styles)
680 g_printerr ("Setting context from style '%s' -- ", style->name);
681
682 enable_repaint = gfig_context->enable_repaint;
683 gfig_context->enable_repaint = FALSE;
684
685 gimp_color_button_set_color (GIMP_COLOR_BUTTON (gfig_context->fg_color_button),
686 &style->foreground);
687 gimp_color_button_set_color (GIMP_COLOR_BUTTON (gfig_context->bg_color_button),
688 &style->background);
689 if (! gimp_context_set_brush (style->brush_name))
690 g_message ("Style from context: Failed to set brush to '%s'",
691 style->brush_name);
692
693 gimp_context_set_brush_default_size ();
694
695 gimp_brush_select_button_set_brush (GIMP_BRUSH_SELECT_BUTTON (gfig_context->brush_select),
696 style->brush_name, -1.0, -1, -1); /* FIXME */
697
698 gimp_pattern_select_button_set_pattern (GIMP_PATTERN_SELECT_BUTTON (gfig_context->pattern_select),
699 style->pattern);
700
701 gimp_gradient_select_button_set_gradient (GIMP_GRADIENT_SELECT_BUTTON (gfig_context->gradient_select),
702 style->gradient);
703
704 gfig_context->bdesc.name = style->brush_name;
705 if (gfig_context->debug_styles)
706 g_printerr ("done.\n");
707
708 gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (gfig_context->fillstyle_combo),
709 (gint) style->fill_type);
710
711 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gfig_context->paint_type_toggle),
712 style->paint_type);
713 gfig_context->enable_repaint = enable_repaint;
714 }
715
716 /*
717 * gfig_style_set_style_from_context() sets the values in the specified
718 * style to those that appear in the style control widgets f
719 */
720 void
gfig_style_set_style_from_context(Style * style)721 gfig_style_set_style_from_context (Style *style)
722 {
723 Style *current_style;
724 GimpRGB color;
725 gint value;
726
727 style->name = "object";
728 current_style = gfig_context_get_current_style ();
729
730 gimp_color_button_get_color (GIMP_COLOR_BUTTON (gfig_context->fg_color_button),
731 &color);
732 if (gfig_context->debug_styles)
733 g_printerr ("Setting foreground color to %lg %lg %lg\n",
734 color.r, color.g, color.b);
735
736 gfig_rgba_copy (&style->foreground, &color);
737 gimp_color_button_get_color (GIMP_COLOR_BUTTON (gfig_context->bg_color_button),
738 &color);
739 gfig_rgba_copy (&style->background, &color);
740
741 style->brush_name = current_style->brush_name;
742
743 if (!style->pattern || strcmp (style->pattern, current_style->pattern))
744 {
745 style->pattern = g_strdup (current_style->pattern); /* why strduping? */
746 }
747
748 style->gradient = current_style->gradient;
749
750 if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (gfig_context->fillstyle_combo), &value))
751 style->fill_type = value;
752
753 /* FIXME when there is an opacity control widget to read */
754 style->fill_opacity = 100.;
755
756 style->paint_type = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gfig_context->paint_type_toggle));
757 }
758
759 void
mygimp_brush_info(gint * width,gint * height)760 mygimp_brush_info (gint *width,
761 gint *height)
762 {
763 gchar *name = gimp_context_get_brush ();
764 gint dummy;
765
766 if (name && gimp_brush_get_info (name, width, height, &dummy, &dummy))
767 {
768 *width = MAX (*width, 32);
769 *height = MAX (*height, 32);
770 }
771 else
772 {
773 g_message ("Failed to get brush info");
774 *width = *height = 48;
775 }
776
777 g_free (name);
778 }
779
780 Style *
gfig_context_get_current_style(void)781 gfig_context_get_current_style (void)
782 {
783 if (gfig_context->selected_obj)
784 return &gfig_context->selected_obj->style;
785 else
786 return &gfig_context->default_style;
787 }
788