16c321187Smrg/* 26c321187Smrg 36c321187SmrgCopyright 1988, 1998 The Open Group 46c321187Smrg 56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its 66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that 76c321187Smrgthe above copyright notice appear in all copies and that both that 86c321187Smrgcopyright notice and this permission notice appear in supporting 96c321187Smrgdocumentation. 106c321187Smrg 116c321187SmrgThe above copyright notice and this permission notice shall be included in 126c321187Smrgall copies or substantial portions of the Software. 136c321187Smrg 146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 206c321187Smrg 216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be 226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings 236c321187Smrgin this Software without prior written authorization from The Open Group. 246c321187Smrg 256c321187Smrg*/ 266c321187Smrg 276c321187Smrg/* 286c321187Smrg * XmuDrawRoundedRectangle, XmuFillRoundedRectangle 296c321187Smrg * 306c321187Smrg * Draw/Fill a rounded rectangle, where x, y, w, h are the dimensions of 316c321187Smrg * the overall rectangle, and ew and eh are the sizes of a bounding box 326c321187Smrg * that the corners are drawn inside of. 336c321187Smrg */ 346c321187Smrg 356c321187Smrg#ifdef HAVE_CONFIG_H 366c321187Smrg#include <config.h> 376c321187Smrg#endif 386c321187Smrg#include <X11/Xlib.h> 396c321187Smrg#include <X11/Xmu/Drawing.h> 406c321187Smrg 416c321187Smrgvoid 426c321187SmrgXmuDrawRoundedRectangle(Display *dpy, Drawable draw, GC gc, 436c321187Smrg int x, int y, int w, int h, int ew, int eh) 446c321187Smrg{ 456c321187Smrg XArc arcs[8]; 466c321187Smrg int ew2, eh2; 476c321187Smrg 486c321187Smrg if ((ew2 = (ew << 1)) > w) 496c321187Smrg ew2 = ew = 0; 506c321187Smrg if ((eh2 = (eh << 1)) > h) 516c321187Smrg eh2 = eh = 0; 526c321187Smrg 536c321187Smrg arcs[0].x = x; 546c321187Smrg arcs[0].y = y; 556c321187Smrg arcs[0].width = ew2; 566c321187Smrg arcs[0].height = eh2; 576c321187Smrg arcs[0].angle1 = 180 * 64; 586c321187Smrg arcs[0].angle2 = -90 * 64; 596c321187Smrg 606c321187Smrg arcs[1].x = x + ew; 616c321187Smrg arcs[1].y = y; 626c321187Smrg arcs[1].width = w - ew2; 636c321187Smrg arcs[1].height = 0; 646c321187Smrg arcs[1].angle1 = 180 * 64; 656c321187Smrg arcs[1].angle2 = -180 * 64; 666c321187Smrg 676c321187Smrg arcs[2].x = x + w - ew2; 686c321187Smrg arcs[2].y = y; 696c321187Smrg arcs[2].width = ew2; 706c321187Smrg arcs[2].height = eh2; 716c321187Smrg arcs[2].angle1 = 90 * 64; 726c321187Smrg arcs[2].angle2 = -90 * 64; 736c321187Smrg 746c321187Smrg arcs[3].x = x + w; 756c321187Smrg arcs[3].y = y + eh; 766c321187Smrg arcs[3].width = 0; 776c321187Smrg arcs[3].height = h - eh2; 786c321187Smrg arcs[3].angle1 = 90 * 64; 796c321187Smrg arcs[3].angle2 = -180 * 64; 806c321187Smrg 816c321187Smrg arcs[4].x = x + w - ew2; 826c321187Smrg arcs[4].y = y + h - eh2; 836c321187Smrg arcs[4].width = ew2; 846c321187Smrg arcs[4].height = eh2; 856c321187Smrg arcs[4].angle1 = 0; 866c321187Smrg arcs[4].angle2 = -90 * 64; 876c321187Smrg 886c321187Smrg arcs[5].x = x + ew; 896c321187Smrg arcs[5].y = y + h; 906c321187Smrg arcs[5].width = w - ew2; 916c321187Smrg arcs[5].height = 0; 926c321187Smrg arcs[5].angle1 = 0; 936c321187Smrg arcs[5].angle2 = -180 * 64; 946c321187Smrg 956c321187Smrg arcs[6].x = x; 966c321187Smrg arcs[6].y = y + h - eh2; 976c321187Smrg arcs[6].width = ew2; 986c321187Smrg arcs[6].height = eh2; 996c321187Smrg arcs[6].angle1 = 270 * 64; 1006c321187Smrg arcs[6].angle2 = -90 * 64; 1016c321187Smrg 1026c321187Smrg arcs[7].x = x; 1036c321187Smrg arcs[7].y = y + eh; 1046c321187Smrg arcs[7].width = 0; 1056c321187Smrg arcs[7].height = h - eh2; 1066c321187Smrg arcs[7].angle1 = 270 * 64; 1076c321187Smrg arcs[7].angle2 = -180 * 64; 1086c321187Smrg 1096c321187Smrg XDrawArcs(dpy, draw, gc, arcs, 8); 1106c321187Smrg} 1116c321187Smrg 1126c321187Smrgvoid 1136c321187SmrgXmuFillRoundedRectangle(Display *dpy, Drawable draw, GC gc, 1146c321187Smrg int x, int y, int w, int h, int ew, int eh) 1156c321187Smrg{ 1166c321187Smrg XArc arcs[4]; 1176c321187Smrg XRectangle rects[3]; 1186c321187Smrg XGCValues vals; 1196c321187Smrg int ew2, eh2; 1206c321187Smrg 1216c321187Smrg XGetGCValues(dpy, gc, GCArcMode, &vals); 1226c321187Smrg if (vals.arc_mode != ArcPieSlice) 1236c321187Smrg XSetArcMode(dpy, gc, ArcPieSlice); 1246c321187Smrg 1256c321187Smrg if ((ew2 = (ew << 1)) > w) 1266c321187Smrg ew2 = ew = 0; 1276c321187Smrg if ((eh2 = (eh << 1)) > h) 1286c321187Smrg eh2 = eh = 0; 1296c321187Smrg 1306c321187Smrg arcs[0].x = x; 1316c321187Smrg arcs[0].y = y; 1326c321187Smrg arcs[0].width = ew2; 1336c321187Smrg arcs[0].height = eh2; 1346c321187Smrg arcs[0].angle1 = 180 * 64; 1356c321187Smrg arcs[0].angle2 = -90 * 64; 1366c321187Smrg 1376c321187Smrg arcs[1].x = x + w - ew2 - 1; 1386c321187Smrg arcs[1].y = y; 1396c321187Smrg arcs[1].width = ew2; 1406c321187Smrg arcs[1].height = eh2; 1416c321187Smrg arcs[1].angle1 = 90 * 64; 1426c321187Smrg arcs[1].angle2 = -90 * 64; 1436c321187Smrg 1446c321187Smrg arcs[2].x = x + w - ew2 - 1; 1456c321187Smrg arcs[2].y = y + h - eh2 - 1; 1466c321187Smrg arcs[2].width = ew2; 1476c321187Smrg arcs[2].height = eh2; 1486c321187Smrg arcs[2].angle1 = 0; 1496c321187Smrg arcs[2].angle2 = -90 * 64; 1506c321187Smrg 1516c321187Smrg arcs[3].x = x; 1526c321187Smrg arcs[3].y = y + h - eh2 - 1; 1536c321187Smrg arcs[3].width = ew2; 1546c321187Smrg arcs[3].height = eh2; 1556c321187Smrg arcs[3].angle1 = 270 * 64; 1566c321187Smrg arcs[3].angle2 = -90 * 64; 1576c321187Smrg 1586c321187Smrg XFillArcs(dpy, draw, gc, arcs, 4); 1596c321187Smrg 1606c321187Smrg rects[0].x = x + ew; 1616c321187Smrg rects[0].y = y; 1626c321187Smrg rects[0].width = w - ew2; 1636c321187Smrg rects[0].height = h; 1646c321187Smrg 1656c321187Smrg rects[1].x = x; 1666c321187Smrg rects[1].y = y + eh; 1676c321187Smrg rects[1].width = ew; 1686c321187Smrg rects[1].height = h - eh2; 1696c321187Smrg 1706c321187Smrg rects[2].x = x + w - ew; 1716c321187Smrg rects[2].y = y + eh; 1726c321187Smrg rects[2].width = ew; 1736c321187Smrg rects[2].height = h - eh2; 1746c321187Smrg 1756c321187Smrg XFillRectangles(dpy, draw, gc, rects, 3); 1766c321187Smrg 1776c321187Smrg if (vals.arc_mode != ArcPieSlice) 1786c321187Smrg XSetArcMode(dpy, gc, vals.arc_mode); 1796c321187Smrg} 180