gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit a40dc740e14f74c52225d2e349140b91de87df7b
parent 411885df252d7327962e0732235d13546e4e6cc8
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Sun, 18 Aug 2024 17:15:25 +0200

add helper func to resize a drawable image

Diffstat:
Msource/juceUiLib/editor.cpp | 26++++++++++++++++++++++++++
Msource/juceUiLib/editor.h | 4+++-
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/source/juceUiLib/editor.cpp b/source/juceUiLib/editor.cpp @@ -262,4 +262,30 @@ namespace genericUI return {}; return it->second; } + + bool Editor::resizeDrawableImage(juce::DrawableImage& _drawable, const uint32_t _percent) + { + if(_percent == 100) + return true; + if(_percent < 1) + return false; + + auto image = _drawable.getImage(); + const auto x = image.getBounds().getX(); + const auto y = image.getBounds().getY(); + const auto w = image.getWidth(); + const auto h = image.getHeight(); + + const int percent = static_cast<int>(_percent); + + image = image.rescaled(w * percent / 100, h * percent / 100); + + _drawable.setImage(image); + auto b = image.getBounds(); + b.setSize(w, h); + b.setPosition(x, y); + _drawable.setBounds(b); + _drawable.setBoundingBox(b.toFloat()); + return true; + } } diff --git a/source/juceUiLib/editor.h b/source/juceUiLib/editor.h @@ -99,7 +99,9 @@ namespace genericUI virtual Button<juce::DrawableButton>* createJuceComponent(Button<juce::DrawableButton>*, UiObject& _object, const std::string& _name, juce::DrawableButton::ButtonStyle) { return nullptr; } virtual Button<juce::TextButton>* createJuceComponent(Button<juce::TextButton>*, UiObject& _object) { return nullptr; } - const UiObject& getRootObject() const { return *(m_rootObject.get()); } + const UiObject& getRootObject() const { return *m_rootObject; } + + static bool resizeDrawableImage(juce::DrawableImage& _drawable, uint32_t _percent); private: EditorInterface& m_interface;