Skip to content

Commit

Permalink
Update PluginEditor pin
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 25, 2024
1 parent e5d4c9a commit 25acd5b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/translates/zh-CN/main.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ countries: cn
"Plugin Editor" = "插件编辑器"
"Config Plugin" = "设置插件"
"Plugin Config" = "插件设置"
"Pin Plugin Window" = "固定插件窗口"
40 changes: 40 additions & 0 deletions src/ui/component/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ PluginEditorContent::PluginEditorContent(PluginEditor* parent,
this->configIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));

this->pinIcon = flowUI::IconManager::getSVG(
utils::getIconFile("Map", "pushpin-line").getFullPathName());
this->pinIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));

this->pinIconOn = flowUI::IconManager::getSVG(
utils::getIconFile("Map", "pushpin-line").getFullPathName());
this->pinIconOn->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOnId));

/** Buttons */
this->bypassButton = std::make_unique<juce::DrawableButton>(
TRANS("Bypass Plugin"), juce::DrawableButton::ImageOnButtonBackground);
Expand All @@ -76,6 +86,16 @@ PluginEditorContent::PluginEditorContent(PluginEditor* parent,
this->configButton->onClick = [this] { this->config(); };
this->addAndMakeVisible(this->configButton.get());

this->pinButton = std::make_unique<juce::DrawableButton>(
TRANS("Pin Plugin Window"), juce::DrawableButton::ImageOnButtonBackground);
this->pinButton->setImages(
this->pinIcon.get(), nullptr, nullptr, nullptr,
this->pinIconOn.get(), nullptr, nullptr, nullptr);
this->pinButton->setWantsKeyboardFocus(false);
this->pinButton->setMouseCursor(juce::MouseCursor::PointingHandCursor);
this->pinButton->onClick = [this] { this->pin(); };
this->addAndMakeVisible(this->pinButton.get());

/** Update Now */
this->update();
}
Expand Down Expand Up @@ -122,6 +142,11 @@ void PluginEditorContent::resized() {
buttonHeight, buttonHeight);
this->configButton->setBounds(configRect);

juce::Rectangle<int> pinRect(
configRect.getRight() + toolSplitWidth, toolPaddingHeight,
buttonHeight, buttonHeight);
this->pinButton->setBounds(pinRect);

/** Content */
juce::Rectangle<int> contentRect =
this->getLocalBounds().withTrimmedTop(toolBarHeight);
Expand Down Expand Up @@ -205,6 +230,13 @@ void PluginEditorContent::config() {
juce::NotificationType::dontSendNotification);
}

void PluginEditorContent::pin() {
bool newState = !(this->pinButton->getToggleState());
this->parent->setPinned(newState);
this->pinButton->setToggleState(newState,
juce::NotificationType::dontSendNotification);
}

void PluginEditorContent::deleteEditor() {
switch (this->type) {
case PluginType::Instr: {
Expand Down Expand Up @@ -282,6 +314,14 @@ void PluginEditor::setWindowIcon(const juce::Image& icon) {
this->getPeer()->setIcon(icon);
}

void PluginEditor::setPinned(bool pin) {
this->setAlwaysOnTop(pin);
}

bool PluginEditor::getPinned() const {
return this->isAlwaysOnTop();
}

void PluginEditor::closeButtonPressed() {
if (auto ptr = dynamic_cast<PluginEditorContent*>(this->getContentComponent())) {
return ptr->deleteEditor();
Expand Down
7 changes: 7 additions & 0 deletions src/ui/component/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ class PluginEditorContent final
std::unique_ptr<juce::Drawable> bypassIconOn = nullptr;
std::unique_ptr<juce::Drawable> configIcon = nullptr;
std::unique_ptr<juce::Drawable> configIconOn = nullptr;
std::unique_ptr<juce::Drawable> pinIcon = nullptr;
std::unique_ptr<juce::Drawable> pinIconOn = nullptr;
std::unique_ptr<juce::DrawableButton> bypassButton = nullptr;
std::unique_ptr<juce::DrawableButton> configButton = nullptr;
std::unique_ptr<juce::DrawableButton> pinButton = nullptr;

void componentBeingDeleted(juce::Component&) override;
void componentMovedOrResized(juce::Component&,
bool wasMoved, bool wasResized) override;

void bypass();
void config();
void pin();

friend class PluginEditor;
void deleteEditor();
Expand All @@ -66,6 +70,9 @@ class PluginEditor final : public juce::DocumentWindow {
void setOpenGL(bool openGLOn);
void setWindowIcon(const juce::Image& icon);

void setPinned(bool pin);
bool getPinned() const;

private:
void closeButtonPressed() override;

Expand Down

0 comments on commit 25acd5b

Please sign in to comment.