AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzUIGrid.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_UI_GRID_H_)
00015 #define _CCZ_UI_GRID_H_
00016 
00017 #include "CzActor.h"
00018 #include "CzScene.h"
00019 #include "CzUIBase.h"
00020 #include "CzTemplates.h"
00021 #include "CzHashes.h"
00022 
00023 /**
00024  @struct    CzUIGridColumn
00025 
00026  @brief A grid column.
00027 
00028  */
00029 
00030 struct CzUIGridColumn
00031 {
00032     CzString            Name;                   ///< Name of column
00033     int                 OriginalWidth;          ///< Original width of column
00034     int                 Width;                  ///< Current width of column
00035     eCzAlignH           Align;                  ///< Column actor alignment
00036     bool                Visible;                ///< Column visibility
00037     CzTemplate*         ItemsTemplate;          ///< Items template used to instantiate grid column items
00038     CzXomlVariableArray* ItemsData;             ///< Bound data array
00039     unsigned int        ItemsTargetTypeHash;        ///< Target item type hash
00040     int                 ItemCount;              ///< Number of items in column
00041 public:
00042 
00043     CzUIGridColumn(const char* name, int width, eCzAlignH align, bool visible)
00044     {
00045         Name = name;
00046         Width = width;
00047         Align = align;
00048         Visible = visible;
00049         ItemsTemplate = NULL;
00050         ItemsData = NULL;
00051         ItemsTargetTypeHash = 0;
00052         ItemCount = 0;
00053     }
00054 };
00055 
00056 /**
00057  @struct    CzUIGridRow
00058 
00059  @brief A grid row.
00060 
00061  */
00062 
00063 struct CzUIGridRow
00064 {
00065     CzString            Name;                   ///< Name of row
00066     int                 OriginalHeight;         ///< Original height of row
00067     int                 Height;                 ///< Current height of row
00068     eCzAlignV           Align;                  ///< Row actor alignment
00069     bool                Visible;                ///< Row visibility
00070 
00071     CzUIGridRow(const char* name, int height, eCzAlignV align, bool visible)
00072     {
00073         Name = name;
00074         Height = height;
00075         Align = align;
00076         Visible = visible;
00077     }
00078 };
00079 
00080 /**
00081  @class CzUIGrid
00082 
00083  @brief An image based actor that acts as a grid, allowing other actors to be arranged into a grid.
00084 
00085  */
00086 
00087 class CzUIGrid : public CzUIBase
00088 {
00089     // Properties
00090 protected:
00091     int                         RowCount;               // Number of rows
00092     int                         ColumnCount;            // Number of columns
00093     CzVector<CzUIGridColumn*>   ColumnDefinitions;      // Definition of columns
00094     CzVector<CzUIGridRow*>      RowDefinitions;         // Definition of rows
00095     CzTemplate*                 ItemsTemplate;          // Items template used to instantiate grid actor items
00096     CzXomlVariableArray*        ItemsData;              // Bound data array
00097     unsigned int                ItemsTargetTypeHash;        // Target item type hash
00098     bool                        MultiSelect;            // If true then multiple selections are allowed
00099     CzUIBase*                   Selection;              // Last selections actor
00100     int                         SelectionIndex;         // Last selection index
00101     CzXomlVariable*             SelectionVar;           // Variable that is updated with the current selection index
00102 public:
00103     int                         getRowCount() const                     { return RowCount; }
00104     int                         getColumnCount() const                  { return ColumnCount; }
00105     CzUIGridColumn*             AddColumn(const char* name, int width, eCzAlignH align, bool visible);
00106     CzUIGridRow*                AddRow(const char* name, int height, eCzAlignV align, bool visible);
00107     CzUIGridRow*                getRow(int index)                       { if (index < 0 || index >= RowCount) return NULL; else return RowDefinitions[index]; }
00108     CzUIGridColumn*             getColumn(int index)                    { if (index < 0 || index >= ColumnCount) return NULL; else return ColumnDefinitions[index]; }
00109     void                        setRowVisible(int index, bool visible);
00110     bool                        isRowVisible(int index) const;
00111     void                        setColumnVisible(int index, bool visible);
00112     bool                        isColumnVisible(int index) const;
00113     void                        setAllVisible(bool visible);
00114     CzTemplate*                 getItemsTemplate() const                { return ItemsTemplate; }
00115     bool                        setItemsTemplate(const char* temp_name);
00116     bool                        setItemsTemplate(CzTemplate* temp);
00117     bool                        setItemsData(const char* variable_name, CzXmlNode* node = NULL);
00118     void                        setItemsData(CzXomlVariableArray* data, unsigned int  type_hash);
00119     bool                        setItemsData(CzXomlVariable* data);
00120     CzXomlVariableArray*        getItemsData()                          { return ItemsData; }
00121     void                        setItemsTargetType(const char* type);
00122     unsigned int                setItemsTargetType() const              { return ItemsTargetTypeHash; }
00123     void                        setMultiSelect(bool enable)             { MultiSelect = enable; }
00124     bool                        isMultiSelect() const                   { return MultiSelect; }
00125     void                        setSelectionIndex(int index);
00126     int                         getSelectionIndex() const               { return SelectionIndex; }
00127     CzUIBase*                   getSelection()                          { return Selection; }
00128     void                        setSelectionVar(CzXomlVariable* var) { SelectionVar = var; }
00129     bool                        setProperty(unsigned int property_name, const CzXomlProperty& data, bool delta);
00130     bool                        setProperty(unsigned int property_name, const CzString& data, bool delta);
00131     bool                        getProperty(unsigned int property_name, CzXomlProperty& prop);
00132     // Properties end
00133 protected:
00134     CzSlotArray<CzUIBase*>      Children;                                           // Collection of actors that are linked to this panel
00135     void                        LinkChanged(CzActor* child, bool remove);           // Links a new actor into the grid
00136     void                        RemoveActor(CzActor* actor);                        // Removes the specified actor from the grid
00137     void                        RemoveAllActors();                                  // Removes and destroys all actiors in the grid
00138     void                        CreateAllActors();                                  // Re-creates all actors within the grid from a template
00139     void                        UpdateAllActors(bool force_update);                 // Moves data from the bound items data array to the actors
00140     void                        RemoveColumnActors(int column);                     // Removes all grid actors in a column
00141     void                        CreateColumnActors(int column);                     // Creates the grid actors for a column
00142     void                        CreateAllColumnActors();                            // Creates the grid actors for all columns
00143     void                        UpdateColumnActors(int column, bool force_update);  // Moves data from the bound column items data array to the column actors
00144     void                        UpdateAllColumnActors(bool force_update);           // Updates all grid column actors
00145     bool                        UpdateLayout();                                     // Updates the layout of the child items
00146     void                        CheckForColumnChanges();
00147     bool                        UpdateBinding(unsigned int property_name, CzXomlVariable* var);
00148 
00149 public:
00150     CzUIGrid() : CzUIBase(), RowCount(0), ColumnCount(0), ItemsData(NULL), ItemsTemplate(NULL), ItemsTargetTypeHash(0), MultiSelect(false), SelectionIndex(-1), Selection(NULL), SelectionVar(NULL)
00151                                 { setActualClassType("grid"); ReceiveEventFromChild = true; }
00152     virtual ~CzUIGrid();
00153 
00154     virtual void                InitGrid(int row_count, int column_count);
00155     bool                        Update(float dt);
00156 
00157     // Event handlers
00158     void                        NotifyOrientationChange(CzScene::eOrientation old_orientation, CzScene::eOrientation new_orientation);
00159     virtual void                NotifySelectionChanged(int old_index, int new_index);
00160 
00161     // Implementation of IzXomlClass interface
00162     int                         LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node);
00163 
00164     // Implementation of IzAnimTarget interface
00165     bool                        UpdateFromAnimation(CzAnimInstance *animation);
00166 
00167     // Utility
00168     void                        ClearAllSelections(CzUIBase* ignore);
00169 
00170     // Internal (used by XOML system to setup and cleanup the XOML class properties system
00171 protected:
00172     static CzXomlClassDef*  UIGridClassDef;                             // XOML class definition
00173 
00174 public:
00175     static void             InitClass();
00176     static void             ReleaseClass();
00177 
00178     static CzXomlProperty   _getColumnCount(IzXomlResource* target);
00179     static CzXomlProperty   _getRowCount(IzXomlResource* target);
00180     static bool             _setItemsTemplate(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00181     static CzXomlProperty   _getItemsTemplate(IzXomlResource* target);
00182     static bool             _setItemsData(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00183     static CzXomlProperty   _getItemsData(IzXomlResource* target);
00184     static bool             _setItemsTargetType(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00185     static bool             _setOnSelectionChanged(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00186     static bool             _setMultiSelect(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00187     static CzXomlProperty   _getMultiSelect(IzXomlResource* target);
00188     static CzXomlProperty   _getSelection(IzXomlResource* target);
00189     static bool             _setSelectionIndex(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00190     static CzXomlProperty   _getSelectionIndex(IzXomlResource* target);
00191     static bool             _setShowRow(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00192     static bool             _setShowColumn(IzXomlResource* target, const CzXomlProperty& prop, bool add);
00193 
00194 };
00195 /**
00196  @class CzUIGridCreator
00197 
00198  @brief Creates an instance of a grid actor object.
00199 
00200  Used by the XOML system to instantiate a CzUIGrid object.
00201 
00202  */
00203 
00204 class CzUIGridCreator : public IzXomlClassCreator
00205 {
00206 public:
00207     CzUIGridCreator()
00208     {
00209         setClassName("grid");
00210     }
00211     IzXomlResource* CreateInstance(IzXomlResource* parent)  { return new CzUIGrid(); }
00212 };
00213 
00214 
00215 
00216 #endif  // _CCZ_UI_GRID_H_