home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch5 / GameBoard.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.7 KB  |  78 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ///////////////////////////////////////////////////////////////
  22. // GameBoard.h: A tic-tac-toe board
  23. ///////////////////////////////////////////////////////////////
  24. #ifndef GAMEBOARD_H
  25. #define GAMEBOARD_H
  26.  
  27. #include <Xm/Xm.h>
  28. #include "UIComponent.h"
  29.  
  30. class TicTacToe;
  31.  
  32. class GameBoard: public UIComponent {
  33.     
  34.   private:
  35.     
  36.     void mark ( int ); // Handle user marking a square
  37.     
  38.     // Callbacks registered with widgets in the grid
  39.     
  40.     static void markCallback ( Widget, XtPointer, XtPointer );
  41.     static void drawXCallback ( Widget, XtPointer, XtPointer );
  42.     static void drawOCallback ( Widget, XtPointer, XtPointer ); 
  43.     
  44.   protected:
  45.     
  46.     Widget     _grid[9];   // 3 X 3 square of buttons
  47.     GC         _gc;
  48.     int        _gridSize;  // Size of each square
  49.     TicTacToe *_game;
  50.     Pixel      _highlightColor;   // Color of border when in 
  51.     // an active square
  52.     Pixel      _noHighlightColor; // Border color of inactive squares
  53.     Dimension  _shadowThickness;  // Default shadow width of a square
  54.     
  55.     // Methods for refreshing the squares and getting input
  56.     
  57.     virtual void drawX ( Widget );
  58.     virtual void drawO ( Widget );
  59.     
  60.     // Override destruction hook, so we can free the GC if needed
  61.     
  62.     void widgetDestroyed();
  63.     
  64.   public:
  65.     
  66.     GameBoard ( Widget, TicTacToe *, char * ); 
  67.     virtual ~GameBoard();
  68.     void highlightSquare ( int square );   // Highlight single square
  69.     void deemphasizeSquare ( int square ); // Fade square to 2D
  70.     void activateSquare ( int square );    // Allow input to square
  71.     void deactivateSquare ( int square );  // Shut off input
  72.     virtual void markO ( int square );     // Put an X in the square
  73.     virtual void markX ( int square );     // Put an O in the square
  74.     void clear();                          // Clear and reset board
  75.     virtual const char *const className() { return "GameBoard"; }
  76. };
  77. #endif
  78.