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 +++++++++++++++++++++------------------------------- generic/Icon.c | 220 ++++++++++++++++++++------------------------------- generic/Rectangle.c | 152 +++++++++++++---------------------- generic/Text.c | 105 +++++++++++++----------- 4 files changed, 283 insertions(+), 418 deletions(-) (limited to 'generic') 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", diff --git a/generic/Icon.c b/generic/Icon.c index d3812ed..37dc235 100644 --- a/generic/Icon.c +++ b/generic/Icon.c @@ -51,16 +51,15 @@ typedef struct _IconItemStruct { /* Public data */ ZnPoint pos; - char *image_name; + ZnImage image; ZnAnchor anchor; ZnAnchor connection_anchor; - Pixmap mask; /* Used only if the image is *NOT* specified */ - ZnGradient *color; /* Used only with the mask in GLX (alpha part + ZnImage mask; /* Used only if the image is *NOT* specified */ + ZnGradient *color; /* Used only with the mask (in GLX alpha part * is always meaningful). */ /* Private data */ ZnPoint pos_dev; - ZnImage image; } IconItemStruct, *IconItem; @@ -69,6 +68,9 @@ static ZnAttrConfig icon_attrs[] = { Tk_Offset(IconItemStruct, anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(IconItemStruct, color), 0, ZN_DRAW_FLAG, False }, + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(IconItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(IconItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -81,9 +83,8 @@ static ZnAttrConfig icon_attrs[] = { { ZN_CONFIG_ANCHOR, "-connectionanchor", NULL, Tk_Offset(IconItemStruct, connection_anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_IMAGE, "-image", NULL, - Tk_Offset(IconItemStruct, image_name), 0, - ZN_COORDS_FLAG|ZN_IMAGE_FLAG, False }, - { ZN_CONFIG_PATTERN, "-mask", NULL, + Tk_Offset(IconItemStruct, image), 0, ZN_COORDS_FLAG, False }, + { ZN_CONFIG_BITMAP, "-mask", NULL, Tk_Offset(IconItemStruct, mask), 0, ZN_DRAW_FLAG|ZN_REPICK_FLAG, False }, { ZN_CONFIG_POINT, "-position", NULL, Tk_Offset(IconItemStruct, pos), 0, ZN_COORDS_FLAG, False}, @@ -93,7 +94,7 @@ static ZnAttrConfig icon_attrs[] = { { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(IconItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(IconItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(IconItemStruct, header.flags), VISIBLE_BIT, @@ -103,28 +104,6 @@ static ZnAttrConfig icon_attrs[] = { }; -/* - ********************************************************************************** - * - * IconImageChange -- - * - ********************************************************************************** - */ -static void -IconImageChange(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) -{ - IconItem icon = (IconItem) client_data; - - InvalidateImage(icon->image_name); - ITEM.Invalidate((Item) icon, ZN_COORDS_FLAG); -} - /* ********************************************************************************** @@ -144,16 +123,16 @@ 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_ICON_PRIORITY; icon->pos.x = icon->pos.y = 0.0; - icon->image_name = ""; icon->image = ZnUnspecifiedImage; icon->anchor = ZnAnchorNW; icon->connection_anchor = ZnAnchorSW; - icon->mask = ZnUnspecifiedPattern; + icon->mask = ZnUnspecifiedImage; icon->color = ZnGetGradientByValue(wi->fore_color); return ZN_OK; @@ -171,19 +150,12 @@ static void Clone(Item item) { IconItem icon = (IconItem) item; - WidgetInfo *wi = item->wi; - char *text; if (icon->image != ZnUnspecifiedImage) { - text = ZnMalloc((strlen(icon->image_name) + 1) * sizeof(char)); - strcpy(text, icon->image_name); - icon->image_name = text; - icon->image = Tk_GetImage(wi->interp, wi->win, icon->image_name, - IconImageChange, (ClientData) icon); + icon->image = ZnGetImageByValue(icon->image); } - if (icon->mask != ZnUnspecifiedPattern) { - icon->mask = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, icon->mask)); + if (icon->mask != ZnUnspecifiedImage) { + icon->mask = ZnGetImageByValue(icon->mask); } icon->color = ZnGetGradientByValue(icon->color); } @@ -199,19 +171,15 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; IconItem icon = (IconItem) item; if (icon->image != ZnUnspecifiedImage) { - Tk_FreeImage(icon->image); + ZnFreeImage(icon->image); icon->image = ZnUnspecifiedImage; } - if (strlen(icon->image_name) != 0) { - ZnFree(icon->image_name); - } - if (icon->mask != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, icon->mask); - icon->mask = ZnUnspecifiedPattern; + if (icon->mask != ZnUnspecifiedImage) { + ZnFreeImage(icon->mask); + icon->mask = ZnUnspecifiedImage; } ZnFreeGradient(icon->color); } @@ -230,12 +198,11 @@ Configure(Item item, Tcl_Obj *CONST argv[], int *flags) { - IconItem icon = (IconItem) item; - WidgetInfo *wi = item->wi; - Item old_connected; + Item old_connected; old_connected = item->connected_item; - if (ZnConfigureAttributes(wi, item, icon_attrs, argc, argv, flags) == ZN_ERROR) { + if (ZnConfigureAttributes(item->wi, item, icon_attrs, + argc, argv, flags) == ZN_ERROR) { return ZN_ERROR; } @@ -254,13 +221,6 @@ Configure(Item item, } } - if (ISSET(*flags, ZN_IMAGE_FLAG)) { - if (ValidateImage(wi, item, icon->image_name, IconImageChange, - &icon->image, "icon -image") == ZN_ERROR) { - return ZN_ERROR; - } - } - return ZN_OK; } @@ -298,8 +258,7 @@ ComputeCoordinates(Item item, { WidgetInfo *wi = item->wi; IconItem icon = (IconItem) item; - ZnDim width, height; - int w, h; + int width, height; ResetBBox(&item->item_bounding_box); @@ -307,18 +266,16 @@ ComputeCoordinates(Item item, * If there is no image and no mask then nothing to show. */ if (icon->image == ZnUnspecifiedImage && - icon->mask == ZnUnspecifiedPattern) { + icon->mask == ZnUnspecifiedImage) { return; } if (icon->image != ZnUnspecifiedImage) { - Tk_SizeOfImage(icon->image, &w, &h); + ZnSizeOfImage(icon->image, &width, &height); } else { - Tk_SizeOfBitmap(wi->dpy, icon->mask, &w,&h); + ZnSizeOfImage(icon->mask, &width, &height); } - width = w; - height = h; /* * The connected item support anchors, this is checked by @@ -367,21 +324,18 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { IconItem icon = (IconItem) item; - ZnBBox box; + ZnBBox box, *area = ta->area; int w, h; box.orig = icon->pos_dev; if (icon->image != ZnUnspecifiedImage) { - Tk_SizeOfImage(icon->image, &w, &h); + ZnSizeOfImage(icon->image, &w, &h); } - else if (icon->mask != ZnUnspecifiedPattern) { - Tk_SizeOfBitmap(item->wi->dpy, icon->mask, &w, &h); + else if (icon->mask != ZnUnspecifiedImage) { + ZnSizeOfImage(icon->mask, &w, &h); } box.corner.x = box.orig.x + w; box.corner.y = box.orig.y + h; @@ -404,12 +358,11 @@ Draw(Item item) IconItem icon = (IconItem) item; XGCValues values; int gc_mask = 0; - ImageBits *im_bits; - Pixmap pmap, mask_pmap; int w, h; ZnBBox box, inter, *clip_box; Region clip_region; ZnBool simple; + Pixmap pixmap, mask_pmap; if (icon->image != ZnUnspecifiedImage) { /* @@ -424,23 +377,22 @@ Draw(Item item) * using the image mask and the current clip and use this * bitmap as the current clip. */ - Tk_SizeOfImage(icon->image, &w, &h); + 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; IntersectBBox(&box, &wi->damaged_area, &inter); box = inter; - im_bits = GetImageBits(wi->win, icon->image_name, icon->image); - pmap = GetImagePixmap(wi->win, icon->image_name, icon->image, &mask_pmap); ZnCurrentClip(wi, &clip_region, NULL, &simple); - if ((im_bits->mask == ZnUnspecifiedPattern) || simple) { - if (im_bits->mask != ZnUnspecifiedPattern) { + pixmap = ZnImagePixmap(icon->image, &mask_pmap); + 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; XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); } - XCopyArea(wi->dpy, pmap, wi->draw_buffer, wi->gc, + XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, box.orig.x-icon->pos_dev.x, box.orig.y-icon->pos_dev.y, box.corner.x-box.orig.x, box.corner.y-box.orig.y, box.orig.x, box.orig.y); @@ -453,19 +405,18 @@ Draw(Item item) /* * Build of the mask */ - mask_pmap = XCreatePixmap(wi->dpy, ZnWindowId(wi->win), - im_bits->width, im_bits->height, 1); + Pixmap mask_pmap = XCreatePixmap(wi->dpy, ZnWindowId(wi->win), w, h, 1); gc = XCreateGC(wi->dpy, mask_pmap, 0, NULL); - XFillRectangle(wi->dpy, mask_pmap, gc, 0, 0, im_bits->width, im_bits->height); + XFillRectangle(wi->dpy, mask_pmap, gc, 0, 0, w, h); 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; XChangeGC(wi->dpy, gc, - GCForeground|GCBackground|GCClipXOrigin|GCClipYOrigin, &values); - XPutImage(wi->dpy, mask_pmap, gc, im_bits->mask, 0, 0, 0, 0, - im_bits->width, im_bits->height); + GCForeground|GCBackground|GCClipXOrigin|GCClipYOrigin, + &values); + XPutImage(wi->dpy, mask_pmap, gc, ZnImageMask(icon->image), 0, 0, 0, 0, w, h); XFreeGC(wi->dpy, gc); /* * Drawing of the icon using the mask. @@ -474,7 +425,7 @@ Draw(Item item) values.clip_x_origin = (int) icon->pos_dev.x; values.clip_y_origin = (int) icon->pos_dev.y; XChangeGC(wi->dpy, wi->gc, GCClipXOrigin|GCClipYOrigin, &values); - XCopyArea(wi->dpy, pmap, wi->draw_buffer, wi->gc, + XCopyArea(wi->dpy, pixmap, wi->draw_buffer, wi->gc, box.orig.x-icon->pos_dev.x, box.orig.y-icon->pos_dev.y, box.corner.x-box.orig.x, box.corner.y-box.orig.y, box.orig.x, box.orig.y); @@ -484,8 +435,9 @@ Draw(Item item) XFreePixmap(wi->dpy, mask_pmap); } } - else if (icon->mask != ZnUnspecifiedPattern) { - Tk_SizeOfBitmap(wi->dpy, icon->mask, &w,&h); + else if (icon->mask != ZnUnspecifiedImage) { + ZnSizeOfImage(icon->mask, &w, &h); + pixmap = ZnImagePixmap(icon->mask, NULL); box.orig = icon->pos_dev; box.corner.x = icon->pos_dev.x + w; box.corner.y = icon->pos_dev.y + h; @@ -495,7 +447,7 @@ Draw(Item item) box = inter; } values.fill_style = FillStippled; - values.stipple = icon->mask; + values.stipple = pixmap; values.ts_x_origin = icon->pos_dev.x; values.ts_y_origin = icon->pos_dev.y; values.foreground = ZnPixel(ZnGetGradientColor(icon->color, 0, NULL)); @@ -523,12 +475,10 @@ Render(Item item) IconItem icon = (IconItem) item; if (icon->image != ZnUnspecifiedImage) { - RenderImage(wi, GetImageTexture(wi->win, icon->image_name, icon->image), - icon->color, &icon->pos_dev, False); + ZnRenderImage(wi, icon->image, icon->color, &icon->pos_dev, False); } - else if (icon->mask != ZnUnspecifiedPattern) { - RenderImage(wi, (ImageBits *) GetBitmapTexture(wi->dpy, icon->mask), - icon->color, &icon->pos_dev, True); + else if (icon->mask != ZnUnspecifiedImage) { + ZnRenderImage(wi, icon->mask, icon->color, &icon->pos_dev, True); } #endif } @@ -559,18 +509,14 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *part) + ZnPick ps) { IconItem icon = (IconItem) item; WidgetInfo *wi = item->wi; double dist; - int width, height; double off_dist = MAX(1, wi->pick_aperture+1); - + ZnPoint *p = ps->point; + dist = RectangleToPointDist(&item->item_bounding_box, p); /* * If inside the bounding box, try to see if the point @@ -583,44 +529,47 @@ Pick(Item item, * vicinity. */ if (dist <= 0.0) { - BitmapBits *bitmap=NULL; - ImageBits *im_bits; ZnPoint dp; + int x, y, w, h, stride; + char *bpixels; dist = 0.0; dp.x = p->x - icon->pos_dev.x; dp.y = p->y - icon->pos_dev.y; if (icon->image != ZnUnspecifiedImage) { - Tk_SizeOfImage(icon->image, &width, &height); - if (dp.x >= width || dp.y >= height) { - dist = off_dist; - goto out_pick; + ZnSizeOfImage(icon->image, &w, &h); + bpixels = ZnImagePattern(icon->image, &stride); + if (!bpixels) { + /* + * The image has no bitmap pattern + * (i.e, it is rectangular and not a bitmap). + */ + return dist; } - im_bits = GetImageBits(wi->win, icon->image_name, icon->image); - bitmap = im_bits->b_bits; - } - else if (icon->mask != ZnUnspecifiedPattern) { - Tk_SizeOfBitmap(wi->dpy, icon->mask, &width, &height); - if (dp.x >= width || dp.y >= height) { - dist = off_dist; - goto out_pick; + else if ((dp.x >= w) || (dp.y >= h)) { + return off_dist; } - bitmap = GetBitmapMask(wi->dpy, icon->mask); } - if (bitmap != NULL) { - int x = (int) dp.x; - int y = (int) dp.y; - if (! GetBitmapPixel(bitmap, x, y)) { - dist = off_dist; + else if (icon->mask != ZnUnspecifiedImage) { + bpixels = ZnImagePattern(icon->mask, &stride); + ZnSizeOfImage(icon->mask, &w, &h); + if ((dp.x >= w) || (dp.y >= h)) { + return off_dist; } } + else { + return dist; + } + x = (int) dp.x; + y = (int) dp.y; + if (! ZnGetBitmapPixel(bpixels, stride, x, y)) { + dist = off_dist; + } } else if (dist < off_dist) { dist = off_dist; } - -out_pick: - /*printf("dist = %g\n", dist);*/ + return dist; } @@ -655,12 +604,12 @@ GetAnchor(Item item, int w=0, h=0; if ((icon->image != ZnUnspecifiedImage) || - (icon->mask != ZnUnspecifiedPattern)) { + (icon->mask != ZnUnspecifiedImage)) { if (icon->image != ZnUnspecifiedImage) { - Tk_SizeOfImage(icon->image, &w, &h); + ZnSizeOfImage(icon->image, &w, &h); } else { - Tk_SizeOfBitmap(item->wi->dpy, icon->mask, &w, &h); + ZnSizeOfImage(icon->mask, &w, &h); } Origin2Anchor(&icon->pos_dev, w, h, anchor, p); } @@ -689,10 +638,10 @@ GetClipVertices(Item item, ZnListAssertSize(item->wi->work_pts, 2); if (icon->image != ZnUnspecifiedImage) { - Tk_SizeOfImage(icon->image, &w, &h); + ZnSizeOfImage(icon->image, &w, &h); } - else { - Tk_SizeOfBitmap(item->wi->dpy, icon->mask, &w, &h); + else if (icon->mask != ZnUnspecifiedImage) { + ZnSizeOfImage(icon->mask, &w, &h); } points = (ZnPoint *) ZnListArray(item->wi->work_pts); TRI_STRIP1(tristrip, points, 2); @@ -755,7 +704,6 @@ Coords(Item item, */ static ItemClassStruct ICON_ITEM_CLASS = { sizeof(IconItemStruct), - False, /* has_fields */ 0, /* num_parts */ True, /* has_anchors */ "icon", diff --git a/generic/Rectangle.c b/generic/Rectangle.c index d17b62c..5418411 100644 --- a/generic/Rectangle.c +++ b/generic/Rectangle.c @@ -66,20 +66,22 @@ typedef struct _RectangleItemStruct { LineStyle line_style; ZnDim line_width; ZnGradient *line_color; - Pixmap fill_pattern; - Pixmap line_pattern; + ZnImage fill_pattern; + ZnImage line_pattern; ZnGradient *fill_color; - char *tile_name; + ZnImage tile; /* Private data */ ZnPoint dev[4]; - ZnImage tile; ZnGradient *gradient; ZnPoint *grad_geo; } RectangleItemStruct, *RectangleItem; static ZnAttrConfig rect_attrs[] = { + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -91,12 +93,12 @@ static ZnAttrConfig rect_attrs[] = { ZN_COORDS_FLAG|ZN_BORDER_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(RectangleItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False }, - { ZN_CONFIG_PATTERN, "-fillpattern", NULL, + { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(RectangleItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_GRADIENT, "-linecolor", NULL, Tk_Offset(RectangleItemStruct, line_color), 0, ZN_DRAW_FLAG, False }, - { ZN_CONFIG_PATTERN, "-linepattern", NULL, + { ZN_CONFIG_BITMAP, "-linepattern", NULL, Tk_Offset(RectangleItemStruct, line_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-linestyle", NULL, Tk_Offset(RectangleItemStruct, line_style), 0, ZN_DRAW_FLAG, False }, @@ -110,11 +112,10 @@ static ZnAttrConfig rect_attrs[] = { { ZN_CONFIG_BOOL, "-sensitive", NULL, Tk_Offset(RectangleItemStruct, header.flags), SENSITIVE_BIT, ZN_REPICK_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(RectangleItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, - Tk_Offset(RectangleItemStruct, tile_name), 0, - ZN_DRAW_FLAG|ZN_TILE_FLAG, False }, + Tk_Offset(RectangleItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(RectangleItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, @@ -123,28 +124,6 @@ static ZnAttrConfig rect_attrs[] = { }; -/* - ********************************************************************************** - * - * RectTileChange -- - * - ********************************************************************************** - */ -static void -RectTileChange(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) -{ - RectangleItem rect = (RectangleItem) client_data; - - InvalidateImage(rect->tile_name); - ITEM.Invalidate((Item) rect, ZN_COORDS_FLAG); -} - /* ********************************************************************************** @@ -169,6 +148,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_RECTANGLE_PRIORITY; @@ -193,10 +173,9 @@ Init(Item item, rect->relief = RELIEF_FLAT; rect->line_style = LINE_SIMPLE; rect->line_width = 1; - rect->line_pattern = ZnUnspecifiedPattern; - rect->tile_name = ""; + rect->line_pattern = ZnUnspecifiedImage; rect->tile = ZnUnspecifiedImage; - rect->fill_pattern = ZnUnspecifiedPattern; + rect->fill_pattern = ZnUnspecifiedImage; rect->line_color = ZnGetGradientByValue(wi->fore_color); rect->fill_color = ZnGetGradientByValue(wi->fore_color); @@ -215,8 +194,6 @@ static void Clone(Item item) { RectangleItem rect = (RectangleItem) item; - WidgetInfo *wi = item->wi; - char *text; if (rect->gradient) { rect->gradient = ZnGetGradientByValue(rect->gradient); @@ -227,19 +204,13 @@ Clone(Item item) rect->grad_geo = grad_geo; } if (rect->tile != ZnUnspecifiedImage) { - text = ZnMalloc((strlen(rect->tile_name) + 1) * sizeof(char)); - strcpy(text, rect->tile_name); - rect->tile_name = text; - rect->tile = Tk_GetImage(wi->interp, wi->win, rect->tile_name, - RectTileChange, (ClientData) rect); + rect->tile = ZnGetImageByValue(rect->tile); } - if (rect->line_pattern != ZnUnspecifiedPattern) { - rect->line_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, rect->line_pattern)); + if (rect->line_pattern != ZnUnspecifiedImage) { + rect->line_pattern = ZnGetImageByValue(rect->line_pattern); } - if (rect->fill_pattern != ZnUnspecifiedPattern) { - rect->fill_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, rect->fill_pattern)); + if (rect->fill_pattern != ZnUnspecifiedImage) { + rect->fill_pattern = ZnGetImageByValue(rect->fill_pattern); } rect->line_color = ZnGetGradientByValue(rect->line_color); rect->fill_color = ZnGetGradientByValue(rect->fill_color); @@ -256,24 +227,22 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; RectangleItem rect = (RectangleItem) item; if (rect->tile != ZnUnspecifiedImage) { - Tk_FreeImage(rect->tile); + ZnFreeImage(rect->tile); rect->tile = ZnUnspecifiedImage; } - if (strlen(rect->tile_name) != 0) { - ZnFree(rect->tile_name); - } if (rect->gradient) { ZnFreeGradient(rect->gradient); } - if (rect->line_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, rect->line_pattern); + if (rect->line_pattern != ZnUnspecifiedImage) { + ZnFreeImage(rect->line_pattern); + rect->line_pattern = ZnUnspecifiedImage; } - if (rect->fill_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, rect->fill_pattern); + if (rect->fill_pattern != ZnUnspecifiedImage) { + ZnFreeImage(rect->fill_pattern); + rect->fill_pattern = ZnUnspecifiedImage; } if (rect->grad_geo) { ZnFree(rect->grad_geo); @@ -317,12 +286,6 @@ Configure(Item item, status = ZN_ERROR; } } - if (ISSET(*flags, ZN_TILE_FLAG)) { - if (ValidateImage(wi, item, rect->tile_name, RectTileChange, - &rect->tile, "rectangle -tile") == ZN_ERROR) { - status = ZN_ERROR; - } - } return status; } @@ -423,7 +386,7 @@ ComputeCoordinates(Item item, rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } POLY_CONTOUR1(&shape, p, 4); - ComputeAxialGradient(wi, &shape, angle, rect->grad_geo); + ZnComputeAxialGradient(wi, &shape, angle, rect->grad_geo); } else { goto free_ggeo; @@ -435,8 +398,8 @@ ComputeCoordinates(Item item, rect->grad_geo = ZnMalloc(4*sizeof(ZnPoint)); } POLY_CONTOUR1(&shape, rect->dev, 4); - ComputeRadialGradient(wi, &shape, &item->item_bounding_box, - &rect->fill_color->g.p, rect->grad_geo); + ZnComputeRadialGradient(wi, &shape, &item->item_bounding_box, + &rect->fill_color->g.p, rect->grad_geo); } else if (rect->fill_color->type == ZN_PATH_GRADIENT) { if (!rect->grad_geo) { @@ -466,13 +429,11 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { RectangleItem rect = (RectangleItem) item; int result; + ZnBBox *area = ta->area; result = -1; @@ -544,9 +505,8 @@ Draw(Item item) if (ISSET(rect->flags, FILLED_BIT)) { values.foreground = ZnPixel(ZnGetGradientColor(rect->fill_color, 0.0, NULL)); if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ - Pixmap pmap = GetImagePixmap(wi->win, rect->tile_name, rect->tile, NULL); values.fill_style = FillTiled; - values.tile = pmap; + values.tile = ZnImagePixmap(rect->tile, NULL); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; @@ -558,9 +518,9 @@ Draw(Item item) XChangeGC(wi->dpy, wi->gc, GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCTile, &values); } - else if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + else if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = rect->fill_pattern; + values.stipple = ZnImagePixmap(rect->fill_pattern, NULL); if (ISSET(rect->flags, ALIGNED_BIT)) { values.ts_x_origin = (int) r.x; values.ts_y_origin = (int) r.y; @@ -590,8 +550,8 @@ Draw(Item item) if (rect->line_width) { if (rect->relief != RELIEF_FLAT) { if (ISSET(rect->flags, ALIGNED_BIT)) { - DrawRectangleRelief(wi, rect->relief, rect->gradient, - &r, rect->line_width); + ZnDrawRectangleRelief(wi, rect->relief, rect->gradient, + &r, rect->line_width); } else { ZnPoint p[5]; @@ -600,12 +560,12 @@ Draw(Item item) p[4-i].y = rect->dev[i].y; } p[0] = p[4]; - DrawPolygonRelief(wi, rect->relief, rect->gradient, - p, 5, rect->line_width); + ZnDrawPolygonRelief(wi, rect->relief, rect->gradient, + p, 5, rect->line_width); } } else { - SetLineStyle(wi, rect->line_style); + ZnSetLineStyle(wi, rect->line_style); gc_mask = GCFillStyle|GCLineWidth|GCForeground|GCJoinStyle; values.foreground = ZnPixel(ZnGetGradientColor(rect->line_color, 0, NULL)); values.line_width = (rect->line_width == 1) ? 0 : rect->line_width; @@ -614,13 +574,13 @@ Draw(Item item) gc_mask |= GCCapStyle; values.cap_style = CapProjecting; } - if (rect->line_pattern == ZnUnspecifiedPattern) { + if (rect->line_pattern == ZnUnspecifiedImage) { values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } else { values.fill_style = FillStippled; - values.stipple = rect->line_pattern; + values.stipple = ZnImagePixmap(rect->line_pattern, NULL); gc_mask |= GCStipple; XChangeGC(wi->dpy, wi->gc, gc_mask, &values); } @@ -675,22 +635,22 @@ Render(Item item) ZnPoly poly; POLY_CONTOUR1(&poly, rect->dev, 4); - RenderGradient(wi, rect->fill_color, - fast ? NULL: RectRenderCB, rect, - fast ? rect->dev : rect->grad_geo, &poly); + ZnRenderGradient(wi, rect->fill_color, + fast ? NULL: RectRenderCB, rect, + fast ? rect->dev : rect->grad_geo, &poly); } else { if (rect->tile != ZnUnspecifiedImage) { /* Fill tiled */ - RenderTile(wi, GetImageTexture(wi->win, rect->tile_name, rect->tile), - rect->fill_color, RectRenderCB, rect, (ZnPoint *) &item->item_bounding_box); + ZnRenderTile(wi, rect->tile, rect->fill_color, RectRenderCB, + rect, (ZnPoint *) &item->item_bounding_box); } else { - if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + if (rect->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ /* * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(GetBitmapMask(wi->dpy, rect->fill_pattern)->pixels); + glPolygonStipple(ZnImagePattern(rect->fill_pattern, NULL)); } color = ZnGetGradientColor(rect->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -709,13 +669,13 @@ Render(Item item) } p[0] = p[4]; if (rect->relief != RELIEF_FLAT) { - RenderPolygonRelief(wi, rect->relief, rect->gradient, False, - p, 5, rect->line_width); + ZnRenderPolygonRelief(wi, rect->relief, rect->gradient, False, + p, 5, rect->line_width); } else { - RenderPolyline(wi, p, 5, rect->line_width, - rect->line_style, CapRound, JoinMiter, - NULL, NULL, rect->line_color); + ZnRenderPolyline(wi, p, 5, rect->line_width, + rect->line_style, CapRound, JoinMiter, + NULL, NULL, rect->line_color); } } #endif @@ -747,14 +707,11 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *part) + ZnPick ps) { RectangleItem rect = (RectangleItem) item; double best_dist; + ZnPoint *p = ps->point; best_dist = PolygonToPointDist(rect->dev, 4, p); @@ -926,7 +883,6 @@ Coords(Item item, */ static ItemClassStruct RECTANGLE_ITEM_CLASS = { sizeof(RectangleItemStruct), - False, /* has_fields */ 0, /* num_parts */ False, /* has_anchors */ "rectangle", diff --git a/generic/Text.c b/generic/Text.c index 64e0c21..e5aaa97 100644 --- a/generic/Text.c +++ b/generic/Text.c @@ -84,7 +84,7 @@ typedef struct _TextItemStruct { ZnAnchor connection_anchor; ZnGradient *color; char *text; - Pixmap fill_pattern; + ZnImage fill_pattern; ZnFont font; ZnJustify alignment; ZnDim width; @@ -98,19 +98,22 @@ typedef struct _TextItemStruct { ZnList text_info; int max_width; #ifdef GLX - TexFont *txf; + ZnTexFontInfo *tfi; #endif } TextItemStruct, *TextItem; static ZnAttrConfig text_attrs[] = { - { ZN_CONFIG_JUSTIFY, "-alignment", NULL, + { ZN_CONFIG_ALIGNMENT, "-alignment", NULL, Tk_Offset(TextItemStruct, alignment), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, { ZN_CONFIG_ANCHOR, "-anchor", NULL, Tk_Offset(TextItemStruct, anchor), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_GRADIENT, "-color", NULL, Tk_Offset(TextItemStruct, color), 0, ZN_DRAW_FLAG, False }, + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(TextItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(TextItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -122,7 +125,7 @@ static ZnAttrConfig text_attrs[] = { ZN_COORDS_FLAG|ZN_ITEM_FLAG, False }, { ZN_CONFIG_ANCHOR, "-connectionanchor", NULL, Tk_Offset(TextItemStruct, connection_anchor), 0, ZN_COORDS_FLAG, False }, - { ZN_CONFIG_PATTERN, "-fillpattern", NULL, + { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(TextItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_FONT, "-font", NULL, Tk_Offset(TextItemStruct, font), 0, @@ -140,9 +143,9 @@ static ZnAttrConfig text_attrs[] = { { ZN_CONFIG_DIM, "-spacing", NULL, Tk_Offset(TextItemStruct, spacing), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(TextItemStruct, header.tags), 0, 0, False }, - { ZN_CONFIG_TEXT, "-text", NULL, + { ZN_CONFIG_STRING, "-text", NULL, Tk_Offset(TextItemStruct, text), 0, ZN_COORDS_FLAG|ZN_LAYOUT_FLAG, False }, { ZN_CONFIG_BOOL, "-underlined", NULL, @@ -178,6 +181,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_TEXT_PRIORITY; @@ -185,17 +189,20 @@ Init(Item item, text->pos.x = text->pos.y = 0.0; text->text = ""; text->num_chars = 0; - text->fill_pattern = ZnUnspecifiedPattern; + text->fill_pattern = ZnUnspecifiedImage; text->anchor = ZnAnchorNW; text->connection_anchor = ZnAnchorSW; text->color = ZnGetGradientByValue(wi->fore_color); text->alignment = ZnJustifyLeft; text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(wi->font)); - text->width = 0; - text->spacing = 0; #ifdef GLX - text->txf = NULL; + text->tfi = NULL; + if (wi->render) { + text->tfi = ZnGetTexFont(wi, text->font); + } #endif + text->width = 0; + text->spacing = 0; text->insert_index = 0; CLEAR(text->flags, UNDERLINED); CLEAR(text->flags, OVERSTRIKED); @@ -223,13 +230,17 @@ Clone(Item item) strcpy(str, text->text); text->text = str; } - if (text->fill_pattern != ZnUnspecifiedPattern) { - text->fill_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, text->fill_pattern)); + if (text->fill_pattern != ZnUnspecifiedImage) { + text->fill_pattern = ZnGetImageByValue(text->fill_pattern); } text->color = ZnGetGradientByValue(text->color); text->font = Tk_GetFont(wi->interp, wi->win, Tk_NameOfFont(text->font)); - +#ifdef GLX + if (wi->render) { + text->tfi = ZnGetTexFont(wi, text->font); + } +#endif + /* * We always need to invalidate, either because the model * has not done its layout (text_info == NULL) or because @@ -251,18 +262,22 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; TextItem text = (TextItem) item; if (strlen(text->text) != 0) { ZnFree(text->text); } - if (text->fill_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, text->fill_pattern); - text->fill_pattern = ZnUnspecifiedPattern; + if (text->fill_pattern != ZnUnspecifiedImage) { + ZnFreeImage(text->fill_pattern); + text->fill_pattern = ZnUnspecifiedImage; } ZnFreeGradient(text->color); Tk_FreeFont(text->font); +#ifdef GLX + if (text->tfi) { + ZnFreeTexFont(text->tfi); + } +#endif if (text->text_info) { ZnListFree(text->text_info); @@ -297,7 +312,15 @@ Configure(Item item, #ifdef GLX if (old_font != text->font) { - text->txf = NULL; + if (text->tfi) { + ZnFreeTexFont(text->tfi); + } + if (item->wi->render) { + text->tfi = ZnGetTexFont(item->wi, text->font); + if (!text->tfi) { + return ZN_ERROR; + } + } } #endif num_chars = strlen(text->text); @@ -544,10 +567,7 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { TextItem text = (TextItem) item; int inside = -1; @@ -556,7 +576,7 @@ ToArea(Item item, TextLineInfo lines, lines_ptr; Tk_FontMetrics fm; int font_height; - ZnBBox line_bbox; + ZnBBox line_bbox, *area = ta->area; ZnPoint o; if (!text->text_info) { @@ -762,9 +782,9 @@ Draw(Item item) values.font = ZnFontId(text->font); values.foreground = ZnPixel(ZnGetGradientColor(text->color, 0, NULL)); gc_mask = GCFont | GCForeground; - if (text->fill_pattern != ZnUnspecifiedPattern) { + if (text->fill_pattern != ZnUnspecifiedImage) { values.fill_style = FillStippled; - values.stipple = text->fill_pattern; + values.stipple = ZnImagePixmap(text->fill_pattern, NULL); gc_mask |= GCFillStyle | GCStipple; } else { @@ -832,13 +852,7 @@ Render(Item item) int sel_first_line=-1, sel_last_line=-1, cursor_line=-1; int sel_start_offset=0, sel_stop_offset=0, cursor_offset=0; - if (!text->text_info) { - return; - } - if (!text->txf) { - text->txf = GetTexFont(wi->win, text->font); - } - if (!text->txf) { + if (!text->text_info || !text->tfi) { return; } @@ -869,12 +883,12 @@ Render(Item item) /* * Render the selection. */ - color = ZnGetGradientColor(ti->sel_color, 0, &alpha); - alpha = ZnComposeAlpha(alpha, wi->alpha); - glColor4us(color->red, color->green, color->blue, alpha); if ((ti->sel_item == item) && (sel_first_line >= 0)) { ZnReal xo, yo, xc, yc; + color = ZnGetGradientColor(ti->sel_color, 0, &alpha); + alpha = ZnComposeAlpha(alpha, wi->alpha); + glColor4us(color->red, color->green, color->blue, alpha); glBegin(GL_QUADS); if (sel_first_line == sel_last_line) { xo = text->pos_dev.x + lines[sel_first_line].text_origin.x + sel_start_offset; @@ -921,13 +935,13 @@ Render(Item item) /* * Render the cursor. */ - color = ZnGetGradientColor(ti->insert_color, 0, &alpha); - alpha = ZnComposeAlpha(alpha, wi->alpha); - glColor4us(color->red, color->green, color->blue, alpha); if ((cursor_line >= 0) && (wi->focus_item == item) && ti->cursor_on) { int xs, ys; + color = ZnGetGradientColor(ti->insert_color, 0, &alpha); + alpha = ZnComposeAlpha(alpha, wi->alpha); + glColor4us(color->red, color->green, color->blue, alpha); glLineWidth(ti->insert_width); xs = text->pos_dev.x + lines[cursor_line].text_origin.x + cursor_offset; ys = text->pos_dev.y + lines[cursor_line].text_origin.y - fm.ascent + 1; @@ -942,7 +956,7 @@ Render(Item item) */ glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glBindTexture(GL_TEXTURE_2D, text->txf->texobj); + glBindTexture(GL_TEXTURE_2D, ZnTexFontTex(text->tfi)); color = ZnGetGradientColor(text->color, 0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); glColor4us(color->red, color->green, color->blue, alpha); @@ -955,7 +969,7 @@ Render(Item item) glPushMatrix(); glTranslatef(xs, ys, 0.0); - txfRenderString(text->txf, lines_ptr->start, lines_ptr->num_chars); + ZnRenderString(text->tfi, lines_ptr->start, lines_ptr->num_chars); glPopMatrix(); if (ISSET(text->flags, UNDERLINED) || ISSET(text->flags, OVERSTRIKED)) { @@ -1007,11 +1021,7 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *part) + ZnPick ps) { TextItem text = (TextItem) item; double dist = 1.0e40, new_dist; @@ -1020,7 +1030,7 @@ Pick(Item item, Tk_FontMetrics fm; int font_height; ZnBBox line_bbox; - ZnPoint o; + ZnPoint o, *p = ps->point; if (!text->text_info) { return dist; @@ -1566,7 +1576,6 @@ Selection(Item item, */ static ItemClassStruct TEXT_ITEM_CLASS = { sizeof(TextItemStruct), - False, /* has_fields */ 0, /* num_parts */ True, /* has_anchors */ "text", -- cgit v1.1