Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 98df6b2

Browse files
committed
feat: add dark mode GUI
1 parent daf28f4 commit 98df6b2

File tree

12 files changed

+96
-42
lines changed

12 files changed

+96
-42
lines changed

Source/GUI/interface_definitions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ namespace zlinterface {
313313
float cornerSize,
314314
const fillRoundedShadowRectangleArgs &args) {
315315
auto mArgs = args;
316-
mArgs.mainColour = getBackgroundColor();
316+
mArgs.mainColour = getBackgroundColor().withAlpha(args.mainColour.getAlpha());
317317
mArgs.darkShadowColor = getDarkShadowColor();
318318
mArgs.brightShadowColor = getBrightShadowColor();
319319
return zlinterface::fillRoundedShadowRectangle(g, boxBounds, cornerSize, mArgs);
@@ -324,7 +324,7 @@ namespace zlinterface {
324324
float cornerSize,
325325
const fillRoundedShadowRectangleArgs &args) {
326326
auto mArgs = args;
327-
mArgs.mainColour = getBackgroundColor();
327+
mArgs.mainColour = getBackgroundColor().withAlpha(args.mainColour.getAlpha());
328328
mArgs.darkShadowColor = getDarkShadowColor();
329329
mArgs.brightShadowColor = getBrightShadowColor();
330330
return zlinterface::fillRoundedInnerShadowRectangle(g, boxBounds, cornerSize, mArgs);
@@ -335,7 +335,7 @@ namespace zlinterface {
335335
float cornerSize,
336336
const fillShadowEllipseArgs &args) {
337337
auto mArgs = args;
338-
mArgs.mainColour = getBackgroundColor();
338+
mArgs.mainColour = getBackgroundColor().withAlpha(args.mainColour.getAlpha());
339339
mArgs.darkShadowColor = getDarkShadowColor();
340340
mArgs.brightShadowColor = getBrightShadowColor();
341341
return zlinterface::drawShadowEllipse(g, boxBounds, cornerSize, mArgs);
@@ -346,7 +346,7 @@ namespace zlinterface {
346346
float cornerSize,
347347
const fillShadowEllipseArgs &args) {
348348
auto mArgs = args;
349-
mArgs.mainColour = getBackgroundColor();
349+
mArgs.mainColour = getBackgroundColor().withAlpha(args.mainColour.getAlpha());
350350
mArgs.darkShadowColor = getDarkShadowColor();
351351
mArgs.brightShadowColor = getBrightShadowColor();
352352
return zlinterface::drawInnerShadowEllipse(g, boxBounds, cornerSize, mArgs);

Source/Panel/CenterPanel/center_panel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ namespace zlpanel {
1515
CenterPanel::CenterPanel(PluginProcessor &p, zlinterface::UIBase &base) :
1616
plotPanel(p, base), monitorPanel(p, base) {
1717
processorRef = &p;
18-
openGLContext.attachTo(*this);
19-
2018
uiBase = &base;
2119

2220
processorRef->states.addParameterListener(zlstate::monitorSetting::ID, this);
2321
monitorSetting.store(static_cast<int>(*p.states.getRawParameterValue(zlstate::monitorSetting::ID)));
2422

23+
2524
addAndMakeVisible(monitorPanel);
2625
addAndMakeVisible(plotPanel);
27-
26+
27+
openGLContext.setComponentPaintingEnabled(true);
28+
openGLContext.attachTo(*this);
29+
2830
setSize(200, 100);
2931
}
3032

33+
void CenterPanel::attachOpenGL(juce::Component &component) {
34+
openGLContext.attachTo(component);
35+
}
36+
3137
CenterPanel::~CenterPanel() {
3238
openGLContext.detach();
3339
processorRef->states.removeParameterListener(zlstate::monitorSetting::ID, this);

Source/Panel/CenterPanel/center_panel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ namespace zlpanel {
2626
public:
2727
explicit CenterPanel(PluginProcessor &p, zlinterface::UIBase &base);
2828

29+
void attachOpenGL(juce::Component &component);
30+
2931
~CenterPanel() override;
3032

3133
void paint(juce::Graphics &g) override;
3234

3335
void resized() override;
3436

35-
void setFontSize(float fSize);
36-
3737
void parameterChanged(const juce::String &parameterID, float newValue) override;
3838

3939
private:

Source/Panel/CenterPanel/monitor_sub_panel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ namespace zlpanel {
3939

4040
void resized() override;
4141

42-
void setFontSize(float fSize);
43-
4442
void setMonitorVisible(bool f);
4543

4644
void setTimeInSecond(float v);

Source/Panel/StatePanel/logo_panel.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111
#include "logo_panel.h"
1212

1313
namespace zlpanel {
14-
LogoPanel::LogoPanel(zlinterface::UIBase &base) :
14+
LogoPanel::LogoPanel(PluginProcessor &p,
15+
zlinterface::UIBase &base) :
1516
brandDrawable(juce::Drawable::createFromImageData(BinaryData::zlaudio_svg, BinaryData::zlaudio_svgSize)),
1617
logoDrawable(juce::Drawable::createFromImageData(BinaryData::logo_svg, BinaryData::logo_svgSize)) {
18+
processorRef = &p;
1719
uiBase = &base;
20+
uiBase->setStyle(static_cast<size_t>(*p.states.getRawParameterValue(zlstate::uiStyle::ID)));
21+
triggerAsyncUpdate();
1822
}
1923

2024
LogoPanel::~LogoPanel() = default;
2125

2226
void LogoPanel::paint(juce::Graphics &g) {
23-
brandDrawable->replaceColour(juce::Colour(87, 96, 110), uiBase->getTextColor());
24-
logoDrawable->replaceColour(juce::Colour(87, 96, 110), uiBase->getTextColor());
27+
auto tempBrand = brandDrawable->createCopy();
28+
auto tempLogo = logoDrawable->createCopy();
29+
tempBrand->replaceColour(juce::Colour(87, 96, 110), uiBase->getTextColor());
30+
tempLogo->replaceColour(juce::Colour(87, 96, 110), uiBase->getTextColor());
31+
2532
auto bound = getLocalBounds().toFloat();
2633
auto padding = juce::jmin(bound.getWidth() * 0.1f, bound.getHeight() * 0.1f);
2734
bound = bound.withSizeKeepingCentre(bound.getWidth() - padding, bound.getHeight() - padding);
@@ -33,12 +40,29 @@ namespace zlpanel {
3340
auto height = juce::jmin(bound.getHeight(), bound.getWidth() / widthOverHeight);
3441
bound = bound.withSizeKeepingCentre(width, height);
3542

36-
brandDrawable->setTransform(
43+
tempBrand->setTransform(
3744
juce::AffineTransform::scale(bound.getHeight() / static_cast<float>(brandDrawable->getHeight())));
38-
brandDrawable->drawAt(g, bound.getX(), bound.getY(), 1.0f);
45+
tempBrand->drawAt(g, bound.getX(), bound.getY(), 1.0f);
3946

40-
logoDrawable->setTransform(
47+
tempLogo->setTransform(
4148
juce::AffineTransform::scale(bound.getHeight() / static_cast<float>(logoDrawable->getHeight())));
42-
logoDrawable->drawAt(g, bound.getX() + bound.getHeight() * (widthOverHeight - logoWOH), bound.getY(), 1.0f);
49+
tempLogo->drawAt(g, bound.getX() + bound.getHeight() * (widthOverHeight - logoWOH), bound.getY(), 1.0f);
50+
}
51+
52+
void LogoPanel::mouseDoubleClick(const juce::MouseEvent &event) {
53+
juce::ignoreUnused(event);
54+
auto styleID = static_cast<size_t>(*processorRef->states.getRawParameterValue(zlstate::uiStyle::ID));
55+
styleID = (styleID + 1) % (zlstate::uiStyle::maxV + 1);
56+
uiBase->setStyle(styleID);
57+
processorRef->states.getParameter(zlstate::uiStyle::ID)->setValueNotifyingHost(
58+
zlstate::uiStyle::convertTo01(static_cast<float>(styleID)));
59+
triggerAsyncUpdate();
60+
}
61+
62+
void LogoPanel::handleAsyncUpdate() {
63+
if (getTopLevelComponent() != nullptr) {
64+
auto topComponent = getTopLevelComponent();
65+
topComponent->repaint(topComponent->getBounds());
66+
}
4367
}
4468
}

Source/Panel/StatePanel/logo_panel.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@
1414
#include "BinaryData.h"
1515
#include "juce_audio_processors/juce_audio_processors.h"
1616
#include "../../GUI/interface_definitions.h"
17+
#include "../../State/state_definitions.h"
18+
#include "../../PluginProcessor.h"
1719

1820
namespace zlpanel {
19-
class LogoPanel : public juce::Component {
21+
class LogoPanel : public juce::Component, private juce::AsyncUpdater {
2022
public:
21-
explicit LogoPanel(zlinterface::UIBase &base);
23+
explicit LogoPanel(PluginProcessor &p,
24+
zlinterface::UIBase &base);
2225

2326
~LogoPanel() override;
2427

2528
void paint(juce::Graphics &g) override;
2629

30+
void mouseDoubleClick(const juce::MouseEvent &event) override;
31+
2732
private:
2833
const std::unique_ptr<juce::Drawable> brandDrawable, logoDrawable;
2934
zlinterface::UIBase *uiBase;
35+
PluginProcessor *processorRef;
36+
37+
void handleAsyncUpdate() override;
3038
};
3139
}
3240
#endif //ZLLMATCH_LOGOPANEL_H

Source/Panel/StatePanel/state_panel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
#include "state_panel.h"
1212

1313
namespace zlpanel {
14-
StatePanel::StatePanel(juce::AudioProcessorValueTreeState &parameters,
15-
zlinterface::UIBase &base) : logoPanel(base) {
14+
StatePanel::StatePanel(PluginProcessor &p,
15+
zlinterface::UIBase &base) : logoPanel(p, base) {
1616
addAndMakeVisible(logoPanel);
1717
std::array<std::string, 2> buttonID{zlstate::showComputer::ID, zlstate::showDetector::ID};
18-
attachButtons<zlinterface::ButtonComponent, 2>(*this, buttonList, buttonAttachments, buttonID, parameters, base);
18+
attachButtons<zlinterface::ButtonComponent, 2>(*this, buttonList, buttonAttachments, buttonID, p.states, base);
1919

2020
std::array<std::string, 1> boxID{zlstate::monitorSetting::ID};
21-
attachBoxes<zlinterface::ComboboxComponent, 1>(*this, boxList, boxAttachments, boxID, parameters, base);
21+
attachBoxes<zlinterface::ComboboxComponent, 1>(*this, boxList, boxAttachments, boxID, p.states, base);
2222

2323
uiBase = &base;
2424
}

Source/Panel/StatePanel/state_panel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace zlpanel {
2222

2323
class StatePanel : public juce::Component {
2424
public:
25-
explicit StatePanel(juce::AudioProcessorValueTreeState &parameters, zlinterface::UIBase &base);
25+
explicit StatePanel(PluginProcessor &p, zlinterface::UIBase &base);
2626

2727
~StatePanel() override;
2828

Source/Panel/main_panel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace zlpanel {
1414
MainPanel::MainPanel(PluginProcessor &p) :
1515
uiBase(),
16-
statePanel(p.states, uiBase),
16+
statePanel(p, uiBase),
1717
centerPanel(p, uiBase),
1818
settingPanel(p.parameters, uiBase) {
1919
// meterPanel(&p.getMeterIn(), &p.getMeterEnd()) {
@@ -23,6 +23,10 @@ namespace zlpanel {
2323
// addAndMakeVisible(meterPanel);
2424
}
2525

26+
void MainPanel::attachOpenGL(juce::Component &component) {
27+
centerPanel.attachOpenGL(component);
28+
}
29+
2630
MainPanel::~MainPanel() = default;
2731

2832
void MainPanel::paint(juce::Graphics &g) {
@@ -31,6 +35,8 @@ namespace zlpanel {
3135
float fontSize = bound.getHeight() * 0.0514f * 0.5f;
3236
bound = uiBase.fillRoundedShadowRectangle(g, bound, fontSize * 0.5f, {});
3337
uiBase.fillRoundedInnerShadowRectangle(g, bound, fontSize * 0.5f, {.blurRadius=0.45f, .flip=true});
38+
39+
centerPanel.repaint();
3440
}
3541

3642
void MainPanel::resized() {

Source/Panel/main_panel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace zlpanel {
2525
public:
2626
explicit MainPanel(PluginProcessor &p);
2727

28+
void attachOpenGL(juce::Component &component);
29+
2830
~MainPanel() override;
2931

3032
void paint(juce::Graphics &g) override;

0 commit comments

Comments
 (0)