/
MaterialChooser.cpp
63 lines (49 loc) · 1.48 KB
/
MaterialChooser.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
#include "MaterialChooser.h"
#include "i18n.h"
#include "texturelib.h"
#include <wx/textctrl.h>
namespace ui
{
MaterialChooser::MaterialChooser(wxWindow* parent, MaterialSelector::TextureFilter filter,
wxTextCtrl* targetEntry)
: wxutil::DeclarationSelectorDialog(decl::Type::Material, _("Choose Material"), "MaterialChooser",
parent),
_targetEntry(targetEntry)
{
auto* selector = new MaterialSelector(this, filter);
selector->signal_selectionChanged().connect(
sigc::mem_fun(*this, &MaterialChooser::shaderSelectionChanged)
);
SetSelector(selector);
}
sigc::signal<void()>& MaterialChooser::signal_shaderChanged()
{
return _shaderChangedSignal;
}
void MaterialChooser::shaderSelectionChanged()
{
if (_targetEntry)
{
_targetEntry->SetValue(GetSelectedDeclName());
}
// Propagate the call up to the client (e.g. SurfaceInspector)
_shaderChangedSignal.emit();
}
int MaterialChooser::ShowModal()
{
std::string initialShader;
if (_targetEntry != nullptr)
{
initialShader = _targetEntry->GetValue();
// Set the cursor of the tree view to the currently selected shader
SetSelectedDeclName(initialShader);
}
auto result = DeclarationSelectorDialog::ShowModal();
if (_targetEntry)
{
_targetEntry->SetValue(result == wxID_OK ? GetSelectedDeclName() : initialShader);
_shaderChangedSignal.emit();
}
return result;
}
} // namespace