Krotos Modules 3
Loading...
Searching...
No Matches
PerformanceArea.h
Go to the documentation of this file.
1#pragma once
2
3namespace krotos
4{
28 class PerformanceArea : public Component, public ActionBroadcaster
29 {
30 public:
31 static const std::string analyticsEventTemplateSelected;
32
33 static const String TemplateFileExtension;
34
35 struct Tag
36 {
37 static const Identifier Template;
38 };
39
41 {
43 static const String ComboboxTemplateId;
44 };
45
57 PerformanceArea(ValueTree& customDataTree, KwidgetAudioProcessor& processor, int id,
58 const StringArray& optionKTypes = StringArray());
59
60 void resized() override;
61 void paint(Graphics& g) override;
62
71 void addKwidgetGUI(KwidgetGUI* kwidget, Rectangle<int> bounds);
72
73 // TODO: Implement remove component by ID
79 void removeComponent(int index) { m_layoutEditor.removeComponent(index); };
80
81 // Called when "add <KType>" option is selected from the dropdown
82 std::function<void(String kType)> addKwidget;
83
89 ValueTree& getLayoutTree() { return m_layoutEditor.getLayoutTree(); };
90
94 std::unique_ptr<XmlElement> saveTemplateXml();
95
100 void loadTemplateXml(const XmlElement& templateXml);
101
103 void setTemplateSelectorVisible(bool isVisible)
104 {
105 if (!m_showEditorControls)
106 {
107 m_layoutSelector.setVisible(isVisible);
108 m_dropdownIcon->setVisible(isVisible);
109 }
110 };
111
113 void setEditModeActive(bool isEditModeActive) { m_layoutEditor.setEditModeActive(isEditModeActive); };
114
117 bool isEditModeActive() { return m_layoutEditor.isEditModeActive(); };
118
119 void enableAutoLayout(bool isEnabled) { m_layoutEditor.setAutoLayout(isEnabled); };
120 bool isAutoLayoutActive() { return m_layoutEditor.isAutoLayoutActive(); };
121
122 /* Specify the flexbox settings for autolayout */
123 void configureAutoLayout(FlexBox flexSettings, FlexItem::Margin margin)
124 {
125 m_layoutEditor.configureAutoLayout(flexSettings, margin);
126 };
127
131 void clearLayout();
132
133 int getID() { return m_id; };
134
140 void addKTypesToDropdown(StringArray kTypes)
141 {
142 m_optionKTypes = kTypes;
143 initialiseEditorControls();
144 };
145
149 void setDrawBackground(bool newValue) { m_drawBackground = newValue; }
150
155 std::function<Rectangle<int>(String componentType, Rectangle<int> currentBounds)> getAutoLayoutBoundsFromType;
156
157 // Hacky flag for adding small versions of components. When true, the next component added to the performance
158 // area will be a small one.
159 bool smallify{false};
160
161 private:
162 struct Layout
163 {
164 static constexpr int selectorBar{4};
165 };
166
168
176 void setLayoutTree(const ValueTree& layoutTree) { m_layoutEditor.setLayoutTree(layoutTree); };
177
187 void resetLayoutTree(const ValueTree& layoutTree) { m_layoutEditor.resetLayoutTree(layoutTree); };
188
197 void addComponent(Component& component, Rectangle<int> bounds = CustomLayout::DefaultSize)
198 {
199 m_layoutEditor.addComponent(component, bounds);
200 };
201
218 void addComponent(Component& component, ValueTree slot) { m_layoutEditor.addComponent(component, slot); };
219
220 void refreshTemplates();
221 void initialiseListeners();
222
223 // Include this kwidget in the current template
224 void addToLayoutBuilder(const ValueTree& kwidgetTree);
225
226 void initialiseEditorControls();
227 void showEditorControls(bool isEnabled);
228
230 std::unique_ptr<Drawable> m_backgroundImage;
231
233
234 StringArray m_optionKTypes;
235
236 std::unique_ptr<FileChooser> m_saveWindow, m_loadWindow;
237
239 std::unique_ptr<ValueTreeAttachment> m_customTreeAttachment;
240
241 Array<File> m_templateFiles;
242
244
245 // Secret editor mode controls
246 const String edit_mode_file_ext{"nikolas"};
248
249 bool m_drawBackground{false};
250
251 int m_id{0};
253
254 std::unique_ptr<Drawable> m_dropdownIcon;
255
256 // Tree to store template being built
258 };
259} // namespace krotos
CustomLayout m_layoutEditor
Definition PerformanceArea.h:229
ValueTree & m_customDataTree
Definition PerformanceArea.h:238
Array< File > m_templateFiles
Definition PerformanceArea.h:241
static const String TemplateFileExtension
Definition PerformanceArea.h:33
bool m_drawBackground
Definition PerformanceArea.h:249
ValueTree m_layoutBuilderTree
Definition PerformanceArea.h:257
StringArray m_optionKTypes
Definition PerformanceArea.h:234
int m_id
Definition PerformanceArea.h:251
std::unique_ptr< FileChooser > m_loadWindow
Definition PerformanceArea.h:236
const String edit_mode_file_ext
Definition PerformanceArea.h:246
bool m_showEditorControls
Definition PerformanceArea.h:247
KwidgetAudioProcessor & m_processor
Definition PerformanceArea.h:243
ComboBox m_layoutSelector
Definition PerformanceArea.h:232
static const std::string analyticsEventTemplateSelected
Definition PerformanceArea.h:31
std::function< Rectangle< int >(String componentType, Rectangle< int > currentBounds)> getAutoLayoutBoundsFromType
Used to look up what bounds should be used for a given component type when using auto layout....
Definition PerformanceArea.h:155
bool smallify
Definition PerformanceArea.h:159
ComboBox m_editorSelector
Definition PerformanceArea.h:232
std::unique_ptr< Drawable > m_dropdownIcon
Definition PerformanceArea.h:254
std::unique_ptr< ValueTreeAttachment > m_customTreeAttachment
Definition PerformanceArea.h:239
std::unique_ptr< Drawable > m_backgroundImage
Definition PerformanceArea.h:230
std::function< void(String kType)> addKwidget
Definition PerformanceArea.h:82
int m_lastSelectedTemplate
Definition PerformanceArea.h:252
std::unique_ptr< FileChooser > m_saveWindow
Definition PerformanceArea.h:236
Definition CustomLayout.h:14
void configureAutoLayout(FlexBox flexboxSettings, FlexItem::Margin margin)
Definition CustomLayout.cpp:227
void setLayoutTree(const ValueTree &layoutTree)
Definition CustomLayout.h:52
ValueTree & getLayoutTree()
Definition CustomLayout.cpp:68
static const Rectangle< int > DefaultSize
Definition CustomLayout.h:32
void setAutoLayout(bool isEnabled)
Use this to enable / disable automatic laying out of slots using FlexBox. FlexBox settings must be co...
Definition CustomLayout.h:119
void addComponent(Component &component, Rectangle< int > bounds=CustomLayout::DefaultSize)
Definition CustomLayout.cpp:94
void resetLayoutTree(const ValueTree &layoutTree)
Definition CustomLayout.cpp:75
bool isAutoLayoutActive()
Returns true if auto layout is active.
Definition CustomLayout.h:125
bool isEditModeActive()
Definition CustomLayout.h:111
void removeComponent(int index)
Definition CustomLayout.cpp:130
void setEditModeActive(bool isEditModeActive)
Definition CustomLayout.cpp:137
Definition KwidgetAudioProcessor.h:12
Interface for a UI Component that controls a KwidgetProcessor.
Definition KwidgetGUI.h:24
Definition AirAbsorptionFilter.cpp:2
Definition KwidgetFactory.h:7
Definition PerformanceArea.h:41
static const String PerformanceAreaLayoutComponentId
Definition PerformanceArea.h:42
static const String ComboboxTemplateId
Definition PerformanceArea.h:43
Definition PerformanceArea.h:163
static constexpr int selectorBar
Definition PerformanceArea.h:164
Definition PerformanceArea.h:36
static const Identifier Template
Definition PerformanceArea.h:37