home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Util / After Dark / AD Programming Examples.sit / AD Programming Examples / Programming Examples / Bouncing Ball in C / GraphicsModule_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-03  |  2.5 KB  |  89 lines  |  [TEXT/KAHL]

  1. /*
  2.     GraphicsModule_main.c
  3.     
  4.     Apple and Think C Implementation of 'ADgm' screen saver code resource.
  5.     
  6.     This file provides a generic interface for writing a After Dark™ graphics module.
  7.     The function "main" is called by After Dark and passed four parameters:
  8.     
  9.         storage:    A Handle to memory you have allocated.
  10.         blankRgn:    A region covering all screens.
  11.         message:    A value indicating which function to call.
  12.         params:        A pointer to a structure containing useful information.
  13.         
  14.     To use it, write the five routines:
  15.     
  16.     OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
  17.     OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  18.     OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  19.     OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  20.     OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  21.     
  22.     For more information, consult the programmer's section of the manual.
  23.     
  24.     By Patrick Beard and Bruce Burkhalter and Colin Glassey
  25.     
  26.     ©1989,1990,1991 Berkeley Systems, Inc.
  27.  */
  28.  
  29. #include <QuickDraw.h>
  30. #include "GraphicsModule_Types.h"
  31. #ifdef THINK_C
  32. /* allows use of Global vars with Think C */
  33. #include <SetUpA4.h>
  34. #define OpenGlobals()    RememberA0(); SetUpA4();
  35. #define CloseGlobals()    RestoreA4();
  36. #endif
  37.  
  38. /* entry point into graphics module */
  39.  
  40. pascal OSErr 
  41. main(storage, blankRgn, message, params)
  42. Handle *storage;            /* storage allocated by graphics module. */
  43. RgnHandle blankRgn;            /* region to do all drawing in. */
  44. short message;                /* the action to take */
  45. GMParamBlockPtr params;        /* parameters & services for controlling graphics module */
  46. {
  47.     OSErr err=noErr;
  48.  
  49. #ifdef THINK_C    
  50.     /* set up globals for strings etc. only for THINK C */
  51.     OpenGlobals();
  52. #endif    
  53.     /* dispatch message to appropriate routine. */
  54.     switch(message) {
  55.         case Initialize:
  56.             err=DoInitialize(storage, blankRgn, params);
  57.             break;
  58.         case Close:
  59.             err=DoClose(*storage, blankRgn, params);
  60.             break;
  61.         case Blank:
  62.             err=DoBlank(*storage, blankRgn, params);
  63.             break;
  64.         case DrawFrame:
  65.             err=DoDrawFrame(*storage, blankRgn, params);        
  66.             break;
  67.         
  68.         /*    Bouncing Ball does not handle the next two messages.    */
  69.         
  70.         case ModuleSelected:
  71.             /*err=DoSelected(*storage, blankRgn, params);*/
  72.             break;
  73.         case DoAbout:
  74.             /*err=DoAbout(*storage, blankRgn, params);*/
  75.             break;
  76.  
  77.         default: /* user may have hit a button */
  78.             if(message>=ButtonMessage) {
  79.                 /* handle the button */
  80.                 err=DoSetUp(blankRgn, message, params);
  81.             }  /* end if */
  82.             break;
  83.     } /* end switch */
  84. #ifdef THINK_C        
  85.     CloseGlobals();
  86. #endif    
  87.     return err;
  88. }
  89.