home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / dr.str / Source / RecentADT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-13  |  3.7 KB  |  175 lines  |  [TEXT/KAHL]

  1. /***************************
  2.   Slide ADT Implementation
  3.  ***************************/
  4.  
  5. #include "StrangeGlove.h"
  6. #include "Glove.h"
  7. #include "RecentADT.h"
  8.  
  9. #define TOP            12
  10. #define LEFT        10
  11.  
  12. extern WindowPtr    gADTWindow;
  13. extern Boolean        gShowADT, gUpdateSlide;
  14.  
  15. static RecentType    mySlide;
  16.  
  17. /***** InitRecent *****/
  18. void InitRecent()
  19. {
  20.     int i;
  21.     i = 0;
  22.     while (i < RECENTLENGTH)
  23.     {
  24.         mySlide.Items[i] = 0;
  25.         i++;
  26.     }
  27.     mySlide.Front = 0;
  28. }
  29.  
  30.  
  31. /***** AddToRecent *****/
  32. void AddToRecent(char newItem)
  33. {
  34.     mySlide.Items[mySlide.Front] = newItem;
  35.     mySlide.Front = ((mySlide.Front + 1) % RECENTLENGTH);
  36.     gUpdateSlide = TRUE;
  37. }
  38.  
  39.  
  40. /***** RecentToGlove *****/
  41. void RecentToGlove(GloveState *s)
  42. {
  43.     int        start;
  44.     short    fingers;
  45.     
  46.     /* Set start to position of flag, '\xA0' */
  47.     start = 0;
  48.     while ((start != RECENTLENGTH) && (mySlide.Items[start] != CONT_FLAG))
  49.         start++;
  50.     
  51.     if (start == RECENTLENGTH)                    /* Error- No Start Flag in Slide */
  52.         s->x = 666;
  53.         
  54.     else                                        /* Transfer data to structure */
  55.     {
  56.         s->x = mySlide.Items[(start + 1) % RECENTLENGTH];
  57.         s->y = mySlide.Items[(start + 2) % RECENTLENGTH];
  58.         s->z = mySlide.Items[(start + 3) % RECENTLENGTH];
  59.         s->rot = mySlide.Items[(start + 4) % RECENTLENGTH];
  60.         fingers = mySlide.Items[(start + 5) % RECENTLENGTH];        /* Mask off individual fingers */
  61.         s->thumb = (fingers & THUMB_MASK) >> 6;
  62.         s->index = (fingers & INDEX_MASK) >> 4;
  63.         s->middle = (fingers & MIDDLE_MASK) >> 2;
  64.         s->ring = (fingers & RING_MASK);
  65.         s->buttons = mySlide.Items[(start + 6) % RECENTLENGTH];
  66.     }
  67. }
  68.  
  69.  
  70. /***** OneToGlove *****/
  71. void OneToGlove(GloveState *s)
  72. {
  73.     int        start;
  74.     short    fingers;
  75.     
  76.     start = ((mySlide.Front + 6) % RECENTLENGTH);
  77.     
  78.     s->x = mySlide.Items[(start + 1) % RECENTLENGTH];
  79.     s->y = mySlide.Items[(start + 2) % RECENTLENGTH];
  80.     s->z = mySlide.Items[(start + 3) % RECENTLENGTH];
  81.     s->rot = mySlide.Items[(start + 4) % RECENTLENGTH];
  82.     fingers = mySlide.Items[(start + 5) % RECENTLENGTH];        /* Mask off individual fingers */
  83.     s->thumb = (fingers & THUMB_MASK) >> 6;
  84.     s->index = (fingers & INDEX_MASK) >> 4;
  85.     s->middle = (fingers & MIDDLE_MASK) >> 2;
  86.     s->ring = (fingers & RING_MASK);
  87.     s->buttons = mySlide.Items[(start + 6) % RECENTLENGTH];
  88. }
  89.  
  90.  
  91. /***** DumpRecent *****/
  92. void DumpRecent()
  93. {
  94.     GrafPtr    oldPort;
  95.     int        i, j, width;
  96.     Str255    intString;
  97.     
  98.     GetPort(&oldPort);
  99.     SetPort(gADTWindow);
  100.     TextFont(monaco);
  101.     
  102.     EraseRect(&(gADTWindow->portRect));
  103.     
  104.     for (i = 0; i < 12; i++)
  105.     {
  106.         MoveTo(41 + (i * 35), 0);
  107.         LineTo(41 + (i * 35), 30);
  108.     }
  109.     MoveTo(0, 14);
  110.     LineTo(468, 14);
  111.  
  112.     MoveTo(LEFT, TOP);
  113.     for (i = 0; i < RECENTLENGTH; i++)    /* Draw as Characters */
  114.     {
  115.         DrawChar(' ');
  116.         DrawChar(' ');
  117.         if (CharWidth(mySlide.Items[(mySlide.Front + i) % RECENTLENGTH]) == 0)
  118.             DrawChar(' ');
  119.         else
  120.             DrawChar(mySlide.Items[(mySlide.Front + i) % RECENTLENGTH]);
  121.         DrawChar(' ');
  122.         DrawChar(' ');
  123.     }
  124.     MoveTo(LEFT, TOP+15);                    /* Move to Next Line */
  125.     for (i = 0; i < RECENTLENGTH; i++)        /* Draw as Integers */
  126.     {
  127.         if (mySlide.Items[(mySlide.Front + i) % RECENTLENGTH] >= 0)
  128.         {
  129.             DrawChar(' ');
  130.             NumToString(mySlide.Items[(mySlide.Front + i) % RECENTLENGTH], &intString);
  131.         }
  132.         else
  133.         {
  134.             DrawChar('-');
  135.             NumToString(-(mySlide.Items[(mySlide.Front + i) % RECENTLENGTH]), &intString);
  136.         }
  137.         width = StringWidth(intString);
  138.         for (j = 0; j < ((21 - width) / 7); j++)
  139.             DrawChar('0');
  140.         DrawString(intString);
  141.         DrawChar(' ');
  142.     }
  143.     
  144.     SetPort(oldPort);
  145.     gUpdateSlide = FALSE;
  146. }
  147.  
  148.  
  149. /***** ShowADT *****/
  150. ShowADT()
  151. {
  152.     GrafPtr    oldPort;
  153.     
  154.     GetPort(&oldPort);
  155.     
  156.     SetPort(gADTWindow);
  157.     gShowADT = TRUE;
  158.     ShowWindow(gADTWindow);
  159.     SelectWindow(gADTWindow);
  160.     AdjustWindowMenu();
  161.     
  162.     SetPort(oldPort);
  163. }
  164.  
  165.  
  166. /***** HideADT *****/
  167. HideADT()
  168. {
  169.     gShowADT = FALSE;
  170.     HideWindow(gADTWindow);
  171.     AdjustWindowMenu();
  172. }
  173.  
  174.  
  175.