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