DrRndRect.c

Go to the documentation of this file.
00001 /* $Xorg: DrRndRect.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */
00002 
00003 /*
00004 
00005 Copyright 1988, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/DrRndRect.c,v 1.6 2001/01/17 19:42:54 dawes Exp $ */
00029 
00030 /*
00031  * XmuDrawRoundedRectangle, XmuFillRoundedRectangle
00032  *
00033  * Draw/Fill a rounded rectangle, where x, y, w, h are the dimensions of
00034  * the overall rectangle, and ew and eh are the sizes of a bounding box
00035  * that the corners are drawn inside of.
00036  */
00037 
00038 #include <X11/Xlib.h>
00039 #include <X11/Xmu/Drawing.h>
00040 
00041 void
00042 XmuDrawRoundedRectangle(Display *dpy, Drawable draw, GC gc,
00043                         int x, int y, int w, int h, int ew, int eh)
00044 {
00045         XArc    arcs[8];
00046   int ew2, eh2;
00047 
00048   if ((ew2 = (ew << 1)) > w)
00049     ew2 = ew = 0;
00050   if ((eh2 = (eh << 1)) > h)
00051     eh2 = eh = 0;
00052 
00053         arcs[0].x = x;
00054         arcs[0].y = y;
00055   arcs[0].width = ew2;
00056   arcs[0].height = eh2;
00057   arcs[0].angle1 = 180 * 64;
00058   arcs[0].angle2 = -90 * 64;
00059 
00060         arcs[1].x = x + ew;
00061         arcs[1].y = y;
00062   arcs[1].width = w - ew2;
00063         arcs[1].height = 0;
00064   arcs[1].angle1 = 180 * 64;
00065   arcs[1].angle2 = -180 * 64;
00066 
00067   arcs[2].x = x + w - ew2;
00068         arcs[2].y = y;
00069   arcs[2].width = ew2;
00070   arcs[2].height = eh2;
00071   arcs[2].angle1 = 90 * 64;
00072   arcs[2].angle2 = -90 * 64;
00073 
00074         arcs[3].x = x + w;
00075         arcs[3].y = y + eh;
00076         arcs[3].width = 0;
00077   arcs[3].height = h - eh2;
00078         arcs[3].angle1 = 90 * 64;
00079   arcs[3].angle2 = -180 * 64;
00080 
00081   arcs[4].x = x + w - ew2;
00082   arcs[4].y = y + h - eh2;
00083   arcs[4].width = ew2;
00084   arcs[4].height = eh2;
00085         arcs[4].angle1 = 0;
00086   arcs[4].angle2 = -90 * 64;
00087 
00088         arcs[5].x = x + ew;
00089         arcs[5].y = y + h;
00090   arcs[5].width = w - ew2;
00091         arcs[5].height = 0;
00092         arcs[5].angle1 = 0;
00093   arcs[5].angle2 = -180 * 64;
00094 
00095         arcs[6].x = x;
00096   arcs[6].y = y + h - eh2;
00097   arcs[6].width = ew2;
00098   arcs[6].height = eh2;
00099   arcs[6].angle1 = 270 * 64;
00100   arcs[6].angle2 = -90 * 64;
00101 
00102         arcs[7].x = x;
00103         arcs[7].y = y + eh;
00104         arcs[7].width = 0;
00105   arcs[7].height = h - eh2;
00106   arcs[7].angle1 = 270 * 64;
00107   arcs[7].angle2 = -180 * 64;
00108 
00109   XDrawArcs(dpy, draw, gc, arcs, 8);
00110 }
00111 
00112 void
00113 XmuFillRoundedRectangle(Display *dpy, Drawable draw, GC gc,
00114                         int x, int y, int w, int h, int ew, int eh)
00115 {
00116         XArc    arcs[4];
00117         XRectangle rects[3];
00118         XGCValues vals;
00119   int ew2, eh2;
00120 
00121         XGetGCValues(dpy, gc, GCArcMode, &vals);
00122         if (vals.arc_mode != ArcPieSlice)
00123             XSetArcMode(dpy, gc, ArcPieSlice);
00124 
00125   if ((ew2 = (ew << 1)) > w)
00126     ew2 = ew = 0;
00127   if ((eh2 = (eh << 1)) > h)
00128     eh2 = eh = 0;
00129 
00130         arcs[0].x = x;
00131         arcs[0].y = y;
00132   arcs[0].width = ew2;
00133   arcs[0].height = eh2;
00134   arcs[0].angle1 = 180 * 64;
00135   arcs[0].angle2 = -90 * 64;
00136 
00137   arcs[1].x = x + w - ew2 - 1;
00138         arcs[1].y = y;
00139   arcs[1].width = ew2;
00140   arcs[1].height = eh2;
00141   arcs[1].angle1 = 90 * 64;
00142   arcs[1].angle2 = -90 * 64;
00143 
00144   arcs[2].x = x + w - ew2 - 1;
00145   arcs[2].y = y + h - eh2 - 1;
00146   arcs[2].width = ew2;
00147   arcs[2].height = eh2;
00148         arcs[2].angle1 = 0;
00149   arcs[2].angle2 = -90 * 64;
00150 
00151         arcs[3].x = x;
00152   arcs[3].y = y + h - eh2 - 1;
00153   arcs[3].width = ew2;
00154   arcs[3].height = eh2;
00155   arcs[3].angle1 = 270 * 64;
00156   arcs[3].angle2 = -90 * 64;
00157 
00158   XFillArcs(dpy, draw, gc, arcs, 4);
00159 
00160         rects[0].x = x + ew;
00161         rects[0].y = y;
00162   rects[0].width = w - ew2;
00163         rects[0].height = h;
00164 
00165         rects[1].x = x;
00166         rects[1].y = y + eh;
00167         rects[1].width = ew;
00168   rects[1].height = h - eh2;
00169 
00170         rects[2].x = x + w - ew;
00171         rects[2].y = y + eh;
00172         rects[2].width = ew;
00173   rects[2].height = h - eh2;
00174 
00175   XFillRectangles(dpy, draw, gc, rects, 3);
00176 
00177         if (vals.arc_mode != ArcPieSlice)
00178             XSetArcMode(dpy, gc, vals.arc_mode);
00179 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1