home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / CSpinner / CSpinner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-02  |  3.2 KB  |  67 lines  |  [TEXT/CWIE]

  1. #pragma once
  2.  
  3. // The CSpinner class lets you spin the mouse cursor using a VBL task. It compiles for 68K and PowerPC, yet it uses no dirty tricks.
  4. // Author: François Pottier (pottier@clipper.ens.fr)
  5. // Release: November 2, 1995
  6. // This code may be used freely. Please drop me a note in email if you find bugs, possible enhancements, or just to say you like it.
  7.  
  8. // View this file as Geneva 9pt on a 17" monitor for best appearance.
  9.  
  10. // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  11.  
  12. // The code was written for CW7. It uses PowerPlant's macros for exception handling, but is otherwise independent from PowerPlant.
  13. // Here is how this class is typically used:
  14. //
  15. //    void MyLengthyTask (void)
  16. //    {
  17. //        CSpinner            theSpinner(myAcurID);                                                        // Create a stack-based object
  18. //        theSpinner.Spin();                                                                            // Start the VBL task
  19. //        
  20. //        // ... execute your gnarly lengthy task, which is allowed to raise exceptions ...
  21. //        
  22. //        theSpinner.Stop();                                                                            // Stop the VBL task
  23. //    }
  24.  
  25. // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  26. // Layout of the 'acur' resource.
  27.  
  28. #pragma options align=mac68k
  29. struct SAcurRec {
  30.     short                itsFrameCount;
  31.     short                itsCurrentFrame;
  32.     CursHandle            itsFrame[1];                                                                // This array is in fact variable-sized
  33. };
  34. #pragma options align=reset
  35.  
  36. typedef SAcurRec* SAcurPtr;
  37. typedef SAcurPtr* SAcurHandle;
  38.  
  39. // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  40. // The VBL task has different calling conventions on the PowerPC and on 68K. Happily, it is possible to keep things relatively simple thanks to the compiler's register directive.
  41.  
  42. #ifdef __powerc
  43. #define    VBLTASKPROTOTYPE        static void MyTask (VBLTaskPtr inTaskPtr)
  44. #else
  45. #define    VBLTASKPROTOTYPE        static pascal void MyTask (register VBLTaskPtr inTaskPtr : __A0)
  46. #endif
  47.  
  48. // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  49. // If you want to add virtual members to this class, BEWARE: the address of mTask should be the address of the whole object. The VBL task relies on this trick.
  50.  
  51. class CSpinner {
  52. private:
  53.     VBLTask                mTask;                                                                    // IMPORTANT: this must be the first member
  54.     SAcurHandle            mAcurHandle;                                                                // Handle to the cursor array
  55.     short                mTickInterval;                                                                // Time interval between two frames
  56.     Boolean                mTaskInstalled;                                                                // Allows additional sanity checks
  57.     
  58.     friend VBLTASKPROTOTYPE;                                                                        // The VBL task itself has access to the object's private members
  59.  
  60. public:
  61.     CSpinner (short inAcurID);                                                                        // Constructor reads in 'acur' and 'CURS' resources
  62.     ~CSpinner ();                                                                                    // Destructor calls Stop if necessary
  63.     
  64.     void Spin (void);                                                                                // Calls to these two methods should be balanced.
  65.     void Stop (void);
  66. };
  67.