Commit 2b46a253 authored by William Skaggs's avatar William Skaggs

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* plug-ins/gfig/*.[ch]:  a bunch of code clean-up and
	debugging.  Created "classes" for the objects, and
	attached functions to classes rather than objects.
parent ef885f76
2004-07-06 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/gfig/*.[ch]: a bunch of code clean-up and
debugging. Created "classes" for the objects, and
attached functions to classes rather than objects.
2004-07-06 Sven Neumann <sven@gimp.org>
Added an RGB histogram based on a patch by Tor Lillqvist. Fixes
......
......@@ -583,16 +583,27 @@ d_new_arc (gint x,
nobj = g_new0 (Dobject, 1);
nobj->type = ARC;
nobj->class = &dobj_class[ARC];
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_arc;
nobj->loadfunc = d_load_arc;
nobj->savefunc = d_save_arc;
nobj->paintfunc = d_paint_arc;
nobj->copyfunc = d_copy_arc;
return nobj;
}
void
d_arc_object_class_init ()
{
DobjClass *class = &dobj_class[ARC];
class->type = ARC;
class->name = "Arc";
class->drawfunc = d_draw_arc;
class->loadfunc = d_load_arc;
class->savefunc = d_save_arc;
class->paintfunc = d_paint_arc;
class->copyfunc = d_copy_arc;
class->createfunc = d_new_arc;
}
void
d_update_arc (GdkPoint *pnt)
{
......@@ -646,11 +657,7 @@ d_arc_end (GdkPoint *pnt,
/* Complete arc */
/* Convert to an arc ... */
tmp_line->type = ARC;
tmp_line->drawfunc = d_draw_arc;
tmp_line->loadfunc = d_load_arc;
tmp_line->savefunc = d_save_arc;
tmp_line->paintfunc = d_paint_arc;
tmp_line->copyfunc = d_copy_arc;
tmp_line->class = &dobj_class[ARC];
d_line_end (pnt, FALSE);
/*d_draw_line (newarc); Should undraw line */
if (need_to_scale)
......
......@@ -26,12 +26,14 @@
#ifndef __GFIG_ARC_H__
#define __GFIG_ARC_H__
Dobject *d_load_arc (FILE *from);
Dobject *d_load_arc (FILE *from);
void d_update_arc (GdkPoint *pnt);
void d_arc_start (GdkPoint *pnt,
gint shift_down);
void d_arc_end (GdkPoint *pnt,
gint shift_down);
void d_update_arc (GdkPoint *pnt);
void d_arc_start (GdkPoint *pnt,
gint shift_down);
void d_arc_end (GdkPoint *pnt,
gint shift_down);
void d_arc_object_class_init (void);
#endif /* __GFIG_ARC_H__ */
......@@ -354,6 +354,21 @@ d_copy_bezier (Dobject *obj)
return np;
}
void
d_bezier_object_class_init ()
{
DobjClass *class = &dobj_class[BEZIER];
class->type = BEZIER;
class->name = "Bezier";
class->drawfunc = d_draw_bezier;
class->loadfunc = d_load_bezier;
class->savefunc = d_save_bezier;
class->paintfunc = d_paint_bezier;
class->copyfunc = d_copy_bezier;
class->createfunc = d_new_bezier;
}
static Dobject *
d_new_bezier (gint x, gint y)
{
......@@ -362,13 +377,9 @@ d_new_bezier (gint x, gint y)
nobj = g_new0 (Dobject, 1);
nobj->type = BEZIER;
nobj->class = &dobj_class[BEZIER];
nobj->type_data = 4; /* Default to four turns */
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_bezier;
nobj->loadfunc = d_load_bezier;
nobj->savefunc = d_save_bezier;
nobj->paintfunc = d_paint_bezier;
nobj->copyfunc = d_copy_bezier;
return nobj;
}
......
......@@ -34,6 +34,7 @@ void d_draw_bezier (Dobject *obj);
void d_update_bezier (GdkPoint *pnt);
void d_bezier_start (GdkPoint *pnt, gint shift_down);
void d_bezier_end (GdkPoint *pnt, gint shift_down);
void d_bezier_object_class_init (void);
void bezier_dialog (void);
......
......@@ -189,6 +189,21 @@ d_copy_circle (Dobject * obj)
return nc;
}
void
d_circle_object_class_init ()
{
DobjClass *class = &dobj_class[CIRCLE];
class->type = CIRCLE;
class->name = "Circle";
class->drawfunc = d_draw_circle;
class->loadfunc = d_load_circle;
class->savefunc = d_save_circle;
class->paintfunc = d_paint_circle;
class->copyfunc = d_copy_circle;
class->createfunc = d_new_circle;
}
static Dobject *
d_new_circle (gint x,
gint y)
......@@ -198,12 +213,8 @@ d_new_circle (gint x,
nobj = g_new0 (Dobject, 1);
nobj->type = CIRCLE;
nobj->class = &dobj_class[CIRCLE];
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_circle;
nobj->loadfunc = d_load_circle;
nobj->savefunc = d_save_circle;
nobj->paintfunc = d_paint_circle;
nobj->copyfunc = d_copy_circle;
return nobj;
}
......
......@@ -28,10 +28,11 @@
Dobject * d_load_circle (FILE *from);
void d_update_circle (GdkPoint *pnt);
void d_circle_start (GdkPoint *pnt,
gint shift_down);
void d_circle_end (GdkPoint *pnt,
gint shift_down);
void d_update_circle (GdkPoint *pnt);
void d_circle_start (GdkPoint *pnt,
gint shift_down);
void d_circle_end (GdkPoint *pnt,
gint shift_down);
void d_circle_object_class_init (void);
#endif /* __GFIG_CIRCLE_H__ */
......@@ -242,13 +242,14 @@ gfig_dialog (void)
for (k=0; k < 1000; k++)
gfig_context->style[k] = NULL;
gfig_context->num_styles = 0;
gfig_context->current_style = &gfig_context->default_style;
gfig_context->enable_repaint = FALSE;
/* debug */
/* gfig_context->debug_styles = TRUE; */
gfig_context->debug_styles = FALSE;
/* 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");
......@@ -506,6 +507,7 @@ gfig_dialog (void)
gfig_style_apply (&gfig_context->default_style);
}
gfig_context->enable_repaint = TRUE;
gfig_paint_callback ();
gtk_main ();
......@@ -566,7 +568,7 @@ gfig_response (GtkWidget *widget,
break;
case GTK_RESPONSE_OK: /* Close button */
gfig_style_copy (&gfig_context->default_style, gfig_context->current_style, NULL);
gfig_style_copy (&gfig_context->default_style, gfig_context->current_style, "object");
gfig_save_as_parasite ();
gtk_widget_destroy (widget);
break;
......@@ -1301,6 +1303,7 @@ gfig_select_obj_by_number (gint count)
{
gfig_context->selected_obj = objs->obj;
gfig_context->current_style = &objs->obj->style;
gfig_style_set_context_from_style (&objs->obj->style);
break;
}
......@@ -1691,7 +1694,7 @@ gfig_paint_callback (void)
gint count;
gint ccount = 0;
if (!gfig_context->current_obj)
if (!gfig_context->enable_repaint || !gfig_context->current_obj)
return;
objs = gfig_context->current_obj->obj_list;
......@@ -1708,7 +1711,7 @@ gfig_paint_callback (void)
gfig_style_apply (&objs->obj->style);
objs->obj->paintfunc (objs->obj);
objs->obj->class->paintfunc (objs->obj);
/* Fill layer if required */
if (selvals.painttype == PAINT_SELECTION_FILL_TYPE
......
......@@ -65,6 +65,20 @@ static void remove_obj_from_list (GFigObj *obj,
static gint scan_obj_points (DobjPoints *opnt,
GdkPoint *pnt);
void
gfig_init_object_classes ()
{
d_arc_object_class_init ();
d_line_object_class_init ();
d_circle_object_class_init ();
d_ellipse_object_class_init ();
d_poly_object_class_init ();
d_spiral_object_class_init ();
d_star_object_class_init ();
d_bezier_object_class_init ();
}
/* Delete a list of points */
void
d_delete_dobjpoints (DobjPoints * pnts)
......@@ -260,7 +274,7 @@ object_operation_start (GdkPoint *pnt,
/* Copy the "operation object" */
/* Then bung us into "copy/move" mode */
new_obj = (Dobject*) operation_obj->copyfunc (operation_obj);
new_obj = (Dobject*) operation_obj->class->copyfunc (operation_obj);
if (new_obj)
{
gfig_style_copy (&new_obj->style, &operation_obj->style, "Object");
......@@ -268,7 +282,7 @@ object_operation_start (GdkPoint *pnt,
add_to_all_obj (gfig_context->current_obj, new_obj);
operation_obj = new_obj;
selvals.otype = MOVE_COPY_OBJ;
new_obj->drawfunc (new_obj);
new_obj->class->drawfunc (new_obj);
}
break;
case DEL_OBJ:
......@@ -294,7 +308,12 @@ object_operation_end (GdkPoint *pnt,
d_draw_bezier (operation_obj);
}
gfig_style_set_context_from_style (&operation_obj->style);
if (operation_obj)
{
gfig_style_set_context_from_style (&operation_obj->style);
gfig_paint_callback ();
}
operation_obj = NULL;
if (move_all_pnt)
......@@ -416,7 +435,7 @@ remove_obj_from_list (GFigObj *obj,
obj->obj_list = all->next;
/* Draw obj (which will actually undraw it! */
del_obj->drawfunc (del_obj);
del_obj->class->drawfunc (del_obj);
free_one_obj (del_obj);
g_free (all);
......@@ -546,7 +565,7 @@ copy_all_objs (DAllObjs *objs)
new_all_objs = nobj;
}
nobj->obj = (Dobject *) objs->obj->copyfunc (objs->obj);
nobj->obj = (Dobject *) objs->obj->class->copyfunc (objs->obj);
objs = objs->next;
}
......@@ -558,7 +577,7 @@ copy_all_objs (DAllObjs *objs)
static void
draw_one_obj (Dobject * obj)
{
obj->drawfunc (obj);
obj->class->drawfunc (obj);
}
void
......@@ -634,12 +653,18 @@ add_to_all_obj (GFigObj *fobj,
prepend_to_all_obj (fobj, nobj);
/* initialize style when we add the object */
/* gfig_style_copy (&obj->style, &gfig_context->gimp_style, "Object"); */
gfig_context->selected_obj = obj;
gfig_context->current_style = &obj->style;
}
/* First button press -- start drawing object */
/*
* object_start() creates a new object of the type specified in the
* button panel. It is activated by a button press, and causes
* a small square to be drawn at the initial point. The style of
* the new object is set to values taken from the style control
* widgets.
*/
void
object_start (GdkPoint *pnt,
gint shift_down)
......@@ -698,6 +723,8 @@ object_start (GdkPoint *pnt,
if (obj_creating)
{
if (gfig_context->debug_styles)
fprintf (stderr, "Creating object, setting style from context\n");
gfig_style_set_style_from_context (&obj_creating->style);
gfig_context->current_style = &obj_creating->style;
}
......
......@@ -29,6 +29,7 @@ void free_all_objs (DAllObjs * objs);
void clear_undo (void);
void new_obj_2edit (GFigObj *obj);
gint gfig_obj_counts (DAllObjs * objs);
void gfig_init_object_classes (void);
#endif /* __GFIG_DOBJECT_H__ */
......
......@@ -325,6 +325,21 @@ d_copy_ellipse (Dobject * obj)
return nc;
}
void
d_ellipse_object_class_init ()
{
DobjClass *class = &dobj_class[ELLIPSE];
class->type = ELLIPSE;
class->name = "Ellipse";
class->drawfunc = d_draw_ellipse;
class->loadfunc = d_load_ellipse;
class->savefunc = d_save_ellipse;
class->paintfunc = d_paint_ellipse;
class->copyfunc = d_copy_ellipse;
class->createfunc = d_new_ellipse;
}
static Dobject *
d_new_ellipse (gint x, gint y)
{
......@@ -333,12 +348,8 @@ d_new_ellipse (gint x, gint y)
nobj = g_new0 (Dobject, 1);
nobj->type = ELLIPSE;
nobj->class = &dobj_class[ELLIPSE];
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_ellipse;
nobj->loadfunc = d_load_ellipse;
nobj->savefunc = d_save_ellipse;
nobj->paintfunc = d_paint_ellipse;
nobj->copyfunc = d_copy_ellipse;
return nobj;
}
......
......@@ -26,10 +26,11 @@
#ifndef __GFIG_ELLIPSE_H__
#define __GFIG_ELLIPSE_H__
Dobject *d_load_ellipse (FILE *from);
Dobject *d_load_ellipse (FILE *from);
void d_update_ellipse (GdkPoint *pnt);
void d_ellipse_start (GdkPoint *pnt, gint shift_down);
void d_ellipse_end (GdkPoint *pnt, gint shift_down);
void d_update_ellipse (GdkPoint *pnt);
void d_ellipse_start (GdkPoint *pnt, gint shift_down);
void d_ellipse_end (GdkPoint *pnt, gint shift_down);
void d_ellipse_object_class_init (void);
#endif /* __GFIG_CIRCLE_H__ */
......@@ -180,16 +180,27 @@ d_new_line (gint x,
nobj = g_new0 (Dobject, 1);
nobj->type = LINE;
nobj->class = &dobj_class[LINE];
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_line;
nobj->loadfunc = d_load_line;
nobj->savefunc = d_save_line;
nobj->paintfunc = d_paint_line;
nobj->copyfunc = d_copy_line;
return nobj;
}
void
d_line_object_class_init ()
{
DobjClass *class = &dobj_class[LINE];
class->type = LINE;
class->name = "Line";
class->drawfunc = d_draw_line;
class->loadfunc = d_load_line;
class->savefunc = d_save_line;
class->paintfunc = d_paint_line;
class->copyfunc = d_copy_line;
class->createfunc = d_new_line;
}
/* You guessed it delete the object !*/
/*
static void
......
......@@ -39,5 +39,6 @@ void d_line_start (GdkPoint *pnt,
gint shift_down);
void d_line_end (GdkPoint *pnt,
gint shift_down);
void d_line_object_class_init (void);
#endif /* __GFIG_LINE_H__ */
......@@ -347,7 +347,7 @@ d_poly2lines (Dobject *obj)
return; /* no-line */
/* Undraw it to start with - removes control points */
obj->drawfunc (obj);
obj->class->drawfunc (obj);
/* NULL out these points free later */
obj->points = NULL;
......@@ -404,14 +404,10 @@ d_poly2lines (Dobject *obj)
/* hey we're a line now */
obj->type = LINE;
obj->drawfunc = d_draw_line;
obj->loadfunc = d_load_line;
obj->savefunc = d_save_line;
obj->paintfunc = d_paint_line;
obj->copyfunc = d_copy_line;
obj->class = &dobj_class[LINE];
/* draw it + control pnts */
obj->drawfunc (obj);
obj->class->drawfunc (obj);
}
void
......@@ -445,7 +441,7 @@ d_star2lines (Dobject *obj)
return; /* no-line */
/* Undraw it to start with - removes control points */
obj->drawfunc (obj);
obj->class->drawfunc (obj);
/* NULL out these points free later */
obj->points = NULL;
......@@ -532,14 +528,10 @@ d_star2lines (Dobject *obj)
/* hey we're a line now */
obj->type = LINE;
obj->drawfunc = d_draw_line;
obj->loadfunc = d_load_line;
obj->savefunc = d_save_line;
obj->paintfunc = d_paint_line;
obj->copyfunc = d_copy_line;
obj->class = &dobj_class[LINE];
/* draw it + control pnts */
obj->drawfunc (obj);
obj->class->drawfunc (obj);
}
static Dobject *
......@@ -556,6 +548,21 @@ d_copy_poly (Dobject *obj)
return np;
}
void
d_poly_object_class_init ()
{
DobjClass *class = &dobj_class[POLY];
class->type = POLY;
class->name = "Poly";
class->drawfunc = d_draw_poly;
class->loadfunc = d_load_poly;
class->savefunc = d_save_poly;
class->paintfunc = d_paint_poly;
class->copyfunc = d_copy_poly;
class->createfunc = d_new_poly;
}
static Dobject *
d_new_poly (gint x, gint y)
{
......@@ -564,13 +571,9 @@ d_new_poly (gint x, gint y)
nobj = g_new0 (Dobject, 1);
nobj->type = POLY;
nobj->class = &dobj_class[POLY];
nobj->type_data = 3; /* Default to three sides */
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_poly;
nobj->loadfunc = d_load_poly;
nobj->savefunc = d_save_poly;
nobj->paintfunc = d_paint_poly;
nobj->copyfunc = d_copy_poly;
return nobj;
}
......
......@@ -40,5 +40,6 @@ void d_paint_poly (Dobject *obj);
void d_poly2lines (Dobject *obj);
void d_star2lines (Dobject *obj);
void d_poly_object_class_init (void);
#endif /* __GFIG_POLY_H__ */
......@@ -341,6 +341,21 @@ d_copy_spiral (Dobject *obj)
return np;
}
void
d_spiral_object_class_init ()
{
DobjClass *class = &dobj_class[SPIRAL];
class->type = SPIRAL;
class->name = "Spiral";
class->drawfunc = d_draw_spiral;
class->loadfunc = d_load_spiral;
class->savefunc = d_save_spiral;
class->paintfunc = d_paint_spiral;
class->copyfunc = d_copy_spiral;
class->createfunc = d_new_spiral;
}
static Dobject *
d_new_spiral (gint x,
gint y)
......@@ -350,13 +365,9 @@ d_new_spiral (gint x,
nobj = g_new0 (Dobject, 1);
nobj->type = SPIRAL;
nobj->class = &dobj_class[SPIRAL];
nobj->type_data = 4; /* Default to for turns */
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_spiral;
nobj->loadfunc = d_load_spiral;
nobj->savefunc = d_save_spiral;
nobj->paintfunc = d_paint_spiral;
nobj->copyfunc = d_copy_spiral;
return nobj;
}
......
......@@ -35,5 +35,6 @@ void d_spiral_start (GdkPoint *pnt, gint shift_down);
void d_spiral_end (GdkPoint *pnt, gint shift_down);
Dobject * d_load_spiral (FILE *from);
void d_spiral_object_class_init (void);
#endif /* __GFIG_SPIRAL_H__ */
......@@ -389,6 +389,21 @@ d_copy_star (Dobject *obj)
return np;
}
void
d_star_object_class_init ()
{
DobjClass *class = &dobj_class[STAR];
class->type = STAR;
class->name = "Star";
class->drawfunc = d_draw_star;
class->loadfunc = d_load_star;
class->savefunc = d_save_star;
class->paintfunc = d_paint_star;
class->copyfunc = d_copy_star;
class->createfunc = d_new_star;
}
static Dobject *
d_new_star (gint x,
gint y)
......@@ -398,13 +413,9 @@ d_new_star (gint x,
nobj = g_new0 (Dobject, 1);
nobj->type = STAR;
nobj->class = &dobj_class[STAR];
nobj->type_data = 3; /* Default to three sides 6 points*/
nobj->points = new_dobjpoint (x, y);
nobj->drawfunc = d_draw_star;
nobj->loadfunc = d_load_star;
nobj->savefunc = d_save_star;
nobj->paintfunc = d_paint_star;
nobj->copyfunc = d_copy_star;
return nobj;
}
......
......@@ -35,5 +35,6 @@ void d_star_start (GdkPoint *pnt, gint shift_down);
void d_star_end (GdkPoint *pnt, gint shift_down);
Dobject * d_load_star (FILE *from);
void d_star_object_class_init (void);
#endif /* __GFIG_STAR_H__ */
......@@ -232,6 +232,9 @@ gfig_load_style (Style *style,
}
gfig_read_parameter_string (style_text, nitems, "BrushName", &style->brush_name);
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);
......@@ -305,8 +308,13 @@ void
gfig_save_style (Style *style,
GString *string)
{
if (gfig_context->debug_styles)
fprintf (stderr, "Saving style %s, brush name '%s'\n", style->name, style->brush_name);
g_string_append_printf (string, "<Style %s>\n", style->name);
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);