1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Modernised some code in CallOutBox and added some logic to scale the window with its content component's transform

This commit is contained in:
ed 2020-08-24 17:07:01 +01:00
parent 333f98d204
commit 268ac3d5c8
8 changed files with 39 additions and 41 deletions

View file

@ -236,14 +236,14 @@ private:
} }
else if (type == calloutBoxWindow) else if (type == calloutBoxWindow)
{ {
auto* colourSelector = new ColourSelector(); auto colourSelector = std::make_unique<ColourSelector>();
colourSelector->setName ("background"); colourSelector->setName ("background");
colourSelector->setCurrentColour (findColour (TextButton::buttonColourId)); colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
colourSelector->setSize (300, 400); colourSelector->setSize (300, 400);
CallOutBox::launchAsynchronously (colourSelector, button.getScreenBounds(), nullptr); CallOutBox::launchAsynchronously (std::move (colourSelector), button.getScreenBounds(), nullptr);
} }
else if (type == extraComponentsAlertWindow) else if (type == extraComponentsAlertWindow)
{ {

View file

@ -87,7 +87,7 @@ public:
void clicked() override void clicked() override
{ {
auto* colourSelector = new ColourSelector (ColourSelector::showAlphaChannel auto colourSelector = std::make_unique<ColourSelector> (ColourSelector::showAlphaChannel
| ColourSelector::showColourAtTop | ColourSelector::showColourAtTop
| ColourSelector::editableColour | ColourSelector::editableColour
| ColourSelector::showSliders | ColourSelector::showSliders
@ -99,7 +99,7 @@ public:
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
colourSelector->setSize (300, 400); colourSelector->setSize (300, 400);
CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr); CallOutBox::launchAsynchronously (std::move (colourSelector), getScreenBounds(), nullptr);
} }
using TextButton::clicked; using TextButton::clicked;

View file

@ -89,8 +89,9 @@ public:
void mouseDown (const MouseEvent&) override void mouseDown (const MouseEvent&) override
{ {
CallOutBox::launchAsynchronously (new ColourSelectorComp (this, canResetToDefault), CallOutBox::launchAsynchronously (std::make_unique<ColourSelectorComp> (this, canResetToDefault),
getScreenBounds(), nullptr); getScreenBounds(),
nullptr);
} }
class ColourSelectorComp : public Component class ColourSelectorComp : public Component

View file

@ -178,10 +178,10 @@ public:
void clicked() override void clicked() override
{ {
auto* w = new InfoWindow (info); auto w = std::make_unique<InfoWindow> (info);
w->setSize (width, w->getHeight() * numLines + 10); w->setSize (width, w->getHeight() * numLines + 10);
CallOutBox::launchAsynchronously (w, getScreenBounds(), nullptr); CallOutBox::launchAsynchronously (std::move (w), getScreenBounds(), nullptr);
} }
using Button::clicked; using Button::clicked;

View file

@ -116,10 +116,11 @@ private:
if (undoManager != nullptr) if (undoManager != nullptr)
undoManager->beginNewTransaction(); undoManager->beginNewTransaction();
CallOutBox::launchAsynchronously (new PopupColourSelector (colourValue, CallOutBox::launchAsynchronously (std::make_unique<PopupColourSelector> (colourValue,
defaultColour, defaultColour,
canResetToDefault), canResetToDefault),
getScreenBounds(), nullptr); getScreenBounds(),
nullptr);
} }
private: private:

View file

@ -40,9 +40,7 @@ CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const pare
else else
{ {
setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows()); setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
updatePosition (area, Desktop::getInstance().getDisplays().findDisplayForRect (area).userArea); updatePosition (area, Desktop::getInstance().getDisplays().findDisplayForRect (area).userArea);
addToDesktop (ComponentPeer::windowIsTemporary); addToDesktop (ComponentPeer::windowIsTemporary);
startTimer (100); startTimer (100);
@ -51,15 +49,14 @@ CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const pare
creationTime = Time::getCurrentTime(); creationTime = Time::getCurrentTime();
} }
CallOutBox::~CallOutBox() = default;
//============================================================================== //==============================================================================
class CallOutBoxCallback : public ModalComponentManager::Callback, class CallOutBoxCallback : public ModalComponentManager::Callback,
private Timer private Timer
{ {
public: public:
CallOutBoxCallback (Component* c, const Rectangle<int>& area, Component* parent) CallOutBoxCallback (std::unique_ptr<Component> c, const Rectangle<int>& area, Component* parent)
: content (c), callout (*c, area, parent) : content (std::move (c)),
callout (*content, area, parent)
{ {
callout.setVisible (true); callout.setVisible (true);
callout.enterModalState (true, this); callout.enterModalState (true, this);
@ -80,11 +77,11 @@ public:
JUCE_DECLARE_NON_COPYABLE (CallOutBoxCallback) JUCE_DECLARE_NON_COPYABLE (CallOutBoxCallback)
}; };
CallOutBox& CallOutBox::launchAsynchronously (Component* content, Rectangle<int> area, Component* parent) CallOutBox& CallOutBox::launchAsynchronously (std::unique_ptr<Component> content, Rectangle<int> area, Component* parent)
{ {
jassert (content != nullptr); // must be a valid content component! jassert (content != nullptr); // must be a valid content component!
return (new CallOutBoxCallback (content, area, parent))->callout; return (new CallOutBoxCallback (std::move (content), area, parent))->callout;
} }
//============================================================================== //==============================================================================
@ -99,7 +96,11 @@ int CallOutBox::getBorderSize() const noexcept
return jmax (getLookAndFeel().getCallOutBoxBorderSize (*this), (int) arrowSize); return jmax (getLookAndFeel().getCallOutBoxBorderSize (*this), (int) arrowSize);
} }
void CallOutBox::lookAndFeelChanged() { resized(); repaint(); } void CallOutBox::lookAndFeelChanged()
{
resized();
repaint();
}
void CallOutBox::paint (Graphics& g) void CallOutBox::paint (Graphics& g)
{ {
@ -158,7 +159,7 @@ void CallOutBox::setDismissalMouseClicksAreAlwaysConsumed (bool b) noexcept
dismissalMouseClicksAreAlwaysConsumed = b; dismissalMouseClicksAreAlwaysConsumed = b;
} }
enum { callOutBoxDismissCommandId = 0x4f83a04b }; static constexpr int callOutBoxDismissCommandId = 0x4f83a04b;
void CallOutBox::handleCommandMessage (int commandId) void CallOutBox::handleCommandMessage (int commandId)
{ {
@ -193,9 +194,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
availableArea = newAreaToFitIn; availableArea = newAreaToFitIn;
auto borderSpace = getBorderSize(); auto borderSpace = getBorderSize();
auto newBounds = getLocalArea (&content, Rectangle<int> (content.getWidth() + borderSpace * 2,
Rectangle<int> newBounds (content.getWidth() + borderSpace * 2, content.getHeight() + borderSpace * 2));
content.getHeight() + borderSpace * 2);
auto hw = newBounds.getWidth() / 2; auto hw = newBounds.getWidth() / 2;
auto hh = newBounds.getHeight() / 2; auto hh = newBounds.getHeight() / 2;
@ -250,7 +250,7 @@ void CallOutBox::refreshPath()
const float gap = 4.5f; const float gap = 4.5f;
outline.addBubble (content.getBounds().toFloat().expanded (gap, gap), outline.addBubble (getLocalArea (&content, content.getLocalBounds().toFloat()).expanded (gap, gap),
getLocalBounds().toFloat(), getLocalBounds().toFloat(),
targetPoint - getPosition().toFloat(), targetPoint - getPosition().toFloat(),
getLookAndFeel().getCallOutBoxCornerSize (*this), arrowSize * 0.7f); getLookAndFeel().getCallOutBoxCornerSize (*this), arrowSize * 0.7f);

View file

@ -43,11 +43,12 @@ namespace juce
@code @code
void mouseUp (const MouseEvent&) void mouseUp (const MouseEvent&)
{ {
FoobarContentComp* content = new FoobarContentComp(); auto content = std::make_unique<FoobarContentComp>();
content->setSize (300, 300); content->setSize (300, 300);
CallOutBox& myBox auto& myBox = CallOutBox::launchAsynchronously (std::move (content),
= CallOutBox::launchAsynchronously (content, getScreenBounds(), nullptr); getScreenBounds(),
nullptr);
} }
@endcode @endcode
@ -77,9 +78,6 @@ public:
Rectangle<int> areaToPointTo, Rectangle<int> areaToPointTo,
Component* parentComponent); Component* parentComponent);
/** Destructor. */
~CallOutBox() override;
//============================================================================== //==============================================================================
/** Changes the base width of the arrow. */ /** Changes the base width of the arrow. */
void setArrowSize (float newSize); void setArrowSize (float newSize);
@ -109,15 +107,13 @@ public:
@param contentComponent the component to display inside the call-out. This should @param contentComponent the component to display inside the call-out. This should
already have a size set (although the call-out will also already have a size set (although the call-out will also
update itself when the component's size is changed later). update itself when the component's size is changed later).
This component will be owned by the callout box and deleted
later when the box is dismissed.
@param areaToPointTo the area that the call-out's arrow should point towards. If @param areaToPointTo the area that the call-out's arrow should point towards. If
a parentComponent is supplied, then this is relative to that a parentComponent is supplied, then this is relative to that
parent; otherwise, it's a global screen coord. parent; otherwise, it's a global screen coord.
@param parentComponent if not a nullptr, this is the component to add the call-out to. @param parentComponent if not a nullptr, this is the component to add the call-out to.
If this is a nullptr, the call-out will be added to the desktop. If this is a nullptr, the call-out will be added to the desktop.
*/ */
static CallOutBox& launchAsynchronously (Component* contentComponent, static CallOutBox& launchAsynchronously (std::unique_ptr<Component> contentComponent,
Rectangle<int> areaToPointTo, Rectangle<int> areaToPointTo,
Component* parentComponent); Component* parentComponent);

View file

@ -406,14 +406,14 @@ struct ColourEditorComp : public Component,
void mouseDown (const MouseEvent&) override void mouseDown (const MouseEvent&) override
{ {
auto* colourSelector = new ColourSelector(); auto colourSelector = std::make_unique<ColourSelector>();
colourSelector->setName ("Colour"); colourSelector->setName ("Colour");
colourSelector->setCurrentColour (getColour()); colourSelector->setCurrentColour (getColour());
colourSelector->addChangeListener (this); colourSelector->addChangeListener (this);
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack); colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
colourSelector->setSize (300, 400); colourSelector->setSize (300, 400);
CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr); CallOutBox::launchAsynchronously (std::move (colourSelector), getScreenBounds(), nullptr);
} }
void changeListenerCallback (ChangeBroadcaster* source) override void changeListenerCallback (ChangeBroadcaster* source) override