Skip to content

Commit 883944d

Browse files
authored
Merge pull request #33 from mpesonen/feature/resizableGUI
Feature: resizable GUI
2 parents bb36c64 + 6d19e4b commit 883944d

File tree

4 files changed

+76
-19
lines changed

4 files changed

+76
-19
lines changed

src/PluginEditor.cpp

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "PluginEditor.h"
1313

1414
//==============================================================================
15-
WaveNetVaAudioProcessorEditor::WaveNetVaAudioProcessorEditor (WaveNetVaAudioProcessor& p)
16-
: AudioProcessorEditor (&p), processor (p)
15+
WaveNetVaComponent::WaveNetVaComponent (WaveNetVaAudioProcessor& p)
16+
: processor (p)
1717
{
1818
// Make sure that before the constructor has finished, you've set the
1919
// editor's size to whatever you need it to
@@ -124,14 +124,11 @@ WaveNetVaAudioProcessorEditor::WaveNetVaAudioProcessorEditor (WaveNetVaAudioProc
124124
ampMasterKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20 );
125125
ampMasterKnob.setDoubleClickReturnValue(true, 0.5);
126126

127-
// Size of plugin GUI
128-
setSize (1085, 540);
129-
130127
processor.loadConfigAmp();
131128
resetImages();
132129
}
133130

134-
WaveNetVaAudioProcessorEditor::~WaveNetVaAudioProcessorEditor()
131+
WaveNetVaComponent::~WaveNetVaComponent()
135132
{
136133
ampPresenceKnob.setLookAndFeel(nullptr);
137134
ampCleanBassKnob.setLookAndFeel(nullptr);
@@ -146,7 +143,7 @@ WaveNetVaAudioProcessorEditor::~WaveNetVaAudioProcessorEditor()
146143
}
147144

148145
//==============================================================================
149-
void WaveNetVaAudioProcessorEditor::paint (Graphics& g)
146+
void WaveNetVaComponent::paint (Graphics& g)
150147
{
151148

152149
// Workaround for graphics on Windows builds (clipping code doesn't work correctly on Windows)
@@ -160,7 +157,7 @@ void WaveNetVaAudioProcessorEditor::paint (Graphics& g)
160157

161158
}
162159

163-
void WaveNetVaAudioProcessorEditor::resized()
160+
void WaveNetVaComponent::resized()
164161
{
165162
// This is generally where you'll want to lay out the positions of any
166163
// subcomponents in your editor..
@@ -183,7 +180,7 @@ void WaveNetVaAudioProcessorEditor::resized()
183180
ampLED.setBounds(975, 40, 15, 25);
184181
}
185182

186-
void WaveNetVaAudioProcessorEditor::buttonClicked(juce::Button* button)
183+
void WaveNetVaComponent::buttonClicked(juce::Button* button)
187184
{
188185
if (button == &ampOnButton) {
189186
ampOnButtonClicked();
@@ -192,7 +189,7 @@ void WaveNetVaAudioProcessorEditor::buttonClicked(juce::Button* button)
192189
}
193190
}
194191

195-
void WaveNetVaAudioProcessorEditor::ampOnButtonClicked() {
192+
void WaveNetVaComponent::ampOnButtonClicked() {
196193
if (processor.amp_state == 0) {
197194
processor.amp_state = 1;
198195
}
@@ -202,7 +199,7 @@ void WaveNetVaAudioProcessorEditor::ampOnButtonClicked() {
202199
resetImages();
203200
}
204201

205-
void WaveNetVaAudioProcessorEditor::ampCleanLeadButtonClicked() {
202+
void WaveNetVaComponent::ampCleanLeadButtonClicked() {
206203
if (processor.amp_lead == 1) {
207204
processor.amp_lead = 0;
208205
processor.loadConfigAmp();
@@ -217,7 +214,7 @@ void WaveNetVaAudioProcessorEditor::ampCleanLeadButtonClicked() {
217214
resetImages();
218215
}
219216

220-
void WaveNetVaAudioProcessorEditor::sliderValueChanged(Slider* slider)
217+
void WaveNetVaComponent::sliderValueChanged(Slider* slider)
221218
{
222219
// Amp
223220

@@ -238,7 +235,7 @@ void WaveNetVaAudioProcessorEditor::sliderValueChanged(Slider* slider)
238235

239236
}
240237

241-
void WaveNetVaAudioProcessorEditor::resetImages()
238+
void WaveNetVaComponent::resetImages()
242239
{
243240
if (processor.amp_state == 1 && processor.amp_lead == 1 ) {
244241
background_set = background_lead;
@@ -289,3 +286,45 @@ void WaveNetVaAudioProcessorEditor::resetImages()
289286
}
290287
repaint();
291288
}
289+
290+
float WaveNetVaComponent::getGuiScaleFactor()
291+
{
292+
return static_cast<float> (processor.gui_scale_factor);
293+
}
294+
295+
void WaveNetVaComponent::persistGuiScaleFactor(float scaleFactor)
296+
{
297+
processor.gui_scale_factor = static_cast<double> (scaleFactor);
298+
}
299+
300+
// Wrapper implementation
301+
WrappedWaveNetVaAudioProcessorEditor::WrappedWaveNetVaAudioProcessorEditor(WaveNetVaAudioProcessor& p)
302+
: AudioProcessorEditor(p), waveNetVaComponent(p)
303+
{
304+
addAndMakeVisible(waveNetVaComponent);
305+
306+
if (auto* constrainer = getConstrainer())
307+
{
308+
constrainer->setFixedAspectRatio(static_cast<double> (originalWidth) / static_cast<double> (originalHeight));
309+
constrainer->setSizeLimits(originalWidth / 4, originalHeight / 4, originalWidth * 2, originalHeight * 2);
310+
}
311+
312+
setResizable(true, true);
313+
float scaledWidth = static_cast<float> (originalWidth) * waveNetVaComponent.getGuiScaleFactor();
314+
float scaledHeight = static_cast<float> (originalHeight) * waveNetVaComponent.getGuiScaleFactor();
315+
setSize(scaledWidth, scaledHeight);
316+
resetImages();
317+
}
318+
319+
void WrappedWaveNetVaAudioProcessorEditor::resized()
320+
{
321+
const auto scaleFactor = static_cast<float> (getWidth()) / originalWidth;
322+
waveNetVaComponent.setTransform(AffineTransform::scale(scaleFactor));
323+
waveNetVaComponent.setBounds(0, 0, originalWidth, originalHeight);
324+
waveNetVaComponent.persistGuiScaleFactor(scaleFactor);
325+
}
326+
327+
void WrappedWaveNetVaAudioProcessorEditor::resetImages()
328+
{
329+
waveNetVaComponent.resetImages();
330+
}

src/PluginEditor.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717
//==============================================================================
1818
/**
1919
*/
20-
class WaveNetVaAudioProcessorEditor : public AudioProcessorEditor,
20+
class WaveNetVaComponent : public Component,
2121
private Button::Listener,
2222
private Slider::Listener
2323

2424
{
2525
public:
26-
WaveNetVaAudioProcessorEditor (WaveNetVaAudioProcessor&);
27-
~WaveNetVaAudioProcessorEditor();
26+
WaveNetVaComponent (WaveNetVaAudioProcessor&);
27+
~WaveNetVaComponent();
2828

2929
//==============================================================================
3030
void paint (Graphics&) override;
3131
void resized() override;
3232

3333
void resetImages();
34+
float getGuiScaleFactor();
35+
void persistGuiScaleFactor(float scaleFactor);
3436

3537
private:
3638
// This reference is provided as a quick way for your editor to
@@ -84,5 +86,18 @@ class WaveNetVaAudioProcessorEditor : public AudioProcessorEditor,
8486
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> presenceSliderAttach;
8587
std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> masterSliderAttach;
8688

87-
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveNetVaAudioProcessorEditor)
89+
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WaveNetVaComponent)
8890
};
91+
92+
class WrappedWaveNetVaAudioProcessorEditor : public AudioProcessorEditor
93+
{
94+
public:
95+
WrappedWaveNetVaAudioProcessorEditor(WaveNetVaAudioProcessor&);
96+
void resized() override;
97+
void resetImages();
98+
private:
99+
static constexpr int originalWidth { 1085 };
100+
static constexpr int originalHeight { 540 };
101+
102+
WaveNetVaComponent waveNetVaComponent;
103+
};

src/PluginProcessor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ bool WaveNetVaAudioProcessor::hasEditor() const
225225

226226
AudioProcessorEditor* WaveNetVaAudioProcessor::createEditor()
227227
{
228-
return new WaveNetVaAudioProcessorEditor (*this);
228+
return new WrappedWaveNetVaAudioProcessorEditor (*this);
229229
}
230230

231231
//==============================================================================
@@ -238,6 +238,7 @@ void WaveNetVaAudioProcessor::getStateInformation (MemoryBlock& destData)
238238
std::unique_ptr<XmlElement> xml (state.createXml());
239239
xml->setAttribute ("amp_state", amp_state);
240240
xml->setAttribute ("amp_lead", amp_lead);
241+
xml->setAttribute ("gui_scale_factor", gui_scale_factor);
241242
copyXmlToBinary (*xml, destData);
242243
}
243244

@@ -255,7 +256,8 @@ void WaveNetVaAudioProcessor::setStateInformation (const void* data, int sizeInB
255256
treeState.replaceState (juce::ValueTree::fromXml (*xmlState));
256257
amp_state = xmlState->getBoolAttribute ("amp_state");
257258
amp_lead = xmlState->getBoolAttribute ("amp_lead");
258-
if (auto* editor = dynamic_cast<WaveNetVaAudioProcessorEditor*> (getActiveEditor()))
259+
gui_scale_factor = xmlState->getDoubleAttribute ("gui_scale_factor", 1.0);
260+
if (auto* editor = dynamic_cast<WrappedWaveNetVaAudioProcessorEditor*> (getActiveEditor()))
259261
editor->resetImages();
260262
}
261263
}

src/PluginProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class WaveNetVaAudioProcessor : public AudioProcessor
9191
int amp_state = 1; // 0 = off, 1 = on
9292
int amp_lead = 1; // 1 = clean, 0 = lead
9393
int custom_tone = 0; // 0 = custom tone loaded, 1 = default channel tone
94+
double gui_scale_factor = 1.0;
9495
File loaded_tone;
9596
juce::String loaded_tone_name;
9697

0 commit comments

Comments
 (0)