aboutsummaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
authorlecoanet2000-05-11 13:58:17 +0000
committerlecoanet2000-05-11 13:58:17 +0000
commitf0ebc4f3affbac34920f7be557312927e6cf8a81 (patch)
tree99f96d06ee7a903c1df7793802fcf337c14d45c5 /generic
parent9663a916b72352db78f2d17d5268c1018904f967 (diff)
downloadtkzinc-f0ebc4f3affbac34920f7be557312927e6cf8a81.zip
tkzinc-f0ebc4f3affbac34920f7be557312927e6cf8a81.tar.gz
tkzinc-f0ebc4f3affbac34920f7be557312927e6cf8a81.tar.bz2
tkzinc-f0ebc4f3affbac34920f7be557312927e6cf8a81.tar.xz
Adaptation suite � la r�alisation des polygones multi-contours.
Diffstat (limited to 'generic')
-rw-r--r--generic/Group.c119
-rw-r--r--generic/Icon.c27
-rw-r--r--generic/Rectangle.c46
-rw-r--r--generic/Tabular.c28
-rw-r--r--generic/Text.c24
5 files changed, 137 insertions, 107 deletions
diff --git a/generic/Group.c b/generic/Group.c
index bc636be..029e32c 100644
--- a/generic/Group.c
+++ b/generic/Group.c
@@ -229,9 +229,10 @@ SetXShape(Item grp)
#ifdef SHAPE
WidgetInfo *wi = grp->wi;
Item clip = ((GroupItem) grp)->clip;
- int i, num_pts;
+ int i, j, num_pts, max_num_pts;
ZnPos min_x, min_y, max_x, max_y;
- ZnPoint *pts, *p;
+ ZnPoly poly;
+ ZnPoint *p;
ZnBool simple;
ZnDim width, height;
XPoint *xpts, *xp;
@@ -255,8 +256,8 @@ SetXShape(Item grp)
/*
* Get the clip shape.
*/
- simple = clip->class->GetClipVertices(clip, &pts, &num_pts);
- if (simple || (num_pts == 0)) {
+ simple = clip->class->GetClipVertices(clip, &poly);
+ if (simple || (poly.num_contours == 0)) {
/*
* Nothing to do: after normalisation the rectangular shape will
* fit exactly the window. We may test here if a shape is currently
@@ -271,53 +272,67 @@ SetXShape(Item grp)
/*
* First make the vertices start at zero.
*/
- p = &pts[0];
- min_x = p->x;
- min_y = p->y;
- p++;
- for (i = 1; i < num_pts; p++, i++) {
- if (p->x < min_x) {
- min_x = p->x;
+ 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;
+ if (num_pts > max_num_pts) {
+ max_num_pts = num_pts;
}
- if (p->y < min_y) {
- min_y = p->y;
+ for (i = 0; i < num_pts; p++, i++) {
+ if (p->x < min_x) {
+ min_x = p->x;
+ }
+ if (p->y < min_y) {
+ min_y = p->y;
+ }
+ if (p->x > max_x) {
+ max_x = p->x;
+ }
+ if (p->y > max_y) {
+ max_y = p->y;
+ }
}
}
- for (p = &pts[0], i = 0; i < num_pts; i++, p++) {
- p->x -= min_x;
- p->y -= min_y;
+ 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;
+
/*
* Now normalize the shape and map it to the window size.
*/
- p = &pts[0];
- max_x = p->x;
- max_y = p->y;
- p++;
- for (i = 1; i < num_pts; p++, i++) {
- if (p->x > max_x) {
- max_x = p->x;
- }
- if (p->y > max_y) {
- max_y = p->y;
- }
- }
width = wi->width + 2*wi->border_width;
height = wi->height + 2*wi->border_width;
- xpts = (XPoint *) ZnMalloc(num_pts * sizeof(XPoint));
- for (p = &pts[0], 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);
- }
- /*
- * Translate it in a region and apply this region to the window.
- */
- reg = XPolygonRegion(xpts, num_pts, EvenOddRule);
- XShapeCombineMask(wi->dpy, wi->full_reshape ? ZnWindowId(wi->win) : wi->real_top,
+ 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, reg, ShapeSet);
- XDestroyRegion(reg);
+ 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);
+ }
+ /*
+ * Translate it in a region and apply this region to the window.
+ */
+ 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);
+ }
ZnFree(xpts);
}
}
@@ -402,15 +417,14 @@ PushClip(GroupItem group,
ZnBool set_gc)
{
WidgetInfo *wi = ((Item) group)->wi;
- int num_pts;
- ZnPoint *pts;
+ ZnPoly poly;
ZnBool simple;
if ((group->clip != ZN_NO_ITEM) &&
((((Item) group) != wi->top_group) || !wi->reshape)) {
- simple = group->clip->class->GetClipVertices(group->clip, &pts, &num_pts);
+ simple = group->clip->class->GetClipVertices(group->clip, &poly);
/*printf("Group: PushClip group %d\n", ((Item) group)->id);*/
- ITEM_P.PushClip(wi, pts, num_pts, simple, set_gc);
+ ITEM_P.PushClip(wi, &poly, simple, set_gc);
}
}
@@ -980,6 +994,7 @@ Pick(Item item,
*/
static int
Coords(Item item,
+ int contour,
int index,
int cmd,
ZnPoint **pts,
@@ -1038,9 +1053,9 @@ PostScript(Item item,
*/
static ItemClassStruct GROUP_ITEM_CLASS = {
sizeof(GroupItemStruct),
- False,
- False,
- False,
+ False, /* has_fields */
+ False, /* has_parts */
+ False, /* has_anchors */
"group",
group_attrs,
Init,
@@ -1048,15 +1063,17 @@ static ItemClassStruct GROUP_ITEM_CLASS = {
Destroy,
Configure,
Query,
- NULL,
- NULL,
- NULL,
+ NULL, /* GetFieldSet */
+ NULL, /* GetAnchor */
+ NULL, /* GetClipVertices */
Coords,
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
IsSensitive,
Pick,
+ NULL, /* PickVertex */
PostScript
};
diff --git a/generic/Icon.c b/generic/Icon.c
index bd8c7e1..7a89753 100644
--- a/generic/Icon.c
+++ b/generic/Icon.c
@@ -669,24 +669,24 @@ GetAnchor(Item item,
*/
static ZnBool
GetClipVertices(Item item,
- ZnPoint **points,
- int *num_points)
+ ZnPoly *poly)
{
IconItem icon = (IconItem) item;
int w=0, h=0;
-
+ ZnPoint *points;
+
ZnListAssertSize(item->wi->work_pts, 2);
- *points = (ZnPoint *) ZnListArray(item->wi->work_pts);
- *num_points = 2;
if (icon->image != ZnUnspecifiedImage) {
Tk_SizeOfImage(icon->image, &w, &h);
}
else {
Tk_SizeOfBitmap(item->wi->dpy, icon->mask, &w, &h);
}
- (*points)[0] = icon->pos_dev;
- (*points)[1].x = icon->pos_dev.x + w;
- (*points)[1].y = icon->pos_dev.y + h;
+ points = (ZnPoint *) ZnListArray(item->wi->work_pts);
+ POLY_CONTOUR1(poly, points, 2);
+ points[0] = icon->pos_dev;
+ points[1].x = points[0].x + w;
+ points[1].y = points[0].y + h;
return True;
}
@@ -704,6 +704,7 @@ GetClipVertices(Item item,
*/
static int
Coords(Item item,
+ int contour,
int index,
int cmd,
ZnPoint **pts,
@@ -742,9 +743,9 @@ Coords(Item item,
*/
static ItemClassStruct ICON_ITEM_CLASS = {
sizeof(IconItemStruct),
- False,
- False,
- True,
+ False, /* has_fields */
+ False, /* has_parts */
+ True, /* has_anchors */
"icon",
icon_attrs,
Init,
@@ -752,15 +753,17 @@ static ItemClassStruct ICON_ITEM_CLASS = {
Destroy,
Configure,
Query,
- NULL,
+ NULL, /* GetFieldSet */
GetAnchor,
GetClipVertices,
Coords,
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
IsSensitive,
Pick,
+ NULL, /* PickVertex */
PostScript
};
diff --git a/generic/Rectangle.c b/generic/Rectangle.c
index 10bf3e4..b1be39f 100644
--- a/generic/Rectangle.c
+++ b/generic/Rectangle.c
@@ -455,7 +455,7 @@ ToArea(Item item,
result = -1;
if (ISSET(rect->flags, FILLED_BIT)) {
- result = PolygonInBBox(rect->dev, 4, area);
+ result = PolygonInBBox(rect->dev, 4, area, NULL);
}
else if (rect->line_width > 0) {
int i;
@@ -534,7 +534,9 @@ Draw(Item item)
DrawRectangleGradient(wi, rect->grad_geom, rect->fill_color, &r);
}
else {
- DrawPolygonGradient(wi, rect->grad_geom, rect->fill_color, rect->dev, 4,
+ ZnPoly poly;
+ POLY_CONTOUR1(&poly, rect->dev, 4);
+ DrawPolygonGradient(wi, rect->grad_geom, rect->fill_color, &poly,
&item->item_bounding_box);
}
}
@@ -710,12 +712,12 @@ PostScript(Item item,
*/
static ZnBool
GetClipVertices(Item item,
- ZnPoint **points,
- int *num_points)
+ ZnPoly *poly)
{
RectangleItem rect = (RectangleItem) item;
double delta;
ZnBool aligned;
+ ZnPoint *points;
delta = rect->dev[0].y - rect->dev[1].y;
delta = ABS(delta);
@@ -726,29 +728,28 @@ GetClipVertices(Item item,
if (aligned) {
ZnListAssertSize(item->wi->work_pts, 2);
- *points = (ZnPoint *) ZnListArray(item->wi->work_pts);
- *num_points = 2;
+ points = (ZnPoint *) ZnListArray(item->wi->work_pts);
+ POLY_CONTOUR1(poly, points, 2);
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;
+ 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;
+ 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;
+ 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;
+ points[0].y = rect->dev[2].y;
+ points[1].y = rect->dev[0].y+1.0;
}
}
else {
- *points = rect->dev;
- *num_points = 4;
+ POLY_CONTOUR1(poly, rect->dev, 4);
}
return aligned;
@@ -765,6 +766,7 @@ GetClipVertices(Item item,
*/
static int
Coords(Item item,
+ int contour,
int index,
int cmd,
ZnPoint **pts,
@@ -833,9 +835,9 @@ Coords(Item item,
*/
static ItemClassStruct RECTANGLE_ITEM_CLASS = {
sizeof(RectangleItemStruct),
- False,
- False,
- False,
+ False, /* has_fields */
+ False, /* has_parts */
+ False, /* has_anchors */
"rectangle",
rect_attrs,
Init,
@@ -843,15 +845,17 @@ static ItemClassStruct RECTANGLE_ITEM_CLASS = {
Destroy,
Configure,
Query,
- NULL,
- NULL,
+ NULL, /* GetFieldSet */
+ NULL, /* GetAnchor */
GetClipVertices,
Coords,
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
IsSensitive,
Pick,
+ NULL, /* PickVertex */
PostScript
};
diff --git a/generic/Tabular.c b/generic/Tabular.c
index 0385203..6f40926 100644
--- a/generic/Tabular.c
+++ b/generic/Tabular.c
@@ -426,23 +426,22 @@ GetAnchor(Item item,
*/
static ZnBool
GetClipVertices(Item item,
- ZnPoint **points,
- int *num_points)
+ ZnPoly *poly)
{
FieldSet field_set = &((TabularItem) item)->field_set;
- ZnDim width, height;
+ ZnDim width, height;
+ ZnPoint *points;
- *points = NULL;
- *num_points = 0;
+ poly->num_contours = 0;
if (field_set->label_format) {
ITEM_P.GetLabelBBox(field_set, &width, &height);
ZnListAssertSize(item->wi->work_pts, 2);
- *points = (ZnPoint *) ZnListArray(item->wi->work_pts);
- *num_points = 2;
- (*points)[0] = field_set->label_pos;
- (*points)[1].x = field_set->label_pos.x + width;
- (*points)[1].y = field_set->label_pos.y + height;
+ points = (ZnPoint *) ZnListArray(item->wi->work_pts);
+ POLY_CONTOUR1(poly, points, 2);
+ points[0] = field_set->label_pos;
+ points[1].x = points[0].x + width;
+ points[1].y = points[0].y + height;
}
return True;
@@ -461,6 +460,7 @@ GetClipVertices(Item item,
*/
static int
Coords(Item item,
+ int contour,
int index,
int cmd,
ZnPoint **pts,
@@ -499,9 +499,9 @@ Coords(Item item,
*/
static ItemClassStruct TABULAR_ITEM_CLASS = {
sizeof(TabularItemStruct),
- True,
- False,
- True,
+ True, /* has_fields */
+ False, /* has_parts */
+ True, /* has_anchors */
"tabular",
tabular_attrs,
Init,
@@ -513,11 +513,13 @@ static ItemClassStruct TABULAR_ITEM_CLASS = {
GetAnchor,
GetClipVertices,
Coords,
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
IsSensitive,
Pick,
+ NULL, /* PickVertex */
PostScript
};
diff --git a/generic/Text.c b/generic/Text.c
index b01348b..187a228 100644
--- a/generic/Text.c
+++ b/generic/Text.c
@@ -845,14 +845,15 @@ GetAnchor(Item item,
*/
static ZnBool
GetClipVertices(Item item,
- ZnPoint **points,
- int *num_points)
+ ZnPoly *poly)
{
+ ZnPoint *points;
+
ZnListAssertSize(item->wi->work_pts, 2);
- *points = (ZnPoint *) ZnListArray(item->wi->work_pts);
- *num_points = 2;
- (*points)[0] = item->item_bounding_box.orig;
- (*points)[1] = item->item_bounding_box.corner;
+ points = (ZnPoint *) ZnListArray(item->wi->work_pts);
+ POLY_CONTOUR1(poly, points, 2);
+ points[0] = item->item_bounding_box.orig;
+ points[1] = item->item_bounding_box.corner;
return True;
}
@@ -870,6 +871,7 @@ GetClipVertices(Item item,
*/
static int
Coords(Item item,
+ int contour,
int index,
int cmd,
ZnPoint **pts,
@@ -908,9 +910,9 @@ Coords(Item item,
*/
static ItemClassStruct TEXT_ITEM_CLASS = {
sizeof(TextItemStruct),
- False,
- False,
- True,
+ False, /* has_fields */
+ False, /* has_parts */
+ True, /* has_anchors */
"text",
text_attrs,
Init,
@@ -918,15 +920,17 @@ static ItemClassStruct TEXT_ITEM_CLASS = {
Destroy,
Configure,
Query,
- NULL,
+ NULL, /* GetFieldSet */
GetAnchor,
GetClipVertices,
Coords,
+ NULL, /* Contour */
ComputeCoordinates,
ToArea,
Draw,
IsSensitive,
Pick,
+ NULL, /* PickVertex */
PostScript
};