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

  1. #include <stdio.h>
  2. #include "vogl.h"
  3.  
  4. static    Astack    *asfree = (Astack *)NULL;
  5.  
  6. /*
  7.  * copyattributes
  8.  *
  9.  *    Copies attribute stack entries from b to a
  10.  */
  11. static    void
  12. copyattributes(a, b)
  13.     Attribute    *a, *b;
  14. {
  15.     a->color = b->color;
  16.     a->fontnum = b->fontnum;
  17.     a->ls = b->ls;
  18.     a->lw = b->lw;
  19.     a->backface = b->backface;
  20. }
  21.  
  22. /*
  23.  * pushattributes
  24.  *
  25.  * save the current attributes on the matrix stack
  26.  *
  27.  */
  28. void
  29. pushattributes()
  30. {
  31.     Astack    *nattr;
  32.     Token    *p;
  33.  
  34.     if (!vdevice.initialised)
  35.         verror("pushattributes:  vogl not initialised");
  36.     
  37.     if (vdevice.inobject) {
  38.         p = newtokens(1);
  39.  
  40.         p[0].i = PUSHATTRIBUTES;
  41.  
  42.         return;
  43.     }
  44.  
  45.     if (asfree != (Astack *)NULL) {
  46.         nattr = vdevice.attr;
  47.         vdevice.attr = asfree;
  48.         asfree = asfree->back;
  49.         vdevice.attr->back = nattr;
  50.         copyattributes(&vdevice.attr->a, &nattr->a);
  51.     } else {    
  52.         nattr = (Astack *)vallocate(sizeof(Astack));
  53.         nattr->back = vdevice.attr;
  54.         copyattributes(&nattr->a, &vdevice.attr->a);
  55.         vdevice.attr = nattr;
  56.     }
  57. }
  58.  
  59. /*
  60.  * popattributes
  61.  *
  62.  * pop the top entry on the attribute stack 
  63.  *
  64.  */
  65. void
  66. popattributes()
  67. {
  68.     Astack    *nattr;
  69.     Token    *p;
  70.  
  71.     if (!vdevice.initialised)
  72.         verror("popattributes: vogl not initialised");
  73.     
  74.     if (vdevice.inobject) {
  75.         p = newtokens(1);
  76.  
  77.         p[0].i = POPATTRIBUTES;
  78.  
  79.         return;
  80.     }
  81.  
  82.     if (vdevice.attr->back == (Astack *)NULL) 
  83.         verror("popattributes: attribute stack is empty");
  84.     else {
  85.         font(vdevice.attr->back->a.fontnum);
  86.         nattr = vdevice.attr;
  87.         vdevice.attr = vdevice.attr->back;
  88.         nattr->back = asfree;
  89.         asfree = nattr;
  90.     }
  91.  
  92.     (*vdevice.dev.Vsetls)(vdevice.attr->a.ls);
  93.     (*vdevice.dev.Vsetlw)(vdevice.attr->a.lw);
  94.  
  95.     color(vdevice.attr->a.color);
  96. }
  97.