/
MaterialThumbnailBrowser.h
264 lines (200 loc) · 7.92 KB
/
MaterialThumbnailBrowser.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#pragma once
#include "wxutil/FreezePointer.h"
#include <sigc++/connection.h>
#include "texturelib.h"
#include "wxutil/menu/PopupMenu.h"
#include "registry/CachedKey.h"
#include "TextureBrowserManager.h"
#include "wxutil/DockablePanel.h"
#include "wxutil/event/SingleIdleCallback.h"
namespace wxutil
{
class NonModalEntry;
class GLWidget;
}
class wxScrollBar;
class wxScrollEvent;
class wxToolBar;
namespace ui
{
constexpr const char* const RKEY_TEXTURES_HIDE_UNUSED = "user/ui/textures/browser/hideUnused";
constexpr const char* const RKEY_TEXTURES_SHOW_FAVOURITES_ONLY = "user/ui/textures/browser/showFavouritesOnly";
constexpr const char* const RKEY_TEXTURES_SHOW_OTHER_MATERIALS = "user/ui/textures/browser/showOtherMaterials";
constexpr const char* const RKEY_TEXTURES_SHOW_NAMES = "user/ui/textures/browser/showNames";
constexpr const char* const RKEY_TEXTURE_UNIFORM_SIZE = "user/ui/textures/browser/uniformSize";
constexpr const char* const RKEY_TEXTURE_USE_UNIFORM_SCALE = "user/ui/textures/browser/useUniformScale";
constexpr const char* const RKEY_TEXTURE_SCALE = "user/ui/textures/browser/textureScale";
constexpr const char* const RKEY_TEXTURE_SHOW_SCROLLBAR = "user/ui/textures/browser/showScrollBar";
constexpr const char* const RKEY_TEXTURE_MOUSE_WHEEL_INCR = "user/ui/textures/browser/mouseWheelIncrement";
constexpr const char* const RKEY_TEXTURE_SHOW_FILTER = "user/ui/textures/browser/showFilter";
constexpr const char* const RKEY_TEXTURE_CONTEXTMENU_EPSILON = "user/ui/textures/browser/contextMenuMouseEpsilon";
constexpr const char* const RKEY_TEXTURE_MAX_NAME_LENGTH = "user/ui/textures/browser/maxShadernameLength";
/**
* \brief Widget for rendering active textures as tiles in a scrollable
* container.
*
* Uses an OpenGL widget to render a rectangular view into a "virtual space"
* containing all active texture tiles.
*/
class TextureBrowser :
public wxutil::DockablePanel,
public sigc::trackable,
public wxutil::SingleIdleCallback
{
class TextureTile;
typedef std::list<TextureTile> TextureTiles;
TextureTiles _tiles;
// Size of the 2D viewport. This is the geometry of the render window, not
// the entire virtual space.
Vector2i _viewportSize;
// Y origin of the virtual space with respect to the current viewport.
// Starts at zero, then becomes more negative as the view is scrolled
// downwards.
int _viewportOriginY;
// Height of the entire virtual space of texture tiles. This changes when
// textures are added or removed.
int _entireSpaceHeight;
std::string _shader;
// The coordinates of the point where the mouse button was pressed
// this is used to check whether the mouse button release is a mouse-drag
// or a contextmenu open command.
int _popupX;
int _popupY;
int _startOrigin;
// The maximum distance the mouse pointer may move and still let the context menu
// pop up on mouse button release
double _epsilon;
wxutil::PopupMenuPtr _popupMenu;
wxMenuItem* _seekInMediaBrowser;
wxMenuItem* _shaderLabel;
wxutil::NonModalEntry* _filter;
bool _filterIgnoresTexturePath;
bool _filterIsIncremental;
wxutil::GLWidget* _wxGLWidget;
wxScrollBar* _scrollbar;
bool _heightChanged;
bool _originInvalid;
wxutil::FreezePointer _freezePointer;
// the increment step we use against the wheel mouse
std::size_t _mouseWheelScrollIncrement;
bool _showTextureFilter;
// make the texture increments match the grid changes
bool _showTextureScrollbar;
// if true, the texture window will only display in-use shaders
// if false, all the shaders in memory are displayed
bool _hideUnused;
bool _showFavouritesOnly;
registry::CachedKey<bool> _showNamesKey;
int _textureScale;
bool _useUniformScale;
// Cached set of material favourites
std::set<std::string> _favourites;
// Whether materials not starting with "textures/" should be visible
bool _showOtherMaterials;
// The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
int _uniformTextureSize;
unsigned int _maxNameLength;
wxToolBar* _textureToolbar;
// renderable items will be updated next round
bool _updateNeeded;
sigc::connection _favouritesChangedHandler;
public:
TextureBrowser(wxWindow* parent);
~TextureBrowser() override;
// Schedules an update of the renderable items
void queueUpdate();
void queueDraw();
/** greebo: Returns the currently selected shader
*/
const std::string& getSelectedShader() const;
/** greebo: Sets the currently selected shader to <newShader> and
* refocuses the texturebrowser to that shader.
*/
void setSelectedShader(const std::string& newShader);
protected:
void onIdle() override;
void onPanelActivated() override;
void onPanelDeactivated() override;
private:
void connectListeners();
void disconnectListeners();
private:
void clearFilter();
int getViewportHeight();
// Callback needed for DeferredAdjustment
void scrollChanged(double value);
// Actually updates the renderable items (usually done before rendering)
void performUpdate();
// This gets called by the ShaderSystem
void onActiveShadersChanged();
// Return the display width/height of a texture in the texture browser
int getTextureWidth(const Texture& tex) const;
int getTextureHeight(const Texture& tex) const;
// Get a new position for the given texture, and advance the CurrentPosition
// state object.
class CurrentPosition;
Vector2i getPositionForTexture(CurrentPosition& layout,
const Texture& texture) const;
bool checkSeekInMediaBrowser(); // sensitivity check
void onSeekInMediaBrowser();
// Displays the context menu
void openContextMenu();
void observeKey(const std::string& key);
void keyChanged();
void loadScaleFromRegistry();
void onFavouritesChanged();
/** greebo: The actual drawing method invoking the GL calls.
*/
void draw();
/** greebo: Performs the actual window movement after a mouse scroll.
*/
void doMouseWheel(bool wheelUp);
void updateScroll();
/** greebo: Returns the currently active filter string or "" if
* the filter is not active.
*/
std::string getFilter();
/**
* Callback run when filter text was changed.
*/
void filterChanged();
/** greebo: Sets the focus of the texture browser to the shader
* with the given name.
*/
void focus(const std::string& name);
/** greebo: Returns the total height of the GL content
*/
int getTotalHeight();
void clampOriginY();
int getOriginY();
void setOriginY(int newOriginY);
/**
* greebo: Returns the shader at the given coords.
* The coords are window coords, not the virtual coords
* which span the entire scrollable area.
* @returns: the MaterialPtr, which may be empty.
*/
MaterialPtr getShaderAtCoords(int x, int y);
/** greebo: Tries to select the shader at the given coords.
* When successful, this applies the shader to the
* current selection.
*/
void selectTextureAt(int mx, int my);
/** greebo: Returns true if the given material is visible,
* taking filter and showUnused into account.
*/
bool materialIsVisible(const MaterialPtr& material);
// wx callbacks
bool onRender();
void onScrollChanged(wxScrollEvent& ev);
void onGLResize(wxSizeEvent& ev);
void onGLMouseScroll(wxMouseEvent& ev);
void onGLMouseButtonPress(wxMouseEvent& ev);
void onGLMouseButtonRelease(wxMouseEvent& ev);
// Called when moving the mouse with the RMB held down (used for scrolling)
void onFrozenMouseMotion(int x, int y, unsigned int state);
void onFrozenMouseCaptureLost();
};
} // namespace ui
// Accessor method to the singleton instance
ui::TextureBrowserManager& GlobalTextureBrowser();