-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatchSavingDialogBox.cpp
84 lines (72 loc) · 2.48 KB
/
PatchSavingDialogBox.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
==============================================================================
PatchSavingDialogBox.cpp
Created: 12 Oct 2020 11:01:32am
Author: Hayden Setlik
==============================================================================
*/
#include "PatchSavingDialogBox.h"
PatchDialogBox::PatchDialogBox(PatchLoader* loader) : patchLoader(loader)
{
savePatchButton.addListener(this);
cancelButton.addListener(this);
addAndMakeVisible(&nameField);
nameField.setMultiLine(false);
nameField.setTextToShowWhenEmpty("Patch Name", UXPalette::lightGray);
nameField.setPopupMenuEnabled(false);
addAndMakeVisible(&savePatchButton);
savePatchButton.setButtonText("Save patch");
addAndMakeVisible(&cancelButton);
cancelButton.setButtonText("Cancel");
addAndMakeVisible(&typeBox);
int idx = 1;
for(auto t : PatchTypeStrings)
{
typeBox.addItem(t, idx);
++idx;
}
typeBox.setSelectedId(1);
}
void PatchDialogBox::paint(juce::Graphics &g)
{
g.fillAll(UXPalette::nearBlack);
auto cushion = getHeight() / 14.0f;
auto lightArea = getLocalBounds().toFloat().reduced(cushion);
g.setColour(UXPalette::darkGray1);
g.fillRect(lightArea);
auto labelFont = UXPalette::square(12.0f);
g.setFont(labelFont);
g.setColour(juce::Colours::white);
int w = getWidth() / 18;
int h = getHeight() / 8;
auto textBox = juce::Rectangle<int> {w, h, 8 * w, 2 * h};
g.drawText("Patch Name:", textBox, juce::Justification::left);
}
void PatchDialogBox::resized()
{
int w = getWidth() / 18;
int h = getHeight() / 12;
nameField.setBounds(w, 3.5 * h, 16 * w, h);
savePatchButton.setBounds(9 * w, 5 * h, 5 * w, 1.5 * h);
cancelButton.setBounds(15 * w, 5 * h, 2 * w, 1.5 * h);
typeBox.setBounds(w, 5 * h, 3 * w, 1.5 * h);
auto name = patchLoader->getCurrentPresetName();
auto type = patchLoader->getCurrentPresetType();
nameField.setText(name);
for(int i = 0; i < typeBox.getNumItems(); ++i)
{
if(typeBox.getItemText(i) == type)
typeBox.setSelectedItemIndex(i);
}
}
void PatchDialogBox::buttonClicked(juce::Button *button)
{
if(button == &savePatchButton)
{
auto patchName = nameField.getText();
patchLoader->savePreset(patchName, typeBox.getText());
}
nameField.clear();
setEnabled(false);
setVisible(false);
}