]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreeitem.h
Initial vogl checkin
[vogl] / src / vogleditor / vogleditor_statetreeitem.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef VOGLEDITOR_STATETREEITEM_H
27 #define VOGLEDITOR_STATETREEITEM_H
28
29 #include <QList>
30 #include <QVariant>
31
32 #include "vogl_context_info.h"
33
34 class vogl_state_vector;
35 class vogleditor_QStateTreeModel;
36
37 class vogleditor_stateTreeItem
38 {
39 public:
40     // Constructor for the root node
41     vogleditor_stateTreeItem(QList<QVariant> columnTitles, vogleditor_QStateTreeModel* pModel);
42
43     // Constructor for other nodes
44     vogleditor_stateTreeItem(QString name, QString value, vogleditor_stateTreeItem* parent);
45
46     virtual ~vogleditor_stateTreeItem();
47
48     vogleditor_stateTreeItem* parent() const;
49
50     void setValue(QString value);
51
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)); }
57
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;
65
66     void appendChild(vogleditor_stateTreeItem* pChild);
67
68     int childCount() const;
69
70     vogleditor_stateTreeItem* child(int index) const;
71
72     int columnCount() const;
73
74     QVariant columnData(int column, int role) const;
75
76     int row() const;
77
78     virtual bool hasChanged() const;
79
80     virtual QString getDiffedValue() const { return ""; }
81
82     virtual void wasEdited(bool bEdited) { m_bWasEdited = bEdited; }
83     virtual bool wasEdited() const { return m_bWasEdited; }
84
85     typedef enum {
86         cDEFAULT,
87         cTEXTURE,
88         cSHADER,
89         cPROGRAM,
90         cFRAMEBUFFER
91     } state_tree_type;
92
93     virtual vogleditor_stateTreeItem::state_tree_type getStateType() const { return cDEFAULT; }
94
95 protected:
96     QList<vogleditor_stateTreeItem*> m_childItems;
97     QList<QVariant> m_columnData;
98     vogleditor_stateTreeItem* m_parentItem;
99     vogleditor_QStateTreeModel* m_pModel;
100     bool m_bWasEdited;
101
102     static QString enum_to_string(GLenum id)
103     {
104         static QString tmp;
105         tmp = g_gl_enums.find_name(id);
106         if (tmp.isNull() || tmp.isEmpty())
107         {
108            tmp = tmp.sprintf("0x%04x", id);
109         }
110         return tmp;
111     }
112
113     static QString int_to_string(int value)
114     {
115         static QString tmp;
116         return tmp.sprintf("%d", value);
117     }
118
119     static QString int64_to_string(int64_t value)
120     {
121         static QString tmp;
122         return tmp.sprintf("%" PRIu64, value);
123     }
124
125 };
126
127 class vogleditor_stateTreeStateVecDiffableItem : public vogleditor_stateTreeItem
128 {
129 public:
130     vogleditor_stateTreeStateVecDiffableItem(QString name, QString value, vogleditor_stateTreeItem* parent)
131         : vogleditor_stateTreeItem(name, value, parent),
132           m_pDiffBaseState(NULL)
133     {
134     }
135
136     virtual void set_diff_base_state(const vogl_state_vector* pBaseState)
137     {
138         m_pDiffBaseState = pBaseState;
139     }
140
141 protected:
142     const vogl_state_vector* m_pDiffBaseState;
143 };
144
145
146 template <typename T>
147 class vogleditor_stateTreeDatatypeItem : public vogleditor_stateTreeStateVecDiffableItem
148 {
149 public:
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; }
152
153    virtual bool hasChanged() const;
154
155    virtual QString getDiffedValue() const;
156
157 protected:
158    GLenum m_name;
159    unsigned int m_index;
160    unsigned int m_numComponents;
161    bool m_isIndexed;
162    const vogl_state_vector* m_pStateVec;
163 };
164
165 class vogleditor_stateTreeStateVecBoolItem : public vogleditor_stateTreeDatatypeItem<bool>
166 {
167 public:
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() {}
171
172     virtual QString getDiffedValue() const;
173 };
174
175 class vogleditor_stateTreeStateVecIntItem : public vogleditor_stateTreeDatatypeItem<int>
176 {
177 public:
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() {}
180
181    virtual QString getDiffedValue() const;
182 };
183
184 class vogleditor_stateTreeStateVecFloatItem : public vogleditor_stateTreeDatatypeItem<float>
185 {
186 public:
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() {}
189
190    virtual QString getDiffedValue() const;
191 };
192
193 class vogleditor_stateTreeStateVecEnumItem : public vogleditor_stateTreeDatatypeItem<int>
194 {
195 public:
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() {}
198
199    virtual QString getDiffedValue() const;
200 };
201
202 class vogleditor_stateTreeStateVecPtrItem : public vogleditor_stateTreeDatatypeItem<int>
203 {
204 public:
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() {}
207
208    virtual QString getDiffedValue() const;
209 };
210
211 class vogleditor_stateTreeStateVecMatrixRowItem: public vogleditor_stateTreeStateVecDiffableItem
212 {
213 public:
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);
215
216     virtual ~vogleditor_stateTreeStateVecMatrixRowItem()
217     {
218         m_pState = NULL;
219     }
220
221     virtual bool hasChanged() const;
222
223     virtual QString getDiffedValue() const;
224
225 private:
226     GLenum m_name;
227     unsigned int m_index;
228     unsigned int m_numComponents;
229     bool m_isIndexed;
230     const vogl_state_vector* m_pState;
231     unsigned int m_rowIndex;
232 };
233
234 class vogleditor_stateTreeStateVecMatrixItem: public vogleditor_stateTreeStateVecDiffableItem
235 {
236 public:
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);
238
239     virtual ~vogleditor_stateTreeStateVecMatrixItem()
240     {
241         m_pState = NULL;
242         m_pDiffBaseState = NULL;
243     }
244
245    virtual void set_diff_base_state(const vogl_state_vector* pBaseState)
246     {
247         m_pDiffBaseState = pBaseState;
248
249         for (vogleditor_stateTreeStateVecMatrixRowItem** iter = m_rowItems.begin(); iter != m_rowItems.end(); iter++)
250         {
251             (*iter)->set_diff_base_state(pBaseState);
252         }
253     }
254
255 private:
256     const vogl_state_vector* m_pState;
257     vogl::vector<vogleditor_stateTreeStateVecMatrixRowItem*> m_rowItems;
258 };
259
260 #endif // VOGLEDITOR_STATETREEITEM_H