diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Arc.c | 178 |
1 files changed, 65 insertions, 113 deletions
diff --git a/generic/Arc.c b/generic/Arc.c index 5911b29..53d6367 100644 --- a/generic/Arc.c +++ b/generic/Arc.c @@ -53,8 +53,7 @@ static const char compile_id[]="$Compile: " __FILE__ " " __DATE__ " " __TIME__ " #define USING_POLY_BIT 1<<5 -static double Pick(Item item, ZnPoint *p, Item start_item, int aperture, - Item *a_item, int *a_part); +static double Pick(Item item, ZnPick ps); /* @@ -71,15 +70,15 @@ typedef struct _ArcItemStruct { ZnPoint coords[2]; int start_angle; int angle_extent; - Pixmap line_pattern; - Pixmap fill_pattern; + ZnImage line_pattern; + ZnImage fill_pattern; ZnGradient *fill_color; ZnGradient *line_color; ZnDim line_width; LineStyle line_style; ZnLineEnd first_end; ZnLineEnd last_end; - char *tile_name; + ZnImage tile; unsigned short flags; /* Private data */ @@ -87,7 +86,6 @@ typedef struct _ArcItemStruct { ZnPoint corner; ZnPoint center1; ZnPoint center2; - ZnImage tile; ZnList render_shape; ZnPoint *grad_geo; } ArcItemStruct, *ArcItem; @@ -96,6 +94,9 @@ typedef struct _ArcItemStruct { static ZnAttrConfig arc_attrs[] = { { ZN_CONFIG_BOOL, "-closed", NULL, Tk_Offset(ArcItemStruct, flags), CLOSED_BIT, ZN_COORDS_FLAG, False }, + { ZN_CONFIG_BOOL, "-composealpha", NULL, + Tk_Offset(ArcItemStruct, header.flags), COMPOSE_ALPHA_BIT, + ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-composerotation", NULL, Tk_Offset(ArcItemStruct, header.flags), COMPOSE_ROTATION_BIT, ZN_COORDS_FLAG, False }, @@ -108,7 +109,7 @@ static ZnAttrConfig arc_attrs[] = { Tk_Offset(ArcItemStruct, fill_color), 0, ZN_COORDS_FLAG, False }, { ZN_CONFIG_BOOL, "-filled", NULL, Tk_Offset(ArcItemStruct, flags), FILLED_BIT, ZN_COORDS_FLAG, False }, - { ZN_CONFIG_PATTERN, "-fillpattern", NULL, + { ZN_CONFIG_BITMAP, "-fillpattern", NULL, Tk_Offset(ArcItemStruct, fill_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_END, "-firstend", NULL, Tk_Offset(ArcItemStruct, first_end), 0, ZN_COORDS_FLAG, False }, @@ -117,7 +118,7 @@ static ZnAttrConfig arc_attrs[] = { { ZN_CONFIG_GRADIENT, "-linecolor", NULL, Tk_Offset(ArcItemStruct, line_color), 0, ZN_DRAW_FLAG|ZN_BORDER_FLAG, False }, - { ZN_CONFIG_PATTERN, "-linepattern", NULL, + { ZN_CONFIG_BITMAP, "-linepattern", NULL, Tk_Offset(ArcItemStruct, line_pattern), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_LINE_STYLE, "-linestyle", NULL, Tk_Offset(ArcItemStruct, line_style), 0, ZN_DRAW_FLAG, False }, @@ -133,11 +134,10 @@ static ZnAttrConfig arc_attrs[] = { ZN_REPICK_FLAG, False }, { ZN_CONFIG_ANGLE, "-startangle", NULL, Tk_Offset(ArcItemStruct, start_angle), 0, ZN_COORDS_FLAG, False }, - { ZN_CONFIG_TAGS, "-tags", NULL, + { ZN_CONFIG_TAG_LIST, "-tags", NULL, Tk_Offset(ArcItemStruct, header.tags), 0, 0, False }, { ZN_CONFIG_IMAGE, "-tile", NULL, - Tk_Offset(ArcItemStruct, tile_name), 0, - ZN_DRAW_FLAG|ZN_TILE_FLAG, False }, + Tk_Offset(ArcItemStruct, tile), 0, ZN_DRAW_FLAG, False }, { ZN_CONFIG_BOOL, "-visible", NULL, Tk_Offset(ArcItemStruct, header.flags), VISIBLE_BIT, ZN_DRAW_FLAG|ZN_REPICK_FLAG|ZN_VIS_FLAG, False }, @@ -149,29 +149,6 @@ static ZnAttrConfig arc_attrs[] = { /* ********************************************************************************** * - * ArcTileChange -- - * - ********************************************************************************** - */ -static void -ArcTileChange(ClientData client_data, - int x, - int y, - int width, - int height, - int image_width, - int image_height) -{ - ArcItem arc = (ArcItem) client_data; - - InvalidateImage(arc->tile_name); - ITEM.Invalidate((Item) arc, ZN_COORDS_FLAG); -} - - -/* - ********************************************************************************** - * * Init -- * ********************************************************************************** @@ -189,6 +166,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_ARC_PRIORITY; @@ -199,13 +177,12 @@ Init(Item item, CLEAR(arc->flags, CLOSED_BIT); CLEAR(arc->flags, PIE_SLICE_BIT); CLEAR(arc->flags, USING_POLY_BIT); - arc->line_pattern = ZnUnspecifiedPattern; - arc->fill_pattern = ZnUnspecifiedPattern; + arc->line_pattern = ZnUnspecifiedImage; + arc->fill_pattern = ZnUnspecifiedImage; + arc->tile = ZnUnspecifiedImage; arc->line_style = LINE_SIMPLE; arc->line_width = 1; arc->first_end = arc->last_end = NULL; - arc->tile_name = ""; - arc->tile = ZnUnspecifiedImage; arc->render_shape = NULL; arc->grad_geo = NULL; @@ -243,8 +220,6 @@ static void Clone(Item item) { ArcItem arc = (ArcItem) item; - WidgetInfo *wi = item->wi; - char *text; if (arc->grad_geo) { ZnPoint *grad_geo = ZnMalloc(4*sizeof(ZnPoint)); @@ -252,11 +227,7 @@ Clone(Item item) arc->grad_geo = grad_geo; } if (arc->tile != ZnUnspecifiedImage) { - text = ZnMalloc((strlen(arc->tile_name) + 1) * sizeof(char)); - strcpy(text, arc->tile_name); - arc->tile_name = text; - arc->tile = Tk_GetImage(wi->interp, wi->win, arc->tile_name, - ArcTileChange, (ClientData) arc); + arc->tile = ZnGetImageByValue(arc->tile); } if (arc->first_end) { LineEndDuplicate(arc->first_end); @@ -264,13 +235,11 @@ Clone(Item item) if (arc->last_end) { LineEndDuplicate(arc->last_end); } - if (arc->line_pattern != ZnUnspecifiedPattern) { - arc->line_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, arc->line_pattern)); + if (arc->line_pattern != ZnUnspecifiedImage) { + arc->line_pattern = ZnGetImageByValue(arc->line_pattern); } - if (arc->fill_pattern != ZnUnspecifiedPattern) { - arc->fill_pattern = Tk_GetBitmap(wi->interp, wi->win, - Tk_NameOfBitmap(wi->dpy, arc->fill_pattern)); + if (arc->fill_pattern != ZnUnspecifiedImage) { + arc->fill_pattern = ZnGetImageByValue(arc->fill_pattern); } arc->line_color = ZnGetGradientByValue(arc->line_color); arc->fill_color = ZnGetGradientByValue(arc->fill_color); @@ -290,7 +259,6 @@ Clone(Item item) static void Destroy(Item item) { - WidgetInfo *wi = item->wi; ArcItem arc = (ArcItem) item; if (arc->render_shape) { @@ -303,17 +271,16 @@ Destroy(Item item) LineEndDelete(arc->last_end); } if (arc->tile != ZnUnspecifiedImage) { - Tk_FreeImage(arc->tile); + ZnFreeImage(arc->tile); arc->tile = ZnUnspecifiedImage; } - if (strlen(arc->tile_name) != 0) { - ZnFree(arc->tile_name); - } - if (arc->line_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, arc->line_pattern); + if (arc->line_pattern != ZnUnspecifiedImage) { + ZnFreeImage(arc->line_pattern); + arc->line_pattern = ZnUnspecifiedImage; } - if (arc->fill_pattern != ZnUnspecifiedPattern) { - Tk_FreeBitmap(wi->dpy, arc->fill_pattern); + if (arc->fill_pattern != ZnUnspecifiedImage) { + ZnFreeImage(arc->fill_pattern); + arc->fill_pattern = ZnUnspecifiedImage; } if (arc->grad_geo) { ZnFree(arc->grad_geo); @@ -363,12 +330,8 @@ Configure(Item item, int status = ZN_OK; status = ZnConfigureAttributes(item->wi, item, arc_attrs, argc, argv, flags); - - if (ISSET(*flags, ZN_TILE_FLAG)) { - if (ValidateImage(item->wi, item, arc->tile_name, ArcTileChange, - &arc->tile, "arc -tile") == ZN_ERROR) { - status = ZN_ERROR; - } + if (arc->start_angle < 0) { + arc->start_angle = 360 + arc->start_angle; } SetRenderFlags(arc); @@ -469,16 +432,12 @@ UpdateRenderShape(ArcItem arc) { ZnPoint *p_list, p, p2, o, o2; ZnReal width, height, d; - int num_p, i, quality, extent; + int num_p, i, quality; ZnTransfo *t = ((Item) arc)->wi->current_transfo; if (!arc->render_shape) { arc->render_shape = ZnListNew(8, sizeof(ZnPoint)); } - extent = arc->angle_extent; - if (extent == 360) { - extent = 0; - } o.x = (arc->coords[1].x + arc->coords[0].x)/2.0; o.y = (arc->coords[1].y + arc->coords[0].y)/2.0; width = (arc->coords[1].x - arc->coords[0].x)/2.0; @@ -488,7 +447,7 @@ UpdateRenderShape(ArcItem arc) p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, quality, DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->start_angle+extent), + DegreesToRadian(arc->angle_extent), &num_p, arc->render_shape); @@ -513,7 +472,7 @@ UpdateRenderShape(ArcItem arc) p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, quality, DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->start_angle+extent), + DegreesToRadian(arc->angle_extent), &num_p, arc->render_shape); } @@ -595,16 +554,18 @@ ComputeCoordinates(Item item, p[3].x = p[0].x; p[3].y = p[2].y; POLY_CONTOUR1(&shape, p, 4); - ComputeAxialGradient(wi, &shape, arc->fill_color->g.angle, arc->grad_geo); + ZnComputeAxialGradient(wi, &shape, arc->fill_color->g.angle, + arc->grad_geo); } else if (arc->fill_color->type == ZN_RADIAL_GRADIENT) { POLY_CONTOUR1(&shape, ZnListArray(arc->render_shape), ZnListSize(arc->render_shape)); - ComputeRadialGradient(wi, &shape, &item->item_bounding_box, - &arc->fill_color->g.p, arc->grad_geo); + ZnComputeRadialGradient(wi, &shape, &item->item_bounding_box, + &arc->fill_color->g.p, arc->grad_geo); } else if (arc->fill_color->type == ZN_PATH_GRADIENT) { - ZnTransformPoint(wi->current_transfo, &arc->fill_color->g.p, &arc->grad_geo[0]); + ZnTransformPoint(wi->current_transfo, &arc->fill_color->g.p, + &arc->grad_geo[0]); } } else { @@ -749,21 +710,19 @@ ComputeCoordinates(Item item, */ static int ToArea(Item item, - ZnBBox *area, - Tk_Uid tag_uid, - int enclosed, - ZnBool report) + ZnToArea ta) { ArcItem arc = (ArcItem) item; ZnPoint *points; ZnPoint pts[20]; /* Should be at least LINE_END_POINTS large */ ZnPoint center, tang; - ZnBBox t_area; + ZnBBox t_area, *area = ta->area; int num_points, result=-1, result2; ZnReal lw = arc->line_width; ZnReal rx, ry, angle, tmp; ZnBool inside, new_inside; - + ZnPickStruct ps; + if (ISSET(arc->flags, USING_POLY_BIT) && (ISSET(arc->flags, FILLED_BIT) || (arc->line_width))) { points = ZnListArray(arc->render_shape); @@ -1015,7 +974,8 @@ ToArea(Item item, * to see if it's inside the arc. If it is, we've got overlap. If * it isn't, the arc's really outside the rectangle. */ - if (Pick(item, &area->orig, ZN_NO_ITEM, 0, NULL, NULL) == 0.0) { + ps.point = &area->orig; + if (Pick(item, &ps) == 0.0) { return 0; } @@ -1063,18 +1023,17 @@ Draw(Item item) values.foreground = ZnPixel(ZnGetGradientColor(arc->fill_color, 0.0, NULL)); values.arc_mode = ISSET(arc->flags, PIE_SLICE_BIT) ? ArcPieSlice : ArcChord; if (arc->tile != ZnUnspecifiedImage) { /* Fill Tiled */ - Pixmap pmap = GetImagePixmap(wi->win, arc->tile_name, arc->tile, NULL); values.fill_style = FillTiled; - values.tile = pmap; + values.tile = ZnImagePixmap(arc->tile, NULL); 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|GCArcMode, &values); } - else if (arc->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + else if (arc->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ values.fill_style = FillStippled; - values.stipple = arc->fill_pattern; + values.stipple = ZnImagePixmap(arc->fill_pattern, NULL); 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, @@ -1104,19 +1063,19 @@ Draw(Item item) XPoint xap[LINE_END_POINTS]; ZnPoint tang; - SetLineStyle(wi, arc->line_style); + ZnSetLineStyle(wi, arc->line_style); values.foreground = ZnPixel(ZnGetGradientColor(arc->line_color, 0, NULL)); values.line_width = (arc->line_width == 1) ? 0 : arc->line_width; values.cap_style = CapRound; values.join_style = JoinRound; - if (arc->line_pattern == ZnUnspecifiedPattern) { + if (arc->line_pattern == ZnUnspecifiedImage) { values.fill_style = FillSolid; XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCLineWidth|GCCapStyle|GCJoinStyle|GCForeground, &values); } else { values.fill_style = FillStippled; - values.stipple = arc->line_pattern; + values.stipple = ZnImagePixmap(arc->line_pattern, NULL); XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCStipple|GCLineWidth|GCCapStyle|GCJoinStyle|GCForeground, &values); @@ -1256,20 +1215,22 @@ Render(Item item) if (!ZnGradientFlat(arc->fill_color)) { ZnPoly poly; - POLY_CONTOUR1(&poly, ZnListArray(arc->render_shape), ZnListSize(arc->render_shape)); - RenderGradient(wi, arc->fill_color,ArcRenderCB, arc, arc->grad_geo, &poly); + POLY_CONTOUR1(&poly, ZnListArray(arc->render_shape), + ZnListSize(arc->render_shape)); + ZnRenderGradient(wi, arc->fill_color,ArcRenderCB, arc, + arc->grad_geo, &poly); } else if (arc->tile != ZnUnspecifiedImage) { /* Fill tiled */ - RenderTile(wi, GetImageTexture(wi->win, arc->tile_name, arc->tile), - arc->fill_color, ArcRenderCB, arc, (ZnPoint *) &item->item_bounding_box); + ZnRenderTile(wi, arc->tile, arc->fill_color, ArcRenderCB, arc, + (ZnPoint *) &item->item_bounding_box); } else { - if (arc->fill_pattern != ZnUnspecifiedPattern) { /* Fill stippled */ + if (arc->fill_pattern != ZnUnspecifiedImage) { /* Fill stippled */ /* * Setup polygon stippling. */ glEnable(GL_POLYGON_STIPPLE); - glPolygonStipple(GetBitmapMask(wi->dpy, arc->fill_pattern)->pixels); + glPolygonStipple(ZnImagePattern(arc->fill_pattern, NULL)); } color = ZnGetGradientColor(arc->fill_color, 0.0, &alpha); alpha = ZnComposeAlpha(alpha, wi->alpha); @@ -1297,9 +1258,9 @@ Render(Item item) } } } - RenderPolyline(wi, p, num_points, arc->line_width, - arc->line_style, CapRound, JoinRound, first, last, - arc->line_color); + ZnRenderPolyline(wi, p, num_points, arc->line_width, + arc->line_style, CapRound, JoinRound, first, last, + arc->line_color); } #endif } @@ -1330,18 +1291,14 @@ IsSensitive(Item item, */ static double Pick(Item item, - ZnPoint *p, - Item start_item, - int aperture, - Item *a_item, - int *a_part) + ZnPick ps) { ArcItem arc = (ArcItem) item; double dist = 1e40, new_dist; ZnBool point_in_angle, filled, closed; ZnBool in_triangle, acute_angle; ZnPoint p1, center, tang; - ZnPoint *points; + ZnPoint *points, *p = ps->point; ZnPoint end_points[LINE_END_POINTS]; int num_points; int width, height; @@ -1616,20 +1573,16 @@ static void UpdateRenderShapeX(ArcItem arc) { ZnReal ox, oy, width_2, height_2; - int i, num_p, extent; + int i, num_p; ZnPoint *p_list; if (!arc->render_shape) { arc->render_shape = ZnListNew(8, sizeof(ZnPoint)); } - extent = arc->angle_extent; - if (extent == 360) { - extent = 0; - } p_list = GetCirclePoints(ISCLEAR(arc->flags, PIE_SLICE_BIT) ? 1 : 2, ZN_CIRCLE_FINE, DegreesToRadian(arc->start_angle), - DegreesToRadian(arc->start_angle+extent), + DegreesToRadian(arc->angle_extent), &num_p, arc->render_shape); ox = (arc->corner.x + arc->orig.x) / 2.0; oy = (arc->corner.y + arc->orig.y) / 2.0; @@ -1781,7 +1734,6 @@ PostScript(Item item, */ static ItemClassStruct ARC_ITEM_CLASS = { sizeof(ArcItemStruct), - False, /* has_fields */ 0, /* num_parts */ False, /* has_anchors */ "arc", |