// $Revision: 1.2 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. // TilesModel.h // Define the USE_ARCHIVES symbol if you with to use archived menus // instead of menus created programmatically. The difference between // the archives-version and the non-archives version be seen by examining // the ifdef'ed sections of code in TilesPresenter.* //#define USE_ARCHIVES #ifndef TaligentSample_TILESMODEL #define TaligentSample_TILESMODEL #include // Include for embedder classes #ifndef Taligent_GUICOMPOUNDDOCUMENTEMBEDDER #include #endif // Include file for the Presentation Framework #ifndef Taligent_GUICOMPOUNDDOCUMENT #include #endif typedef short TileIndex; // A TTile can be either kRock, kPaper or kScissors and has an associated color, // position and size. class TTile { public: // The following macro must be called within class declarations in order to use Taligent // Type Extensions.The macro defines a set of Taligent Type Extension utility functions. // This macro call matches a macro call to TaligentTypeExtensionMacro in TilesModel.C TaligentTypeExtensionDeclarationsMacro( TTile ) enum EType {kRock, kPaper, kScissors}; TTile (EType, TRGBColor, TGPoint position, TGPoint size); // TTile is TaligentTypeExtension so default and copy constructors must be // written as well as assignment and streaming operators. TTile (); TTile (const TTile ©); virtual ~TTile (); TTile& operator= (const TTile& rhs); virtual TStream& operator>>= (TStream& towhere) const; virtual TStream& operator<<= (TStream& fromwhere); // Careful use of const for all Get... functions EType GetType () const; void SetType (EType type); TRGBColor GetColor () const; void SetColor (TRGBColor color); TGPoint GetPosition () const; void SetPosition (const TGPoint& point); TGPoint GetSize () const; void SetSize (const TGPoint& size); bool ContainsPoint (const TGPoint&) const; private: // Used for versioning during streaming enum {kOriginalVersion}; EType fType; TRGBColor fColor; // fBounds stores both position and size TGRect fBounds; }; // The TTilesModel will contain a set of three TTiles. TTilesModel is derived from // TModel and contains a data representation which should be independent of the visual // presentation. class TTilesModel : public TGUIEmbedderModel { public: // All TModel's should include the following delcaration macro. // This macro declares TaligentTypeExtension and DynamicCast functions. // This macro call matches the ModelDefinitionsMacro in TilesModel.C ModelDeclarationsMacro(TTilesModel); // TModel is TaligentTypeExtension so default and copy constructors must be // written as well as assignment and streaming operators. TTilesModel (); TTilesModel (const TTilesModel ©); virtual ~TTilesModel (); // Streaming operators stream out/in a full representation of the model. // These methods are called automatically by the Framework to store and // retrieve models. >>= operators should provide version stamping // of the data so that <<= operators can convert from older versions. virtual TStream& operator>>= (TStream& towhere) const; virtual TStream& operator<<= (TStream& fromwhere); // Create a default selection. The returned selection can then be used // to select the whole model, part of it or none of it. virtual TModelSelection* CreateSelection () const; // Get the number of tiles in the model. TileIndex GetNumTiles () const; // Get a tile data for reading, used by view for rendering. Made const // so clients call call this function when the model is read-only locked. const TTile* GetTileForReading (TileIndex whichTile) const; // Get a tile data for writing, used by selections to modify the model. // A client cannot call non-const methods when the model is read-only locked. TTile* GetTileForWriting (TileIndex whichTile); // Adopt a TTile into the model. Responsibility for the TTile is taken from the // caller and the TileIndex is returned to the caller by which the caller can get // back to the TTile. The Taligent convention of calling the function AdoptSomething, // passing a pointer, and naming it somethingToAdopt is followed. TileIndex AdoptTile (TTile* tileToAdopt); // Orphan a TTile from the model. Return a pointer to the TTile for which the // caller now has responsibility. The Taligent convention of calling the function // OrphanSomething and returning a pointer is followed. TTile* OrphanTile (TileIndex index); private: // Used for versioning during streaming enum {kOriginalVersion, kVersionTwo}; // The TTiles are stored in a growable array TArrayOf fTiles; // Place operator= in private section to prevent it from being called. TTilesModel& operator= (const TTilesModel& model) {return *this;} }; #endif // TaligentSample_TILESMODEL