// $Revision: 1.2 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. // TilesView.h #ifndef TaligentSample_TILESVIEW #define TaligentSample_TILESVIEW // Include for Presentation Framework #ifndef Taligent_GUICOMPOUNDDOCUMENT #include #endif // Include for Presentation Framework commands #ifndef Taligent_GUICOMPOUNDDOCUMENTCOMMAND #include #endif // Include for drawing services, TGrafPort #ifndef Taligent_GRAFPORT #include #endif // Include for current selection support #ifndef TaligentSample_TILESSELECTIONS #include "TilesSelections.h" #endif #ifndef TaligentSample_TILESMODEL #include "TilesModel.h" #endif // The view is where all rendering will occur. TTilesView derives from TDocumentComponentView // which provides for view capabilities (DrawContents) and GUIBundle (GetModelReference, // GetPresenterStateReference, etc.). // MMouseEventHandler is mixed in to handle mouse events in the view. class TTilesView : public TDocumentComponentView, public MMouseEventHandler { public: // VersionDeclarationsMacro required because of inheritance from TDocumentComponentView // and MDropAcceptor. VersionDeclarationsMacro (TTilesView); // All classes derived from TDocumentComponentView need to accept // a TGUIBundle* in their constructor,which they pass on to // TDocumentComponentView. The TGUIBundle "ties together" the elements // in a Presentation Framework document. TTilesView (TGUIBundle* b); virtual ~TTilesView (); // MouseDown() will figure out which tile is affected, create a command/ // selection pair and have the document AdoptAndDo() it. virtual bool MouseDown (TMouseDownEvent&); // A convenience function which calls MGUIBundle's GetCurrentModelSelection and // safely downcasts the TModelSelection to a TTilesSelection*. The user should // always check for a 0 pointer after calling this function. const TTilesSelection* GetTilesSelection () const; protected: // HandleAfterConnectionToViewRoot is called by the Framework when the view is added // to the view hierachy. This usually happens just before the view is made // visible. Initialization routines are usually added here. virtual void HandleAfterConnectionToViewRoot (); // HandleBeforeDisconnectionFromViewRoot is called by the Framework when the view is removed // to the view hierachy. This usually happens just before the view is destroyed. // Cleanup routines are usually added here. virtual void HandleBeforeDisconnectionFromViewRoot (); // Draw contents renders the data from the model. This is the primary method // of a content view. The TGrafPort is already clipped to the region which needs // to be redrawn, so DrawContents should re-render the entire view and rely on // the port to do any necessary clipping. virtual void DrawContents (TGrafPort& port) const; // Draw an individual TTile into the port. Hilight the TTile if it is in the current selection. void DrawTile (TGrafPort& port, const TTile* tile, bool inCurrentSelection) const; // Build an array of MGraphics which maps the data in the model (rock, // paper, scissors) to drawable objects for use by DrawContents. void BuildTilesGraphicsMapToModel (); void DestroyTilesGraphicsMapToModel (); protected: TTilesView (); TTilesView (const TTilesView& copy); private: // Used in the VersionDefinitionsMacro enum {kOriginalVersion}; // Used to store the map of MGraphics used for rendering enum {kNumTilesGraphics=3}; MGraphic* fTilesGraphics[kNumTilesGraphics]; }; #endif // TaligentSample_TILESVIEW