home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-05  |  2.5 KB  |  155 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5.  
  6. #include <applet.h>
  7. #include "cursor.h"
  8.  
  9.  
  10.  
  11. int lastcursor = cursorisdirty;
  12.    
  13. int beachballstate = cursorisbeachball4;
  14.  
  15. int earthstate = cursorisearth7;
  16.  
  17. long ticklastroll = 0;
  18.  
  19.  
  20.  
  21.  
  22. void setcursortype (newcursor) tycursortype newcursor; {
  23.     
  24.     /*
  25.     7/30/90 dmb:  don't assume that cursor is never changed behind your back
  26.     */
  27.     
  28.     register int cursor = newcursor;
  29.     register CursHandle hcursor;
  30.     
  31.     /*
  32.     if (cursor == lastcursor) /*no change%/
  33.         return;
  34.     */
  35.     
  36.     lastcursor = cursor; /*remember for next time*/
  37.     
  38.     if (cursor == cursorisdirty)
  39.         return;
  40.     
  41.     if (cursor == cursorisarrow) {
  42.         
  43.         ticklastroll = 0; /*disable rolling until reinitialized*/
  44.         
  45.         SetCursor (&arrow);
  46.         
  47.         return;
  48.         }
  49.     
  50.     hcursor = GetCursor (cursor);
  51.     
  52.     if (hcursor == nil) /*resource error*/
  53.         return;
  54.     
  55.     SetCursor (*hcursor);
  56.     } /*setcursortype*/
  57.  
  58.  
  59. void obscurecursor (void) {
  60.     
  61.     ObscureCursor ();
  62.     } /*obscurecursor*/
  63.  
  64.  
  65. static boolean rollingtimerexpired (void) {
  66.     
  67.     register long tc;
  68.     
  69.     if (ticklastroll == 0) /*timer hasn't been initted*/
  70.         return (false);
  71.     
  72.     tc = TickCount ();
  73.     
  74.     if ((ticklastroll + 6) > tc) /*a tenth of a second hasn't passed since last bump*/
  75.         return (false);
  76.         
  77.     ticklastroll = tc; /*enough time has passed, reset the timer*/
  78.     
  79.     return (true);
  80.     } /*rollingtimerexpired*/
  81.     
  82.     
  83. void initbeachball (void) {
  84.     
  85.     beachballstate = cursorisbeachball4;
  86.     
  87.     ticklastroll = TickCount ();
  88.     } /*initbeachball*/
  89.     
  90.     
  91. void rollbeachball (void) {
  92.     
  93.     register int state;
  94.     
  95.     if (rollingtimerexpired ()) {
  96.     
  97.         state = beachballstate + 1;
  98.         
  99.         if (state > cursorisbeachball4) /*wrap around*/
  100.             state = cursorisbeachball1;
  101.         
  102.         setcursortype (state);
  103.         
  104.         beachballstate = state;
  105.         }
  106.     } /*rollbeachball*/
  107.  
  108.  
  109. static boolean beachballcursor (void) {
  110.     
  111.     /*
  112.     return true if the cursor is one of the beachballs.
  113.     
  114.     12/26/90 dmb: new test accounts for the fact that, after an initbeachball, 
  115.     lastcursor won't be a beach ball until the timer has expired.  this test 
  116.     will return true if either rolling cursor is active (earth or beach ball)
  117.     */
  118.     
  119.     /*
  120.     return ((lastcursor >= cursorisbeachball1) && (lastcursor <= cursorisbeachball4));
  121.     */
  122.     
  123.     return (ticklastroll != 0);
  124.     } /*beachballcursor*/
  125.  
  126.  
  127. void initearth (void) {
  128.     
  129.     earthstate = cursorisearth1;
  130.     
  131.     ticklastroll = TickCount ();
  132.     } /*initearth*/
  133.  
  134.  
  135. void rollearth (void) {
  136.     
  137.     register int state;
  138.     
  139.     if (rollingtimerexpired ()) {
  140.     
  141.         state = earthstate + 1; 
  142.         
  143.         if (state > cursorisearth7) /*wrap around*/
  144.             state = cursorisearth1;
  145.                         
  146.         setcursortype (state);
  147.         
  148.         earthstate = state;
  149.         }
  150.     } /*rollearth*/
  151.  
  152.  
  153.  
  154.  
  155.