@@ -91,14 +91,15 @@ class PluginMode final : public Component
9191 scaleComboBox.setColour (ComboBox::backgroundColourId, findColour (PlugDataColour::toolbarHoverColourId).withAlpha (0 .8f ));
9292 scaleComboBox.onChange = [this ] {
9393 auto const itemId = scaleComboBox.getSelectedId ();
94+ if (itemId == 0 ) return ;
9495 if (itemId == 8 ) {
9596 setKioskMode (true );
9697 return ;
9798 }
9899 if (selectedItemId != itemId) {
99100 selectedItemId = itemId;
100101 setWidthAndHeight (pluginScales[itemId - 1 ].floatScale );
101- pluginPreviousScale = pluginScales[itemId - 1 ].intScale ;
102+ patchPtr-> pluginModeScale = pluginScales[itemId - 1 ].intScale ;
102103 }
103104 };
104105
@@ -112,8 +113,6 @@ class PluginMode final : public Component
112113
113114 ~PluginMode () override
114115 {
115- pluginModeScaleMap[patchPtr->getPointer ().get ()] = pluginPreviousScale;
116-
117116 if (pluginModeLnf) {
118117 editor->setLookAndFeel (editor->pd ->lnf );
119118 editor->pd ->lnf ->setTheme (SettingsFile::getInstance ()->getTheme (lastTheme));
@@ -131,15 +130,9 @@ class PluginMode final : public Component
131130 return ;
132131#endif
133132 // set scale to the last scale that was set for this patches plugin mode
134- // if none was set, use 100% scale
135- if (pluginModeScaleMap.contains (patchPtr->getPointer ().get ())) {
136- int const previousScale = pluginModeScaleMap[patchPtr->getPointer ().get ()];
137- scaleComboBox.setText (String (previousScale) + String (" %" ), dontSendNotification);
138- setWidthAndHeight (previousScale * 0 .01f );
139- } else {
140- scaleComboBox.setText (String (static_cast <int >(editor->pd ->pluginModeScale * 100 )) + String (" %" ), dontSendNotification);
141- setWidthAndHeight (editor->pd ->pluginModeScale );
142- }
133+ int const previousScale = patchPtr->pluginModeScale ;
134+ scaleComboBox.setText (String (previousScale) + String (" %" ), dontSendNotification);
135+ setWidthAndHeight (previousScale * 0 .01f );
143136 }
144137
145138 void setWidthAndHeight (float const scale)
@@ -186,11 +179,11 @@ class PluginMode final : public Component
186179 }
187180 });
188181 }
189-
182+
190183 void render (NVGcontext* nvg, Rectangle<int > area)
191184 {
192185 NVGScopedState scopedState (nvg);
193- float scale = editor-> pd -> pluginModeScale ;
186+ auto const scale = pluginModeScale;
194187#if !JUCE_IOS
195188 if (isWindowFullscreen ())
196189#endif
@@ -207,6 +200,8 @@ class PluginMode final : public Component
207200
208201 void closePluginMode ()
209202 {
203+ isClosing = true ;
204+
210205 auto const constrainedNewBounds = windowBounds.withWidth (std::max (windowBounds.getWidth (), 890 )).withHeight (std::max (windowBounds.getHeight (), 650 ));
211206 if (auto * mainWindow = dynamic_cast <PlugDataWindow*>(editor->getTopLevelComponent ())) {
212207 editor->constrainer .setSizeLimits (890 , 650 , 99000 , 99000 );
@@ -226,6 +221,7 @@ class PluginMode final : public Component
226221
227222 cnv->patch .openInPluginMode = false ;
228223 editor->getTabComponent ().updateNow ();
224+ isClosing = false ;
229225 }
230226
231227 bool isWindowFullscreen () const
@@ -271,6 +267,8 @@ class PluginMode final : public Component
271267
272268 void resized () override
273269 {
270+ if (isClosing) return ;
271+
274272 // Detect if the user exited fullscreen with the macOS's fullscreen button
275273#if JUCE_MAC
276274 if (ProjectInfo::isStandalone && isWindowFullscreen () && !desktopWindow->isFullScreen ()) {
@@ -285,7 +283,7 @@ class PluginMode final : public Component
285283 float const scaleY = static_cast <float >(getHeight ()) / height;
286284 float scale = jmin (scaleX, scaleY);
287285
288- editor-> pd -> pluginModeScale = scale;
286+ pluginModeScale = scale;
289287 scaleComboBox.setVisible (false );
290288 editorButton->setVisible (true );
291289
@@ -318,7 +316,7 @@ class PluginMode final : public Component
318316 int const x = (getWidth () - scaledWidth) / 2 ;
319317 int const y = (getHeight () - scaledHeight) / 2 ;
320318
321- editor-> pd -> pluginModeScale = scale;
319+ pluginModeScale = scale;
322320
323321 // Hide titlebar
324322 titleBar.setBounds (0 , 0 , 0 , 0 );
@@ -332,7 +330,7 @@ class PluginMode final : public Component
332330 cnv->setBounds (-b.getX () + x / scale, -b.getY () + y / scale, b.getWidth () + b.getX (), b.getHeight () + b.getY ());
333331 } else {
334332 float scale = getWidth () / width;
335- editor-> pd -> pluginModeScale = scale;
333+ pluginModeScale = scale;
336334 scaleComboBox.setVisible (true );
337335 editorButton->setVisible (true );
338336
@@ -473,23 +471,22 @@ class PluginMode final : public Component
473471 int selectedItemId = 3 ; // default is 100% for now
474472
475473 WindowDragger windowDragger;
476- bool isDraggingWindow = false ;
477-
478- bool isFullScreenKioskMode = false ;
474+ bool isDraggingWindow: 1 = false ;
475+ bool isClosing: 1 = false ;
476+ bool isFullScreenKioskMode: 1 = false ;
479477
480478 Rectangle<int > originalPluginWindowBounds;
481479
482480 Rectangle<int > windowBounds;
483481 float const width = static_cast <float >(cnv->patchWidth.getValue()) + 1.0f;
484482 float const height = static_cast <float >(cnv->patchHeight.getValue()) + 1.0f;
485- int pluginPreviousScale = 100 ;
483+
484+ float pluginModeScale = 1 .0f ;
486485
487486 String lastTheme;
488487
489488 std::unique_ptr<PlugDataLook> pluginModeLnf;
490489
491- static inline UnorderedMap<t_canvas*, int > pluginModeScaleMap;
492-
493490 struct Scale {
494491 float floatScale;
495492 int intScale;
0 commit comments