1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 #ifndef VOGLEDITOR_STATETREEITEM_H
27 #define VOGLEDITOR_STATETREEITEM_H
32 #include "vogl_context_info.h"
34 class vogl_state_vector;
35 class vogleditor_QStateTreeModel;
37 class vogleditor_stateTreeItem
40 // Constructor for the root node
41 vogleditor_stateTreeItem(QList<QVariant> columnTitles, vogleditor_QStateTreeModel* pModel);
43 // Constructor for other nodes
44 vogleditor_stateTreeItem(QString name, QString value, vogleditor_stateTreeItem* parent);
46 virtual ~vogleditor_stateTreeItem();
48 vogleditor_stateTreeItem* parent() const;
50 void setValue(QString value);
52 void setValue(int value) { QString tmp; setValue(tmp.sprintf("%d", value)); }
53 void setValue(uint value) { QString tmp; setValue(tmp.sprintf("%u", value)); }
54 void setValue(bool value) { QString tmp; setValue(tmp.sprintf("%s", value ? "GL_TRUE" :"GL_FALSE")); }
55 void setValue(void* value) { QString tmp; setValue(tmp.sprintf("%p", value)); }
56 void setValue(const char* value) { setValue(QString(value)); }
58 QString getValueFromBools(const bool* values, uint count) const;
59 QString getValueFromInts(const int* values, uint count) const;
60 QString getValueFromUints(const uint* values, uint count) const;
61 QString getValueFromFloats(const float* values, uint count) const;
62 QString getValueFromDoubles(const double* values, uint count) const;
63 QString getValueFromEnums(const int* values, uint count) const;
64 QString getValueFromPtrs(const int* values, uint count) const;
66 void appendChild(vogleditor_stateTreeItem* pChild);
68 int childCount() const;
70 vogleditor_stateTreeItem* child(int index) const;
72 int columnCount() const;
74 QVariant columnData(int column, int role) const;
78 virtual bool hasChanged() const;
80 virtual QString getDiffedValue() const { return ""; }
82 virtual void wasEdited(bool bEdited) { m_bWasEdited = bEdited; }
83 virtual bool wasEdited() const { return m_bWasEdited; }
93 virtual vogleditor_stateTreeItem::state_tree_type getStateType() const { return cDEFAULT; }
96 QList<vogleditor_stateTreeItem*> m_childItems;
97 QList<QVariant> m_columnData;
98 vogleditor_stateTreeItem* m_parentItem;
99 vogleditor_QStateTreeModel* m_pModel;
102 static QString enum_to_string(GLenum id)
105 tmp = g_gl_enums.find_name(id);
106 if (tmp.isNull() || tmp.isEmpty())
108 tmp = tmp.sprintf("0x%04x", id);
113 static QString int_to_string(int value)
116 return tmp.sprintf("%d", value);
119 static QString int64_to_string(int64_t value)
122 return tmp.sprintf("%" PRIu64, value);
127 class vogleditor_stateTreeStateVecDiffableItem : public vogleditor_stateTreeItem
130 vogleditor_stateTreeStateVecDiffableItem(QString name, QString value, vogleditor_stateTreeItem* parent)
131 : vogleditor_stateTreeItem(name, value, parent),
132 m_pDiffBaseState(NULL)
136 virtual void set_diff_base_state(const vogl_state_vector* pBaseState)
138 m_pDiffBaseState = pBaseState;
142 const vogl_state_vector* m_pDiffBaseState;
146 template <typename T>
147 class vogleditor_stateTreeDatatypeItem : public vogleditor_stateTreeStateVecDiffableItem
150 vogleditor_stateTreeDatatypeItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
151 virtual ~vogleditor_stateTreeDatatypeItem() { m_pStateVec = NULL; }
153 virtual bool hasChanged() const;
155 virtual QString getDiffedValue() const;
159 unsigned int m_index;
160 unsigned int m_numComponents;
162 const vogl_state_vector* m_pStateVec;
165 class vogleditor_stateTreeStateVecBoolItem : public vogleditor_stateTreeDatatypeItem<bool>
168 vogleditor_stateTreeStateVecBoolItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, bool* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
169 vogleditor_stateTreeStateVecBoolItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, int* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
170 virtual ~vogleditor_stateTreeStateVecBoolItem() {}
172 virtual QString getDiffedValue() const;
175 class vogleditor_stateTreeStateVecIntItem : public vogleditor_stateTreeDatatypeItem<int>
178 vogleditor_stateTreeStateVecIntItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, int* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
179 virtual ~vogleditor_stateTreeStateVecIntItem() {}
181 virtual QString getDiffedValue() const;
184 class vogleditor_stateTreeStateVecFloatItem : public vogleditor_stateTreeDatatypeItem<float>
187 vogleditor_stateTreeStateVecFloatItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, float* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
188 virtual ~vogleditor_stateTreeStateVecFloatItem() {}
190 virtual QString getDiffedValue() const;
193 class vogleditor_stateTreeStateVecEnumItem : public vogleditor_stateTreeDatatypeItem<int>
196 vogleditor_stateTreeStateVecEnumItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, int* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
197 virtual ~vogleditor_stateTreeStateVecEnumItem() {}
199 virtual QString getDiffedValue() const;
202 class vogleditor_stateTreeStateVecPtrItem : public vogleditor_stateTreeDatatypeItem<int>
205 vogleditor_stateTreeStateVecPtrItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, int* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
206 virtual ~vogleditor_stateTreeStateVecPtrItem() {}
208 virtual QString getDiffedValue() const;
211 class vogleditor_stateTreeStateVecMatrixRowItem: public vogleditor_stateTreeStateVecDiffableItem
214 vogleditor_stateTreeStateVecMatrixRowItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, float* values, unsigned int numComponents, unsigned int rowIndex, bool isIndexed, vogleditor_stateTreeItem* parent);
216 virtual ~vogleditor_stateTreeStateVecMatrixRowItem()
221 virtual bool hasChanged() const;
223 virtual QString getDiffedValue() const;
227 unsigned int m_index;
228 unsigned int m_numComponents;
230 const vogl_state_vector* m_pState;
231 unsigned int m_rowIndex;
234 class vogleditor_stateTreeStateVecMatrixItem: public vogleditor_stateTreeStateVecDiffableItem
237 vogleditor_stateTreeStateVecMatrixItem(QString glenumName, GLenum name, unsigned int index, const vogl_state_vector& stateVec, float* values, unsigned int numComponents, bool isIndexed, vogleditor_stateTreeItem* parent);
239 virtual ~vogleditor_stateTreeStateVecMatrixItem()
242 m_pDiffBaseState = NULL;
245 virtual void set_diff_base_state(const vogl_state_vector* pBaseState)
247 m_pDiffBaseState = pBaseState;
249 for (vogleditor_stateTreeStateVecMatrixRowItem** iter = m_rowItems.begin(); iter != m_rowItems.end(); iter++)
251 (*iter)->set_diff_base_state(pBaseState);
256 const vogl_state_vector* m_pState;
257 vogl::vector<vogleditor_stateTreeStateVecMatrixRowItem*> m_rowItems;
260 #endif // VOGLEDITOR_STATETREEITEM_H