commit bda357886a32743c9dddb4a35e4f2142d9568f3f
parent 19ef240627beed99d0881e1a400cde17f29e98bc
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sat, 8 Jun 2024 01:52:30 +0200
fix overlay positioning before editor window becomes visible
Diffstat:
6 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/source/jucePluginEditorLib/parameterOverlay.cpp b/source/jucePluginEditorLib/parameterOverlay.cpp
@@ -65,7 +65,12 @@ namespace jucePluginEditorLib
auto updatePosition = [&]()
{
- drawableImage->setCentrePosition(static_cast<int>(props.position.x) + m_component->getPosition().x, static_cast<int>(props.position.y) + m_component->getPosition().y);
+ const auto x = static_cast<int>(props.position.x) + m_component->getPosition().x;
+ const auto y = static_cast<int>(props.position.y) + m_component->getPosition().y;
+ const auto w = drawableImage->getWidth();
+ const auto h = drawableImage->getHeight();
+
+ drawableImage->setBoundingBox(juce::Rectangle(x - (w>>1), y - (h>>1), w, h).toFloat());
};
if(!drawableImage)
@@ -81,7 +86,6 @@ namespace jucePluginEditorLib
// _image->setOverlayColour(props.color); // juce cannot do it, it does not multiply but replaced the color entirely
drawableImage->setInterceptsMouseClicks(false, false);
drawableImage->setAlwaysOnTop(true);
-
m_component->getParentComponent()->addAndMakeVisible(drawableImage);
}
}
@@ -102,6 +106,9 @@ namespace jucePluginEditorLib
void ParameterOverlay::updateOverlays()
{
+ if(m_component->getParentComponent() == nullptr)
+ return;
+
const auto isLocked = m_parameter != nullptr && m_parameter->isLocked();
const auto isLinkSource = m_parameter != nullptr && (m_parameter->getLinkState() & pluginLib::Source);
const auto isLinkTarget = m_parameter != nullptr && (m_parameter->getLinkState() & pluginLib::Target);
@@ -130,11 +137,18 @@ namespace jucePluginEditorLib
const auto avgWidth = totalWidth / count;
- int x = -(totalWidth >> 1) + (avgWidth>>1) + visibleOverlays[0]->getPosition().x;
+ int x = -static_cast<int>(totalWidth >> 1) + static_cast<int>(avgWidth >> 1) + static_cast<int>(visibleOverlays[0]->getBoundingBox().topLeft.x);
for(uint32_t i=0; i<count; ++i)
{
- visibleOverlays[i]->setTopLeftPosition(x, visibleOverlays[i]->getPosition().y);
+ auto bounds = visibleOverlays[i]->getBoundingBox();
+ const auto w = bounds.getWidth();
+ const auto fx = static_cast<float>(x);
+ bounds.topLeft.x = fx;
+ bounds.bottomLeft.x = fx;
+ bounds.topRight.x = fx + w;
+ visibleOverlays[i]->setBoundingBox(bounds);
+
x += visibleOverlays[i]->getWidth();
}
}
diff --git a/source/jucePluginEditorLib/parameterOverlay.h b/source/jucePluginEditorLib/parameterOverlay.h
@@ -24,6 +24,11 @@ namespace jucePluginEditorLib
void onBind(const pluginLib::ParameterBinding::BoundParameter& _parameter);
void onUnbind(const pluginLib::ParameterBinding::BoundParameter& _parameter);
+ void refresh()
+ {
+ updateOverlays();
+ }
+
private:
struct OverlayProperties
{
diff --git a/source/jucePluginEditorLib/parameterOverlays.cpp b/source/jucePluginEditorLib/parameterOverlays.cpp
@@ -33,6 +33,12 @@ namespace jucePluginEditorLib
return true;
}
+ void ParameterOverlays::refreshAll() const
+ {
+ for (const auto& overlay : m_overlays)
+ overlay.second->refresh();
+ }
+
void ParameterOverlays::onBind(const pluginLib::ParameterBinding::BoundParameter& _parameter)
{
registerComponent(_parameter.component);
diff --git a/source/jucePluginEditorLib/parameterOverlays.h b/source/jucePluginEditorLib/parameterOverlays.h
@@ -31,6 +31,8 @@ namespace jucePluginEditorLib
Editor& getEditor() const { return m_editor; }
+ void refreshAll() const;
+
private:
void onBind(const pluginLib::ParameterBinding::BoundParameter& _parameter);
void onUnbind(const pluginLib::ParameterBinding::BoundParameter& _parameter);
diff --git a/source/jucePluginEditorLib/pluginEditor.cpp b/source/jucePluginEditorLib/pluginEditor.cpp
@@ -445,6 +445,14 @@ namespace jucePluginEditorLib
return getProcessor().getController().setParameters(_paramValues, m_processor.getController().getCurrentPart(), pluginLib::Parameter::Origin::Ui);
}
+ void Editor::parentHierarchyChanged()
+ {
+ genericUI::Editor::parentHierarchyChanged();
+
+ if(isShowing())
+ m_overlays.refreshAll();
+ }
+
bool Editor::keyPressed(const juce::KeyPress& _key)
{
if(_key.getModifiers().isCommandDown())
diff --git a/source/jucePluginEditorLib/pluginEditor.h b/source/jucePluginEditorLib/pluginEditor.h
@@ -80,6 +80,7 @@ namespace jucePluginEditorLib
auto& getImagePool() { return m_imagePool; }
+ void parentHierarchyChanged() override;
private:
bool keyPressed(const juce::KeyPress& _key) override;