Skip to content

Commit 8f02017

Browse files
author
alcomposer
committed
Fix palette bar visibility when first run with default settings. Fix resizing of nvg surface when palette bar is hidden/shown with openGL
1 parent 7eb47bd commit 8f02017

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

Source/NVGSurface.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,12 @@ void NVGSurface::updateBufferSize()
211211
void NVGSurface::timerCallback()
212212
{
213213
updateBounds(newBounds);
214-
if (getBounds() == newBounds)
214+
if (getBounds() == newBounds) {
215215
stopTimer();
216+
// The editor will be full of junk from the buffer, so clear it
217+
if (renderThroughImage)
218+
editor->repaint();
219+
}
216220
}
217221
#endif
218222

@@ -231,9 +235,15 @@ bool NVGSurface::makeContextActive()
231235
// No need to make context active with Metal, so just check if we have initialised and return that
232236
return getView() != nullptr && nvg != nullptr && mnvgDevice(nvg) != nullptr;
233237
#else
234-
if (glContext)
235-
return glContext->makeActive();
236-
return false;
238+
bool ret = false;
239+
if (glContext) {
240+
ret = glContext->makeActive();
241+
242+
if (renderThroughImage)
243+
updateWindowContextVisibility();
244+
}
245+
246+
return ret;
237247
#endif
238248
}
239249

@@ -267,6 +277,8 @@ void NVGSurface::updateBounds(Rectangle<int> bounds)
267277
setBounds(bounds.withWidth(getWidth()));
268278

269279
resizing = true;
280+
281+
updateWindowContextVisibility();
270282
#else
271283
setBounds(bounds);
272284
#endif
@@ -304,7 +316,7 @@ void NVGSurface::render()
304316
// Flush message queue before rendering, to make sure all GUIs are up-to-date
305317
editor->pd->flushMessageQueue();
306318

307-
if (renderThroughImage) {
319+
if (renderThroughImage && !resizing) {
308320
auto const startTime = Time::getMillisecondCounter();
309321
if (startTime - lastRenderTime < 32) {
310322
return; // When rendering through juce::image, limit framerate to 30 fps
@@ -380,6 +392,12 @@ void NVGSurface::render()
380392

381393
if (renderThroughImage) {
382394
renderFrameToImage(backupRenderImage, invalidArea);
395+
if (resizing) {
396+
hresize = !hresize;
397+
resizing = false;
398+
}
399+
if (getBounds() != newBounds)
400+
startTimerHz(60);
383401
} else {
384402
needsBufferSwap = true;
385403
}

Source/NVGSurface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ class NVGSurface final :
107107

108108
void renderFrameToImage(Image& image, Rectangle<int> area);
109109

110+
void resized() override;
111+
110112
private:
111113
float calculateRenderScale() const;
112114

113-
void resized() override;
114-
115115
// Sets the surface context to render through floating window, or inside editor as image
116116
void updateWindowContextVisibility();
117117

Source/Sidebar/Palettes.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,18 @@ class Palettes final : public Component
583583
void settingsChanged(String const& name, var const& value) override
584584
{
585585
if (name == "show_palettes") {
586-
setVisible(value);
586+
auto const settingsTree = SettingsFile::getInstance()->getValueTree();
587+
// Check if we have recently opened files
588+
if (settingsTree.getChildWithName("RecentlyOpened").getNumChildren() || editor->getCurrentCanvas()) {
589+
if (isVisible() != static_cast<bool>(value)) {
590+
setVisible(value);
591+
592+
// Update the editor and nvg surface in case we are rendering through image
593+
// So that the editor can correctly set the size of the canvas area
594+
editor->resized();
595+
editor->nvgSurface.resized();
596+
}
597+
}
587598
}
588599
if (name == "centre_sidepanel_buttons") {
589600
resized();

0 commit comments

Comments
 (0)