home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglw.zip / lines.c < prev    next >
C/C++ Source or Header  |  1997-02-13  |  2KB  |  128 lines

  1. #include "vogl.h"
  2. #include <stdio.h>
  3.  
  4. #define LT_SIZE    11
  5.  
  6. typedef struct l {
  7.     short        n;
  8.     unsigned    ls;
  9.     struct l    *next;
  10. } LT;
  11.  
  12. static LT    *ls_table[LT_SIZE] = { (LT *)0, };
  13.  
  14. /*
  15.  * deflinestyle
  16.  *
  17.  *     Define a line style
  18.  *      There can be 2*166 line styles!
  19.  */
  20. void
  21. deflinestyle(n, ls)
  22.     short        n;
  23.     Linestyle    ls;
  24. {
  25.     LT    *l;
  26.  
  27.     /*
  28.      * If it's already there, then redefine it...
  29.      */
  30.     for (l = ls_table[n % LT_SIZE]; l != (LT *)NULL; l = l->next)
  31.         if (l->n == n) {
  32.             if (n == 0) /* Not allowed  to redefine 0 (0xffff) */
  33.                 verror("vogl: deflinestyle can't redefine 0");
  34.  
  35.             l->ls = ls;
  36.             return;
  37.         }
  38.  
  39.     /*
  40.      * Othersize, we have to add it...
  41.      */
  42.  
  43.     l = (LT *)vallocate(sizeof(LT));
  44.     l->n = n;
  45.     l->ls = ls;
  46.     l->next = ls_table[n % LT_SIZE];
  47.     ls_table[n % LT_SIZE] = l;
  48. }
  49.  
  50. /*
  51.  * setlinestyle
  52.  *
  53.  *    Set the current linestyle...
  54.  */
  55. void
  56. setlinestyle(n)
  57.     short    n;
  58. {
  59.     LT    *l;
  60.     Token    *tok;
  61.  
  62.     if (!vdevice.initialised)
  63.         verror("setlinestyle: vogl not initialised");
  64.  
  65.     if (vdevice.inobject) {
  66.         tok = newtokens(2);
  67.  
  68.         tok[0].i = LINESTYLE;
  69.         tok[1].i = n;
  70.         return;
  71.         }
  72.  
  73.     /*
  74.      * Find it....
  75.      */
  76.     for (l = ls_table[n % LT_SIZE]; l != (LT *)NULL; l = l->next) {
  77.         if (l->n == n) {
  78.             vdevice.attr->a.ls = l->ls;
  79.             (*vdevice.dev.Vsetls)(l->ls);
  80.             return;
  81.         }
  82.     }
  83.  
  84.     verror("vogl: undefined linestyle used.");
  85. }
  86.  
  87. /*
  88.  * linewidth
  89.  *
  90.  *    Set's the line width in pixels if we can....
  91.  */
  92. void
  93. linewidth(w)
  94.     short    w;
  95. {
  96.     Token    *tok;
  97.  
  98.     if (!vdevice.initialised)
  99.         verror("linewidth: vogl not initialised");
  100.  
  101.     if (vdevice.inobject) {
  102.         tok = newtokens(2);
  103.  
  104.         tok[0].i = LINEWIDTH;
  105.         tok[1].i = w;
  106.         return;
  107.         }
  108.  
  109.     vdevice.attr->a.lw = w;
  110.     (*vdevice.dev.Vsetlw)((int)vdevice.attr->a.lw);
  111. }
  112.  
  113. /*
  114.  * linewidthf
  115.  *
  116.  *    The 'float' version of the above. (Used for antialiased lines on
  117.  *    a real SGI, here, we'll just round it to the nearest int and be
  118.  *    the same as linewidth).
  119.  */
  120. void
  121. linewidthf(w)
  122.     float    w;
  123. {
  124.     linewidth((short)(w + 0.5));
  125. }
  126.  
  127.  
  128.