Krotos Modules 3
Loading...
Searching...
No Matches
KwidgetGUI.h
Go to the documentation of this file.
1namespace krotos
2{
3 const int k_padding{5};
4 const float k_borderThickness{1.0f};
5 const int k_buttonSize{15};
6 const int k_minimumHeight{25};
7 const float k_topBarCornerSize{6.0f};
8 //==============================================================================
23 class KwidgetGUI : public Component, public ActionBroadcaster
24 {
25 public:
26 KwidgetGUI(Kwidget& owner);
27
29 ~KwidgetGUI() override = default;
30
31 enum class RenderStyle
32 {
33 normal = 0,
36 minimised, // this style shows only the top Bar and everything else invisible
38 };
39
40 void moved() override;
41
43 void paint(Graphics& g) override;
44
48 void resized() override;
49
51 void mouseDown(const MouseEvent& event) override;
52
53#if ENABLE_SANDBOX
54 void mouseDrag(const MouseEvent& event) override;
55#endif
56
58 const String& getKwidgetType() const;
59
61 const String& getKwidgetID() const;
62
66 void setRenderStyle(RenderStyle newStyle);
67
69 inline int divideIntByFloat(int dividend, float divisor)
70 {
71 return static_cast<int>(static_cast<float>(dividend) / divisor);
72 }
73
75 inline int multiplyIntByFloat(int mult, float factor)
76 {
77 return static_cast<int>(static_cast<float>(mult) * factor);
78 }
79
83 virtual void finalSetup() {}
84
86 void ignorePadding(bool ignore) { m_ignorePadding = ignore; };
87
90
93
95 std::function<void(const String&)> onDelete;
96
97 protected:
98 std::unique_ptr<SliderParameterAttachment> createParameterAttachment(const String& paramID, Slider& slider);
99 std::unique_ptr<ButtonParameterAttachment> createParameterAttachment(const String& paramID, Button& button);
100 std::unique_ptr<ComboBoxParameterAttachment> createParameterAttachment(const String& paramID,
101 ComboBox& comboBox);
102 std::unique_ptr<ParameterAttachment> createParameterAttachment(const String& paramID,
103 std::function<void(float)> callback);
104
105 std::unique_ptr<LabelCustomParameterAttachment> createCustomParameterAttachment(const String& paramID,
106 Label& label);
107
111 template <typename AttachedComponentType>
112 void addAttachedComponent(AttachedComponentType& component, const String& paramID, bool isDraggable = true)
113 {
114 addAndMakeVisible(component);
115
116 if (isDraggable)
117 component.setDragAndDropDescription(m_owner.getDragID(paramID));
118
119 component.getAttachment() = createParameterAttachment(paramID, component.getControlComponent());
120 }
121
126 template <typename AttachedComponentType>
127 void addAttachedComponent(Component& parent, AttachedComponentType& component, const String& paramID,
128 bool isDraggable = true)
129 {
130 parent.addAndMakeVisible(component);
131
132 if (isDraggable)
133 component.setDragAndDropDescription(m_owner.getDragID(paramID));
134
135 component.getAttachment() = createParameterAttachment(paramID, component.getControlComponent());
136 }
137
143 void addParameterCallback(const String& paramID, std::function<void(float)> callback);
144
145 bool m_ignorePadding{false};
146 Rectangle<int> m_currentBounds;
147 TextButton m_selectButton;
148 TextButton m_deleteButton;
149 Colour m_borderColour{Colours::fuchsia};
150
152
154
155 private:
157 UndoManager* m_undoManager{nullptr};
158 OwnedArray<KParameter::AsyncListenerObject> m_parameterCallbacks;
159
160 // Takes care of the logic for dragging KWidgetGUIs around with the mouse
161 ComponentDragger m_dragger;
162
163 bool m_allowDrag{false};
164 };
165} // namespace krotos
Interface for a UI Component that controls a KwidgetProcessor.
Definition KwidgetGUI.h:24
TopBarComponent m_topBarComponent
Definition KwidgetGUI.h:151
KwidgetGUI(Kwidget &owner)
Definition KwidgetGUI.cpp:3
TextButton m_deleteButton
Definition KwidgetGUI.h:148
RenderStyle
Definition KwidgetGUI.h:32
void mouseDown(const MouseEvent &event) override
Definition KwidgetGUI.cpp:158
Kwidget & m_owner
Definition KwidgetGUI.h:156
void ignorePadding(bool ignore)
Definition KwidgetGUI.h:86
virtual void finalSetup()
Definition KwidgetGUI.h:83
std::unique_ptr< LabelCustomParameterAttachment > createCustomParameterAttachment(const String &paramID, Label &label)
Definition KwidgetGUI.cpp:100
std::unique_ptr< SliderParameterAttachment > createParameterAttachment(const String &paramID, Slider &slider)
Definition KwidgetGUI.cpp:72
void addParameterCallback(const String &paramID, std::function< void(float)> callback)
Definition KwidgetGUI.cpp:108
OwnedArray< KParameter::AsyncListenerObject > m_parameterCallbacks
Definition KwidgetGUI.h:158
Colour m_borderColour
Definition KwidgetGUI.h:149
TopBarComponent & getTopBarComponent()
Definition KwidgetGUI.h:89
TextButton m_selectButton
Definition KwidgetGUI.h:147
void paint(Graphics &g) override
Definition KwidgetGUI.cpp:26
int divideIntByFloat(int dividend, float divisor)
Definition KwidgetGUI.h:69
~KwidgetGUI() override=default
bool m_allowDrag
Definition KwidgetGUI.h:163
RenderStyle m_renderStyle
Definition KwidgetGUI.h:153
int multiplyIntByFloat(int mult, float factor)
Definition KwidgetGUI.h:75
const String & getKwidgetType() const
Definition KwidgetGUI.cpp:68
Kwidget & getOwner()
Definition KwidgetGUI.cpp:106
void addAttachedComponent(AttachedComponentType &component, const String &paramID, bool isDraggable=true)
Definition KwidgetGUI.h:112
ComponentDragger m_dragger
Definition KwidgetGUI.h:161
Rectangle< int > m_currentBounds
Definition KwidgetGUI.h:146
void moved() override
Definition KwidgetGUI.cpp:19
void resized() override
Definition KwidgetGUI.cpp:45
const String & getKwidgetID() const
Definition KwidgetGUI.cpp:70
UndoManager * m_undoManager
Definition KwidgetGUI.h:157
std::function< void(const String &)> onDelete
Definition KwidgetGUI.h:95
void addAttachedComponent(Component &parent, AttachedComponentType &component, const String &paramID, bool isDraggable=true)
Definition KwidgetGUI.h:127
void setRenderStyle(RenderStyle newStyle)
Definition KwidgetGUI.cpp:114
bool m_ignorePadding
Definition KwidgetGUI.h:145
Definition Kwidget.h:8
StringArray getDragID(const String &parameterID)
Definition Kwidget.cpp:394
The TopBarComponent in each Kwidget containing the 3 Buttons and their functionality.
Definition topBarComponent.h:14
Definition AirAbsorptionFilter.cpp:2
const int k_buttonSize
Definition KwidgetGUI.h:5
const float k_topBarCornerSize
Definition KwidgetGUI.h:7
const int k_padding
Definition KwidgetGUI.h:3
const float k_borderThickness
Definition KwidgetGUI.h:4
const int k_minimumHeight
Definition KwidgetGUI.h:6