mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
CallOutBox: changed parameters to allow better positioning, and improved layout algorithm.
This commit is contained in:
parent
6d8bd3029d
commit
b4fe06fb81
4 changed files with 41 additions and 38 deletions
|
|
@ -376,9 +376,10 @@ public:
|
|||
if (undoManager != nullptr)
|
||||
undoManager->beginNewTransaction();
|
||||
|
||||
CallOutBox::launchAsynchronously (*this, new PopupColourSelector (colourValue,
|
||||
defaultColour,
|
||||
canResetToDefault), nullptr);
|
||||
CallOutBox::launchAsynchronously (new PopupColourSelector (colourValue,
|
||||
defaultColour,
|
||||
canResetToDefault),
|
||||
getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
void valueChanged (Value&)
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ public:
|
|||
colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
|
||||
colourSelector->setSize (300, 400);
|
||||
|
||||
CallOutBox::launchAsynchronously (*this, colourSelector, nullptr);
|
||||
CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
|
||||
}
|
||||
|
||||
void changeListenerCallback (ChangeBroadcaster* source)
|
||||
|
|
|
|||
|
|
@ -23,20 +23,15 @@
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
CallOutBox::CallOutBox (Component& contentComponent,
|
||||
Component& componentToPointTo,
|
||||
Component* const parent)
|
||||
: borderSpace (20), arrowSize (16.0f), content (contentComponent)
|
||||
CallOutBox::CallOutBox (Component& c, const Rectangle<int>& area, Component* const parent)
|
||||
: borderSpace (20), arrowSize (16.0f), content (c)
|
||||
{
|
||||
addAndMakeVisible (&content);
|
||||
|
||||
if (parent != nullptr)
|
||||
{
|
||||
parent->addChildComponent (this);
|
||||
|
||||
updatePosition (parent->getLocalArea (&componentToPointTo, componentToPointTo.getLocalBounds()),
|
||||
parent->getLocalBounds());
|
||||
|
||||
updatePosition (area, parent->getLocalBounds());
|
||||
setVisible (true);
|
||||
}
|
||||
else
|
||||
|
|
@ -44,8 +39,8 @@ CallOutBox::CallOutBox (Component& contentComponent,
|
|||
if (! JUCEApplication::isStandaloneApp())
|
||||
setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
|
||||
|
||||
updatePosition (componentToPointTo.getScreenBounds(),
|
||||
componentToPointTo.getParentMonitorArea());
|
||||
updatePosition (area, Desktop::getInstance().getDisplays()
|
||||
.getDisplayContaining (area.getCentre()).userArea);
|
||||
|
||||
addToDesktop (ComponentPeer::windowIsTemporary);
|
||||
}
|
||||
|
|
@ -59,8 +54,8 @@ CallOutBox::~CallOutBox()
|
|||
class CallOutBoxCallback : public ModalComponentManager::Callback
|
||||
{
|
||||
public:
|
||||
CallOutBoxCallback (Component& attachTo, Component* content_, Component* parentComponent)
|
||||
: content (content_), callout (*content_, attachTo, parentComponent)
|
||||
CallOutBoxCallback (Component* c, const Rectangle<int>& area, Component* parent)
|
||||
: content (c), callout (*c, area, parent)
|
||||
{
|
||||
callout.setVisible (true);
|
||||
callout.enterModalState (true, this);
|
||||
|
|
@ -68,20 +63,19 @@ public:
|
|||
|
||||
void modalStateFinished (int) {}
|
||||
|
||||
private:
|
||||
ScopedPointer<Component> content;
|
||||
CallOutBox callout;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE (CallOutBoxCallback);
|
||||
};
|
||||
|
||||
void CallOutBox::launchAsynchronously (Component& componentToPointTo,
|
||||
Component* contentComponent,
|
||||
Component* parentComponent)
|
||||
CallOutBox& CallOutBox::launchAsynchronously (Component* content,
|
||||
const Rectangle<int>& area,
|
||||
Component* parent)
|
||||
{
|
||||
jassert (contentComponent != nullptr); // must be a valid content component!
|
||||
jassert (content != nullptr); // must be a valid content component!
|
||||
|
||||
new CallOutBoxCallback (componentToPointTo, contentComponent, parentComponent);
|
||||
return (new CallOutBoxCallback (content, area, parent))->callout;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -185,6 +179,7 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
|
|||
Line<float> (targets[3].translated (-hwReduced, -(hh - arrowIndent)), targets[3].translated (hwReduced, -(hh - arrowIndent))) };
|
||||
|
||||
const Rectangle<float> centrePointArea (newAreaToFitIn.reduced (hw, hh).toFloat());
|
||||
const Point<float> targetCentre (targetArea.getCentre().toFloat());
|
||||
|
||||
float nearest = 1.0e9f;
|
||||
|
||||
|
|
@ -193,19 +188,19 @@ void CallOutBox::updatePosition (const Rectangle<int>& newAreaToPointTo, const R
|
|||
Line<float> constrainedLine (centrePointArea.getConstrainedPoint (lines[i].getStart()),
|
||||
centrePointArea.getConstrainedPoint (lines[i].getEnd()));
|
||||
|
||||
const Point<float> centre (constrainedLine.findNearestPointTo (centrePointArea.getCentre()));
|
||||
float distanceFromCentre = centre.getDistanceFrom (centrePointArea.getCentre());
|
||||
const Point<float> centre (constrainedLine.findNearestPointTo (targetCentre));
|
||||
float distanceFromCentre = centre.getDistanceFrom (targets[i]);
|
||||
|
||||
if (! (centrePointArea.contains (lines[i].getStart()) || centrePointArea.contains (lines[i].getEnd())))
|
||||
distanceFromCentre *= 2.0f;
|
||||
distanceFromCentre *= 50.0f;
|
||||
|
||||
if (distanceFromCentre < nearest)
|
||||
{
|
||||
nearest = distanceFromCentre;
|
||||
|
||||
targetPoint = targets[i];
|
||||
newBounds.setPosition ((int) (centre.getX() - hw),
|
||||
(int) (centre.getY() - hh));
|
||||
newBounds.setPosition ((int) (centre.x - hw),
|
||||
(int) (centre.y - hh));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,12 +64,14 @@ public:
|
|||
update itself when the component's size is changed later).
|
||||
Obviously this component must not be deleted until the
|
||||
call-out box has been deleted.
|
||||
@param componentToPointTo the component that the call-out's arrow should point towards
|
||||
@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 non-zero, this is the component to add the call-out to. If
|
||||
this is zero, the call-out will be added to the desktop.
|
||||
this is a nullptr, the call-out will be added to the desktop.
|
||||
*/
|
||||
CallOutBox (Component& contentComponent,
|
||||
Component& componentToPointTo,
|
||||
const Rectangle<int>& areaToPointTo,
|
||||
Component* parentComponent);
|
||||
|
||||
/** Destructor. */
|
||||
|
|
@ -98,15 +100,20 @@ public:
|
|||
the box will continue to run modally until the user clicks on some other component, at
|
||||
which point it will be dismissed automatically.
|
||||
|
||||
The content component that is passed-in will be owned by the callout, which will
|
||||
delete it when it is dismissed.
|
||||
|
||||
The parentComponent parameter can be a nullptr if you want the window to appear on
|
||||
the desktop.
|
||||
@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 copmonent 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 non-zero, 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 void launchAsynchronously (Component& componentToPointTo,
|
||||
Component* contentComponent,
|
||||
Component* parentComponent);
|
||||
static CallOutBox& launchAsynchronously (Component* contentComponent,
|
||||
const Rectangle<int>& areaToPointTo,
|
||||
Component* parentComponent);
|
||||
|
||||
//==============================================================================
|
||||
/** @internal */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue