drawing.c revision 8db30ca8
18db30ca8Sthorpej/* xscreensaver, Copyright (c) 1991-1998 Jamie Zawinski <jwz@netscape.com>
28db30ca8Sthorpej *
38db30ca8Sthorpej * Permission to use, copy, modify, distribute, and sell this software and its
48db30ca8Sthorpej * documentation for any purpose is hereby granted without fee, provided that
58db30ca8Sthorpej * the above copyright notice appear in all copies and that both that
68db30ca8Sthorpej * copyright notice and this permission notice appear in supporting
78db30ca8Sthorpej * documentation.  No representations are made about the suitability of this
88db30ca8Sthorpej * software for any purpose.  It is provided "as is" without express or
98db30ca8Sthorpej * implied warranty.
108db30ca8Sthorpej */
118db30ca8Sthorpej
128db30ca8Sthorpej/* 1999-Nov-21 Modified by Jim Knoble <jmknoble@pobox.com>
138db30ca8Sthorpej * Modifications:
148db30ca8Sthorpej *   - Extracted draw_shaded_rectangle() from xscreensaver source for use
158db30ca8Sthorpej *     in a separate application.  Constructed separate header file.
168db30ca8Sthorpej */
178db30ca8Sthorpej
188db30ca8Sthorpej#include <X11/Intrinsic.h>
198db30ca8Sthorpej
208db30ca8Sthorpejvoid
218db30ca8Sthorpejdraw_shaded_rectangle (Display *dpy, Window window,
228db30ca8Sthorpej		       int x, int y,
238db30ca8Sthorpej		       int width, int height,
248db30ca8Sthorpej		       int thickness,
258db30ca8Sthorpej		       unsigned long top_color,
268db30ca8Sthorpej		       unsigned long bottom_color)
278db30ca8Sthorpej{
288db30ca8Sthorpej  XPoint points[4];
298db30ca8Sthorpej  XGCValues gcv;
308db30ca8Sthorpej  GC gc1, gc2;
318db30ca8Sthorpej  if (thickness == 0) return;
328db30ca8Sthorpej
338db30ca8Sthorpej  gcv.foreground = top_color;
348db30ca8Sthorpej  gc1 = XCreateGC (dpy, window, GCForeground, &gcv);
358db30ca8Sthorpej  gcv.foreground = bottom_color;
368db30ca8Sthorpej  gc2 = XCreateGC (dpy, window, GCForeground, &gcv);
378db30ca8Sthorpej
388db30ca8Sthorpej  points [0].x = x;
398db30ca8Sthorpej  points [0].y = y;
408db30ca8Sthorpej  points [1].x = x + width;
418db30ca8Sthorpej  points [1].y = y;
428db30ca8Sthorpej  points [2].x = x + width - thickness;
438db30ca8Sthorpej  points [2].y = y + thickness;
448db30ca8Sthorpej  points [3].x = x;
458db30ca8Sthorpej  points [3].y = y + thickness;
468db30ca8Sthorpej  XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
478db30ca8Sthorpej
488db30ca8Sthorpej  points [0].x = x;
498db30ca8Sthorpej  points [0].y = y + thickness;
508db30ca8Sthorpej  points [1].x = x;
518db30ca8Sthorpej  points [1].y = y + height;
528db30ca8Sthorpej  points [2].x = x + thickness;
538db30ca8Sthorpej  points [2].y = y + height - thickness;
548db30ca8Sthorpej  points [3].x = x + thickness;
558db30ca8Sthorpej  points [3].y = y + thickness;
568db30ca8Sthorpej  XFillPolygon (dpy, window, gc1, points, 4, Convex, CoordModeOrigin);
578db30ca8Sthorpej
588db30ca8Sthorpej  points [0].x = x + width;
598db30ca8Sthorpej  points [0].y = y;
608db30ca8Sthorpej  points [1].x = x + width - thickness;
618db30ca8Sthorpej  points [1].y = y + thickness;
628db30ca8Sthorpej  points [2].x = x + width - thickness;
638db30ca8Sthorpej  points [2].y = y + height - thickness;
648db30ca8Sthorpej  points [3].x = x + width;
658db30ca8Sthorpej  points [3].y = y + height - thickness;
668db30ca8Sthorpej  XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
678db30ca8Sthorpej
688db30ca8Sthorpej  points [0].x = x;
698db30ca8Sthorpej  points [0].y = y + height;
708db30ca8Sthorpej  points [1].x = x + width;
718db30ca8Sthorpej  points [1].y = y + height;
728db30ca8Sthorpej  points [2].x = x + width;
738db30ca8Sthorpej  points [2].y = y + height - thickness;
748db30ca8Sthorpej  points [3].x = x + thickness;
758db30ca8Sthorpej  points [3].y = y + height - thickness;
768db30ca8Sthorpej  XFillPolygon (dpy, window, gc2, points, 4, Convex, CoordModeOrigin);
778db30ca8Sthorpej
788db30ca8Sthorpej  XFreeGC (dpy, gc1);
798db30ca8Sthorpej  XFreeGC (dpy, gc2);
808db30ca8Sthorpej}
818db30ca8Sthorpej
82