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:
parent
333f98d204
commit
268ac3d5c8
8 changed files with 39 additions and 41 deletions
|
|
@ -236,14 +236,14 @@ private:
|
|||
}
|
||||
else if (type == calloutBoxWindow)
|
||||
{
|
||||
auto* colourSelector = new ColourSelector();
|
||||
auto colourSelector = std::make_unique<ColourSelector>();
|
||||
|
||||
colourSelector->setName ("background");
|
||||
colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
|
||||
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
colourSelector->setSize (300, 400);
|
||||
|
||||
CallOutBox::launchAsynchronously (colourSelector, button.getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::move (colourSelector), button.getScreenBounds(), nullptr);
|
||||
}
|
||||
else if (type == extraComponentsAlertWindow)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,11 +87,11 @@ public:
|
|||
|
||||
void clicked() override
|
||||
{
|
||||
auto* colourSelector = new ColourSelector (ColourSelector::showAlphaChannel
|
||||
| ColourSelector::showColourAtTop
|
||||
| ColourSelector::editableColour
|
||||
| ColourSelector::showSliders
|
||||
| ColourSelector::showColourspace);
|
||||
auto colourSelector = std::make_unique<ColourSelector> (ColourSelector::showAlphaChannel
|
||||
| ColourSelector::showColourAtTop
|
||||
| ColourSelector::editableColour
|
||||
| ColourSelector::showSliders
|
||||
| ColourSelector::showColourspace);
|
||||
|
||||
colourSelector->setName ("background");
|
||||
colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
|
||||
|
|
@ -99,7 +99,7 @@ public:
|
|||
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
colourSelector->setSize (300, 400);
|
||||
|
||||
CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::move (colourSelector), getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
using TextButton::clicked;
|
||||
|
|
|
|||
|
|
@ -89,8 +89,9 @@ public:
|
|||
|
||||
void mouseDown (const MouseEvent&) override
|
||||
{
|
||||
CallOutBox::launchAsynchronously (new ColourSelectorComp (this, canResetToDefault),
|
||||
getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::make_unique<ColourSelectorComp> (this, canResetToDefault),
|
||||
getScreenBounds(),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
class ColourSelectorComp : public Component
|
||||
|
|
|
|||
|
|
@ -178,10 +178,10 @@ public:
|
|||
|
||||
void clicked() override
|
||||
{
|
||||
auto* w = new InfoWindow (info);
|
||||
auto w = std::make_unique<InfoWindow> (info);
|
||||
w->setSize (width, w->getHeight() * numLines + 10);
|
||||
|
||||
CallOutBox::launchAsynchronously (w, getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::move (w), getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
using Button::clicked;
|
||||
|
|
|
|||
|
|
@ -116,10 +116,11 @@ private:
|
|||
if (undoManager != nullptr)
|
||||
undoManager->beginNewTransaction();
|
||||
|
||||
CallOutBox::launchAsynchronously (new PopupColourSelector (colourValue,
|
||||
defaultColour,
|
||||
canResetToDefault),
|
||||
getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::make_unique<PopupColourSelector> (colourValue,
|
||||
defaultColour,
|
||||
canResetToDefault),
|
||||
getScreenBounds(),
|
||||
nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -40,9 +40,7 @@ CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const pare
|
|||
else
|
||||
{
|
||||
setAlwaysOnTop (juce_areThereAnyAlwaysOnTopWindows());
|
||||
|
||||
updatePosition (area, Desktop::getInstance().getDisplays().findDisplayForRect (area).userArea);
|
||||
|
||||
addToDesktop (ComponentPeer::windowIsTemporary);
|
||||
|
||||
startTimer (100);
|
||||
|
|
@ -51,15 +49,14 @@ CallOutBox::CallOutBox (Component& c, Rectangle<int> area, Component* const pare
|
|||
creationTime = Time::getCurrentTime();
|
||||
}
|
||||
|
||||
CallOutBox::~CallOutBox() = default;
|
||||
|
||||
//==============================================================================
|
||||
class CallOutBoxCallback : public ModalComponentManager::Callback,
|
||||
private Timer
|
||||
{
|
||||
public:
|
||||
CallOutBoxCallback (Component* c, const Rectangle<int>& area, Component* parent)
|
||||
: content (c), callout (*c, area, parent)
|
||||
CallOutBoxCallback (std::unique_ptr<Component> c, const Rectangle<int>& area, Component* parent)
|
||||
: content (std::move (c)),
|
||||
callout (*content, area, parent)
|
||||
{
|
||||
callout.setVisible (true);
|
||||
callout.enterModalState (true, this);
|
||||
|
|
@ -80,11 +77,11 @@ public:
|
|||
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!
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void CallOutBox::lookAndFeelChanged() { resized(); repaint(); }
|
||||
void CallOutBox::lookAndFeelChanged()
|
||||
{
|
||||
resized();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void CallOutBox::paint (Graphics& g)
|
||||
{
|
||||
|
|
@ -158,7 +159,7 @@ void CallOutBox::setDismissalMouseClicksAreAlwaysConsumed (bool b) noexcept
|
|||
dismissalMouseClicksAreAlwaysConsumed = b;
|
||||
}
|
||||
|
||||
enum { callOutBoxDismissCommandId = 0x4f83a04b };
|
||||
static constexpr int callOutBoxDismissCommandId = 0x4f83a04b;
|
||||
|
||||
void CallOutBox::handleCommandMessage (int commandId)
|
||||
{
|
||||
|
|
@ -193,9 +194,8 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
|
|||
availableArea = newAreaToFitIn;
|
||||
|
||||
auto borderSpace = getBorderSize();
|
||||
|
||||
Rectangle<int> newBounds (content.getWidth() + borderSpace * 2,
|
||||
content.getHeight() + borderSpace * 2);
|
||||
auto newBounds = getLocalArea (&content, Rectangle<int> (content.getWidth() + borderSpace * 2,
|
||||
content.getHeight() + borderSpace * 2));
|
||||
|
||||
auto hw = newBounds.getWidth() / 2;
|
||||
auto hh = newBounds.getHeight() / 2;
|
||||
|
|
@ -250,7 +250,7 @@ void CallOutBox::refreshPath()
|
|||
|
||||
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(),
|
||||
targetPoint - getPosition().toFloat(),
|
||||
getLookAndFeel().getCallOutBoxCornerSize (*this), arrowSize * 0.7f);
|
||||
|
|
|
|||
|
|
@ -43,11 +43,12 @@ namespace juce
|
|||
@code
|
||||
void mouseUp (const MouseEvent&)
|
||||
{
|
||||
FoobarContentComp* content = new FoobarContentComp();
|
||||
auto content = std::make_unique<FoobarContentComp>();
|
||||
content->setSize (300, 300);
|
||||
|
||||
CallOutBox& myBox
|
||||
= CallOutBox::launchAsynchronously (content, getScreenBounds(), nullptr);
|
||||
auto& myBox = CallOutBox::launchAsynchronously (std::move (content),
|
||||
getScreenBounds(),
|
||||
nullptr);
|
||||
}
|
||||
@endcode
|
||||
|
||||
|
|
@ -77,9 +78,6 @@ public:
|
|||
Rectangle<int> areaToPointTo,
|
||||
Component* parentComponent);
|
||||
|
||||
/** Destructor. */
|
||||
~CallOutBox() override;
|
||||
|
||||
//==============================================================================
|
||||
/** Changes the base width of the arrow. */
|
||||
void setArrowSize (float newSize);
|
||||
|
|
@ -109,15 +107,13 @@ public:
|
|||
@param contentComponent the component to display inside the call-out. This should
|
||||
already have a size set (although the call-out will also
|
||||
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
|
||||
a parentComponent is supplied, then this is relative to that
|
||||
parent; otherwise, it's a global screen coord.
|
||||
@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.
|
||||
*/
|
||||
static CallOutBox& launchAsynchronously (Component* contentComponent,
|
||||
static CallOutBox& launchAsynchronously (std::unique_ptr<Component> contentComponent,
|
||||
Rectangle<int> areaToPointTo,
|
||||
Component* parentComponent);
|
||||
|
||||
|
|
|
|||
|
|
@ -406,14 +406,14 @@ struct ColourEditorComp : public Component,
|
|||
|
||||
void mouseDown (const MouseEvent&) override
|
||||
{
|
||||
auto* colourSelector = new ColourSelector();
|
||||
auto colourSelector = std::make_unique<ColourSelector>();
|
||||
colourSelector->setName ("Colour");
|
||||
colourSelector->setCurrentColour (getColour());
|
||||
colourSelector->addChangeListener (this);
|
||||
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
colourSelector->setSize (300, 400);
|
||||
|
||||
CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
|
||||
CallOutBox::launchAsynchronously (std::move (colourSelector), getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
void changeListenerCallback (ChangeBroadcaster* source) override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue