/* * Rectangle.c -- Implementation of rectangle item. * * Authors : Patrick Lecoanet. * Creation date : Fri Dec 2 14:47:42 1994 * * $Id$ */ /* * Copyright (c) 1993 - 1999 CENA, Patrick Lecoanet -- * * This code is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This code 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this code; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include "Item.h" #include "Geo.h" #include "Draw.h" #include "Types.h" #include "Image.h" #include "Color.h" #include "WidgetInfo.h" #include "tkZinc.h" static const char rcsid[] = "$Id$"; static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " $"; /* * Bit offset of flags. */ #define FILLED_BIT 1 /* If the rectangle is filled with color/pattern */ #define ALIGNED_BIT 2 /* ********************************************************************************** * * Specific Rectangle item record * ********************************************************************************** */ typedef struct _RectangleItemStruct { ItemStruct header; /* Public data */ ZnPoint coords[2]; unsigned short flags; ReliefStyle relief; LineStyle line_style; ZnDim line_width; ZnGradient *line_color; ZnImage fill_pattern; ZnImage line_pattern; ZnGradient *fill_color; ZnImage tile; /* Private data */ ZnPoint dev[4]; ZnGradient *gradient; ZnPoint *grad_geo; } RectangleItemStruct, *RectangleItem; static ZnAttrConfig rect_attrs[] = { { ZN_CONFIG_BOOL, "-composealpha", NULL, Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-fillcolor", NULL, Tk_Offset(RectangleItemStruct, fill_color), 0, ZN_COORDS_FLAG|ZN_BORDER_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(RectangleItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(RectangleItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_GRADIENT, "-linecolor", NULL, Tk_Offset(RectangleItemStruct, line_color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BITMAP, "-linepattern", NULL, Tk_Offset(RectangleItemStruct, line_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-linestyle", NULL, Tk_Offset(RectangleItemStruct, line_style), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_DIM, "-linewidth", NULL, Tk_Offset(RectangleItemStruct, line_width), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_PRI, "-priority", NULL, Tk_Offset(RectangleItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_RELIEF, "-relief", NULL, Tk_Offset(RectangleItemStruct, relief), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(RectangleItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(RectangleItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, Tk_Offset(RectangleItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(RectangleItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } }; /* ********************************************************************************** * * Init -- * ********************************************************************************** */ static int Init(Item item, int *argc, Tcl_Obj *CONST *args[]) { WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; int num_points; ZnPoint *points; rect->gradient = NULL; rect->grad_geo = NULL; /* Init attributes */ SET(item->flags, VISIBLE_BIT); SET(item->flags, SENSITIVE_BIT); SET(item->flags, COMPOSE_ALPHA_BIT); SET(item->flags, COMPOSE_ROTATION_BIT); SET(item->flags, COMPOSE_SCALE_BIT); item->priority = DEFAULT_RECTANGLE_PRIORITY; if (*argc < 1) { Tcl_AppendResult(wi->interp, " rectangle coords expected", NULL); return ZN_ERROR; } if (ZnParseCoordList(wi, (*args)[0], &points, NULL, &num_points, NULL) == ZN_ERROR) { return ZN_ERROR; } if (num_points != 2) { Tcl_AppendResult(wi->interp, " malformed rectangle coords", NULL); return ZN_ERROR; }; rect->coords[0] = points[0]; rect->coords[1] = points[1]; (*args)++; (*argc)--; CLEAR(rect->flags, FILLED_BIT); rect->relief = RELIEF_FLAT; rect->line_style = LINE_SIMPLE; rect->line_width = 1; rect->line_pattern = ZnUnspecifiedImage; rect->tile = ZnUnspecifiedImage; rect->fill_pattern = ZnUnspecifiedImage; rect->line_color = ZnGetGradientByValue(wi->fore_color); rect->fill_color = ZnGetGradientByValue(wi->fore_color); return ZN_OK; } /* ********************************************************************************** * * Clone -- * ********************************************************************************** */ static void Clone(Item item) { RectangleItem rect = (RectangleItem) item; if (rect->gradient) { rect->gradient = ZnGetGradientByValue(rect->gradient); } if (rect->grad_geo) { ZnPoint *grad_geo = ZnMalloc(4*sizeof(ZnPoint)); memcpy(grad_geo, rect->grad_geo, 4*sizeof(ZnPoint)); rect->grad_geo = grad_geo; } if (rect->tile != ZnUnspecifiedImage) { rect->tile = ZnGetImageByValue(rect->tile); } if (rect->line_pattern != ZnUnspecifiedImage) { rect->line_pattern = ZnGetImageByValue(rect->line_pattern); } if (rect->fill_pattern != ZnUnspecifiedImage) { rect->fill_pattern = ZnGetImageByValue(rect->fill_pattern); } rect->line_color = ZnGetGradientByValue(rect->line_color); rect->fill_color = ZnGetGradientByValue(rect->fill_color); } /* ********************************************************************************** * * Destroy -- * ********************************************************************************** */ static void Destroy(Item item) { RectangleItem rect = (RectangleItem) item; if (rect->tile != ZnUnspecifiedImage) { ZnFreeImage(rect->tile); rect->tile = ZnUnspecifiedImage; } if (rect->gradient) { ZnFreeGradient(rect->gradient); } if (rect->line_pattern != ZnUnspecifiedImage) { ZnFreeImage(rect->line_pattern); rect->line_pattern = ZnUnspecifiedImage; } if (rect->fill_pattern != ZnUnspecifiedImage) { ZnFreeImage(rect->fill_pattern); rect->fill_pattern = ZnUnspecifiedImage; } if (rect->grad_geo) { ZnFree(rect->grad_geo); } ZnFreeGradient(rect->fill_color); ZnFreeGradient(rect->line_color); } /* ********************************************************************************** * * Configure -- * ********************************************************************************** */ static int Configure(Item item, int argc, Tcl_Obj *CONST argv[], int *flags) { WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; int status = ZN_OK; XColor *color; int alpha; status = ZnConfigureAttributes(wi, item, rect_attrs, argc, argv, flags); if (rect->gradient && (ISSET(*flags, ZN_BORDER_FLAG) || (rect->relief == RELIEF_FLAT))) { ZnFreeGradient(rect->gradient); rect->gradient = NULL; } if ((rect->relief != RELIEF_FLAT) && !rect->gradient) { color = ZnGetGradientColor(rect->line_color, 51.0, &alpha); rect->gradient = ZnGetReliefGradient(wi->interp, wi->win, ZnNameOfColor(color), alpha); if (rect->gradient == NULL) { status = ZN_ERROR; } } return status; } /* ********************************************************************************** * * Query -- * ********************************************************************************** */ static int Query(Item item, int argc, Tcl_Obj *CONST argv[]) { if (ZnQueryAttribute(item->wi, item, rect_attrs, argv[0]) == ZN_ERROR) { return ZN_ERROR; } return ZN_OK; } /* ********************************************************************************** * * ComputeCoordinates -- * ********************************************************************************** */ static void ComputeCoordinates(Item item, ZnBool force) { WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; ZnPoint p[4]; int i; ZnBool aligned; ZnDim delta; ResetBBox(&item->item_bounding_box); if (!rect->line_width && ISCLEAR(rect->flags, FILLED_BIT)) { return; } p[0] = rect->coords[0]; p[2] = rect->coords[1]; p[1].x = p[2].x; p[1].y = p[0].y; p[3].x = p[0].x; p[3].y = p[2].y; ZnTransformPoints(wi->current_transfo, p, rect->dev, 4); for (i = 0; i < 4; i++) { rect->dev[i].x = REAL_TO_INT(rect->dev[i].x); rect->dev[i].y = REAL_TO_INT(rect->dev[i].y); } /* * Add all points to the bounding box. Then expand by the line * width to account for mitered corners. This is an overestimate. */ AddPointsToBBox(&item->item_bounding_box, rect->dev, 4); if (rect->line_width > 0) { item->item_bounding_box.orig.x -= rect->line_width; item->item_bounding_box.orig.y -= rect->line_width; item->item_bounding_box.corner.x += rect->line_width; item->item_bounding_box.corner.y += rect->line_width; } item->item_bounding_box.orig.x -= 1; item->item_bounding_box.orig.y -= 1; item->item_bounding_box.corner.x += 1; item->item_bounding_box.corner.y += 1; delta = rect->dev[0].y - rect->dev[1].y; delta = ABS(delta); aligned = delta < X_PRECISION_LIMIT; delta = rect->dev[0].x - rect->dev[1].x; delta = ABS(delta); aligned |= delta < X_PRECISION_LIMIT; ASSIGN(rect->flags, ALIGNED_BIT, aligned); #ifdef GLX /* * If there is an axial gradient with an unaligned axis * compute the bbox in the coordinate system defined * by the gradient axis. */ if (!ZnGradientFlat(rect->fill_color)) { ZnPoly shape; if (rect->fill_color->type == ZN_AXIAL_GRADIENT) { int angle = rect->fill_color->g.angle; if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) { if (!rect->grad_geo) { rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } POLY_CONTOUR1(&shape, p, 4, False); ZnComputeAxialGradient(wi, &shape, angle, rect->grad_geo); } else { goto free_ggeo; } } else if (rect->fill_color->type == ZN_RADIAL_GRADIENT) { ZnPoint pp[4]; if (!rect->grad_geo) { rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } pp[0] = rect->coords[0]; pp[2] = rect->coords[1]; pp[1].x = pp[2].x; pp[1].y = pp[0].y; pp[3].x = pp[0].x; pp[3].y = pp[2].y; POLY_CONTOUR1(&shape, pp, 4, False); ZnComputeRadialGradient(wi, &shape, False, &rect->fill_color->g.p, rect->grad_geo); } else if (rect->fill_color->type == ZN_PATH_GRADIENT) { if (!rect->grad_geo) { rect->grad_geo = ZnMalloc(6*sizeof(ZnPoint)); } POLY_CONTOUR1(&shape, rect->coords, 2, False); ZnComputePathGradient(wi, &shape, &rect->fill_color->g.p, rect->grad_geo); } } else { free_ggeo: if (rect->grad_geo) { ZnFree(rect->grad_geo); rect->grad_geo = NULL; } } #endif } /* ********************************************************************************** * * ToArea -- * Tell if the object is entirely outside (-1), * entirely inside (1) or in between (0). * ********************************************************************************** */ static int ToArea(Item item, ZnToArea ta) { RectangleItem rect = (RectangleItem) item; int result; ZnBBox *area = ta->area; result = -1; if (ISSET(rect->flags, FILLED_BIT)) { result = PolygonInBBox(rect->dev, 4, area, NULL); } else if (rect->line_width > 0) { int i; ZnPoint pts[5]; for (i = 0; i < 4; i++) { pts[i] = rect->dev[i]; } pts[4] = pts[0]; result = PolylineInBBox(pts, 5, rect->line_width, CapProjecting, JoinMiter, area); } return result; } /* ********************************************************************************** * * Draw -- * ********************************************************************************** */ static void Draw(Item item) { WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; XGCValues values; int i, gc_mask; XRectangle r; XPoint xp[5]; if (ISSET(rect->flags, ALIGNED_BIT)) { if (rect->dev[0].x < rect->dev[2].x) { r.x = rect->dev[0].x; r.width = rect->dev[2].x - r.x; } else { r.x = rect->dev[2].x; r.width = rect->dev[0].x - r.x; } if (rect->dev[0].y < rect->dev[2].y) { r.y = rect->dev[0].y; r.height = rect->dev[2].y - r.y; } else { r.y = rect->dev[2].y; r.height = rect->dev[0].y - r.y; } } else { for (i = 0; i < 4; i++) { xp[i].x = rect->dev[i].x; xp[i].y = rect->dev[i].y; } xp[i] = xp[0]; } /* * Fill if requested. */ if (ISSET(rect->flags, FILLED_BIT)) { values.foreground = ZnPixel(ZnGetGradientColor(rect->fill_color, 0.0, NULL)); if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ values.fill_style = FillTiled; values.tile = ZnImagePixmap(rect->tile, NULL); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; } else { values.ts_x_origin = (int) item->item_bounding_box.orig.x; values.ts_y_origin = (int) item->item_bounding_box.orig.y; } XChangeGC(wi->dpy, wi->gc, GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCTile, &values); } else if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; values.stipple = ZnImagePixmap(rect->fill_pattern, NULL); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; } else { values.ts_x_origin = (int) item->item_bounding_box.orig.x; values.ts_y_origin = (int) item->item_bounding_box.orig.y; } XChangeGC(wi->dpy, wi->gc, GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCStipple|GCForeground, &values); } else { /* Fill solid */ values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle, &values); } if (ISSET(rect->flags, ALIGNED_BIT)) { XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.width, r.height); } else { XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, 4, Convex, CoordModeOrigin); } } /* Draw the outline */ if (rect->line_width) { if (rect->relief != RELIEF_FLAT) { if (ISSET(rect->flags, ALIGNED_BIT)) { ZnDrawRectangleRelief(wi, rect->relief, rect->gradient, &r, rect->line_width); } else { ZnPoint p[5]; for (i = 0; i < 4; i++) { p[4-i].x = rect->dev[i].x; p[4-i].y = rect->dev[i].y; } p[0] = p[4]; ZnDrawPolygonRelief(wi, rect->relief, rect->gradient, p, 5, rect->line_width); } } else { ZnSetLineStyle(wi, rect->line_style); gc_mask = GCFillStyle|GCLineWidth|GCForeground|GCJoinStyle; values.foreground = ZnPixel(ZnGetGradientColor(rect->line_color, 0, NULL)); values.line_width = (rect->line_width == 1) ? 0 : rect->line_width; values.join_style = JoinMiter; if (ISCLEAR(rect->flags, ALIGNED_BIT)) { gc_mask |= GCCapStyle; values.cap_style = CapProjecting; } if (rect->line_pattern == ZnUnspecifiedImage) { values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } else { values.fill_style = FillStippled; values.stipple = ZnImagePixmap(rect->line_pattern, NULL); gc_mask |= GCStipple; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } if (ISSET(rect->flags, ALIGNED_BIT)) { XDrawRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y, r.width, r.height); } else { XDrawLines(wi->dpy, wi->draw_buffer, wi->gc, xp, 5, CoordModeOrigin); } } } } /* ********************************************************************************** * * Render -- * ********************************************************************************** */ #ifdef GLX static void RectRenderCB(void *closure) { RectangleItem rect = (RectangleItem) closure; glBegin(GL_TRIANGLE_STRIP); glVertex2f(rect->dev[0].x, rect->dev[0].y); glVertex2f(rect->dev[3].x, rect->dev[3].y); glVertex2f(rect->dev[1].x, rect->dev[1].y); glVertex2f(rect->dev[2].x, rect->dev[2].y); glEnd(); } #endif static void Render(Item item) { #ifdef GLX WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; XColor *color; int i, alpha; #ifdef GL_LIST if (!item->gl_list) { item->gl_list = glGenLists(1); glNewList(item->gl_list, GL_COMPILE); #endif if (ISSET(rect->flags, FILLED_BIT)) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (!ZnGradientFlat(rect->fill_color)) { ZnBool fast = (rect->fill_color->type == ZN_AXIAL_GRADIENT) && !rect->grad_geo; ZnPoly poly; POLY_CONTOUR1(&poly, rect->dev, 4, False); ZnRenderGradient(wi, rect->fill_color, fast ? NULL: RectRenderCB, rect, fast ? rect->dev : rect->grad_geo, &poly); } else { if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ ZnRenderTile(wi, rect->tile, rect->fill_color, RectRenderCB, rect, (ZnPoint *) &item->item_bounding_box); } else { if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ /* * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); glPolygonStipple(ZnImagePattern(rect->fill_pattern, NULL)); } color = ZnGetGradientColor(rect->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); RectRenderCB(rect); glDisable(GL_POLYGON_STIPPLE); } } } if (rect->line_width) { ZnPoint p[5]; for (i = 0; i < 4; i++) { p[4-i].x = rect->dev[i].x; p[4-i].y = rect->dev[i].y; } p[0] = p[4]; if (rect->relief != RELIEF_FLAT) { ZnRenderPolygonRelief(wi, rect->relief, rect->gradient, False, p, 5, rect->line_width); } else { ZnRenderPolyline(wi, p, 5, rect->line_width, rect->line_style, CapRound, JoinMiter, NULL, NULL, rect->line_color); } } #ifdef GL_LIST glEndList(); } glCallList(item->gl_list); #endif #endif } /* ********************************************************************************** * * IsSensitive -- * ********************************************************************************** */ static ZnBool IsSensitive(Item item, int item_part) { return (ISSET(item->flags, SENSITIVE_BIT) && item->parent->class->IsSensitive(item->parent, ZN_NO_PART)); } /* ********************************************************************************** * * Pick -- * ********************************************************************************** */ static double Pick(Item item, ZnPick ps) { RectangleItem rect = (RectangleItem) item; double best_dist; ZnPoint *p = ps->point; best_dist = PolygonToPointDist(rect->dev, 4, p); if (ISSET(rect->flags, FILLED_BIT)) { if (best_dist <= 0.0) { return 0.0; } } best_dist = ABS(best_dist); if (rect->line_width > 1) { double dist; int i; ZnPoint pts[5]; for (i = 0; i < 4; i++) { pts[i] = rect->dev[i]; } pts[4] = pts[0]; dist = PolylineToPointDist(pts, 5, rect->line_width, CapProjecting, JoinMiter, p); if (dist <= 0.0) { return 0.0; } best_dist = MIN(dist, best_dist); } return best_dist; } /* ********************************************************************************** * * PostScript -- * ********************************************************************************** */ static void PostScript(Item item, PostScriptInfo ps_info) { } /* ********************************************************************************** * * GetClipVertices -- * Get the clipping shape. * Never ever call TRI_FREE on the tristrip returned by GetClipVertices. * ********************************************************************************** */ static ZnBool GetClipVertices(Item item, ZnTriStrip *tristrip) { RectangleItem rect = (RectangleItem) item; ZnPoint *points; if (ISSET(rect->flags, ALIGNED_BIT)) { ZnListAssertSize(item->wi->work_pts, 2); points = (ZnPoint *) ZnListArray(item->wi->work_pts); TRI_STRIP1(tristrip, points, 2, False); tristrip->strips[0].fan = False; if (rect->dev[0].x < rect->dev[2].x) { points[0].x = rect->dev[0].x; points[1].x = rect->dev[2].x+1.0; } else { points[0].x = rect->dev[2].x; points[1].x = rect->dev[0].x+1.0; } if (rect->dev[0].y < rect->dev[2].y) { points[0].y = rect->dev[0].y; points[1].y = rect->dev[2].y+1.0; } else { points[0].y = rect->dev[2].y; points[1].y = rect->dev[0].y+1.0; } } else { TRI_STRIP1(tristrip, rect->dev, 4, False); } return ISSET(rect->flags, ALIGNED_BIT); } /* ********************************************************************************** * * Coords -- * Return or edit the item vertices. * ********************************************************************************** */ static int Coords(Item item, int contour, int index, int cmd, ZnPoint **pts, char **controls, int *num_pts) { RectangleItem rect = (RectangleItem) item; if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " rectangles can't add or remove vertices", NULL); return ZN_ERROR; } else if (cmd == COORDS_REPLACE_ALL) { if (*num_pts != 2) { Tcl_AppendResult(item->wi->interp, " coords command need 2 points on rectangles", NULL); return ZN_ERROR; } rect->coords[0] = (*pts)[0]; rect->coords[1] = (*pts)[1]; ITEM.Invalidate(item, ZN_COORDS_FLAG); } else if (cmd == COORDS_REPLACE) { if (*num_pts < 1) { Tcl_AppendResult(item->wi->interp, " coords command need at least 1 point", NULL); return ZN_ERROR; } if (index < 0) { index += 2; } if ((index < 0) || (index > 1)) { range_err: Tcl_AppendResult(item->wi->interp, " incorrect coord index, should be between -2 and 1", NULL); return ZN_ERROR; } rect->coords[index] = (*pts)[0]; ITEM.Invalidate(item, ZN_COORDS_FLAG); } else if (cmd == COORDS_READ_ALL) { *num_pts = 2; *pts = rect->coords; } else if (cmd == COORDS_READ) { if (index < 0) { index += 2; } if ((index < 0) || (index > 1)) { goto range_err; } *num_pts = 1; *pts = &rect->coords[index]; } return ZN_OK; } /* ********************************************************************************** * * GetAnchor -- * ********************************************************************************** */ static void GetAnchor(Item item, ZnAnchor anchor, ZnPoint *p) { ZnBBox *bbox = &item->item_bounding_box; Origin2Anchor(&bbox->orig, bbox->corner.x - bbox->orig.x, bbox->corner.y - bbox->orig.y, anchor, p); } /* ********************************************************************************** * * Exported functions struct -- * ********************************************************************************** */ static ItemClassStruct RECTANGLE_ITEM_CLASS = { sizeof(RectangleItemStruct), 0, /* num_parts */ False, /* has_anchors */ "rectangle", rect_attrs, Init, Clone, Destroy, Configure, Query, NULL, /* GetFieldSet */ GetAnchor, GetClipVertices, NULL, /* GetContours */ Coords, NULL, /* InsertChars */ NULL, /* DeleteChars */ NULL, /* Cursor */ NULL, /* Index */ NULL, /* Part */ NULL, /* Selection */ NULL, /* Contour */ ComputeCoordinates, ToArea, Draw, Render, IsSensitive, Pick, NULL, /* PickVertex */ PostScript }; ZnItemClassId ZnRectangle = (ZnItemClassId) &RECTANGLE_ITEM_CLASS;