Skip to content

Commit

Permalink
Added functionality for temporarily showing/hiding plugin windows to …
Browse files Browse the repository at this point in the history
…PluginWindowState
  • Loading branch information
julianstorer committed Oct 17, 2024
1 parent 826062d commit f1accb8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
68 changes: 68 additions & 0 deletions modules/tracktion_engine/plugins/tracktion_PluginWindowState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ void PluginWindowState::showWindowExplicitly()
showWindow();
}

void PluginWindowState::showWindowIfTemporarilyHidden()
{
if (temporarilyHidden && ! isWindowShowing())
showWindowExplicitly();
}

void PluginWindowState::closeWindowExplicitly()
{
TRACKTION_ASSERT_MESSAGE_THREAD
Expand All @@ -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();
Expand Down Expand Up @@ -121,6 +140,55 @@ void PluginWindowState::showWindow()
}
}

std::vector<PluginWindowState*> PluginWindowState::getAllWindows (Edit& ed)
{
std::vector<PluginWindowState*> windows;

for (auto p : getAllPlugins (ed, true))
{
if (auto w = p->windowState.get())
windows.push_back (w);

if (auto rf = dynamic_cast<RackInstance*> (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();
Expand Down
26 changes: 23 additions & 3 deletions modules/tracktion_engine/plugins/tracktion_PluginWindowState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginWindowState*> 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<int> 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<juce::Component> pluginWindow;
Expand Down

0 comments on commit f1accb8

Please sign in to comment.