From e5d4c9a06cd275c8c16b8d31fa6c16111eaf353b Mon Sep 17 00:00:00 2001 From: WuChang <3142324836@qq.com> Date: Thu, 25 Jan 2024 14:41:21 +0800 Subject: [PATCH] Add PluginEditor OpenGL and icon --- src/main.cpp | 21 ++++++++++++++++++++- src/ui/component/ConfigComponent.cpp | 2 ++ src/ui/component/PluginEditor.cpp | 19 +++++++++++++++++++ src/ui/component/PluginEditor.h | 6 ++++++ src/ui/misc/PluginEditorHub.cpp | 28 ++++++++++++++++++++++++++++ src/ui/misc/PluginEditorHub.h | 5 +++++ 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4f67a2a5..c6519689 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -203,12 +203,28 @@ class MainApplication : public juce::JUCEApplication { auto& funcVar = ConfigManager::getInstance()->get("function"); flowUI::FlowWindowHub::setTitle(utils::getAudioPlatformName()); - flowUI::FlowWindowHub::setIcon("./rc/logo.png"); + flowUI::FlowWindowHub::setIcon(utils::getResourceFile("logo.png").getFullPathName()); flowUI::FlowWindowHub::setOpenGL(!((bool)(funcVar["cpu-painting"]))); } ); }; + void configPluginEditor() { + InitTaskList::getInstance()->add( + [splash = Splash::SafePointer(this->splash.get())] { + if (splash) { splash->showMessage("Config Plugin Editor..."); } + } + ); + InitTaskList::getInstance()->add( + [] { + auto& funcVar = ConfigManager::getInstance()->get("function"); + + PluginEditorHub::getInstance()->setIcon(utils::getResourceFile("logo.png").getFullPathName()); + PluginEditorHub::getInstance()->setOpenGL(!((bool)(funcVar["cpu-painting"]))); + } + ); + }; + void loadUITranslate() { InitTaskList::getInstance()->add( [splash = Splash::SafePointer(this->splash.get())] { @@ -531,6 +547,9 @@ class MainApplication : public juce::JUCEApplication { /** Config Flow Window */ this->configFlowUI(); + /** Config Plugin Editor */ + this->configPluginEditor(); + /** Load UI Translate */ this->loadUITranslate(); diff --git a/src/ui/component/ConfigComponent.cpp b/src/ui/component/ConfigComponent.cpp index 4e1b1f63..81e3d648 100644 --- a/src/ui/component/ConfigComponent.cpp +++ b/src/ui/component/ConfigComponent.cpp @@ -4,6 +4,7 @@ #include "PluginConfigComponent.h" #include "KeyMappingEditorComponent.h" #include "../misc/MainThreadPool.h" +#include "../misc/PluginEditorHub.h" #include "../menuAndCommand/CommandManager.h" #include "../menuAndCommand/CommandTypes.h" #include "../Utils.h" @@ -303,6 +304,7 @@ void ConfigComponent::createFunctionPage() { auto cpuPaintingUpdateCallback = [](const juce::var& data) { flowUI::FlowWindowHub::setOpenGL(!((bool)data)); + PluginEditorHub::getInstance()->setOpenGL(!((bool)data)); return true; }; diff --git a/src/ui/component/PluginEditor.cpp b/src/ui/component/PluginEditor.cpp index c31d89a2..4ec8503c 100644 --- a/src/ui/component/PluginEditor.cpp +++ b/src/ui/component/PluginEditor.cpp @@ -239,6 +239,10 @@ PluginEditor::PluginEditor(const juce::String& name, PluginType type, ); } +PluginEditor::~PluginEditor() { + this->renderer = nullptr; +} + quickAPI::EditorPointer PluginEditor::getEditor() const { if (auto ptr = dynamic_cast(this->getContentComponent())) { return ptr->getEditor(); @@ -263,6 +267,21 @@ void PluginEditor::updateSize() { } } +void PluginEditor::setOpenGL(bool openGLOn) { + if (openGLOn) { + this->renderer = std::make_unique(); + this->renderer->attachTo(*this); + } + else { + this->renderer = nullptr; + } +} + +void PluginEditor::setWindowIcon(const juce::Image& icon) { + this->setIcon(icon); + this->getPeer()->setIcon(icon); +} + void PluginEditor::closeButtonPressed() { if (auto ptr = dynamic_cast(this->getContentComponent())) { return ptr->deleteEditor(); diff --git a/src/ui/component/PluginEditor.h b/src/ui/component/PluginEditor.h index 935d9718..48f3823c 100644 --- a/src/ui/component/PluginEditor.h +++ b/src/ui/component/PluginEditor.h @@ -56,15 +56,21 @@ class PluginEditor final : public juce::DocumentWindow { PluginEditor() = delete; PluginEditor(const juce::String& name, PluginType type, quickAPI::PluginHolder plugin, quickAPI::EditorPointer editor); + ~PluginEditor(); quickAPI::EditorPointer getEditor() const; void update(); void updateSize(); + void setOpenGL(bool openGLOn); + void setWindowIcon(const juce::Image& icon); + private: void closeButtonPressed() override; private: + std::unique_ptr renderer = nullptr; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginEditor) }; diff --git a/src/ui/misc/PluginEditorHub.cpp b/src/ui/misc/PluginEditorHub.cpp index 68440119..27a47a06 100644 --- a/src/ui/misc/PluginEditorHub.cpp +++ b/src/ui/misc/PluginEditorHub.cpp @@ -1,5 +1,6 @@ #include "PluginEditorHub.h" #include "CoreCallbacks.h" +#include "RCManager.h" #include "../../audioCore/AC_API.h" PluginEditorHub::PluginEditorHub() { @@ -20,6 +21,8 @@ void PluginEditorHub::openInstr(int index) { auto container = std::make_unique( quickAPI::getInstrName(plugin), PluginType::Instr, plugin, editor); + container->setOpenGL(this->openGLOn); + container->setWindowIcon(this->iconTemp); /** Show */ this->openEditor(container.get()); @@ -70,6 +73,31 @@ bool PluginEditorHub::checkInstr(int index) const { return false; } +void PluginEditorHub::setOpenGL(bool opneGLOn) { + this->openGLOn = openGLOn; + for (auto i : this->instrEditors) { + i->setOpenGL(openGLOn); + } + for (auto i : this->effectEditors) { + i->setOpenGL(openGLOn); + } +} + +void PluginEditorHub::setIcon(const juce::String& path) { + /** Load Icon */ + juce::File iconFile = juce::File::getSpecialLocation( + juce::File::SpecialLocationType::hostApplicationPath).getParentDirectory().getChildFile(path); + this->iconTemp = RCManager::getInstance()->loadImage(iconFile); + + /** Set All Windows */ + for (auto i : this->instrEditors) { + i->setWindowIcon(this->iconTemp); + } + for (auto i : this->effectEditors) { + i->setWindowIcon(this->iconTemp); + } +} + void PluginEditorHub::deleteInstrEditor(PluginEditor* ptr) { /** Close Comp */ this->closeEditor(ptr); diff --git a/src/ui/misc/PluginEditorHub.h b/src/ui/misc/PluginEditorHub.h index d8f23164..3567967c 100644 --- a/src/ui/misc/PluginEditorHub.h +++ b/src/ui/misc/PluginEditorHub.h @@ -11,9 +11,14 @@ class PluginEditorHub final : private juce::DeletedAtShutdown { void closeInstr(int index); bool checkInstr(int index) const; + void setOpenGL(bool opneGLOn); + void setIcon(const juce::String& path); + private: juce::OwnedArray instrEditors; juce::OwnedArray effectEditors; + bool openGLOn = true; + juce::Image iconTemp; friend class PluginEditorContent; void deleteInstrEditor(PluginEditor* ptr);