diff options
Diffstat (limited to 'generic/Group.c')
-rw-r--r-- | generic/Group.c | 116 |
1 files changed, 74 insertions, 42 deletions
diff --git a/generic/Group.c b/generic/Group.c index d2f290b..8a32d30 100644 --- a/generic/Group.c +++ b/generic/Group.c @@ -234,12 +234,12 @@ SetXShape(Item grp) Item clip = ((GroupItem) grp)->clip; int i, j, num_pts, max_num_pts; ZnPos min_x, min_y, max_x, max_y; - ZnPoly poly; + ZnTriStrip tristrip; ZnPoint *p; ZnBool simple; ZnDim width, height; - XPoint *xpts, *xp; - Region reg; + XPoint xpts[3], *xp2, *xpts2; + Region reg, reg_op, reg_to; if (!wi->has_x_shape) { return; @@ -259,8 +259,10 @@ SetXShape(Item grp) /* * Get the clip shape. */ - simple = clip->class->GetClipVertices(clip, &poly); - if (simple || (poly.num_contours == 0)) { + tristrip.num_strips = 0; + tristrip.fan = False; + simple = clip->class->GetClipVertices(clip, &tristrip); + if (simple || (tristrip.num_strips == 0)) { /* * Nothing to do: after normalisation the rectangular shape will * fit exactly the window. We may test here if a shape is currently @@ -274,13 +276,17 @@ SetXShape(Item grp) else { /* * First make the vertices start at zero. + * In case of a fan we benefit from the fact that + * ALL the contour vertices are included in + * the tristrip, so we dont need to consider the + * center (arc in pie slice mode). */ - max_x = min_x = poly.contours[0].points[0].x; - max_y = min_y = poly.contours[0].points[0].y; - max_num_pts = poly.contours[0].num_points; - for (j = 0; j < poly.num_contours; j++) { - p = poly.contours[j].points; - num_pts = poly.contours[j].num_points; + max_x = min_x = tristrip.strips[0].points[0].x; + max_y = min_y = tristrip.strips[0].points[0].y; + max_num_pts = tristrip.strips[0].num_points; + for (j = 0; j < tristrip.num_strips; j++) { + p = tristrip.strips[j].points; + num_pts = tristrip.strips[j].num_points; if (num_pts > max_num_pts) { max_num_pts = num_pts; } @@ -299,44 +305,67 @@ SetXShape(Item grp) } } } - for (j = 0; j < poly.num_contours; j++) { - p = poly.contours[j].points; - num_pts = poly.contours[j].num_points; - for (i = 0; i < num_pts; i++, p++) { - p->x -= min_x; - p->y -= min_y; - } - } max_x -= min_x; max_y -= min_y; + XShapeCombineMask(wi->dpy, wi->full_reshape?ZnWindowId(wi->win):wi->real_top, + ShapeBounding, 0, 0, None, ShapeSet); + reg = XCreateRegion(); /* - * Now normalize the shape and map it to the window size. + * Now normalize the shape and map it to the window size, + * then Translate it in a region and apply this region to + * the window. */ width = wi->width + 2*wi->inset; height = wi->height + 2*wi->inset; - xpts = (XPoint *) ZnMalloc(max_num_pts * sizeof(XPoint)); - XShapeCombineMask(wi->dpy, wi->full_reshape?ZnWindowId(wi->win):wi->real_top, - ShapeBounding, 0, 0, None, ShapeSet); - XShapeCombineRegion(wi->dpy, wi->full_reshape?wi->real_top:ZnWindowId(wi->win), - ShapeBounding, 0, 0, None, ShapeSet); - for (j = 0; j < poly.num_contours; j++) { - p = poly.contours[j].points; - num_pts = poly.contours[j].num_points; - for (xp = xpts, i = 0; i < num_pts; i++, p++, xp++) { - xp->x = (short) (p->x * width / max_x); - xp->y = (short) (p->y * height / max_y); - } + for (j = 0; j < tristrip.num_strips; j++) { + p = tristrip.strips[j].points; + num_pts = tristrip.strips[j].num_points; + /* - * Translate it in a region and apply this region to the window. + * In case of a fan we benefit from the fact that + * ALL the contour vertices are included in + * the tristrip, so we can use the corresponding + * polygon instead of going through all the triangles. */ - reg = XPolygonRegion(xpts, num_pts, EvenOddRule); - XShapeCombineRegion(wi->dpy, wi->full_reshape?wi->real_top:ZnWindowId(wi->win), - ShapeBounding, 0, 0, reg, - poly.holes[j]?ShapeSubtract:ShapeUnion); - XDestroyRegion(reg); + if (tristrip.fan) { + xp2 = xpts2 = ZnMalloc(num_pts*sizeof(XPoint)); + for (i = 0 ; i < num_pts; i++, p++, xp2++) { + xp2->x = (short) ((p->x - min_x) * width / max_x); + xp2->y = (short) ((p->y - min_y) * height / max_y); + } + reg_op = XPolygonRegion(xpts2, num_pts, EvenOddRule); + reg_to = XCreateRegion(); + XUnionRegion(reg, reg_op, reg_to); + XDestroyRegion(reg); + XDestroyRegion(reg_op); + reg = reg_to; + ZnFree(xpts2); + } + else { + xpts[0].x = (short) ((p->x - min_x) * width / max_x); + xpts[0].y = (short) ((p->y - min_y) * height / max_y); + p++; + xpts[1].x = (short) ((p->x - min_x) * width / max_x); + xpts[1].y = (short) ((p->y - min_y) * height / max_y); + p++; + for (i = 2 ; i < num_pts; i++, p++) { + xpts[2].x = (short) ((p->x - min_x) * width / max_x); + xpts[2].y = (short) ((p->y - min_y) * height / max_y); + reg_op = XPolygonRegion(xpts, 3, EvenOddRule); + reg_to = XCreateRegion(); + XUnionRegion(reg, reg_op, reg_to); + XDestroyRegion(reg); + XDestroyRegion(reg_op); + reg = reg_to; + xpts[0] = xpts[1]; + xpts[1] = xpts[2]; + } + } } - ZnFree(xpts); + XShapeCombineRegion(wi->dpy, wi->full_reshape?wi->real_top:ZnWindowId(wi->win), + ShapeBounding, 0, 0, reg, ShapeSet); + XDestroyRegion(reg); } } #endif @@ -420,14 +449,14 @@ PushClip(GroupItem group, ZnBool set_gc) { WidgetInfo *wi = ((Item) group)->wi; - ZnPoly poly; + ZnTriStrip tristrip; ZnBool simple; if ((group->clip != ZN_NO_ITEM) && ((((Item) group) != wi->top_group) || !wi->reshape)) { - simple = group->clip->class->GetClipVertices(group->clip, &poly); + simple = group->clip->class->GetClipVertices(group->clip, &tristrip); /*printf("Group: PushClip group %d\n", ((Item) group)->id);*/ - ITEM_P.PushClip(wi, &poly, simple, set_gc); + ITEM_P.PushClip(wi, &tristrip, simple, set_gc); } } @@ -861,8 +890,10 @@ Render(Item item) GroupItem group = (GroupItem) item; Item current_item; WidgetInfo *wi = item->wi; +#if 0 ZnBBox *clip_box; ZnBBox bbox, old_damaged_area; +#endif unsigned char save_alpha = wi->alpha; wi->alpha = wi->alpha * group->alpha / 100; @@ -1142,6 +1173,7 @@ static ItemClassStruct GROUP_ITEM_CLASS = { NULL, /* GetFieldSet */ NULL, /* GetAnchor */ NULL, /* GetClipVertices */ + NULL, /* GetContours */ Coords, NULL, /* InsertChars */ NULL, /* DeleteChars */ |