From f8c4a63cf27597af47f88363b45abfc0f869e660 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Thu, 16 May 2002 09:40:36 +0000 Subject: Adaptation suite au remaniement du code des images. Ajout de l'attribut -composealpha. Mise en correspondance des types d'attributs avec la doc. Adaptation des prototypes de ToArea et Pick pour accomoder les nouvelles fonctionalit�s des commandes de find/addtag. Suppression de la variable de classe has_fields --- generic/Curve.c | 224 ++++++++++++++++++++++---------------------------------- 1 file changed, 88 insertions(+), 136 deletions(-) (limited to 'generic/Curve.c') diff --git a/generic/Curve.c b/generic/Curve.c index 46f55dc..811872a 100644 --- a/generic/Curve.c +++ b/generic/Curve.c @@ -75,7 +75,7 @@ typedef struct _CurveItemStruct { /* Public data */ ZnPoly shape; unsigned short flags; - Pixmap marker; + ZnImage marker; ZnLineEnd first_end; /* These two are considered only if relief is flat */ ZnLineEnd last_end; LineStyle line_style; /* This is considered only if relief is flat */ @@ -83,15 +83,14 @@ typedef struct _CurveItemStruct { int join_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; ZnGradient *marker_color; - char *tile_name; + ZnImage tile; /* Private data */ - ZnImage tile; ZnPoly dev_shape; ZnGradient *gradient; ZnTriStrip tristrip; @@ -104,6 +103,9 @@ static ZnAttrConfig cv_attrs[] = { ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-closed", NULL, Tk_Offset(CurveItemStruct, flags), CLOSED_BIT, ZN_COORDS_FLAG, False }, + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(CurveItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(CurveItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -113,7 +115,7 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_GRADIENT, "-fillcolor", NULL, Tk_Offset(CurveItemStruct, fill_color), 0, ZN_COORDS_FLAG|ZN_BORDER_FLAG, False }, - { ZN_CONFIG_PATTERN, "-fillpattern", NULL, + { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(CurveItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(CurveItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False }, @@ -127,7 +129,7 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_GRADIENT, "-linecolor", NULL, Tk_Offset(CurveItemStruct, line_color), 0, ZN_DRAW_FLAG, False }, - { ZN_CONFIG_PATTERN, "-linepattern", NULL, + { ZN_CONFIG_BITMAP, "-linepattern", NULL, Tk_Offset(CurveItemStruct, line_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-linestyle", NULL, Tk_Offset(CurveItemStruct, line_style), 0, ZN_DRAW_FLAG, False }, @@ -136,7 +138,7 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_PRI, "-priority", NULL, Tk_Offset(CurveItemStruct, header.priority), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, - { ZN_CONFIG_PATTERN, "-marker", NULL, + { ZN_CONFIG_BITMAP, "-marker", NULL, Tk_Offset(CurveItemStruct, marker), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-markercolor", NULL, Tk_Offset(CurveItemStruct, marker_color), 0, ZN_DRAW_FLAG, False }, @@ -148,11 +150,10 @@ static ZnAttrConfig cv_attrs[] = { { ZN_CONFIG_BOOL, "-smoothrelief", NULL, Tk_Offset(CurveItemStruct, flags), SMOOTH_RELIEF_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(CurveItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, - Tk_Offset(CurveItemStruct, tile_name), 0, - ZN_DRAW_FLAG|ZN_TILE_FLAG, False }, + Tk_Offset(CurveItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(CurveItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, @@ -164,29 +165,6 @@ static ZnAttrConfig cv_attrs[] = { /* ********************************************************************************** * - * CvTileChange -- - * - ********************************************************************************** - */ -static void -CvTileChange(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) -{ - CurveItem cv = (CurveItem) client_data; - - InvalidateImage(cv->tile_name); - ITEM.Invalidate((Item) cv, ZN_COORDS_FLAG); -} - - -/* - ********************************************************************************** - * * Init -- * ********************************************************************************** @@ -211,6 +189,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); CLEAR(cv->flags, CLOSED_BIT); @@ -258,10 +237,9 @@ Init(Item item, cv->line_style = LINE_SIMPLE; cv->relief = RELIEF_FLAT; cv->line_width = 1; - cv->tile_name = ""; cv->tile = ZnUnspecifiedImage; - cv->fill_pattern = ZnUnspecifiedPattern; - cv->line_pattern = ZnUnspecifiedPattern; + cv->fill_pattern = ZnUnspecifiedImage; + cv->line_pattern = ZnUnspecifiedImage; cv->cap_style = CapRound; cv->join_style = JoinRound; @@ -270,7 +248,7 @@ Init(Item item, * being unspecified. */ SET(cv->flags, MARKED_BIT); - cv->marker = ZnUnspecifiedPattern; + cv->marker = ZnUnspecifiedImage; cv->fill_color = ZnGetGradientByValue(wi->fore_color); cv->line_color = ZnGetGradientByValue(wi->fore_color); cv->marker_color = ZnGetGradientByValue(wi->fore_color); @@ -290,8 +268,6 @@ static void Clone(Item item) { CurveItem cv = (CurveItem) item; - WidgetInfo *wi = item->wi; - char *text; int i; ZnContour *conts; ZnBool *holes; @@ -327,10 +303,6 @@ Clone(Item item) if (cv->gradient) { cv->gradient = ZnGetGradientByValue(cv->gradient); } - if (cv->line_pattern != ZnUnspecifiedPattern) { - cv->line_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, cv->line_pattern)); - } if (cv->first_end) { LineEndDuplicate(cv->first_end); } @@ -338,19 +310,16 @@ Clone(Item item) LineEndDuplicate(cv->last_end); } if (cv->tile != ZnUnspecifiedImage) { - text = ZnMalloc((strlen(cv->tile_name) + 1) * sizeof(char)); - strcpy(text, cv->tile_name); - cv->tile_name = text; - cv->tile = Tk_GetImage(wi->interp, wi->win, cv->tile_name, - CvTileChange, (ClientData) cv); + cv->tile = ZnGetImageByValue(cv->tile); + } + if (cv->line_pattern != ZnUnspecifiedImage) { + cv->line_pattern = ZnGetImageByValue(cv->line_pattern); } - if (cv->fill_pattern != ZnUnspecifiedPattern) { - cv->fill_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, cv->fill_pattern)); + if (cv->fill_pattern != ZnUnspecifiedImage) { + cv->fill_pattern = ZnGetImageByValue(cv->fill_pattern); } - if (cv->marker != ZnUnspecifiedPattern) { - cv->marker = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, cv->marker)); + if (cv->marker != ZnUnspecifiedImage) { + cv->marker = ZnGetImageByValue(cv->marker); } cv->line_color = ZnGetGradientByValue(cv->line_color); cv->fill_color = ZnGetGradientByValue(cv->fill_color); @@ -369,7 +338,6 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; CurveItem cv = (CurveItem) item; POLY_FREE(&cv->shape); @@ -389,20 +357,20 @@ Destroy(Item item) ZnFreeGradient(cv->gradient); } if (cv->tile != ZnUnspecifiedImage) { - Tk_FreeImage(cv->tile); + ZnFreeImage(cv->tile); cv->tile = ZnUnspecifiedImage; } - if (strlen(cv->tile_name) != 0) { - ZnFree(cv->tile_name); - } - if (cv->line_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, cv->line_pattern); + if (cv->line_pattern != ZnUnspecifiedImage) { + ZnFreeImage(cv->line_pattern); + cv->line_pattern = ZnUnspecifiedImage; } - if (cv->fill_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, cv->fill_pattern); + if (cv->fill_pattern != ZnUnspecifiedImage) { + ZnFreeImage(cv->fill_pattern); + cv->fill_pattern = ZnUnspecifiedImage; } - if (cv->marker != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, cv->marker); + if (cv->marker != ZnUnspecifiedImage) { + ZnFreeImage(cv->marker); + cv->marker = ZnUnspecifiedImage; } ZnFreeGradient(cv->fill_color); ZnFreeGradient(cv->line_color); @@ -434,7 +402,7 @@ SetRenderFlags(CurveItem cv) (cv->line_width > 1)); ASSIGN(cv->flags, MARKER_OK, - (cv->marker != ZnUnspecifiedPattern) && + (cv->marker != ZnUnspecifiedImage) && ISCLEAR(cv->flags, RELIEF_OK)); ASSIGN(cv->flags, FIRST_END_OK, @@ -486,12 +454,6 @@ Configure(Item item, status = ZN_ERROR; } } - if (ISSET(*flags, ZN_TILE_FLAG)) { - if (ValidateImage(wi, item, cv->tile_name, CvTileChange, - &cv->tile, "curve -tile") == ZN_ERROR) { - status = ZN_ERROR; - } - } return status; } @@ -704,7 +666,7 @@ ComputeCoordinates(Item item, /* * Add to bounding box. */ - GetPolygonReliefBBox(points, num_points, (*cw ^ *holes)?-lw:lw, &bbox); + ZnGetPolygonReliefBBox(points, num_points, (*cw ^ *holes)?-lw:lw, &bbox); AddBBoxToBBox(&item->item_bounding_box, &bbox); } } @@ -749,10 +711,11 @@ ComputeCoordinates(Item item, */ if (ISSET(cv->flags, MARKER_OK)) { int w, h; - ZnBBox bbox; - Tk_SizeOfBitmap(wi->dpy, cv->marker, &w, &h); + ZnBBox bbox; + + ZnSizeOfImage(cv->marker, &w, &h); w = w/2 + 2; - h = w/2 + 2; + h = h/2 + 2; num_points = c2->num_points; for (i = 0, points = c2->points; i < num_points; i++, points++) { bbox.orig.x = points->x - w; @@ -794,11 +757,11 @@ ComputeCoordinates(Item item, cv->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } if (cv->fill_color->type == ZN_AXIAL_GRADIENT) { - ComputeAxialGradient(wi, &cv->shape, cv->fill_color->g.angle, cv->grad_geo); + ZnComputeAxialGradient(wi, &cv->shape, cv->fill_color->g.angle, cv->grad_geo); } else if (cv->fill_color->type == ZN_RADIAL_GRADIENT) { - ComputeRadialGradient(wi, &cv->dev_shape, &item->item_bounding_box, - &cv->fill_color->g.p, cv->grad_geo); + ZnComputeRadialGradient(wi, &cv->dev_shape, &item->item_bounding_box, + &cv->fill_color->g.p, cv->grad_geo); } else if (cv->fill_color->type == ZN_PATH_GRADIENT) { ZnTransformPoint(wi->current_transfo, &cv->fill_color->g.p, &cv->grad_geo[0]); @@ -825,14 +788,10 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { CurveItem cv = (CurveItem) item; - WidgetInfo *wi = item->wi; - ZnBBox bbox; + ZnBBox bbox, *area = ta->area; ZnPoint *points; ZnPoint end_points[LINE_END_POINTS]; int i, num_points, result=-1, result2; @@ -884,8 +843,9 @@ ToArea(Item item, cv->line_width, cv->cap_style, cv->join_style, area); } else { - result = PolygonReliefInBBox(points, num_points, - (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, area); + result = ZnPolygonReliefInBBox(points, num_points, + (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, + area); } if (result == 0) { return 0; @@ -897,8 +857,9 @@ ToArea(Item item, cv->line_width, cv->cap_style, cv->join_style, area); } else { - result2 = PolygonReliefInBBox(points, num_points, - (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, area); + result2 = ZnPolygonReliefInBBox(points, num_points, + (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, + area); } if (result2 != result) { return 0; @@ -943,7 +904,7 @@ ToArea(Item item, num_points--; } - Tk_SizeOfBitmap(wi->dpy, cv->marker, &width, &height); + ZnSizeOfImage(cv->marker, &width, &height); for (; num_points > 0; num_points--, points++) { bbox.orig.x = points->x - (width+1)/2; bbox.orig.y = points->y - (height+1)/2; @@ -992,16 +953,15 @@ Draw(Item item) values.foreground = ZnPixel(ZnGetGradientColor(cv->fill_color, 0.0, NULL)); gc_mask = GCFillStyle; if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */ - Pixmap pmap = GetImagePixmap(wi->win, cv->tile_name, cv->tile, NULL); values.fill_style = FillTiled; - values.tile = pmap; + values.tile = ZnImagePixmap(cv->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 (cv->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + else if (cv->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = cv->fill_pattern; + values.stipple = ZnImagePixmap(cv->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; @@ -1079,23 +1039,23 @@ Draw(Item item) } relief = (relief & ~RELIEF_MASK) | relief_dir; } - DrawPolygonRelief(wi, relief, cv->gradient, points, num_points, lw); + ZnDrawPolygonRelief(wi, relief, cv->gradient, points, num_points, lw); } } else { - SetLineStyle(wi, cv->line_style); + ZnSetLineStyle(wi, cv->line_style); values.foreground = ZnPixel(ZnGetGradientColor(cv->line_color, 0, NULL)); values.line_width = (cv->line_width == 1) ? 0 : cv->line_width; values.join_style = cv->join_style; values.cap_style = cv->cap_style; - if (cv->line_pattern == ZnUnspecifiedPattern) { + if (cv->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 = cv->line_pattern; + values.stipple = ZnImagePixmap(cv->line_pattern, NULL); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCLineWidth|GCJoinStyle|GCCapStyle|GCForeground, &values); @@ -1143,14 +1103,14 @@ Draw(Item item) * if last point join first point suppress markers at end points. */ if (ISSET(cv->flags, MARKER_OK)) { - int width, h_width, height, h_height; + int h_width, h_height, width, height; ZnPoint ptmp; - - Tk_SizeOfBitmap(wi->dpy, cv->marker, &width, &height); + + ZnSizeOfImage(cv->marker, &width, &height); h_width = (width+1)/2; h_height = (height+1)/2; values.fill_style = FillStippled; - values.stipple = cv->marker; + values.stipple = ZnImagePixmap(cv->marker, NULL); values.foreground = ZnPixel(ZnGetGradientColor(cv->marker_color, 0, NULL)); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCForeground, &values); for (j = 0; j < cv->dev_shape.num_contours; j++) { @@ -1242,21 +1202,20 @@ Render(Item item) if (ISSET(cv->flags, FILLED_OK)) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (!ZnGradientFlat(cv->fill_color)) { - RenderGradient(wi, cv->fill_color, CurveRenderCB, cv, cv->grad_geo, - &cv->dev_shape); + ZnRenderGradient(wi, cv->fill_color, CurveRenderCB, cv, cv->grad_geo, + &cv->dev_shape); } else if (cv->tile != ZnUnspecifiedImage) { /* Fill tiled */ - RenderTile(wi, GetImageTexture(wi->win, cv->tile_name, cv->tile), - cv->fill_color, CurveRenderCB, cv, - (ZnPoint *) &item->item_bounding_box); + ZnRenderTile(wi, cv->tile, cv->fill_color, CurveRenderCB, cv, + (ZnPoint *) &item->item_bounding_box); } else { - if (cv->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + if (cv->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ /* * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(GetBitmapMask(wi->dpy, cv->fill_pattern)->pixels); + glPolygonStipple(ZnImagePattern(cv->fill_pattern, NULL)); } color = ZnGetGradientColor(cv->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -1301,9 +1260,8 @@ Render(Item item) } relief = (relief & ~RELIEF_MASK) | relief_dir; } - RenderPolygonRelief(wi, relief, cv->gradient, - ISSET(cv->flags, SMOOTH_RELIEF_BIT), - points, num_points, line_width); + ZnRenderPolygonRelief(wi, relief, cv->gradient, ISSET(cv->flags, SMOOTH_RELIEF_BIT), + points, num_points, line_width); } } else { @@ -1311,11 +1269,11 @@ Render(Item item) ZnLineEnd last = ISSET(cv->flags, LAST_END_OK) ? cv->last_end : NULL; for (j = 0; j < cv->dev_shape.num_contours; j++) { - RenderPolyline(wi, - cv->dev_shape.contours[j].points, - cv->dev_shape.contours[j].num_points, - cv->line_width, cv->line_style, cv->cap_style, cv->join_style, - first, last, cv->line_color); + ZnRenderPolyline(wi, + cv->dev_shape.contours[j].points, + cv->dev_shape.contours[j].num_points, + cv->line_width, cv->line_style, cv->cap_style, cv->join_style, + first, last, cv->line_color); } } } @@ -1325,12 +1283,12 @@ Render(Item item) * if last point join first point suppress markers at end points. */ if (ISSET(cv->flags, MARKER_OK)) { - int width, h_width, height, h_height; + int h_width, h_height; ZnPoint ptmp; - - Tk_SizeOfBitmap(wi->dpy, cv->marker, &width, &height); - h_width = (width+1.0)/2.0; - h_height = (height+1.0)/2.0; + + ZnSizeOfImage(cv->marker, &h_width, & h_height); + h_width = (h_width+1.0)/2.0; + h_height = (h_height+1.0)/2.0; for (j = 0; j < cv->dev_shape.num_contours; j++) { num_points = cv->dev_shape.contours[j].num_points; points = cv->dev_shape.contours[j].points; @@ -1344,8 +1302,7 @@ Render(Item item) for (; num_points > 0; num_points--, points++) { ptmp.x = points->x - h_width; ptmp.y = points->y - h_height; - RenderImage(wi, (ImageBits *) GetBitmapTexture(wi->dpy, cv->marker), - cv->marker_color, &ptmp, True); + ZnRenderImage(wi, cv->marker, cv->marker_color, &ptmp, True); } } } @@ -1378,17 +1335,12 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *part) + ZnPick ps) { CurveItem cv = (CurveItem) item; - WidgetInfo *wi = item->wi; ZnBBox bbox; double dist=1.0e40, new_dist; - ZnPoint *points; + ZnPoint *points, *p = ps->point; ZnPoint end_points[LINE_END_POINTS]; int num_points; int width, height; @@ -1453,8 +1405,9 @@ Pick(Item item, } } else { - new_dist = PolygonReliefToPointDist(points, num_points, - (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, p); + new_dist = ZnPolygonReliefToPointDist(points, num_points, + (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, + p); if (new_dist < dist) { dist = new_dist; } @@ -1512,7 +1465,7 @@ Pick(Item item, num_points--; } - Tk_SizeOfBitmap(wi->dpy, cv->marker, &width, &height); + ZnSizeOfImage(cv->marker, &width, &height); for (; num_points > 0; num_points--, points++) { bbox.orig.x = points->x - (width+1)/2; bbox.orig.y = points->y - (height+1)/2; @@ -1920,7 +1873,6 @@ PickVertex(Item item, */ static ItemClassStruct CURVE_ITEM_CLASS = { sizeof(CurveItemStruct), - False, /* has_fields */ 0, /* num_parts */ False, /* has_anchors */ "curve", -- cgit v1.1