home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / qdss / qdfill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-19  |  8.1 KB  |  265 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26.  
  27. #include "misc.h"
  28. #include "windowstr.h"
  29. #include "gcstruct.h"
  30. #include "qd.h"
  31. #include "qdgc.h"
  32. #include "qdprocs.h"
  33. #include "pixmapstr.h"
  34.  
  35. /* Mixing of levels! Needed for ScreenHeight */
  36. #include "libtl/tl.h"
  37.  
  38. /*
  39.  * make this FillSpans instead?        XX
  40.  */
  41. void
  42. qdPolyFillBoxesOddSize(pWin, pGC, nrect, pdestboxes)
  43.     WindowPtr    pWin;
  44.     GCPtr    pGC;
  45.     int        nrect;           /* number of rectangles to fill */
  46.     BoxPtr    pdestboxes;
  47. {
  48.     int        nr, ok;
  49.     register BoxPtr pbox;
  50.     RegionPtr    pSaveGCclip = QDGC_COMPOSITE_CLIP(pGC);
  51.     RegionPtr    pcompregion;        /* built from pboxes argument */
  52.     int rx, ry;  /* origin in window coordinates */
  53.     int width, height;
  54.     int ix, iy;    /* steps through the box; in window coordinate */
  55.     PixmapPtr    pTile =
  56.     pGC->fillStyle == FillTiled ? pGC->tile.pixmap : pGC->stipple;
  57.     int xStart;
  58.  
  59.     pcompregion = qdRegionInit( pdestboxes, nrect);
  60.     miTranslateRegion( pcompregion, pGC->lastWinOrg.x, pGC->lastWinOrg.y);
  61.     miIntersect( pcompregion, pcompregion, QDGC_COMPOSITE_CLIP(pGC));
  62.     QDGC_COMPOSITE_CLIP(pGC) = pcompregion;
  63.  
  64.     rx = pcompregion->extents.x1 - pGC->lastWinOrg.x;
  65.     ry = pcompregion->extents.y1 - pGC->lastWinOrg.y;
  66.     width = pcompregion->extents.x2 - pcompregion->extents.x1;
  67.     height = pcompregion->extents.y2 - pcompregion->extents.y1;
  68.     xStart = rx - UMOD( rx-pGC->patOrg.x, QDPIX_WIDTH(pTile));
  69.     iy = ry - UMOD( ry-pGC->patOrg.y, QDPIX_HEIGHT(pTile));
  70.     /*
  71.      * for each row of tiles, bump iy
  72.      * subtract enough off of initial iy to align tile
  73.      *
  74.      * for each column of tiles, bump ix
  75.      * subtract enough off of initial ix to align tile
  76.      */
  77.  
  78.     switch ( pGC->fillStyle) {
  79.       case FillStippled: {
  80.       long gcval;
  81.       gcval = (long)FillSolid;
  82.       /*  temporarily set fillstyle to FillSolid */
  83.       DoChangeGC(pGC, GCFillStyle, &gcval, 0);
  84.       ValidateGC(pWin, pGC);
  85.       for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  86.           for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  87.           qdPushPixels(pGC, pTile, pWin,
  88.                    QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  89.                    ix, iy);
  90.       gcval = (long)FillStippled;
  91.       DoChangeGC(pGC, GCFillStyle, &gcval, 0);
  92.       ValidateGC(pWin, pGC);
  93.       break;
  94.       }
  95.       case FillOpaqueStippled:
  96.     for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  97.         for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  98.         (*pGC->ops->CopyPlane)(pTile, pWin, pGC, 0, 0,
  99.                   QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  100.                   ix, iy, 1);
  101.     break;
  102.       case FillTiled: {
  103. #if 1
  104. #define TILE_X 0
  105. #define TILE_Y ScreenHeight
  106.       if ( tlConfirmPixmap(pTile)
  107.           && (pWin->drawable.type == DRAWABLE_WINDOW
  108.           || QDPIX_Y((QDPixPtr)pWin) != NOTOFFSCREEN)) {
  109.           int tileX, tileY;
  110.           int tileW = QDPIX_WIDTH(pTile);
  111.           int tileH = QDPIX_HEIGHT(pTile);
  112.           if (tileW < 32 && tileH < 32) {
  113.           tileW = (32 / tileW) * tileW;
  114.           tileH = (32 / tileH) * tileH;
  115.           tileX = TILE_X;
  116.           tileY = TILE_Y;
  117.           /* Makes gross assumptions about what tlrotile does! */
  118.           tlrotile(pTile, pGC->patOrg, NULL);
  119.           } else {
  120.           tileX = QDPIX_X((QDPixPtr)pTile);
  121.           tileY = QDPIX_Y((QDPixPtr)pTile);
  122.           }
  123.           for ( ; iy < ry + height; iy += tileH)
  124.           for (ix = xStart; ix < rx + width; ix += tileW)
  125.               tlbitblt(pGC,
  126.                    pGC->lastWinOrg.x + ix, pGC->lastWinOrg.y + iy,
  127.                    tileW, tileH, tileX, tileY);
  128.           }
  129.       else
  130. #endif
  131.           for ( ; iy < ry + height; iy += QDPIX_HEIGHT(pTile))
  132.           for (ix = xStart; ix < rx + width; ix += QDPIX_WIDTH(pTile))
  133.               (*pGC->ops->CopyArea)(pTile, pWin, pGC, 0, 0,
  134.                        QDPIX_WIDTH(pTile), QDPIX_HEIGHT(pTile),
  135.                        ix, iy);
  136.       break;
  137.       }
  138.       case FillSolid:
  139.     FatalError( "Should have called tldrawshapes code!\n");
  140.     break;
  141.     }
  142.     miRegionDestroy( pcompregion);
  143.     QDGC_COMPOSITE_CLIP(pGC) = pSaveGCclip;
  144. }
  145.  
  146. void
  147. qdPolyFillRectOddSize( pDrawable, pGC, nrect, prect)
  148.     DrawablePtr    pDrawable;
  149.     GCPtr    pGC;
  150.     int        nrect;           /* number of rectangles to fill */
  151.     xRectangle * prect;          /* Pointer to first rectangle to fill */
  152. {
  153.     BoxPtr    pdestboxes;
  154.     register BoxPtr    pdb;
  155.     int        nr;
  156.  
  157.     if ( nrect == 0) return;
  158.  
  159.     pdb = pdestboxes = (BoxPtr) ALLOCATE_LOCAL( nrect*sizeof(BoxRec));
  160.     /*
  161.     * turn the rectangles into Boxes
  162.     */
  163.     for (nr = nrect; --nr >= 0; pdb++, prect++)
  164.     {
  165.     pdb->x1 = prect->x;
  166.     pdb->x2 = prect->x + (int)prect->width;
  167.     pdb->y1 = prect->y;
  168.     pdb->y2 = prect->y + (int)prect->height;
  169.     }
  170.  
  171.     qdPolyFillBoxesOddSize((WindowPtr)pDrawable, pGC, nrect, pdestboxes);
  172.     DEALLOCATE_LOCAL(pdestboxes);
  173. }
  174.  
  175. void
  176. qdFillPolygon( pDrawable, pGC, shape, mode, npt, pptInit)
  177.     DrawablePtr         pDrawable;
  178.     register GCPtr      pGC;
  179.     int                 shape, mode;
  180.     register int        npt;
  181.     DDXPointPtr         pptInit;
  182. {
  183.     DDXPointPtr         abspts;
  184.     DDXPointPtr         closepts;
  185.     Bool        allocated = FALSE;
  186.  
  187.     if ( pDrawable->type != DRAWABLE_WINDOW || shape != Convex ||
  188.         pGC->fillStyle != FillSolid)
  189.     {
  190.     miFillPolygon( pDrawable, pGC, shape, mode, npt, pptInit);
  191.     return;
  192.     }
  193.  
  194.     if ( npt == 0)        /* make sure abspts[0] is valid */
  195.      return;
  196.     if ( mode == CoordModeOrigin)
  197.     abspts = pptInit;
  198.     else    /* CoordModePrevious */
  199.     {
  200.     register int    ip;
  201.  
  202.     /* It is 'npt=1' in case we need to close the polygon below */
  203.     abspts = (DDXPointPtr) ALLOCATE_LOCAL( (npt+1) * sizeof( DDXPointRec));
  204.         allocated = TRUE;
  205.     abspts[ 0].x = pptInit[ 0].x;
  206.     abspts[ 0].y = pptInit[ 0].y;
  207.     for ( ip=1; ip<npt; ip++)
  208.     {
  209.         abspts[ ip].x = abspts[ ip-1].x + pptInit[ ip].x;
  210.         abspts[ ip].y = abspts[ ip-1].y + pptInit[ ip].y;
  211.     }
  212.  
  213.     }
  214.     /* close the polygon if necessary */
  215.     if (abspts[npt-1].x != abspts[0].x
  216.         || abspts[npt-1].y != abspts[0].y)    /* not closed */
  217.     {
  218.     register int    ip;
  219.  
  220.     if (allocated)
  221.         closepts = abspts;
  222.     else {
  223.         allocated = TRUE;
  224.         closepts =
  225.         (DDXPointPtr) ALLOCATE_LOCAL( (npt+1) * sizeof(DDXPointRec));
  226.         for ( ip = npt; --ip >= 0; ) {
  227.         closepts[ ip].x = abspts[ ip].x;
  228.         closepts[ ip].y = abspts[ ip].y;
  229.         }
  230.     }
  231.     closepts[npt].x = abspts[0].x;
  232.     closepts[npt].y = abspts[0].y;
  233.     npt++;    /* add duplicate point to end */
  234.     }
  235.     else
  236.     closepts = abspts;
  237.     tlconpoly( (WindowPtr)pDrawable, pGC, npt, closepts);
  238.     if (allocated) DEALLOCATE_LOCAL( closepts );
  239. }
  240.  
  241. void
  242. qdPixFillRect(pPix, pGC, nshapes, pshape)
  243.      QDPixPtr pPix;
  244.      GCPtr pGC;
  245.      int nshapes;
  246.      DDXPointPtr pshape;
  247.      
  248. {
  249.     extern int PixmapUseOffscreen;
  250. /* if PixmapUseOffscreen allow debugging of tlSolidSpans */
  251.     if (QD_PIX_DATA(&pPix->pixmap) == NULL) {
  252.     extern void tlSolidRects(), tlTiledRects(),
  253.         tlStipRects(), tlOpStipRects();
  254.     static void (*FillFuncs[4])() = {
  255.         tlSolidRects, tlTiledRects, tlStipRects, tlOpStipRects};
  256.     /* make dummy window and use that as the drawable */
  257.     SETUP_PIXMAP_AS_WINDOW(&pPix->pixmap.drawable, pGC);
  258.     CHECK_MOVED(pGC, &pPix->pixmap.drawable);
  259.     (*FillFuncs[pGC->fillStyle])(pPix, pGC, nshapes, pshape);
  260.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  261.     }
  262.     else
  263.     miPolyFillRect(pPix, pGC, nshapes, pshape);
  264. }
  265.