home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / pointer_430.lzh / Pointer / test.c < prev    next >
C/C++ Source or Header  |  1991-01-11  |  4KB  |  156 lines

  1. /**************************************
  2. *  TEST.C  08/05/90
  3. *  Written by Timm Martin
  4. *  This source code is public domain.
  5. ***************************************/
  6.  
  7. #include <exec/types.h>
  8. #include <functions.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include "zz_pointer.h"
  12.  
  13. /********************
  14. *  SHARED VARIABLES
  15. *********************/
  16.  
  17. struct IntuitionBase *IntuitionBase = NULL;
  18. struct Window        *win           = NULL;
  19.  
  20. /************************
  21. *  NEW WINDOW STRUCTURE
  22. *************************/
  23.  
  24. struct NewWindow new_window =
  25. {
  26.   /* SHORT           LeftEdge    */ 0,
  27.   /* SHORT           TopEdge     */ 0,
  28.   /* SHORT           Width       */ 640,
  29.   /* SHORT           Height      */ 160,
  30.   /* UBYTE           DetailPen   */ 0,
  31.   /* UBYTE           BlockPen    */ 1,
  32.   /* ULONG           IDCMPFlags  */ CLOSEWINDOW|MOUSEBUTTONS,
  33.   /* ULONG           Flags       */ ACTIVATE|NOCAREREFRESH|SIMPLE_REFRESH|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING,
  34.   /* struct Gadget * FirstGadget */ NULL,
  35.   /* struct Image *  CheckMark   */ NULL,
  36.   /* UBYTE *         Title       */ (STRPTR)"Pointer Test Program -- click in the window!",
  37.   /* struct Screen * Screen      */ NULL,
  38.   /* struct BitMap * BitMap      */ NULL,
  39.   /* SHORT           MinWidth    */ 230,
  40.   /* SHORT           MinHeight   */ 20,
  41.   /* USHORT          MaxWidth    */ 640,
  42.   /* USHORT          MaxHeight   */ 200,
  43.   /* USHORT          Type        */ WBENCHSCREEN,
  44. };
  45.  
  46. /*************
  47. *  FUNCTIONS
  48. **************/
  49.  
  50. void main( void );
  51. void program_end( void );
  52. void program_begin( void );
  53. void window_input( void );
  54.  
  55. /***********
  56. *  M A I N
  57. ************/
  58.  
  59. void main( void )
  60. {
  61.   program_begin();
  62.   window_input();
  63.   program_end();
  64. }
  65.  
  66. /*****************
  67. *  PROGRAM BEGIN
  68. ******************/
  69.  
  70. /*
  71. This procedure opens the Intuition library, the window, and the pointer.
  72. If any of these things fail, the program ends.
  73. */
  74.  
  75. void program_begin( void )
  76. {
  77.   if (!(IntuitionBase = (struct IntuitionBase *)
  78.                         OpenLibrary( "intuition.library", 0L )) ||
  79.       !(win = OpenWindow( &new_window )) ||
  80.       !zz_pointer_open())
  81.     program_end();
  82. }
  83.  
  84. /***************
  85. *  PROGRAM END
  86. ****************/
  87.  
  88. /*
  89. This procedure closes the pointer, the window, and the Intuition
  90. library.
  91. */
  92.  
  93. void program_end( void )
  94. {
  95.   zz_pointer_close();
  96.  
  97.   if (win)           CloseWindow( win );
  98.   if (IntuitionBase) CloseLibrary( IntuitionBase );
  99. }
  100.  
  101. /****************
  102. *  WINDOW INPUT
  103. *****************/
  104.  
  105. /*
  106. This procedure monitors for window input.  It returns when the user clicks on
  107. the window close gadget.
  108. */
  109.  
  110. void window_input( void )
  111. {
  112.   BOOL finished;
  113.   struct IntuiMessage *imessage;
  114.   BOOL pointer;
  115.  
  116.   finished = pointer = FALSE;
  117.   while (!finished)
  118.   {
  119.     /* wait for input from the window and the timer device */
  120.     Wait( 1L<<win->UserPort->mp_SigBit );
  121.  
  122.     /* for each window input message */
  123.     while (imessage = (struct IntuiMessage *)GetMsg( win->UserPort ))
  124.     {
  125.       switch (imessage->Class)
  126.       {
  127.         case CLOSEWINDOW:
  128.           /* end the program */
  129.           finished = TRUE;
  130.           break;
  131.         case MOUSEBUTTONS:
  132.           /* if clicked down the left mouse button */
  133.           if (imessage->Code == SELECTDOWN)
  134.           {
  135.             /* if the ZZ pointer is currently visible */
  136.             if (pointer)
  137.             {
  138.               /* clear it */
  139.               CLEAR_POINTER( win );
  140.               pointer = FALSE;
  141.             }
  142.             else
  143.             {
  144.               /* else display it */
  145.               ZZ_POINTER( win );
  146.               pointer = TRUE;
  147.             }
  148.           }
  149.           break;
  150.       }
  151.       /* reply to the message to free its memory */
  152.       ReplyMsg( (struct Message *)imessage );
  153.     }
  154.   }
  155. }
  156.