* plug-ins/gfig/gfig-dialog.[ch]:
	* plug-ins/gfig/gfig-style.[ch]:
	* plug-ins/gfig/notes.txt:       New files.
	* plug-ins/gfig/*.[ch]:  Complete reworking of the gfig plug-in.
	See 'notes.txt' for a summary of what has changed, and how to use
	it now.  Plenty of bugs have been  introduced, which will take a
	while to straighten out.
This commit is contained in:
William Skaggs
2004-07-04 20:50:25 +00:00
parent ffa1d155c8
commit 0fd3c264d7
32 changed files with 4530 additions and 5315 deletions

View File

@ -1,3 +1,13 @@
2004-07-04 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/gfig/gfig-dialog.[ch]:
* plug-ins/gfig/gfig-style.[ch]:
* plug-ins/gfig/notes.txt: New files.
* plug-ins/gfig/*.[ch]: Complete reworking of the gfig plug-in.
See 'notes.txt' for a summary of what has changed, and how to use
it now. Plenty of bugs have been introduced, which will take a
while to straighten out.
2004-07-04 Tor Lillqvist <tml@iki.fi>
* app/core/gimpdrawable-equalize.c (gimp_drawable_equalize): Drop

View File

@ -12,7 +12,7 @@ endif
AM_LDFLAGS = $(mwindows)
SUBDIRS = gfig-examples images
SUBDIRS = images
libexecdir = $(gimpplugindir)/plug-ins
@ -27,6 +27,8 @@ gfig_SOURCES = \
gfig-bezier.h \
gfig-circle.c \
gfig-circle.h \
gfig-dialog.c \
gfig-dialog.h \
gfig-dobject.c \
gfig-dobject.h \
gfig-ellipse.c \
@ -45,6 +47,8 @@ gfig_SOURCES = \
gfig-star.h \
gfig-stock.c \
gfig-stock.h \
gfig-style.c \
gfig-style.h \
pix-data.h
EXTRA_DIST = README

View File

@ -58,11 +58,11 @@ dist (gdouble x1,
/* Mid point of line returned */
static void
mid_point (gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gdouble *mx,
gdouble *my)
gdouble y1,
gdouble x2,
gdouble y2,
gdouble *mx,
gdouble *my)
{
*mx = (x1 + x2) / 2.0;
*my = (y1 + y2) / 2.0;
@ -71,9 +71,9 @@ mid_point (gdouble x1,
/* Careful about infinite grads */
static gdouble
line_grad (gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2)
gdouble y1,
gdouble x2,
gdouble y2)
{
double dx, dy;
@ -86,8 +86,8 @@ line_grad (gdouble x1,
/* Constant of line that goes through x, y with grad lgrad */
static gdouble
line_cons (gdouble x,
gdouble y,
gdouble lgrad)
gdouble y,
gdouble lgrad)
{
return y - lgrad * x;
}
@ -95,11 +95,11 @@ line_cons (gdouble x,
/*Get grad & const for perpend. line to given points */
static void
line_definition (gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gdouble *lgrad,
gdouble *lconst)
gdouble y1,
gdouble x2,
gdouble y2,
gdouble *lgrad,
gdouble *lconst)
{
double grad1;
double midx, midy;
@ -130,10 +130,10 @@ line_definition (gdouble x1,
static void
arc_details (GdkPoint *vert_a,
GdkPoint *vert_b,
GdkPoint *vert_c,
GdkPoint *center_pnt,
gdouble *radius)
GdkPoint *vert_b,
GdkPoint *vert_c,
GdkPoint *center_pnt,
gdouble *radius)
{
/* Only vertices are in whole numbers - everything else is in doubles */
double ax, ay;
@ -195,37 +195,37 @@ arc_details (GdkPoint *vert_a,
{
/* vert line -> mid point gives inter_x */
if (ax == bx && bx == cx)
{
/* Straight line */
double miny = ay;
double maxy = ay;
{
/* Straight line */
double miny = ay;
double maxy = ay;
if (by > maxy)
maxy = by;
if (by < miny)
miny = by;
if (by > maxy)
maxy = by;
if (by < miny)
miny = by;
if (cy > maxy)
maxy = cy;
if (cy > maxy)
maxy = cy;
if (cy < miny)
miny = cy;
if (cy < miny)
miny = cy;
inter_y = (maxy - miny)/2 + miny;
}
inter_y = (maxy - miny)/2 + miny;
}
else if (ax == bx)
{
inter_y = (ay - by)/2 + by;
}
{
inter_y = (ay - by)/2 + by;
}
else if (bx == cx)
{
inter_y = (by - cy)/2 + cy;
}
{
inter_y = (by - cy)/2 + cy;
}
else
{
inter_y = (cy - ay)/2 + ay;
}
{
inter_y = (cy - ay)/2 + ay;
}
got_y = 1;
}
@ -233,37 +233,37 @@ arc_details (GdkPoint *vert_a,
{
/* Horz line -> midpoint gives inter_y */
if (ax == bx && bx == cx)
{
/* Straight line */
double minx = ax;
double maxx = ax;
{
/* Straight line */
double minx = ax;
double maxx = ax;
if (bx > maxx)
maxx = bx;
if (bx < minx)
minx = bx;
if (bx > maxx)
maxx = bx;
if (bx < minx)
minx = bx;
if (cx > maxx)
maxx = cx;
if (cx > maxx)
maxx = cx;
if (cx < minx)
minx = cx;
if (cx < minx)
minx = cx;
inter_x = (maxx - minx)/2 + minx;
}
inter_x = (maxx - minx)/2 + minx;
}
else if (ay == by)
{
inter_x = (ax - bx)/2 + bx;
}
{
inter_x = (ax - bx)/2 + bx;
}
else if (by == cy)
{
inter_x = (bx - cx)/2 + cx;
}
{
inter_x = (bx - cx)/2 + cx;
}
else
{
inter_x = (cx - ax)/2 + ax;
}
{
inter_x = (cx - ax)/2 + ax;
}
got_x = 1;
}
@ -272,14 +272,14 @@ arc_details (GdkPoint *vert_a,
/* At least two of the lines are not parallel to the axis */
/*first line */
if (ax != bx && ay != by)
line_definition (ax, ay, bx, by, &line1_grad, &line1_const);
line_definition (ax, ay, bx, by, &line1_grad, &line1_const);
else
line_definition (ax, ay, cx, cy, &line1_grad, &line1_const);
line_definition (ax, ay, cx, cy, &line1_grad, &line1_const);
/* second line */
if (bx != cx && by != cy)
line_definition (bx, by, cx, cy, &line2_grad, &line2_const);
line_definition (bx, by, cx, cy, &line2_grad, &line2_const);
else
line_definition (ax, ay, cx, cy, &line2_grad, &line2_const);
line_definition (ax, ay, cx, cy, &line2_grad, &line2_const);
}
/* Intersection point */
@ -295,7 +295,7 @@ arc_details (GdkPoint *vert_a,
static gdouble
arc_angle (GdkPoint *pnt,
GdkPoint *center)
GdkPoint *center)
{
/* Get angle (in degress) of point given origin of center */
gint16 shift_x;
@ -314,11 +314,9 @@ arc_angle (GdkPoint *pnt,
static void
d_save_arc (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<ARC>\n");
do_save_obj (obj, to);
fprintf (to, "</ARC>\n");
do_save_obj (obj, string);
}
Dobject *
@ -333,25 +331,18 @@ d_load_arc (FILE *from)
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Must be the end */
if (strcmp ("</ARC>", buf) || num_pnts != 3)
{
g_warning ("[%d] Internal load error while loading arc",
line_no);
return NULL;
}
return new_obj;
}
{
return new_obj;
}
num_pnts++;
if (!new_obj)
new_obj = d_new_arc (xpnt, ypnt);
new_obj = d_new_arc (xpnt, ypnt);
else
{
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
{
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
}
g_warning ("[%d] Not enough points for arc", line_no);
return NULL;
@ -359,12 +350,12 @@ d_load_arc (FILE *from)
static void
arc_drawing_details (Dobject *obj,
gdouble *minang,
GdkPoint *center_pnt,
gdouble *arcang,
gdouble *radius,
gint draw_cnts,
gint do_scale)
gdouble *minang,
GdkPoint *center_pnt,
gdouble *arcang,
gdouble *radius,
gint draw_cnts,
gint do_scale)
{
DobjPoints * pnt1 = NULL;
DobjPoints * pnt2 = NULL;
@ -412,16 +403,16 @@ arc_drawing_details (Dobject *obj,
pnt3 = &dpnts[2];
for (j = 0 ; j < 3; j++)
{
xy[0] = dpnts[j].pnt.x;
xy[1] = dpnts[j].pnt.y;
if (selvals.scaletoimage)
scale_to_original_xy (&xy[0], 1);
else
scale_to_xy (&xy[0], 1);
dpnts[j].pnt.x = xy[0];
dpnts[j].pnt.y = xy[1];
}
{
xy[0] = dpnts[j].pnt.x;
xy[1] = dpnts[j].pnt.y;
if (selvals.scaletoimage)
scale_to_original_xy (&xy[0], 1);
else
scale_to_xy (&xy[0], 1);
dpnts[j].pnt.x = xy[0];
dpnts[j].pnt.y = xy[1];
}
}
arc_details (&pnt1->pnt, &pnt2->pnt, &pnt3->pnt, center_pnt, radius);
@ -460,7 +451,7 @@ d_draw_arc (Dobject * obj)
return;
arc_drawing_details (obj, &minang, &center_pnt, &arcang, &radius, TRUE,
FALSE);
FALSE);
gfig_draw_arc (center_pnt.x, center_pnt.y, radius, radius, minang, arcang);
}
@ -521,22 +512,22 @@ d_paint_arc (Dobject *obj)
/* Miss out duped pnts */
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
line_pnts[i++] = calc_pnt.x;
line_pnts[i++] = calc_pnt.y;
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
/* Reverse line if approp */
@ -547,24 +538,24 @@ d_paint_arc (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
if (selopt.as_pie)
{
/* Add center point - cause a pie like selection... */
line_pnts[i++] = center_pnt.x;
line_pnts[i++] = center_pnt.y;
}
{
/* Add center point - cause a pie like selection... */
line_pnts[i++] = center_pnt.x;
line_pnts[i++] = center_pnt.y;
}
gimp_free_select (gfig_image,
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);
}
g_free (line_pnts);
@ -585,7 +576,7 @@ d_copy_arc (Dobject * obj)
static Dobject *
d_new_arc (gint x,
gint y)
gint y)
{
Dobject *nobj;
@ -629,7 +620,7 @@ d_update_arc (GdkPoint *pnt)
void
d_arc_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* Draw lines to start with -- then convert to an arc */
if (!tmp_line)
@ -639,7 +630,7 @@ d_arc_start (GdkPoint *pnt,
void
d_arc_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* Under contrl point */
if (!tmp_line ||
@ -663,15 +654,15 @@ d_arc_end (GdkPoint *pnt,
d_line_end (pnt, FALSE);
/*d_draw_line (newarc); Should undraw line */
if (need_to_scale)
{
selvals.scaletoimage = 0;
}
{
selvals.scaletoimage = 0;
}
/*d_draw_arc (newarc);*/
gtk_widget_queue_draw (gfig_preview);
gtk_widget_queue_draw (gfig_context->preview);
if (need_to_scale)
{
selvals.scaletoimage = 1;
}
{
selvals.scaletoimage = 1;
}
}
}

View File

@ -30,8 +30,8 @@ Dobject *d_load_arc (FILE *from);
void d_update_arc (GdkPoint *pnt);
void d_arc_start (GdkPoint *pnt,
gint shift_down);
gint shift_down);
void d_arc_end (GdkPoint *pnt,
gint shift_down);
gint shift_down);
#endif /* __GFIG_ARC_H__ */

View File

@ -40,7 +40,7 @@
static gint bezier_closed = 0; /* Closed curve 0 = false 1 = true */
static gint bezier_line_frame = 0; /* Show frame = false 1 = true */
Dobject *tmp_bezier; /* Needed when drawing bezier curves */
Dobject *tmp_bezier; /* Needed when drawing bezier curves */
static void d_paint_bezier (Dobject *obj);
static Dobject * d_copy_bezier (Dobject * obj);
@ -48,13 +48,11 @@ static Dobject * d_new_bezier (gint x, gint y);
static void
d_save_bezier (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<BEZIER>\n");
do_save_obj (obj, to);
fprintf (to, "<EXTRA>\n");
fprintf (to, "%d\n</EXTRA>\n", obj->type_data);
fprintf (to, "</BEZIER>\n");
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 *
@ -68,49 +66,44 @@ d_load_bezier (FILE *from)
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 if (strcmp ("</BEZIER>", buf))
{
g_message ("[%d] Internal load error while loading bezier",
line_no);
return NULL;
}
return new_obj;
}
{
/* 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);
new_obj = d_new_bezier (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
@ -132,9 +125,9 @@ fp_pnt_start (void)
/* Add a line segment to collection array */
static void
fp_pnt_add (gdouble p1,
gdouble p2,
gdouble p3,
gdouble p4)
gdouble p2,
gdouble p3,
gdouble p4)
{
if (!fp_pnt_pnts)
{
@ -147,8 +140,8 @@ fp_pnt_add (gdouble p1,
/* more space pls */
fp_pnt_chunk++;
fp_pnt_pnts =
(gdouble *) g_realloc (fp_pnt_pnts,
sizeof (gdouble) * fp_pnt_chunk * FP_PNT_MAX);
(gdouble *) g_realloc (fp_pnt_pnts,
sizeof (gdouble) * fp_pnt_chunk * FP_PNT_MAX);
}
fp_pnt_pnts[fp_pnt_cnt++] = p1;
@ -188,9 +181,9 @@ typedef gdouble (*fp_pnt)[2];
static void
DrawBezier (gdouble (*points)[2],
gint np,
gdouble mid,
gint depth)
gint np,
gdouble mid,
gint depth)
{
gint i, j, x0 = 0, y0 = 0, x1, y1;
fp_pnt left;
@ -198,48 +191,48 @@ DrawBezier (gdouble (*points)[2],
if (depth == 0) /* draw polyline */
{
for (i = 0; i < np; i++)
{
x1 = (int) points[i][0];
y1 = (int) points[i][1];
if (i > 0 && (x1 != x0 || y1 != y0))
{
/* Add pnts up */
fp_pnt_add ((gdouble) x0, (gdouble) y0,
(gdouble) x1, (gdouble) y1);
}
x0 = x1;
y0 = y1;
}
for (i = 0; i < np; i++)
{
x1 = (int) points[i][0];
y1 = (int) points[i][1];
if (i > 0 && (x1 != x0 || y1 != y0))
{
/* Add pnts up */
fp_pnt_add ((gdouble) x0, (gdouble) y0,
(gdouble) x1, (gdouble) y1);
}
x0 = x1;
y0 = y1;
}
}
else /* subdivide control points at mid */
{
left = (fp_pnt) g_new (gdouble, np * 2);
right = (fp_pnt) g_new (gdouble, np * 2);
for (i = 0; i < np; i++)
{
right[i][0] = points[i][0];
right[i][1] = points[i][1];
}
left[0][0] = right[0][0];
left[0][1] = right[0][1];
for (j = np - 1; j >= 1; j--)
{
for (i = 0; i < j; i++)
{
right[i][0] = (1 - mid) * right[i][0] + mid * right[i + 1][0];
right[i][1] = (1 - mid) * right[i][1] + mid * right[i + 1][1];
}
left[np - j][0] = right[0][0];
left[np - j][1] = right[0][1];
}
if (depth > 0)
{
DrawBezier (left, np, mid, depth - 1);
DrawBezier (right, np, mid, depth - 1);
g_free (left);
g_free (right);
}
left = (fp_pnt) g_new (gdouble, np * 2);
right = (fp_pnt) g_new (gdouble, np * 2);
for (i = 0; i < np; i++)
{
right[i][0] = points[i][0];
right[i][1] = points[i][1];
}
left[0][0] = right[0][0];
left[0][1] = right[0][1];
for (j = np - 1; j >= 1; j--)
{
for (i = 0; i < j; i++)
{
right[i][0] = (1 - mid) * right[i][0] + mid * right[i + 1][0];
right[i][1] = (1 - mid) * right[i][1] + mid * right[i + 1][1];
}
left[np - j][0] = right[0][0];
left[np - j][1] = right[0][1];
}
if (depth > 0)
{
DrawBezier (left, np, mid, depth - 1);
DrawBezier (right, np, mid, depth - 1);
g_free (left);
g_free (right);
}
}
}
@ -272,7 +265,7 @@ d_draw_bezier (Dobject *obj)
/* Generate an array of doubles which are the control points */
if (!drawing_pic && bezier_line_frame && tmp_bezier)
if (bezier_line_frame && tmp_bezier)
{
fp_pnt_start ();
DrawBezier (line_pnts, seg_count, 0.5, 0);
@ -330,17 +323,17 @@ d_paint_bezier (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_image,
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);
}
g_free (bz_line_pnts);
@ -401,9 +394,9 @@ d_update_bezier (GdkPoint *pnt)
{
/* Undraw */
while (l_pnt->next)
{
l_pnt = l_pnt->next;
}
{
l_pnt = l_pnt->next;
}
draw_circle (&l_pnt->pnt);
selvals.opts.showcontrol = 0;
@ -456,38 +449,38 @@ d_bezier_end (GdkPoint *pnt, gint shift_down)
{
/* Undraw circle on last pnt */
while (l_pnt->next)
{
l_pnt = l_pnt->next;
}
{
l_pnt = l_pnt->next;
}
if (l_pnt)
{
draw_circle (&l_pnt->pnt);
draw_sqr (&l_pnt->pnt);
{
draw_circle (&l_pnt->pnt);
draw_sqr (&l_pnt->pnt);
if (bezier_closed)
{
gint tmp_frame = bezier_line_frame;
/* if closed then add first point */
d_draw_bezier (tmp_bezier);
d_pnt_add_line (tmp_bezier,
tmp_bezier->points->pnt.x,
tmp_bezier->points->pnt.y,-1);
/* Final has no frame */
bezier_line_frame = 0; /* False */
d_draw_bezier (tmp_bezier);
bezier_line_frame = tmp_frame; /* What is was */
}
else if (bezier_line_frame)
{
d_draw_bezier (tmp_bezier);
bezier_line_frame = 0; /* False */
d_draw_bezier (tmp_bezier);
bezier_line_frame = 1; /* What is was */
}
if (bezier_closed)
{
gint tmp_frame = bezier_line_frame;
/* if closed then add first point */
d_draw_bezier (tmp_bezier);
d_pnt_add_line (tmp_bezier,
tmp_bezier->points->pnt.x,
tmp_bezier->points->pnt.y,-1);
/* Final has no frame */
bezier_line_frame = 0; /* False */
d_draw_bezier (tmp_bezier);
bezier_line_frame = tmp_frame; /* What is was */
}
else if (bezier_line_frame)
{
d_draw_bezier (tmp_bezier);
bezier_line_frame = 0; /* False */
d_draw_bezier (tmp_bezier);
bezier_line_frame = 1; /* What is was */
}
add_to_all_obj (current_obj, obj_creating);
}
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
/* small mem leak if !l_pnt ? */
tmp_bezier = NULL;
@ -496,10 +489,10 @@ d_bezier_end (GdkPoint *pnt, gint shift_down)
else
{
if (!tmp_bezier->points->next)
{
draw_circle (&tmp_bezier->points->pnt);
draw_sqr (&tmp_bezier->points->pnt);
}
{
draw_circle (&tmp_bezier->points->pnt);
draw_sqr (&tmp_bezier->points->pnt);
}
d_draw_bezier (tmp_bezier);
d_pnt_add_line (tmp_bezier, pnt->x, pnt->y,-1);
@ -522,11 +515,11 @@ bezier_dialog (void)
window = gimp_dialog_new (_("Bezier Settings"), "gfig",
NULL, 0,
gimp_standard_help_func, HELP_ID,
gimp_standard_help_func, HELP_ID,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
NULL);
NULL);
g_signal_connect (window, "response",
G_CALLBACK (gtk_widget_destroy),
@ -538,7 +531,7 @@ bezier_dialog (void)
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox,
FALSE, FALSE, 0);
FALSE, FALSE, 0);
gtk_widget_show (vbox);
toggle = gtk_check_button_new_with_label (_("Closed"));
@ -546,7 +539,7 @@ bezier_dialog (void)
G_CALLBACK (gimp_toggle_button_update),
&bezier_closed);
gimp_help_set_help_data (toggle,
_("Close curve on completion"), NULL);
_("Close curve on completion"), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), bezier_closed);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle);
@ -556,8 +549,8 @@ bezier_dialog (void)
G_CALLBACK (gimp_toggle_button_update),
&bezier_line_frame);
gimp_help_set_help_data (toggle,
_("Draws lines between the control points. "
"Only during curve creation"), NULL);
_("Draws lines between the control points. "
"Only during curve creation"), NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), bezier_line_frame);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle);

View File

@ -35,6 +35,6 @@ 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 bezier_dialog (void);
void bezier_dialog (void);
#endif /* __GFIG_BEZIER_H__ */

View File

@ -43,11 +43,9 @@ static Dobject *d_new_circle (gint x, gint y);
static void
d_save_circle (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<CIRCLE>\n");
do_save_obj (obj, to);
fprintf (to, "</CIRCLE>\n");
do_save_obj (obj, string);
}
Dobject *
@ -60,24 +58,21 @@ d_load_circle (FILE *from)
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
/* kludge */
if (buf[0] == '<')
return new_obj;
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Must be the end */
if (strcmp ("</CIRCLE>", buf))
{
g_warning ("[%d] Internal load error while loading circle",
line_no);
return NULL;
}
return new_obj;
}
{
g_warning ("[%d] Internal load error while loading circle",
line_no);
return NULL;
}
if (!new_obj)
new_obj = d_new_circle (xpnt, ypnt);
new_obj = d_new_circle (xpnt, ypnt);
else
{
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
g_warning ("[%d] Not enough points for circle", line_no);
@ -164,21 +159,21 @@ d_paint_circle (Dobject *obj)
else
scale_to_xy (&dpnts[0], 2);
gimp_ellipse_select (gfig_image,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
gimp_ellipse_select (gfig_context->image_id,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
/* Is selection all we need ? */
if (selvals.painttype == PAINT_SELECTION_TYPE)
return;
gimp_edit_stroke (gfig_drawable);
gimp_edit_stroke (gfig_context->drawable_id);
gimp_selection_clear (gfig_image);
gimp_selection_clear (gfig_context->image_id);
}
static Dobject*
@ -196,7 +191,7 @@ d_copy_circle (Dobject * obj)
static Dobject *
d_new_circle (gint x,
gint y)
gint y)
{
Dobject *nobj;
@ -231,15 +226,15 @@ d_update_circle (GdkPoint *pnt)
draw_circle (&edge_pnt->pnt);
radius = calc_radius (&center_pnt->pnt, &edge_pnt->pnt);
gdk_draw_arc (gfig_preview->window,
gfig_gc,
0,
center_pnt->pnt.x - (gint) RINT (radius),
center_pnt->pnt.y - (gint) RINT (radius),
(gint) RINT (radius) * 2,
(gint) RINT (radius) * 2,
0,
360 * 64);
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
center_pnt->pnt.x - (gint) RINT (radius),
center_pnt->pnt.y - (gint) RINT (radius),
(gint) RINT (radius) * 2,
(gint) RINT (radius) * 2,
0,
360 * 64);
}
draw_circle (pnt);
@ -247,29 +242,29 @@ d_update_circle (GdkPoint *pnt)
edge_pnt = new_dobjpoint (pnt->x, pnt->y);
radius = calc_radius (&center_pnt->pnt, &edge_pnt->pnt);
gdk_draw_arc (gfig_preview->window,
gfig_gc,
0,
center_pnt->pnt.x - (gint) RINT (radius),
center_pnt->pnt.y - (gint) RINT (radius),
(gint) RINT (radius) * 2,
(gint) RINT (radius) * 2,
0,
360 * 64);
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
center_pnt->pnt.x - (gint) RINT (radius),
center_pnt->pnt.y - (gint) RINT (radius),
(gint) RINT (radius) * 2,
(gint) RINT (radius) * 2,
0,
360 * 64);
center_pnt->next = edge_pnt;
}
void
d_circle_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
obj_creating = d_new_circle (pnt->x, pnt->y);
}
void
d_circle_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* Under contrl point */
if (!obj_creating->points->next)
@ -280,7 +275,7 @@ d_circle_end (GdkPoint *pnt,
else
{
draw_circle (pnt);
add_to_all_obj (current_obj, obj_creating);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;

View File

@ -30,8 +30,8 @@ Dobject * d_load_circle (FILE *from);
void d_update_circle (GdkPoint *pnt);
void d_circle_start (GdkPoint *pnt,
gint shift_down);
gint shift_down);
void d_circle_end (GdkPoint *pnt,
gint shift_down);
gint shift_down);
#endif /* __GFIG_CIRCLE_H__ */

1975
plug-ins/gfig/gfig-dialog.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Generates images containing vector type drawings.
*
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GFIG_DIALOG_H__
#define __GFIG_DIALOG_H__
#define RESPONSE_UNDO 1
#define RESPONSE_CLEAR 2
#define RESPONSE_SAVE 3
#define RESPONSE_PAINT 4
gint gfig_dialog (void);
void update_options (GFigObj *old_obj);
gint undo_water_mark; /* Last slot filled in -1 = no undo */
DAllObjs *undo_table[MAX_UNDO];
#endif /* __GFIG_DIALOG_H__ */

View File

@ -26,10 +26,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "gfig.h"
#include "gfig-dialog.h"
#include "gfig-style.h"
#include "gfig-arc.h"
#include "gfig-bezier.h"
#include "gfig-circle.h"
@ -45,16 +54,16 @@
static Dobject *operation_obj;
static GdkPoint *move_all_pnt; /* Point moving all from */
static void draw_one_obj (Dobject *obj);
static void do_move_obj (Dobject *obj,
GdkPoint *to_pnt);
static void do_move_all_obj (GdkPoint *to_pnt);
static void do_move_obj_pnt (Dobject *obj,
GdkPoint *to_pnt);
static void remove_obj_from_list (GFigObj *obj,
Dobject *del_obj);
static gint scan_obj_points (DobjPoints *opnt,
GdkPoint *pnt);
static void draw_one_obj (Dobject *obj);
static void do_move_obj (Dobject *obj,
GdkPoint *to_pnt);
static void do_move_all_obj (GdkPoint *to_pnt);
static void do_move_obj_pnt (Dobject *obj,
GdkPoint *to_pnt);
static void remove_obj_from_list (GFigObj *obj,
Dobject *del_obj);
static gint scan_obj_points (DobjPoints *opnt,
GdkPoint *pnt);
/* Delete a list of points */
void
@ -95,14 +104,14 @@ d_copy_dobjpoints (DobjPoints *pnts)
newpnt = new_dobjpoint (pnt2copy->pnt.x, pnt2copy->pnt.y);
if (!ret)
{
head = ret = newpnt;
}
{
head = ret = newpnt;
}
else
{
head->next = newpnt;
head = newpnt;
}
{
head->next = newpnt;
head = newpnt;
}
}
return ret;
@ -110,9 +119,9 @@ d_copy_dobjpoints (DobjPoints *pnts)
static DobjPoints *
get_diffs (Dobject *obj,
gint *xdiff,
gint *ydiff,
GdkPoint *to_pnt)
gint *xdiff,
gint *ydiff,
GdkPoint *to_pnt)
{
DobjPoints *spnt;
@ -121,18 +130,18 @@ get_diffs (Dobject *obj,
for (spnt = obj->points; spnt; spnt = spnt->next)
{
if (spnt->found_me)
{
*xdiff = spnt->pnt.x - to_pnt->x;
*ydiff = spnt->pnt.y - to_pnt->y;
return spnt;
}
{
*xdiff = spnt->pnt.x - to_pnt->x;
*ydiff = spnt->pnt.y - to_pnt->y;
return spnt;
}
}
return NULL;
}
static gboolean
inside_sqr (GdkPoint *cpnt,
GdkPoint *testpnt)
GdkPoint *testpnt)
{
/* Return TRUE if testpnt is near cpnt */
gint x = cpnt->x;
@ -145,15 +154,15 @@ inside_sqr (GdkPoint *cpnt,
static gboolean
scan_obj_points (DobjPoints *opnt,
GdkPoint *pnt)
GdkPoint *pnt)
{
while (opnt)
{
if (inside_sqr (&opnt->pnt, pnt))
{
opnt->found_me = TRUE;
return TRUE;
}
{
opnt->found_me = TRUE;
return TRUE;
}
opnt->found_me = FALSE;
opnt = opnt->next;
}
@ -162,7 +171,7 @@ scan_obj_points (DobjPoints *opnt,
static Dobject *
get_nearest_objs (GFigObj *obj,
GdkPoint *pnt)
GdkPoint *pnt)
{
/* Nearest object to given point or NULL */
DAllObjs *all;
@ -177,10 +186,10 @@ get_nearest_objs (GFigObj *obj,
test_obj = all->obj;
if (count == obj_show_single || obj_show_single == -1)
if (scan_obj_points (test_obj->points, pnt))
{
return test_obj;
}
if (scan_obj_points (test_obj->points, pnt))
{
return test_obj;
}
count++;
}
return NULL;
@ -188,12 +197,12 @@ get_nearest_objs (GFigObj *obj,
void
object_operation_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
Dobject *new_obj;
/* Find point in given object list */
operation_obj = get_nearest_objs (current_obj, pnt);
operation_obj = get_nearest_objs (gfig_context->current_obj, pnt);
/* Special case if shift down && move obj then moving all objs */
@ -214,38 +223,38 @@ object_operation_start (GdkPoint *pnt,
{
case MOVE_OBJ:
if (operation_obj->type == BEZIER)
{
d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
d_draw_bezier (operation_obj);
}
{
d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
d_draw_bezier (operation_obj);
}
break;
case MOVE_POINT:
if (operation_obj->type == BEZIER)
{
d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
d_draw_bezier (operation_obj);
}
{
d_draw_bezier (operation_obj);
tmp_bezier = operation_obj;
d_draw_bezier (operation_obj);
}
/* If shift is down the break into sep lines */
if ((operation_obj->type == POLY
|| operation_obj->type == STAR)
&& shift_down)
{
switch (operation_obj->type)
{
case POLY:
d_poly2lines (operation_obj);
break;
case STAR:
d_star2lines (operation_obj);
break;
default:
break;
}
/* Re calc which object point we are lookin at */
scan_obj_points (operation_obj->points, pnt);
}
|| operation_obj->type == STAR)
&& shift_down)
{
switch (operation_obj->type)
{
case POLY:
d_poly2lines (operation_obj);
break;
case STAR:
d_star2lines (operation_obj);
break;
default:
break;
}
/* Re calc which object point we are lookin at */
scan_obj_points (operation_obj->points, pnt);
}
break;
case COPY_OBJ:
/* Copy the "operation object" */
@ -253,27 +262,29 @@ object_operation_start (GdkPoint *pnt,
new_obj = (Dobject*) operation_obj->copyfunc (operation_obj);
if (new_obj)
{
scan_obj_points (new_obj->points, pnt);
add_to_all_obj (current_obj, new_obj);
operation_obj = new_obj;
selvals.otype = MOVE_COPY_OBJ;
new_obj->drawfunc (new_obj);
}
{
gfig_style_copy (&new_obj->style, &operation_obj->style, "Object");
scan_obj_points (new_obj->points, 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);
}
break;
case DEL_OBJ:
remove_obj_from_list (current_obj, operation_obj);
remove_obj_from_list (gfig_context->current_obj, operation_obj);
break;
case MOVE_COPY_OBJ: /* Never when button down */
default:
g_warning ("Internal error selvals.otype object operation start");
break;
}
}
void
object_operation_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
if (selvals.otype != DEL_OBJ && operation_obj &&
operation_obj->type == BEZIER)
@ -283,6 +294,7 @@ object_operation_end (GdkPoint *pnt,
d_draw_bezier (operation_obj);
}
gfig_style_set_context_from_style (&operation_obj->style);
operation_obj = NULL;
if (move_all_pnt)
@ -299,7 +311,7 @@ object_operation_end (GdkPoint *pnt,
/* Move object around */
void
object_operation (GdkPoint *to_pnt,
gint shift_down)
gint shift_down)
{
/* Must do diffent things depending on object type */
/* but must have object to operate on! */
@ -319,41 +331,41 @@ object_operation (GdkPoint *to_pnt,
case MOVE_OBJ:
case MOVE_COPY_OBJ:
switch (operation_obj->type)
{
case LINE:
case CIRCLE:
case ELLIPSE:
case POLY:
case ARC:
case STAR:
case SPIRAL:
case BEZIER:
do_move_obj (operation_obj, to_pnt);
break;
default:
/* Internal error */
g_warning ("Internal error in operation_obj->type");
break;
}
{
case LINE:
case CIRCLE:
case ELLIPSE:
case POLY:
case ARC:
case STAR:
case SPIRAL:
case BEZIER:
do_move_obj (operation_obj, to_pnt);
break;
default:
/* Internal error */
g_warning ("Internal error in operation_obj->type");
break;
}
break;
case MOVE_POINT:
switch (operation_obj->type)
{
case LINE:
case CIRCLE:
case ELLIPSE:
case POLY:
case ARC:
case STAR:
case SPIRAL:
case BEZIER:
do_move_obj_pnt (operation_obj, to_pnt);
break;
default:
/* Internal error */
g_warning ("Internal error in operation_obj->type");
break;
}
{
case LINE:
case CIRCLE:
case ELLIPSE:
case POLY:
case ARC:
case STAR:
case SPIRAL:
case BEZIER:
do_move_obj_pnt (operation_obj, to_pnt);
break;
default:
/* Internal error */
g_warning ("Internal error in operation_obj->type");
break;
}
break;
case DEL_OBJ:
break;
@ -366,8 +378,8 @@ object_operation (GdkPoint *to_pnt,
static void
update_pnts (Dobject *obj,
gint xdiff,
gint ydiff)
gint xdiff,
gint ydiff)
{
DobjPoints *spnt;
@ -383,7 +395,7 @@ update_pnts (Dobject *obj,
static void
remove_obj_from_list (GFigObj *obj,
Dobject *del_obj)
Dobject *del_obj)
{
/* Nearest object to given point or NULL */
DAllObjs *all;
@ -396,27 +408,27 @@ remove_obj_from_list (GFigObj *obj,
while (all)
{
if (all->obj == del_obj)
{
/* Found the one to delete */
if (prev_all)
prev_all->next = all->next;
else
obj->obj_list = all->next;
{
/* Found the one to delete */
if (prev_all)
prev_all->next = all->next;
else
obj->obj_list = all->next;
/* Draw obj (which will actually undraw it! */
del_obj->drawfunc (del_obj);
/* Draw obj (which will actually undraw it! */
del_obj->drawfunc (del_obj);
free_one_obj (del_obj);
g_free (all);
free_one_obj (del_obj);
g_free (all);
if (obj_show_single != -1)
{
/* We've just deleted the only visible one */
draw_grid_clear ();
obj_show_single = -1; /* Show all again */
}
return;
}
if (obj_show_single != -1)
{
/* We've just deleted the only visible one */
draw_grid_clear ();
obj_show_single = -1; /* Show all again */
}
return;
}
prev_all = all;
all = all->next;
}
@ -435,37 +447,38 @@ do_move_all_obj (GdkPoint *to_pnt)
{
DAllObjs *all;
for (all = current_obj->obj_list; all; all = all->next)
{
Dobject *obj = all->obj;
/* undraw ! */
draw_one_obj (obj);
update_pnts (obj, xdiff, ydiff);
/* Draw in new pos */
draw_one_obj (obj);
}
for (all = gfig_context->current_obj->obj_list; all; all = all->next)
{
Dobject *obj = all->obj;
/* undraw ! */
draw_one_obj (obj);
update_pnts (obj, xdiff, ydiff);
/* Draw in new pos */
draw_one_obj (obj);
}
*move_all_pnt = *to_pnt;
}
}
void
do_save_obj (Dobject *obj, FILE *to)
do_save_obj (Dobject *obj,
GString *string)
{
DobjPoints *spnt;
for (spnt = obj->points; spnt; spnt = spnt->next)
{
fprintf (to, "%d %d\n", spnt->pnt.x, spnt->pnt.y);
g_string_append_printf (string, "%d %d\n", spnt->pnt.x, spnt->pnt.y);
}
}
static void
do_move_obj (Dobject *obj,
GdkPoint *to_pnt)
GdkPoint *to_pnt)
{
/* Move the whole line - undraw the line to start with */
/* Then draw in new pos */
@ -488,7 +501,7 @@ do_move_obj (Dobject *obj,
static void
do_move_obj_pnt (Dobject *obj,
GdkPoint *to_pnt)
GdkPoint *to_pnt)
{
/* Move the whole line - undraw the line to start with */
/* Then draw in new pos */
@ -524,14 +537,14 @@ copy_all_objs (DAllObjs *objs)
nobj = g_new0 (DAllObjs, 1);
if (!ret)
{
ret = new_all_objs = nobj;
}
{
ret = new_all_objs = nobj;
}
else
{
new_all_objs->next = nobj;
new_all_objs = nobj;
}
{
new_all_objs->next = nobj;
new_all_objs = nobj;
}
nobj->obj = (Dobject *) objs->obj->copyfunc (objs->obj);
@ -550,7 +563,7 @@ draw_one_obj (Dobject * obj)
void
draw_objects (DAllObjs *objs,
gint show_single)
gint show_single)
{
/* Show_single - only one object to draw Unless shift
* is down in which case show all.
@ -561,7 +574,7 @@ draw_objects (DAllObjs *objs,
while (objs)
{
if (!show_single || count == obj_show_single || obj_show_single == -1)
draw_one_obj (objs->obj);
draw_one_obj (objs->obj);
objs = objs->next;
count++;
@ -570,7 +583,7 @@ draw_objects (DAllObjs *objs,
void
prepend_to_all_obj (GFigObj *fobj,
DAllObjs *nobj)
DAllObjs *nobj)
{
DAllObjs *cobj;
@ -594,8 +607,8 @@ prepend_to_all_obj (GFigObj *fobj,
static void
scale_obj_points (DobjPoints *opnt,
gdouble scale_x,
gdouble scale_y)
gdouble scale_x,
gdouble scale_y)
{
while (opnt)
{
@ -607,7 +620,7 @@ scale_obj_points (DobjPoints *opnt,
void
add_to_all_obj (GFigObj *fobj,
Dobject *obj)
Dobject *obj)
{
DAllObjs *nobj;
@ -619,12 +632,17 @@ add_to_all_obj (GFigObj *fobj,
scale_obj_points (obj->points, scale_x_factor, scale_y_factor);
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 */
void
object_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* start for the current object */
if (!selvals.scaletoimage)
@ -642,7 +660,7 @@ object_start (GdkPoint *pnt,
case LINE:
/* Shift means we are still drawing */
if (!shift_down || !obj_creating)
draw_sqr (pnt);
draw_sqr (pnt);
d_line_start (pnt, shift_down);
break;
case CIRCLE:
@ -670,18 +688,25 @@ object_start (GdkPoint *pnt,
break;
case BEZIER:
if (!tmp_bezier)
draw_sqr (pnt);
draw_sqr (pnt);
d_bezier_start (pnt, shift_down);
break;
default:
/* Internal error */
break;
}
if (obj_creating)
{
gfig_style_set_style_from_context (&obj_creating->style);
gfig_context->current_style = &obj_creating->style;
}
}
void
object_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* end for the current object */
/* Add onto global object list */
@ -770,3 +795,177 @@ object_update (GdkPoint *pnt)
}
/* Stuff for the generation/deletion of objects. */
/* Objects are easy one they are created - you just go down the object
* list calling the draw function for each object but... when they
* are been created we have to be a little more careful. When
* the first point is placed on the canvas we create the object,
* the mouse position then defines the next point that can move around.
* careful how we draw this position.
*/
void
free_one_obj (Dobject *obj)
{
d_delete_dobjpoints (obj->points);
g_free (obj);
}
void
free_all_objs (DAllObjs * objs)
{
/* Free all objects */
DAllObjs * next;
while (objs)
{
free_one_obj (objs->obj);
next = objs->next;
g_free (objs);
objs = next;
}
}
gchar *
get_line (gchar *buf,
gint s,
FILE *from,
gint init)
{
gint slen;
char * ret;
if (init)
line_no = 1;
else
line_no++;
do
{
ret = fgets (buf, s, from);
} while (!ferror (from) && buf[0] == '#');
slen = strlen (buf);
/* The last newline is a pain */
if (slen > 0)
buf[slen - 1] = '\0';
if (ferror (from))
{
g_warning (_("Error reading file"));
return (0);
}
#ifdef DEBUG
printf ("Processing line '%s'\n", buf);
#endif /* DEBUG */
return (ret);
}
void
clear_undo (void)
{
int lv;
for (lv = undo_water_mark; lv >= 0; lv--)
{
free_all_objs (undo_table[lv]);
undo_table[lv] = NULL;
}
undo_water_mark = -1;
gtk_dialog_set_response_sensitive (GTK_DIALOG (top_level_dlg),
RESPONSE_UNDO, FALSE);
}
void
setup_undo (void)
{
/* Copy object list to undo buffer */
#if DEBUG
printf ("setup undo level [%d]\n", undo_water_mark);
#endif /*DEBUG*/
if (!gfig_context->current_obj)
{
/* If no current_obj must be loading -> no undo */
return;
}
if (undo_water_mark >= selvals.maxundo - 1)
{
int loop;
/* the little one in the bed said "roll over".. */
if (undo_table[0])
free_one_obj (undo_table[0]->obj);
for (loop = 0; loop < undo_water_mark; loop++)
{
undo_table[loop] = undo_table[loop + 1];
}
}
else
{
undo_water_mark++;
}
undo_table[undo_water_mark] = copy_all_objs (gfig_context->current_obj->obj_list);
gtk_dialog_set_response_sensitive (GTK_DIALOG (top_level_dlg),
RESPONSE_UNDO, TRUE);
gfig_context->current_obj->obj_status |= GFIG_MODIFIED;
}
void
new_obj_2edit (GFigObj *obj)
{
GFigObj *old_current = gfig_context->current_obj;
/* Clear undo levels */
/* redraw the preview */
/* Set up options as define in the selected object */
clear_undo ();
/* Point at this one */
gfig_context->current_obj = obj;
/* Show all objects to start with */
obj_show_single = -1;
/* Change options */
update_options (old_current);
/* 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)
{
g_message (_("Editing read-only object - "
"you will not be able to save it"));
gtk_dialog_set_response_sensitive (GTK_DIALOG (top_level_dlg),
RESPONSE_SAVE, FALSE);
}
else
{
gtk_dialog_set_response_sensitive (GTK_DIALOG (top_level_dlg),
RESPONSE_SAVE, TRUE);
}
}
gint
gfig_obj_counts (DAllObjs *objs)
{
gint count = 0;
for (; objs; objs = objs->next)
count++;
return count;
}

View File

@ -25,84 +25,10 @@
#ifndef __GFIG_DOBJECT_H__
#define __GFIG_DOBJECT_H__
struct Dobject; /* fwd declaration for DobjFunc */
typedef void (*DobjFunc) (struct Dobject *);
typedef struct Dobject *(*DobjGenFunc) (struct Dobject *);
typedef struct Dobject *(*DobjLoadFunc) (FILE *);
typedef void (*DobjSaveFunc) (struct Dobject *, FILE *);
typedef enum
{
LINE,
CIRCLE,
ELLIPSE,
ARC,
POLY,
STAR,
SPIRAL,
BEZIER,
MOVE_OBJ,
MOVE_POINT,
COPY_OBJ,
MOVE_COPY_OBJ,
DEL_OBJ,
NULL_OPER
} DobjType;
typedef struct DobjPoints
{
struct DobjPoints *next;
GdkPoint pnt;
gint found_me;
} DobjPoints;
/* The object itself */
typedef struct Dobject
{
DobjType type; /* What is the type? */
gint type_data; /* Extra data needed by the object */
DobjPoints *points; /* List of points */
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 */
} Dobject;
typedef struct DAllObjs
{
struct DAllObjs *next;
Dobject *obj; /* Object on list */
} DAllObjs;
/* States of the object */
#define GFIG_OK 0x0
#define GFIG_MODIFIED 0x1
#define GFIG_READONLY 0x2
extern Dobject *obj_creating;
void d_pnt_add_line (Dobject *obj,
gint x,
gint y,
gint pos);
DobjPoints *new_dobjpoint (gint x, gint y);
void do_save_obj (Dobject *obj, FILE *to);
DobjPoints *d_copy_dobjpoints (DobjPoints * pnts);
void free_one_obj (Dobject *obj);
void d_delete_dobjpoints (DobjPoints * pnts);
void object_update (GdkPoint *pnt);
DAllObjs *copy_all_objs (DAllObjs *objs);
void draw_objects (DAllObjs *objs, gint show_single);
void object_start (GdkPoint *pnt, gint);
void object_operation (GdkPoint *pnt, gint);
void object_operation_start (GdkPoint *pnt, gint shift_down);
void object_operation_end (GdkPoint *pnt, gint);
void object_end (GdkPoint *pnt, gint shift_down);
void free_all_objs (DAllObjs * objs);
void clear_undo (void);
void new_obj_2edit (GFigObj *obj);
gint gfig_obj_counts (DAllObjs * objs);
#endif /* __GFIG_DOBJECT_H__ */

View File

@ -44,11 +44,9 @@ static Dobject *d_new_ellipse (gint x, gint y);
static void
d_save_ellipse (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<ELLIPSE>\n");
do_save_obj (obj, to);
fprintf (to, "</ELLIPSE>\n");
do_save_obj (obj, string);
}
Dobject *
@ -61,24 +59,20 @@ d_load_ellipse (FILE *from)
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Must be the end */
if (strcmp ("</ELLIPSE>", buf))
{
g_message ("[%d] Internal load error while loading ellipse",
line_no);
return NULL;
}
return new_obj;
}
/* 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);
new_obj = d_new_ellipse (xpnt, ypnt);
else
{
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
new_obj->points->next = new_dobjpoint (xpnt, ypnt);
}
g_message ("[%d] Not enough points for ellipse", line_no);
@ -176,8 +170,8 @@ d_paint_approx_ellipse (Dobject *obj)
ang_loop = (gdouble)loop * ang_grid;
radius = (a_axis * b_axis /
(sqrt (cos (ang_loop) * cos (ang_loop) *
(b_axis * b_axis - a_axis * a_axis) + a_axis * a_axis)));
(sqrt (cos (ang_loop) * cos (ang_loop) *
(b_axis * b_axis - a_axis * a_axis) + a_axis * a_axis)));
lx = radius * cos (ang_loop);
ly = radius * sin (ang_loop);
@ -187,22 +181,22 @@ d_paint_approx_ellipse (Dobject *obj)
/* Miss out duped pnts */
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
line_pnts[i++] = calc_pnt.x;
line_pnts[i++] = calc_pnt.y;
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
line_pnts[i++] = first_pnt.x;
@ -222,17 +216,17 @@ d_paint_approx_ellipse (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_image,
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);
}
g_free (line_pnts);
@ -301,21 +295,21 @@ d_paint_ellipse (Dobject *obj)
scale_to_xy (&dpnts[0], 2);
gimp_ellipse_select (gfig_image,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
gimp_ellipse_select (gfig_context->image_id,
dpnts[0], dpnts[1],
dpnts[2], dpnts[3],
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
/* Is selection all we need ? */
if (selvals.painttype == PAINT_SELECTION_TYPE)
return;
gimp_edit_stroke (gfig_drawable);
gimp_edit_stroke (gfig_context->drawable_id);
gimp_selection_clear (gfig_image);
gimp_selection_clear (gfig_context->image_id);
}
static Dobject *
@ -372,26 +366,26 @@ d_update_ellipse (GdkPoint *pnt)
bound_wy = abs (center_pnt->pnt.y - edge_pnt->pnt.y)*2;
if (edge_pnt->pnt.x > center_pnt->pnt.x)
top_x = 2*center_pnt->pnt.x - edge_pnt->pnt.x;
top_x = 2*center_pnt->pnt.x - edge_pnt->pnt.x;
else
top_x = edge_pnt->pnt.x;
top_x = edge_pnt->pnt.x;
if (edge_pnt->pnt.y > center_pnt->pnt.y)
top_y = 2*center_pnt->pnt.y - edge_pnt->pnt.y;
top_y = 2*center_pnt->pnt.y - edge_pnt->pnt.y;
else
top_y = edge_pnt->pnt.y;
top_y = edge_pnt->pnt.y;
draw_circle (&edge_pnt->pnt);
gdk_draw_arc (gfig_preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360*64);
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360*64);
}
draw_circle (pnt);
@ -411,15 +405,15 @@ d_update_ellipse (GdkPoint *pnt)
else
top_y = edge_pnt->pnt.y;
gdk_draw_arc (gfig_preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360*64);
gdk_draw_arc (gfig_context->preview->window,
gfig_gc,
0,
top_x,
top_y,
bound_wx,
bound_wy,
0,
360*64);
center_pnt->next = edge_pnt;
}
@ -442,7 +436,7 @@ d_ellipse_end (GdkPoint *pnt, gint shift_down)
else
{
draw_circle (pnt);
add_to_all_obj (current_obj, obj_creating);
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;

View File

@ -47,9 +47,9 @@
static GdkGC *grid_hightlight_drawgc;
gint grid_gc_type = GTK_STATE_NORMAL;
static GdkGC *gfig_get_grid_gc (GtkWidget *widget,
gint gctype);
static gint get_num_radials (void);
static GdkGC *gfig_get_grid_gc (GtkWidget *widget,
gint gctype);
static gint get_num_radials (void);
/* find_grid_pos - Given an x, y point return the grid position of it */
/* return the new position in the passed point */
@ -85,19 +85,19 @@ gfig_grid_colours (GtkWidget *widget)
values.foreground.pixel = col2.pixel;
values.fill = GDK_OPAQUE_STIPPLED;
values.stipple = gdk_bitmap_create_from_data (widget->window,
(gchar *) stipple, 4, 4);
(gchar *) stipple, 4, 4);
grid_hightlight_drawgc = gdk_gc_new_with_values (widget->window,
&values,
GDK_GC_FOREGROUND |
GDK_GC_BACKGROUND |
GDK_GC_FILL |
GDK_GC_STIPPLE);
&values,
GDK_GC_FOREGROUND |
GDK_GC_BACKGROUND |
GDK_GC_FILL |
GDK_GC_STIPPLE);
}
void
find_grid_pos (GdkPoint *p,
GdkPoint *gp,
guint is_butt3)
GdkPoint *gp,
guint is_butt3)
{
gint16 x = p->x;
gint16 y = p->y;
@ -109,26 +109,26 @@ find_grid_pos (GdkPoint *p,
if (selvals.opts.gridtype == RECT_GRID)
{
if (p->x % selvals.opts.gridspacing > selvals.opts.gridspacing/2)
x += selvals.opts.gridspacing;
x += selvals.opts.gridspacing;
if (p->y % selvals.opts.gridspacing > selvals.opts.gridspacing/2)
y += selvals.opts.gridspacing;
y += selvals.opts.gridspacing;
gp->x = (x/selvals.opts.gridspacing)*selvals.opts.gridspacing;
gp->y = (y/selvals.opts.gridspacing)*selvals.opts.gridspacing;
if (is_butt3)
{
if (abs (gp->x - cons_pnt.x) < abs (gp->y - cons_pnt.y))
gp->x = cons_pnt.x;
else
gp->y = cons_pnt.y;
}
{
if (abs (gp->x - cons_pnt.x) < abs (gp->y - cons_pnt.y))
gp->x = cons_pnt.x;
else
gp->y = cons_pnt.y;
}
else
{
/* Store the point since might be used later */
cons_pnt = *gp; /* Structure copy */
}
{
/* Store the point since might be used later */
cons_pnt = *gp; /* Structure copy */
}
}
else if (selvals.opts.gridtype == POLAR_GRID)
{
@ -146,28 +146,28 @@ find_grid_pos (GdkPoint *p,
/* round radius */
rounded_radius = (gint)(RINT (ang_radius/selvals.opts.gridspacing))*selvals.opts.gridspacing;
if (rounded_radius <= 0 || real_radius <=0)
{
/* DEAD CENTER */
gp->x = preview_width/2;
gp->y = preview_height/2;
if (!is_butt3) cons_center = TRUE;
{
/* DEAD CENTER */
gp->x = preview_width/2;
gp->y = preview_height/2;
if (!is_butt3) cons_center = TRUE;
#ifdef DEBUG
printf ("Dead center\n");
printf ("Dead center\n");
#endif /* DEBUG */
return;
}
return;
}
ang_grid = 2*G_PI/get_num_radials ();
real_angle = atan2 (shift_y, shift_x);
if (real_angle < 0)
real_angle += 2*G_PI;
real_angle += 2*G_PI;
rounded_angle = (RINT ((real_angle/ang_grid)))*ang_grid;
#ifdef DEBUG
printf ("real_ang = %f ang_gid = %f rounded_angle = %f rounded radius = %d\n",
real_angle, ang_grid, rounded_angle, rounded_radius);
real_angle, ang_grid, rounded_angle, rounded_radius);
printf ("preview_width = %d preview_height = %d\n", preview_width, preview_height);
#endif /* DEBUG */
@ -176,27 +176,27 @@ find_grid_pos (GdkPoint *p,
gp->y = -(gint)RINT ((rounded_radius*sin (rounded_angle))) + preview_height/2;
if (is_butt3)
{
if (!cons_center)
{
if (fabs (rounded_angle - cons_ang) > ang_grid/2)
{
gp->x = (gint)RINT ((cons_radius*cos (rounded_angle))) + preview_width/2;
gp->y = -(gint)RINT ((cons_radius*sin (rounded_angle))) + preview_height/2;
}
else
{
gp->x = (gint)RINT ((rounded_radius*cos (cons_ang))) + preview_width/2;
gp->y = -(gint)RINT ((rounded_radius*sin (cons_ang))) + preview_height/2;
}
}
}
{
if (!cons_center)
{
if (fabs (rounded_angle - cons_ang) > ang_grid/2)
{
gp->x = (gint)RINT ((cons_radius*cos (rounded_angle))) + preview_width/2;
gp->y = -(gint)RINT ((cons_radius*sin (rounded_angle))) + preview_height/2;
}
else
{
gp->x = (gint)RINT ((rounded_radius*cos (cons_ang))) + preview_width/2;
gp->y = -(gint)RINT ((rounded_radius*sin (cons_ang))) + preview_height/2;
}
}
}
else
{
cons_radius = rounded_radius;
cons_ang = rounded_angle;
cons_center = FALSE;
}
{
cons_radius = rounded_radius;
cons_ang = rounded_angle;
cons_center = FALSE;
}
}
else if (selvals.opts.gridtype == ISO_GRID)
{
@ -269,11 +269,11 @@ find_grid_pos (GdkPoint *p,
m_hi_n_lo = m_lo_n_lo + 1;
/* figure out which is the better candidate */
if (abs((m_lo_n_lo * r + (0.5 * r * (n_lo % 2))) - y) <
abs((m_hi_n_lo * r + (0.5 * r * (n_lo % 2))) - y)) {
m_n_lo = m_lo_n_lo;
abs((m_hi_n_lo * r + (0.5 * r * (n_lo % 2))) - y)) {
m_n_lo = m_lo_n_lo;
}
else {
m_n_lo = m_hi_n_lo;
m_n_lo = m_hi_n_lo;
}
/* evaluate m candidates for n_hi */
@ -281,11 +281,11 @@ find_grid_pos (GdkPoint *p,
m_hi_n_hi = m_lo_n_hi + 1;
/* figure out which is the better candidate */
if (abs((m_lo_n_hi * r + (0.5 * r * (n_hi % 2))) - y) <
abs((m_hi_n_hi * r + (0.5 * r * (n_hi % 2))) - y)) {
m_n_hi = m_lo_n_hi;
abs((m_hi_n_hi * r + (0.5 * r * (n_hi % 2))) - y)) {
m_n_hi = m_lo_n_hi;
}
else {
m_n_hi = m_hi_n_hi;
m_n_hi = m_hi_n_hi;
}
/* Now, which is closer to [x,y]? we can use a somewhat abbreviated form of the
@ -297,13 +297,13 @@ find_grid_pos (GdkPoint *p,
y2 = (gint) (m_n_hi * r + (0.5 * r * (n_hi % 2)));
if (((x - x1) * (x - x1) + (y - y1) * (y - y1)) <
((x - x2) * (x - x2) + (y - y2) * (y - y2))) {
gp->x = x1;
gp->y = y1;
((x - x2) * (x - x2) + (y - y2) * (y - y2))) {
gp->x = x1;
gp->y = y1;
}
else {
gp->x = x2;
gp->y = y2;
gp->x = x2;
gp->y = y2;
}
}
@ -326,43 +326,43 @@ draw_grid_polar (GdkGC *drawgc)
step = selvals.opts.gridspacing;
max_rad = sqrt (preview_width * preview_width +
preview_height * preview_height) / 2;
preview_height * preview_height) / 2;
for (loop = 0; loop < max_rad; loop += step)
{
radius = loop;
gdk_draw_arc (gfig_preview->window,
drawgc,
0,
grid_x_center - radius,
grid_y_center - radius,
radius*2,
radius*2,
0,
360 * 64);
gdk_draw_arc (gfig_context->preview->window,
drawgc,
0,
grid_x_center - radius,
grid_y_center - radius,
radius*2,
radius*2,
0,
360 * 64);
}
/* Lines */
ang_grid = 2 * G_PI / get_num_radials ();
ang_radius = sqrt ((preview_width * preview_width) +
(preview_height * preview_height)) / 2;
(preview_height * preview_height)) / 2;
for (loop = 0; loop <= get_num_radials (); loop++)
{
gint lx, ly;
ang_loop = loop * ang_grid;
lx = RINT (ang_radius * cos (ang_loop));
ly = RINT (ang_radius * sin (ang_loop));
gdk_draw_line (gfig_preview->window,
drawgc,
lx + (preview_width) / 2,
- ly + (preview_height) / 2,
(preview_width) / 2,
(preview_height) / 2);
gdk_draw_line (gfig_context->preview->window,
drawgc,
lx + (preview_width) / 2,
- ly + (preview_height) / 2,
(preview_width) / 2,
(preview_height) / 2);
}
}
@ -377,24 +377,24 @@ draw_grid_sq (GdkGC *drawgc)
for (loop = 0 ; loop < preview_height ; loop += step)
{
gdk_draw_line (gfig_preview->window,
drawgc,
0,
loop,
preview_width,
loop);
gdk_draw_line (gfig_context->preview->window,
drawgc,
0,
loop,
preview_width,
loop);
}
/* Draw the vertical lines */
for (loop = 0 ; loop < preview_width ; loop += step)
{
gdk_draw_line (gfig_preview->window,
drawgc,
loop,
0,
loop,
preview_height);
gdk_draw_line (gfig_context->preview->window,
drawgc,
loop,
0,
loop,
preview_height);
}
}
@ -416,12 +416,12 @@ draw_grid_iso (GdkGC *drawgc)
/* Draw the vertical lines - These are easy */
for (loop = 0 ; loop < preview_width ; loop += hstep){
gdk_draw_line (gfig_preview->window,
drawgc,
(gint)loop,
(gint)0,
(gint)loop,
(gint)preview_height);
gdk_draw_line (gfig_context->preview->window,
drawgc,
(gint)loop,
(gint)0,
(gint)loop,
(gint)preview_height);
}
/* draw diag lines at a Theta of +/- 1/6 Pi Rad */
@ -437,19 +437,19 @@ draw_grid_iso (GdkGC *drawgc)
/* Draw diag lines */
for (loop = diagonal_start ; loop < diagonal_end ; loop += vstep)
{
gdk_draw_line (gfig_preview->window,
drawgc,
(gint)0,
(gint)loop,
(gint)diagonal_width,
(gint)loop + diagonal_height);
gdk_draw_line (gfig_context->preview->window,
drawgc,
(gint)0,
(gint)loop,
(gint)diagonal_width,
(gint)loop + diagonal_height);
gdk_draw_line (gfig_preview->window,
drawgc,
(gint)0,
(gint)loop,
(gint)diagonal_width,
(gint)loop - diagonal_height);
gdk_draw_line (gfig_context->preview->window,
drawgc,
(gint)0,
(gint)loop,
(gint)diagonal_width,
(gint)loop - diagonal_height);
}
}
@ -490,15 +490,14 @@ draw_grid (void)
*/
if ((preview_width < selvals.opts.gridspacing &&
preview_height < selvals.opts.gridspacing) ||
drawing_pic)
preview_height < selvals.opts.gridspacing))
{
/* Don't draw if they don't fit */
return;
}
if (selvals.opts.drawgrid)
drawgc = gfig_get_grid_gc (gfig_preview, grid_gc_type);
drawgc = gfig_get_grid_gc (gfig_context->preview, grid_gc_type);
else
return;

View File

@ -35,10 +35,10 @@
extern gint grid_gc_type;
void gfig_grid_colours (GtkWidget *widget);
void find_grid_pos (GdkPoint *p,
GdkPoint *gp,
guint state);
void draw_grid (void);
void gfig_grid_colours (GtkWidget *widget);
void find_grid_pos (GdkPoint *p,
GdkPoint *gp,
guint state);
void draw_grid (void);
#endif /* __GFIG_GRID_H__ */

View File

@ -42,11 +42,9 @@ static Dobject * d_new_line (gint x, gint y);
void
d_save_line (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<LINE>\n");
do_save_obj (obj, to);
fprintf (to, "</LINE>\n");
do_save_obj (obj, string);
}
Dobject *
@ -59,22 +57,21 @@ d_load_line (FILE *from)
while (get_line (buf, MAX_LOAD_LINE, from, 0))
{
/* kludge */
if (buf[0] == '<')
return new_obj;
if (sscanf (buf, "%d %d", &xpnt, &ypnt) != 2)
{
/* Must be the end */
if (strcmp ("</LINE>", buf))
{
g_warning ("[%d] Internal load error while loading line",
line_no);
return NULL;
}
return new_obj;
}
{
g_warning ("[%d] Internal load error while loading line",
line_no);
return NULL;
}
if (!new_obj)
new_obj = d_new_line (xpnt, ypnt);
new_obj = d_new_line (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
@ -154,17 +151,17 @@ d_paint_line (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
seg_count * 2, line_pnts);
gfig_context->drawable_id,
seg_count * 2, line_pnts);
}
else
{
gimp_free_select (gfig_image,
seg_count * 2, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
gimp_free_select (gfig_context->image_id,
seg_count * 2, line_pnts,
selopt.type,
selopt.antia,
selopt.feather,
selopt.feather_radius);
}
g_free (line_pnts);
@ -176,7 +173,7 @@ d_paint_line (Dobject *obj)
static Dobject *
d_new_line (gint x,
gint y)
gint y)
{
Dobject *nobj;
@ -213,9 +210,9 @@ d_delete_line (Dobject *obj)
void
d_pnt_add_line (Dobject *obj,
gint x,
gint y,
gint pos)
gint x,
gint y,
gint pos)
{
DobjPoints *npnts = new_dobjpoint (x, y);
@ -233,18 +230,18 @@ d_pnt_add_line (Dobject *obj,
/* Go down chain until the end if pos */
while (pos < 0 || pos-- > 0)
{
if (!(pnt->next) || !pos)
{
npnts->next = pnt->next;
pnt->next = npnts;
break;
}
else
{
pnt = pnt->next;
}
}
{
if (!(pnt->next) || !pos)
{
npnts->next = pnt->next;
pnt->next = npnts;
break;
}
else
{
pnt = pnt->next;
}
}
}
}
@ -270,13 +267,13 @@ d_update_line (GdkPoint *pnt)
/* Draw square on point */
draw_circle (&epnt->pnt);
gdk_draw_line (gfig_preview->window,
/*gfig_preview->style->bg_gc[GTK_STATE_NORMAL],*/
gfig_gc,
spnt->pnt.x,
spnt->pnt.y,
epnt->pnt.x,
epnt->pnt.y);
gdk_draw_line (gfig_context->preview->window,
/*gfig_context->preview->style->bg_gc[GTK_STATE_NORMAL],*/
gfig_gc,
spnt->pnt.x,
spnt->pnt.y,
epnt->pnt.x,
epnt->pnt.y);
g_free (epnt);
}
@ -286,19 +283,19 @@ d_update_line (GdkPoint *pnt)
epnt = new_dobjpoint (pnt->x, pnt->y);
gdk_draw_line (gfig_preview->window,
/*gfig_preview->style->bg_gc[GTK_STATE_NORMAL],*/
gfig_gc,
spnt->pnt.x,
spnt->pnt.y,
epnt->pnt.x,
epnt->pnt.y);
gdk_draw_line (gfig_context->preview->window,
/*gfig_context->preview->style->bg_gc[GTK_STATE_NORMAL],*/
gfig_gc,
spnt->pnt.x,
spnt->pnt.y,
epnt->pnt.x,
epnt->pnt.y);
spnt->next = epnt;
}
void
d_line_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
if (!obj_creating || !shift_down)
{
@ -315,7 +312,7 @@ d_line_start (GdkPoint *pnt,
void
d_line_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
/* Undraw the last circle */
draw_circle (pnt);
@ -323,49 +320,49 @@ d_line_end (GdkPoint *pnt,
if (shift_down)
{
if (tmp_line)
{
GdkPoint tmp_pnt = *pnt;
{
GdkPoint tmp_pnt = *pnt;
if (need_to_scale)
{
tmp_pnt.x = pnt->x * scale_x_factor;
tmp_pnt.y = pnt->y * scale_y_factor;
}
if (need_to_scale)
{
tmp_pnt.x = pnt->x * scale_x_factor;
tmp_pnt.y = pnt->y * scale_y_factor;
}
d_pnt_add_line (tmp_line, tmp_pnt.x, tmp_pnt.y, -1);
free_one_obj (obj_creating);
/* Must free obj_creating */
}
d_pnt_add_line (tmp_line, tmp_pnt.x, tmp_pnt.y, -1);
free_one_obj (obj_creating);
/* Must free obj_creating */
}
else
{
tmp_line = obj_creating;
add_to_all_obj (current_obj, obj_creating);
}
{
tmp_line = obj_creating;
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = d_new_line (pnt->x, pnt->y);
}
else
{
if (tmp_line)
{
GdkPoint tmp_pnt = *pnt;
{
GdkPoint tmp_pnt = *pnt;
if (need_to_scale)
{
tmp_pnt.x = pnt->x * scale_x_factor;
tmp_pnt.y = pnt->y * scale_y_factor;
}
if (need_to_scale)
{
tmp_pnt.x = pnt->x * scale_x_factor;
tmp_pnt.y = pnt->y * scale_y_factor;
}
d_pnt_add_line (tmp_line, tmp_pnt.x, tmp_pnt.y, -1);
free_one_obj (obj_creating);
/* Must free obj_creating */
}
d_pnt_add_line (tmp_line, tmp_pnt.x, tmp_pnt.y, -1);
free_one_obj (obj_creating);
/* Must free obj_creating */
}
else
{
add_to_all_obj (current_obj, obj_creating);
}
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;
tmp_line = NULL;
}
/*gtk_widget_queue_draw (gfig_preview);*/
/*gtk_widget_queue_draw (gfig_context->preview);*/
}

View File

@ -26,18 +26,18 @@
#ifndef __GFIG_LINE_H__
#define __GFIG_LINE_H__
Dobject * d_load_line (FILE *from);
void d_save_line (Dobject *obj,
FILE *to);
Dobject * d_load_line (FILE *from);
void d_save_line (Dobject *obj,
GString *string);
void d_draw_line (Dobject *obj);
void d_paint_line (Dobject *obj);
Dobject *d_copy_line (Dobject *obj);
void d_draw_line (Dobject *obj);
void d_paint_line (Dobject *obj);
Dobject *d_copy_line (Dobject *obj);
void d_update_line (GdkPoint *pnt);
void d_line_start (GdkPoint *pnt,
gint shift_down);
void d_line_end (GdkPoint *pnt,
gint shift_down);
void d_update_line (GdkPoint *pnt);
void d_line_start (GdkPoint *pnt,
gint shift_down);
void d_line_end (GdkPoint *pnt,
gint shift_down);
#endif /* __GFIG_LINE_H__ */

View File

@ -41,31 +41,32 @@
static gint poly_num_sides = 3; /* Default to three sided object */
static void d_save_poly (Dobject * obj, FILE *to);
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,
GdkEventButton *event,
gpointer data)
GdkEventButton *event,
gpointer data)
{
if ((event->type == GDK_2BUTTON_PRESS) &&
(event->button == 1))
num_sides_dialog (_("Regular Polygon Number of Sides"),
&poly_num_sides, NULL, 3, 200);
&poly_num_sides, NULL, 3, 200);
return FALSE;
}
static void
d_save_poly (Dobject * obj, FILE *to)
d_save_poly (Dobject * obj,
GString *string)
{
fprintf (to, "<POLY>\n");
do_save_obj (obj, to);
fprintf (to, "<EXTRA>\n");
fprintf (to, "%d\n</EXTRA>\n", obj->type_data);
fprintf (to, "</POLY>\n");
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 *
@ -79,49 +80,44 @@ d_load_poly (FILE *from)
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 if (strcmp ("</POLY>", buf))
{
g_warning ("[%d] Internal load error while loading poly",
line_no);
return (NULL);
}
return new_obj;
}
{
/* 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);
new_obj = d_new_poly (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
d_pnt_add_line (new_obj, xpnt, ypnt, -1);
}
return new_obj;
}
@ -183,7 +179,7 @@ d_draw_poly (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid + offset_angle;
lx = radius * cos (ang_loop);
ly = radius * sin (ang_loop);
@ -191,19 +187,19 @@ d_draw_poly (Dobject *obj)
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
if (do_line)
{
{
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
else
{
do_line = TRUE;
first_pnt = calc_pnt;
}
{
do_line = TRUE;
first_pnt = calc_pnt;
}
start_pnt = calc_pnt;
}
@ -262,7 +258,7 @@ d_paint_poly (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid + offset_angle;
lx = radius * cos (ang_loop);
ly = radius * sin (ang_loop);
@ -271,22 +267,22 @@ d_paint_poly (Dobject *obj)
/* Miss out duped pnts */
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
line_pnts[i++] = calc_pnt.x;
line_pnts[i++] = calc_pnt.y;
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
line_pnts[i++] = first_pnt.x;
@ -306,17 +302,17 @@ d_paint_poly (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_image,
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);
}
g_free (line_pnts);
@ -376,7 +372,7 @@ d_poly2lines (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid + offset_angle;
lx = radius * cos (ang_loop);
ly = radius * sin (ang_loop);
@ -384,22 +380,22 @@ d_poly2lines (Dobject *obj)
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
d_pnt_add_line (obj, calc_pnt.x, calc_pnt.y, 0);
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
d_pnt_add_line (obj, first_pnt.x, first_pnt.y, 0);
@ -498,36 +494,36 @@ d_star2lines (Dobject *obj)
ang_loop = (gdouble)loop * ang_grid + offset_angle;
if (loop%2)
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
else
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
d_pnt_add_line (obj, calc_pnt.x, calc_pnt.y, 0);
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
d_pnt_add_line (obj, first_pnt.x, first_pnt.y, 0);
@ -630,7 +626,7 @@ d_update_poly (GdkPoint *pnt)
void
d_poly_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
obj_creating = d_new_poly (pnt->x, pnt->y);
obj_creating->type_data = poly_num_sides;
@ -638,9 +634,9 @@ d_poly_start (GdkPoint *pnt,
void
d_poly_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
draw_circle (pnt);
add_to_all_obj (current_obj, obj_creating);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View File

@ -27,8 +27,8 @@
#define __GFIG_POLY_H__
gboolean poly_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
GdkEventButton *event,
gpointer data);
Dobject *d_load_poly (FILE *from);
@ -38,7 +38,7 @@ void d_poly_end (GdkPoint *pnt, gint shift_down);
void d_paint_poly (Dobject *obj);
void d_poly2lines (Dobject *obj);
void d_star2lines (Dobject *obj);
void d_poly2lines (Dobject *obj);
void d_star2lines (Dobject *obj);
#endif /* __GFIG_POLY_H__ */

View File

@ -70,7 +70,6 @@ static gint gfig_invscale_x (gint x);
static gint gfig_invscale_y (gint y);
static GtkWidget* gfig_pos_labels (void);
static GtkWidget* make_pos_info (void);
static GtkWidget* make_status (void);
static void gfig_pos_update (gint x,
gint y);
@ -84,22 +83,22 @@ make_preview (void)
GtkWidget *table;
GtkWidget *ruler;
gfig_preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_widget_set_events (GTK_WIDGET (gfig_preview), PREVIEW_MASK);
gfig_context->preview = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_widget_set_events (GTK_WIDGET (gfig_context->preview), PREVIEW_MASK);
g_signal_connect (gfig_preview , "realize",
g_signal_connect (gfig_context->preview , "realize",
G_CALLBACK (gfig_preview_realize),
NULL);
g_signal_connect (gfig_preview , "event",
g_signal_connect (gfig_context->preview , "event",
G_CALLBACK (gfig_preview_events),
NULL);
g_signal_connect_after (gfig_preview , "expose_event",
g_signal_connect_after (gfig_context->preview , "expose_event",
G_CALLBACK (gfig_preview_expose),
NULL);
gtk_preview_size (GTK_PREVIEW (gfig_preview), preview_width,
gtk_preview_size (GTK_PREVIEW (gfig_context->preview), preview_width,
preview_height);
frame = gtk_frame_new (NULL);
@ -107,13 +106,13 @@ make_preview (void)
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
table = gtk_table_new (3, 3, FALSE);
gtk_table_attach (GTK_TABLE (table), gfig_preview, 1, 2, 1, 2,
gtk_table_attach (GTK_TABLE (table), gfig_context->preview, 1, 2, 1, 2,
GTK_FILL , GTK_FILL , 0, 0);
gtk_container_add (GTK_CONTAINER (frame), table);
ruler = gtk_hruler_new ();
gtk_ruler_set_range (GTK_RULER (ruler), 0, preview_width, 0, PREVIEW_SIZE);
g_signal_connect_swapped (gfig_preview, "motion_notify_event",
g_signal_connect_swapped (gfig_context->preview, "motion_notify_event",
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
ruler);
gtk_table_attach (GTK_TABLE (table), ruler, 1, 2, 0, 1,
@ -122,7 +121,7 @@ make_preview (void)
ruler = gtk_vruler_new ();
gtk_ruler_set_range (GTK_RULER (ruler), 0, preview_height, 0, PREVIEW_SIZE);
g_signal_connect_swapped (gfig_preview, "motion_notify_event",
g_signal_connect_swapped (gfig_context->preview, "motion_notify_event",
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
ruler);
gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 2,
@ -140,9 +139,6 @@ make_preview (void)
frame = make_pos_info ();
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
frame = make_status ();
gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
gtk_widget_show (vbox);
gtk_widget_show (hbox);
@ -169,24 +165,24 @@ refill_cache (GimpDrawable *drawable)
if (!preview_cursor1)
{
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (gfig_preview));
GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (gfig_context->preview));
preview_cursor1 = gdk_cursor_new_for_display (display, GDK_WATCH);
preview_cursor2 = gdk_cursor_new_for_display (display, GDK_TOP_LEFT_ARROW);
}
gdk_window_set_cursor
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_preview))->window,
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_context->preview))->window,
preview_cursor1);
gdk_window_set_cursor (gfig_preview->window, preview_cursor1);
gdk_window_set_cursor (gfig_context->preview->window, preview_cursor1);
gdk_flush ();
cache_preview (drawable);
gdk_window_set_cursor
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_preview))->window,
(gtk_widget_get_toplevel (GTK_WIDGET (gfig_context->preview))->window,
preview_cursor2);
toggle_obj_type (NULL, GINT_TO_POINTER (selvals.otype));
@ -273,7 +269,7 @@ dialog_update_preview (GimpDrawable *drawable)
memset (preview_row, -1, preview_width*4);
for (y = 0; y < preview_height; y++)
{
gtk_preview_draw_row (GTK_PREVIEW (gfig_preview), preview_row,
gtk_preview_draw_row (GTK_PREVIEW (gfig_context->preview), preview_row,
0, y, preview_width);
}
return;
@ -326,7 +322,7 @@ dialog_update_preview (GimpDrawable *drawable)
}
}
gtk_preview_draw_row (GTK_PREVIEW (gfig_preview), preview_row,
gtk_preview_draw_row (GTK_PREVIEW (gfig_context->preview), preview_row,
0, y, preview_width);
}
}
@ -336,27 +332,25 @@ gfig_preview_realize (GtkWidget *widget)
{
GdkDisplay *display = gtk_widget_get_display (widget);
gdk_window_set_cursor (gfig_preview->window,
gdk_window_set_cursor (gfig_context->preview->window,
gdk_cursor_new_for_display (display, GDK_CROSSHAIR));
}
static void
draw_background (void)
draw_background ()
{
static GdkPixbuf *pixbuf = NULL;
if (! back_pixbuf)
back_pixbuf = gimp_image_get_thumbnail (gfig_context->image_id,
preview_width, preview_height,
GIMP_PIXBUF_LARGE_CHECKS);
if (! pixbuf)
pixbuf = gimp_image_get_thumbnail (gfig_image,
preview_width, preview_height,
GIMP_PIXBUF_LARGE_CHECKS);
if (pixbuf)
gdk_draw_pixbuf (gfig_preview->window,
gfig_preview->style->fg_gc[GTK_STATE_NORMAL],
pixbuf, 0, 0,
if (back_pixbuf)
gdk_draw_pixbuf (gfig_context->preview->window,
gfig_context->preview->style->fg_gc[GTK_STATE_NORMAL],
back_pixbuf, 0, 0,
0, 0,
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf),
gdk_pixbuf_get_width (back_pixbuf),
gdk_pixbuf_get_height (back_pixbuf),
GDK_RGB_DITHER_NONE, 0, 0);
}
@ -364,7 +358,7 @@ gboolean
gfig_preview_expose (GtkWidget *widget,
GdkEvent *event)
{
gdk_window_clear (gfig_preview->window);
gdk_window_clear (gfig_context->preview->window);
if (gfig_context->show_background)
draw_background ();
@ -462,8 +456,8 @@ gfig_preview_events (GtkWidget *widget,
break;
}
/* make small preview reflect changes ?*/
list_button_update (current_obj);
gfig_paint_callback ();
list_button_update (gfig_context->current_obj);
break;
case GDK_MOTION_NOTIFY:
@ -545,95 +539,6 @@ make_pos_info (void)
return frame;
}
static GtkWidget*
make_status (void)
{
GtkWidget *frame;
GtkWidget *table;
GtkWidget *label;
frame = gimp_frame_new (_("Collection Details"));
table = gtk_table_new (6, 6, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
label = gtk_label_new (_("Draw name:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label);
label = gtk_label_new (_("Filename:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (label);
status_label_dname = gtk_label_new (_("(none)"));
gtk_misc_set_alignment (GTK_MISC (status_label_dname), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), status_label_dname, 2, 4, 0, 1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_widget_show (status_label_dname);
status_label_fname = gtk_label_new (_("(none)"));
gtk_misc_set_alignment (GTK_MISC (status_label_fname), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), status_label_fname, 2, 4, 1, 2,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_widget_show (status_label_fname);
gtk_widget_show (frame);
return frame;
}
void
gfig_update_stat_labels (void)
{
gchar str[45];
if (current_obj->draw_name)
sprintf (str, "%.34s", current_obj->draw_name);
else
sprintf (str,_("<NONE>"));
gtk_label_set_text (GTK_LABEL (status_label_dname), str);
if (current_obj->filename)
{
gint slen;
const gchar *hm = g_get_home_dir ();
gchar *dfn = g_strdup (current_obj->filename);
if (hm != NULL && !strncmp (dfn, hm, strlen (hm)-1))
{
strcpy (dfn, "~");
strcat (dfn, &dfn[strlen (hm)]);
}
if ((slen = strlen (dfn)) > 40)
{
strncpy (str, dfn, 19);
str[19] = '\0';
strcat (str, "...");
strncat (str, &dfn[slen - 21], 19);
str[40] ='\0';
}
else
{
sprintf (str, "%.40s", dfn);
}
g_free (dfn);
}
else
sprintf (str,_("<NONE>"));
gtk_label_set_text (GTK_LABEL (status_label_fname), str);
}
static gint
gfig_invscale_x (gint x)
{

View File

@ -28,11 +28,11 @@
#define PREVIEW_SIZE 400
GtkWidget *make_preview (void);
void gfig_update_stat_labels (void);
void gfig_pos_enable (GtkWidget *widget,
gpointer data);
void dialog_update_preview (GimpDrawable *drawable);
void refill_cache (GimpDrawable *drawable);
GtkWidget *make_preview (void);
void gfig_update_stat_labels (void);
void gfig_pos_enable (GtkWidget *widget,
gpointer data);
void dialog_update_preview (GimpDrawable *drawable);
void refill_cache (GimpDrawable *drawable);
#endif /* __GFIG_PREVIEW_H__ */

View File

@ -49,25 +49,23 @@ static gint spiral_toggle = 0; /* 0 = clockwise -1 = anti-clockwise */
gint
spiral_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
GdkEventButton *event,
gpointer data)
{
if ((event->type == GDK_2BUTTON_PRESS) &&
(event->button == 1))
num_sides_dialog (_("Spiral Number of Turns"),
&spiral_num_turns, &spiral_toggle, 1, 20);
&spiral_num_turns, &spiral_toggle, 1, 20);
return FALSE;
}
static void
d_save_spiral (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<SPIRAL>\n");
do_save_obj (obj, to);
fprintf (to, "<EXTRA>\n");
fprintf (to, "%d\n</EXTRA>\n", obj->type_data);
fprintf (to, "</SPIRAL>\n");
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 */
@ -83,49 +81,44 @@ d_load_spiral (FILE *from)
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 if (strcmp ("</SPIRAL>", buf))
{
g_warning ("[%d] Internal load error while loading spiral",
line_no);
return (NULL);
}
return (new_obj);
}
{
/* 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);
new_obj = d_new_spiral (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
return (new_obj);
}
@ -192,13 +185,13 @@ d_draw_spiral (Dobject *obj)
for (loop = 0 ; loop <= abs (obj->type_data * 180) +
clock_wise * (gint)RINT (offset_angle/ang_grid) ; loop++)
clock_wise * (gint)RINT (offset_angle/ang_grid) ; loop++)
{
gdouble lx, ly;
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid;
lx = sp_cons * ang_loop * cos (ang_loop)*clock_wise;
ly = sp_cons * ang_loop * sin (ang_loop);
@ -206,18 +199,18 @@ d_draw_spiral (Dobject *obj)
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
if (do_line)
{
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
{
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
else
{
do_line = TRUE;
first_pnt = calc_pnt;
}
{
do_line = TRUE;
first_pnt = calc_pnt;
}
start_pnt = calc_pnt;
}
}
@ -283,7 +276,7 @@ d_paint_spiral (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid;
lx = sp_cons * ang_loop * cos (ang_loop)*clock_wise;
ly = sp_cons * ang_loop * sin (ang_loop);
@ -292,12 +285,12 @@ d_paint_spiral (Dobject *obj)
/* Miss out duped pnts */
if (!loop)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
line_pnts[i++] = calc_pnt.x;
line_pnts[i++] = calc_pnt.y;
@ -318,17 +311,17 @@ d_paint_spiral (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_image,
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);
}
g_free (line_pnts);
@ -350,7 +343,7 @@ d_copy_spiral (Dobject *obj)
static Dobject *
d_new_spiral (gint x,
gint y)
gint y)
{
Dobject *nobj;
@ -418,7 +411,7 @@ d_update_spiral (GdkPoint *pnt)
void
d_spiral_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
obj_creating = d_new_spiral (pnt->x, pnt->y);
obj_creating->type_data = spiral_num_turns * ((spiral_toggle == 0) ? 1 : -1);
@ -426,9 +419,9 @@ d_spiral_start (GdkPoint *pnt,
void
d_spiral_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
draw_circle (pnt);
add_to_all_obj (current_obj, obj_creating);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View File

@ -27,8 +27,8 @@
#define __GFIG_SPIRAL_H__
gint spiral_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
GdkEventButton *event,
gpointer data);
void d_update_spiral (GdkPoint *pnt);
void d_spiral_start (GdkPoint *pnt, gint shift_down);

View File

@ -40,7 +40,8 @@
static gint star_num_sides = 3; /* Default to three sided object */
static void d_save_star (Dobject * obj, FILE *to);
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);
@ -48,25 +49,23 @@ static Dobject *d_new_star (gint x, gint y);
gboolean
star_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
GdkEventButton *event,
gpointer data)
{
if ((event->type == GDK_2BUTTON_PRESS) &&
(event->button == 1))
num_sides_dialog (_("Star Number of Points"),
&star_num_sides, NULL, 3, 200);
&star_num_sides, NULL, 3, 200);
return FALSE;
}
static void
d_save_star (Dobject *obj,
FILE *to)
GString *string)
{
fprintf (to, "<STAR>\n");
do_save_obj (obj, to);
fprintf (to, "<EXTRA>\n");
fprintf (to, "%d\n</EXTRA>\n", obj->type_data);
fprintf (to, "</STAR>\n");
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 *
@ -80,49 +79,44 @@ d_load_star (FILE *from)
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 if (strcmp ("</STAR>", buf))
{
g_warning ("[%d] Internal load error while loading star",
line_no);
return NULL;
}
return new_obj;
}
{
/* 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);
new_obj = d_new_star (xpnt, ypnt);
else
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
d_pnt_add_line (new_obj, xpnt, ypnt,-1);
}
return new_obj;
}
@ -202,35 +196,35 @@ d_draw_star (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid + offset_angle;
if (loop % 2)
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
else
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
if (do_line)
{
{
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
/* Miss out points that come to the same location */
if (calc_pnt.x == start_pnt.x && calc_pnt.y == start_pnt.y)
continue;
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
gfig_draw_line (calc_pnt.x, calc_pnt.y, start_pnt.x, start_pnt.y);
}
else
{
do_line = TRUE;
first_pnt = calc_pnt;
}
{
do_line = TRUE;
first_pnt = calc_pnt;
}
start_pnt = calc_pnt;
}
@ -313,39 +307,39 @@ d_paint_star (Dobject *obj)
GdkPoint calc_pnt;
ang_loop = (gdouble)loop * ang_grid + offset_angle;
if (loop % 2)
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
{
lx = inner_radius * cos (ang_loop);
ly = inner_radius * sin (ang_loop);
}
else
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
{
lx = outer_radius * cos (ang_loop);
ly = outer_radius * sin (ang_loop);
}
calc_pnt.x = RINT (lx + center_pnt->pnt.x);
calc_pnt.y = RINT (ly + center_pnt->pnt.y);
/* Miss out duped pnts */
if (!first)
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
{
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
{
continue;
}
}
line_pnts[i++] = calc_pnt.x;
line_pnts[i++] = calc_pnt.y;
last_pnt = calc_pnt;
if (first)
{
first_pnt = calc_pnt;
first = FALSE;
}
{
first_pnt = calc_pnt;
first = FALSE;
}
}
line_pnts[i++] = first_pnt.x;
@ -365,17 +359,17 @@ d_paint_star (Dobject *obj)
if (selvals.painttype == PAINT_BRUSH_TYPE)
{
gfig_paint (selvals.brshtype,
gfig_drawable,
i, line_pnts);
gfig_context->drawable_id,
i, line_pnts);
}
else
{
gimp_free_select (gfig_image,
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);
}
g_free (line_pnts);
@ -397,7 +391,7 @@ d_copy_star (Dobject *obj)
static Dobject *
d_new_star (gint x,
gint y)
gint y)
{
Dobject *nobj;
@ -458,9 +452,9 @@ d_update_star (GdkPoint *pnt)
outer_pnt = center_pnt->next;
/* Inner radius */
d_pnt_add_line (obj_creating,
pnt->x + (2*(center_pnt->pnt.x - pnt->x))/3,
pnt->y + (2*(center_pnt->pnt.y - pnt->y))/3,
-1);
pnt->x + (2*(center_pnt->pnt.x - pnt->x))/3,
pnt->y + (2*(center_pnt->pnt.y - pnt->y))/3,
-1);
inner_pnt = outer_pnt->next;
}
@ -476,7 +470,7 @@ d_update_star (GdkPoint *pnt)
void
d_star_start (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
obj_creating = d_new_star (pnt->x, pnt->y);
obj_creating->type_data = star_num_sides;
@ -484,10 +478,10 @@ d_star_start (GdkPoint *pnt,
void
d_star_end (GdkPoint *pnt,
gint shift_down)
gint shift_down)
{
draw_circle (pnt);
add_to_all_obj (current_obj, obj_creating);
add_to_all_obj (gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View File

@ -26,9 +26,9 @@
#ifndef __GFIG_STAR_H__
#define __GFIG_STAR_H__
gboolean star_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
gboolean star_button_press (GtkWidget *widget,
GdkEventButton *event,
gpointer data);
void d_update_star (GdkPoint *pnt);
void d_star_start (GdkPoint *pnt, gint shift_down);

View File

@ -54,7 +54,7 @@ static GtkStockItem gfig_stock_items[] =
static void
add_stock_icon (const gchar *stock_id,
GtkIconSize size,
const guint8 *inline_data)
const guint8 *inline_data)
{
GtkIconSource *source;
GtkIconSet *set;

566
plug-ins/gfig/gfig-style.c Normal file
View File

@ -0,0 +1,566 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#ifdef G_OS_WIN32
# include <io.h>
# ifndef W_OK
# define W_OK 2
# endif
#endif
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include "libgimp/stdplugins-intl.h"
#include "gfig.h"
#include "gfig-style.h"
static void gfig_read_parameter_string (gchar **text,
gint nitems,
gchar *name,
gchar **style_entry);
static void gfig_read_parameter_int (gchar **text,
gint nitems,
gchar *name,
gint *style_entry);
static void gfig_read_parameter_double (gchar **text,
gint nitems,
gchar *name,
gdouble *style_entry);
static void gfig_read_parameter_gimp_rgb (gchar **text,
gint nitems,
gchar *name,
GimpRGB *style_entry);
static void
gfig_read_parameter_string (gchar **text,
gint nitems,
gchar *name,
gchar **style_entry)
{
gint n = 0;
gchar *ptr;
gchar *tmpstr;
*style_entry = NULL;
while (n < nitems)
{
ptr = strchr (text[n], ':');
if (ptr)
{
tmpstr = g_strndup (text[n], ptr - text[n]);
ptr++;
if (!strcmp (tmpstr, name))
{
*style_entry = g_strdup (g_strchug (ptr));
g_free (tmpstr);
return;
}
g_free (tmpstr);
}
++n;
}
g_message ("Parameter '%s' not found", name);
}
static void
gfig_read_parameter_int (gchar **text,
gint nitems,
gchar *name,
gint *style_entry)
{
gint n = 0;
gchar *ptr;
gchar *tmpstr;
*style_entry = 0;
while (n < nitems)
{
ptr = strchr (text[n], ':');
if (ptr)
{
tmpstr = g_strndup (text[n], ptr - text[n]);
ptr++;
if (!strcmp (tmpstr, name))
{
*style_entry = atoi (g_strchug (ptr));
g_free (tmpstr);
return;
}
g_free (tmpstr);
}
++n;
}
}
static void
gfig_read_parameter_double (gchar **text,
gint nitems,
gchar *name,
gdouble *style_entry)
{
gint n = 0;
gchar *ptr;
gchar *endptr;
gchar *tmpstr;
*style_entry = 0.;
while (n < nitems)
{
ptr = strchr (text[n], ':');
if (ptr)
{
tmpstr = g_strndup (text[n], ptr - text[n]);
ptr++;
if (!strcmp (tmpstr, name))
{
*style_entry = g_strtod (g_strchug (ptr), &endptr);
g_free (tmpstr);
return;
}
g_free (tmpstr);
}
++n;
}
}
static void
gfig_read_parameter_gimp_rgb (gchar **text,
gint nitems,
gchar *name,
GimpRGB *style_entry)
{
gint n = 0;
gchar *ptr;
gchar *tmpstr;
style_entry->r = style_entry->g = style_entry->b = style_entry->a = 0.;
while (n < nitems)
{
ptr = strchr (text[n], ':');
if (ptr)
{
tmpstr = g_strndup (text[n], ptr - text[n]);
ptr++;
if (!strcmp (tmpstr, name))
{
sscanf (ptr, "%lf %lf %lf %lf", &style_entry->r, &style_entry->g,
&style_entry->b, &style_entry->a);
g_free (tmpstr);
return;
}
g_free (tmpstr);
}
++n;
}
}
gboolean
gfig_load_style (Style *style,
FILE *fp)
{
gulong offset;
gchar load_buf2[MAX_LOAD_LINE];
gchar *style_text[100];
gint nitems = 0;
gint k;
gchar name[100];
offset = ftell (fp);
get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
if (1 != sscanf (load_buf2, "<Style %s>", name))
{
/* no style data */
fprintf (stderr, "No style data\n");
fseek (fp, offset, SEEK_SET);
return TRUE;
}
if (gfig_context->debug_styles)
fprintf (stderr, "Loading style '%s' -- ", name);
/* nuke final > in name */
*strrchr (name, '>') = '\0';
style->name = g_strdup (name);
while (TRUE)
{
get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
if (!strcmp (load_buf2, "</Style>") || feof (fp))
break;
style_text[nitems] = (gchar *) g_malloc (MAX_LOAD_LINE);
strcpy (style_text[nitems], load_buf2);
nitems++;
}
if (feof (fp))
{
g_message ("Error reading style data");
return TRUE;
}
gfig_read_parameter_string (style_text, nitems, "BrushName", &style->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);
for (k = 0; k < nitems; k++)
{
g_free (style_text[k]);
}
if (gfig_context->debug_styles)
fprintf (stderr, "done\n");
return FALSE;
}
gboolean
gfig_skip_style (Style *style,
FILE *fp)
{
gulong offset;
gchar load_buf2[MAX_LOAD_LINE];
offset = ftell (fp);
get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
if (strncmp (load_buf2, "<Style ", 7))
{
/* no style data */
fseek (fp, offset, SEEK_SET);
return TRUE;
}
while (TRUE)
{
get_line (load_buf2, MAX_LOAD_LINE, fp, 0);
if (!strcmp (load_buf2, "</Style>") || feof (fp))
break;
}
if (feof (fp))
{
g_message ("Error trying to skip style data");
return TRUE;
}
return FALSE;
}
/*
* FIXME: need to make this load a list of styles if there are more than one.
*/
gboolean
gfig_load_styles (GFigObj *gfig,
FILE *fp)
{
if (gfig_context->debug_styles)
fprintf (stderr, "Loading global styles -- ");
/* currently we only have the default style */
gfig_load_style (&gfig_context->default_style, fp);
if (gfig_context->debug_styles)
fprintf (stderr, "done\n");
return FALSE;
}
void
gfig_save_style (Style *style,
GString *string)
{
g_string_append_printf (string, "<Style %s>\n", style->name);
g_string_append_printf (string, "BrushName: %s\n", style->brush_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, "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: %lg %lg %lg %lg\n", style->foreground.r,
style->foreground.g, style->foreground.b, 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, "</Style>\n");
}
void
gfig_save_styles (GString *string)
{
gint k;
for (k = 1; k < gfig_context->num_styles; k++)
gfig_save_style (gfig_context->style[k], string);
}
void
set_foreground_callback (GimpColorButton *button,
gpointer data)
{
GimpRGB color2;
gimp_color_button_get_color (button, &color2);
gimp_rgba_set (&gfig_context->default_style.foreground,
color2.r, color2.g, color2.b, color2.a);
gimp_rgba_set (&gfig_context->current_style->foreground,
color2.r, color2.g, color2.b, color2.a);
gfig_paint_callback ();
}
void
set_background_callback (GimpColorButton *button,
gpointer data)
{
GimpRGB color2;
gimp_color_button_get_color (button, &color2);
gimp_rgba_set (&gfig_context->default_style.background,
color2.r, color2.g, color2.b, color2.a);
gimp_rgba_set (&gfig_context->current_style->background,
color2.r, color2.g, color2.b, color2.a);
gfig_paint_callback ();
}
void
gfig_brush_changed_callback (const gchar *brush_name,
gdouble opacity,
gint spacing,
GimpLayerModeEffects paint_mode,
gint width,
gint height,
const guchar *mask_data,
gboolean dialog_closing,
gpointer user_data)
{
gfig_context->current_style->brush_name = (gchar *) brush_name;
gfig_context->default_style.brush_name = (gchar *) brush_name;
/* this will soon be unneeded */
gfig_context->bdesc.name = (gchar *) brush_name;
gfig_context->bdesc.width = width;
gfig_context->bdesc.height = height;
gimp_brushes_set_brush (brush_name);
gfig_paint_callback ();
}
void
gfig_pattern_changed_callback (const gchar *pattern_name,
gint width,
gint height,
gint bpp,
const guchar *mask_data,
gboolean dialog_closing,
gpointer user_data)
{
gfig_context->current_style->pattern = (gchar *) pattern_name;
gfig_context->default_style.pattern = (gchar *) pattern_name;
gfig_paint_callback ();
}
void
gfig_gradient_changed_callback (const gchar *gradient_name,
gint width,
const gdouble *grad_data,
gboolean dialog_closing,
gpointer user_data)
{
gfig_context->current_style->gradient = (gchar *) gradient_name;
gfig_context->default_style.gradient = (gchar *) gradient_name;
gfig_paint_callback ();
}
void
gfig_rgba_copy (GimpRGB *color1,
GimpRGB *color2)
{
color1->r = color2->r;
color1->g = color2->g;
color1->b = color2->b;
color1->a = color2->a;
}
void
gfig_style_copy (Style *style1,
Style *style0,
const gchar *name)
{
if (name)
style1->name = g_strdup (name);
gfig_rgba_copy (&style1->foreground, &style0->foreground);
gfig_rgba_copy (&style1->background, &style0->background);
style1->brush_name = g_strdup (style0->brush_name);
style1->gradient = g_strdup (style0->gradient);
style1->pattern = g_strdup (style0->pattern);
}
void
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;
}
void
gfig_style_append (Style *style)
{
gfig_context->style[gfig_context->num_styles] = style;
++gfig_context->num_styles;
}
void
gfig_read_gimp_style (Style *style,
const gchar *name)
{
gint w, h;
style->name = g_strdup (name);
gimp_palette_get_foreground (&style->foreground);
gimp_palette_get_background (&style->background);
style->brush_name = (gchar *) gimp_brushes_get_brush (&style->brush_width,
&style->brush_height,
&style->brush_spacing);
style->gradient = gimp_gradients_get_gradient ();
style->pattern = gimp_patterns_get_pattern (&w, &h);
}
void
gfig_style_set_context_from_style (Style *style)
{
if (gfig_context->debug_styles)
fprintf (stderr, "Setting context from style '%s' -- ", style->name);
gfig_context->current_style = style;
gimp_color_button_set_color (GIMP_COLOR_BUTTON (gfig_context->fg_color_button),
&style->foreground);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (gfig_context->bg_color_button),
&style->background);
if (!gimp_brushes_set_brush (style->brush_name))
g_message ("Style from context: Failed to set brush to '%s'", style->brush_name);
gimp_brush_select_widget_set (gfig_context->brush_select,
style->brush_name,
-1., -1, -1); /* FIXME */
gfig_context->bdesc.name = style->brush_name;
if (gfig_context->debug_styles)
fprintf (stderr, "done.\n");
}
void
gfig_style_set_style_from_context (Style *style)
{
GimpRGB color;
gimp_color_button_get_color (GIMP_COLOR_BUTTON (gfig_context->fg_color_button),
&color);
gfig_rgba_copy (&style->foreground, &color);
gimp_color_button_get_color (GIMP_COLOR_BUTTON (gfig_context->bg_color_button),
&color);
gfig_rgba_copy (&style->background, &color);
style->brush_name = gfig_context->current_style->brush_name;
style->pattern = gfig_context->current_style->pattern;
style->gradient = gfig_context->current_style->gradient;
}
char *
mygimp_brush_get (void)
{
gint width, height, spacing;
return gimp_brushes_get_brush (&width, &height, &spacing);
}
void
mygimp_brush_info (gint *width,
gint *height)
{
char *name;
gint spacing;
name = gimp_brushes_get_brush (width, height, &spacing);
if (name)
{
*width = MAX (*width, 32);
*height = MAX (*height, 32);
g_free (name);
}
else
{
g_message ("Failed to get brush info");
*width = *height = 48;
}
}

104
plug-ins/gfig/gfig-style.h Normal file
View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This is a plug-in for the GIMP.
*
* Generates images containing vector type drawings.
*
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef __GFIG_STYLE_H__
#define __GFIG_STYLE_H__
void set_foreground_callback (GimpColorButton *button,
gpointer data);
void set_background_callback (GimpColorButton *button,
gpointer data);
void gfig_brush_changed_callback (const gchar *brush_name,
gdouble opacity,
gint spacing,
GimpLayerModeEffects paint_mode,
gint width,
gint height,
const guchar *mask_data,
gboolean dialog_closing,
gpointer user_data);
void gfig_pattern_changed_callback (const gchar *pattern_name,
gint width,
gint height,
gint bpp,
const guchar *mask_data,
gboolean dialog_closing,
gpointer user_data);
void gfig_gradient_changed_callback (const gchar *gradient_name,
gint width,
const gdouble *grad_data,
gboolean dialog_closing,
gpointer user_data);
void mygimp_brush_info (gint *width,
gint *height);
gchar *mygimp_brush_get (void);
void gfig_read_gimp_style (Style *style,
const gchar *name);
void gfig_style_append (Style *style);
void gfig_style_set_all_sources (Style *style,
StyleSource source);
void gfig_style_apply (Style *style);
void gfig_style_copy (Style *style1,
Style *style0,
const gchar *name);
void gfig_rgba_copy (GimpRGB *color1,
GimpRGB *color2);
void gfig_style_copy (Style *style1,
Style *style0,
const gchar *name);
gboolean gfig_load_style (Style *style,
FILE *fp);
gboolean gfig_skip_style (Style *style,
FILE *fp);
gboolean gfig_load_styles (GFigObj *gfig,
FILE *fp);
void gfig_save_style (Style *style,
GString *string);
void gfig_save_styles (GString *string);
void gfig_style_set_context_from_style (Style *style);
void gfig_style_set_style_from_context (Style *style);
#endif /* __GFIG_STYLE_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -26,27 +26,15 @@
#ifndef __GFIG_H__
#define __GFIG_H__
#include "gfig-dobject.h"
#define MAX_UNDO 10
#define MIN_UNDO 1
#define MAX_LOAD_LINE 256
#define SQ_SIZE 8
struct Dobject; /* fwd declaration for DobjFunc */
#define HELP_ID "plug-in-gfig"
extern gint line_no;
extern gint preview_width, preview_height;
extern gboolean drawing_pic;
extern gint need_to_scale;
extern gint32 gfig_image;
extern gint32 gfig_drawable;
extern GdkGC *gfig_gc;
extern gdouble scale_x_factor, scale_y_factor;
extern GdkPixbuf *back_pixbuf;
extern GtkWidget *gfig_preview;
extern GtkWidget *pic_preview;
extern Dobject *tmp_line;
extern gint obj_show_single;
typedef void (*DobjFunc) (struct Dobject *);
typedef struct Dobject *(*DobjGenFunc) (struct Dobject *);
typedef struct Dobject *(*DobjLoadFunc) (FILE *);
typedef void (*DobjSaveFunc) (struct Dobject *, GString *);
typedef enum
{
@ -73,7 +61,6 @@ typedef enum
INTERSECT
} SelectionType;
typedef enum
{
ARC_SEGMENT = 0,
@ -113,13 +100,13 @@ typedef enum
} DrawonLayers;
typedef enum
{
LAYER_TRANS_BG = 0,
LAYER_BG_BG,
LAYER_FG_BG,
LAYER_WHITE_BG,
LAYER_COPY_BG
} LayersBGType;
{
LAYER_TRANS_BG = 0,
LAYER_BG_BG,
LAYER_FG_BG,
LAYER_WHITE_BG,
LAYER_COPY_BG
} LayersBGType;
typedef enum
{
@ -129,12 +116,137 @@ typedef enum
} PaintType;
typedef enum
{
BRUSH_BRUSH_TYPE = 0,
BRUSH_PENCIL_TYPE,
BRUSH_AIRBRUSH_TYPE,
BRUSH_PATTERN_TYPE
} BrushType;
typedef enum
{
STYLE_SOURCE_GIMP = 0,
STYLE_SOURCE_DEFAULT,
STYLE_SOURCE_STYLE,
STYLE_SOURCE_OBJECT
} StyleSource;
typedef struct
{
BRUSH_BRUSH_TYPE = 0,
BRUSH_PENCIL_TYPE,
BRUSH_AIRBRUSH_TYPE,
BRUSH_PATTERN_TYPE
} BrushType;
gchar *name;
gchar *brush_name;
gint brush_width;
gint brush_height;
gint brush_spacing;
BrushType brush_type;
gdouble brushfade;
gdouble brushgradient;
gdouble airbrushpressure;
StyleSource brush_source;
FillType fill_type;
StyleSource fill_type_source;
gchar *pattern;
StyleSource pattern_source;
gchar *gradient;
StyleSource gradient_source;
PaintType paint_type;
GimpRGB foreground;
StyleSource foreground_source;
GimpRGB background;
StyleSource background_source;
gboolean reverselines;
} Style;
typedef enum
{
LINE,
CIRCLE,
ELLIPSE,
ARC,
POLY,
STAR,
SPIRAL,
BEZIER,
MOVE_OBJ,
MOVE_POINT,
COPY_OBJ,
MOVE_COPY_OBJ,
DEL_OBJ,
NULL_OPER
} DobjType;
typedef struct DobjPoints
{
struct DobjPoints *next;
GdkPoint pnt;
gint found_me;
} DobjPoints;
/* The object itself */
typedef struct Dobject
{
DobjType type; /* What is the type? */
gint type_data; /* Extra data needed by the object */
DobjPoints *points; /* List of points */
Style style; /* this object's individual style settings */
gint style_no; /* style index of this specific object */
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 */
} Dobject;
typedef struct DAllObjs
{
struct DAllObjs *next;
Dobject *obj; /* Object on list */
} DAllObjs;
/* States of the object */
#define GFIG_OK 0x0
#define GFIG_MODIFIED 0x1
#define GFIG_READONLY 0x2
extern Dobject *obj_creating;
void d_pnt_add_line (Dobject *obj,
gint x,
gint y,
gint pos);
DobjPoints *new_dobjpoint (gint x, gint y);
void do_save_obj (Dobject *obj,
GString *to);
DobjPoints *d_copy_dobjpoints (DobjPoints * pnts);
void free_one_obj (Dobject *obj);
void d_delete_dobjpoints (DobjPoints * pnts);
void object_update (GdkPoint *pnt);
DAllObjs *copy_all_objs (DAllObjs *objs);
void draw_objects (DAllObjs *objs, gint show_single);
void object_start (GdkPoint *pnt, gint);
void object_operation (GdkPoint *pnt, gint);
void object_operation_start (GdkPoint *pnt, gint shift_down);
void object_operation_end (GdkPoint *pnt, gint);
void object_end (GdkPoint *pnt, gint shift_down);
#define MAX_LOAD_LINE 256
#define SQ_SIZE 8
#define HELP_ID "plug-in-gfig"
extern gint line_no;
extern gint preview_width, preview_height;
extern gint need_to_scale;
extern GdkGC *gfig_gc;
extern gdouble scale_x_factor, scale_y_factor;
extern GdkPixbuf *back_pixbuf;
extern GtkWidget *pic_preview;
extern Dobject *tmp_line;
extern gint obj_show_single;
typedef struct
@ -171,14 +283,48 @@ typedef struct DFigObj
GtkWidget *pixmap_widget;
} GFigObj;
/* this is temp, should be able to get rid of */
typedef struct BrushDesc
{
gchar *name;
gdouble opacity;
gint spacing;
GimpLayerModeEffects paint_mode;
gint width;
gint height;
guchar *pv_buf; /* Buffer where brush placed */
gint16 x_off;
gint16 y_off;
const gchar *popup;
} BrushDesc;
typedef struct
{
gboolean show_background;
gboolean debug_styles;
gboolean show_background; /* show thumbnail of image behind figure */
gint32 image_id; /* Gimp image id */
gint32 drawable_id; /* Gimp drawable to paint on */
GFigObj *current_obj;
Dobject *selected_obj;
GtkWidget *preview;
Style *style[1000]; /* hack, but hopefully way more than enough! */
gint num_styles;
Style gimp_style;
Style default_style;
Style *current_style;
BrushDesc bdesc;
GtkWidget *fg_color_button;
GtkWidget *bg_color_button;
GtkWidget *brush_select;
GtkWidget *pattern_select;
GtkWidget *gradient_select;
GtkWidget *fillstyle_combo;
GimpRGB *fg_color;
GimpRGB *bg_color;
} GFigContext;
GFigContext *gfig_context;
extern GFigObj *current_obj;
extern GFigObj *pic_obj;
extern selection_option selopt;
@ -235,4 +381,36 @@ void gfig_draw_line (gint x0,
gboolean gfig_preview_expose (GtkWidget *widget,
GdkEvent *event);
void gfig_paint_callback (void);
void gfig_read_gimp_style (Style *style,
const gchar *name);
GFigObj *gfig_load (const gchar *filename,
const gchar *name);
void gfig_name_encode (gchar *dest,
gchar *src);
void gfig_name_decode (gchar *dest,
const gchar *src);
gint gfig_list_pos (GFigObj *gfig);
gint gfig_list_insert (GFigObj *gfig);
void gfig_free (GFigObj *gfig);
void save_options (GString *string);
GString *gfig_save_as_string (void);
gboolean gfig_save_as_parasite (void);
GFigObj *gfig_load_from_parasite (void);
GFigObj * gfig_new (void);
void gfig_save_callbk (void);
GtkWidget *top_level_dlg;
GimpDrawable *gfig_drawable;
GList *gfig_list;
gdouble org_scale_x_factor, org_scale_y_factor;
#endif /* __GFIG_H__ */

66
plug-ins/gfig/notes.txt Normal file
View File

@ -0,0 +1,66 @@
Notes regarding GFig
Bill Skaggs, July 3, 2004
Most importantly: this version of Gfig has been massively revised. It
is very unstable. It is likely to crash at any moment. It is full of
bugs. Many things are incompletely implemented, and others do not
work yet. Play with it at your own risk.
(If it does crash, though, it is not likely to corrupt the image, so
in most cases you should be able to Exit the plug-in and continue
working.)
A quick summary of recent changes:
Gfig now works somewhat like the text tool. It uses special dedicated
"Gfig" layers. A Gfig layer is defined by the presence of a parasite
called "Gfig", which contains a representation of the figure. (It is
actually a Gfig file whose contents are attached to the layer as a
parasite.)
If Gfig is run when the active layer is a Gfig layer, then it loads
the figure that is stored there, so that it can be modified. If the
active layer is not a Gfig layer, then a new layer is created, and
initialized to transparent.
The figure that you create is saved to the layer when you hit the
Close button. If you hit the Cancel button, the results of your work
are not saved. The GFig data parasite is not overwritten until you
hit Close, so you can always revert to the previous version of the
figure by hitting Cancel and then re-running GFig.
Each object that you create in Gfig can have its own style. Currently
the only style attributes that work are foreground color and brush
shape; others will be added shortly.
When you start Gfig, and the dialog comes up, the background of the
preview shows a represntation of the image you are working on. Each
time you do something in GFig, the result is reflected by a change in
both the Gimp image and the GFig preview, so you can see in real time
the results of everything that you do. (The rendering could stand to
be speeded up, though.) You can turn the background display in the
preview on or off by toggling Edit->Options->Show image.
PLEASE NOTE: The Gfig file format has not yet stabilized. Until it
does, the parasite used to store the layer data is marked
non-persistent, meaning it will not be stored in XCF files. This will
be trivial to change when the time comes. The ordinary pixel data
*is* stored in XCF files, though. This means that if you save the
image as XCF and re-open it, the GFig layers will be there but you
will not be able to use GFig to modify them.
ALSO NOTE: When GFig loads a GFig layer, it begins by clearing the
layer to transparent and redrawing it as stored in the GFig parasite.
This means that any changes you have made in the layer in the meantime
will be lost. It would be nice if GFig could give a warning that this
is about to happen, but it is difficult to implement, because Gimp
does not yet provide an easy way to tell whether a layer has been
modified (as far as I know).
PLEASE DO NOT FILE BUG REPORTS ABOUT THIS VERSION OF GFIG. Given the
pace of development, it would just be unnecessary clutter in
Bugzilla. I would be happy to see your thoughts, though; my address
is weskaggs@primate.ucdavis.edu.

View File

@ -1,89 +1,3 @@
/* XPM */
static char * mini_cross_xpm[] = {
"16 14 4 1",
" c None s None",
". c red",
"X c gray50",
"o c black",
" ",
" . ",
" ..X ... ",
" ..X ..... ",
" .......oo ",
" .....o ",
" ....o ",
" ...... ",
" ..o ... ",
" ..o ... ",
" .o ..X ",
" .o .o ",
" o o ",
" "};
/* XPM */
static char * blank_xpm[] = {
"18 17 1 1",
" c None",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
/* XPM */
static char * Floppy6_xpm[] = {
"18 18 24 1",
" c None",
". c #861782078617",
"X c #5965596571C6",
"o c #618565955965",
"O c #596559659E79",
"+ c #0000000079E7",
"@ c #0820082071C6",
"# c #9E799E790000",
"$ c #FFFFFFFF0000",
"% c #186118614103",
"& c #965896589E79",
"* c #9E799E795965",
"= c #000000006185",
"- c #9E799E799E79",
"; c #FFFFFFFFFFFF",
": c #000000000000",
"> c #71C675D69658",
", c #BEFBBEFBBEFB",
"< c #B6DAB2CABEFB",
"1 c #1040145171C6",
"2 c #28A228A28617",
"3 c #79E77DF78E38",
"4 c #A699A289A699",
"5 c #38E33CF379E7",
" ",
" .XXoooooooooXO ",
" +@#$$$$$$$$$%+O ",
" &++*$$$$$$$$$%+O ",
" &+=-;;;;;;;;;%+O ",
" &==-;::;:;:;;%+O ",
" &++-;;;;;;;;;%+O ",
" &++-;:;:::;:;%+O ",
" &++-;;;;;;;;;%+O ",
" &+=>,,<,,,,,,1+O ",
" &++==========++O ",
" &+++22222222+++O ",
" &++;11>-333.+++O ",
" &++;++>43333+++O ",
" &++5++>4...3=++O ",
" 31+++======+++O ",
" &&&&&&&&&&&& ",
" "};