From 23e0a06574a231cce7e0a7bd50de2573d512a679 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Thu, 16 May 2002 08:00:26 +0000 Subject: Adaptation suite au changement du code des images. Ajout du -composealpha Adaptation des types d'attributs pour coller � la doc Adaptation du prototype de ToArea et Pick pour accomoder les fonctions de find/addtag Suppression de la variable de class has_fields. --- Bezier.c | 164 +++++++++++++++++++++++---------------------------------------- 1 file changed, 59 insertions(+), 105 deletions(-) diff --git a/Bezier.c b/Bezier.c index b5b505f..a61ff5f 100644 --- a/Bezier.c +++ b/Bezier.c @@ -77,14 +77,13 @@ typedef struct _BezierItemStruct { int cap_style; ReliefStyle relief; ZnDim line_width; /* If 0 the path is not drawn, if <2 relief is flat */ - Pixmap fill_pattern; + ZnImage fill_pattern; ZnGradient *fill_color; - Pixmap line_pattern; + ZnImage line_pattern; ZnGradient *line_color; - char *tile_name; + ZnImage tile; /* Private data */ - ZnImage tile; ZnList dev_points; ZnGradient *gradient; ZnTriStrip tristrip; @@ -96,6 +95,9 @@ static ZnAttrConfig bz_attrs[] = { { ZN_CONFIG_CAP_STYLE, "-capstyle", NULL, Tk_Offset(BezierItemStruct, cap_style), 0, ZN_COORDS_FLAG, False }, + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(BezierItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(BezierItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -105,7 +107,7 @@ static ZnAttrConfig bz_attrs[] = { { ZN_CONFIG_GRADIENT, "-fillcolor", NULL, Tk_Offset(BezierItemStruct, fill_color), 0, ZN_COORDS_FLAG|ZN_BORDER_FLAG, False }, - { ZN_CONFIG_PATTERN, "-fillpattern", NULL, + { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(BezierItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(BezierItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False }, @@ -116,7 +118,7 @@ static ZnAttrConfig bz_attrs[] = { { ZN_CONFIG_GRADIENT, "-linecolor", NULL, Tk_Offset(BezierItemStruct, line_color), 0, ZN_DRAW_FLAG, False }, - { ZN_CONFIG_PATTERN, "-linepattern", NULL, + { ZN_CONFIG_BITMAP, "-linepattern", NULL, Tk_Offset(BezierItemStruct, line_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-linestyle", NULL, Tk_Offset(BezierItemStruct, line_style), 0, ZN_DRAW_FLAG, False }, @@ -130,11 +132,10 @@ static ZnAttrConfig bz_attrs[] = { { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(BezierItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(BezierItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, - Tk_Offset(BezierItemStruct, tile_name), 0, - ZN_DRAW_FLAG|ZN_TILE_FLAG, False }, + Tk_Offset(BezierItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(BezierItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, @@ -143,28 +144,6 @@ static ZnAttrConfig bz_attrs[] = { }; -/* - ********************************************************************************** - * - * BzTileChange -- - * - ********************************************************************************** - */ -static void -BzTileChange(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) -{ - BezierItem bz = (BezierItem) client_data; - - InvalidateImage(bz->tile_name); - ITEM.Invalidate((Item) bz, ZN_COORDS_FLAG); -} - /* ********************************************************************************** @@ -192,6 +171,7 @@ Init(Item 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_BEZIER_PRIORITY; @@ -229,10 +209,9 @@ Init(Item item, bz->line_style = LINE_SIMPLE; bz->relief = RELIEF_FLAT; bz->line_width = 1; - bz->tile_name = ""; bz->tile = ZnUnspecifiedImage; - bz->fill_pattern = ZnUnspecifiedPattern; - bz->line_pattern = ZnUnspecifiedPattern; + bz->fill_pattern = ZnUnspecifiedImage; + bz->line_pattern = ZnUnspecifiedImage; bz->cap_style = CapRound; bz->fill_color = ZnGetGradientByValue(wi->fore_color); @@ -253,8 +232,6 @@ static void Clone(Item item) { BezierItem bz = (BezierItem) item; - WidgetInfo *wi = item->wi; - char *text; bz->dev_points = NULL; bz->tristrip.num_strips = 0; @@ -270,10 +247,6 @@ Clone(Item item) if (bz->points) { bz->points = ZnListDuplicate(bz->points); } - if (bz->line_pattern != ZnUnspecifiedPattern) { - bz->line_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, bz->line_pattern)); - } if (bz->first_end) { LineEndDuplicate(bz->first_end); } @@ -281,15 +254,13 @@ Clone(Item item) LineEndDuplicate(bz->last_end); } if (bz->tile != ZnUnspecifiedImage) { - text = ZnMalloc((strlen(bz->tile_name) + 1) * sizeof(char)); - strcpy(text, bz->tile_name); - bz->tile_name = text; - bz->tile = Tk_GetImage(wi->interp, wi->win, bz->tile_name, - BzTileChange, (ClientData) bz); + bz->tile = ZnGetImageByValue(bz->tile); + } + if (bz->line_pattern != ZnUnspecifiedImage) { + bz->line_pattern = ZnGetImageByValue(bz->line_pattern); } - if (bz->fill_pattern != ZnUnspecifiedPattern) { - bz->fill_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, bz->fill_pattern)); + if (bz->fill_pattern != ZnUnspecifiedImage) { + bz->fill_pattern = ZnGetImageByValue(bz->fill_pattern); } bz->line_color = ZnGetGradientByValue(bz->line_color); bz->fill_color = ZnGetGradientByValue(bz->fill_color); @@ -306,8 +277,7 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; - BezierItem bz = (BezierItem) item; + BezierItem bz = (BezierItem) item; if (bz->points) { ZnListFree(bz->points); @@ -331,17 +301,16 @@ Destroy(Item item) ZnFreeGradient(bz->gradient); } if (bz->tile != ZnUnspecifiedImage) { - Tk_FreeImage(bz->tile); + ZnFreeImage(bz->tile); bz->tile = ZnUnspecifiedImage; } - if (strlen(bz->tile_name) != 0) { - ZnFree(bz->tile_name); - } - if (bz->line_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, bz->line_pattern); + if (bz->line_pattern != ZnUnspecifiedImage) { + ZnFreeImage(bz->line_pattern); + bz->line_pattern = ZnUnspecifiedImage; } - if (bz->fill_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, bz->fill_pattern); + if (bz->fill_pattern != ZnUnspecifiedImage) { + ZnFreeImage(bz->fill_pattern); + bz->fill_pattern = ZnUnspecifiedImage; } ZnFreeGradient(bz->fill_color); ZnFreeGradient(bz->line_color); @@ -412,12 +381,6 @@ Configure(Item item, status = ZN_ERROR; } } - if (ISSET(*flags, ZN_TILE_FLAG)) { - if (ValidateImage(wi, item, bz->tile_name, BzTileChange, - &bz->tile, "bezier -tile") == ZN_ERROR) { - status = ZN_ERROR; - } - } return status; } @@ -539,8 +502,8 @@ ComputeCoordinates(Item item, /* * Compute the bounding box. */ - GetPolygonReliefBBox(dev_points, num_points, - ISCLEAR(bz->flags, CCW)?-lw:lw, &bbox); + ZnGetPolygonReliefBBox(dev_points, num_points, + ISCLEAR(bz->flags, CCW)?-lw:lw, &bbox); AddBBoxToBBox(&item->item_bounding_box, &bbox); return; } @@ -592,13 +555,13 @@ ComputeCoordinates(Item item, } if (bz->fill_color->type == ZN_AXIAL_GRADIENT) { POLY_CONTOUR1(&poly, points, num_points); - ComputeAxialGradient(wi, &poly, bz->fill_color->g.angle, - bz->grad_geo); + ZnComputeAxialGradient(wi, &poly, bz->fill_color->g.angle, + bz->grad_geo); } else if (bz->fill_color->type == ZN_RADIAL_GRADIENT) { POLY_CONTOUR1(&poly, dev_points, num_points); - ComputeRadialGradient(wi, &poly, &item->item_bounding_box, - &bz->fill_color->g.p, bz->grad_geo); + ZnComputeRadialGradient(wi, &poly, &item->item_bounding_box, + &bz->fill_color->g.p, bz->grad_geo); } else if (bz->fill_color->type == ZN_PATH_GRADIENT) { ZnTransformPoint(wi->current_transfo, &bz->fill_color->g.p, @@ -626,10 +589,7 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { BezierItem bz = (BezierItem) item; WidgetInfo *wi = item->wi; @@ -637,6 +597,7 @@ ToArea(Item item, ZnPoint end_points[LINE_END_POINTS]; int num_points, result=-1, result2; int lw = bz->line_width; + ZnBBox *area = ta->area; if (bz->dev_points == NULL) { return -1; @@ -660,8 +621,8 @@ ToArea(Item item, bz->cap_style, JoinRound, area); } else { - result2 = PolygonReliefInBBox(points, num_points, - ISCLEAR(bz->flags, CCW)?-lw:lw, area); + result2 = ZnPolygonReliefInBBox(points, num_points, + ISCLEAR(bz->flags, CCW)?-lw:lw, area); } if (ISCLEAR(bz->flags, FILLED_OK)) { if (result2 == 0) { @@ -730,16 +691,15 @@ Draw(Item item) values.foreground = ZnPixel(ZnGetGradientColor(bz->fill_color, 0.0, NULL)); gc_mask = GCFillStyle; if (bz->tile != ZnUnspecifiedImage) { /* Fill tiled */ - Pixmap pmap = GetImagePixmap(wi->win, bz->tile_name, bz->tile, NULL); values.fill_style = FillTiled; - values.tile = pmap; + values.tile = ZnImagePixmap(bz->tile, NULL); values.ts_x_origin = REAL_TO_INT(item->item_bounding_box.orig.x); values.ts_y_origin = REAL_TO_INT(item->item_bounding_box.orig.y); gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCTile; } - else if (bz->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + else if (bz->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = bz->fill_pattern; + values.stipple = ZnImagePixmap(bz->fill_pattern, NULL); values.ts_x_origin = REAL_TO_INT(item->item_bounding_box.orig.x); values.ts_y_origin = REAL_TO_INT(item->item_bounding_box.orig.y); gc_mask |= GCTileStipXOrigin|GCTileStipYOrigin|GCStipple|GCForeground; @@ -788,22 +748,22 @@ Draw(Item item) } relief = (relief & ~RELIEF_MASK) | relief_dir; } - DrawPolygonRelief(wi, relief, bz->gradient, points, num_points, lw); + ZnDrawPolygonRelief(wi, relief, bz->gradient, points, num_points, lw); } else { - SetLineStyle(wi, bz->line_style); + ZnSetLineStyle(wi, bz->line_style); values.foreground = ZnPixel(ZnGetGradientColor(bz->line_color, 0, NULL)); values.line_width = (lw == 1) ? 0 : lw; values.join_style = JoinRound; values.cap_style = bz->cap_style; - if (bz->line_pattern == ZnUnspecifiedPattern) { + if (bz->line_pattern == ZnUnspecifiedImage) { values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCLineWidth|GCJoinStyle|GCCapStyle|GCForeground, &values); } else { values.fill_style = FillStippled; - values.stipple = bz->line_pattern; + values.stipple = ZnImagePixmap(bz->line_pattern, NULL); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCLineWidth|GCJoinStyle|GCCapStyle|GCForeground, &values); @@ -909,21 +869,20 @@ Render(Item item) ZnPoly poly; POLY_CONTOUR1(&poly, points, num_points); - RenderGradient(wi, bz->fill_color, BezierRenderCB, bz, - bz->grad_geo, &poly); + ZnRenderGradient(wi, bz->fill_color, BezierRenderCB, bz, + bz->grad_geo, &poly); } else if (bz->tile != ZnUnspecifiedImage) { /* Fill tiled */ - RenderTile(wi, GetImageTexture(wi->win, bz->tile_name, bz->tile), - bz->fill_color, BezierRenderCB, bz, - (ZnPoint *) &item->item_bounding_box); + ZnRenderTile(wi, bz->tile, bz->fill_color, BezierRenderCB, bz, + (ZnPoint *) &item->item_bounding_box); } else { - if (bz->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + if (bz->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ /* * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(GetBitmapMask(wi->dpy, bz->fill_pattern)->pixels); + glPolygonStipple(ZnImagePattern(bz->fill_pattern, NULL)); } color = ZnGetGradientColor(bz->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -958,16 +917,16 @@ Render(Item item) } relief = (relief & ~RELIEF_MASK) | relief_dir; } - RenderPolygonRelief(wi, relief, bz->gradient, True, - points, num_points, line_width); + ZnRenderPolygonRelief(wi, relief, bz->gradient, True, + points, num_points, line_width); } else { ZnLineEnd first = ISSET(bz->flags, FIRST_END_OK) ? bz->first_end : NULL; ZnLineEnd last = ISSET(bz->flags, LAST_END_OK) ? bz->last_end : NULL; - RenderPolyline(wi, points, num_points, - bz->line_width, bz->line_style, bz->cap_style, JoinRound, - first, last, bz->line_color); + ZnRenderPolyline(wi, points, num_points, + bz->line_width, bz->line_style, bz->cap_style, + JoinRound, first, last, bz->line_color); } } #endif @@ -999,16 +958,12 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *part) + ZnPick ps) { BezierItem bz = (BezierItem) item; WidgetInfo *wi = item->wi; double dist=1.0e40, new_dist; - ZnPoint *points; + ZnPoint *points, *p = ps->point; ZnPoint end_points[LINE_END_POINTS]; int num_points; int lw = bz->line_width; @@ -1041,8 +996,8 @@ Pick(Item item, } } else { - new_dist = PolygonReliefToPointDist(points, num_points, - ISCLEAR(bz->flags, CCW)?-lw:lw, p); + new_dist = ZnPolygonReliefToPointDist(points, num_points, + ISCLEAR(bz->flags, CCW)?-lw:lw, p); if (new_dist < dist) { dist = new_dist; } @@ -1370,7 +1325,6 @@ PickVertex(Item item, */ static ItemClassStruct BEZIER_ITEM_CLASS = { sizeof(BezierItemStruct), - False, /* has_fields */ 0, /* num_parts */ False, /* has_anchors */ "bezier", -- cgit v1.1