aboutsummaryrefslogtreecommitdiff
path: root/generic/Curve.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Curve.c')
-rw-r--r--generic/Curve.c84
1 files changed, 51 insertions, 33 deletions
diff --git a/generic/Curve.c b/generic/Curve.c
index 5ada355..54af677 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -34,7 +34,9 @@
#include "WidgetInfo.h"
#include "Image.h"
#include "Color.h"
+#ifdef GPC
#include "gpc/gpc.h"
+#endif
#include <ctype.h>
#include <malloc.h>
@@ -92,7 +94,9 @@ typedef struct _CurveItemStruct {
ZnImage tile;
ZnPoly dev_shape;
ZnColorGradient gradient;
+#ifdef GPC
gpc_tristrip tristrip;
+#endif
} CurveItemStruct, *CurveItem;
static ZnAttrConfig cv_attrs[] = {
@@ -188,22 +192,21 @@ CvTileChange(ClientData client_data,
**********************************************************************************
*/
static int
-Init(Item item,
- int *argc,
- Arg **args)
+Init(Item item,
+ int *argc,
+ Tcl_Obj *CONST *args[])
{
WidgetInfo *wi = item->wi;
CurveItem cv = (CurveItem) item;
- Arg *elems;
- int i, result, num_elems;
+ Tcl_Obj **elems;
+ int i, num_elems;
ZnPoint *p, *points;
double dbl;
-#ifdef PTK
- LangFreeProc *freeProc = NULL;
-#endif
POLY_INIT(&cv->dev_shape);
+#ifdef GPC
cv->tristrip.num_strips = 0;
+#endif
cv->gradient = NULL;
/* Init attributes */
@@ -220,14 +223,9 @@ Init(Item item,
Tcl_AppendResult(wi->interp, " curve coords expected", NULL);
return ZN_ERROR;
}
- result = Lang_SplitList(wi->interp, (*args)[0], &num_elems, &elems, &freeProc);
- if ((result == ZN_ERROR) || ((num_elems%2) != 0)) {
+ if ((Tcl_ListObjGetElements(wi->interp, (*args)[0], &num_elems, &elems) == ZN_ERROR) ||
+ ((num_elems % 2) != 0)) {
cv_error:
-#ifdef PTK
- if (elems != NULL && freeProc) {
- (*freeProc)(num_elems, elems);
- }
-#endif
Tcl_AppendResult(wi->interp, " malformed curve coords", NULL);
return ZN_ERROR;
}
@@ -239,16 +237,13 @@ Init(Item item,
p = points = (ZnPoint *) ZnMalloc(num_elems/2 * sizeof(ZnPoint));
POLY_CONTOUR1(&cv->shape, points, num_elems/2);
for (i = 0; i < num_elems; i += 2, p++) {
- if (Tcl_GetDouble(wi->interp, elems[i], &dbl) == ZN_ERROR) {
+ if (Tcl_GetDoubleFromObj(wi->interp, elems[i], &dbl) == ZN_ERROR) {
cv_error2:
-#ifndef PTK
- Tcl_Free((char *) elems);
-#endif
POLY_FREE(&cv->shape);
goto cv_error;
}
p->x = dbl;
- if (Tcl_GetDouble(wi->interp, elems[i+1], &dbl) == ZN_ERROR) {
+ if (Tcl_GetDoubleFromObj(wi->interp, elems[i+1], &dbl) == ZN_ERROR) {
goto cv_error2;
}
p->y = dbl;
@@ -256,13 +251,6 @@ Init(Item item,
}
(*args)++;
(*argc)--;
-#ifndef PTK
- Tcl_Free((char *) elems);
-#else
- if (freeProc) {
- (*freeProc)(num_elems, elems);
- }
-#endif
CLEAR(cv->flags, FILLED_BIT);
cv->first_end = NULL;
@@ -416,6 +404,11 @@ Destroy(Item item)
if (cv->grad_geom) {
GradientGeomDelete(cv->grad_geom);
}
+#ifdef GPC
+ if (cv->tristrip.num_strips) {
+ gpc_free_tristrip(&cv->tristrip);
+ }
+#endif
}
@@ -468,7 +461,7 @@ SetRenderFlags(CurveItem cv)
static int
Configure(Item item,
int argc,
- ZnAttrList argv,
+ Tcl_Obj *CONST argv[],
int *flags)
{
WidgetInfo *wi = item->wi;
@@ -523,7 +516,7 @@ Configure(Item item,
static int
Query(Item item,
int argc,
- ZnAttrList argv)
+ Tcl_Obj *CONST argv[])
{
if (ITEM_P.QueryAttribute((char *) item, -1, argv[0]) == ZN_ERROR) {
return ZN_ERROR;
@@ -579,6 +572,7 @@ TestCCW(ZnPoint *points,
* Create a reduced polygon from an unknown one by
* adding/clipping all the shapes/holes in turn.
*/
+#ifdef GPC
static void
ReduceContours(ZnPoly *poly_in,
ZnPoly *poly_out)
@@ -597,6 +591,7 @@ ReduceContours(ZnPoly *poly_in,
POLY_SET(poly_out, &rpoly);
}
}
+#endif
/*
@@ -633,9 +628,11 @@ ComputeCoordinates(Item item,
SET(cv->flags, REDUCED_BIT);
}
else if (ISCLEAR(cv->flags, REDUCED_BIT)) {
+#ifdef GPC
ZnPoly poly;
ReduceContours(&cv->shape, &poly);
POLY_SET(&cv->shape, &poly);
+#endif
SET(cv->flags, REDUCED_BIT);
}
@@ -644,9 +641,11 @@ ComputeCoordinates(Item item,
return;
}
+#ifdef GPC
if (cv->tristrip.num_strips) {
gpc_free_tristrip(&cv->tristrip);
}
+#endif
/*
* Allocate space for devices coordinates, the holes array is _NOT_
@@ -822,7 +821,7 @@ ToArea(Item item,
ZnBBox bbox;
ZnPoint *points;
ZnPoint end_points[LINE_END_POINTS];
- int i, num_points, result, result2;
+ int i, num_points, result=-1, result2;
int width, height;
ZnBool first_done = False;
@@ -964,10 +963,10 @@ Draw(Item item)
WidgetInfo *wi = item->wi;
CurveItem cv = (CurveItem) item;
XGCValues values;
- int i, j, num_points, num2;
+ int i, j, num_points=0, num2;
unsigned int gc_mask;
- ZnPoint *points;
- XPoint *xpoints = NULL;
+ ZnPoint *points=NULL;
+ XPoint *xpoints=NULL;
if ((cv->dev_shape.num_contours == 0) ||
(ISCLEAR(cv->flags, FILLED_OK) &&
@@ -1008,6 +1007,7 @@ Draw(Item item)
}
XChangeGC(wi->dpy, wi->gc, gc_mask, &values);
+#ifdef GPC
if (cv->tristrip.num_strips == 0) {
gpc_polygon_to_tristrip((gpc_polygon *) &cv->dev_shape, &cv->tristrip);
}
@@ -1025,6 +1025,18 @@ Draw(Item item)
&xpoints[j], 3, Convex, CoordModeOrigin);
}
}
+#else
+ num_points = cv->dev_shape.contours[0].num_points;
+ points = cv->dev_shape.contours[0].points;
+ ZnListAssertSize(wi->work_xpts, num_points);
+ xpoints = (XPoint *) ZnListArray(wi->work_xpts);
+ for (i = 0; i < num_points; i++) {
+ xpoints[i].x = REAL_TO_INT(points[i].x);
+ xpoints[i].y = REAL_TO_INT(points[i].y);
+ }
+ XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc,
+ xpoints, num_points, Complex, CoordModeOrigin);
+#endif
}
}
@@ -1531,6 +1543,7 @@ Coords(Item item,
*
**********************************************************************************
*/
+#ifdef GPC
static void
Contour(Item item,
int cmd,
@@ -1549,6 +1562,7 @@ Contour(Item item,
cv->shape.contours[0].num_points);*/
ITEM.Invalidate(item, ZN_COORDS_FLAG);
}
+#endif
/*
@@ -1579,7 +1593,11 @@ static ItemClassStruct CURVE_ITEM_CLASS = {
NULL, /* Cursor */
NULL, /* Index */
NULL, /* Selection */
+#ifdef GPC
Contour,
+#else
+ NULL,
+#endif
ComputeCoordinates,
ToArea,
Draw,