From 507c2d377d80f9cfb36558b61b9d7cf4bd73d8f6 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 10 Jun 2002 13:09:22 +0000 Subject: L'item Icon supporte la rotation et le redimensionnement. --- generic/Icon.c | 184 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 124 insertions(+), 60 deletions(-) diff --git a/generic/Icon.c b/generic/Icon.c index d9219f6..9029b6c 100644 --- a/generic/Icon.c +++ b/generic/Icon.c @@ -58,7 +58,7 @@ typedef struct _IconItemStruct { * is always meaningful). */ /* Private data */ - ZnPoint pos_dev; + ZnPoint dev[4]; } IconItemStruct, *IconItem; @@ -123,8 +123,8 @@ Init(Item item, 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); + CLEAR(item->flags, COMPOSE_ROTATION_BIT); + CLEAR(item->flags, COMPOSE_SCALE_BIT); item->priority = DEFAULT_ICON_PRIORITY; icon->pos.x = icon->pos.y = 0.0; @@ -212,6 +212,11 @@ Configure(Item item, } } + if (!item->wi->render) { + CLEAR(item->flags, COMPOSE_ROTATION_BIT); + CLEAR(item->flags, COMPOSE_SCALE_BIT); + } + return ZN_OK; } @@ -264,30 +269,66 @@ ComputeCoordinates(Item item, ZnSizeOfImage(icon->image, &width, &height); } - /* - * The connected item support anchors, this is checked by - * configure. - */ - if (item->connected_item != ZN_NO_ITEM) { - item->connected_item->class->GetAnchor(item->connected_item, - icon->connection_anchor, - &icon->pos_dev); + if (wi->render) { + ZnPoint pos, quad[4]; + int i; + + /* + * The connected item support anchors, this is checked by + * configure. + */ + if (item->connected_item != ZN_NO_ITEM) { + ZnTransfo t; + + item->connected_item->class->GetAnchor(item->connected_item, + icon->connection_anchor, quad); + ZnTransfoInvert(wi->current_transfo, &t); + ZnTransformPoint(&t, quad, &pos); + } + else { + pos = icon->pos; + } + Anchor2Origin(&pos, width, height, icon->anchor, quad); + quad[1].x = quad[0].x; + quad[1].y = quad[0].y + height; + quad[2].x = quad[0].x + width; + quad[2].y = quad[1].y; + quad[3].x = quad[2].x; + quad[3].y = quad[0].y; + 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); + } + + /* + * Compute the bounding box. + */ + AddPointsToBBox(&item->item_bounding_box, icon->dev, 4); } else { - ZnTransformPoint(wi->current_transfo, &icon->pos, &icon->pos_dev); + if (item->connected_item != ZN_NO_ITEM) { + item->connected_item->class->GetAnchor(item->connected_item, + icon->connection_anchor, + icon->dev); + } + else { + 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); + + /* + * 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); } - - Anchor2Origin(&icon->pos_dev, width, height, icon->anchor, - &icon->pos_dev); - icon->pos_dev.x = REAL_TO_INT(icon->pos_dev.x); - icon->pos_dev.y = REAL_TO_INT(icon->pos_dev.y); - /* - * Compute the bounding box. - */ - AddPointToBBox(&item->item_bounding_box, icon->pos_dev.x, icon->pos_dev.y); - AddPointToBBox(&item->item_bounding_box, icon->pos_dev.x+width, - icon->pos_dev.y+height); item->item_bounding_box.orig.x -= 1.0; item->item_bounding_box.orig.y -= 1.0; item->item_bounding_box.corner.x += 1.0; @@ -315,16 +356,23 @@ ToArea(Item item, { IconItem icon = (IconItem) item; ZnBBox box, *area = ta->area; - int w, h; - box.orig = icon->pos_dev; if (icon->image != ZnUnspecifiedImage) { + return -1; + } + if (item->wi->render) { + return PolygonInBBox(icon->dev, 4, ta->area, NULL); + } + else { + int w, h; + + box.orig = *icon->dev; ZnSizeOfImage(icon->image, &w, &h); + box.corner.x = box.orig.x + w; + box.corner.y = box.orig.y + h; + + return BBoxInBBox(&box, area); } - box.corner.x = box.orig.x + w; - box.corner.y = box.orig.y + h; - - return BBoxInBBox(&box, area); } @@ -353,9 +401,9 @@ Draw(Item item) } ZnSizeOfImage(icon->image, &w, &h); - box.orig = icon->pos_dev; - box.corner.x = icon->pos_dev.x + w; - box.corner.y = icon->pos_dev.y + h; + box.orig = *icon->dev; + box.corner.x = icon->dev->x + w; + box.corner.y = icon->dev->y + h; if (!ZnImageIsBitmap(icon->image)) { /* * Added the case of a rectangular aligned clipping and the @@ -376,12 +424,12 @@ Draw(Item item) if (mask_pmap == ZnUnspecifiedImage || simple) { if (mask_pmap != ZnUnspecifiedImage) { XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->pos_dev.x; - values.clip_y_origin = (int) icon->pos_dev.y; + 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->pos_dev.x, box.orig.y-icon->pos_dev.y, + 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; @@ -399,8 +447,8 @@ Draw(Item item) XSetRegion(wi->dpy, gc, clip_region); values.foreground = 1; values.background = 0; - values.clip_x_origin = (int) -icon->pos_dev.x; - values.clip_y_origin = (int) -icon->pos_dev.y; + 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); @@ -410,11 +458,11 @@ Draw(Item item) * Drawing of the icon using the mask. */ XSetClipMask(wi->dpy, wi->gc, mask_pmap); - values.clip_x_origin = (int) icon->pos_dev.x; - values.clip_y_origin = (int) icon->pos_dev.y; + 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->pos_dev.x, box.orig.y-icon->pos_dev.y, + 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; @@ -432,8 +480,8 @@ Draw(Item item) } values.fill_style = FillStippled; values.stipple = pixmap; - values.ts_x_origin = icon->pos_dev.x; - values.ts_y_origin = icon->pos_dev.y; + values.ts_x_origin = icon->dev->x; + values.ts_y_origin = icon->dev->y; values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0, NULL)); gc_mask |= GCFillStyle | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCForeground; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); @@ -457,9 +505,9 @@ Render(Item item) #ifdef GLX WidgetInfo *wi = item->wi; IconItem icon = (IconItem) item; - + if (icon->image != ZnUnspecifiedImage) { - ZnRenderImage(wi, icon->image, icon->color, &icon->pos_dev, + ZnRenderImage(wi, icon->image, icon->color, icon->dev, ZnImageIsBitmap(icon->image)); } #endif @@ -501,10 +549,10 @@ Pick(Item item, dist = RectangleToPointDist(&item->item_bounding_box, p); /* - * If inside the bounding box, try to see if the point + * If inside the icon rectangle, try to see if the point * is actually on the image or not. If it lies in an - * area that is between pick_aperture+1 around the bbox - * and the actual shape, the distance will be reported + * area that is between pick_aperture+1 around the external + * rectangle and the actual shape, the distance will be reported * as pick_aperture+1. Inside the actual shape it will be * reported as 0. This is a kludge, there is currently * no means to compute the real distance in the icon's @@ -516,8 +564,8 @@ Pick(Item item, char *bpixels; dist = 0.0; - dp.x = p->x - icon->pos_dev.x; - dp.y = p->y - icon->pos_dev.y; + dp.x = p->x - icon->dev->x; + dp.y = p->y - icon->dev->y; if (icon->image != ZnUnspecifiedImage) { ZnSizeOfImage(icon->image, &w, &h); bpixels = ZnImagePattern(icon->image, &stride); @@ -535,6 +583,10 @@ Pick(Item item, else { return dist; } + /* BUG: when images can be scaled/rotated (openGL) this doesn't. + * work. We must compute the invert transform and find the point + * coordinate in the image space. + */ x = (int) dp.x; y = (int) dp.y; if (! ZnGetBitmapPixel(bpixels, stride, x, y)) { @@ -579,11 +631,16 @@ GetAnchor(Item item, int w=0, h=0; if (icon->image == ZnUnspecifiedImage) { - p->x = p->y = 0.0; + *p = *icon->dev; } else { ZnSizeOfImage(icon->image, &w, &h); - Origin2Anchor(&icon->pos_dev, w, h, anchor, p); + if (item->wi->render) { + Origin2Anchor(&item->item_bounding_box.orig, w, h, anchor, p); + } + else { + Origin2Anchor(icon->dev, w, h, anchor, p); + } } } @@ -605,17 +662,24 @@ GetClipVertices(Item item, int w=0, h=0; ZnPoint *points; - ZnListAssertSize(item->wi->work_pts, 2); - if (icon->image != ZnUnspecifiedImage) { - ZnSizeOfImage(icon->image, &w, &h); + if (item->wi->render) { + TRI_STRIP1(tristrip, icon->dev, 4); + + return False; } - points = (ZnPoint *) ZnListArray(item->wi->work_pts); - TRI_STRIP1(tristrip, points, 2); - points[0] = icon->pos_dev; - points[1].x = points[0].x + w; - points[1].y = points[0].y + h; + else { + ZnListAssertSize(item->wi->work_pts, 2); + if (icon->image != ZnUnspecifiedImage) { + ZnSizeOfImage(icon->image, &w, &h); + } + points = ZnListArray(item->wi->work_pts); + TRI_STRIP1(tristrip, points, 2); + points[0] = *icon->dev; + points[1].x = points[0].x + w; + points[1].y = points[0].y + h; - return True; + return True; + } } -- cgit v1.1