From f1accb880e87c8711ad01f1a0355d8a1de18a728 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 17 Oct 2024 09:09:43 +0100 Subject: [PATCH] Added functionality for temporarily showing/hiding plugin windows to PluginWindowState --- .../plugins/tracktion_PluginWindowState.cpp | 68 +++++++++++++++++++ .../plugins/tracktion_PluginWindowState.h | 26 ++++++- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/modules/tracktion_engine/plugins/tracktion_PluginWindowState.cpp b/modules/tracktion_engine/plugins/tracktion_PluginWindowState.cpp index 1717a6cf1d0..f5440f61dcb 100644 --- a/modules/tracktion_engine/plugins/tracktion_PluginWindowState.cpp +++ b/modules/tracktion_engine/plugins/tracktion_PluginWindowState.cpp @@ -59,6 +59,12 @@ void PluginWindowState::showWindowExplicitly() showWindow(); } +void PluginWindowState::showWindowIfTemporarilyHidden() +{ + if (temporarilyHidden && ! isWindowShowing()) + showWindowExplicitly(); +} + void PluginWindowState::closeWindowExplicitly() { TRACKTION_ASSERT_MESSAGE_THREAD @@ -71,6 +77,19 @@ void PluginWindowState::closeWindowExplicitly() } } +void PluginWindowState::hideWindowTemporarily() +{ + if (isWindowShowing()) + { + closeWindowExplicitly(); + temporarilyHidden = true; + } + else + { + temporarilyHidden = false; + } +} + bool PluginWindowState::isWindowShowing() const { return pluginWindow != nullptr && pluginWindow->isVisible(); @@ -121,6 +140,55 @@ void PluginWindowState::showWindow() } } +std::vector PluginWindowState::getAllWindows (Edit& ed) +{ + std::vector windows; + + for (auto p : getAllPlugins (ed, true)) + { + if (auto w = p->windowState.get()) + windows.push_back (w); + + if (auto rf = dynamic_cast (p)) + if (auto rft = rf->type) + for (auto ws : rft->getWindowStates()) + windows.push_back (ws); + } + + return windows; +} + +uint32_t PluginWindowState::getNumOpenWindows (Edit& ed) +{ + uint32_t openWindows = 0; + + for (auto w : getAllWindows (ed)) + if (w->isWindowShowing()) + ++openWindows; + + return openWindows; +} + +void PluginWindowState::showAllTemporarilyHiddenWindows (Edit& ed) +{ + for (auto w : getAllWindows (ed)) + w->showWindowIfTemporarilyHidden(); +} + +void PluginWindowState::hideAllWindowsTemporarily (Edit& ed) +{ + for (auto w : getAllWindows (ed)) + w->hideWindowTemporarily(); +} + +void PluginWindowState::showOrHideAllWindows (Edit& ed) +{ + if (getNumOpenWindows (ed) == 0) + showAllTemporarilyHiddenWindows (ed); + else + hideAllWindowsTemporarily (ed); +} + void PluginWindowState::pluginClicked (const juce::MouseEvent& e) { bool isShowing = isWindowShowing(); diff --git a/modules/tracktion_engine/plugins/tracktion_PluginWindowState.h b/modules/tracktion_engine/plugins/tracktion_PluginWindowState.h index 8d3f800b263..2a044b948f0 100644 --- a/modules/tracktion_engine/plugins/tracktion_PluginWindowState.h +++ b/modules/tracktion_engine/plugins/tracktion_PluginWindowState.h @@ -18,20 +18,40 @@ struct PluginWindowState : private juce::Timer void incRefCount(); void decRefCount(); - void showWindowExplicitly(); - void closeWindowExplicitly(); - + //============================================================================== bool isWindowShowing() const; + + void showWindowExplicitly(); + void showWindowIfTemporarilyHidden(); void recreateWindowIfShowing(); + + void closeWindowExplicitly(); void hideWindowForShutdown(); + void hideWindowTemporarily(); + + /// Calls hideWindowTemporarily() for any windows of plugins in this edit + static void hideAllWindowsTemporarily (Edit&); + /// Calls showWindowIfTemporarilyHidden() for all plugins in this edit + static void showAllTemporarilyHiddenWindows (Edit&); + + /// If any windows are showing, hide them all temporarily, otherwise + /// bring back any temporarily hidden ones. + static void showOrHideAllWindows (Edit&); + + /// Finds all windows for all plugins in this edit + static std::vector getAllWindows (Edit&); + /// Counts the number of visible windows for plugins in this edit + static uint32_t getNumOpenWindows (Edit&); // Attempts to use either the last saved bounds from this state, // or pick a default position for a newly created window that is // going to hold this plugin's UI juce::Point choosePositionForPluginWindow(); + /// Can be used to manually fire a mouse event into the window void pluginClicked (const juce::MouseEvent&); + //============================================================================== Edit& edit; Engine& engine; std::unique_ptr pluginWindow;