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.
This commit is contained in:
William Skaggs 2004-07-07 17:52:16 +00:00
parent 94163a8beb
commit f8869bd1cd
22 changed files with 215 additions and 660 deletions

View file

@ -1,3 +1,9 @@
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

View file

@ -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

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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 ()

View file

@ -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__ */

View file

@ -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 = d_new_object (ELLIPSE, pnt->x, pnt->y);
}
void

View file

@ -26,8 +26,6 @@
#ifndef __GFIG_ELLIPSE_H__
#define __GFIG_ELLIPSE_H__
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);

View file

@ -35,48 +35,10 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "libgimp/stdplugins-intl.h"
static Dobject * d_new_line (gint x, gint y);
void
d_save_line (Dobject *obj,
GString *string)
{
do_save_obj (obj, string);
}
Dobject *
d_load_line (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 line",
line_no);
return NULL;
}
if (!new_obj)
new_obj = d_new_line (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
}
Dobject *
d_copy_line (Dobject *obj)
{
@ -84,7 +46,7 @@ d_copy_line (Dobject *obj)
g_assert (obj->type == LINE);
nl = d_new_line (obj->points->pnt.x, obj->points->pnt.y);
nl = d_new_object (LINE, obj->points->pnt.x, obj->points->pnt.y);
nl->points->next = d_copy_dobjpoints (obj->points->next);
return nl;
@ -171,21 +133,6 @@ d_paint_line (Dobject *obj)
* later.
*/
static Dobject *
d_new_line (gint x,
gint y)
{
Dobject *nobj;
nobj = g_new0 (Dobject, 1);
nobj->type = LINE;
nobj->class = &dobj_class[LINE];
nobj->points = new_dobjpoint (x, y);
return nobj;
}
void
d_line_object_class_init ()
{
@ -194,11 +141,8 @@ d_line_object_class_init ()
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 !*/
@ -312,7 +256,7 @@ d_line_start (GdkPoint *pnt,
{
/* Draw square on point */
/* Must delete obj_creating if we have one */
obj_creating = d_new_line (pnt->x, pnt->y);
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
}
else
{
@ -350,7 +294,7 @@ d_line_end (GdkPoint *pnt,
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = d_new_line (pnt->x, pnt->y);
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
}
else
{

View file

@ -26,7 +26,6 @@
#ifndef __GFIG_LINE_H__
#define __GFIG_LINE_H__
Dobject * d_load_line (FILE *from);
void d_save_line (Dobject *obj,
GString *string);

View file

@ -35,17 +35,15 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "gfig-line.h"
#include "libgimp/stdplugins-intl.h"
static gint poly_num_sides = 3; /* Default to three sided object */
static void d_save_poly (Dobject * obj,
GString * string);
static void d_draw_poly (Dobject *obj);
static Dobject * d_copy_poly (Dobject * obj);
static Dobject * d_new_poly (gint x, gint y);
gboolean
poly_button_press (GtkWidget *widget,
@ -59,69 +57,6 @@ poly_button_press (GtkWidget *widget,
return FALSE;
}
static void
d_save_poly (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);
g_string_append_printf (string, "</POLY>\n");
}
Dobject *
d_load_poly (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_warning ("[%d] Internal load error while loading poly (extra area)",
line_no);
return NULL;
}
get_line (buf, MAX_LOAD_LINE, from, 0);
if (sscanf (buf, "%d", &nsides) != 1)
{
g_warning ("[%d] Internal load error while loading poly (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_warning ("[%d] Internal load error while loading poly",
line_no);
return NULL;
}
/* Go around and read the last line */
continue;
}
else
return new_obj;
}
if (!new_obj)
new_obj = d_new_poly (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
}
static void
d_draw_poly (Dobject *obj)
{
@ -541,7 +476,7 @@ d_copy_poly (Dobject *obj)
g_assert (obj->type == POLY);
np = d_new_poly (obj->points->pnt.x, obj->points->pnt.y);
np = d_new_object (POLY, obj->points->pnt.x, obj->points->pnt.y);
np->points->next = d_copy_dobjpoints (obj->points->next);
np->type_data = obj->type_data;
@ -556,26 +491,8 @@ d_poly_object_class_init ()
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)
{
Dobject *nobj;
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);
return nobj;
}
void
@ -631,7 +548,7 @@ void
d_poly_start (GdkPoint *pnt,
gint shift_down)
{
obj_creating = d_new_poly (pnt->x, pnt->y);
obj_creating = d_new_object (POLY, pnt->x, pnt->y);
obj_creating->type_data = poly_num_sides;
}

View file

@ -30,8 +30,6 @@ gboolean poly_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
Dobject *d_load_poly (FILE *from);
void d_update_poly (GdkPoint *pnt);
void d_poly_start (GdkPoint *pnt, gint shift_down);
void d_poly_end (GdkPoint *pnt, gint shift_down);

View file

@ -36,13 +36,12 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "libgimp/stdplugins-intl.h"
static void d_draw_spiral (Dobject *obj);
static void d_paint_spiral (Dobject *obj);
static Dobject *d_copy_spiral (Dobject * obj);
static Dobject *d_new_spiral (gint x, gint y);
static gint spiral_num_turns = 4; /* Default to 4 turns */
static gint spiral_toggle = 0; /* 0 = clockwise -1 = anti-clockwise */
@ -59,69 +58,6 @@ spiral_button_press (GtkWidget *widget,
return FALSE;
}
static void
d_save_spiral (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);
}
/* Load a spiral from the specified stream */
Dobject *
d_load_spiral (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_warning ("[%d] Internal load error while loading spiral (extra area)",
line_no);
return (NULL);
}
get_line (buf, MAX_LOAD_LINE, from, 0);
if (sscanf (buf, "%d", &nsides) != 1)
{
g_warning ("[%d] Internal load error while loading spiral (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_warning ("[%d] Internal load error while loading spiral",
line_no);
return (NULL);
}
/* Go around and read the last line */
continue;
}
else
return (new_obj);
}
if (!new_obj)
new_obj = d_new_spiral (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
return (new_obj);
}
static void
d_draw_spiral (Dobject *obj)
@ -334,7 +270,7 @@ d_copy_spiral (Dobject *obj)
g_assert (obj->type == SPIRAL);
np = d_new_spiral (obj->points->pnt.x, obj->points->pnt.y);
np = d_new_object (SPIRAL, obj->points->pnt.x, obj->points->pnt.y);
np->points->next = d_copy_dobjpoints (obj->points->next);
np->type_data = obj->type_data;
@ -349,27 +285,8 @@ d_spiral_object_class_init ()
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)
{
Dobject *nobj;
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);
return nobj;
}
void
@ -424,7 +341,7 @@ void
d_spiral_start (GdkPoint *pnt,
gint shift_down)
{
obj_creating = d_new_spiral (pnt->x, pnt->y);
obj_creating = d_new_object (SPIRAL, pnt->x, pnt->y);
obj_creating->type_data = spiral_num_turns * ((spiral_toggle == 0) ? 1 : -1);
}

View file

@ -34,7 +34,6 @@ void d_update_spiral (GdkPoint *pnt);
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__ */

View file

@ -35,17 +35,15 @@
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dobject.h"
#include "libgimp/stdplugins-intl.h"
static gint star_num_sides = 3; /* Default to three sided object */
static void d_save_star (Dobject * obj,
GString * string);
static void d_draw_star (Dobject *obj);
static void d_paint_star (Dobject *obj);
static Dobject *d_copy_star (Dobject * obj);
static Dobject *d_new_star (gint x, gint y);
gboolean
star_button_press (GtkWidget *widget,
@ -59,68 +57,6 @@ star_button_press (GtkWidget *widget,
return FALSE;
}
static void
d_save_star (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_star (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_warning ("[%d] Internal load error while loading star (extra area)",
line_no);
return (NULL);
}
get_line (buf, MAX_LOAD_LINE, from, 0);
if (sscanf (buf, "%d", &nsides) != 1)
{
g_warning ("[%d] Internal load error while loading star (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_warning ("[%d] Internal load error while loading star",
line_no);
return NULL;
}
/* Go around and read the last line */
continue;
}
else
return new_obj;
}
if (!new_obj)
new_obj = d_new_star (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
return new_obj;
}
static void
d_draw_star (Dobject *obj)
{
@ -382,7 +318,7 @@ d_copy_star (Dobject *obj)
g_assert (obj->type == STAR);
np = d_new_star (obj->points->pnt.x, obj->points->pnt.y);
np = d_new_object (STAR, obj->points->pnt.x, obj->points->pnt.y);
np->points->next = d_copy_dobjpoints (obj->points->next);
np->type_data = obj->type_data;
@ -397,27 +333,8 @@ d_star_object_class_init ()
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)
{
Dobject *nobj;
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);
return nobj;
}
void
@ -483,7 +400,7 @@ void
d_star_start (GdkPoint *pnt,
gint shift_down)
{
obj_creating = d_new_star (pnt->x, pnt->y);
obj_creating = d_new_object (STAR, pnt->x, pnt->y);
obj_creating->type_data = star_num_sides;
}

View file

@ -34,7 +34,6 @@ void d_update_star (GdkPoint *pnt);
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__ */

View file

@ -141,7 +141,7 @@ gfig_read_parameter_double (gchar **text,
ptr++;
if (!strcmp (tmpstr, name))
{
*style_entry = g_strtod (g_strchug (ptr), &endptr);
*style_entry = g_ascii_strtod (g_strchug (ptr), &endptr);
g_free (tmpstr);
return;
}
@ -160,6 +160,11 @@ gfig_read_parameter_gimp_rgb (gchar **text,
gint n = 0;
gchar *ptr;
gchar *tmpstr;
gchar *endptr;
gchar colorstr_r[G_ASCII_DTOSTR_BUF_SIZE];
gchar colorstr_g[G_ASCII_DTOSTR_BUF_SIZE];
gchar colorstr_b[G_ASCII_DTOSTR_BUF_SIZE];
gchar colorstr_a[G_ASCII_DTOSTR_BUF_SIZE];
style_entry->r = style_entry->g = style_entry->b = style_entry->a = 0.;
@ -172,8 +177,11 @@ gfig_read_parameter_gimp_rgb (gchar **text,
ptr++;
if (!strcmp (tmpstr, name))
{
sscanf (ptr, "%lf %lf %lf %lf", &style_entry->r, &style_entry->g,
&style_entry->b, &style_entry->a);
sscanf (ptr, "%s %s %s %s", colorstr_r, colorstr_g, colorstr_b, colorstr_a);
style_entry->r = g_ascii_strtod (colorstr_r, &endptr);
style_entry->g = g_ascii_strtod (colorstr_g, &endptr);
style_entry->b = g_ascii_strtod (colorstr_b, &endptr);
style_entry->a = g_ascii_strtod (colorstr_a, &endptr);
g_free (tmpstr);
return;
}
@ -308,6 +316,12 @@ void
gfig_save_style (Style *style,
GString *string)
{
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, brush name '%s'\n", style->name, style->brush_name);
@ -322,12 +336,18 @@ gfig_save_style (Style *style,
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: %lg %lg %lg %lg\n", style->foreground.r,
style->foreground.g, style->foreground.b, style->foreground.a);
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: %lg %lg %lg %lg\n", style->background.r,
style->background.g, style->background.b, style->background.a);
g_string_append_printf (string, "BackgroundSource: %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");
}

View file

@ -385,23 +385,6 @@ gfig_new (void)
return g_new0 (GFigObj, 1);
}
static gboolean
match_element (gchar *buf,
gchar *element_name)
{
gchar *ptr = buf;
if (* ptr != '<')
return FALSE;
ptr++;
if (ptr == strstr (ptr, element_name))
return TRUE;
return FALSE;
}
static void
gfig_load_objs (GFigObj *gfig,
gint load_count,
@ -422,42 +405,7 @@ gfig_load_objs (GFigObj *gfig,
offset = ftell (fp);
gfig_skip_style (&style, fp);
if (match_element (load_buf, "Line"))
{
obj = d_load_line (fp);
}
else if (match_element (load_buf, "Circle"))
{
obj = d_load_circle (fp);
}
else if (match_element (load_buf, "Ellipse"))
{
obj = d_load_ellipse (fp);
}
else if (match_element (load_buf, "Poly"))
{
obj = d_load_poly (fp);
}
else if (match_element (load_buf, "Star"))
{
obj = d_load_star (fp);
}
else if (match_element (load_buf, "Spiral"))
{
obj = d_load_spiral (fp);
}
else if (match_element (load_buf, "Bezier"))
{
obj = d_load_bezier (fp);
}
else if (match_element (load_buf, "Arc"))
{
obj = d_load_arc (fp);
}
else
{
g_warning ("Unknown obj type file %s line %d\n", gfig->filename, line_no);
}
obj = d_load_object (load_buf, fp);
if (obj)
{
@ -467,6 +415,10 @@ gfig_load_objs (GFigObj *gfig,
gfig_load_style (&obj->style, fp);
fseek (fp, offset2, SEEK_SET);
}
else
{
g_message ("Failed to load object, load count = %d", load_count);
}
}
}
@ -779,9 +731,7 @@ gfig_save_as_string ()
gfig_save_style (&objs->obj->style, string);
if (objs->obj->points)
{
objs->obj->class->savefunc (objs->obj, string);
}
d_save_object (objs->obj, string);
gfig_save_obj_end (objs->obj, string);
}

View file

@ -160,7 +160,8 @@ typedef struct
typedef enum
{
LINE = 0,
OBJ_TYPE_NONE = 0,
LINE,
CIRCLE,
ELLIPSE,
ARC,
@ -168,6 +169,7 @@ typedef enum
STAR,
SPIRAL,
BEZIER,
NUM_OBJ_TYPES,
MOVE_OBJ,
MOVE_POINT,
COPY_OBJ,
@ -190,9 +192,6 @@ typedef struct
DobjFunc drawfunc; /* How do I draw myself */
DobjFunc paintfunc; /* Draw me on canvas */
DobjGenFunc copyfunc; /* copy */
DobjLoadFunc loadfunc; /* Load this type of object */
DobjSaveFunc savefunc; /* Save me out */
DobjCreateFunc createfunc; /* create a new one */
} DobjClass;
DobjClass dobj_class[10];