/
ShaderSelector.h
88 lines (70 loc) · 2.23 KB
/
ShaderSelector.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
#pragma once
#include <string>
#include <vector>
#include <memory>
#include "wxutil/dataview/DeclarationTreeView.h"
#include <wx/panel.h>
#include "TexturePreviewCombo.h"
// FORWARD DECLS
class Material;
typedef std::shared_ptr<Material> MaterialPtr;
class wxDataViewCtrl;
namespace ui
{
/**
* A widget that allows the selection of a shader. The widget contains
* three elements - a tree view displaying available shaders as
* identified by the specified prefixes, a TexturePreviewComob displaying a
* preview of the currently-selected shader and a table containing certain
* information about the shader.
*
* Use the wxWindow* operator to incorporate this class into a dialog window.
*
* This widget populates its list of shaders automatically, and offers a method
* that allows calling code to retrieve the user's selection. The set of
* displayed textures can be defined by passing a list of texture prefixes to
* the constructor (comma-separated, e.g. "fog,light").
*/
class ShaderSelector :
public wxPanel
{
public:
enum class TextureFilter
{
Regular, // prefix: "textures/"
Lights, // prefix: light/, fog/
};
private:
wxutil::DeclarationTreeView::Columns _shaderTreeColumns;
wxutil::DeclarationTreeView* _treeView;
TextureFilter _textureFilter;
std::function<void()> _selectionChanged;
TexturePreviewCombo* _previewCombo;
public:
/** Constructor.
*
* @selectionChanged: Functor invoked when the tree view selection changes.
* @prefixes: A comma-separated list of shader prefixes.
*/
ShaderSelector(wxWindow* parent, const std::function<void()>& selectionChanged, TextureFilter filter);
/** Return the shader selected by the user, or an empty string if there
* was no selection.
*/
std::string getSelection();
/** Set the given shader name as the current selection, highlighting it
* in the tree view.
*
* @param selection
* The fullname of the shader to select, or the empty string if there
* should be no selection.
*/
void setSelection(const std::string& selection);
// Get the selected Material
MaterialPtr getSelectedShader();
private:
// Create GUI elements
void createTreeView();
void createPreview();
void _onSelChange(wxDataViewEvent& ev);
};
} // namespace ui