home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / TicTacToe / TicTacToe.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.7 KB  |  120 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. // TicTacToe.C: TicTacToe subsystem that encapsulates all
  23. //              major components of the game.
  24. ///////////////////////////////////////////////////////////////
  25. #include "TicTacToe.h"
  26. #include "GameBoard.h"
  27. #include "Engine.h"
  28. #include "Command.h"
  29. #include "Message.h"
  30. #include <Xm/Form.h>
  31. #include <Xm/Separator.h>
  32.  
  33. TicTacToe::TicTacToe ( Widget parent, char *name ) : UIComponent( name )
  34. {
  35.     // Create the driving engine for the game
  36.     
  37.     _engine = new Engine ( this );
  38.     
  39.     // Create a form to hold all other widgets
  40.     
  41.     _w = XtCreateWidget ( _name, 
  42.              xmFormWidgetClass, 
  43.              parent, NULL, 0 );
  44.     
  45.     installDestroyHandler();
  46.     
  47.     // Separate the commands from the message area
  48.     
  49.     Widget sep = XtCreateManagedWidget ( "commandSeparator", 
  50.                     xmSeparatorWidgetClass, 
  51.                     _w, 
  52.                     NULL, 0 );
  53.     
  54.     // Create the widgets for the UI components
  55.     
  56.     _msgArea     = new Message ( _w, "messages" );
  57.     _commandArea = new Command ( _w, this, "commands" );
  58.     _gameBoard   = new GameBoard ( _w, this, "gameBoard" );
  59.     
  60.     // Set up all constraints
  61.     
  62.     // The GameBoard is attached to the parent XmForm widget
  63.     // on the top and sides; to an XmSeparator on the bottom.
  64.     
  65.     XtVaSetValues ( _gameBoard->baseWidget(), 
  66.            XmNtopAttachment,    XmATTACH_FORM,
  67.            XmNleftAttachment,   XmATTACH_FORM,
  68.            XmNrightAttachment,  XmATTACH_FORM,
  69.            XmNbottomWidget,     sep,
  70.            XmNbottomAttachment, XmATTACH_WIDGET,
  71.            NULL );
  72.     
  73.     // Attach a separator widget to the top of the message area
  74.     
  75.     XtVaSetValues ( sep,
  76.            XmNtopAttachment,    XmATTACH_NONE,
  77.            XmNleftAttachment,   XmATTACH_FORM,
  78.            XmNrightAttachment,  XmATTACH_FORM,
  79.            XmNbottomWidget,     _msgArea->baseWidget(),
  80.            XmNbottomAttachment, XmATTACH_WIDGET,
  81.            NULL );
  82.     
  83.     // Attach the Message component to the separator,
  84.     // and span the width of the Form widget
  85.     
  86.     XtVaSetValues ( _msgArea->baseWidget(),
  87.            XmNtopAttachment,    XmATTACH_NONE,
  88.            XmNleftAttachment,   XmATTACH_FORM,
  89.            XmNrightAttachment,  XmATTACH_FORM,
  90.            XmNbottomWidget,     _commandArea->baseWidget(),
  91.            XmNbottomAttachment, XmATTACH_WIDGET,
  92.            NULL );
  93.     
  94.     // Attach the Command component to the top, left, and right
  95.     // sides of the form, so it floats along the top
  96.     
  97.     XtVaSetValues ( _commandArea->baseWidget(),
  98.            XmNtopAttachment,    XmATTACH_NONE,
  99.            XmNleftAttachment,   XmATTACH_FORM,
  100.            XmNrightAttachment,  XmATTACH_FORM,
  101.            XmNbottomAttachment, XmATTACH_FORM,
  102.            NULL );
  103.     
  104.     // Manage the widgets for all subcomponents, so that managing
  105.     // the TicTacToe base widget displays everything.
  106.     
  107.     _commandArea->manage();
  108.     _gameBoard->manage();
  109.     _msgArea->manage();
  110.     _gameBoard->clear();
  111. }
  112.  
  113. TicTacToe::~TicTacToe()
  114. {
  115.     delete _gameBoard;
  116.     delete _msgArea;
  117.     delete _commandArea;
  118.     delete _engine;
  119. }
  120.