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 / mpelLine.c < prev    next >
C/C++ Source or Header  |  1989-11-09  |  15KB  |  521 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. /***********************************************************
  24.         Copyright IBM Corporation 1987,1988
  25.  
  26.                       All Rights Reserved
  27.  
  28. Permission to use, copy, modify, and distribute this software and its
  29. documentation for any purpose and without fee is hereby granted, 
  30. provided that the above copyright notice appear in all copies and that
  31. both that copyright notice and this permission notice appear in
  32. supporting documentation, and that the name of IBM not be
  33. used in advertising or publicity pertaining to distribution of the
  34. software without specific, written prior permission.
  35.  
  36. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  37. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  38. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
  40. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 
  41. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  42. SOFTWARE.
  43.  
  44. ******************************************************************/
  45.  
  46. /* $Header: /andrew/X11/r3src/earlyRelease/server/ddx/ibm/mpel/RCS/mpelLine.c,v 6.5 88/11/04 19:37:45 paul Exp $ */
  47. /* $Source: /andrew/X11/r3src/earlyRelease/server/ddx/ibm/mpel/RCS/mpelLine.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Header: /andrew/X11/r3src/earlyRelease/server/ddx/ibm/mpel/RCS/mpelLine.c,v 6.5 88/11/04 19:37:45 paul Exp $" ;
  51. #endif
  52.  
  53. #include "X.h"
  54. #include "misc.h"
  55. #include "gc.h"
  56. #include "gcstruct.h"
  57. #include "regionstr.h"
  58. #include "colormapst.h"
  59. #include "pixmapstr.h"
  60. #include "windowstr.h"
  61.  
  62. #include "OScompiler.h"
  63.  
  64. #include "ppc.h"
  65.  
  66. #include "mpel.h"
  67. #include "mpelHdwr.h"
  68. #include "mpelFifo.h"
  69.  
  70. #include "ibmTrace.h"
  71.  
  72. #define X_AXIS 0
  73.  
  74. /* Cursor Stuff */
  75. extern int mpelcursorSemaphore ;
  76. extern int mpelCheckCursor() ;
  77. extern void mpelReplaceCursor() ;
  78.  
  79. /*****************************************************************
  80.  * mpelPolySegment
  81.  *
  82.  *    For each segment, draws a line between (x1, y1 ) and (x2, y2 ) .  The
  83.  *    lines are drawn in the order listed.
  84.  *
  85.  *****************************************************************/
  86.  
  87. void
  88. mpelPolySegment( pDraw, pGC, nseg, pSegs )
  89.     DrawablePtr pDraw ;
  90.     GCPtr     pGC ;
  91.     int        nseg ;
  92.     xSegment    *pSegs ;
  93. {
  94.     register DDXPointPtr ppt ;
  95.     register int nbox ;
  96.     register BoxPtr pbox ;
  97.     int nptTmp ;
  98.     RegionPtr pRegion ;
  99.     mpelRectangle scissor ;
  100.     int cursor_saved ;
  101.     ppcPrivGCPtr pPriv = (ppcPrivGCPtr ) pGC->devPrivates[mfbGCPrivateIndex].ptr ;
  102.     mpelPrivGCPtr mpelPriv = (mpelPrivGCPtr ) pPriv->devPriv ;
  103.  
  104.     if (  pPriv->colorRrop.alu == GXnoop )
  105.     return ;
  106.  
  107.     pRegion = pPriv->pCompositeClip ;
  108.     if ( !( nbox = REGION_NUM_RECTS(pRegion) ) )
  109.     return ;
  110.  
  111.     /* translate the point list */
  112.     nptTmp = nseg * 2 ;
  113.     ppt = (DDXPointPtr ) pSegs ;
  114.  
  115.     while ( nptTmp-- )
  116.     {
  117.         register int xorg = pDraw->x ;
  118.         register int yorg = pDraw->y ;
  119.  
  120.     ppt->x += xorg ;
  121.     ppt->y += yorg ;
  122.     ppt->y = MPEL_HEIGHT - 1 - ppt->y ;
  123.     ppt++ ;
  124.     }
  125.  
  126.     /* If Cursor Is In The Way Remove It */
  127.     cursor_saved = !mpelcursorSemaphore
  128.        && mpelCheckCursor(
  129.         pRegion->extents.x1,
  130.          pRegion->extents.y1,
  131.         pRegion->extents.x2 - pRegion->extents.x1,
  132.         pRegion->extents.y2 - pRegion->extents.y1
  133.     ) ;
  134.  
  135.     switch(pGC->lineStyle ) {
  136.     case LineOnOffDash:
  137.         switch ( pPriv->colorRrop.fillStyle ) {
  138.         case FillStippled :
  139.         case FillSolid : /* Can Use Optimized Color Raster-Op */
  140.             mpelSetALU( pPriv->colorRrop.alu ) ;
  141.             mpelSetPlaneMask( pPriv->colorRrop.planemask ) ;
  142.             MPELSetPolylineColor( pPriv->colorRrop.fgPixel ) ;
  143.             break ;
  144.         case FillOpaqueStippled :
  145.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  146.             mpelSetALU(pGC->alu ) ;
  147.             mpelSetPlaneMask(pGC->planemask ) ;
  148.             MPELSetPolylineColor( pGC->fgPixel ) ;
  149.             break ;
  150.         }
  151.     break ;
  152.     case LineDoubleDash:
  153.         switch ( pPriv->colorRrop.fillStyle ) {
  154.         case FillStippled :
  155.         case FillSolid :
  156.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  157.             mpelSetALU(pGC->alu ) ;
  158.             mpelSetPlaneMask(pGC->planemask ) ;
  159.             MPELSetPolylineColor( pGC->fgPixel ) ;
  160.             if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  161.             MPELSetUserLineStyle(&mpelPriv->LineStyle ) ;
  162.             MPELSetLineType(mpelPriv->LineType ) ;
  163. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  164.             for ( pbox = REGION_RECTS(pRegion) ;nbox-- ;pbox++ ) {
  165.             scissor.uright.x=     pbox->x2-1 ;
  166.             scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  167.             scissor.lleft.x=      pbox->x1 ;
  168.             scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  169.             MPELSetScissor(&scissor ) ;
  170.                 MPELMultiline(nseg * 2, pSegs ) ;
  171.             }
  172.             MPELSetPolylineColor( pGC->bgPixel ) ;
  173.         mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  174.             break ;
  175.         case FillOpaqueStippled : /* Can Use Optimized Color Raster-Op */
  176.             mpelSetALU( pPriv->colorRrop.alu ) ;
  177.             mpelSetPlaneMask( pPriv->colorRrop.planemask ) ;
  178.             MPELSetPolylineColor( pPriv->colorRrop.fgPixel ) ;
  179.             if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  180.             MPELSetUserLineStyle(&mpelPriv->LineStyle ) ;
  181.             MPELSetLineType(mpelPriv->LineType ) ;
  182. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  183.             for ( pbox = REGION_RECTS(pRegion) ; nbox-- ; pbox++ ) {
  184.             scissor.uright.x=     pbox->x2-1 ;
  185.             scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  186.             scissor.lleft.x=      pbox->x1 ;
  187.             scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  188.             MPELSetScissor(&scissor ) ;
  189.                 MPELMultiline( nseg*2, pSegs ) ;
  190.             }
  191.             MPELSetPolylineColor(
  192.                 pPriv->colorRrop.bgPixel ) ;
  193.         mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  194.             break ;
  195.         }
  196.     break ;
  197.     case LineSolid:
  198.         mpelSetALU( pGC->alu ) ;
  199.         mpelSetPlaneMask( pGC->planemask ) ;
  200.         MPELSetPolylineColor( pGC->fgPixel ) ;
  201.     break ;
  202.     default:
  203.     ErrorF( "unknown line type\n" ) ;
  204.     break ;
  205.     }
  206.  
  207.     if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  208.     MPELSetUserLineStyle( &mpelPriv->LineStyle ) ;
  209.     MPELSetLineType( mpelPriv->LineType ) ;
  210.  
  211.     pbox = REGION_RECTS(pRegion) ;
  212. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  213.     for ( nbox = REGION_NUM_RECTS(pRegion) ; nbox-- ; pbox++ ) {
  214.     scissor.uright.x=     pbox->x2-1 ;
  215.     scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  216.     scissor.lleft.x=      pbox->x1 ;
  217.     scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  218.     MPELSetScissor( &scissor ) ;
  219.         MPELMultiline( nseg*2, pSegs ) ;
  220.     }
  221.  
  222.     MPELResetScissor() ;
  223.  
  224.     if ( pGC->lineStyle == LineDoubleDash )
  225.     mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  226.  
  227.     if ( cursor_saved )
  228.     mpelReplaceCursor() ;
  229.     return ;
  230. }
  231.  
  232. void
  233. mpelHorzLine( color, alu, mask, x, y, w )
  234. unsigned long int color ;
  235. int alu ;
  236. unsigned long int mask ;
  237. int x, y, w ;
  238. {
  239.     mpelFillSolid( color, alu, mask, x, y, w, 1 ) ;
  240.     return ;
  241. }
  242.  
  243. void
  244. mpelVertLine( color, alu, mask, x, y, h )
  245. unsigned long int color ;
  246. int alu ;
  247. unsigned long int mask ;
  248. int x, y, h ;
  249. {
  250.     mpelFillSolid( color, alu, mask, x, y, 1, h ) ;
  251.     return ;
  252. }
  253.  
  254. /* Solid bresenham line */
  255.  
  256. void
  257. mpelBresLine( color, alu, mask, signdx, signdy, axis, x1, y1, e, e1, e2, len )
  258. unsigned long int color ;
  259. int alu ;
  260. unsigned long int mask ;
  261. int signdx, signdy ;    /* signs of directions */
  262. int axis ;        /* major axis (Y_AXIS or X_AXIS ) */
  263. int x1, y1 ;        /* initial point */
  264. register int e ;        /* error accumulator */
  265. register int e1 ;    /* bresenham increments */
  266. int e2 ;
  267. register int len ;    /* length of line */
  268. {
  269.     register int x = x1 ;
  270.     register int y = y1 ;
  271.  
  272.     if (axis == X_AXIS )
  273.     {
  274.         if (signdx > 0 )
  275.         {
  276.             while ( len-- )
  277.             {
  278.             mpelFillSolid( color, alu, mask, x, y, 1, 1 ) ;
  279.                 if (e < 0 )
  280.                     e += e1 ;
  281.                 else
  282.                 {
  283.                 if ( signdy > 0 )
  284.                         y++ ;
  285.                 else
  286.                     y-- ;
  287.                     e += e2 ;
  288.                 }
  289.             x++ ;
  290.             }
  291.         }
  292.         else
  293.         {
  294.             while ( len-- )
  295.             {
  296.             mpelFillSolid( color, alu, mask, x, y, 1, 1 ) ;
  297.                 if (e <= 0 )
  298.                     e += e1 ;
  299.                 else
  300.                 {
  301.                 if ( signdy > 0 )
  302.                         y++ ;
  303.                 else
  304.                     y-- ;
  305.                     e += e2 ;
  306.                 }
  307.             x-- ;
  308.             }
  309.         }
  310.    } /* if X_AXIS */
  311.    else
  312.    {
  313.         if (signdx > 0 )
  314.         {
  315.             while ( len-- )
  316.             {
  317.             mpelFillSolid( color, alu, mask, x, y, 1, 1 ) ;
  318.                 if (e < 0 )
  319.                     e += e1 ;
  320.                 else
  321.                 {
  322.                 x++ ;
  323.                     e += e2 ;
  324.                 }
  325.             if ( signdy > 0 )
  326.                        y++ ;
  327.             else
  328.                 y-- ;
  329.             }
  330.         }
  331.         else
  332.         {
  333.             while ( len-- )
  334.             {
  335.             mpelFillSolid( color, alu, mask, x, y, 1, 1 ) ;
  336.                 if (e <= 0 )
  337.                     e += e1 ;
  338.                 else
  339.                 {
  340.                 x-- ;
  341.                     e += e2 ;
  342.                 }
  343.             if (signdy > 0 )
  344.                        y++ ;
  345.             else
  346.                 y-- ;
  347.             }
  348.         }
  349.     } /* else Y_AXIS */
  350.     return ;
  351. }
  352.  
  353. /***==================================================================***/
  354.  
  355. void
  356. mpelZeroLine( dst, pGC, mode, n, pPoint )
  357.     DrawablePtr dst ;
  358.     GCPtr pGC ;
  359.     int mode ;
  360.     int n ;
  361.     DDXPointPtr pPoint ;
  362. {
  363.     register DDXPointPtr ppt ;
  364.     register int nbox ;
  365.     register BoxPtr pbox ;
  366.     int nptTmp ;
  367.     RegionPtr pRegion ;
  368.     int cursor_saved ;
  369.     mpelRectangle scissor ;
  370.     ppcPrivGCPtr pPriv = (ppcPrivGCPtr ) pGC->devPrivates[mfbGCPrivateIndex].ptr ;
  371.     mpelPrivGCPtr mpelPriv = (mpelPrivGCPtr ) pPriv->devPriv ;
  372.  
  373.     TRACE( ("mpelZeroLine(0x%x,0x%x,%d,%d,0x%x)\n", dst, pGC, mode, n, pPoint));
  374.  
  375.     if ( pPriv->colorRrop.alu == GXnoop )
  376.     return ;
  377.  
  378.     pRegion = pPriv->pCompositeClip ;
  379.     if ( !( nbox = REGION_NUM_RECTS(pRegion) ) )
  380.     return ;
  381.  
  382.     /* translate the point list */
  383.     ppt = pPoint ;
  384.     nptTmp = n ;
  385.  
  386.     if (mode == CoordModeOrigin )
  387.     {
  388.     while ( nptTmp-- )
  389.     {
  390.             register int xorg = dst->x ;
  391.             register int yorg = dst->y ;
  392.  
  393.         ppt->x += xorg ;
  394.         ppt->y += yorg ;
  395.         ppt->y = MPEL_HEIGHT - 1 - ppt->y ;
  396.         ppt++ ;
  397.     }
  398.     }
  399.     else
  400.     {
  401.         register int xorg = dst->x ;
  402.         register int yorg = dst->y ;
  403.  
  404.     ppt->x += xorg ;
  405.     ppt->y += yorg ;
  406.     nptTmp-- ;
  407.     while ( nptTmp-- )
  408.     {
  409.         ppt++ ;
  410.         ppt->x += (ppt-1)->x ;
  411.         ppt->y += (ppt-1)->y ;
  412.         (ppt-1)->y = MPEL_HEIGHT - 1 - (ppt-1)->y ;
  413.     }
  414.     ppt->y = MPEL_HEIGHT - 1 - ppt->y ;
  415.     }
  416.  
  417.     /* If Cursor Is In The Way Remove It */
  418.     cursor_saved = !mpelcursorSemaphore
  419.        && mpelCheckCursor(
  420.         pRegion->extents.x1,
  421.          pRegion->extents.y1,
  422.         pRegion->extents.x2 - pRegion->extents.x1,
  423.         pRegion->extents.y2 - pRegion->extents.y1
  424.     ) ;
  425.  
  426.     switch ( pGC->lineStyle ) {
  427.     case LineOnOffDash:
  428.         switch ( pPriv->colorRrop.fillStyle ) {
  429.         case FillStippled :
  430.         case FillSolid : /* Can Use Optimized Color Raster-Op */
  431.             mpelSetALU( pPriv->colorRrop.alu ) ;
  432.             mpelSetPlaneMask( pPriv->colorRrop.planemask ) ;
  433.             MPELSetPolylineColor( pPriv->colorRrop.fgPixel ) ;
  434.             break ;
  435.         case FillOpaqueStippled :
  436.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  437.             mpelSetALU( pGC->alu ) ;
  438.             mpelSetPlaneMask( pGC->planemask ) ;
  439.             MPELSetPolylineColor( pGC->fgPixel ) ;
  440.             break ;
  441.         }
  442.     break ;
  443.     case LineDoubleDash:
  444.         switch ( pPriv->colorRrop.fillStyle ) {
  445.         case FillStippled :
  446.         case FillSolid :
  447.         case FillTiled : /* Can't Use Optimized Color Raster-Op */
  448.             mpelSetALU( pGC->alu ) ;
  449.             mpelSetPlaneMask( pGC->planemask ) ;
  450.             MPELSetPolylineColor( pGC->fgPixel ) ;
  451.             if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  452.             MPELSetUserLineStyle(&mpelPriv->LineStyle ) ;
  453.             MPELSetLineType( mpelPriv->LineType ) ;
  454. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  455.             for ( pbox = REGION_RECTS(pRegion) ; nbox-- ; pbox++ ) {
  456.             scissor.uright.x=     pbox->x2-1 ;
  457.             scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  458.             scissor.lleft.x=      pbox->x1 ;
  459.             scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  460.             MPELSetScissor( &scissor ) ;
  461.                 MPELPolyline( n, pPoint ) ;
  462.             }
  463.             MPELSetPolylineColor( pGC->bgPixel ) ;
  464.         mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  465.             break ;
  466.         case FillOpaqueStippled : /* Can Use Optimized Color Raster-Op */
  467.             mpelSetALU( pPriv->colorRrop.alu ) ;
  468.             mpelSetPlaneMask( pPriv->colorRrop.planemask ) ;
  469.             MPELSetPolylineColor( pPriv->colorRrop.fgPixel ) ;
  470.             if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  471.             MPELSetUserLineStyle( &mpelPriv->LineStyle ) ;
  472.             MPELSetLineType( mpelPriv->LineType ) ;
  473. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  474.             for ( pbox = REGION_RECTS(pRegion); nbox-- ; pbox++ ) {
  475.             scissor.uright.x=     pbox->x2-1 ;
  476.             scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  477.             scissor.lleft.x=      pbox->x1 ;
  478.             scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  479.             MPELSetScissor( &scissor ) ;
  480.                 MPELPolyline( n, pPoint ) ;
  481.             }
  482.             MPELSetPolylineColor( pPriv->colorRrop.bgPixel ) ;
  483.         mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  484.             break ;
  485.         }
  486.     break ;
  487.     case LineSolid:
  488.         mpelSetALU( pGC->alu ) ;
  489.         mpelSetPlaneMask( pGC->planemask ) ;
  490.         MPELSetPolylineColor( pGC->fgPixel ) ;
  491.     break ;
  492.     default:
  493.     ErrorF( "unknown line type\n" ) ;
  494.     break ;
  495.     }
  496.  
  497.     if ( mpelPriv->LineType == MPEL_USERLINESTYLE_CONT )
  498.     MPELSetUserLineStyle( &mpelPriv->LineStyle ) ;
  499.     MPELSetLineType( mpelPriv->LineType ) ;
  500.  
  501.     pbox = REGION_RECTS(pRegion) ;
  502. /* SCISSOR CODE STINKS -- IT MUST GO AWAY !! */
  503.     for ( nbox = REGION_NUM_RECTS(pRegion) ; nbox-- ; pbox++ ) {
  504.     scissor.uright.x=     pbox->x2-1 ;
  505.     scissor.uright.y=     MPEL_HEIGHT - 1 - pbox->y1 ;
  506.     scissor.lleft.x=      pbox->x1 ;
  507.     scissor.lleft.y=    MPEL_HEIGHT - pbox->y2 ;
  508.     MPELSetScissor( &scissor ) ;
  509.         MPELPolyline( n, pPoint ) ;
  510.     }
  511.  
  512.     MPELResetScissor() ;
  513.  
  514.     if ( pGC->lineStyle == LineDoubleDash )
  515.     mpelPriv->LineStyle.mask = ~mpelPriv->LineStyle.mask ;
  516.  
  517.     if ( cursor_saved )
  518.     mpelReplaceCursor() ;
  519.     return ;
  520. }
  521.