Commit f8869bd1 authored by William Skaggs's avatar William Skaggs
Browse files

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* plug-ins/gfig/*.[ch]: Use single centralized functions to
	create, load, and save objects, instead of separate functions
	for each type of object. A few other miscellaneous fixes.
parent 94163a8b
2004-07-07 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/gfig/*.[ch]: Use single centralized functions to
create, load, and save objects, instead of separate functions
for each type of object. A few other miscellaneous fixes.
2004-07-07 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpclipboard.[ch]: changed to allow pasting any
......
......@@ -35,12 +35,11 @@
#include <libgimp/gimp.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "gfig-line.h"
#include "libgimp/stdplugins-intl.h"
static Dobject *d_new_arc (gint x, gint y);
/* Distance between two lines */
static gdouble
dist (gdouble x1,
......@@ -312,42 +311,6 @@ arc_angle (GdkPoint *pnt,
return offset_angle * 360 / (2*G_PI);
}
static void
d_save_arc (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
}
Dobject *
d_load_arc (FILE *from)
{
Dobject *new_obj = NULL;
gint xpnt;
gint ypnt;
gchar buf[MAX_LOAD_LINE];
gint num_pnts = 0;
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
return new_obj;
}
num_pnts++;
if (!new_obj)
new_obj = d_new_arc (xpnt, ypnt);
else
{
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
}
g_warning ("[%d] Not enough points for arc", line_no);
return NULL;
}
static void
arc_drawing_details (Dobject *obj,
gdouble *minang,
......@@ -568,27 +531,12 @@ d_copy_arc (Dobject * obj)
g_assert (obj->type == ARC);
nc = d_new_arc (obj->points->pnt.x, obj->points->pnt.y);
nc = d_new_object (ARC, obj->points->pnt.x, obj->points->pnt.y);
nc->points->next = d_copy_dobjpoints (obj->points->next);
return nc;
}
static Dobject *
d_new_arc (gint x,
gint y)
{
Dobject *nobj;
nobj = g_new0 (Dobject, 1);
nobj->type = ARC;
nobj->class = &dobj_class[ARC];
nobj->points = new_dobjpoint (x, y);
return nobj;
}
void
d_arc_object_class_init ()
{
......@@ -597,11 +545,8 @@ d_arc_object_class_init ()
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
......
......@@ -26,8 +26,6 @@
#ifndef __GFIG_ARC_H__
#define __GFIG_ARC_H__
Dobject *d_load_arc (FILE *from);
void d_update_arc (GdkPoint *pnt);
void d_arc_start (GdkPoint *pnt,
gint shift_down);
......
......@@ -35,6 +35,7 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "libgimp/stdplugins-intl.h"
......@@ -44,70 +45,6 @@ Dobject *tmp_bezier; /* Needed when drawing bezier curves */
static void d_paint_bezier (Dobject *obj);
static Dobject * d_copy_bezier (Dobject * obj);
static Dobject * d_new_bezier (gint x, gint y);
static void
d_save_bezier (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
g_string_append_printf (string, "<EXTRA>\n");
g_string_append_printf (string, "%d\n</EXTRA>\n", obj->type_data);
}
Dobject *
d_load_bezier (FILE *from)
{
Dobject *new_obj = NULL;
gint xpnt;
gint ypnt;
gchar buf[MAX_LOAD_LINE];
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Must be the end */
if (!strcmp ("<EXTRA>", buf))
{
gint nsides = 3;
/* Number of sides - data item */
if ( !new_obj)
{
g_message ("[%d] Internal load error while loading bezier "
"(extra area)", line_no);
return NULL;
}
get_line (buf, MAX_LOAD_LINE, from, 0);
if (sscanf (buf, "%d", &nsides) != 1)
{
g_message ("[%d] Internal load error while loading bezier "
"(extra area scanf)", line_no);
return NULL;
}
new_obj->type_data = nsides;
get_line (buf, MAX_LOAD_LINE, from, 0);
if (strcmp ("</EXTRA>", buf))
{
g_message ("[%d] Internal load error while loading bezier",
line_no);
return NULL;
}
/* Go around and read the last line */
continue;
}
else
return new_obj;
}
if (!new_obj)
new_obj = d_new_bezier (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
}
#define FP_PNT_MAX 10
......@@ -347,7 +284,7 @@ d_copy_bezier (Dobject *obj)
g_assert (obj->type == BEZIER);
np = d_new_bezier (obj->points->pnt.x, obj->points->pnt.y);
np = d_new_object (BEZIER, obj->points->pnt.x, obj->points->pnt.y);
np->points->next = d_copy_dobjpoints (obj->points->next);
np->type_data = obj->type_data;
......@@ -362,26 +299,8 @@ d_bezier_object_class_init ()
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)
{
Dobject *nobj;
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);
return nobj;
}
void
......@@ -437,7 +356,7 @@ d_bezier_start (GdkPoint *pnt, gint shift_down)
if (!tmp_bezier)
{
/* New curve */
tmp_bezier = obj_creating = d_new_bezier (pnt->x, pnt->y);
tmp_bezier = obj_creating = d_new_object (BEZIER, pnt->x, pnt->y);
}
}
......
......@@ -28,7 +28,6 @@
extern Dobject *tmp_bezier;
Dobject * d_load_bezier (FILE *from);
void d_draw_bezier (Dobject *obj);
void d_update_bezier (GdkPoint *pnt);
......
......@@ -35,50 +35,11 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "gfig-poly.h"
#include "libgimp/stdplugins-intl.h"
static Dobject *d_new_circle (gint x, gint y);
static void
d_save_circle (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
}
Dobject *
d_load_circle (FILE *from)
{
Dobject *new_obj = NULL;
gint xpnt;
gint ypnt;
gchar buf[MAX_LOAD_LINE];
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
/* kludge */
if (buf[0] == '<')
return new_obj;
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
g_warning ("[%d] Internal load error while loading circle",
line_no);
return NULL;
}
if (!new_obj)
new_obj = d_new_circle (xpnt, ypnt);
else
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
g_warning ("[%d] Not enough points for circle", line_no);
return NULL;
}
static gint
calc_radius (GdkPoint *center, GdkPoint *edge)
{
......@@ -183,7 +144,7 @@ d_copy_circle (Dobject * obj)
g_assert (obj->type == CIRCLE);
nc = d_new_circle (obj->points->pnt.x, obj->points->pnt.y);
nc = d_new_object (CIRCLE, obj->points->pnt.x, obj->points->pnt.y);
nc->points->next = d_copy_dobjpoints (obj->points->next);
return nc;
......@@ -197,26 +158,8 @@ d_circle_object_class_init ()
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)
{
Dobject *nobj;
nobj = g_new0 (Dobject, 1);
nobj->type = CIRCLE;
nobj->class = &dobj_class[CIRCLE];
nobj->points = new_dobjpoint (x, y);
return nobj;
}
void
......@@ -270,7 +213,7 @@ void
d_circle_start (GdkPoint *pnt,
gint shift_down)
{
obj_creating = d_new_circle (pnt->x, pnt->y);
obj_creating = d_new_object (CIRCLE, pnt->x, pnt->y);
}
void
......
......@@ -26,8 +26,6 @@
#ifndef __GFIG_CIRCLE_H__
#define __GFIG_CIRCLE_H__
Dobject * d_load_circle (FILE *from);
void d_update_circle (GdkPoint *pnt);
void d_circle_start (GdkPoint *pnt,
gint shift_down);
......
......@@ -65,6 +65,137 @@ static void remove_obj_from_list (GFigObj *obj,
static gint scan_obj_points (DobjPoints *opnt,
GdkPoint *pnt);
void
d_save_object (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
switch (obj->type)
{
case BEZIER:
case POLY:
case SPIRAL:
case STAR:
g_string_append_printf (string, "<EXTRA>\n");
g_string_append_printf (string, "%d\n</EXTRA>\n", obj->type_data);
break;
default:
break;
}
}
static DobjType
gfig_read_object_type (gchar *desc)
{
gchar *ptr = desc;
DobjType type;
if (* ptr != '<')
return OBJ_TYPE_NONE;
ptr++;
for (type = LINE; type < NUM_OBJ_TYPES; type++)
{
if (ptr == strstr (ptr, dobj_class[type].name))
return type;
}
return OBJ_TYPE_NONE;
}
Dobject *
d_load_object (gchar *desc,
FILE *fp)
{
Dobject *new_obj = NULL;
gint xpnt;
gint ypnt;
gchar buf[MAX_LOAD_LINE];
DobjType type;
type = gfig_read_object_type (desc);
if (type == OBJ_TYPE_NONE)
{
g_message ("Error loading object: type not recognized.");
return NULL;
}
while (get_line (buf, MAX_LOAD_LINE, fp, 0))
{
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Read <EXTRA> block if there is one */
if (!strcmp ("<EXTRA>", buf))
{
if ( !new_obj)
{
g_message ("Error while loading object (no points)");
return NULL;
}
get_line (buf, MAX_LOAD_LINE, fp, 0);
if (sscanf (buf, "%d", &new_obj->type_data) != 1)
{
g_message ("Error while loading object (no type data)");
return NULL;
}
get_line (buf, MAX_LOAD_LINE, fp, 0);
if (strcmp ("</EXTRA>", buf))
{
g_message ("Syntax error while loading object");
return NULL;
}
/* Go around and read the last line */
continue;
}
else
return new_obj;
}
if (!new_obj)
new_obj = d_new_object (type, xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
}
Dobject *
d_new_object (DobjType type,
gint x,
gint y)
{
Dobject *nobj = g_new0 (Dobject, 1);
nobj->type = type;
nobj->class = &dobj_class[type];
nobj->points = new_dobjpoint (x, y);
nobj->type_data = 0;
if (type == BEZIER)
{
nobj->type_data = 4;
}
else if (type == POLY)
{
nobj->type_data = 3; /* default to 3 sides */
}
else if (type == SPIRAL)
{
nobj->type_data = 4; /* default to 4 turns */
}
else if (type == STAR)
{
nobj->type_data = 3; /* default to 3 sides 6 points */
}
return nobj;
}
void
gfig_init_object_classes ()
......
......@@ -25,10 +25,24 @@
#ifndef __GFIG_DOBJECT_H__
#define __GFIG_DOBJECT_H__
void free_all_objs (DAllObjs * objs);
Dobject *d_load_object (gchar *desc,
FILE *fp);
Dobject *d_new_object (DobjType type,
gint x,
gint y);
void d_save_object (Dobject *obj,
GString *string);
void free_all_objs (DAllObjs *objs);
void clear_undo (void);
void new_obj_2edit (GFigObj *obj);
gint gfig_obj_counts (DAllObjs * objs);
void new_obj_2edit (GFigObj *obj);
gint gfig_obj_counts (DAllObjs *objs);
void gfig_init_object_classes (void);
#endif /* __GFIG_DOBJECT_H__ */
......
......@@ -36,49 +36,11 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "gfig-poly.h"
#include "libgimp/stdplugins-intl.h"
static Dobject *d_new_ellipse (gint x, gint y);
static void
d_save_ellipse (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
}
Dobject *
d_load_ellipse (FILE *from)
{
Dobject *new_obj = NULL;
gint xpnt;
gint ypnt;
gchar buf[MAX_LOAD_LINE];
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
/* kludge */
if (buf[0] == '<')
return new_obj;
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
g_message ("[%d] Not enough points for ellipse", line_no);
return NULL;
}
if (!new_obj)
new_obj = d_new_ellipse (xpnt, ypnt);
else
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
g_message ("[%d] Not enough points for ellipse", line_no);
return NULL;
}
static void
d_draw_ellipse (Dobject * obj)
{
......@@ -319,7 +281,7 @@ d_copy_ellipse (Dobject * obj)
g_assert (obj->type == ELLIPSE);
nc = d_new_ellipse (obj->points->pnt.x, obj->points->pnt.y);
nc = d_new_object (ELLIPSE, obj->points->pnt.x, obj->points->pnt.y);
nc->points->next = d_copy_dobjpoints (obj->points->next);
return nc;
......@@ -333,25 +295,8 @@ d_ellipse_object_class_init ()
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)
{
Dobject *nobj;
nobj = g_new0 (Dobject, 1);
nobj->type = ELLIPSE;
nobj->class = &dobj_class[ELLIPSE];
nobj->points = new_dobjpoint (x, y);
return nobj;
}
void
......@@ -432,7 +377,7 @@ d_update_ellipse (GdkPoint *pnt)
void
d_ellipse_start (GdkPoint *pnt, gint shift_down)
{
obj_creating = d_new_ellipse (pnt->x, pnt->y);
obj_creating <