Skip to content

Commit

Permalink
Add PluginEditor OpenGL and icon
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 25, 2024
1 parent 1738b5f commit e5d4c9a
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Splash>(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<Splash>(this->splash.get())] {
Expand Down Expand Up @@ -531,6 +547,9 @@ class MainApplication : public juce::JUCEApplication {
/** Config Flow Window */
this->configFlowUI();

/** Config Plugin Editor */
this->configPluginEditor();

/** Load UI Translate */
this->loadUITranslate();

Expand Down
2 changes: 2 additions & 0 deletions src/ui/component/ConfigComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
};

Expand Down
19 changes: 19 additions & 0 deletions src/ui/component/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginEditorContent*>(this->getContentComponent())) {
return ptr->getEditor();
Expand All @@ -263,6 +267,21 @@ void PluginEditor::updateSize() {
}
}

void PluginEditor::setOpenGL(bool openGLOn) {
if (openGLOn) {
this->renderer = std::make_unique<juce::OpenGLContext>();
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<PluginEditorContent*>(this->getContentComponent())) {
return ptr->deleteEditor();
Expand Down
6 changes: 6 additions & 0 deletions src/ui/component/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<juce::OpenGLContext> renderer = nullptr;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PluginEditor)
};
28 changes: 28 additions & 0 deletions src/ui/misc/PluginEditorHub.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PluginEditorHub.h"
#include "CoreCallbacks.h"
#include "RCManager.h"
#include "../../audioCore/AC_API.h"

PluginEditorHub::PluginEditorHub() {
Expand All @@ -20,6 +21,8 @@ void PluginEditorHub::openInstr(int index) {
auto container = std::make_unique<PluginEditor>(
quickAPI::getInstrName(plugin),
PluginType::Instr, plugin, editor);
container->setOpenGL(this->openGLOn);
container->setWindowIcon(this->iconTemp);

/** Show */
this->openEditor(container.get());
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/ui/misc/PluginEditorHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginEditor> instrEditors;
juce::OwnedArray<PluginEditor> effectEditors;
bool openGLOn = true;
juce::Image iconTemp;

friend class PluginEditorContent;
void deleteInstrEditor(PluginEditor* ptr);
Expand Down

0 comments on commit e5d4c9a

Please sign in to comment.