1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5 *
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <X11/Intrinsic.h>
25 #include <Xm/DrawUtils.h>
26
27 #define STATIC_RECTS 20
28 /*
29 * Function:
30 * XmDrawBevel(dpy, d, top_GC, bottom_GC, x, y, size, option)
31 * Description:
32 * Draws a shadow corner (beveled) at the given location and size.
33 * Input:
34 * dpy : Display* - the display to draw to
35 * d : Drawable - the drawable to use
36 * top_GC : GC - the GC to use to draw the top half of
37 * the bevel
38 * bottom_GC : GC - the GC to use to draw the bottom half
39 * of the bevel
40 * x : int - the x location of the corner
41 * y : int - the y location of the corner
42 * size : unsigned int - the size of the corner
43 * (width = height = size)
44 * option : XmBevelOption- what part of the bevel should we draw.
45 * Output:
46 * None.
47 */
48 void
49 #ifndef _NO_PROTO
XmDrawBevel(Display * dpy,Drawable d,GC top_gc,GC bottom_gc,int x,int y,unsigned int size,XmBevelOption option)50 XmDrawBevel(Display *dpy, Drawable d, GC top_gc, GC bottom_gc,
51 int x, int y, unsigned int size, XmBevelOption option)
52 #else
53 XmDrawBevel(dpy, d, top_gc, bottom_gc, x, y, size, option)
54 Display *dpy;
55 Drawable d;
56 GC top_gc, bottom_gc;
57 int x, y;
58 unsigned int size;
59 XmBevelOption option;
60 #endif
61 {
62 static XRectangle saved[STATIC_RECTS], *alloced = NULL;
63 static int numAlloced = 0;
64 XRectangle *rt;
65 int i;
66
67 /*
68 * First lets see if we can get away with using our list rectangles
69 * without allocating any.
70 */
71 if( size < STATIC_RECTS )
72 {
73 /*
74 * OK we don't need to allocate any so lets use the static
75 * array.
76 */
77 rt = saved;
78 }
79 else
80 {
81 /*
82 * Well we need more than our static array holds so lets see
83 * if we have enough in our alloced array and if no lets
84 * allocate what we need.
85 */
86 if( size > numAlloced )
87 {
88 numAlloced = size;
89 alloced = (XRectangle*) XtRealloc((XtPointer) alloced,
90 sizeof(XRectangle) * numAlloced);
91 }
92 rt = alloced;
93 }
94
95 /*
96 * Now that we have enough rectangles to fill in an area lets
97 * set up the rectangles and pass them off to be drawn. First the
98 * top half of the beveled corner ...
99 */
100 if( option == XmBEVEL_TOP )
101 {
102 for( i = 0; i < size; ++i )
103 {
104 rt[i].x = x;
105 rt[i].y = y + i;
106 rt[i].width = size - i;
107 rt[i].height = 1;
108 }
109 XFillRectangles(dpy, d, top_gc, rt, size);
110 }
111 else if( option == XmBEVEL_BOTH )
112 {
113 XFillRectangle(dpy, d, top_gc, x, y, size, size);
114 }
115
116 /*
117 * ... And the the bottom half of the beveled corner.
118 */
119 if( option == XmBEVEL_BOTH || option == XmBEVEL_BOTTOM )
120 {
121 for( i = 0; i < size; ++i )
122 {
123 rt[i].x = x + size - i;
124 rt[i].y = y + i;
125 rt[i].width = i;
126 rt[i].height = 1;
127 }
128 XFillRectangles(dpy, d, bottom_gc, rt, size);
129 }
130 }
131
132