Commit 4563aa04 authored by William Skaggs's avatar William Skaggs
Browse files

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* gimp/plug-ins/gfig/gfig-circle.c
	* gimp/plug-ins/gfig/gfig-dialog.c
	* gimp/plug-ins/gfig/gfig-dobject.c
	* gimp/plug-ins/gfig/gfig-ellipse.c
	* gimp/plug-ins/gfig/gfig-poly.c
	* gimp/plug-ins/gfig/gfig-preview.c
	* gimp/plug-ins/gfig/gfig-star.c
	* gimp/plug-ins/gfig/gfig-style.c
	* gimp/plug-ins/gfig/gfig-style.h
	* gimp/plug-ins/gfig/gfig.c
	* gimp/plug-ins/gfig/gfig.h: Made FG, BG, and pattern fill work for
	fillable objects; other miscellaneous cleanups and minor fixes.
parent 9000f4a9
2004-07-09 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* gimp/plug-ins/gfig/gfig-circle.c
* gimp/plug-ins/gfig/gfig-dialog.c
* gimp/plug-ins/gfig/gfig-dobject.c
* gimp/plug-ins/gfig/gfig-ellipse.c
* gimp/plug-ins/gfig/gfig-poly.c
* gimp/plug-ins/gfig/gfig-preview.c
* gimp/plug-ins/gfig/gfig-star.c
* gimp/plug-ins/gfig/gfig-style.c
* gimp/plug-ins/gfig/gfig-style.h
* gimp/plug-ins/gfig/gfig.c
* gimp/plug-ins/gfig/gfig.h: Made FG, BG, and pattern fill work for
fillable objects; other miscellaneous cleanups and minor fixes.
2004-07-09 Sven Neumann <sven@gimp.org>
* app/gui/gui.c: removed the quit dialog code here.
......
......@@ -128,13 +128,10 @@ d_paint_circle (Dobject *obj)
selopt.feather,
selopt.feather_radius);
/* Is selection all we need ? */
if (selvals.painttype == PAINT_SELECTION_TYPE)
return;
paint_layer_fill ();
gimp_edit_stroke (gfig_context->drawable_id);
gimp_selection_clear (gfig_context->image_id);
}
static Dobject*
......
......@@ -143,7 +143,6 @@ selection_option selopt =
10.0, /* feather radius */
ARC_SEGMENT, /* Arc as a segment */
FILL_PATTERN, /* Fill as pattern */
FILL_EACH, /* Fill after each selection */
100.0, /* Max opacity */
};
......@@ -250,10 +249,8 @@ gfig_dialog (void)
/* initial gimp and default styles */
gfig_read_gimp_style (&gfig_context->gimp_style, "Gimp");
gfig_context->current_style = &gfig_context->default_style;
gfig_style_set_all_sources (&gfig_context->gimp_style, STYLE_SOURCE_GIMP);
gfig_style_append (&gfig_context->gimp_style);
gfig_read_gimp_style (&gfig_context->default_style, "Base");
gfig_style_set_all_sources (&gfig_context->default_style, STYLE_SOURCE_DEFAULT);
gfig_style_append (&gfig_context->default_style);
if (parasite)
......@@ -472,9 +469,11 @@ gfig_dialog (void)
/* fill style combo box in Style frame */
gfig_context->fillstyle_combo = combo
= gimp_int_combo_box_new (_("Pattern"), FILL_PATTERN,
_("Foreground"), FILL_FOREGROUND,
_("Background"), FILL_BACKGROUND,
= gimp_int_combo_box_new (_("No fill"), FILL_NONE,
_("FG fill"), FILL_FOREGROUND,
_("BG fill"), FILL_BACKGROUND,
_("Pattern fill"), FILL_PATTERN,
_("Gradient fill"), FILL_GRADIENT,
NULL);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), 0);
g_signal_connect (combo, "changed",
......@@ -536,7 +535,6 @@ gfig_response (GtkWidget *widget,
/* Update the screen */
gtk_widget_queue_draw (gfig_context->preview);
/* And preview */
list_button_update (gfig_context->current_obj);
gfig_context->current_obj->obj_status |= GFIG_MODIFIED;
}
......@@ -558,8 +556,6 @@ gfig_response (GtkWidget *widget,
tmp_line = NULL;
tmp_bezier = NULL;
gtk_widget_queue_draw (gfig_context->preview);
/* And preview */
list_button_update (gfig_context->current_obj);
gfig_paint_callback ();
break;
......@@ -637,8 +633,6 @@ merge_button_callback (GtkWidget *widget,
/* redraw all */
gtk_widget_queue_draw (gfig_context->preview);
/* And preview */
list_button_update (gfig_context->current_obj);
}
}
......@@ -691,7 +685,7 @@ static void
gfig_list_load_all (const gchar *path)
{
/* Make sure to clear any existing gfigs */
gfig_context->current_obj = pic_obj = NULL;
gfig_context->current_obj = NULL;
gfig_list_free_all ();
......@@ -705,7 +699,7 @@ gfig_list_load_all (const gchar *path)
gfig_list_insert (gfig);
}
pic_obj = gfig_context->current_obj = gfig_list->data; /* set to first entry */
gfig_context->current_obj = gfig_list->data; /* set to first entry */
}
static void
......@@ -777,8 +771,6 @@ create_save_file_chooser (GFigObj *obj,
}
fprintf (stderr, "Got here.\n");
gtk_window_present (GTK_WINDOW (window));
}
......@@ -938,10 +930,7 @@ select_combo_callback (GtkWidget *widget,
selopt.as_pie = (ArcType) value;
break;
case SELECT_TYPE_MENU_FILL:
selopt.fill_type = (FillType) value;
break;
case SELECT_TYPE_MENU_WHEN:
selopt.fill_when = (FillWhen) value;
gfig_context->current_style->fill_type = (FillType) value;
break;
default:
g_return_if_reached ();
......@@ -1252,17 +1241,6 @@ update_options (GFigObj *old_obj)
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (gfig_opt_widget.gridtypemenu),
gfig_context->current_obj->opts.gridtype);
#ifdef DEBUG
printf ("Gridtype set in options to ");
if (gfig_context->current_obj->opts.gridtype == RECT_GRID)
printf ("RECT_GRID\n");
else if (gfig_context->current_obj->opts.gridtype == POLAR_GRID)
printf ("POLAR_GRID\n");
else if (gfig_context->current_obj->opts.gridtype == ISO_GRID)
printf ("ISO_GRID\n");
else printf ("NONE\n");
#endif /* DEBUG */
}
}
......@@ -1553,24 +1531,9 @@ paint_combo_callback (GtkWidget *widget,
switch (mtype)
{
case PAINT_LAYERS_MENU:
selvals.onlayers = (DrawonLayers) value;
case PAINT_BGS_MENU:
selvals.onlayerbg = (LayersBGType) value;
#ifdef DEBUG
printf ("BG type = %d\n", selvals.onlayerbg);
#endif /* DEBUG */
break;
case PAINT_TYPE_MENU:
selvals.painttype = (PaintType) value;
#ifdef DEBUG
printf ("Got type menu = %d\n", selvals.painttype);
#endif /* DEBUG */
default:
g_return_if_reached ();
break;
......@@ -1621,16 +1584,6 @@ typedef struct _GfigListOptions
gboolean created;
} GfigListOptions;
void
list_button_update (GFigObj *obj)
{
g_return_if_fail (obj != NULL);
pic_obj = (GFigObj *) obj;
}
static void
gfig_load_file_chooser_response (GtkFileChooser *chooser,
gint response_id,
......@@ -1672,13 +1625,32 @@ gfig_load_file_chooser_response (GtkFileChooser *chooser,
gfig_paint_callback ();
}
static void
void
paint_layer_fill (void)
{
GimpBucketFillMode fill_mode;
switch (gfig_context->current_style->fill_type)
{
case FILL_NONE:
return;
case FILL_FOREGROUND:
fill_mode = GIMP_FG_BUCKET_FILL;
break;
case FILL_BACKGROUND:
fill_mode = GIMP_BG_BUCKET_FILL;
break;
case FILL_PATTERN:
fill_mode = GIMP_PATTERN_BUCKET_FILL;
break;
default:
return;
}
gimp_edit_bucket_fill (gfig_context->drawable_id,
selopt.fill_type, /* Fill mode */
fill_mode, /* Fill mode */
GIMP_NORMAL_MODE,
selopt.fill_opacity, /* Fill opacity */
gfig_context->current_style->fill_opacity, /* Fill opacity */
0.0, /* threshold - ignored */
FALSE, /* Sample merged - ignored */
0.0, /* x - ignored */
......@@ -1693,6 +1665,7 @@ gfig_paint_callback (void)
gchar buf[128];
gint count;
gint ccount = 0;
Style *style0;
if (!gfig_context->enable_repaint || !gfig_context->current_obj)
return;
......@@ -1703,6 +1676,9 @@ gfig_paint_callback (void)
gimp_drawable_fill (gfig_context->drawable_id, GIMP_TRANSPARENT_FILL);
/* remember current style because it will be changed while painting */
style0 = gfig_context->current_style;
while (objs)
{
if (ccount == obj_show_single || obj_show_single == -1)
......@@ -1713,10 +1689,8 @@ gfig_paint_callback (void)
objs->obj->class->paintfunc (objs->obj);
/* Fill layer if required */
if (selvals.painttype == PAINT_SELECTION_FILL_TYPE
&& selopt.fill_when == FILL_EACH)
paint_layer_fill ();
gimp_selection_clear (gfig_context->image_id);
}
objs = objs->next;
......@@ -1724,12 +1698,8 @@ gfig_paint_callback (void)
ccount++;
}
/* Fill layer if required */
if (selvals.painttype == PAINT_SELECTION_FILL_TYPE
&& selopt.fill_when == FILL_AFTER)
paint_layer_fill ();
/* gfig_style_apply (&gfig_context->gimp_style); */
/* set style back to its value on entry*/
gfig_context->current_style = style0;
gimp_displays_flush ();
......@@ -1796,8 +1766,6 @@ toggle_obj_type (GtkWidget *widget,
}
/* Update draw areas */
gtk_widget_queue_draw (gfig_context->preview);
/* And preview */
list_button_update (gfig_context->current_obj);
}
selvals.otype = (DobjType) GPOINTER_TO_INT (data);
......
......@@ -440,10 +440,7 @@ object_operation_end (GdkPoint *pnt,
}
if (operation_obj)
{
gfig_style_set_context_from_style (&operation_obj->style);
gfig_paint_callback ();
}
gfig_style_set_context_from_style (&operation_obj->style);
operation_obj = NULL;
......@@ -1099,8 +1096,6 @@ new_obj_2edit (GFigObj *obj)
/* redraw with new */
gtk_widget_queue_draw (gfig_context->preview);
/* And preview */
list_button_update (gfig_context->current_obj);
if (obj->obj_status & GFIG_READONLY)
{
......
......@@ -66,8 +66,8 @@ d_draw_ellipse (Dobject * obj)
draw_sqr (&center_pnt->pnt);
draw_sqr (&edge_pnt->pnt);
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x) * 2;
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y) * 2;
bound_wx = abs (center_pnt->pnt.x - edge_pnt->pnt.x);
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y);
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2 * center_pnt->pnt.x - edge_pnt->pnt.x;
......@@ -79,7 +79,7 @@ d_draw_ellipse (Dobject * obj)
else
top_y = edge_pnt->pnt.y;
gfig_draw_arc (top_x, top_y, bound_wx, bound_wy, 0, 360);
gfig_draw_arc (center_pnt->pnt.x, center_pnt->pnt.y, bound_wx, bound_wy, 0, 360);
}
static void
......@@ -256,7 +256,6 @@ d_paint_ellipse (Dobject *obj)
else
scale_to_xy (&dpnts[0], 2);
gimp_ellipse_select (gfig_context->image_id,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
......@@ -265,13 +264,9 @@ d_paint_ellipse (Dobject *obj)
selopt.feather,
selopt.feather_radius);
/* Is selection all we need ? */
if (selvals.painttype == PAINT_SELECTION_TYPE)
return;
paint_layer_fill ();
gimp_edit_stroke (gfig_context->drawable_id);
gimp_selection_clear (gfig_context->image_id);
}
static Dobject *
......
......@@ -233,22 +233,17 @@ d_paint_poly (Dobject *obj)
else
scale_to_xy (&line_pnts[0], i/2);
/* One go */
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_context->image_id,
i, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
}
gimp_free_select (gfig_context->image_id,
i, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
paint_layer_fill ();
gimp_edit_stroke (gfig_context->drawable_id);
g_free (line_pnts);
}
......
/*
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
......@@ -364,7 +364,7 @@ gfig_preview_expose (GtkWidget *widget,
draw_background ();
draw_grid ();
draw_objects (pic_obj->obj_list, TRUE);
draw_objects (gfig_context->current_obj->obj_list, TRUE);
return FALSE;
}
......@@ -457,7 +457,6 @@ gfig_preview_events (GtkWidget *widget,
}
gfig_paint_callback ();
list_button_update (gfig_context->current_obj);
break;
case GDK_MOTION_NOTIFY:
......
......@@ -291,22 +291,16 @@ d_paint_star (Dobject *obj)
else
scale_to_xy (&line_pnts[0], i/2);
/* One go */
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_context->image_id,
i, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
}
gimp_free_select (gfig_context->image_id,
i, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
paint_layer_fill ();
gimp_edit_stroke (gfig_context->drawable_id);
g_free (line_pnts);
}
......
......@@ -243,10 +243,13 @@ gfig_load_style (Style *style,
if (! &style->brush_name )
g_message ("Error loading style: got NULL for brush name.");
gfig_read_parameter_string (style_text, nitems, "Pattern", &style->pattern);
gfig_read_parameter_string (style_text, nitems, "Gradient", &style->gradient);
gfig_read_parameter_gimp_rgb (style_text, nitems, "Foreground", &style->foreground);
gfig_read_parameter_gimp_rgb (style_text, nitems, "Background", &style->background);
gfig_read_parameter_string (style_text, nitems, "Pattern", &style->pattern);
gfig_read_parameter_string (style_text, nitems, "Gradient", &style->gradient);
gfig_read_parameter_gimp_rgb (style_text, nitems, "Foreground", &style->foreground);
gfig_read_parameter_gimp_rgb (style_text, nitems, "Background", &style->background);
gfig_read_parameter_int (style_text, nitems, "FillType", (gint *)&style->fill_type);
gfig_read_parameter_double (style_text, nitems, "FillOpacity",
(gdouble *)&style->fill_opacity);
for (k = 0; k < nitems; k++)
{
......@@ -316,6 +319,7 @@ void
gfig_save_style (Style *style,
GString *string)
{
gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_r[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_g[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_b[G_ASCII_DTOSTR_BUF_SIZE];
......@@ -329,28 +333,66 @@ gfig_save_style (Style *style,
g_string_append_printf (string, "BrushName: %s\n", style->brush_name);
if (!style->brush_name)
g_message ("Error saving style %s: saving NULL for brush name", style->name);
g_string_append_printf (string, "BrushSource: %d\n", style->brush_source);
g_string_append_printf (string, "FillType: %d\n", style->fill_type);
g_string_append_printf (string, "FillTypeSource: %d\n", style->fill_type_source);
g_string_append_printf (string, "FillOpacity: %s\n",
g_ascii_dtostr (buffer, blen, style->fill_opacity));
g_string_append_printf (string, "Pattern: %s\n", style->pattern);
g_string_append_printf (string, "PatternSource: %d\n", style->pattern_source);
g_string_append_printf (string, "Gradient: %s\n", style->gradient);
g_string_append_printf (string, "GradientSource: %d\n", style->gradient_source);
g_string_append_printf (string, "Foreground: %s %s %s %s\n",
g_ascii_dtostr (buffer_r, blen, style->foreground.r),
g_ascii_dtostr (buffer_g, blen, style->foreground.g),
g_ascii_dtostr (buffer_b, blen, style->foreground.b),
g_ascii_dtostr (buffer_a, blen, style->foreground.a));
g_string_append_printf (string, "ForegroundSource: %d\n", style->background_source);
g_string_append_printf (string, "Background: %s %s %s %s\n",
g_ascii_dtostr (buffer_r, blen, style->background.r),
g_ascii_dtostr (buffer_g, blen, style->background.g),
g_ascii_dtostr (buffer_b, blen, style->background.b),
g_ascii_dtostr (buffer_a, blen, style->background.a));
g_string_append_printf (string, "BackgroundSource: %d\n", style->background_source);
g_string_append_printf (string, "</Style>\n");
}
void
gfig_style_save_as_attributes (Style *style,
GString *string)
{
gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_r[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_g[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_b[G_ASCII_DTOSTR_BUF_SIZE];
gchar buffer_a[G_ASCII_DTOSTR_BUF_SIZE];
gint blen = G_ASCII_DTOSTR_BUF_SIZE;
if (gfig_context->debug_styles)
fprintf (stderr, "Saving style %s as attributes\n", style->name);
g_string_append_printf (string, "BrushName=\"%s\" ", style->brush_name);
g_string_append_printf (string, "Foreground=\"%s %s %s %s\" ",
g_ascii_dtostr (buffer_r, blen, style->foreground.r),
g_ascii_dtostr (buffer_g, blen, style->foreground.g),
g_ascii_dtostr (buffer_b, blen, style->foreground.b),
g_ascii_dtostr (buffer_a, blen, style->foreground.a));
g_string_append_printf (string, "Background=\"%s %s %s %s\" ",
g_ascii_dtostr (buffer_r, blen, style->background.r),
g_ascii_dtostr (buffer_g, blen, style->background.g),
g_ascii_dtostr (buffer_b, blen, style->background.b),
g_ascii_dtostr (buffer_a, blen, style->background.a));
g_string_append_printf (string, "FillType=%d ", style->fill_type);
g_string_append_printf (string, "FillOpacity=%s ",
g_ascii_dtostr (buffer, blen, style->fill_opacity));
}
void
gfig_save_styles (GString *string)
{
......@@ -449,8 +491,8 @@ gfig_pattern_changed_callback (const gchar *pattern_name,
gboolean dialog_closing,
gpointer user_data)
{
gfig_context->current_style->pattern = (gchar *) pattern_name;
gfig_context->default_style.pattern = (gchar *) pattern_name;
gfig_context->current_style->pattern = g_strdup (pattern_name);
gfig_context->default_style.pattern = g_strdup (pattern_name);
gfig_paint_callback ();
}
......@@ -462,8 +504,8 @@ gfig_gradient_changed_callback (const gchar *gradient_name,
gboolean dialog_closing,
gpointer user_data)
{
gfig_context->current_style->gradient = (gchar *) gradient_name;
gfig_context->default_style.gradient = (gchar *) gradient_name;
gfig_context->current_style->gradient = g_strdup (gradient_name);
gfig_context->default_style.gradient = g_strdup (gradient_name);
gfig_paint_callback ();
}
......@@ -497,11 +539,11 @@ gfig_style_copy (Style *style1,
if (!style0->brush_name)
g_message ("Error copying style %s: brush name is NULL.", style0->name);
style1->brush_name = g_strdup (style0->brush_name);
style1->gradient = g_strdup (style0->gradient);
style1->pattern = g_strdup (style0->pattern);
style1->brush_name = g_strdup (style0->brush_name);
style1->gradient = g_strdup (style0->gradient);
style1->pattern = g_strdup (style0->pattern);
style1->fill_type = style0->fill_type;
style1->fill_opacity = style0->fill_opacity;
}
/*
......@@ -514,25 +556,23 @@ gfig_style_apply (Style *style)
{
if (gfig_context->debug_styles)
fprintf (stderr, "Applying style '%s' -- ", style->name);
gimp_palette_set_foreground (&style->foreground);
gimp_palette_set_background (&style->background);
if (!gimp_brushes_set_brush (style->brush_name))
g_message ("Style apply: Failed to set brush to '%s' in style '%s'",
style->brush_name, style->name);
if (gfig_context->debug_styles)
fprintf (stderr, "done.\n");
}
void
gfig_style_set_all_sources (Style *style,
StyleSource source)
{
style->foreground_source = source;
style->background_source = source;
style->brush_source = source;
style->gradient_source = source;
style->pattern_source = source;
gimp_patterns_set_pattern (style->pattern);
gimp_gradients_set_gradient (style->gradient);
gfig_context->current_style = style;
if (gfig_context->debug_styles)
fprintf (stderr, "done.\n");
}
void
......@@ -569,6 +609,8 @@ gfig_read_gimp_style (Style *style,
style->gradient = gimp_gradients_get_gradient ();
style->pattern = gimp_patterns_get_pattern (&w, &h);
style->fill_opacity = 100.;
gfig_context->bdesc.name = style->brush_name;