home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / x11p-13.zip / do_rects.c < prev    next >
C/C++ Source or Header  |  1991-04-29  |  3KB  |  128 lines

  1. /*****************************************************************************
  2. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  3.  
  4.                         All Rights Reserved
  5.  
  6. Permission to use, copy, modify, and distribute this software and its 
  7. documentation for any purpose and without fee is hereby granted, 
  8. provided that the above copyright notice appear in all copies and that
  9. both that copyright notice and this permission notice appear in 
  10. supporting documentation, and that the name of Digital not be
  11. used in advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.  
  13.  
  14. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20. SOFTWARE.
  21.  
  22. ******************************************************************************/
  23.  
  24. #include "x11perf.h"
  25. #include "bitmaps.h"
  26.  
  27. static XRectangle   *rects;
  28. static GC        pgc;
  29.  
  30. int InitRectangles(xp, p, reps)
  31.     XParms  xp;
  32.     Parms   p;
  33.     int     reps;
  34. {
  35.     int i;
  36.     int size = p->special;
  37.     int step;
  38.     int x, y;
  39.     int rows;
  40.     int    half;
  41.     int    lw = 0;
  42.  
  43.     pgc = xp->fggc;
  44.  
  45.     if (p->bfont)
  46.     {
  47.     lw = atoi (p->bfont);
  48.  
  49.     XSetLineAttributes(xp->d, xp->bggc, lw, LineSolid, CapButt, JoinMiter);
  50.     XSetLineAttributes(xp->d, xp->fggc, lw, LineSolid, CapButt, JoinMiter);
  51.     lw = (lw >> 1) + 1;
  52.     }
  53.  
  54.     rects = (XRectangle *)malloc(p->objects * sizeof(XRectangle));
  55.     x = lw;
  56.     y = lw;
  57.     rows = 0;
  58.     if (xp->pack) {
  59.     /* Pack rectangles as close as possible, mainly for debugging faster
  60.        tiling, stippling routines in a server */
  61.     step = size;
  62.     } else {
  63.     /* Try to exercise all alignments...any odd number is okay */
  64.     step = size + 1 + (size % 2);
  65.     }
  66.  
  67.     for (i = 0; i != p->objects; i++) {
  68.     rects[i].x = x;
  69.         rects[i].y = y;
  70.     rects[i].width = rects[i].height = size;
  71.  
  72.     y += step;
  73.     rows++;
  74.     if (y + size > HEIGHT || rows == MAXROWS) {
  75.         rows = 0;
  76.         y = lw;
  77.         x += step;
  78.         if (x + size > WIDTH) {
  79.         x = lw;
  80.         }
  81.     }
  82.     }
  83.  
  84.     SetFillStyle(xp, p);
  85.  
  86.     return reps;
  87. }
  88.  
  89. void DoRectangles(xp, p, reps)
  90.     XParms  xp;
  91.     Parms   p;
  92.     int     reps;
  93. {
  94.     int i;
  95.  
  96.     for (i = 0; i != reps; i++) {
  97.         XFillRectangles(xp->d, xp->w, pgc, rects, p->objects);
  98.         if (pgc == xp->bggc)
  99.             pgc = xp->fggc;
  100.         else
  101.             pgc = xp->bggc;
  102.     }
  103. }
  104.  
  105. void DoOutlineRectangles (xp, p, reps)
  106.     XParms  xp;
  107.     Parms   p;
  108.     int        reps;
  109. {
  110.     int    i;
  111.  
  112.     for (i = 0; i != reps; i++) {
  113.     XDrawRectangles (xp->d, xp->w, pgc, rects, p->objects);
  114.         if (pgc == xp->bggc)
  115.             pgc = xp->fggc;
  116.         else
  117.             pgc = xp->bggc;
  118.     }
  119. }
  120.  
  121. void EndRectangles(xp, p)
  122.     XParms  xp;
  123.     Parms p;
  124. {
  125.     free(rects);
  126. }
  127.  
  128.