Skip to content

Commit

Permalink
Fullscreen Mode for Standalone (surge-synthesizer#7167)
Browse files Browse the repository at this point in the history
Fullscreen mode now properly scales and unscales on full and unfull
To do this I introduced an intermediate component, so I also checked
acccessibility still works, and it does.

Closes surge-synthesizer#7104
  • Loading branch information
baconpaul authored Aug 10, 2023
1 parent f4a40d0 commit aad142f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
52 changes: 41 additions & 11 deletions src/surge-xt/SurgeSynthEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ SurgeSynthEditor::SurgeSynthEditor(SurgeSynthProcessor &p)

addKeyListener(this);

topLevelContainer = std::make_unique<juce::Component>();
addAndMakeVisible(*topLevelContainer);

sge = std::make_unique<SurgeGUIEditor>(this, processor.surge.get());

auto mcValue = Surge::Storage::getUserDefaultValue(&(this->processor.surge->storage),
Expand Down Expand Up @@ -198,13 +201,13 @@ SurgeSynthEditor::SurgeSynthEditor(SurgeSynthProcessor &p)
tempoLabel = std::make_unique<juce::Label>("Tempo", "Tempo");
sustainLabel = std::make_unique<juce::Label>("Sustain", "Sustain");

addChildComponent(*keyboard);
addChildComponent(*pitchwheel);
addChildComponent(*modwheel);
addChildComponent(*suspedal);
addChildComponent(*tempoLabel);
addChildComponent(*sustainLabel);
addChildComponent(*tempoTypein);
topLevelContainer->addChildComponent(*keyboard);
topLevelContainer->addChildComponent(*pitchwheel);
topLevelContainer->addChildComponent(*modwheel);
topLevelContainer->addChildComponent(*suspedal);
topLevelContainer->addChildComponent(*tempoLabel);
topLevelContainer->addChildComponent(*sustainLabel);
topLevelContainer->addChildComponent(*tempoTypein);

drawExtendedControls = sge->getShowVirtualKeyboard();

Expand Down Expand Up @@ -292,6 +295,19 @@ void SurgeSynthEditor::handleAsyncUpdate() {}
void SurgeSynthEditor::paint(juce::Graphics &g)
{
g.fillAll(findColour(SurgeJUCELookAndFeel::SurgeColourIds::tempoBackgroundId));

#if DEBUG_FULLSCREENBOUNDS
/* For debugging fullscreen */
g.setColour(juce::Colours::red);
for (int x = 100; x < getWidth(); x += 100)
{
g.drawLine(x, 0, x, getHeight(), 1);
}
for (int y = 100; y < getWidth(); y += 100)
{
g.drawLine(0, y, getWidth(), y, 1);
}
#endif
}

void SurgeSynthEditor::idle() { sge->idle(); }
Expand Down Expand Up @@ -339,6 +355,7 @@ void SurgeSynthEditor::reapplySurgeComponentColours()

void SurgeSynthEditor::resized()
{
topLevelContainer->setBounds(getLocalBounds());
drawExtendedControls = sge->getShowVirtualKeyboard();

auto w = getWidth();
Expand All @@ -356,21 +373,32 @@ void SurgeSynthEditor::resized()
{
if (cdw->isFullScreen())
{
auto b = getLocalBounds();
auto xw = 1.f * sge->getWindowSizeX() / b.getWidth();
auto xh = 1.f *
(sge->getWindowSizeY() +
(drawExtendedControls ? extraYSpaceForVirtualKeyboard : 0)) /
b.getHeight();

auto nz = std::min(1.0 / xw, 1.0 / xh);
auto snz = nz / sge->getZoomFactor() * 100.f;

topLevelContainer->setTransform(juce::AffineTransform().scaled(snz));

// target width
auto tw = sge->getWindowSizeX() * sge->getZoomFactor() * 0.01f;
auto tw = sge->getWindowSizeX() * sge->getZoomFactor() * 0.01 * snz;
auto th = (sge->getWindowSizeY() +
(drawExtendedControls ? extraYSpaceForVirtualKeyboard : 0)) *
sge->getZoomFactor() * 0.01f;
sge->getZoomFactor() * 0.01 * snz;

auto b = getLocalBounds();
auto pw = (b.getWidth() - tw) / 2.0;
auto ph = (b.getHeight() - th) / 2.0;

// turn off aspect ratio
if (getConstrainer())
getConstrainer()->setFixedAspectRatio(0.f);

sge->moveTopLeftTo(pw, ph);
sge->moveTopLeftTo(std::round(pw / snz), std::round(ph / snz));
return;
}
comp = nullptr;
Expand All @@ -384,6 +412,8 @@ void SurgeSynthEditor::resized()
sge->moveTopLeftTo(0, 0);
}

topLevelContainer->setTransform(juce::AffineTransform());

auto b = getLocalBounds();
auto wR = 1.0 * w / sge->getWindowSizeX();
auto hR = 1.0 * h / sge->getWindowSizeY();
Expand Down
2 changes: 2 additions & 0 deletions src/surge-xt/SurgeSynthEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class SurgeSynthEditor : public juce::AudioProcessorEditor,
std::unique_ptr<juce::Label> tempoLabel, sustainLabel;
std::unique_ptr<juce::TextEditor> tempoTypein;

std::unique_ptr<juce::Component> topLevelContainer;

/* Drag and drop */
bool isInterestedInFileDrag(const juce::StringArray &files) override;
void filesDropped(const juce::StringArray &files, int, int) override;
Expand Down
2 changes: 1 addition & 1 deletion src/surge-xt/gui/SurgeGUIEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2340,7 +2340,7 @@ bool SurgeGUIEditor::open(void *parent)
frame->setBounds(0, 0, currentSkin->getWindowSizeX(), currentSkin->getWindowSizeY());
frame->setSurgeGUIEditor(this);

juceEditor->addAndMakeVisible(*frame);
juceEditor->topLevelContainer->addAndMakeVisible(*frame);
juceEditor->addKeyListener(this);

// TODO: SET UP JUCE EDITOR BETTER!
Expand Down

0 comments on commit aad142f

Please sign in to comment.