/
SoundChooser.h
102 lines (76 loc) · 2.41 KB
/
SoundChooser.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
#pragma once
#include "iresourcechooser.h"
#include "wxutil/dialog/DialogBase.h"
#include "wxutil/TreeModel.h"
#include "wxutil/TreeView.h"
#include "wxutil/menu/PopupMenu.h"
#include "SoundShaderPreview.h"
#include <memory>
#include <string>
namespace ui
{
/**
* Dialog for listing and selection of sound shaders.
*/
class SoundChooser :
public wxutil::DialogBase,
public IResourceChooser
{
public:
// Treemodel definition
struct TreeColumns :
public wxutil::TreeModel::ColumnRecord
{
TreeColumns() :
displayName(add(wxutil::TreeModel::Column::IconText)),
shaderName(add(wxutil::TreeModel::Column::String)),
isFolder(add(wxutil::TreeModel::Column::Boolean))
{}
wxutil::TreeModel::Column displayName;
wxutil::TreeModel::Column shaderName;
wxutil::TreeModel::Column isFolder;
};
private:
TreeColumns _columns;
// Tree store for shaders, and the tree selection
wxutil::TreeModel::Ptr _treeStore;
wxutil::TreeView* _treeView;
class ThreadedSoundShaderLoader;
std::unique_ptr<ThreadedSoundShaderLoader> _shaderLoader; // PIMPL idiom
// The preview widget group
SoundShaderPreview* _preview;
// Last selected shader
std::string _selectedShader;
// For memorising what we need to pre-select once the population is done
std::string _shaderToSelect;
// Context menu
wxutil::PopupMenuPtr _popupMenu;
bool _loadingShaders;
private:
// Widget construction
wxWindow* createTreeView(wxWindow* parent);
void setTreeViewModel();
void loadSoundShaders();
void handleSelectionChange();
// callbacks
void _onSelectionChange(wxDataViewEvent& ev);
void _onItemActivated(wxDataViewEvent& ev);
void _onTreeStorePopulationFinished(wxutil::TreeModel::PopulationFinishedEvent& ev);
void _onContextMenu(wxDataViewEvent& ev);
void onShowShaderDefinition();
bool testShowShaderDefinition();
public:
/**
* Constructor creates widgets.
*/
SoundChooser(wxWindow* parent = nullptr);
// Retrieve the selected sound shader
const std::string& getSelectedShader() const;
// Set the selected sound shader, and focuses the treeview to the new selection
void setSelectedShader(const std::string& shader);
virtual int ShowModal() override;
// Run the dialog and return the selected shader - this will be empty if the user clicks cancel
virtual std::string chooseResource(const std::string& preselected = std::string()) override;
virtual void destroyDialog() override;
};
} // namespace