home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / clock.zip / CLKIMGH.C < prev    next >
Text File  |  1987-01-03  |  5KB  |  171 lines

  1. /***************************************************** CLKIMGH.C
  2.  * NAME:    CLKIMGH
  3.  *
  4.  * FUNCTION:    Images hands for clock program.
  5.  *
  6.  * EXAMPLE:    clkimgh (pointr, handnb)
  7.  *
  8.  * INPUTS:    type    name    description
  9.  *        pointer    pointr    points to output structure
  10.  *        int    handnb    hand number ("minute")
  11.  *
  12.  * OUTPUT:    type    name    description
  13.  *        struct.    ---    array of dots (see structure ACTIMAGE)
  14.  *
  15.  ****************************************************************
  16.  * 12/04/86 -RBM- original implementation
  17.  * 12/13/86 -RBM- converted to "ACTIMAGE" handef table
  18.  * 12/20/86 -RBM- converted to singlelinewidth handef table
  19.  ****************************************************************/
  20.  
  21. #define XTRNALGLOBALS 1    /* globals defined externally    */
  22. #include "E:CLKGBL.H"        /* setup global storage        */
  23. #include "E:CLKHN2.H"        /* include hands definition    */
  24.  
  25. /****************************************************************
  26.  * BEGIN ROUTINE
  27.  ****************************************************************/
  28.  
  29. clkimgh (pointr, handnb)
  30.  
  31. struct    ACTIMAGE *pointr;    /* pointer to hand image structure    */
  32. int    handnb;            /* hand number (0 - 59)            */
  33.  
  34. {
  35. int    hstart;            /* entry in hand image table to start    */
  36. int    hstop;            /* entry in hand image table to stop    */
  37. int    hoct;            /* this hand's octant indicator        */
  38. int    hentr;            /* this hand's entry in "handef" table    */
  39. int    hwidth;            /* this hand's width            */
  40.  
  41. int    tblidx;            /* index into handef table        */
  42.  
  43. int    rowlocater;        /* used to locate center of clock    */
  44. int    collocater;        /* used to locate center of clock    */
  45. int    shifter;        /* shift row/col start by this much    */
  46.  
  47. /*--- get hand's octant & entry from "handqud" table ------------*/
  48. hoct  = hanqud[handnb].qoc;    /* get "octant"     indicator    */
  49. hentr = hanqud[handnb].qhe;    /* get entry in "handef" table    */
  50.  
  51. /*--- determine "start", "stop" entries in handef table ---*/
  52. tblidx = hentr * HANDSZ;    /* point to first entry in handef    */
  53.  
  54. if      ((pointr == &acbhr) || (pointr == &acdhr))
  55.     { /* we are doing the hour hand */
  56.     hstart = tblidx + handef[(tblidx+HANDSZ-7)].row;
  57.     hstop  = tblidx + handef[(tblidx+HANDSZ-7)].col;
  58.     hwidth = hrwth;
  59.     }
  60. else if ((pointr == &acbmn) || (pointr == &acdmn))
  61.     { /* we are doing the minute hand */
  62.     hstart = tblidx + handef[(tblidx+HANDSZ-6)].row;
  63.     hstop  = tblidx + handef[(tblidx+HANDSZ-6)].col;
  64.     hwidth = mnwth;
  65.     }
  66. else if ((pointr == &acbsc) || (pointr == &acdsc))
  67.     { /* we are doing the second hand */
  68.     hstart = tblidx + handef[(tblidx+HANDSZ-5)].row;
  69.     hstop  = tblidx + handef[(tblidx+HANDSZ-5)].col;
  70.     hwidth = scwth;
  71.     }
  72. else    
  73.     { /* must be doing clock face */
  74.     hstart = tblidx + handef[(tblidx+HANDSZ-8)].row;
  75.     hstop  = tblidx + handef[(tblidx+HANDSZ-8)].col;
  76.     hwidth = fcwth;
  77.     };
  78.  
  79. rowlocater = cntrow - CENTR;    /* compute center shifter    */
  80. collocater = cntcol - CENTC;    /* compute center shifter    */
  81. shifter = hwidth/2;        /* account for hand's width    */
  82.  
  83. /* --- build hand image ----------------------------------------*/
  84.  
  85. /*DEBUG printf ("<CLKIMGH>hentr=%5d hstart=%5d hstop=%5d tblidx=%5d\n",
  86.                             hentr,    hstart,    hstop,    tblidx);
  87. */
  88. tblidx = hstart;
  89. while (tblidx <= hstop)
  90.     {
  91.  
  92.     if (tblidx >= hstart)    /* see if building image yet        */
  93.     {
  94.     switch (hoct)    /*--- image build based on octant  -------------*/
  95.         {
  96.         case OCT1 : /* --- first octant ---*/
  97.             {
  98.             pointr->row = handef[tblidx].row;
  99.             pointr->col = handef[tblidx].col - shifter;
  100.             pointr->wth = hwidth;
  101.             break;
  102.             };
  103.         case OCT2 : /* --- second octant ---*/
  104.             {
  105.             pointr->row = (260 - handef[tblidx].col) + shifter - hwidth;
  106.             pointr->col = 260 - handef[tblidx].row;
  107.             pointr->wth = -hwidth;
  108.             break;
  109.             };
  110.         case OCT3 : /* --- third octant ---*/
  111.             {
  112.             pointr->row = handef[tblidx].col - 60 - shifter;
  113.             pointr->col = 260 - handef[tblidx].row;
  114.             pointr->wth = -hwidth;
  115.             break;
  116.             };
  117.         case OCT4 : /* --- fourth octant ---*/
  118.             {
  119.             pointr->row = 200 - handef[tblidx].row;
  120.             pointr->col = handef[tblidx].col - shifter;
  121.             pointr->wth = hwidth;
  122.             break;
  123.             };
  124.         case OCT5 : /* --- fifth octant ---*/
  125.             {
  126.             pointr->row = 200 - handef[tblidx].row;
  127.             pointr->col = (320 - handef[tblidx].col) + shifter - hwidth;
  128.             pointr->wth = hwidth;
  129.             break;
  130.             };
  131.         case OCT6 : /* --- sixth octant ---*/
  132.             {
  133.             pointr->row = handef[tblidx].col - 60 - shifter;
  134.             pointr->col = 60 + handef[tblidx].row;
  135.             pointr->wth = - hwidth;
  136.             break;
  137.             };
  138.         case OCT7 : /* --- seventh octant ---*/
  139.             {
  140.             pointr->row = (260 - handef[tblidx].col) + shifter - hwidth;
  141.             pointr->col = 60 + handef[tblidx].row;
  142.             pointr->wth = - hwidth;
  143.             break;
  144.             };
  145.         case OCT8 : /* --- eighth octant ---*/
  146.             {
  147.             pointr->row = handef[tblidx].row;
  148.             pointr->col = (320 - handef[tblidx].col) + shifter - hwidth;
  149.             pointr->wth = hwidth;
  150.             break;
  151.             };
  152.  
  153.  
  154.  
  155.         };
  156.  
  157.     pointr->row += rowlocater;    /* adjust location        */
  158.     pointr->col += collocater;    /* adjust location        */
  159.     pointr++;
  160.     };
  161.  
  162.     tblidx++;            /* point to next entry            */
  163.     };
  164.  
  165. /*--- save last row/col/width in image table ---*/
  166. pointr->row = 0;
  167. pointr->col = 0;
  168. pointr->wth = 0;
  169.  
  170. }                /*--- end of routine ---*/
  171.