DrRndRect.c revision 6c321187
1/* $Xorg: DrRndRect.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */
2
3/*
4
5Copyright 1988, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from The Open Group.
26
27*/
28/* $XFree86: xc/lib/Xmu/DrRndRect.c,v 1.6 2001/01/17 19:42:54 dawes Exp $ */
29
30/*
31 * XmuDrawRoundedRectangle, XmuFillRoundedRectangle
32 *
33 * Draw/Fill a rounded rectangle, where x, y, w, h are the dimensions of
34 * the overall rectangle, and ew and eh are the sizes of a bounding box
35 * that the corners are drawn inside of.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include <config.h>
40#endif
41#include <X11/Xlib.h>
42#include <X11/Xmu/Drawing.h>
43
44void
45XmuDrawRoundedRectangle(Display *dpy, Drawable draw, GC gc,
46			int x, int y, int w, int h, int ew, int eh)
47{
48	XArc	arcs[8];
49  int ew2, eh2;
50
51  if ((ew2 = (ew << 1)) > w)
52    ew2 = ew = 0;
53  if ((eh2 = (eh << 1)) > h)
54    eh2 = eh = 0;
55
56	arcs[0].x = x;
57	arcs[0].y = y;
58  arcs[0].width = ew2;
59  arcs[0].height = eh2;
60  arcs[0].angle1 = 180 * 64;
61  arcs[0].angle2 = -90 * 64;
62
63	arcs[1].x = x + ew;
64	arcs[1].y = y;
65  arcs[1].width = w - ew2;
66	arcs[1].height = 0;
67  arcs[1].angle1 = 180 * 64;
68  arcs[1].angle2 = -180 * 64;
69
70  arcs[2].x = x + w - ew2;
71	arcs[2].y = y;
72  arcs[2].width = ew2;
73  arcs[2].height = eh2;
74  arcs[2].angle1 = 90 * 64;
75  arcs[2].angle2 = -90 * 64;
76
77	arcs[3].x = x + w;
78	arcs[3].y = y + eh;
79	arcs[3].width = 0;
80  arcs[3].height = h - eh2;
81	arcs[3].angle1 = 90 * 64;
82  arcs[3].angle2 = -180 * 64;
83
84  arcs[4].x = x + w - ew2;
85  arcs[4].y = y + h - eh2;
86  arcs[4].width = ew2;
87  arcs[4].height = eh2;
88	arcs[4].angle1 = 0;
89  arcs[4].angle2 = -90 * 64;
90
91	arcs[5].x = x + ew;
92	arcs[5].y = y + h;
93  arcs[5].width = w - ew2;
94	arcs[5].height = 0;
95	arcs[5].angle1 = 0;
96  arcs[5].angle2 = -180 * 64;
97
98	arcs[6].x = x;
99  arcs[6].y = y + h - eh2;
100  arcs[6].width = ew2;
101  arcs[6].height = eh2;
102  arcs[6].angle1 = 270 * 64;
103  arcs[6].angle2 = -90 * 64;
104
105	arcs[7].x = x;
106	arcs[7].y = y + eh;
107	arcs[7].width = 0;
108  arcs[7].height = h - eh2;
109  arcs[7].angle1 = 270 * 64;
110  arcs[7].angle2 = -180 * 64;
111
112  XDrawArcs(dpy, draw, gc, arcs, 8);
113}
114
115void
116XmuFillRoundedRectangle(Display *dpy, Drawable draw, GC gc,
117			int x, int y, int w, int h, int ew, int eh)
118{
119	XArc	arcs[4];
120	XRectangle rects[3];
121	XGCValues vals;
122  int ew2, eh2;
123
124	XGetGCValues(dpy, gc, GCArcMode, &vals);
125	if (vals.arc_mode != ArcPieSlice)
126	    XSetArcMode(dpy, gc, ArcPieSlice);
127
128  if ((ew2 = (ew << 1)) > w)
129    ew2 = ew = 0;
130  if ((eh2 = (eh << 1)) > h)
131    eh2 = eh = 0;
132
133	arcs[0].x = x;
134	arcs[0].y = y;
135  arcs[0].width = ew2;
136  arcs[0].height = eh2;
137  arcs[0].angle1 = 180 * 64;
138  arcs[0].angle2 = -90 * 64;
139
140  arcs[1].x = x + w - ew2 - 1;
141	arcs[1].y = y;
142  arcs[1].width = ew2;
143  arcs[1].height = eh2;
144  arcs[1].angle1 = 90 * 64;
145  arcs[1].angle2 = -90 * 64;
146
147  arcs[2].x = x + w - ew2 - 1;
148  arcs[2].y = y + h - eh2 - 1;
149  arcs[2].width = ew2;
150  arcs[2].height = eh2;
151	arcs[2].angle1 = 0;
152  arcs[2].angle2 = -90 * 64;
153
154	arcs[3].x = x;
155  arcs[3].y = y + h - eh2 - 1;
156  arcs[3].width = ew2;
157  arcs[3].height = eh2;
158  arcs[3].angle1 = 270 * 64;
159  arcs[3].angle2 = -90 * 64;
160
161  XFillArcs(dpy, draw, gc, arcs, 4);
162
163	rects[0].x = x + ew;
164	rects[0].y = y;
165  rects[0].width = w - ew2;
166	rects[0].height = h;
167
168	rects[1].x = x;
169	rects[1].y = y + eh;
170	rects[1].width = ew;
171  rects[1].height = h - eh2;
172
173	rects[2].x = x + w - ew;
174	rects[2].y = y + eh;
175	rects[2].width = ew;
176  rects[2].height = h - eh2;
177
178  XFillRectangles(dpy, draw, gc, rects, 3);
179
180	if (vals.arc_mode != ArcPieSlice)
181	    XSetArcMode(dpy, gc, vals.arc_mode);
182}
183