/
MaterialEditor.h
189 lines (156 loc) · 6.49 KB
/
MaterialEditor.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once
#include <sigc++/connection.h>
#include "icommandsystem.h"
#include "ishaders.h"
#include "wxutil/dialog/DialogBase.h"
#include "wxutil/WindowPosition.h"
#include "wxutil/PanedPosition.h"
#include "wxutil/XmlResourceBasedWidget.h"
#include "MaterialPreview.h"
#include "wxutil/SourceView.h"
#include "../MaterialTreeView.h"
#include "Binding.h"
namespace ui
{
class MaterialEditor :
public wxutil::DialogBase,
private wxutil::XmlResourceBasedWidget
{
private:
MaterialTreeView* _treeView;
wxDataViewItem _selectedMaterialItem;
wxutil::TreeModel::Ptr _stageList;
wxutil::TreeView* _stageView;
wxBitmap _iconVisible;
wxBitmap _iconInvisible;
std::multimap<int, std::pair<wxWindow*, wxString>> _notebookPages;
wxutil::WindowPosition _windowPosition;
wxutil::PanedPosition _panedPosition;
std::unique_ptr<MaterialPreview> _preview;
wxutil::D3MaterialSourceViewCtrl* _sourceView;
MaterialPtr _material;
sigc::connection _materialChanged;
std::set<std::shared_ptr<Binding<MaterialPtr>>> _materialBindings;
std::set<std::shared_ptr<Binding<IShaderLayer::Ptr>>> _stageBindings;
std::map<Material::DeformType, wxPanel*> _deformPanels;
struct StageProgramColumns :
public wxutil::TreeModel::ColumnRecord
{
StageProgramColumns() :
type(add(wxutil::TreeModel::Column::String)),
index(add(wxutil::TreeModel::Column::String)),
expression(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column type;
wxutil::TreeModel::Column index;
wxutil::TreeModel::Column expression;
};
struct StageTransformColumns :
public wxutil::TreeModel::ColumnRecord
{
StageTransformColumns() :
type(add(wxutil::TreeModel::Column::String)),
index(add(wxutil::TreeModel::Column::String)),
expression1(add(wxutil::TreeModel::Column::String)),
expression2(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column type;
wxutil::TreeModel::Column index;
wxutil::TreeModel::Column expression1;
wxutil::TreeModel::Column expression2;
};
StageProgramColumns _stageProgramColumns;
wxutil::TreeModel::Ptr _stageProgramParameters;
StageTransformColumns _stageTransformationColumns;
wxutil::TreeModel::Ptr _stageTransformations;
wxutil::TreeView* _stageTransformView;
bool _stageUpdateInProgress;
bool _materialUpdateInProgress;
private:
MaterialEditor();
~MaterialEditor();
int ShowModal() override;
public:
static void ShowDialog(const cmd::ArgumentList& args);
void _onClose(wxCommandEvent& ev);
private:
void setupMaterialTreeView();
void setupMaterialStageView();
void setupMaterialStageProperties();
void setupMaterialProperties();
void setupMaterialSurfaceFlags();
void setupMaterialShaderFlags();
void setupMaterialLightFlags();
void setupMaterialDeformPage();
void setupSurfaceFlag(const std::string& controlName, Material::SurfaceFlags flag);
void setupMaterialFlag(const std::string& controlName, Material::Flags flag);
void setupStageFlag(const std::string& controlName, IShaderLayer::Flags flags);
void createExpressionBinding(const std::string& textCtrlName,
const std::function<shaders::IShaderExpression::Ptr(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>& saveFunc);
void createRadioButtonBinding(const std::string& ctrlName,
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc);
void createSpinCtrlBinding(const std::string& ctrlName,
const std::function<int(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, int)>& saveFunc);
void createSpinCtrlDoubleBinding(const std::string& ctrlName,
const std::function<double(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, double)>& saveFunc);
void updateControlsFromMaterial();
void updateDeformControlsFromMaterial();
void updateStageListFromMaterial();
void updateMaterialPropertiesFromMaterial();
void selectStageByIndex(std::size_t index);
void selectMaterial(const MaterialPtr& material);
IShaderLayer::Ptr getSelectedStage();
IEditableShaderLayer::Ptr getEditableStageForSelection();
void updateStageControls();
void updateStageBlendControls();
void updateStageTextureControls();
void updateStageProgramControls();
void updateStageTransformControls();
void updateStageColoredStatus();
void updateNameOfSelectedStage();
void moveStagePosition(int direction);
void updateStageButtonSensitivity();
void updateSettingsNotebook();
void updateMaterialControlSensitivity();
void updateSourceView();
void updateMaterialTreeItem();
void updateMaterialNameControl();
void handleMaterialSelectionChange();
bool isAllowedToChangeMaterial();
bool askUserAboutModifiedMaterial();
bool saveCurrentMaterial();
void revertCurrentMaterial();
void _onMaterialSelectionChanged(wxDataViewEvent& ev);
void _onNewMaterial(wxCommandEvent& ev);
void _onSaveMaterial(wxCommandEvent& ev);
void _onCopyMaterial(wxCommandEvent& ev);
void _onRevertMaterial(wxCommandEvent& ev);
void _onStageListSelectionChanged(wxDataViewEvent& ev);
void _onStageListItemActivated(wxDataViewEvent& ev);
void _onMaterialTypeChoice(wxCommandEvent& ev);
void _onAddStageTransform(wxCommandEvent& ev);
void _onRemoveStageTransform(wxCommandEvent& ev);
void _onStageTransformEdited(wxDataViewEvent& ev);
void _onStageColoredChecked(const IEditableShaderLayer::Ptr& layer, bool newValue);
void _onStageMapTypeChanged(wxCommandEvent& ev);
void _onStageBlendTypeChanged(wxCommandEvent& ev);
void _onAddStage(wxCommandEvent& ev);
void _onRemoveStage(wxCommandEvent& ev);
void _onToggleStage(wxCommandEvent& ev);
void _onDuplicateStage(wxCommandEvent& ev);
void _onSortRequestChanged(wxCommandEvent& ev);
void toggleSelectedStage();
void onMaterialChanged();
void convertTextCtrlToMapExpressionEntry(const std::string& ctrlName);
// Shortcut
template<typename ObjectClass>
ObjectClass* getControl(const std::string& name)
{
return findNamedObject<ObjectClass>(this, name);
}
};
}