aboutsummaryrefslogtreecommitdiff
path: root/generic/Draw.c
blob: 26d952fc584a04679e263a4cb2114026274ac59d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/*
 * Draw.c -- Implementation of common drawing routines.
 *
 * Authors		: Patrick Lecoanet.
 * Creation date	: Sat Dec 10 12:51:30 1994
 *
 * $Id$
 */

/*
 *  Copyright (c) 1993 - 1999 CENA, Patrick Lecoanet --
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this code; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


/*
 **********************************************************************************
 *
 * The algorihms used to draw the arrows, to do the 3d effects and to
 * smooth the polygons are adapted from Tk.
 *
 **********************************************************************************
 */

#include "config.h"
#include "Types.h"
#include "Draw.h"
#include "Geo.h"
#include "List.h"
#include "WidgetInfo.h"

#include <math.h>
#include <stdarg.h>
#include <alloca.h>


#define	POLYGON_RELIEF_DRAW	0
#define	POLYGON_RELIEF_DIST	1
#define	POLYGON_RELIEF_BBOX	2
#define	POLYGON_RELIEF_IN_BBOX	3

#define	TOP_CONTRAST		13
#define BOTTOM_CONTRAST		6
#define MAX_INTENSITY		65535

#define ARROW_SHAPE_B		10.0
#define ARROW_SHAPE_C		5.0
#define OPEN_ARROW_SHAPE_A	4.0
#define CLOSED_ARROW_SHAPE_A	ARROW_SHAPE_B

#define LIGHTNING_SHAPE_A_RATIO	10.0
#define LIGHTNING_SHAPE_B_RATIO	8.0


/*
 **********************************************************************************
 *
 * SetLineStyle -- 
 *
 **********************************************************************************
 */
void
SetLineStyle(Display	*display,
	     GC		gc,
	     LineStyle	line_style)
{
  XGCValues		values;
  static const char	dashed[] = { 8 };
  static const char	dotted[] = { 2, 5 };
  static const char	mixed[]  = { 8, 5, 2, 5 };

  values.line_style = LineOnOffDash;
  switch (line_style) {
  case LINE_DASHED :
    XSetDashes(display, gc, 0, dashed, 1);
    break;
  case LINE_MIXED :
    XSetDashes(display, gc, 0, mixed, 4);
    break;
  case LINE_DOTTED :
    XSetDashes(display, gc, 0, dotted, 2);
    break;
  default:
    values.line_style = LineSolid;
    break;
  }
  XChangeGC(display, gc, GCLineStyle, &values);
}


/*
 **********************************************************************************
 *
 * GetLineShape --
 *	Compute the points describing the given line shape between point p1 and p2.
 *	If bbox is non null, it is filled with the bounding box of the shape.
 *
 * For the time being this procedure handles straight lines, right and left
 * lightnings, right and left corners, right and left double corners..
 *
 *
 * Here are the parameters for lightnings:
 *
 *                                        *******
 *                                 *******     *
 *                           ******           *
 *                     ******      ******+   *
 *               ******      ******     *   *|
 *         ******      ******          *   * | LIGHTNING_SHAPE_A
 *   ******      ******               *   *  |
 *         ******                    *   *   |
 * ..******.........................+.+.*........................******..
 *   |                             *   *                    ******
 *   |                            *   *               ******      ******
 *   |                           *   *          ******      ******
 *   |                          *   *     ******      ******
 *   |                         *   *******      ******
 *   |                        *          ******
 *   |                       *     ******
 *   |                      ********   
 *   |                         |    | |
 *   |                         |----| | LIGHTNING_SHAPE_B
 *   |                                |
 *   |--------------------------------| LENGTH / 2
 *
 **********************************************************************************
 */
void
GetLineShape(ZnPoint		*p1,
	     ZnPoint		*p2,
	     unsigned int	line_width,
	     LineShape		shape,
	     ZnBBox		*bbox,
	     ZnList		to_points)
{
  ZnPoint	*points;
  int		num_points, i;

  /*
   * Compute all line points according to shape.
   */
  if ((shape == LINE_LEFT_LIGHTNING) ||
      (shape == LINE_RIGHT_LIGHTNING)) {
    double	alpha, theta;
    double	length, length2;
    double	shape_a, shape_b;
    double	dx, dy;
    double	temp;

    num_points = LIGHTNING_POINTS;
    ZnListAssertSize(to_points, num_points);
    points = (ZnPoint *) ZnListArray(to_points);

    points[0] = *p1;
    points[3] = *p2;

    dx = p2->x - p1->x;
    dy = p2->y - p1->y;
    length = hypot(dx, dy);
    shape_a = length/LIGHTNING_SHAPE_A_RATIO + ((double) line_width)/2;
    shape_b = length/LIGHTNING_SHAPE_B_RATIO + ((double) line_width)/2;

    if (shape == LINE_LEFT_LIGHTNING)
      alpha = atan2(shape_a, shape_b);
    else
      alpha = -atan2(shape_a, shape_b);
    length2 = hypot(shape_a, shape_b);
    theta = atan2(-dy, dx);

    dx = p1->x + dx/2;
    dy = p1->y + dy/2;
    temp = cos(theta + alpha) * length2;
    points[1].x = dx + temp;
    points[2].x = dx - temp;
    temp = sin(theta + alpha) * length2;
    points[1].y = dy - temp;
    points[2].y = dy + temp;
  }
  else if (shape == LINE_LEFT_CORNER ||
	   shape == LINE_RIGHT_CORNER) {
    num_points = CORNER_POINTS;
    ZnListAssertSize(to_points, num_points);
    points = (ZnPoint *) ZnListArray(to_points);

    points[0] = *p1;
    points[2] = *p2;

    if (shape == LINE_LEFT_CORNER) {
      points[1].x = p1->x;
      points[1].y = p2->y;
    }
    else {
      points[1].x = p2->x;
      points[1].y = p1->y;
    }
  }
  else if (shape == LINE_DOUBLE_LEFT_CORNER ||
	   shape == LINE_DOUBLE_RIGHT_CORNER) {
    int	dx, dy;

    num_points = DOUBLE_CORNER_POINTS;
    ZnListAssertSize(to_points, num_points);
    points = (ZnPoint *) ZnListArray(to_points);

    points[0] = *p1;
    points[3] = *p2;

    if (shape == LINE_DOUBLE_LEFT_CORNER) {
      dy = p2->y - p1->y;
      points[1].x = p1->x;
      points[2].x = p2->x;
      points[1].y = points[2].y = p1->y + dy/2;
    }
    else {
      dx = p2->x - p1->x;
      points[1].x = points[2].x = p1->x + dx/2;
      points[1].y = p1->y;
      points[2].y = p2->y;
    }
  }
  else /* if (shape) == LINE_STRAIGHT) */ {
    num_points = STRAIGHT_POINTS;
    ZnListAssertSize(to_points, num_points);
    points = (ZnPoint *) ZnListArray(to_points);

    points[0] = *p1;
    points[1] = *p2;
  }

  /*
   * Fill in the bbox, if requested.
   */
  if (bbox) {
    ResetBBox(bbox);
    for (i = 0; i < num_points; i++) {
      AddPointToBBox(bbox, points[i].x, points[i].y);
    }
    
    /* Enlarge to take line_width into account. */
    if (line_width > 1) {
      int lw_2 = (line_width+1)/2;
      
      bbox->orig.x -= lw_2;
      bbox->orig.y -= lw_2;
      bbox->corner.x += lw_2;
      bbox->corner.y += lw_2;
    }
  }
}


/*
 **********************************************************************************
 *
 * DrawLineShape --
 *	Draw a line given the points describing its path. It is designed to work
 *	with GetLineShape albeit it does fairly trivial things. In the future some
 *	shapes might need cooperation between the two and the clients will be ready
 *	for that.
 *
 *
 **********************************************************************************
 */
void
DrawLineShape(Display		*display,
	      Drawable		draw_buffer,
	      GC		gc,
	      ZnPoint		*p,
	      int		num_p,
	      LineStyle		line_style,
	      ZnColor		foreground,
	      unsigned int	line_width,
	      LineShape		shape)
{
  XPoint	*xpoints;
  int		i;
  XGCValues	values;

  /*
   * Setup GC.
   */
  SetLineStyle(display, gc, line_style);
  values.foreground = ZnPixel(foreground);
  values.line_width = (line_width == 1) ? 0 : line_width;
  values.fill_style = FillSolid;
  values.join_style = JoinRound;
  values.cap_style = CapRound;
  XChangeGC(display, gc,
	    GCFillStyle | GCLineWidth | GCJoinStyle | GCCapStyle | GCForeground, &values);
  xpoints = (XPoint *) alloca(num_p * sizeof(XPoint));
  for (i = 0; i < num_p; i++) {
    xpoints[i].x = p[i].x;
    xpoints[i].y = p[i].y;
  }
  XDrawLines(display, draw_buffer, gc, xpoints, num_p, CoordModeOrigin);
}


/*
 **********************************************************************************
 *
 * DrawRectangleRelief --
 *	Draw the bevels inside bbox.
 *
 **********************************************************************************
 */
void
DrawRectangleRelief(WidgetInfo		*wi,
		    ReliefStyle		relief,
		    ZnColorGradient	gradient,
		    XRectangle		*bbox,
		    unsigned int	line_width)
{
  XGCValues  	gc_values;
  XPoint	top_points[7];
  
  /*
   * If we haven't enough space to draw, exit.
   */
  if ((bbox->width < 2*line_width) || (bbox->height < 2*line_width)) {
    return;
  }
  
  /*
   * Grooves and ridges are drawn with two recursives calls with
   * half the width of the original one.
   */
  if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) {
    unsigned int	new_line_width;
    int			offset;
    XRectangle		internal_bbox;
    
    new_line_width = line_width/2;
    offset = line_width - new_line_width;
    DrawRectangleRelief(wi,
 			(relief==RELIEF_GROOVE)?RELIEF_BEVEL_IN:RELIEF_BEVEL_OUT,
 			gradient, bbox, new_line_width);
    internal_bbox = *bbox;
    internal_bbox.x +=offset;
    internal_bbox.y += offset;
    internal_bbox.width -= offset*2;
    internal_bbox.height -= offset*2;
    DrawRectangleRelief(wi,
 			(relief==RELIEF_GROOVE)?RELIEF_BEVEL_OUT:RELIEF_BEVEL_IN,
 			gradient, &internal_bbox, new_line_width);
    return;
  }

  gc_values.fill_style = FillSolid;
  if (relief == RELIEF_BEVEL_IN) {
    gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, -1);
  }
  else {
    gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, 0);
  }
  XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &gc_values);
  XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc,
 		 bbox->x, bbox->y + bbox->height - line_width,
 		 bbox->width, line_width);
  XFillRectangle(wi->dpy, wi->draw_buffer, wi->gc,
 		 bbox->x + bbox->width - line_width, bbox->y,
 		 line_width, bbox->height);

  if (relief == RELIEF_BEVEL_IN) {
    gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, 0);
  }
  else {
    gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, -1);
  }
  XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &gc_values);
  top_points[0].x = top_points[1].x = top_points[6].x = bbox->x;
  top_points[0].y = top_points[6].y = bbox->y + bbox->height;
  top_points[1].y = top_points[2].y = bbox->y;
  top_points[2].x = bbox->x + bbox->width;
  top_points[3].x = bbox->x + bbox->width - line_width;
  top_points[3].y = top_points[4].y = bbox->y + line_width;
  top_points[4].x = top_points[5].x = bbox->x + line_width;
  top_points[5].y = bbox->y + bbox->height - line_width;
  XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, top_points, 7,
	       Nonconvex, CoordModeOrigin);
}


static void
DoPolygonRelief(ZnPoint		*p,
		int		num_points,
		unsigned int	line_width,
		int		what_to_do,
		...)
{
  int			i, j, processed_points, *result;
  ZnPoint		*p1, *p2;
  ZnPoint		pp1, pp2, new_pp1, new_pp2;
  ZnPoint		perp, c, shift1, shift2;
  ZnPoint		bevel_points[4];
  XPoint		bevel_xpoints[4];
  ZnBool		parallel, closed;
  WidgetInfo		*wi = NULL;
  ReliefStyle		relief = 0;
  ZnColorGradient	gradient = NULL;
  ZnPoint		*pp = NULL;
  double		*dist = NULL;
  ZnBBox		*bbox = NULL;
  va_list		var;

  va_start(var, what_to_do);
  if (what_to_do == POLYGON_RELIEF_DIST) {
    pp = va_arg(var, ZnPoint *);
    dist = va_arg(var, double *);
    *dist = 1.0e40;
  }
  if (what_to_do == POLYGON_RELIEF_IN_BBOX) {
    bbox = va_arg(var, ZnBBox *);
    result = va_arg(var, int *);
  }
  else if (what_to_do == POLYGON_RELIEF_BBOX) {
    bbox = va_arg(var, ZnBBox *);
    ResetBBox(bbox);
  }
  else if (what_to_do == POLYGON_RELIEF_DRAW) {
    wi = va_arg(var, WidgetInfo *);
    relief = va_arg(var, int);
    gradient = va_arg(var, ZnColorGradient);
  }
  va_end(var);

  /*
   * If the polygon is closed (last point is the same as first) open it by
   * dropping the last point. The algorithm closes the path automatically.
   * We remember this to decide if we draw the last bevel or not and if we
   * need to generate ends perpendicular to the path..
   */
  closed = False;
  if ((p->x == p[num_points-1].x) && (p->y == p[num_points-1].y)) {
    closed = True;
    num_points--;
  }

  /*
   * We loop on all vertices of the polygon.
   * At each step we try to compute the corresponding border
   * corner `corner'. Then we build a polygon for the bevel.
   * Things look like this:
   *
   *          bevel[1]     /
   *             *        /
   *		 |       /
   *             |      /
   *         pp1 *    * p[i-1]
   *             |    | bevel[0]
   *             |    |
   *             |    |
   *             |    | bevel[3]
   *             |    | p[i]
   *             |    | p1                 p2
   *         pp2 *    *--------------------*
   *             |
   *             |
   *      corner *----*--------------------*
   *     bevel[2]   new_pp1             new_pp2
   *
   * pp1 and pp2 are the ends of a segment // to p1 p2 at line_width
   * from it. These points are *NOT* necessarily on the perpendicular
   * going through p1 or p2.
   * This loop needs a bootstrap phase of two iterations (i.e we need to
   * process two points). This is why we start at the point before the last
   * and then wrap to the first point.
   * The algorithm discards any duplicate contiguous points.
   * It makes a special case if two consecutives edges are parallel:
   *
   *  bevel[1]      pp1            pp2        a bevel[2]
   *    *-----------*--------------*----------*
   *                                           \
   *                                            \
   *     p[i-1]                                  \  bevel[3]
   *       *--------*-------------------------*---* corner
   *    bevel[0]    p2                       p1  /
   *                                            /
   *                                           /
   *      ----------*-----------*-------------*
   *             new_pp1     new_pp2          c
   *
   * In such a case we need to compute a, b, corner from pp1, pp2, new_pp1
   * and new_pp2. We compute the perpendicular to p&,p2 through p1, intersect
   * it with pp1,pp2 to obtain a, intersect it with new_pp1, new_pp2 to
   * obtain c, shift a,c and intersect it with p1,p2 to obtain corner.
   *
   */

  processed_points = 0;
  if (!closed) {
    i = 0;
    p1 = p;
  }
  else {
    i = -2;
    p1 = &p[num_points-2];
  }
  for (p2 = p1+1; i < num_points; i++, p1 = p2, p2++) {
    /*
     * When it is time to wrap, do it
     */
    if ((i == -1) || (i == num_points-1)) {
      p2 = p;
    }
    
    /*
     * Skip over duplicate vertices.
     */
    if ((p2->x == p1->x) && (p2->y == p1->y)) {
      continue;
    }

    ShiftLine(p1, p2, line_width, &new_pp1, &new_pp2);
    bevel_points[3] = *p1;
    parallel = False;
    /*
     * The first two cases are for `open' polygons. We compute
     * a bevel closure that is perpendicular to the path.
     */
    if ((processed_points == 0) && !closed) {
      perp.x = p1->x + (p2->y - p1->y);
      perp.y = p1->y - (p2->x - p1->x);
      IntersectLines(p1, &perp, &new_pp1, &new_pp2, &bevel_points[2]);
    }
    else if ((processed_points == num_points-1) && !closed) {
      perp.x = p1->x + ((p1-1)->y - p1->y);
      perp.y = p1->y - ((p1-1)->x - p1->x);
      IntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]);      
    }
    else if (processed_points >= 1) {
      parallel = !IntersectLines(&new_pp1, &new_pp2, &pp1, &pp2, &bevel_points[2]);
      if (parallel) {
	perp.x = p1->x + (p2->y - p1->y);
	perp.y = p1->y - (p2->x - p1->x);
	IntersectLines(p1, &perp, &pp1, &pp2, &bevel_points[2]);
	IntersectLines(p1, &perp, &new_pp1, &new_pp2, &c);
	ShiftLine(p1, &perp, line_width, &shift1, &shift2);
	IntersectLines(p1, p2, &shift1, &shift2, &bevel_points[3]);
      }
    }

    if ((processed_points >= 2) || (!closed && (processed_points == 1))) {
      if (what_to_do == POLYGON_RELIEF_DIST) {
	double	new_dist;

	new_dist = PolygonToPointDist(bevel_points, 4, pp);
	if (new_dist < 0) {
	  new_dist = 0;
	}
	*dist = MIN(*dist, new_dist);
      }
      else if (what_to_do == POLYGON_RELIEF_IN_BBOX) {
	if (processed_points <= 2) {
	  *result = PolygonInBBox(bevel_points, 4, bbox);
	  if (*result == 0) {
	    return;
	  }
	}
	else {
	  if (PolygonInBBox(bevel_points, 4, bbox) != *result) {
	    *result = 0;
	    return;
	  }
	}
      }
      else if (what_to_do == POLYGON_RELIEF_BBOX) {
	int	i;
	
	for (i = 0; i < 4; i++) {
	  AddPointToBBox(bbox, bevel_points[i].x, bevel_points[i].y);
	}
      }
      else if (what_to_do == POLYGON_RELIEF_DRAW) {
	ZnReal	dx, dy;
	ZnBool	light_on_left;
	XGCValues	gc_values;

	dx = bevel_points[3].x - bevel_points[0].x;
	dy = bevel_points[3].y - bevel_points[0].y;
	if (dx > 0.0) {
	  light_on_left = (dy <= dx);
	}
	else {
	  light_on_left = (dy < dx);
	}
	
	gc_values.fill_style = FillSolid;
	if (light_on_left ^ (relief == RELIEF_BEVEL_OUT)) {
	  gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, -1);
	}
	else {
	  gc_values.foreground = ZnColorGradientPixel(gradient, wi->win, 0);
	}
	XChangeGC(wi->dpy, wi->gc, GCFillStyle|GCForeground, &gc_values);
	
	for (j = 0; j < 4; j++) {
	  bevel_xpoints[j].x = REAL_TO_INT(bevel_points[j].x);
	  bevel_xpoints[j].y = REAL_TO_INT(bevel_points[j].y);
	}
	XFillPolygon(wi->dpy, wi->draw_buffer, wi->gc, bevel_xpoints, 4,
		     Convex, CoordModeOrigin);
      }
    }

    pp1 = new_pp1;
    pp2 = new_pp2;
    bevel_points[0] = bevel_points[3];
    if (parallel) {
      bevel_points[1] = c;
    }
    else if ((processed_points >= 1) || !closed) {
      bevel_points[1] = bevel_points[2];
    }

    processed_points++;
  }
}


/*
 **********************************************************************************
 *
 * GetPolygonReliefBBox --
 *	Returns the bevelled polygon bounding box.
 *
 **********************************************************************************
 */
void
GetPolygonReliefBBox(ZnList		points,
		     unsigned int	line_width,
		     ZnBBox		*bbox)
{
  DoPolygonRelief(ZnListArray(points), ZnListSize(points),
		  line_width, POLYGON_RELIEF_BBOX, bbox);
}


/*
 **********************************************************************************
 *
 * PolygonReliefInBBox --
 *	Returns (-1) if the relief is entirely outside the bbox, (1) if it is
 *	entirely inside or (0) if in between
 *
 **********************************************************************************
 */
int
PolygonReliefInBBox(ZnList		points,
		    unsigned int	line_width,
		    ZnBBox		*area)
{
  int	result;

  DoPolygonRelief(ZnListArray(points), ZnListSize(points),
		  line_width, POLYGON_RELIEF_IN_BBOX, area, &result);

  return result;
}


/*
 **********************************************************************************
 *
 * PolygonReliefToPointDist --
 *	Returns the distance between the given point and
 *	the bevelled polygon.
 *
 **********************************************************************************
 */
double
PolygonReliefToPointDist(ZnList		points,
			 unsigned int	line_width,
			 ZnPoint	*pp)
{
  double	dist;

  DoPolygonRelief(ZnListArray(points), ZnListSize(points),
		  line_width, POLYGON_RELIEF_DIST, pp, &dist);

  return dist;
}


/*
 **********************************************************************************
 *
 * DrawPolygonRelief --
 *	Draw the bevels around path.
 *
 **********************************************************************************
 */
void
DrawPolygonRelief(WidgetInfo		*wi,
		  ReliefStyle		relief,
		  ZnColorGradient	gradient,
		  ZnPoint		*points,
		  int			num_points,
		  int			line_width)
{
  /*
   * Grooves and ridges are drawn with two calls. The first
   * with the original width, the second with half the width.
   */
  if ((relief == RELIEF_RIDGE) || (relief == RELIEF_GROOVE)) {
    DoPolygonRelief(points, num_points, line_width, POLYGON_RELIEF_DRAW, wi,
  		    (int) (relief==RELIEF_GROOVE)?RELIEF_BEVEL_OUT:RELIEF_BEVEL_IN,
 		    gradient);
    DoPolygonRelief(points, num_points, line_width/2, POLYGON_RELIEF_DRAW, wi,
 		    (int) (relief==RELIEF_GROOVE)?RELIEF_BEVEL_IN:RELIEF_BEVEL_OUT,
 		    gradient);
  }
  else {
    DoPolygonRelief(points, num_points, line_width, POLYGON_RELIEF_DRAW, wi,
		    (int) relief, gradient);
  }
}