Krotos Modules 3
Loading...
Searching...
No Matches
KwidgetGUI.cpp
Go to the documentation of this file.
1namespace krotos
2{
3 KwidgetGUI::KwidgetGUI(Kwidget& k) : m_owner(k), m_topBarComponent(true, k.getKwidgetID())
4 {
5 setComponentID(getKwidgetID());
6 setInterceptsMouseClicks(true, true);
7
8 // Add TopBarComponent
9 addAndMakeVisible(m_topBarComponent);
10
11 // Default to borderless if we are a child kwidget
12 if (k.isAChildKwidget())
14
15 // assign getTopBarComponent().onDelete to KwidgetGUI::onDelete to avoid duplicate definitions
17 }
18
20 {
21 Rectangle<int> bounds = getBoundsInParent();
23 boundsParameter->setValue(bounds.toString());
24 }
25
26 void KwidgetGUI::paint(Graphics& g)
27 {
28 auto backgroundBounds = getLocalBounds();
29
31 {
32 backgroundBounds = getTopBarComponent().getLocalBounds();
33 }
34
36 {
37 g.setColour(getLookAndFeel().findColour(ResizableWindow::backgroundColourId));
38 g.fillRoundedRectangle(backgroundBounds.reduced(1).toFloat(), 8.0f);
39
40 g.setColour(m_borderColour);
41 g.drawRoundedRectangle(getLocalBounds().reduced(3).toFloat(), 6.0f, k_borderThickness);
42 }
43 }
44
46 {
47 // GUI proportion we want to be on screen when dragged off limits - Bound constrainer not used atm
48 // m_constrainer.setMinimumOnscreenAmounts(getHeight(), getWidth(), getHeight(), getWidth());
49
51 {
52 m_currentBounds = getLocalBounds();
53 }
54 else
55 {
56 m_currentBounds = getLocalBounds().reduced(k_padding);
57 }
58
60 {
61 auto dim = k_buttonSize + k_padding;
62 auto topBar = m_currentBounds.removeFromTop(dim);
63
64 m_topBarComponent.setBounds(topBar);
65 }
66 }
67
68 const String& KwidgetGUI::getKwidgetType() const { return m_owner.getKwidgetType(); }
69
70 const String& KwidgetGUI::getKwidgetID() const { return m_owner.getKwidgetID(); }
71
72 std::unique_ptr<SliderParameterAttachment> KwidgetGUI::createParameterAttachment(const String& paramID,
73 Slider& slider)
74 {
75 return std::make_unique<SliderParameterAttachment>(*m_owner.getParameter(paramID)->getAttachedParameter(),
76 slider, m_undoManager);
77 }
78
79 std::unique_ptr<ButtonParameterAttachment> KwidgetGUI::createParameterAttachment(const String& paramID,
80 Button& button)
81 {
82 return std::make_unique<ButtonParameterAttachment>(*m_owner.getParameter(paramID)->getAttachedParameter(),
83 button, m_undoManager);
84 }
85
86 std::unique_ptr<ComboBoxParameterAttachment> KwidgetGUI::createParameterAttachment(const String& paramID,
87 ComboBox& comboBox)
88 {
89 return std::make_unique<ComboBoxParameterAttachment>(*m_owner.getParameter(paramID)->getAttachedParameter(),
90 comboBox, m_undoManager);
91 }
92
93 std::unique_ptr<ParameterAttachment> KwidgetGUI::createParameterAttachment(const String& paramID,
94 std::function<void(float)> callback)
95 {
96 return std::make_unique<ParameterAttachment>(*m_owner.getParameter(paramID)->getAttachedParameter(),
97 std::move(callback), m_undoManager);
98 }
99
100 std::unique_ptr<LabelCustomParameterAttachment> KwidgetGUI::createCustomParameterAttachment(const String& paramID,
101 Label& label)
102 {
103 return std::make_unique<LabelCustomParameterAttachment>(*m_owner.getCustomParameter(paramID), label);
104 }
105
107
108 void KwidgetGUI::addParameterCallback(const String& paramID, std::function<void(float)> callback)
109 {
111 new KParameter::AsyncListenerObject(m_owner.getParameterToAttach(paramID), std::move(callback)));
112 }
113
115 {
116 m_renderStyle = newStyle;
117
118#if ENABLE_SANDBOX
120 renderStyleParameter->setValue(static_cast<int>(m_renderStyle));
121
124
125 String topBarComponentID = m_topBarComponent.getComponentID();
126
128 {
129 setInterceptsMouseClicks(false, true);
130 for (Component* child : getChildren())
131 {
132 if (child->getComponentID() != topBarComponentID)
133 {
134 child->setVisible(false);
135 child->setEnabled(false);
136 child->setAccessible(false);
137 }
138 }
139 }
140 else
141 {
142 setInterceptsMouseClicks(true, true);
143 toFront(false);
144 for (Component* child : getChildren())
145 {
146 if (child->getComponentID() != topBarComponentID)
147 {
148 child->setVisible(true);
149 child->setEnabled(true);
150 child->setAccessible(true);
151 }
152 }
153 }
154#endif
155 repaint();
156 }
157
158 void KwidgetGUI::mouseDown(const MouseEvent& event)
159 {
160 String topBarComponentID = getTopBarComponent().getComponentID();
161
162 if (event.eventComponent->getComponentID() == topBarComponentID)
163 {
164 m_dragger.startDraggingComponent(this, event);
165 m_allowDrag = true;
166 }
167 else
168 {
169 m_allowDrag = false;
170 }
171 }
172
173#if ENABLE_SANDBOX
174 void KwidgetGUI::mouseDrag(const MouseEvent& event)
175 {
176 if (m_allowDrag == true)
177 {
178 m_dragger.dragComponent(this, event, nullptr);
179 // Constaint the GUI within the screen - Not used atm
180 // m_constrainer.checkComponentBounds(this);
181 }
182 }
183#endif
184} // namespace krotos
A wrapper around juce::ValueTree designed to store custom plugin state (strings, arrays,...
Definition CustomParameter.h:9
void setValue(const var &newValue, bool selfUpdate=false)
Definition CustomParameter.cpp:46
GenericParameter * getAttachedParameter()
Definition KParameter.cpp:170
TopBarComponent m_topBarComponent
Definition KwidgetGUI.h:151
KwidgetGUI(Kwidget &owner)
Definition KwidgetGUI.cpp:3
RenderStyle
Definition KwidgetGUI.h:32
void mouseDown(const MouseEvent &event) override
Definition KwidgetGUI.cpp:158
Kwidget & m_owner
Definition KwidgetGUI.h:156
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
void paint(Graphics &g) override
Definition KwidgetGUI.cpp:26
bool m_allowDrag
Definition KwidgetGUI.h:163
RenderStyle m_renderStyle
Definition KwidgetGUI.h:153
const String & getKwidgetType() const
Definition KwidgetGUI.cpp:68
Kwidget & getOwner()
Definition KwidgetGUI.cpp:106
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 setRenderStyle(RenderStyle newStyle)
Definition KwidgetGUI.cpp:114
bool m_ignorePadding
Definition KwidgetGUI.h:145
Definition Kwidget.h:8
bool isAChildKwidget()
Definition Kwidget.cpp:248
KParameter * getParameter(const String &parameterID) const noexcept
Get a raw pointer to a KParameter belonging to this Kwidget's KwidgetProcessor. Useful for low overhe...
Definition Kwidget.cpp:168
const String & getKwidgetType() const
Definition Kwidget.cpp:365
const String & getKwidgetID() const
Definition Kwidget.cpp:367
CustomParameter * getCustomParameter(const String &parameterID)
Definition Kwidget.cpp:188
std::shared_ptr< KParameter > getParameterToAttach(const String &parameterID) const noexcept
Get a shared pointer to a KParameter, for use with KParameter::Listener objects and situations where ...
Definition Kwidget.cpp:178
std::function< void(const String &)> onDelete
Definition topBarComponent.h:32
Definition AirAbsorptionFilter.cpp:2
const int k_buttonSize
Definition KwidgetGUI.h:5
const int k_padding
Definition KwidgetGUI.h:3
const float k_borderThickness
Definition KwidgetGUI.h:4
Used to create a KParameter listener for GUI or non time critical updates.
Definition KParameter.h:72
static const String Renderstyle
Definition Kwidget.h:26
static const String Bounds
Definition Kwidget.h:25