aboutsummaryrefslogtreecommitdiff
path: root/generic/Rectangle.c
diff options
context:
space:
mode:
authorlecoanet2002-05-16 09:40:36 +0000
committerlecoanet2002-05-16 09:40:36 +0000
commitf8c4a63cf27597af47f88363b45abfc0f869e660 (patch)
treeb1e13b5cf3c08f6f391501a2c7306d638060c6e8 /generic/Rectangle.c
parentfc5443fb490fcb2c4eafc084db91000a08068c71 (diff)
downloadtkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.zip
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.gz
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.bz2
tkzinc-f8c4a63cf27597af47f88363b45abfc0f869e660.tar.xz
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
Diffstat (limited to 'generic/Rectangle.c')
-rw-r--r--generic/Rectangle.c152
1 files changed, 54 insertions, 98 deletions
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",