]> git.cworth.org Git - vogl/blob - src/vogleditor/vogleditor_statetreematrixitem.cpp
UI: Add a settings file
[vogl] / src / vogleditor / vogleditor_statetreematrixitem.cpp
1 #include "vogleditor_statetreematrixitem.h"
2 #include "vogl_matrix.h"
3
4 vogleditor_stateTreeMatrixRowItem::vogleditor_stateTreeMatrixRowItem(QString name, unsigned int rowIndex, vogleditor_stateTreeItem* parent, const matrix44D& matrix)
5     : vogleditor_stateTreeItem(name, "", parent),
6       m_rowIndex(rowIndex),
7       m_pState(&matrix),
8       m_pDiffBaseState(NULL)
9 {
10     const matrix44D::row_vec& row = matrix.get_row(rowIndex);
11     QString tmp;
12     setValue(tmp.sprintf("%lf, %lf, %lf, %lf", row[0], row[1], row[2], row[3]));
13 }
14
15 bool vogleditor_stateTreeMatrixRowItem::hasChanged() const
16 {
17     if (m_pDiffBaseState == NULL)
18     {
19         return false;
20     }
21
22     const matrix44D::row_vec& curRow = m_pState->get_row(m_rowIndex);
23     const matrix44D::row_vec& baseRow = m_pDiffBaseState->get_row(m_rowIndex);
24     if ((curRow[0] != baseRow[0]) ||
25         (curRow[1] != baseRow[1]) ||
26         (curRow[2] != baseRow[2]) ||
27         (curRow[3] != baseRow[3]))
28     {
29         return true;
30     }
31
32     return false;
33 }
34
35 QString vogleditor_stateTreeMatrixRowItem::getDiffedValue() const
36 {
37     if (m_pDiffBaseState == NULL)
38     {
39         return "";
40     }
41
42     const matrix44D::row_vec& baseRow = m_pDiffBaseState->get_row(m_rowIndex);
43
44     return getValueFromDoubles(baseRow.get_ptr(), 4);
45 }
46
47 vogleditor_stateTreeMatrixItem::vogleditor_stateTreeMatrixItem(QString name, vogleditor_stateTreeItem* parent, const matrix44D& matrix, unsigned int stackIndex)
48     : vogleditor_stateTreeItem(name, "", parent),
49       m_stackIndex(stackIndex),
50       m_pState(&matrix),
51       m_pDiffBaseState(NULL)
52 {
53     { vogleditor_stateTreeMatrixRowItem* pItem = new vogleditor_stateTreeMatrixRowItem("row 0", 0, this, matrix); m_rowItems.push_back(pItem); this->appendChild(pItem); }
54     { vogleditor_stateTreeMatrixRowItem* pItem = new vogleditor_stateTreeMatrixRowItem("row 1", 1, this, matrix); m_rowItems.push_back(pItem); this->appendChild(pItem); }
55     { vogleditor_stateTreeMatrixRowItem* pItem = new vogleditor_stateTreeMatrixRowItem("row 2", 2, this, matrix); m_rowItems.push_back(pItem); this->appendChild(pItem); }
56     { vogleditor_stateTreeMatrixRowItem* pItem = new vogleditor_stateTreeMatrixRowItem("row 3", 3, this, matrix); m_rowItems.push_back(pItem); this->appendChild(pItem); }
57 }
58
59 vogleditor_stateTreeMatrixStackItem::vogleditor_stateTreeMatrixStackItem(QString name, GLenum target, unsigned int index, vogleditor_stateTreeItem* parent, const vogl_matrix_state& state)
60     : vogleditor_stateTreeItem(name, "", parent),
61       m_target(target),
62       m_index(index),
63       m_pState(&state),
64       m_pDiffBaseState(NULL)
65 {
66     uint stack_depth = m_pState->get_matrix_stack_depth(m_target, m_index);
67     for (uint i = 0; i < stack_depth; i++)
68     {
69         QString tmpName;
70         tmpName = tmpName.sprintf("%d", i);
71         if (i == stack_depth - 1) { tmpName = tmpName.append(" (top)"); }
72         if (i == 0) { tmpName = tmpName.append(" (bottom)"); }
73
74         const matrix44D* pMatrix = m_pState->get_matrix(m_target, m_index, i);
75         if (pMatrix != NULL)
76         {
77             vogleditor_stateTreeMatrixItem* pItem = new vogleditor_stateTreeMatrixItem(tmpName, this, *pMatrix, i);
78             m_matrixItems.push_back(pItem);
79             this->appendChild(pItem);
80         }
81     }
82 }