/
TextureDirectoryLoader.h
62 lines (48 loc) · 1.4 KB
/
TextureDirectoryLoader.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
#pragma once
#include "ishaders.h"
#include "wxutil/ModalProgressDialog.h"
#include "EventRateLimiter.h"
#include "i18n.h"
#include "string/predicate.h"
#include "../texturebrowser/TextureBrowserPanel.h"
#include "../texturebrowser/TextureBrowserManager.h"
namespace ui
{
/** Functor object to load all of the textures under the given directory
* path. Loaded textures will then display in the Textures view.
*/
class TextureDirectoryLoader
{
// Directory to search
const std::string _searchDir;
// Modal dialog window to display progress
wxutil::ModalProgressDialog _dialog;
// Event limiter for dialog updates
EventRateLimiter _evLimiter;
public:
// Constructor sets the directory to search
TextureDirectoryLoader(const std::string& directory)
: _searchDir(directory + "/"),
_dialog(_("Loading textures")),
_evLimiter(100)
{}
// Functor operator
void visit(const std::string& shaderName)
{
// Visited texture must start with the directory name
// separated by a slash.
if (string::istarts_with(shaderName, _searchDir))
{
// Update the text in the dialog
if (_evLimiter.readyForEvent())
{
_dialog.setText(shaderName);
}
// Load the shader
MaterialPtr ref = GlobalMaterialManager().getMaterial(shaderName);
// Signal the texture browser that is has to update it next time it renders
GlobalTextureBrowser().updateAllWindows();
}
}
};
}