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_arcs.c < prev    next >
C/C++ Source or Header  |  1991-04-29  |  12KB  |  521 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.  
  26. static XArc *arcs;
  27. static GC   pgc;
  28.  
  29. #define DegreesToX(degrees) (degrees * 64)
  30.  
  31. static void GenerateCircles(xp, p, partialArcs)
  32.     XParms  xp;
  33.     Parms   p;
  34.     Bool    partialArcs;
  35. {
  36.     int     i;
  37.     int     rows;       /* Number of rows filled in current column        */
  38.     int     x, y;       /* base of square to draw the circle in            */
  39.     int     xorg, yorg; /* Used to get from column to column or row to row  */
  40.     int     size;
  41.     int     half;
  42.     int     startAngle, arcAngle;
  43.  
  44.     pgc = xp->fggc;
  45.  
  46.     size = p->special;
  47.     half = (size + 19) / 20;
  48.     arcs = (XArc *)malloc((p->objects) * sizeof(XArc));
  49.     x = xorg = half; y = yorg = half;
  50.     rows = 0;
  51.     startAngle = DegreesToX(0);
  52.     arcAngle = DegreesToX(360);
  53.  
  54.     for (i = 0; i != p->objects; i++) {    
  55.     arcs[i].x = x;
  56.     arcs[i].y = y;
  57.     arcs[i].width = size;
  58.     arcs[i].height = size;
  59.     arcs[i].angle1 = startAngle;
  60.     arcs[i].angle2 = arcAngle;
  61.  
  62.     if (partialArcs) {
  63.         startAngle += DegreesToX(30);
  64.         if (startAngle >= DegreesToX(360)) startAngle -= DegreesToX(360);
  65.         arcAngle -= DegreesToX(20);
  66.         if (arcAngle <= DegreesToX(0)) arcAngle += DegreesToX(360);
  67.     }
  68.  
  69.     y += size + 1;
  70.     rows++;
  71.     if (y >= HEIGHT - size  - half || rows == MAXROWS) {
  72.         /* Go to next column */
  73.         rows = 0;
  74.         x += size + 1;
  75.         if (x >= WIDTH - size) {
  76.         yorg++;
  77.         if (yorg >= size + half || yorg >= HEIGHT - size - half) {
  78.             yorg = half;
  79.             xorg++;
  80.             if (xorg >= size + half || xorg >= WIDTH - size - half) {
  81.             xorg = half;
  82.             }
  83.         }
  84.         x = xorg;
  85.         }
  86.         y = yorg;
  87.     }
  88.     }
  89. }
  90.  
  91. int InitCircles(xp, p, reps)
  92.     XParms  xp;
  93.     Parms   p;
  94.     int     reps;
  95. {
  96.     GenerateCircles(xp, p, False);
  97.     return reps;
  98. }
  99.  
  100. int InitPartCircles(xp, p, reps)
  101.     XParms  xp;
  102.     Parms   p;
  103.     int     reps;
  104. {
  105.     GenerateCircles(xp, p, True);
  106.     return reps;
  107. }
  108.  
  109.  
  110. int InitChordPartCircles(xp, p, reps)
  111.     XParms  xp;
  112.     Parms   p;
  113.     int     reps;
  114. {
  115.     GenerateCircles(xp, p, True);
  116.     XSetArcMode(xp->d, xp->bggc, ArcChord);
  117.     XSetArcMode(xp->d, xp->fggc, ArcChord);
  118.     return reps;
  119. }
  120.  
  121.  
  122. int InitSlicePartCircles(xp, p, reps)
  123.     XParms  xp;
  124.     Parms   p;
  125.     int     reps;
  126. {
  127.     GenerateCircles(xp, p, True);
  128.     XSetArcMode(xp->d, xp->bggc, ArcPieSlice);
  129.     XSetArcMode(xp->d, xp->fggc, ArcPieSlice);
  130.     return reps;
  131. }
  132.  
  133. static void
  134. GenerateWideCircles (xp, p, partialArcs)
  135.     XParms  xp;
  136.     Parms   p;
  137.     Bool    partialArcs;
  138. {
  139.     int        size;
  140.  
  141.     GenerateCircles(xp, p, partialArcs);
  142.  
  143.     size = p->special;
  144.     XSetLineAttributes(xp->d, xp->bggc, (int) ((size + 9) / 10),
  145.     LineSolid, CapRound, JoinRound);
  146.     XSetLineAttributes(xp->d, xp->fggc, (int) ((size + 9) / 10),
  147.     LineSolid, CapRound, JoinRound);
  148. }
  149.  
  150. int InitWideCircles(xp, p, reps)
  151.     XParms  xp;
  152.     Parms   p;
  153.     int     reps;
  154. {
  155.     GenerateWideCircles (xp, p, False);
  156.     return reps;
  157. }
  158.  
  159. int InitPartWideCircles(xp, p, reps)
  160.     XParms  xp;
  161.     Parms   p;
  162.     int     reps;
  163. {
  164.     GenerateWideCircles (xp, p, True);
  165.     return reps;
  166. }
  167.  
  168. int InitDashedCircles(xp, p, reps)
  169.     XParms  xp;
  170.     Parms   p;
  171.     int     reps;
  172. {
  173.     char dashes[2];
  174.  
  175.     (void)InitCircles(xp, p, reps);
  176.  
  177.     /* Modify GCs to draw dashed */
  178.     XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  179.     XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  180.     dashes[0] = 3;   dashes[1] = 2;
  181.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  182.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  183.     return reps;
  184. }
  185.  
  186. int InitWideDashedCircles(xp, p, reps)
  187.     XParms  xp;
  188.     Parms   p;
  189.     int     reps;
  190. {
  191.     int        size;
  192.     XGCValues   gcv;
  193.     char    dashes[2];
  194.  
  195.     (void)InitWideCircles(xp, p, reps);
  196.     size = p->special;
  197.     size = (size + 9) / 10;
  198.  
  199.     /* Modify GCs to draw dashed */
  200.     dashes[0] = 2*size;   dashes[1] = 2*size;
  201.     gcv.line_style = LineOnOffDash;
  202.     XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  203.     XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  204.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  205.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  206.     return reps;
  207. }
  208.  
  209. int InitDoubleDashedCircles(xp, p, reps)
  210.     XParms  xp;
  211.     Parms   p;
  212.     int     reps;
  213. {
  214.     char dashes[2];
  215.  
  216.     (void)InitCircles(xp, p, reps);
  217.  
  218.     /* Modify GCs to draw dashed */
  219.     XSetLineAttributes(xp->d, xp->bggc, 0, LineDoubleDash, CapButt, JoinMiter);
  220.     XSetLineAttributes(xp->d, xp->fggc, 0, LineDoubleDash, CapButt, JoinMiter);
  221.     dashes[0] = 3;   dashes[1] = 2;
  222.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  223.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  224.     return reps;
  225. }
  226.  
  227. int InitWideDoubleDashedCircles(xp, p, reps)
  228.     XParms  xp;
  229.     Parms   p;
  230.     int     reps;
  231. {
  232.     int        size;
  233.     XGCValues   gcv;
  234.     char    dashes[2];
  235.  
  236.     (void)InitWideCircles(xp, p, reps);
  237.     size = p->special;
  238.     size = (size + 9) / 10;
  239.  
  240.     /* Modify GCs to draw dashed */
  241.     dashes[0] = 2*size;   dashes[1] = 2*size;
  242.     gcv.line_style = LineDoubleDash;
  243.     XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  244.     XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  245.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  246.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  247.     return reps;
  248. }
  249.  
  250. static void GenerateEllipses(xp, p, partialArcs)
  251.     XParms  xp;
  252.     Parms   p;
  253.     int    partialArcs;
  254. {
  255.     int     size;
  256.     int     half;
  257.     int     rows;       /* Number of rows filled in current column        */
  258.     int     i;
  259.     int     x, y;        /* base of square to draw ellipse in        */
  260.     int     vsize, vsizeinc;
  261.     int     dir;
  262.     int     startAngle, arcAngle;
  263.  
  264.     pgc = xp->fggc;
  265.  
  266.     size = p->special;
  267.     half = (size + 19) / 20;
  268.     arcs = (XArc *)malloc((p->objects) * sizeof(XArc));
  269.     vsize = 1;
  270.     vsizeinc = (size - 1) / (p->objects - 1);
  271.     if (vsizeinc == 0) vsizeinc = 1;
  272.  
  273.     x = half; y = half;
  274.     dir = 0;
  275.     rows = 0;
  276.     startAngle = DegreesToX(0);
  277.     arcAngle = DegreesToX(360);
  278.  
  279.     for (i = 0; i != p->objects; i++) {    
  280.     arcs[i].x = x;
  281.     arcs[i].y = y;
  282.     if ((i & 1) ^ dir) {
  283.         /* Make vertical axis longer */
  284.         arcs[i].width = vsize;
  285.         arcs[i].height = size;
  286.     } else {
  287.         /* Make horizontal axis longer */
  288.         arcs[i].width = size;
  289.         arcs[i].height = vsize;
  290.     }
  291.     arcs[i].angle1 = startAngle;
  292.     arcs[i].angle2 = arcAngle;
  293.  
  294.     if (partialArcs) {
  295.         startAngle += DegreesToX(30);
  296.         if (startAngle >= DegreesToX(360)) startAngle -= DegreesToX(360);
  297.         arcAngle -= DegreesToX(20);
  298.         if (arcAngle <= DegreesToX(0)) arcAngle += DegreesToX(360);
  299.     }
  300.  
  301.     y += size + 1;
  302.     rows++;
  303.     if (y >= HEIGHT - size - half || rows == MAXROWS) {
  304.         /* Go to next column */
  305.         rows = 0;
  306.         y = half;
  307.         x += size + 1;
  308.         if (x >= WIDTH - size - half) {
  309.         x = half;
  310.         }
  311.     }
  312.     
  313.     vsize += vsizeinc;
  314.     if (vsize > size) {
  315.         vsize -= size;
  316.         dir = 1 - dir;
  317.     }
  318.     }
  319. }
  320.  
  321. int InitEllipses(xp, p, reps)
  322.     XParms  xp;
  323.     Parms   p;
  324.     int     reps;
  325. {
  326.     GenerateEllipses(xp, p, False);
  327.     return reps;
  328. }
  329.  
  330.  
  331. int InitPartEllipses(xp, p, reps)
  332.     XParms  xp;
  333.     Parms   p;
  334.     int     reps;
  335. {
  336.     GenerateEllipses(xp, p, True);
  337.     return reps;
  338. }
  339.  
  340.  
  341. int InitChordPartEllipses(xp, p, reps)
  342.     XParms  xp;
  343.     Parms   p;
  344.     int     reps;
  345. {
  346.     GenerateEllipses(xp, p, True);
  347.     XSetArcMode(xp->d, xp->bggc, ArcChord);
  348.     XSetArcMode(xp->d, xp->fggc, ArcChord);
  349.     return reps;
  350. }
  351.  
  352.  
  353. int InitSlicePartEllipses(xp, p, reps)
  354.     XParms  xp;
  355.     Parms   p;
  356.     int     reps;
  357. {
  358.     GenerateEllipses(xp, p, True);
  359.     XSetArcMode(xp->d, xp->bggc, ArcPieSlice);
  360.     XSetArcMode(xp->d, xp->fggc, ArcPieSlice);
  361.     return reps;
  362. }
  363.  
  364.  
  365. static void
  366. GenerateWideEllipses (xp, p, partialArcs)
  367.     XParms  xp;
  368.     Parms   p;
  369.     Bool    partialArcs;
  370. {
  371.     int size;
  372.  
  373.     GenerateEllipses (xp, p, partialArcs);
  374.     size = p->special;
  375.     XSetLineAttributes(xp->d, xp->bggc, (int) ((size + 9) / 10),
  376.     LineSolid, CapRound, JoinRound);
  377.     XSetLineAttributes(xp->d, xp->fggc, (int) ((size + 9) / 10),
  378.     LineSolid, CapRound, JoinRound);
  379.  
  380. }
  381.  
  382. int InitWideEllipses(xp, p, reps)
  383.     XParms  xp;
  384.     Parms   p;
  385.     int     reps;
  386. {
  387.     GenerateWideEllipses(xp, p, False);
  388.     return reps;
  389. }
  390.  
  391. int InitPartWideEllipses(xp, p, reps)
  392.     XParms  xp;
  393.     Parms   p;
  394.     int     reps;
  395. {
  396.     GenerateWideEllipses(xp, p, True);
  397.     return reps;
  398. }
  399.  
  400. int InitDashedEllipses(xp, p, reps)
  401.     XParms  xp;
  402.     Parms   p;
  403.     int     reps;
  404. {
  405.     char dashes[2];
  406.  
  407.     (void)InitEllipses(xp, p, reps);
  408.  
  409.     /* Modify GCs to draw dashed */
  410.     XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  411.     XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  412.     dashes[0] = 3;   dashes[1] = 2;
  413.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  414.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  415.     return reps;
  416. }
  417.  
  418. int InitWideDashedEllipses(xp, p, reps)
  419.     XParms  xp;
  420.     Parms   p;
  421.     int     reps;
  422. {
  423.     int        size;
  424.     XGCValues   gcv;
  425.     char    dashes[2];
  426.  
  427.     (void)InitWideEllipses(xp, p, reps);
  428.     size = p->special;
  429.     size = (size + 9) / 10;
  430.  
  431.     /* Modify GCs to draw dashed */
  432.     dashes[0] = 2*size;   dashes[1] = 2*size;
  433.     gcv.line_style = LineOnOffDash;
  434.     XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  435.     XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  436.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  437.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  438.     return reps;
  439. }
  440.  
  441. int InitDoubleDashedEllipses(xp, p, reps)
  442.     XParms  xp;
  443.     Parms   p;
  444.     int     reps;
  445. {
  446.     char dashes[2];
  447.  
  448.     (void)InitEllipses(xp, p, reps);
  449.  
  450.     /* Modify GCs to draw dashed */
  451.     XSetLineAttributes(xp->d, xp->bggc, 0, LineDoubleDash, CapButt, JoinMiter);
  452.     XSetLineAttributes(xp->d, xp->fggc, 0, LineDoubleDash, CapButt, JoinMiter);
  453.     dashes[0] = 3;   dashes[1] = 2;
  454.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  455.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  456.     return reps;
  457. }
  458.  
  459. int InitWideDoubleDashedEllipses(xp, p, reps)
  460.     XParms  xp;
  461.     Parms   p;
  462.     int     reps;
  463. {
  464.     int        size;
  465.     XGCValues   gcv;
  466.     char    dashes[2];
  467.  
  468.     (void)InitWideEllipses(xp, p, reps);
  469.     size = p->special;
  470.     size = (size + 9) / 10;
  471.  
  472.     /* Modify GCs to draw dashed */
  473.     dashes[0] = 2*size;   dashes[1] = 2*size;
  474.     gcv.line_style = LineDoubleDash;
  475.     XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  476.     XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  477.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  478.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  479.     return reps;
  480. }
  481.  
  482. void DoArcs(xp, p, reps)
  483.     XParms  xp;
  484.     Parms   p;
  485.     int     reps;
  486. {
  487.     int i;
  488.  
  489.     for (i = 0; i != reps; i++) {
  490.         XDrawArcs(xp->d, xp->w, pgc, arcs, p->objects);
  491.         if (pgc == xp->bggc)
  492.             pgc = xp->fggc;
  493.         else
  494.             pgc = xp->bggc;
  495.     }
  496. }
  497.  
  498. void DoFilledArcs(xp, p, reps)
  499.     XParms  xp;
  500.     Parms   p;
  501.     int     reps;
  502. {
  503.     int i;
  504.  
  505.     for (i = 0; i != reps; i++) {
  506.         XFillArcs(xp->d, xp->w, pgc, arcs, p->objects);
  507.         if (pgc == xp->bggc)
  508.             pgc = xp->fggc;
  509.         else
  510.             pgc = xp->bggc;
  511.     }
  512. }
  513.  
  514. void EndArcs(xp, p)
  515.     XParms  xp;
  516.     Parms   p;
  517. {
  518.     free(arcs);
  519. }
  520.  
  521.