home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / beach.c < prev    next >
Encoding:
Text File  |  1992-09-14  |  3.1 KB  |  110 lines  |  [TEXT/R*ch]

  1. Boolean setupbeachball( void );
  2. void rollbeachball( void );
  3.  
  4. typedef struct {
  5.     short    num_cursors;
  6.     short    tick_interval;
  7.     Cursor    *cursor[];    // in resource, hi word has CURS resource ID
  8. }    acur;
  9.  
  10. /* (c) copyright 1987 Symantec Corporation.  For use with THINK's Lightspeed
  11. C only.
  12.  
  13. You may incorporate these routines in any of your programs, for commercial
  14. distribution or otherwise, but you may not charge for the specific use of
  15. this code.  Symantec Corporation makes no warranty regarding the fitness of
  16. this software for any particular purpose.
  17.  
  18. beach.c -- Simple little program that rolls a "beach ball cursor" while
  19. something important but time-consuming is happening.  Lots of commercial
  20. applications are doing this as a standard way to keep the user comfortable
  21. that the machine hasn't crashed -- that it's still busy doing whatever its
  22. supposed to be doing.
  23.  
  24. Also included is the resource source in beach.r.  There are four cursors with
  25. id's of 256, 257, 258 and 259, representing each of the four possible beach
  26. ball states.
  27.  
  28. To change the rate of rotation, just change the constant "beachrate".
  29.  
  30. To use the beachball in your application, just call "setupbeachball" at the
  31. beginning of your program and add calls to "rollbeachball" in places where
  32. your program is doing a lot of computation, or reading from disk, or
  33. printing, or compiling or whatever...
  34.  
  35. First upload to LVTFORUM -- 1/6/88, by Dave Winer/LVT.
  36. */
  37.  
  38. #define mod        %
  39.  
  40.  
  41. static int beachstate = 1; /*current state of the beachball, varies from 0 to 3*/
  42. static short    beachrate;    /* ticks between frames */
  43. static long tickalarm; /*the time the ball is scheduled to roll again*/
  44. static short    num_cursors;
  45. static acur        **acur_h;
  46.  
  47.  
  48. Boolean setupbeachball ()
  49. {
  50.     /*
  51.     call this routine before your first call to rollbeachball
  52.     */
  53.     
  54.     register short    i;
  55.     register CursHandle cursor;
  56.     register short    curs_id;
  57.     
  58.     tickalarm = TickCount (); /*roll the ball the first time rollbeachball is called*/
  59.     if (acur_h == NIL)    // first time we rolled the ball
  60.     {
  61.         acur_h = (acur **) Get1Resource( 'acur', 128 );
  62.         if (acur_h == NIL)
  63.             return false;
  64.         num_cursors = (**acur_h).num_cursors;
  65.         beachrate = (**acur_h).tick_interval;
  66.         
  67.         for (i = 0; i < num_cursors; i++)
  68.         {
  69.             curs_id = ((long)(**acur_h).cursor[i]) >> 16;
  70.             cursor = GetCursor(curs_id); /*pull it out of the resource file*/
  71.             
  72.             if (cursor == nil) /*error loading the cursor*/
  73.                 return (false);
  74.             
  75.             MoveHHi( (Handle) cursor );
  76.             HLock( (Handle) cursor );
  77.             (**acur_h).cursor[i] = *cursor; /*no error, copy into array*/
  78.         } /*for*/
  79.         
  80.     }
  81.     
  82.     return (true); /*all beachballs loaded correctly*/
  83. } /*setupbeachball*/
  84.     
  85. void
  86. rollbeachball ()
  87. {
  88.     
  89.     /*
  90.     if enough time has elapsed since the last roll, reset the timer and
  91.     roll the beachball into the next state.
  92.     */
  93.     
  94.     register long tc; 
  95.     register Cursor *cursor;
  96.     
  97.     tc = TickCount ();
  98.     
  99.     if (tc < tickalarm) /*not enough time has elapsed since last roll*/
  100.         return;
  101.         
  102.     tickalarm = tc + beachrate; /*time for the next roll*/
  103.     
  104.     beachstate = (beachstate + 1) mod num_cursors; /*advance to next state*/
  105.     
  106.     cursor = (**acur_h).cursor[beachstate]; /*copy from array*/
  107.     
  108.     SetCursor (cursor); /*show the next state*/
  109. } /*rollbeachball*/
  110.