From 3261805fee19e346b4d1f84b23816daa1628764a Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 16 Apr 2003 09:49:22 +0000 Subject: Update from the Windows port and general cleanup/restructure --- generic/Icon.c | 308 +++++++++++++++++++++++++++------------------------------ 1 file changed, 144 insertions(+), 164 deletions(-) (limited to 'generic/Icon.c') diff --git a/generic/Icon.c b/generic/Icon.c index a16acaf..a1bd7a1 100644 --- a/generic/Icon.c +++ b/generic/Icon.c @@ -25,8 +25,6 @@ */ -#include - #include "Item.h" #include "Geo.h" #include "Draw.h" @@ -47,14 +45,14 @@ static const char compile_id[] = "$Compile: " __FILE__ " " __DATE__ " " __TIME__ ********************************************************************************** */ typedef struct _IconItemStruct { - ItemStruct header; + ZnItemStruct header; /* Public data */ ZnPoint pos; ZnImage image; - ZnAnchor anchor; - ZnAnchor connection_anchor; - ZnGradient *color; /* Used only if the image is a bitmap (in GLX alpha part + Tk_Anchor anchor; + Tk_Anchor connection_anchor; + ZnGradient *color; /* Used only if the image is a bitmap (in GL alpha part * is always meaningful). */ /* Private data */ @@ -68,13 +66,13 @@ static ZnAttrConfig icon_attrs[] = { { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(IconItemStruct, color), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composealpha", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_ALPHA_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_ALPHA_BIT, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_ROTATION_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-composescale", NULL, - Tk_Offset(IconItemStruct, header.flags), COMPOSE_SCALE_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_COMPOSE_SCALE_BIT, ZN_COORDS_FLAG, False }, { ZN_CONFIG_ITEM, "-connecteditem", NULL, Tk_Offset(IconItemStruct, header.connected_item), 0, @@ -91,15 +89,15 @@ static ZnAttrConfig icon_attrs[] = { Tk_Offset(IconItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_BOOL, "-sensitive", NULL, - Tk_Offset(IconItemStruct, header.flags), SENSITIVE_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_SENSITIVE_BIT, ZN_REPICK_FLAG, False }, { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(IconItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, - Tk_Offset(IconItemStruct, header.flags), VISIBLE_BIT, + Tk_Offset(IconItemStruct, header.flags), ZN_VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, - { ZN_CONFIG_END, NULL, NULL, 0, 0, 0 } + { ZN_CONFIG_END, NULL, NULL, 0, 0, 0, False } }; @@ -112,28 +110,28 @@ static ZnAttrConfig icon_attrs[] = { ********************************************************************************** */ static int -Init(Item item, - int *argc, - Tcl_Obj *CONST *args[]) +Init(ZnItem item, + int *argc __unused, + Tcl_Obj *CONST *args[] __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; /* 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_ICON_PRIORITY; + SET(item->flags, ZN_VISIBLE_BIT); + SET(item->flags, ZN_SENSITIVE_BIT); + SET(item->flags, ZN_COMPOSE_ALPHA_BIT); + SET(item->flags, ZN_COMPOSE_ROTATION_BIT); + SET(item->flags, ZN_COMPOSE_SCALE_BIT); + item->priority = 1; icon->pos.x = icon->pos.y = 0.0; icon->image = ZnUnspecifiedImage; - icon->anchor = ZnAnchorNW; - icon->connection_anchor = ZnAnchorSW; + icon->anchor = TK_ANCHOR_NW; + icon->connection_anchor = TK_ANCHOR_SW; icon->color = ZnGetGradientByValue(wi->fore_color); - return ZN_OK; + return TCL_OK; } @@ -145,7 +143,7 @@ Init(Item item, ********************************************************************************** */ static void -Clone(Item item) +Clone(ZnItem item) { IconItem icon = (IconItem) item; @@ -164,7 +162,7 @@ Clone(Item item) ********************************************************************************** */ static void -Destroy(Item item) +Destroy(ZnItem item) { IconItem icon = (IconItem) item; @@ -184,17 +182,17 @@ Destroy(Item item) ********************************************************************************** */ static int -Configure(Item item, +Configure(ZnItem item, int argc, Tcl_Obj *CONST argv[], int *flags) { - Item old_connected; + ZnItem old_connected; old_connected = item->connected_item; if (ZnConfigureAttributes(item->wi, item, icon_attrs, - argc, argv, flags) == ZN_ERROR) { - return ZN_ERROR; + argc, argv, flags) == TCL_ERROR) { + return TCL_ERROR; } if (ISSET(*flags, ZN_ITEM_FLAG)) { @@ -205,14 +203,14 @@ Configure(Item item, if ((item->connected_item == ZN_NO_ITEM) || (item->connected_item->class->has_anchors && (item->parent == item->connected_item->parent))) { - ITEM.UpdateItemDependency(item, old_connected); + ZnITEM.UpdateItemDependency(item, old_connected); } else { item->connected_item = old_connected; } } - return ZN_OK; + return TCL_OK; } @@ -224,15 +222,15 @@ Configure(Item item, ********************************************************************************** */ static int -Query(Item item, - int argc, +Query(ZnItem item, + int argc __unused, Tcl_Obj *CONST argv[]) { - if (ZnQueryAttribute(item->wi, item, icon_attrs, argv[0]) == ZN_ERROR) { - return ZN_ERROR; + if (ZnQueryAttribute(item->wi, item, icon_attrs, argv[0]) == TCL_ERROR) { + return TCL_ERROR; } - return ZN_OK; + return TCL_OK; } @@ -244,14 +242,14 @@ Query(Item item, ********************************************************************************** */ static void -ComputeCoordinates(Item item, - ZnBool force) +ComputeCoordinates(ZnItem item, + ZnBool force __unused) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; int width, height; - ResetBBox(&item->item_bounding_box); + ZnResetBBox(&item->item_bounding_box); /* * If there is no image then nothing to show. @@ -283,7 +281,7 @@ ComputeCoordinates(Item item, else { pos = icon->pos; } - Anchor2Origin(&pos, width, height, icon->anchor, quad); + ZnAnchor2Origin(&pos, (ZnReal) width, (ZnReal) height, icon->anchor, quad); quad[1].x = quad[0].x; quad[1].y = quad[0].y + height; quad[2].x = quad[0].x + width; @@ -293,14 +291,14 @@ ComputeCoordinates(Item item, ZnTransformPoints(wi->current_transfo, quad, icon->dev, 4); for (i = 0; i < 4; i++) { - icon->dev[i].x = REAL_TO_INT(icon->dev[i].x); - icon->dev[i].y = REAL_TO_INT(icon->dev[i].y); + icon->dev[i].x = ZnNearestInt(icon->dev[i].x); + icon->dev[i].y = ZnNearestInt(icon->dev[i].y); } /* * Compute the bounding box. */ - AddPointsToBBox(&item->item_bounding_box, icon->dev, 4); + ZnAddPointsToBBox(&item->item_bounding_box, icon->dev, 4); } else { if (item->connected_item != ZN_NO_ITEM) { @@ -312,16 +310,16 @@ ComputeCoordinates(Item item, ZnTransformPoint(wi->current_transfo, &icon->pos, icon->dev); } - Anchor2Origin(icon->dev, width, height, icon->anchor, icon->dev); - icon->dev->x = REAL_TO_INT(icon->dev->x); - icon->dev->y = REAL_TO_INT(icon->dev->y); + ZnAnchor2Origin(icon->dev, (ZnReal) width, (ZnReal) height, icon->anchor, icon->dev); + icon->dev->x = ZnNearestInt(icon->dev->x); + icon->dev->y = ZnNearestInt(icon->dev->y); /* * Compute the bounding box. */ - AddPointToBBox(&item->item_bounding_box, icon->dev->x, icon->dev->y); - AddPointToBBox(&item->item_bounding_box, icon->dev->x+width, - icon->dev->y+height); + ZnAddPointToBBox(&item->item_bounding_box, icon->dev->x, icon->dev->y); + ZnAddPointToBBox(&item->item_bounding_box, icon->dev->x+width, + icon->dev->y+height); } item->item_bounding_box.orig.x -= 1.0; @@ -332,7 +330,7 @@ ComputeCoordinates(Item item, /* * Update connected items. */ - SET(item->flags, UPDATE_DEPENDENT_BIT); + SET(item->flags, ZN_UPDATE_DEPENDENT_BIT); } @@ -346,7 +344,7 @@ ComputeCoordinates(Item item, ********************************************************************************** */ static int -ToArea(Item item, +ToArea(ZnItem item, ZnToArea ta) { IconItem icon = (IconItem) item; @@ -356,7 +354,7 @@ ToArea(Item item, return -1; } if (item->wi->render) { - return PolygonInBBox(icon->dev, 4, ta->area, NULL); + return ZnPolygonInBBox(icon->dev, 4, ta->area, NULL); } else { int w, h; @@ -366,7 +364,7 @@ ToArea(Item item, box.corner.x = box.orig.x + w; box.corner.y = box.orig.y + h; - return BBoxInBBox(&box, area); + return ZnBBoxInBBox(&box, area); } } @@ -379,17 +377,17 @@ ToArea(Item item, ********************************************************************************** */ static void -Draw(Item item) +Draw(ZnItem item) { - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; XGCValues values; - int gc_mask = 0; + unsigned int gc_mask = 0; int w, h; ZnBBox box, inter, *clip_box; - Region clip_region; + TkRegion clip_region, photo_region, clip; ZnBool simple; - Pixmap pixmap, mask_pmap; + Pixmap pixmap; if (icon->image == ZnUnspecifiedImage) { return; @@ -401,88 +399,65 @@ Draw(Item item) box.corner.y = icon->dev->y + h; if (!ZnImageIsBitmap(icon->image)) { /* - * Added the case of a rectangular aligned clipping and the - * simple case of the damaged area clip. These are done here - * to avoid the use of Tk_RedrawImage which use a different - * GC and lead to wrong clip behaviour. - * - * Non rectangular clipping. Two cases here: if the image - * has no contour mask, simply use the clipping set in the - * current gc, if not, we have to generate a bitmap mask - * using the image mask and the current clip and use this - * bitmap as the current clip. + * The code below does not use of Tk_RedrawImage to be + * able to clip with the current clip region. */ - IntersectBBox(&box, &wi->damaged_area, &inter); + ZnIntersectBBox(&box, &wi->damaged_area, &inter); box = inter; ZnCurrentClip(wi, &clip_region, NULL, &simple); - pixmap = ZnImagePixmap(icon->image, &mask_pmap); - if (mask_pmap == ZnUnspecifiedImage || simple) { - if (mask_pmap != ZnUnspecifiedImage) { - XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->dev->x; - values.clip_y_origin = (int) icon->dev->y; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - } - XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, - box.orig.x-icon->dev->x, box.orig.y-icon->dev->y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y, - box.orig.x, box.orig.y); - values.clip_x_origin = values.clip_y_origin = 0; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XSetRegion(wi->dpy, wi->gc, clip_region); + pixmap = ZnImagePixmap(icon->image); + photo_region = ZnImageRegion(icon->image); + clip = TkCreateRegion(); + /* + * ZnImageRegion may fail: perl/Tk 800.24 doesn't support + * some internal TkPhoto functions. + * This is a workaround using a rectangular region based + * on the image size. + */ + if (photo_region == NULL) { + XRectangle rect; + rect.x = rect.y = 0; + rect.width = w; + rect.height = h; + TkUnionRectWithRegion(&rect, clip, clip); } else { - GC gc; - /* - * Build of the mask - */ - Pixmap mask_pmap = XCreatePixmap(wi->dpy, ZnWindowId(wi->win), w, h, 1); - gc = XCreateGC(wi->dpy, mask_pmap, 0, NULL); - XFillRectangle(wi->dpy, mask_pmap, gc, 0, 0, w, h); - XSetRegion(wi->dpy, gc, clip_region); - values.foreground = 1; - values.background = 0; - values.clip_x_origin = (int) -icon->dev->x; - values.clip_y_origin = (int) -icon->dev->y; - XChangeGC(wi->dpy, gc, - GCForeground|GCBackground|GCClipXOrigin|GCClipYOrigin, - &values); - XPutImage(wi->dpy, mask_pmap, gc, ZnImageMask(icon->image), 0, 0, 0, 0, w, h); - XFreeGC(wi->dpy, gc); - /* - * Drawing of the icon using the mask. - */ - XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->dev->x; - values.clip_y_origin = (int) icon->dev->y; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, - box.orig.x-icon->dev->x, box.orig.y-icon->dev->y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y, - box.orig.x, box.orig.y); - values.clip_x_origin = values.clip_y_origin = 0; - XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XSetRegion(wi->dpy, wi->gc, clip_region); - XFreePixmap(wi->dpy, mask_pmap); + ZnUnionRegion(clip, photo_region, clip); } + ZnOffsetRegion(clip, (int) icon->dev->x, (int) icon->dev->y); + TkIntersectRegion(clip_region, clip, clip); + TkSetRegion(wi->dpy, wi->gc, clip); + XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, + (int) (box.orig.x-icon->dev->x), + (int) (box.orig.y-icon->dev->y), + (unsigned int) (box.corner.x-box.orig.x), + (unsigned int) (box.corner.y-box.orig.y), + (int) box.orig.x, + (int) box.orig.y); + values.clip_x_origin = values.clip_y_origin = 0; + XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); + TkSetRegion(wi->dpy, wi->gc, clip_region); + TkDestroyRegion(clip); } else { - pixmap = ZnImagePixmap(icon->image, NULL); + pixmap = ZnImagePixmap(icon->image); ZnCurrentClip(wi, NULL, &clip_box, &simple); if (simple) { - IntersectBBox(&box, clip_box, &inter); + ZnIntersectBBox(&box, clip_box, &inter); box = inter; } values.fill_style = FillStippled; values.stipple = pixmap; - values.ts_x_origin = icon->dev->x; - values.ts_y_origin = icon->dev->y; - values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0, NULL)); + values.ts_x_origin = (int) icon->dev->x; + values.ts_y_origin = (int) icon->dev->y; + values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0.0, NULL)); gc_mask |= GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCForeground; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, - box.orig.x, box.orig.y, - box.corner.x-box.orig.x, box.corner.y-box.orig.y); + (int) box.orig.x, + (int) box.orig.y, + (unsigned int) (box.corner.x-box.orig.x), + (unsigned int) (box.corner.y-box.orig.y)); } } @@ -494,19 +469,24 @@ Draw(Item item) * ********************************************************************************** */ +#ifdef GL static void -Render(Item item) +Render(ZnItem item) { -#ifdef GLX - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; IconItem icon = (IconItem) item; if (icon->image != ZnUnspecifiedImage) { ZnRenderImage(wi, icon->image, icon->color, icon->dev, ZnImageIsBitmap(icon->image)); } -#endif } +#else +static void +Render(ZnItem item __unused) +{ +} +#endif /* @@ -517,10 +497,10 @@ Render(Item item) ********************************************************************************** */ static ZnBool -IsSensitive(Item item, - int item_part) +IsSensitive(ZnItem item, + int item_part __unused) { - return (ISSET(item->flags, SENSITIVE_BIT) && + return (ISSET(item->flags, ZN_SENSITIVE_BIT) && item->parent->class->IsSensitive(item->parent, ZN_NO_PART)); } @@ -533,16 +513,16 @@ IsSensitive(Item item, ********************************************************************************** */ static double -Pick(Item item, +Pick(ZnItem item, ZnPick ps) { IconItem icon = (IconItem) item; - WidgetInfo *wi = item->wi; + ZnWInfo *wi = item->wi; double dist; double off_dist = MAX(1, wi->pick_aperture+1); ZnPoint *p = ps->point; - dist = RectangleToPointDist(&item->item_bounding_box, p); + dist = ZnRectangleToPointDist(&item->item_bounding_box, p); /* * If inside the icon rectangle, try to see if the point * is actually on the image or not. If it lies in an @@ -563,7 +543,7 @@ Pick(Item item, dp.y = p->y - icon->dev->y; if (icon->image != ZnUnspecifiedImage) { ZnSizeOfImage(icon->image, &w, &h); - bpixels = ZnImagePattern(icon->image, &stride); + bpixels = ZnImageMask(icon->image, &stride); if (!bpixels) { /* * The image has no bitmap pattern @@ -604,8 +584,8 @@ Pick(Item item, ********************************************************************************** */ static void -PostScript(Item item, - PostScriptInfo ps_info) +PostScript(ZnItem item __unused, + ZnPostScriptInfo ps_info __unused) { } @@ -618,8 +598,8 @@ PostScript(Item item, ********************************************************************************** */ static void -GetAnchor(Item item, - ZnAnchor anchor, +GetAnchor(ZnItem item, + Tk_Anchor anchor, ZnPoint *p) { IconItem icon = (IconItem) item; @@ -629,10 +609,10 @@ GetAnchor(Item item, } else { ZnBBox *bbox = &item->item_bounding_box; - Origin2Anchor(&bbox->orig, - bbox->corner.x - bbox->orig.x, - bbox->corner.y - bbox->orig.y, - anchor, p); + ZnOrigin2Anchor(&bbox->orig, + bbox->corner.x - bbox->orig.x, + bbox->corner.y - bbox->orig.y, + anchor, p); } } @@ -642,12 +622,12 @@ GetAnchor(Item item, * * GetClipVertices -- * Get the clipping shape. - * Never ever call TRI_FREE on the tristrip returned by GetClipVertices. + * Never ever call ZnTriFree on the tristrip returned by GetClipVertices. * ********************************************************************************** */ static ZnBool -GetClipVertices(Item item, +GetClipVertices(ZnItem item, ZnTriStrip *tristrip) { IconItem icon = (IconItem) item; @@ -655,7 +635,7 @@ GetClipVertices(Item item, ZnPoint *points; if (item->wi->render) { - TRI_STRIP1(tristrip, icon->dev, 4, False); + ZnTriStrip1(tristrip, icon->dev, 4, False); return False; } @@ -665,7 +645,7 @@ GetClipVertices(Item item, ZnSizeOfImage(icon->image, &w, &h); } points = ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2, False); + ZnTriStrip1(tristrip, points, 2, False); points[0] = *icon->dev; points[1].x = points[0].x + w; points[1].y = points[0].y + h; @@ -686,35 +666,35 @@ GetClipVertices(Item item, ********************************************************************************** */ static int -Coords(Item item, - int contour, - int index, - int cmd, - ZnPoint **pts, - char **controls, - int *num_pts) +Coords(ZnItem item, + int contour __unused, + int index __unused, + int cmd, + ZnPoint **pts, + char **controls __unused, + unsigned int *num_pts) { IconItem icon = (IconItem) item; - if ((cmd == COORDS_ADD) || (cmd == COORDS_ADD_LAST) || (cmd == COORDS_REMOVE)) { + if ((cmd == ZN_COORDS_ADD) || (cmd == ZN_COORDS_ADD_LAST) || (cmd == ZN_COORDS_REMOVE)) { Tcl_AppendResult(item->wi->interp, " icons can't add or remove vertices", NULL); - return ZN_ERROR; + return TCL_ERROR; } - else if ((cmd == COORDS_REPLACE) || (cmd == COORDS_REPLACE_ALL)) { + else if ((cmd == ZN_COORDS_REPLACE) || (cmd == ZN_COORDS_REPLACE_ALL)) { if (*num_pts == 0) { Tcl_AppendResult(item->wi->interp, " coords command need 1 point on icons", NULL); - return ZN_ERROR; + return TCL_ERROR; } icon->pos = (*pts)[0]; - ITEM.Invalidate(item, ZN_COORDS_FLAG); + ZnITEM.Invalidate(item, ZN_COORDS_FLAG); } - else if ((cmd == COORDS_READ) || (cmd == COORDS_READ_ALL)) { + else if ((cmd == ZN_COORDS_READ) || (cmd == ZN_COORDS_READ_ALL)) { *num_pts = 1; *pts = &icon->pos; } - return ZN_OK; + return TCL_OK; } @@ -725,7 +705,7 @@ Coords(Item item, * ********************************************************************************** */ -static ItemClassStruct ICON_ITEM_CLASS = { +static ZnItemClassStruct ICON_ITEM_CLASS = { sizeof(IconItemStruct), 0, /* num_parts */ True, /* has_anchors */ -- cgit v1.1