aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generic/Rectangle.c113
1 files changed, 70 insertions, 43 deletions
diff --git a/generic/Rectangle.c b/generic/Rectangle.c
index 19146a6..10bf3e4 100644
--- a/generic/Rectangle.c
+++ b/generic/Rectangle.c
@@ -67,7 +67,8 @@ typedef struct _RectangleItemStruct {
ZnColor line_color;
Pixmap fill_pattern;
Pixmap line_pattern;
- ZnColor fill_color;
+ ZnColorGradient fill_color;
+ ZnGradientGeom grad_geom;
char *tile_name;
/* Private data */
@@ -84,13 +85,15 @@ static ZnAttrConfig rect_attrs[] = {
{ ZN_CONFIG_BOOL, "-composescale", NULL,
Tk_Offset(RectangleItemStruct, header.flags), COMPOSE_SCALE_BIT,
ZN_COORDS_FLAG, False },
- { ZN_CONFIG_COLOR, "-fillcolor", NULL,
+ { ZN_CONFIG_GRADIENT_COLOR, "-fillcolor", NULL,
Tk_Offset(RectangleItemStruct, fill_color), 0,
ZN_DRAW_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,
Tk_Offset(RectangleItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False },
+ { ZN_CONFIG_GRADIENT_GEOM, "-gradient", NULL,
+ Tk_Offset(RectangleItemStruct, grad_geom), 0, ZN_DRAW_FLAG, False },
{ ZN_CONFIG_COLOR, "-linecolor", NULL,
Tk_Offset(RectangleItemStruct, line_color), 0,
ZN_DRAW_FLAG, False },
@@ -223,7 +226,9 @@ Init(Item item,
rect->tile = ZnUnspecifiedImage;
rect->fill_pattern = ZnUnspecifiedPattern;
rect->line_color = ZnGetColorByValue(wi->win, wi->fore_color);
- rect->fill_color = ZnGetColorByValue(wi->win, wi->fore_color);
+ rect->fill_color = ZnGetColorGradient(wi->interp, wi->win,
+ ZnNameOfColor(wi->fore_color));
+ rect->grad_geom = NULL;
return ZN_OK;
}
@@ -262,7 +267,10 @@ Clone(Item item)
Tk_NameOfBitmap(wi->dpy, rect->fill_pattern));
}
rect->line_color = ZnGetColorByValue(wi->win, rect->line_color);
- rect->fill_color = ZnGetColorByValue(wi->win, rect->fill_color);
+ rect->fill_color = ZnGetColorGradientByValue(rect->fill_color);
+ if (rect->grad_geom) {
+ rect->grad_geom = GradientGeomDuplicate(rect->grad_geom);
+ }
}
@@ -295,8 +303,11 @@ Destroy(Item item)
if (rect->fill_pattern != ZnUnspecifiedPattern) {
Tk_FreeBitmap(wi->dpy, rect->fill_pattern);
}
- ZnFreeColor(rect->fill_color);
+ ZnFreeColorGradient(rect->fill_color);
ZnFreeColor(rect->line_color);
+ if (rect->grad_geom) {
+ GradientGeomDelete(rect->grad_geom);
+ }
}
@@ -326,7 +337,7 @@ Configure(Item item,
}
if ((rect->relief != RELIEF_FLAT) && !rect->gradient) {
rect->gradient = ZnGetReliefGradient(wi->interp, wi->win,
- ZnNameOfColor(rect->fill_color));
+ ZnNameOfColor(ZnColorGradientMidColor(wi->win, rect->fill_color)));
}
if (ISSET(*flags, ZN_TILE_FLAG)) {
Tk_Image tile;
@@ -389,6 +400,7 @@ ComputeCoordinates(Item item,
WidgetInfo *wi = item->wi;
RectangleItem rect = (RectangleItem) item;
ZnPoint p[4];
+ int i;
ResetBBox(&item->item_bounding_box);
if (!rect->line_width && ISCLEAR(rect->flags, FILLED_BIT)) {
@@ -402,6 +414,10 @@ ComputeCoordinates(Item item,
p[3].x = p[0].x;
p[3].y = p[2].y;
ZnTransformPoints(wi->current_transfo, p, rect->dev, 4);
+ for (i = 0; i < 4; i++) {
+ rect->dev[i].x = REAL_TO_INT(rect->dev[i].x);
+ rect->dev[i].y = REAL_TO_INT(rect->dev[i].y);
+ }
/*
* Add all points to the bounding box. Then expand by the line
@@ -485,26 +501,26 @@ Draw(Item item)
if (aligned) {
if (rect->dev[0].x < rect->dev[2].x) {
- r.x = REAL_TO_INT(rect->dev[0].x);
- r.width = REAL_TO_INT(rect->dev[2].x) - r.x;
+ r.x = rect->dev[0].x;
+ r.width = rect->dev[2].x - r.x;
}
else {
- r.x = REAL_TO_INT(rect->dev[2].x);
- r.width = REAL_TO_INT(rect->dev[0].x) - r.x;
+ r.x = rect->dev[2].x;
+ r.width = rect->dev[0].x - r.x;
}
if (rect->dev[0].y < rect->dev[2].y) {
- r.y = REAL_TO_INT(rect->dev[0].y);
- r.height = REAL_TO_INT(rect->dev[2].y) - r.y;
+ r.y = rect->dev[0].y;
+ r.height = rect->dev[2].y - r.y;
}
else {
- r.y = REAL_TO_INT(rect->dev[2].y);
- r.height = REAL_TO_INT(rect->dev[0].y) - r.y;
+ r.y = rect->dev[2].y;
+ r.height = rect->dev[0].y - r.y;
}
}
else {
for (i = 0; i < 4; i++) {
- xp[i].x = REAL_TO_INT(rect->dev[i].x);
- xp[i].y = REAL_TO_INT(rect->dev[i].y);
+ xp[i].x = rect->dev[i].x;
+ xp[i].y = rect->dev[i].y;
}
xp[i] = xp[0];
}
@@ -513,35 +529,46 @@ Draw(Item item)
* Fill if requested.
*/
if (ISSET(rect->flags, FILLED_BIT)) {
- values.foreground = ZnPixel(rect->fill_color);
- 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.ts_x_origin = (int) item->item_bounding_box.orig.x;
- values.ts_y_origin = (int) item->item_bounding_box.orig.y;
- XChangeGC(wi->dpy, wi->gc,
- GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCTile, &values);
- }
- else if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */
- values.fill_style = FillStippled;
- values.stipple = rect->fill_pattern;
- values.ts_x_origin = (int) item->item_bounding_box.orig.x;
- values.ts_y_origin = (int) item->item_bounding_box.orig.y;
- XChangeGC(wi->dpy, wi->gc,
- GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCStipple|GCForeground,
- &values);
- }
- else { /* Fill solid */
- values.fill_style = FillSolid;
- XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle, &values);
- }
- if (aligned) {
- XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y,
- r.width, r.height);
+ if (rect->grad_geom) {
+ if (aligned) {
+ DrawRectangleGradient(wi, rect->grad_geom, rect->fill_color, &r);
+ }
+ else {
+ DrawPolygonGradient(wi, rect->grad_geom, rect->fill_color, rect->dev, 4,
+ &item->item_bounding_box);
+ }
}
else {
- XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, 4, Convex, CoordModeOrigin);
+ values.foreground = ZnPixel(ZnColorGradientMidColor(wi->win, rect->fill_color));
+ 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.ts_x_origin = (int) item->item_bounding_box.orig.x;
+ values.ts_y_origin = (int) item->item_bounding_box.orig.y;
+ XChangeGC(wi->dpy, wi->gc,
+ GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCTile, &values);
+ }
+ else if (rect->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */
+ values.fill_style = FillStippled;
+ values.stipple = rect->fill_pattern;
+ values.ts_x_origin = (int) item->item_bounding_box.orig.x;
+ values.ts_y_origin = (int) item->item_bounding_box.orig.y;
+ XChangeGC(wi->dpy, wi->gc,
+ GCTileStipXOrigin|GCTileStipYOrigin|GCFillStyle|GCStipple|GCForeground,
+ &values);
+ }
+ else { /* Fill solid */
+ values.fill_style = FillSolid;
+ XChangeGC(wi->dpy, wi->gc, GCForeground | GCFillStyle, &values);
+ }
+ if (aligned) {
+ XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc, r.x, r.y,
+ r.width, r.height);
+ }
+ else {
+ XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, xp, 4, Convex, CoordModeOrigin);
+ }
}
}