/
ShaderSelector.h
164 lines (133 loc) · 4.64 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
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
#pragma once
#include <string>
#include <vector>
#include <memory>
#include "wxutil/GLWidget.h"
#include "wxutil/dataview/TreeView.h"
#include "wxutil/dataview/DeclarationTreeView.h"
#include "wxutil/menu/PopupMenu.h"
#include <wx/panel.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, an OpenGL widget 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").
*
* The client class has to derive from the abstract ShaderSelector::Client class
* providing an interface to allow the update of the info liststore.
*
* For convenience purposes, this class provides two static members that
* allow populating the infostore widget with common lightshader/shader information.
*
*/
class ShaderSelector :
public wxPanel
{
public:
// Derive from this class to update the info widget
class Client
{
public:
/// destructor
virtual ~Client() {}
/** greebo: This gets invoked upon selection changed to allow the client
* class to display custom information in the selector's liststore.
*/
virtual void shaderSelectionChanged(const std::string& shader, wxutil::TreeModel& listStore) = 0;
};
struct ShaderTreeColumns :
public wxutil::TreeModel::ColumnRecord
{
ShaderTreeColumns() :
iconAndName(add(wxutil::TreeModel::Column::IconText)),
shaderName(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column iconAndName;
wxutil::TreeModel::Column shaderName;
};
private:
wxutil::DeclarationTreeView::Columns _shaderTreeColumns;
wxutil::DeclarationTreeView* _treeView;
// GL preview widget
wxutil::GLWidget* _glWidget;
// The client of this class.
Client* _client;
// TRUE, if the first light layers are to be rendered instead of the editorimages
bool _isLightTexture;
struct InfoStoreColumns :
public wxutil::TreeModel::ColumnRecord
{
InfoStoreColumns() :
attribute(add(wxutil::TreeModel::Column::String)),
value(add(wxutil::TreeModel::Column::String))
{}
wxutil::TreeModel::Column attribute;
wxutil::TreeModel::Column value;
};
InfoStoreColumns _infoStoreColumns;
// List store for info table
wxutil::TreeModel::Ptr _infoStore;
public:
// This is where the prefixes are stored (needed to filter the possible shaders)
typedef std::vector<std::string> PrefixList;
PrefixList _prefixes;
/** Constructor.
*
* @client: The client class that gets notified on selection change
* @prefixes: A comma-separated list of shader prefixes.
* @isLightTexture: set this to TRUE to render the light textures instead of the editor images
*/
ShaderSelector(wxWindow* parent, Client* client,
const std::string& prefixes, bool isLightTexture = false);
/** 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();
/** greebo: Static info display function (can be used by other UI classes as well
* to allow code reuse).
*/
static void displayShaderInfo(const MaterialPtr& shader,
wxutil::TreeModel& listStore,
int attrCol = 0, // attribute column number
int valueCol = 1); // value column number
/** greebo: Populates the given listStore with the light shader information.
*/
static void displayLightShaderInfo(const MaterialPtr& shader,
wxutil::TreeModel& listStore,
int attrCol = 0, // attribute column number
int valueCol = 1); // value column number
private:
// Create GUI elements
void createTreeView();
void createPreview();
// Update the info in the table (passes the call to the client class)
void updateInfoTable();
// callbacks
bool onPreviewRender();
void _onSelChange(wxDataViewEvent& ev);
void _onShowShaderDefinition();
};
} // namespace ui