Blame lib/Xm/DrawUtils.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
*/
Packit b099d7
Packit b099d7
#include <X11/Intrinsic.h>
Packit b099d7
#include <Xm/DrawUtils.h>
Packit b099d7
Packit b099d7
#define STATIC_RECTS 20
Packit b099d7
/*
Packit b099d7
 * Function:
Packit b099d7
 *	XmDrawBevel(dpy, d, top_GC, bottom_GC, x, y, size, option)
Packit b099d7
 * Description:
Packit b099d7
 *	Draws a shadow corner (beveled) at the given location and size.
Packit b099d7
 * Input:
Packit b099d7
 *	dpy       : Display*     - the display to draw to
Packit b099d7
 *	d         : Drawable     - the drawable to use
Packit b099d7
 *	top_GC    : GC           - the GC to use to draw the top half of
Packit b099d7
 *                                 the bevel
Packit b099d7
 *	bottom_GC : GC           - the GC to use to draw the bottom half
Packit b099d7
 *                                 of the bevel
Packit b099d7
 *	x         : int          - the x location of the corner
Packit b099d7
 *	y         : int          - the y location of the corner
Packit b099d7
 *	size      : unsigned int - the size of the corner
Packit b099d7
 *                                 (width = height = size)
Packit b099d7
 *	option    : XmBevelOption- what part of the bevel should we draw.
Packit b099d7
 * Output:
Packit b099d7
 *	None.
Packit b099d7
 */
Packit b099d7
void
Packit b099d7
#ifndef _NO_PROTO
Packit b099d7
XmDrawBevel(Display *dpy, Drawable d, GC top_gc, GC bottom_gc,
Packit b099d7
	    int x, int y, unsigned int size, XmBevelOption option)
Packit b099d7
#else
Packit b099d7
XmDrawBevel(dpy, d, top_gc, bottom_gc, x, y, size, option)
Packit b099d7
    Display       *dpy;
Packit b099d7
    Drawable      d;
Packit b099d7
    GC            top_gc, bottom_gc;
Packit b099d7
    int           x, y;
Packit b099d7
    unsigned int  size;
Packit b099d7
    XmBevelOption option;
Packit b099d7
#endif
Packit b099d7
{
Packit b099d7
    static     XRectangle saved[STATIC_RECTS], *alloced = NULL;
Packit b099d7
    static int numAlloced = 0;
Packit b099d7
    XRectangle *rt;
Packit b099d7
    int        i;
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * First lets see if we can get away with using our list rectangles
Packit b099d7
     * without allocating any.
Packit b099d7
     */
Packit b099d7
    if( size < STATIC_RECTS )
Packit b099d7
    {
Packit b099d7
	/*
Packit b099d7
	 * OK we don't need to allocate any so lets use the static
Packit b099d7
	 * array.
Packit b099d7
	 */
Packit b099d7
	rt = saved;
Packit b099d7
    }
Packit b099d7
    else
Packit b099d7
    {
Packit b099d7
	/*
Packit b099d7
	 * Well we need more than our static array holds so lets see
Packit b099d7
	 * if we have enough in our alloced array and if no lets
Packit b099d7
	 * allocate what we need.
Packit b099d7
	 */
Packit b099d7
	if( size > numAlloced )
Packit b099d7
	{
Packit b099d7
	    numAlloced = size;
Packit b099d7
	    alloced = (XRectangle*) XtRealloc((XtPointer) alloced,
Packit b099d7
					      sizeof(XRectangle) * numAlloced);
Packit b099d7
	}
Packit b099d7
	rt = alloced;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Now that we have enough rectangles to fill in an area lets
Packit b099d7
     * set up the rectangles and pass them off to be drawn.  First the
Packit b099d7
     * top half of the beveled corner ...
Packit b099d7
     */
Packit b099d7
    if( option == XmBEVEL_TOP )
Packit b099d7
    {
Packit b099d7
	for( i = 0; i < size; ++i )
Packit b099d7
	{
Packit b099d7
	    rt[i].x = x;
Packit b099d7
	    rt[i].y = y + i;
Packit b099d7
	    rt[i].width = size - i;
Packit b099d7
	    rt[i].height = 1;
Packit b099d7
	}
Packit b099d7
	XFillRectangles(dpy, d, top_gc, rt, size);
Packit b099d7
    }
Packit b099d7
    else if( option == XmBEVEL_BOTH )
Packit b099d7
    {
Packit b099d7
	XFillRectangle(dpy, d, top_gc, x, y, size, size);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * ... And the the bottom half of the beveled corner.
Packit b099d7
     */
Packit b099d7
    if( option == XmBEVEL_BOTH || option == XmBEVEL_BOTTOM )
Packit b099d7
    {
Packit b099d7
	for( i = 0; i < size; ++i )
Packit b099d7
	{
Packit b099d7
	    rt[i].x = x + size - i;
Packit b099d7
	    rt[i].y = y + i;
Packit b099d7
	    rt[i].width = i;
Packit b099d7
	    rt[i].height = 1;
Packit b099d7
	}
Packit b099d7
	XFillRectangles(dpy, d, bottom_gc, rt, size);
Packit b099d7
    }
Packit b099d7
}
Packit b099d7