home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mi / mizerline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-25  |  5.7 KB  |  279 lines

  1. /***********************************************************
  2. Copyright 1987 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. /* $XConsortium: mizerline.c,v 5.3 89/11/25 12:30:33 rws Exp $ */
  25. #include "X.h"
  26.  
  27. #include "misc.h"
  28. #include "scrnintstr.h"
  29. #include "gcstruct.h"
  30. #include "windowstr.h"
  31. #include "pixmap.h"
  32. #include "mi.h"
  33.  
  34. void
  35. miZeroLine(dst, pgc, mode, nptInit, pptInit)
  36. DrawablePtr dst;
  37. GCPtr pgc;
  38. int mode;
  39. int nptInit;        /* number of points in polyline */
  40. DDXPointRec *pptInit;    /* points in the polyline */
  41. {
  42.     int xorg, yorg;
  43.     DDXPointRec *ppt;
  44.     int npt;
  45.  
  46.     DDXPointRec pt1, pt2;
  47.     int dx, dy;
  48.     int adx, ady;
  49.     int signdx, signdy;
  50.     register int len;
  51.  
  52.     int du, dv;
  53.     register int e, e1, e2;
  54.  
  55.     register int x,y;    /* current point on the line */
  56.     int i;        /* traditional name for loop counter */
  57.  
  58.     DDXPointPtr pspanInit;
  59.     int *pwidthInit;
  60.     int list_len = dst->height;
  61.     Bool local = TRUE;
  62.  
  63.     pspanInit = (DDXPointPtr)ALLOCATE_LOCAL(list_len * sizeof(DDXPointRec));
  64.     pwidthInit = (int *)ALLOCATE_LOCAL(list_len * sizeof(int));
  65.     if (!pspanInit || !pwidthInit)
  66.     return;
  67.     ppt = pptInit;
  68.     npt = nptInit;
  69.     if (pgc->miTranslate)
  70.     {
  71.     xorg = dst->x;
  72.     yorg = dst->y;
  73.  
  74.         if (mode == CoordModeOrigin) 
  75.         {
  76.             for (i = 0; i<npt; i++) 
  77.                 {    
  78.                 ppt->x += xorg;
  79.                 ppt++->y += yorg;
  80.             }
  81.         }
  82.         else 
  83.         {
  84.         ppt->x += xorg;
  85.         ppt++->y += yorg;
  86.         for (i = 1; i<npt; i++) 
  87.             {
  88.             ppt->x += (ppt-1)->x;
  89.             ppt->y += (ppt-1)->y;
  90.             ppt++;
  91.         }
  92.         }
  93.     }
  94.     else
  95.     {
  96.     if (mode == CoordModePrevious)
  97.         {
  98.         ppt++;
  99.         for (i = 1; i<npt; i++) 
  100.             {
  101.             ppt->x += (ppt-1)->x;
  102.             ppt->y += (ppt-1)->y;
  103.             ppt++;
  104.         }
  105.         }
  106.     }
  107.  
  108.     ppt = pptInit;
  109.     npt = nptInit;
  110.     while (--npt)
  111.     {
  112.     DDXPointPtr pspan;
  113.      int *pwidth;
  114.     int width;
  115.  
  116.     pt1 = *ppt++;
  117.     pt2 = *ppt;
  118.     dx = pt2.x - pt1.x;
  119.     dy = pt2.y - pt1.y;
  120.     adx = abs(dx);
  121.     ady = abs(dy);
  122.     signdx = sign(dx);
  123.     signdy = sign(dy);
  124.  
  125.     if (adx > ady)
  126.     {
  127.         du = adx;
  128.         dv = ady;
  129.         len = adx;
  130.     }
  131.     else
  132.     {
  133.         du = ady;
  134.         dv = adx;
  135.         len = ady;
  136.     }
  137.  
  138.     e1 = dv * 2;
  139.     e2 = e1 - 2*du;
  140.     e = e1 - du;
  141.  
  142.     if (ady >= list_len)
  143.     {
  144.         DDXPointPtr npspanInit;
  145.         int *npwidthInit;
  146.  
  147.         if (local)
  148.         {
  149.         DEALLOCATE_LOCAL(pwidthInit);
  150.         pwidthInit = (int *)NULL;
  151.         DEALLOCATE_LOCAL(pspanInit);
  152.         pspanInit = (DDXPointPtr)NULL;
  153.         local = FALSE;
  154.         }
  155.         list_len = ady + 1;
  156.         npspanInit = (DDXPointPtr)xrealloc(pspanInit,
  157.                            sizeof(DDXPointRec) * list_len);
  158.         if (!npspanInit)
  159.         {
  160.         list_len = 0;
  161.         continue;
  162.         }
  163.         pspanInit = npspanInit;
  164.         npwidthInit = (int *)xrealloc(pwidthInit, sizeof(int) * list_len);
  165.         if (!npwidthInit)
  166.         {
  167.         list_len = 0;
  168.         continue;
  169.         }
  170.         pwidthInit = npwidthInit;
  171.     }
  172.     pspan = pspanInit;
  173.     pwidth = pwidthInit;
  174.  
  175.     x = pt1.x;
  176.     y = pt1.y;
  177.     *pspan = pt1;
  178.     if (adx > ady)
  179.     {
  180.         /* X_AXIS */
  181.         width = 0;
  182.         while(len--)
  183.         {
  184.         if (((signdx > 0) && (e < 0)) ||
  185.             ((signdx <=0) && (e <=0))
  186.            )
  187.         {
  188.             e += e1;
  189.             x+= signdx;
  190.             width++;
  191.         }
  192.         else
  193.         {
  194.             /* give this span a width */
  195.             width++;
  196.             *pwidth++ = width;
  197.  
  198.             /* force the span the right way */
  199.             if (signdx < 0)
  200.             pspan->x -= (width-1);
  201.  
  202.             /* initialize next span */
  203.             x += signdx;
  204.             y += signdy;
  205.             e += e2;
  206.  
  207.             width = 0;
  208.             pspan++;
  209.             pspan->x = x;
  210.             pspan->y = y;
  211.  
  212.         }
  213.         };
  214.         /* do the last span */
  215.         *pwidth++ = width;
  216.         if (signdx < 0)
  217.         pspan->x -= (width-1);
  218.     }
  219.     else
  220.     {
  221.         /* Y_AXIS */
  222.         while(len--)
  223.         {
  224.         if (((signdx > 0) && (e < 0)) ||
  225.             ((signdx <=0) && (e <=0))
  226.            )
  227.         {
  228.             e +=e1;
  229.         }
  230.         else
  231.         {
  232.             x += signdx;
  233.             e += e2;
  234.         }
  235.         y += signdy;
  236.         pspan++;
  237.         pspan->x = x;
  238.         pspan->y = y;
  239.         *pwidth++ = 1;
  240.         };
  241.     }
  242.  
  243.     (*pgc->ops->FillSpans)(dst, pgc, pwidth-pwidthInit,
  244.               pspanInit, pwidthInit, FALSE);
  245.     }
  246.     if (local)
  247.     {
  248.     DEALLOCATE_LOCAL(pwidthInit);
  249.     DEALLOCATE_LOCAL(pspanInit);
  250.     }
  251.     else
  252.     {
  253.     xfree(pwidthInit);
  254.     xfree(pspanInit);
  255.     }
  256.  
  257.     if ((pgc->capStyle != CapNotLast) &&
  258.     ((ppt->x != pptInit->x) ||
  259.      (ppt->y != pptInit->y) ||
  260.      (ppt == pptInit + 1)))
  261.     {
  262.     int width = 1;
  263.     (*pgc->ops->FillSpans)(dst, pgc, 1, ppt, &width, TRUE);
  264.     }
  265.  
  266. miZeroDashLine(dst, pgc, mode, nptInit, pptInit)
  267. DrawablePtr dst;
  268. GCPtr pgc;
  269. int mode;
  270. int nptInit;        /* number of points in polyline */
  271. DDXPointRec *pptInit;    /* points in the polyline */
  272. {
  273.     /* XXX kludge until real zero-width dash code is written */
  274.     pgc->lineWidth = 1;
  275.     miWideDash (dst, pgc, mode, nptInit, pptInit);
  276.     pgc->lineWidth = 0;
  277. }
  278.