Skip to content

Commit d8c1452

Browse files
committed
Update control panel buttons
1 parent a05ac62 commit d8c1452

File tree

2 files changed

+88
-26
lines changed

2 files changed

+88
-26
lines changed

Source/UI/ControlPanel.cpp

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,61 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3333
#include "LookAndFeel/CustomLookAndFeel.h"
3434

3535
const int SIZE_AUDIO_EDITOR_MAX_WIDTH = 500;
36-
//const int SIZE_AUDIO_EDITOR_MIN_WIDTH = 250;
3736

38-
ForceNewDirectoryButton::ForceNewDirectoryButton () : Button ("ForceNewDirectory")
37+
NewDirectoryButton::NewDirectoryButton() : Button ("NewDirectory")
3938
{
39+
//XmlDocument xmlDoc (R"(
40+
// <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
41+
// fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round"
42+
// stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-folder-plus">
43+
// <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 19h-7a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v3.5" />
44+
//<path d="M16 19h6" /><path d="M19 16v6" /></svg>)");
45+
4046
XmlDocument xmlDoc (R"(
41-
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-lock" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="currentColor" stroke-linecap="round" stroke-linejoin="round">
42-
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
43-
<path d="M5 13a2 2 0 0 1 2 -2h10a2 2 0 0 1 2 2v6a2 2 0 0 1 -2 2h-10a2 2 0 0 1 -2 -2v-6z" fill="currentColor" />
44-
<path d="M11 16a1 1 0 1 0 2 0a1 1 0 0 0 -2 0" fill="currentColor" />
45-
<path d="M8 11v-4a4 4 0 1 1 8 0v4" fill="currentColor"/>
46-
</svg>)");
47+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-folder"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 3a1 1 0 0 1 .608 .206l.1 .087l2.706 2.707h6.586a3 3 0 0 1 2.995 2.824l.005 .176v8a3 3 0 0 1 -2.824 2.995l-.176 .005h-14a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-11a3 3 0 0 1 2.824 -2.995l.176 -.005h4z" /></svg>)");
4748

48-
forceNewDirectoryIcon = Drawable::createFromSVG (*xmlDoc.getDocumentElement().get());
49+
//XmlDocument xmlDoc (R"(
50+
// <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-lock"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2a5 5 0 0 1 5 5v3a3 3 0 0 1 3 3v6a3 3 0 0 1 -3 3h-10a3 3 0 0 1 -3 -3v-6a3 3 0 0 1 3 -3v-3a5 5 0 0 1 5 -5m0 12a2 2 0 0 0 -1.995 1.85l-.005 .15a2 2 0 1 0 2 -2m0 -10a3 3 0 0 0 -3 3v3h6v-3a3 3 0 0 0 -3 -3" /></svg>)");
51+
52+
newDirectoryIcon = Drawable::createFromSVG (*xmlDoc.getDocumentElement().get());
53+
54+
newDirectoryIcon->replaceColour (Colours::black, Colours::black);
4955

5056
setClickingTogglesState (true);
57+
}
58+
59+
void NewDirectoryButton::paintButton (Graphics& g, bool isMouseOver, bool isButtonDown)
60+
{
61+
Colour buttonColour;
5162

63+
if (getToggleState())
64+
buttonColour = findColour (ThemeColours::highlightedFill);
65+
else
66+
buttonColour = findColour (ThemeColours::controlPanelBackground);
67+
68+
if (isMouseOver)
69+
buttonColour = buttonColour.brighter (0.2f);
70+
71+
g.setColour (Colours::black);
72+
g.fillRoundedRectangle (0, 0, getWidth(), getHeight(), 5);
73+
g.setColour (buttonColour);
74+
g.fillRoundedRectangle (1, 1, getWidth() - 2, getHeight() - 2, 3);
75+
76+
g.setColour (Colours::black);
77+
newDirectoryIcon->drawWithin (g, juce::Rectangle<float>(2,2.5,18,18), RectanglePlacement::centred, 1.0f);
78+
g.setColour (buttonColour);
79+
g.drawRect (10, 9, 2, 6);
80+
g.drawRect (8, 11, 6, 2);
81+
}
82+
83+
ForceNewDirectoryButton::ForceNewDirectoryButton() : Button ("ForceNewDirectory")
84+
{
85+
XmlDocument xmlDoc (R"(
86+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-lock"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2a5 5 0 0 1 5 5v3a3 3 0 0 1 3 3v6a3 3 0 0 1 -3 3h-10a3 3 0 0 1 -3 -3v-6a3 3 0 0 1 3 -3v-3a5 5 0 0 1 5 -5m0 12a2 2 0 0 0 -1.995 1.85l-.005 .15a2 2 0 1 0 2 -2m0 -10a3 3 0 0 0 -3 3v3h6v-3a3 3 0 0 0 -3 -3" /></svg>)");
87+
88+
forceNewDirectoryIcon = Drawable::createFromSVG (*xmlDoc.getDocumentElement().get());
89+
90+
setClickingTogglesState (true);
5291
}
5392

5493
void ForceNewDirectoryButton::paintButton (Graphics& g, bool isMouseOver, bool isButtonDown)
@@ -58,7 +97,7 @@ void ForceNewDirectoryButton::paintButton (Graphics& g, bool isMouseOver, bool i
5897
if (getToggleState())
5998
buttonColour = findColour (ThemeColours::highlightedFill);
6099
else
61-
buttonColour = findColour (ThemeColours::defaultText);
100+
buttonColour = findColour (ThemeColours::controlPanelText);
62101

63102
if (isMouseOver)
64103
buttonColour = buttonColour.brighter (0.2f);
@@ -152,7 +191,8 @@ void RecordButton::updateImages (bool recordingIsActive)
152191
setImages (&normal, &over, &down);
153192
}
154193

155-
CPUMeter::CPUMeter() : Label ("CPU Meter", "0.0"), cpu (0.0f)
194+
CPUMeter::CPUMeter() : Label ("CPU Meter", "0.0"),
195+
cpu (0.0f)
156196
{
157197
font = FontOptions ("Silkscreen", "Regular", 14);
158198

@@ -375,8 +415,8 @@ void Clock::mouseDown (const MouseEvent& e)
375415
}
376416

377417
ControlPanel::ControlPanel (ProcessorGraph* graph_, AudioComponent* audio_, bool isConsoleApp_)
378-
: graph (graph_),
379-
audio (audio_),
418+
: graph (graph_),
419+
audio (audio_),
380420
isConsoleApp (isConsoleApp_)
381421
{
382422
AccessClass::setControlPanel (this);
@@ -420,16 +460,15 @@ ControlPanel::ControlPanel (ProcessorGraph* graph_, AudioComponent* audio_, bool
420460
recordOptionsButton->setTooltip ("Configure options for selected record engine");
421461
addChildComponent (recordOptionsButton.get());
422462

423-
newDirectoryButton = std::make_unique<UtilityButton> ("+");
424-
newDirectoryButton->setFont (FontOptions ("Silkscreen", "Regular", 15));
463+
newDirectoryButton = std::make_unique<NewDirectoryButton>();
425464
newDirectoryButton->setEnabled (false);
426465
newDirectoryButton->addListener (this);
427466
newDirectoryButton->setTooltip ("Start a new data directory for next recording");
428467
newDirectoryButton->setToggleState (true, sendNotification);
429468
newDirectoryButton->setClickingTogglesState (true);
430469
addChildComponent (newDirectoryButton.get());
431470

432-
forceNewDirectoryButton = std::make_unique<ForceNewDirectoryButton> ();
471+
forceNewDirectoryButton = std::make_unique<ForceNewDirectoryButton>();
433472
forceNewDirectoryButton->setEnabled (true);
434473
forceNewDirectoryButton->addListener (this);
435474
forceNewDirectoryButton->setTooltip ("Force a new data directory for each recording");
@@ -542,7 +581,6 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
542581

543582
graph->startAcquisition(); // inform processors that acquisition will start
544583

545-
546584
if (recordingShouldAlsoStart)
547585
{
548586
startRecording();
@@ -563,9 +601,8 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
563601
recordSelector->setEnabled (false); // why is this outside the "if" statement?
564602
recordOptionsButton->setEnabled (false);
565603
}
566-
604+
567605
audio->beginCallbacks(); // starts acquisition callbacks
568-
569606
}
570607
}
571608

@@ -950,7 +987,7 @@ void ControlPanel::componentBeingDeleted (Component& component)
950987
filenameText->setButtonText (generateFilenameFromFields (true));
951988

952989
//TODO: Assumes any change in filename settings should start a new directory next recording
953-
if (!newDirectoryButton->getToggleState())
990+
if (! newDirectoryButton->getToggleState())
954991
newDirectoryButton->setToggleState (true, dontSendNotification);
955992

956993
CoreServices::saveRecoveryConfig();
@@ -991,18 +1028,21 @@ void ControlPanel::buttonClicked (Button* button)
9911028
if (button == newDirectoryButton.get())
9921029
{
9931030
//Setting the button state only takes effect on the next recording
1031+
9941032
return;
9951033
}
9961034

9971035
if (button == forceNewDirectoryButton.get())
9981036
{
999-
if (button->getToggleState()) {
1037+
if (button->getToggleState())
1038+
{
10001039
newDirectoryButton->setToggleState (true, dontSendNotification);
10011040
newDirectoryButton->setEnabled (false);
10021041
}
10031042
else
10041043
{
1005-
newDirectoryButton->setEnabled (true);
1044+
if (hasRecorded)
1045+
newDirectoryButton->setEnabled (true);
10061046
}
10071047
return;
10081048
}
@@ -1262,7 +1302,8 @@ String ControlPanel::getRecordingDirectoryName()
12621302
void ControlPanel::createNewRecordingDirectory()
12631303
{
12641304
//TODO: Remove depdendency on button states/callbacks
1265-
MessageManager::callAsync ([this] { buttonClicked (newDirectoryButton.get()); });
1305+
MessageManager::callAsync ([this]
1306+
{ buttonClicked (newDirectoryButton.get()); });
12661307
}
12671308

12681309
String ControlPanel::getRecordingDirectoryPrependText()
@@ -1395,15 +1436,15 @@ void ControlPanel::setRecordingDirectoryBaseText (String text)
13951436

13961437
String ControlPanel::generateFilenameFromFields (bool usePlaceholderText)
13971438
{
1398-
13991439
String filename = "";
14001440

14011441
for (auto& field : filenameFields) //loops in order through prepend, main, append
14021442
{
14031443
filename += field->getNextValue (usePlaceholderText);
14041444
}
14051445

1406-
MessageManager::callAsync ([this, filename] { filenameText->setButtonText (filename); });
1446+
MessageManager::callAsync ([this, filename]
1447+
{ filenameText->setButtonText (filename); });
14071448

14081449
return filename;
14091450
}

Source/UI/ControlPanel.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@
3838
#include "LookAndFeel/CustomLookAndFeel.h"
3939
#include <queue>
4040

41+
/**
42+
43+
Triggers a new directory to be created at the start of each recording
44+
45+
*/
46+
class NewDirectoryButton : public Button
47+
{
48+
public:
49+
/** Constructor */
50+
NewDirectoryButton();
51+
52+
/** Destructor */
53+
~NewDirectoryButton() {}
54+
55+
void paintButton (Graphics& g, bool isMouseOver, bool isButtonDown) override;
56+
57+
private:
58+
std::unique_ptr<Drawable> newDirectoryIcon;
59+
};
60+
61+
4162
/**
4263
4364
Locks the new directory button to force new directories for each recording.
@@ -481,7 +502,7 @@ class TESTABLE ControlPanel : public Component,
481502
std::unique_ptr<CPUMeter> cpuMeter;
482503
std::unique_ptr<DiskSpaceMeter> diskMeter;
483504
std::unique_ptr<FilenameComponent> filenameComponent;
484-
std::unique_ptr<UtilityButton> newDirectoryButton;
505+
std::unique_ptr<NewDirectoryButton> newDirectoryButton;
485506
std::unique_ptr<ForceNewDirectoryButton> forceNewDirectoryButton;
486507
std::unique_ptr<CustomArrowButton> showHideRecordingOptionsButton;
487508
std::unique_ptr<RecordButton> recordButton;

0 commit comments

Comments
 (0)