Skip to content

Commit 9a01005

Browse files
committed
Optimise statusbar, basic implementation for console notifications
1 parent 7508699 commit 9a01005

9 files changed

Lines changed: 47 additions & 28 deletions

File tree

Source/Components/TouchSelectionHelper.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ class TouchSelectionHelper final : public Component
251251
}
252252
}
253253

254-
void render(NVGcontext* nvg) override
255-
{
256-
componentImage.renderJUCEComponent(nvg, *this, 2.0f);
257-
}
258-
259254
private:
260255
void paint(Graphics& g) override
261256
{
@@ -270,6 +265,5 @@ class TouchSelectionHelper final : public Component
270265
}
271266

272267
PluginEditor* editor;
273-
NVGImage componentImage;
274268
OwnedArray<MainToolbarButton> actionButtons;
275269
};

Source/Pd/Instance.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,23 @@ class ConsoleMessageHandler final : public Timer {
130130
auto item = std::tuple<void*, SmallString, bool>();
131131
int numReceived = 0;
132132
bool newWarning = false;
133+
SmallString lastMessage;
134+
bool lastIsWarning = false;
133135

134136
while (pendingMessages.try_dequeue(item)) {
135137
auto& [object, message, type] = item;
136138
addMessage(object, message.toString(), type);
137139

138140
numReceived++;
139141
newWarning = newWarning || type;
142+
lastMessage = message;
143+
lastIsWarning = type;
144+
140145
}
141146

142147
// Check if any item got assigned
143148
if (numReceived) {
144-
instance->updateConsole(numReceived, newWarning);
149+
instance->updateConsole(lastMessage, lastIsWarning, numReceived, newWarning);
145150
}
146151
}
147152

Source/Pd/Instance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class Instance : public AsyncUpdater {
221221
static void registerLuaClass(char const* object);
222222
static bool isLuaClass(hash32 objectNameHash);
223223

224-
virtual void updateConsole(int numMessages, bool newWarning) = 0;
224+
virtual void updateConsole(SmallString const& message, bool isWarning, int numMessages, bool newWarning) = 0;
225225

226226
virtual void titleChanged() = 0;
227227

Source/PluginEditor.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <juce_gui_basics/juce_gui_basics.h>
88
#include <juce_audio_processors/juce_audio_processors.h>
9+
#include <juce_animation/juce_animation.h>
910

1011
#include "Utility/Config.h"
1112
#include "Utility/Fonts.h"
@@ -26,6 +27,7 @@
2627
#include "Canvas.h"
2728
#include "Connection.h"
2829
#include "Components/ConnectionMessageDisplay.h"
30+
#include "Components/ConsoleMessageDisplay.h"
2931
#include "Dialogs/Dialogs.h"
3032
#include "Statusbar.h"
3133
#include "Toolbar.h"
@@ -104,6 +106,7 @@ PluginEditor::PluginEditor(PluginProcessor& p)
104106
return true; })
105107
, tabComponent(this)
106108
, pluginMode(nullptr)
109+
, consoleMessageDisplay(std::make_unique<ConsoleMessageDisplay>(this))
107110
, touchSelectionHelper(std::make_unique<TouchSelectionHelper>(this))
108111
, recentlyOpenedPanelSelector(Icons::Home, "Home")
109112
, libraryPanelSelector(Icons::ItemGrid, "Library")
@@ -260,6 +263,9 @@ PluginEditor::PluginEditor(PluginProcessor& p)
260263
statusbar->setAlwaysOnTop(true);
261264
addAndMakeVisible(statusbar.get());
262265

266+
consoleMessageDisplay->setAlwaysOnTop(true);
267+
addAndMakeVisible(consoleMessageDisplay.get());
268+
263269
audioToolbar = std::make_unique<AudioToolbar>(pd, this);
264270
audioToolbar->setAlwaysOnTop(true);
265271
addAndMakeVisible(audioToolbar.get());
@@ -449,19 +455,27 @@ void PluginEditor::renderArea(NVGcontext* nvg, Rectangle<int> const area)
449455
} else {
450456
tabComponent.renderArea(nvg, area);
451457

458+
if(sidebar->isHidden())
459+
sidebar->renderButtonsOnCanvas(nvg);
460+
461+
Graphics g(*getNanoLLGC());
452462
if (touchSelectionHelper && touchSelectionHelper->getParentComponent() && touchSelectionHelper->isVisible() && area.intersects(touchSelectionHelper->getBounds() - nvgSurface.getPosition())) {
453463
NVGScopedState scopedState(nvg);
454464
nvgTranslate(nvg, touchSelectionHelper->getX() - nvgSurface.getX(), touchSelectionHelper->getY() - nvgSurface.getY());
455-
touchSelectionHelper->render(nvg);
465+
touchSelectionHelper->paintEntireComponent(g, false);
456466
}
457467

458-
if(sidebar->isHidden())
459-
sidebar->renderButtonsOnCanvas(nvg);
460-
461468
{
462469
NVGScopedState scopedState(nvg);
463470
nvgTranslate(nvg, statusbar->getX() - nvgSurface.getX(), statusbar->getY() - nvgSurface.getY());
464-
statusbar->render(nvg);
471+
statusbar->paintEntireComponent(g, false);
472+
}
473+
474+
if(consoleMessageDisplay->isVisible())
475+
{
476+
NVGScopedState scopedState(nvg);
477+
nvgTranslate(nvg, consoleMessageDisplay->getX() - nvgSurface.getX(), consoleMessageDisplay->getY() - nvgSurface.getY());
478+
consoleMessageDisplay->paintEntireComponent(g, false);
465479
}
466480
}
467481
}
@@ -590,14 +604,15 @@ void PluginEditor::resized()
590604
redoButton.setBounds(2 * buttonDistance + offset, 0, buttonSize, buttonSize);
591605
addObjectMenuButton.setBounds(3 * buttonDistance + offset, 0, buttonSize, buttonSize);
592606

607+
auto statusbarBounds = getLocalBounds().removeFromBottom(46).translated(0, -12);
593608
if (SettingsFile::getInstance()->isUsingTouchMode()) {
594-
auto statusbarBounds = getLocalBounds().removeFromBottom(48).translated(0, -12);
595-
touchSelectionHelper->setBounds(statusbarBounds.withSizeKeepingCentre(192, 48));
609+
touchSelectionHelper->setBounds(statusbarBounds.withSizeKeepingCentre(192, 46));
596610
statusbar->setBounds(statusbarBounds.removeFromLeft(208).translated(4, 0));
611+
consoleMessageDisplay->setBounds(statusbarBounds.removeFromRight(consoleMessageDisplay->getDesiredWidth() + 2).translated(-8, 0));
597612
}
598613
else {
599-
auto statusbarBounds = getLocalBounds().removeFromBottom(48).withSizeKeepingCentre(204, 48).translated(0, -12);
600-
statusbar->setBounds(statusbarBounds);
614+
statusbar->setBounds(statusbarBounds.withSizeKeepingCentre(204, 46));
615+
consoleMessageDisplay->setBounds(statusbarBounds.removeFromRight(consoleMessageDisplay->getDesiredWidth() + 2).translated(-8, 0));
601616
}
602617

603618
#if JUCE_IOS
@@ -878,6 +893,12 @@ void PluginEditor::installPackage(File const& file)
878893
}
879894
}
880895

896+
void PluginEditor::updateConsole(SmallString const& message, bool messageIsWarning, int numMessages, bool newWarning)
897+
{
898+
sidebar->updateConsole(numMessages, newWarning);
899+
if(sidebar->isHidden())
900+
consoleMessageDisplay->showMessage(message, messageIsWarning);
901+
}
881902

882903
TabComponent& PluginEditor::getTabComponent()
883904
{

Source/PluginEditor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TouchSelectionHelper;
3737
class WelcomePanel;
3838
class CalloutArea;
3939
class NVGGraphicsContext;
40+
class ConsoleMessageDisplay;
4041
class PluginEditor final : public AudioProcessorEditor
4142
, public Value::Listener
4243
, public ApplicationCommandTarget
@@ -96,6 +97,8 @@ class PluginEditor final : public AudioProcessorEditor
9697

9798
void installPackage(File const& file);
9899

100+
void updateConsole(SmallString const& message, bool isWarning, int numMessages, bool newWarning);
101+
99102
bool isInterestedInFileDrag(StringArray const& files) override;
100103
void filesDropped(StringArray const& files, int x, int y) override;
101104
void fileDragEnter(StringArray const&, int, int) override;
@@ -169,6 +172,7 @@ class PluginEditor final : public AudioProcessorEditor
169172

170173
public:
171174
std::unique_ptr<PluginMode> pluginMode;
175+
std::unique_ptr<ConsoleMessageDisplay> consoleMessageDisplay;
172176

173177
private:
174178
std::unique_ptr<TouchSelectionHelper> touchSelectionHelper;

Source/PluginProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,10 +2237,10 @@ void PluginProcessor::parseDataBuffer(XmlElement const& xml)
22372237
}
22382238
}
22392239

2240-
void PluginProcessor::updateConsole(int const numMessages, bool const newWarning)
2240+
void PluginProcessor::updateConsole(SmallString const& message, bool isWarning, int const numMessages, bool const newWarning)
22412241
{
2242-
for (auto const* editor : getEditors()) {
2243-
editor->sidebar->updateConsole(numMessages, newWarning);
2242+
for (auto* editor : getEditors()) {
2243+
editor->updateConsole(message, isWarning, numMessages, newWarning);
22442244
}
22452245
}
22462246

Source/PluginProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PluginProcessor final : public AudioProcessor
108108
void clearTextEditor(uint64_t ptr) override;
109109
bool isTextEditorDialogShown(uint64_t ptr) override;
110110

111-
void updateConsole(int numMessages, bool newWarning) override;
111+
void updateConsole(SmallString const& message, bool isWarning, int numMessages, bool newWarning) override;
112112

113113
void reloadAbstractions(File changedPatch, t_glist* except) override;
114114

Source/Statusbar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
#include <juce_gui_basics/juce_gui_basics.h>
8+
#include <juce_animation/juce_animation.h>
9+
810
#include "Utility/Config.h"
911
#include "Utility/Fonts.h"
1012

@@ -206,7 +208,6 @@ class CanvasModePicker final : public Component {
206208
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CanvasModePicker)
207209
};
208210

209-
// New statusbar
210211
Statusbar::Statusbar(PluginProcessor* processor, PluginEditor* e)
211212
: NVGComponent(this)
212213
, pd(processor)

Source/Statusbar.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class Statusbar final : public Component
5555

5656
~Statusbar() override;
5757

58-
void render(NVGcontext* nvg) override
59-
{
60-
componentImage.renderJUCEComponent(nvg, *this, 2.0f);
61-
}
62-
6358
void updateZoomLevel() { triggerAsyncUpdate(); }
6459

6560
void setEditButtonState(bool locked, bool present = false);
@@ -82,7 +77,6 @@ class Statusbar final : public Component
8277
std::unique_ptr<StatusbarButtonGroup> overlayGroup;
8378
std::unique_ptr<StatusbarButtonGroup> editModeGroup;
8479

85-
NVGImage componentImage;
8680
bool welcomePanelIsShown = false;
8781

8882
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Statusbar)

0 commit comments

Comments
 (0)