/
MaterialEditor.cpp
132 lines (100 loc) · 3.63 KB
/
MaterialEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "MaterialEditor.h"
#include "i18n.h"
#include <wx/panel.h>
#include <wx/splitter.h>
namespace ui
{
namespace
{
const char* const DIALOG_TITLE = N_("Material Editor");
const std::string RKEY_ROOT = "user/ui/materialEditor/";
const std::string RKEY_SPLIT_POS = RKEY_ROOT + "splitPos";
const std::string RKEY_WINDOW_STATE = RKEY_ROOT + "window";
// Columns for the stages list
struct StageColumns :
public wxutil::TreeModel::ColumnRecord
{
StageColumns() :
name(add(wxutil::TreeModel::Column::String)),
index(add(wxutil::TreeModel::Column::Integer)),
visible(add(wxutil::TreeModel::Column::Boolean))
{}
wxutil::TreeModel::Column name;
wxutil::TreeModel::Column index;
wxutil::TreeModel::Column visible;
};
StageColumns& STAGE_COLS()
{
static StageColumns _i;
return _i;
}
}
MaterialEditor::MaterialEditor() :
DialogBase(DIALOG_TITLE),
_treeView(nullptr),
_stageList(new wxutil::TreeModel(STAGE_COLS(), true)),
_stageView(nullptr)
{
loadNamedPanel(this, "MaterialEditorMainPanel");
makeLabelBold(this, "MaterialEditorDefinitionLabel");
makeLabelBold(this, "MaterialEditorMaterialPropertiesLabel");
makeLabelBold(this, "MaterialEditorMaterialStagesLabel");
makeLabelBold(this, "MaterialEditorStageSettingsLabel");
// Wire up the close button
findNamedObject<wxButton>(this, "MaterialEditorCloseButton")->Bind(wxEVT_BUTTON, &MaterialEditor::_onClose, this);
// Add the treeview
auto* panel = findNamedObject<wxPanel>(this, "MaterialEditorTreeView");
_treeView = new MaterialTreeView(panel);
panel->GetSizer()->Add(_treeView, 1, wxEXPAND);
// Setup the splitter and preview
auto* splitter = findNamedObject<wxSplitterWindow>(this, "MaterialEditorSplitter");
splitter->SetSashPosition(GetSize().GetWidth() * 0.6f);
splitter->SetMinimumPaneSize(10); // disallow unsplitting
// Set up the preview
auto* previewPanel = findNamedObject<wxPanel>(this, "MaterialEditorPreviewPanel");
_preview.reset(new wxutil::ModelPreview(previewPanel));
previewPanel->GetSizer()->Add(_preview->getWidget(), 1, wxEXPAND);
setupMaterialStageView();
// Set the default size of the window
FitToScreen(0.8f, 0.6f);
Layout();
Fit();
// Connect the window position tracker
_windowPosition.loadFromPath(RKEY_WINDOW_STATE);
_windowPosition.connect(this);
_windowPosition.applyPosition();
_panedPosition.connect(splitter);
_panedPosition.loadFromPath(RKEY_SPLIT_POS);
CenterOnParent();
_treeView->Populate();
}
int MaterialEditor::ShowModal()
{
// Restore the position
_windowPosition.applyPosition();
int returnCode = DialogBase::ShowModal();
// Tell the position tracker to save the information
_windowPosition.saveToPath(RKEY_WINDOW_STATE);
return returnCode;
}
void MaterialEditor::_onClose(wxCommandEvent& ev)
{
EndModal(wxID_CLOSE);
}
void MaterialEditor::ShowDialog(const cmd::ArgumentList& args)
{
MaterialEditor* editor = new MaterialEditor;
editor->ShowModal();
editor->Destroy();
}
void MaterialEditor::setupMaterialStageView()
{
// Stage view
auto* panel = findNamedObject<wxPanel>(this, "MaterialEditorStageView");
_stageView = wxutil::TreeView::CreateWithModel(panel, _stageList.get(), wxDV_NO_HEADER);
panel->GetSizer()->Add(_stageView, 1, wxEXPAND);
// Single text column
_stageView->AppendTextColumn(_("Stage"), STAGE_COLS().name.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
}
}