Browse Source

Add support for plug-ins which do not want to use a resize corner

tags/2021-05-28
hogliux 9 years ago
parent
commit
a0259ce408
3 changed files with 57 additions and 35 deletions
  1. +2
    -2
      modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
  2. +48
    -31
      modules/juce_audio_processors/processors/juce_AudioProcessorEditor.cpp
  3. +7
    -2
      modules/juce_audio_processors/processors/juce_AudioProcessorEditor.h

+ 2
- 2
modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp View File

@@ -799,9 +799,9 @@ private:
{
if (component != nullptr)
if (AudioProcessorEditor* editor = component->pluginEditor)
return editor->isResizable();
return editor->isResizable() ? kResultTrue : kResultFalse;
return true;
return kResultFalse;
}
tresult PLUGIN_API checkSizeConstraint (ViewRect* rectToCheck) override


+ 48
- 31
modules/juce_audio_processors/processors/juce_AudioProcessorEditor.cpp View File

@@ -47,39 +47,44 @@ int AudioProcessorEditor::getControlParameterIndex (Component&) { return -1; }
void AudioProcessorEditor::initialise()
{
setConstrainer (&defaultConstrainer);
resizable = false;
attachConstrainer (&defaultConstrainer);
addComponentListener (resizeListener = new AudioProcessorEditorListener (this));
}
//==============================================================================
void AudioProcessorEditor::setResizable (const bool shouldBeResizable)
void AudioProcessorEditor::setResizable (const bool shouldBeResizable, const bool useBottomRightCornerResizer)
{
if (shouldBeResizable)
if (shouldBeResizable != resizable)
{
if (resizableCorner == nullptr)
resizable = shouldBeResizable;
if (! resizable)
{
Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
resizableCorner->setAlwaysOnTop (true);
setConstrainer (&defaultConstrainer);
if (getWidth() > 0 && getHeight() > 0)
{
defaultConstrainer.setSizeLimits (getWidth(), getHeight(), getWidth(), getHeight());
resized();
}
}
}
else
{
setConstrainer (&defaultConstrainer);
resizableCorner = nullptr;
if (getWidth() > 0 && getHeight() > 0)
const bool shouldHaveCornerResizer = (useBottomRightCornerResizer && shouldBeResizable);
if (shouldHaveCornerResizer != (resizableCorner != nullptr))
{
if (shouldHaveCornerResizer)
{
defaultConstrainer.setSizeLimits (getWidth(), getHeight(), getWidth(), getHeight());
resized();
Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
resizableCorner->setAlwaysOnTop (true);
}
else
resizableCorner = nullptr;
}
}
bool AudioProcessorEditor::isResizable() const noexcept
{
return resizableCorner != nullptr;
}
void AudioProcessorEditor::setResizeLimits (const int newMinimumWidth,
const int newMinimumHeight,
const int newMaximumWidth,
@@ -88,7 +93,10 @@ void AudioProcessorEditor::setResizeLimits (const int newMinimumWidth,
// if you've set up a custom constrainer then these settings won't have any effect..
jassert (constrainer == &defaultConstrainer || constrainer == nullptr);
setResizable (newMinimumWidth != newMaximumWidth || newMinimumHeight != newMaximumHeight);
const bool shouldEnableResize = (newMinimumWidth != newMaximumWidth || newMinimumHeight != newMaximumHeight);
const bool shouldHaveCornerResizer = (shouldEnableResize != resizable || resizableCorner != nullptr);
setResizable (shouldEnableResize, shouldHaveCornerResizer);
if (constrainer == nullptr)
setConstrainer (&defaultConstrainer);
@@ -103,17 +111,17 @@ void AudioProcessorEditor::setConstrainer (ComponentBoundsConstrainer* newConstr
{
if (constrainer != newConstrainer)
{
constrainer = newConstrainer;
const bool shouldBeResizable = resizableCorner != nullptr;
resizableCorner = nullptr;
setResizable (shouldBeResizable);
resizable = true;
attachConstrainer (newConstrainer);
}
}
if (isOnDesktop())
if (ComponentPeer* const peer = getPeer())
peer->setConstrainer (constrainer);
void AudioProcessorEditor::attachConstrainer (ComponentBoundsConstrainer* newConstrainer)
{
if (constrainer != newConstrainer)
{
constrainer = newConstrainer;
updatePeer();
}
}
@@ -136,14 +144,16 @@ void AudioProcessorEditor::editorResized (bool wasResized)
if (resizableCorner != nullptr)
{
resizableCorner->setVisible (! resizerHidden);
resizableCorner->setVisible (! resizerHidden);
const int resizerSize = 18;
resizableCorner->setBounds (getWidth() - resizerSize,
getHeight() - resizerSize,
resizerSize, resizerSize);
}
else
if (! resizable)
{
if (getWidth() > 0 && getHeight() > 0)
defaultConstrainer.setSizeLimits (getWidth(), getHeight(),
@@ -151,3 +161,10 @@ void AudioProcessorEditor::editorResized (bool wasResized)
}
}
}
void AudioProcessorEditor::updatePeer()
{
if (isOnDesktop())
if (ComponentPeer* const peer = getPeer())
peer->setConstrainer (constrainer);
}

+ 7
- 2
modules/juce_audio_processors/processors/juce_AudioProcessorEditor.h View File

@@ -90,13 +90,13 @@ public:
@param shouldBeResizable whether it's resizable at all
@see setResizeLimits, isResizable
*/
void setResizable (bool shouldBeResizable);
void setResizable (bool shouldBeResizable, bool useBottomRightCornerResizer);
/** Returns true if resizing is enabled.
@see setResizable
*/
bool isResizable() const noexcept;
bool isResizable() const noexcept { return resizable; }
/** This sets the maximum and minimum sizes for the window.
@@ -143,16 +143,21 @@ private:
struct AudioProcessorEditorListener : ComponentListener
{
AudioProcessorEditorListener (AudioProcessorEditor* audioEditor) : e (audioEditor) {}
void componentMovedOrResized (Component&, bool, bool wasResized) override { e->editorResized (wasResized); }
void componentParentHierarchyChanged (Component&) override { e->updatePeer(); }
AudioProcessorEditor* e;
};
//==============================================================================
void initialise();
void editorResized (bool wasResized);
void updatePeer();
void attachConstrainer (ComponentBoundsConstrainer* newConstrainer);
//==============================================================================
ScopedPointer<AudioProcessorEditorListener> resizeListener;
bool resizable;
ComponentBoundsConstrainer defaultConstrainer;
ComponentBoundsConstrainer* constrainer;


Loading…
Cancel
Save