home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / Animator.m < prev    next >
Encoding:
Text File  |  1997-06-20  |  5.4 KB  |  212 lines

  1. //*****************************************************************************
  2. //
  3. //    Animator.m  
  4. //
  5. //        Controls app Icon animation
  6. //
  7. //            by    Felipe A. Rodriguez        
  8. //
  9. //    This code is supplied "as is" the author makes no warranty as to its 
  10. //    suitability for any purpose.  This code is free and may be distributed 
  11. //    in accordance with the terms of the:
  12. //        
  13. //            GNU GENERAL PUBLIC LICENSE
  14. //            Version 2, June 1991
  15. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  16. //             675 Mass Ave, Cambridge, MA 02139, USA
  17. //
  18. //*****************************************************************************
  19.  
  20.  
  21. #import <appkit/appkit.h>
  22.  
  23. #import "Animator.h"
  24. #import "IconView.h"
  25.  
  26.  
  27.         // used in producing timed events
  28. static void Animate();
  29.     static DPSTimedEntry aniTimeTag;
  30.  
  31.  
  32. @implementation Animator
  33.  
  34. //*****************************************************************************
  35. //
  36. //             standard init
  37. //
  38. //*****************************************************************************
  39.  
  40. - init
  41. {
  42. NXRect    appIconFrame;
  43. NXRect    lineViewRect;
  44. id appIcon;
  45.  
  46.     [super init];
  47.                             // setup appIcon for animation
  48.     appIcon = [NXApp appIcon];                    // get appIcon window
  49.     [appIcon getFrame:&appIconFrame];            // get frame rect
  50.     [Window getContentRect:&lineViewRect         // get content view rect appIco
  51.                         forFrameRect:&appIconFrame style:[appIcon style]];
  52.     NX_X(&lineViewRect) = 1;                    // reduce the size and width/ht 
  53.     NX_Y(&lineViewRect) = 1;                    // by a border of 1
  54.     NX_WIDTH(&lineViewRect) -= 1 ;
  55.     NX_HEIGHT(&lineViewRect) -= 1;
  56.     theIconView = [[IconView alloc] initFrame:&lineViewRect];
  57.     [[appIcon contentView] addSubview:theIconView];
  58.             
  59.     imageList = [[List alloc] init];        // produce an array of objects
  60.     [imageList insertObject: [NXImage findImageNamed: "g20"] at: 0];
  61.     [imageList insertObject: [NXImage findImageNamed: "g21"] at: 1];
  62.     [imageList insertObject: [NXImage findImageNamed: "g22"] at: 2];
  63.     [imageList insertObject: [NXImage findImageNamed: "g23"] at: 3];
  64.     [imageList insertObject: [NXImage findImageNamed: "g24"] at: 4];
  65.     [imageList insertObject: [NXImage findImageNamed: "g10"] at: 5];
  66.     [imageList insertObject: [NXImage findImageNamed: "g11"] at: 6];
  67.     [imageList insertObject: [NXImage findImageNamed: "g12"] at: 7];
  68.     [imageList insertObject: [NXImage findImageNamed: "g13"] at: 8];
  69.     [imageList insertObject: [NXImage findImageNamed: "GateKeeper"] at: 9];
  70.  
  71.     return self;
  72. }
  73. //*****************************************************************************
  74. //
  75. //         setup to do open gate anim 
  76. //
  77. //*****************************************************************************
  78.  
  79. - startAnimTimer
  80. {
  81.     if(!aniTimeTag)  
  82.         aniTimeTag = DPSAddTimedEntry(            // register function Animate
  83.             0.2,                                 // to be called every period of         
  84.             (DPSTimedEntryProc)Animate,         // arg0
  85.             (id)self, 
  86.             NX_BASETHRESHOLD);
  87.  
  88.     return self;
  89. }
  90. //*****************************************************************************
  91. //
  92. //         icon animation
  93. //
  94. //*****************************************************************************
  95.  
  96. - _animate
  97. {
  98. static int Index = 0;
  99. static BOOL reverse = NO;
  100.  
  101.     if(standbyGate && Index < 0)         // app running but not dialing
  102.         {
  103.         [self removeTimedEntry];
  104.         Index = 9;
  105.         }
  106.     if(Index < 0)                        // restarted before standby was reached
  107.         {
  108.         reverse = NO;
  109.         Index++;
  110.         }
  111.     if(openGate)                        // app stops dialing
  112.         {
  113.         Index = 4;
  114.         reverse = YES;
  115.         openGate = NO;
  116.         }
  117.     [theIconView setImage:[imageList objectAt:Index]]; 
  118.     if(Index >= 8)
  119.         {
  120.         if(reverse)
  121.             Index = -1;
  122.         else
  123.             Index = 5;
  124.         }
  125.     else
  126.         {
  127.         if(reverse)
  128.             Index--;
  129.         else
  130.             Index++;
  131.         }
  132.             
  133.     return self;
  134. }
  135. //*****************************************************************************
  136. //
  137. //         animate should do open gate icon sequence
  138. //
  139. //*****************************************************************************
  140.  
  141. - setOpenGate:(BOOL)doSeq
  142. {
  143.     openGate = doSeq;
  144.         
  145.     return self;
  146. }
  147. //*****************************************************************************
  148. //
  149. //         animate should do open standby icon seq
  150. //
  151. //*****************************************************************************
  152.  
  153. - setStandbyGate:(BOOL)doSeq
  154. {
  155.     standbyGate = doSeq;
  156.         
  157.     return self;
  158. }
  159. //*****************************************************************************
  160. //
  161. //         remove the timed entry when connection is made or we exit
  162. //
  163. //*****************************************************************************
  164.  
  165. - removeTimedEntry
  166. {
  167.     if (aniTimeTag)  
  168.         DPSRemoveTimedEntry (aniTimeTag);
  169.     aniTimeTag = 0;
  170.         
  171.     return self;
  172. }
  173. //*****************************************************************************
  174. //
  175. //         return the app icon view 
  176. //
  177. //*****************************************************************************
  178.  
  179. - iconView
  180. {
  181.     return theIconView;
  182. }
  183. //*****************************************************************************
  184. //
  185. //     free simply gets rid of everything we created
  186. //     This is how nice objects clean up.
  187. //
  188. //*****************************************************************************
  189.  
  190. - free
  191. {
  192.     if(imageList)
  193.         [imageList free];
  194.  
  195.     return [super free];
  196. }
  197.  
  198. @end
  199.  
  200. //*****************************************************************************
  201. //
  202. //        This fucntion is registered by DPSaddtimedentry.
  203. //        It is subsequently called every period t as registered  
  204. //        in arg 0 of DPSaddtimedentry.
  205. //
  206. //*****************************************************************************
  207.  
  208. static void Animate(DPSTimedEntry time_tag, double now, id self)
  209. {
  210.     [self _animate];
  211. }
  212.