home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelPolyPt.c < prev    next >
C/C++ Source or Header  |  1992-03-24  |  6KB  |  226 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  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 IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM 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. /* $Header: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/mpel/RCS/mpelPolyPt.c,v 5.1 1992/03/24 07:51:20 jfc Exp $ */
  24. /* $Source: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/mpel/RCS/mpelPolyPt.c,v $ */
  25.  
  26. #ifndef lint
  27. static char *rcsid = "$Id: mpelPolyPt.c,v 5.1 1992/03/24 07:51:20 jfc Exp $";
  28. #endif
  29.  
  30. #include "X.h"
  31. #include "misc.h"
  32. #include "gcstruct.h"
  33. #include "windowstr.h"
  34. #include "pixmapstr.h"
  35. #include "colormapst.h"
  36. #include "scrnintstr.h"
  37. #include "regionstr.h"
  38. #include "region.h"
  39.  
  40. #include "OScompiler.h"
  41.  
  42. #include "ppc.h"
  43.  
  44. #include "mpel.h"
  45. #include "mpelHdwr.h"
  46. #include "mpelFifo.h"
  47.  
  48. #include "ibmTrace.h"
  49.  
  50. /* Cursor Stuff */
  51. extern int mpelcursorSemaphore;
  52. extern int mpelCheckCursor();
  53. extern void mpelReplaceCursor();
  54.  
  55. /* The maximum number of points in a Polymarker request (a polyline
  56.    request can include half as many points).
  57.    This number is (32760 / sizeof(mpelPoint)).  */
  58. #define MAXRQPTS    8190
  59. /* Maxmimum number of points when using disjoint polyline. */
  60. #define    MAXRQPTS_L    3270
  61. /* emulate poly point using disjoint polyline requests; this is
  62.    sometimes necessary because the ALU is ignored for polymarker. */
  63.  
  64. static void emul_PolyPoint(npt, ppt)
  65. int npt;
  66. xPoint *ppt;
  67. {
  68.   register int i;
  69.   register short *data = (short *)ALLOCATE_LOCAL(npt * 10 + 4);
  70.  
  71.   if (data == 0)
  72.     return;
  73.  
  74.   data[0] = npt * 10 + 4;
  75.   data[1] = 0x501d;
  76.   for (i = 0; i < npt; i++)
  77.     {
  78.       data[i * 5 + 2] = 10;
  79.       data[i * 5 + 5] = data[i * 5 + 3] = ppt->x;
  80.       data[i * 5 + 6] = data[i * 5 + 4] = ppt->y;
  81.       ppt++;
  82.     }
  83.   mfData(data, npt * 10 + 4);
  84.  
  85.   DEALLOCATE_LOCAL(data);
  86. }
  87.  
  88. void
  89. mpelPolyPoint(pDrawable, pGC, mode, npt, pptInit)
  90. DrawablePtr    pDrawable;
  91. GCPtr        pGC;
  92. int        mode;                /* Origin or Previous */
  93. int        npt;
  94. xPoint        *pptInit;
  95. {
  96.     register xPoint *ppt;
  97.     ppcPrivGC *devPriv = (ppcPrivGC *) ( pGC->devPrivates[mfbGCPrivateIndex].ptr);
  98.     register RegionPtr pRegion = devPriv->pCompositeClip;
  99.     int    cursor_saved;
  100.     int color, alu;
  101.  
  102.     TRACE( ("mpelPolyPoint(0x%x,0x%x,\"%s\",%d,0x%x)\n",
  103.         pDrawable, pGC, (mode == CoordModePrevious) ?
  104.         "Relative" : "Absolute", npt, pptInit));
  105.  
  106.     if ( pGC->alu == GXnoop || REGION_NIL(pRegion) || npt == 0)
  107.         return;
  108.  
  109.     if ( pDrawable->type == DRAWABLE_PIXMAP ) {
  110.         ppcPolyPoint( pDrawable, pGC, mode, npt, pptInit );
  111.         return;
  112.     }
  113.  
  114.     /* make pointlist origin relative
  115.      * AND adjust for the window org
  116.      * AND adjust for the Mpel's Backward Y coordinates
  117.      */
  118.     {
  119.     register const int xorg = pDrawable->x;
  120.     register const int yorg = pDrawable->y;
  121.     register int nptTmp = npt;
  122.     register xPoint *mpt = pptInit;
  123.     register int (* PointInRegion)() = pDrawable->pScreen->PointInRegion;
  124.     BoxRec box;
  125.  
  126.     if ( mode == CoordModePrevious ) {
  127.         ppt = pptInit;
  128.         ppt->x += xorg;
  129.         ppt->y += yorg;
  130.         if((* PointInRegion)( pRegion, ppt->x, ppt->y, &box)) {
  131.             mpt->x = ppt->x;
  132.             mpt->y = (MPEL_HEIGHT - 1) - ppt->y;
  133.             mpt++;
  134.         }
  135.         while (--nptTmp) {
  136.             ppt++;
  137.             ppt->x += xorg + (ppt-1)->x;
  138.             ppt->y = yorg + ppt->y + (ppt-1)->y;
  139.             if((* PointInRegion)( pRegion, ppt->x, ppt->y, &box)) {
  140.                 mpt->x = ppt->x;
  141.                 mpt->y = (MPEL_HEIGHT - 1) - ppt->y;
  142.                 mpt++;
  143.             }
  144.         }
  145.         npt = mpt - pptInit;
  146.     } else {
  147.         for ( ppt = pptInit; nptTmp--; ppt++) {
  148.             ppt->x += xorg;
  149.             ppt->y += yorg;
  150.             if((* PointInRegion)( pRegion, ppt->x, ppt->y, &box)) {
  151.                 mpt->x = ppt->x;
  152.                 mpt->y = (MPEL_HEIGHT - 1) - ppt->y;
  153.                 mpt++;
  154.             }
  155.         }
  156.         npt = mpt - pptInit;
  157.     }
  158.     }
  159.     TRACE(("mpelPolyPoint: %d points\n", npt));
  160.     if(!npt)    /* Nothing to do */
  161.         return;
  162.     /* If Cursor Is In The Way Remove It */
  163.     cursor_saved = !mpelcursorSemaphore
  164.         && mpelCheckCursor(
  165.             pRegion->extents.x1,
  166.             pRegion->extents.y1,
  167.             pRegion->extents.x2 - pRegion->extents.x1,
  168.             pRegion->extents.y2 - pRegion->extents.y1
  169.         );
  170.  
  171.     /* do the actual drawing */
  172.     /* Check if the optimized rRop is valid */
  173.     if ( devPriv->colorRrop.fillStyle == FillStippled
  174.       || devPriv->colorRrop.fillStyle == FillSolid) {
  175.         color = devPriv->colorRrop.fgPixel;
  176.         alu = devPriv->colorRrop.alu;
  177.         mpelSetPlaneMask(devPriv->colorRrop.planemask);
  178.     }
  179.     else {
  180.         alu = pGC->alu;
  181.         color = pGC->fgPixel;
  182.         mpelSetPlaneMask(pGC->planemask);
  183.     }
  184.     switch (alu)
  185.       {
  186.       case GXclear:
  187.         color = 0;
  188.         alu = GXcopy;
  189.         break;
  190.       case GXcopyInverted:
  191.         color = ~color;
  192.       alu = GXcopy;
  193.         break;
  194.       case GXset:
  195.         color = ~0;
  196.         alu = GXcopy;
  197.         break;
  198.       }
  199.     if (alu == GXcopy)
  200.       {
  201.         MPELSetPolymarkerColor(color);
  202.         MPELSetMarkerType(1); /* Magic number for solid dots */
  203.         /* Break into bite-sized pieces */
  204.         {
  205.           register int rem;
  206.           /* MPELPolymarker does not evaluate any of its arguments
  207.          more than once. */
  208.           for(rem = npt; rem > 0; rem -= MAXRQPTS, pptInit+=MAXRQPTS)
  209.         MPELPolymarker((rem>MAXRQPTS)?MAXRQPTS:rem, pptInit);
  210.         }
  211.       }
  212.     else
  213.       {
  214.         mpelSetALU(alu);
  215.         MPELSetPolylineColor(color);
  216.         register int rem;
  217.         for(rem = npt; rem > 0; rem -= MAXRQPTS_L, pptInit += MAXRQPTS_L)
  218.           emul_PolyPoint((rem>MAXRQPTS_L)?MAXRQPTS_L:rem, pptInit);
  219.       }
  220.  
  221.     if (cursor_saved)
  222.         mpelReplaceCursor();
  223.  
  224.     return;
  225. }
  226.