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