First Commit

This commit is contained in:
Legaeli
2025-10-22 09:20:23 +02:00
commit a36f2ca925
4393 changed files with 1570219 additions and 0 deletions
@@ -0,0 +1,162 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
BubbleComponent::BubbleComponent()
: allowablePlacements (above | below | left | right)
{
setInterceptsMouseClicks (false, false);
lookAndFeelChanged();
}
BubbleComponent::~BubbleComponent() {}
//==============================================================================
void BubbleComponent::lookAndFeelChanged()
{
getLookAndFeel().setComponentEffectForBubbleComponent (*this);
}
void BubbleComponent::paint (Graphics& g)
{
getLookAndFeel().drawBubble (g, *this, arrowTip.toFloat(), content.toFloat());
g.reduceClipRegion (content);
g.setOrigin (content.getPosition());
paintContent (g, content.getWidth(), content.getHeight());
}
void BubbleComponent::setAllowedPlacement (const int newPlacement)
{
allowablePlacements = newPlacement;
}
//==============================================================================
void BubbleComponent::setPosition (Component* componentToPointTo, int distanceFromTarget, int arrowLength)
{
jassert (componentToPointTo != nullptr);
Rectangle<int> target;
if (Component* p = getParentComponent())
target = p->getLocalArea (componentToPointTo, componentToPointTo->getLocalBounds());
else
target = componentToPointTo->getScreenBounds().transformedBy (getTransform().inverted());
setPosition (target, distanceFromTarget, arrowLength);
}
void BubbleComponent::setPosition (Point<int> arrowTipPos, int arrowLength)
{
setPosition (Rectangle<int> (arrowTipPos.x, arrowTipPos.y, 1, 1), arrowLength, arrowLength);
}
void BubbleComponent::setPosition (Rectangle<int> rectangleToPointTo,
int distanceFromTarget, int arrowLength)
{
{
int contentW = 150, contentH = 30;
getContentSize (contentW, contentH);
content.setBounds (distanceFromTarget, distanceFromTarget, contentW, contentH);
}
const int totalW = content.getWidth() + distanceFromTarget * 2;
const int totalH = content.getHeight() + distanceFromTarget * 2;
auto availableSpace = (getParentComponent() != nullptr ? getParentComponent()->getLocalBounds()
: getParentMonitorArea().transformedBy (getTransform().inverted()));
int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
// look at whether the component is elongated, and if so, try to position next to its longer dimension.
if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
&& (spaceAbove > totalH + 20 || spaceBelow > totalH + 20))
{
spaceLeft = spaceRight = 0;
}
else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
&& (spaceLeft > totalW + 20 || spaceRight > totalW + 20))
{
spaceAbove = spaceBelow = 0;
}
int targetX, targetY;
if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
{
targetX = rectangleToPointTo.getCentre().x;
arrowTip.x = totalW / 2;
if (spaceAbove >= spaceBelow)
{
// above
targetY = rectangleToPointTo.getY();
arrowTip.y = content.getBottom() + arrowLength;
}
else
{
// below
targetY = rectangleToPointTo.getBottom();
arrowTip.y = content.getY() - arrowLength;
}
}
else
{
targetY = rectangleToPointTo.getCentre().y;
arrowTip.y = totalH / 2;
if (spaceLeft > spaceRight)
{
// on the left
targetX = rectangleToPointTo.getX();
arrowTip.x = content.getRight() + arrowLength;
}
else
{
// on the right
targetX = rectangleToPointTo.getRight();
arrowTip.x = content.getX() - arrowLength;
}
}
setBounds (targetX - arrowTip.x, targetY - arrowTip.y, totalW, totalH);
}
} // namespace juce
@@ -0,0 +1,213 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A component for showing a message or other graphics inside a speech-bubble-shaped
outline, pointing at a location on the screen.
This is a base class that just draws and positions the bubble shape, but leaves
the drawing of any content up to a subclass. See BubbleMessageComponent for a subclass
that draws a text message.
To use it, create your subclass, then either add it to a parent component or
put it on the desktop with addToDesktop (0), use setPosition() to
resize and position it, then make it visible.
@see BubbleMessageComponent
@tags{GUI}
*/
class JUCE_API BubbleComponent : public Component
{
protected:
//==============================================================================
/** Creates a BubbleComponent.
Your subclass will need to implement the getContentSize() and paintContent()
methods to draw the bubble's contents.
*/
BubbleComponent();
public:
/** Destructor. */
~BubbleComponent() override;
//==============================================================================
/** A list of permitted placements for the bubble, relative to the coordinates
at which it should be pointing.
@see setAllowedPlacement
*/
enum BubblePlacement
{
above = 1,
below = 2,
left = 4,
right = 8
};
/** Tells the bubble which positions it's allowed to put itself in, relative to the
point at which it's pointing.
By default when setPosition() is called, the bubble will place itself either
above, below, left, or right of the target area. You can pass in a bitwise-'or' of
the values in BubblePlacement to restrict this choice.
E.g. if you only want your bubble to appear above or below the target area,
use setAllowedPlacement (above | below);
@see BubblePlacement
*/
void setAllowedPlacement (int newPlacement);
//==============================================================================
/** Moves and resizes the bubble to point at a given component.
This will resize the bubble to fit its content, then find a position for it
so that it's next to, but doesn't overlap the given component.
It'll put itself either above, below, or to the side of the component depending
on where there's the most space, honouring any restrictions that were set
with setAllowedPlacement().
*/
void setPosition (Component* componentToPointTo,
int distanceFromTarget = 15, int arrowLength = 10);
/** Moves and resizes the bubble to point at a given point.
This will resize the bubble to fit its content, then position it
so that the tip of the bubble points to the given coordinate. The coordinates
are relative to either the bubble component's parent component if it has one, or
they are screen coordinates if not.
It'll put itself either above, below, or to the side of this point, depending
on where there's the most space, honouring any restrictions that were set
with setAllowedPlacement().
*/
void setPosition (Point<int> arrowTipPosition, int arrowLength = 10);
/** Moves and resizes the bubble to point at a given rectangle.
This will resize the bubble to fit its content, then find a position for it
so that it's next to, but doesn't overlap the given rectangle. The rectangle's
coordinates are relative to either the bubble component's parent component
if it has one, or they are screen coordinates if not.
It'll put itself either above, below, or to the side of the component depending
on where there's the most space, honouring any restrictions that were set
with setAllowedPlacement().
distanceFromTarget is the amount of space to leave between the bubble and the
target rectangle, and arrowLength is the length of the arrow that it will draw.
*/
void setPosition (Rectangle<int> rectangleToPointTo,
int distanceFromTarget = 15, int arrowLength = 10);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the bubble component.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
backgroundColourId = 0x1000af0, /**< A background colour to fill the bubble with. */
outlineColourId = 0x1000af1 /**< The colour to use for an outline around the bubble. */
};
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes.
*/
struct JUCE_API LookAndFeelMethods
{
virtual ~LookAndFeelMethods() = default;
/** Override this method to draw a speech-bubble pointing at a specific location on
the screen.
*/
virtual void drawBubble (Graphics& g,
BubbleComponent& bubbleComponent,
const Point<float>& positionOfTip,
const Rectangle<float>& body) = 0;
/** Override this method to set effects, such as a drop-shadow, on a
BubbleComponent.
This will be called whenever a BubbleComponent is constructed or its
look-and-feel changes.
If you need to trigger this callback to update an effect, call
sendLookAndFeelChange() on the component.
@see Component::setComponentEffect, Component::sendLookAndFeelChange
*/
virtual void setComponentEffectForBubbleComponent (BubbleComponent& bubbleComponent) = 0;
};
//==============================================================================
/** @internal */
void paint (Graphics&) override;
/** @internal */
void lookAndFeelChanged() override;
protected:
//==============================================================================
/** Subclasses should override this to return the size of the content they
want to draw inside the bubble.
*/
virtual void getContentSize (int& width, int& height) = 0;
/** Subclasses should override this to draw their bubble's contents.
The graphics object's clip region and the dimensions passed in here are
set up to paint just the rectangle inside the bubble.
*/
virtual void paintContent (Graphics& g, int width, int height) = 0;
private:
Rectangle<int> content;
Point<int> arrowTip;
int allowablePlacements;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleComponent)
};
} // namespace juce
@@ -0,0 +1,409 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
class DropShadower::ShadowWindow final : public Component
{
public:
ShadowWindow (Component* comp, const DropShadow& ds)
: target (comp), shadow (ds)
{
setVisible (true);
setAccessible (false);
setInterceptsMouseClicks (false, false);
if (comp->isOnDesktop())
{
#if JUCE_WINDOWS
const auto scope = [&]() -> std::optional<ScopedThreadDPIAwarenessSetter>
{
if (comp != nullptr)
if (auto* handle = comp->getWindowHandle())
return ScopedThreadDPIAwarenessSetter (handle);
return {};
}();
#endif
setSize (1, 1); // to keep the OS happy by not having zero-size windows
addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
}
else if (Component* const parent = comp->getParentComponent())
{
parent->addChildComponent (this);
}
}
void paint (Graphics& g) override
{
if (Component* c = target)
shadow.drawForRectangle (g, getLocalArea (c, c->getLocalBounds()));
}
void resized() override
{
repaint(); // (needed for correct repainting)
}
float getDesktopScaleFactor() const override
{
if (target != nullptr)
return target->getDesktopScaleFactor();
return Component::getDesktopScaleFactor();
}
private:
WeakReference<Component> target;
DropShadow shadow;
JUCE_DECLARE_NON_COPYABLE (ShadowWindow)
};
class DropShadower::VirtualDesktopWatcher final : public ComponentListener,
private Timer
{
public:
//==============================================================================
VirtualDesktopWatcher (Component& c) : component (&c)
{
component->addComponentListener (this);
update();
}
~VirtualDesktopWatcher() override
{
stopTimer();
if (auto* c = component.get())
c->removeComponentListener (this);
}
bool shouldHideDropShadow() const
{
return hasReasonToHide;
}
void addListener (void* listener, std::function<void()> cb)
{
listeners[listener] = std::move (cb);
}
void removeListener (void* listener)
{
listeners.erase (listener);
}
//==============================================================================
void componentParentHierarchyChanged (Component& c) override
{
if (component.get() == &c)
update();
}
private:
//==============================================================================
void update()
{
bool newHasReasonToHide = false;
if (! component.wasObjectDeleted() && isWindows && component->isOnDesktop())
{
startTimerHz (5);
WeakReference<VirtualDesktopWatcher> weakThis (this);
// During scaling changes this call can trigger a call to HWNDComponentPeer::handleDPIChanging()
// which deletes this VirtualDesktopWatcher.
newHasReasonToHide = ! detail::WindowingHelpers::isWindowOnCurrentVirtualDesktop (component->getWindowHandle());
if (weakThis == nullptr)
return;
}
else
{
stopTimer();
}
if (std::exchange (hasReasonToHide, newHasReasonToHide) != newHasReasonToHide)
for (auto& l : listeners)
l.second();
}
void timerCallback() override
{
update();
}
//==============================================================================
WeakReference<Component> component;
const bool isWindows = (SystemStats::getOperatingSystemType() & SystemStats::Windows) != 0;
bool hasReasonToHide = false;
std::map<void*, std::function<void()>> listeners;
JUCE_DECLARE_WEAK_REFERENCEABLE (VirtualDesktopWatcher)
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VirtualDesktopWatcher)
};
class DropShadower::ParentVisibilityChangedListener final : public ComponentListener
{
public:
ParentVisibilityChangedListener (Component& r, ComponentListener& l)
: root (&r), listener (&l)
{
updateParentHierarchy();
}
~ParentVisibilityChangedListener() override
{
for (auto& compEntry : observedComponents)
if (auto* comp = compEntry.get())
comp->removeComponentListener (this);
}
void componentVisibilityChanged (Component& component) override
{
if (root != &component)
listener->componentVisibilityChanged (*root);
}
void componentParentHierarchyChanged (Component& component) override
{
if (root == &component)
updateParentHierarchy();
}
private:
class ComponentWithWeakReference
{
public:
explicit ComponentWithWeakReference (Component& c)
: ptr (&c), ref (&c) {}
Component* get() const { return ref.get(); }
bool operator< (const ComponentWithWeakReference& other) const { return ptr < other.ptr; }
private:
Component* ptr;
WeakReference<Component> ref;
};
void updateParentHierarchy()
{
const auto lastSeenComponents = std::exchange (observedComponents, [&]
{
std::set<ComponentWithWeakReference> result;
for (auto node = root; node != nullptr; node = node->getParentComponent())
result.emplace (*node);
return result;
}());
const auto withDifference = [] (const auto& rangeA, const auto& rangeB, auto&& callback)
{
std::vector<ComponentWithWeakReference> result;
std::set_difference (rangeA.begin(), rangeA.end(), rangeB.begin(), rangeB.end(), std::back_inserter (result));
for (const auto& item : result)
if (auto* c = item.get())
callback (*c);
};
withDifference (lastSeenComponents, observedComponents, [this] (auto& comp) { comp.removeComponentListener (this); });
withDifference (observedComponents, lastSeenComponents, [this] (auto& comp) { comp.addComponentListener (this); });
}
Component* root = nullptr;
ComponentListener* listener = nullptr;
std::set<ComponentWithWeakReference> observedComponents;
JUCE_DECLARE_NON_COPYABLE (ParentVisibilityChangedListener)
JUCE_DECLARE_NON_MOVEABLE (ParentVisibilityChangedListener)
};
//==============================================================================
DropShadower::DropShadower (const DropShadow& ds) : shadow (ds) {}
DropShadower::~DropShadower()
{
if (virtualDesktopWatcher != nullptr)
virtualDesktopWatcher->removeListener (this);
if (owner != nullptr)
{
owner->removeComponentListener (this);
owner = nullptr;
}
updateParent();
const ScopedValueSetter<bool> setter (reentrant, true);
shadowWindows.clear();
}
void DropShadower::setOwner (Component* componentToFollow)
{
if (componentToFollow != owner)
{
if (owner != nullptr)
owner->removeComponentListener (this);
// (the component can't be null)
jassert (componentToFollow != nullptr);
owner = componentToFollow;
jassert (owner != nullptr);
updateParent();
owner->addComponentListener (this);
// The visibility of `owner` is transitively affected by the visibility of its parents. Thus we need to trigger the
// componentVisibilityChanged() event in case it changes for any of the parents.
visibilityChangedListener = std::make_unique<ParentVisibilityChangedListener> (*owner,
static_cast<ComponentListener&> (*this));
virtualDesktopWatcher = std::make_unique<VirtualDesktopWatcher> (*owner);
virtualDesktopWatcher->addListener (this, [this]() { updateShadows(); });
updateShadows();
}
}
void DropShadower::updateParent()
{
if (Component* p = lastParentComp)
p->removeComponentListener (this);
lastParentComp = owner != nullptr ? owner->getParentComponent() : nullptr;
if (Component* p = lastParentComp)
p->addComponentListener (this);
}
void DropShadower::componentMovedOrResized (Component& c, bool /*wasMoved*/, bool /*wasResized*/)
{
if (owner == &c)
updateShadows();
}
void DropShadower::componentBroughtToFront (Component& c)
{
if (owner == &c)
updateShadows();
}
void DropShadower::componentChildrenChanged (Component&)
{
updateShadows();
}
void DropShadower::componentParentHierarchyChanged (Component& c)
{
if (owner == &c)
{
updateParent();
updateShadows();
}
}
void DropShadower::componentVisibilityChanged (Component& c)
{
if (owner == &c)
updateShadows();
}
void DropShadower::updateShadows()
{
if (reentrant)
return;
const ScopedValueSetter<bool> setter (reentrant, true);
if (owner != nullptr
&& owner->isShowing()
&& owner->getWidth() > 0 && owner->getHeight() > 0
&& (Desktop::canUseSemiTransparentWindows() || owner->getParentComponent() != nullptr)
&& (virtualDesktopWatcher == nullptr || ! virtualDesktopWatcher->shouldHideDropShadow()))
{
while (shadowWindows.size() < 4)
shadowWindows.add (new ShadowWindow (owner, shadow));
const int shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;
const int x = owner->getX();
const int y = owner->getY() - shadowEdge;
const int w = owner->getWidth();
const int h = owner->getHeight() + shadowEdge + shadowEdge;
for (int i = 4; --i >= 0;)
{
// there seem to be rare situations where the dropshadower may be deleted by
// callbacks during this loop, so use a weak ref to watch out for this..
WeakReference<Component> sw (shadowWindows[i]);
if (sw != nullptr)
{
sw->setAlwaysOnTop (owner->isAlwaysOnTop());
if (sw == nullptr)
return;
switch (i)
{
case 0: sw->setBounds (x - shadowEdge, y, shadowEdge, h); break;
case 1: sw->setBounds (x + w, y, shadowEdge, h); break;
case 2: sw->setBounds (x, y, w, shadowEdge); break;
case 3: sw->setBounds (x, owner->getBottom(), w, shadowEdge); break;
default: break;
}
if (sw == nullptr)
return;
sw->toBehind (i == 3 ? owner.get() : shadowWindows.getUnchecked (i + 1));
}
}
}
else
{
shadowWindows.clear();
}
}
} // namespace juce
@@ -0,0 +1,96 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
Adds a drop-shadow to a component.
This object creates and manages a set of components which sit around a
component, creating a gaussian shadow around it. The components will track
the position of the component and if it's brought to the front they'll also
follow this.
For desktop windows you don't need to use this class directly - just
set the Component::windowHasDropShadow flag when calling
Component::addToDesktop(), and the system will create one of these if it's
needed (which it obviously isn't on the Mac, for example).
@tags{GUI}
*/
class JUCE_API DropShadower : private ComponentListener
{
public:
//==============================================================================
/** Creates a DropShadower. */
DropShadower (const DropShadow& shadowType);
/** Destructor. */
~DropShadower() override;
/** Attaches the DropShadower to the component you want to shadow. */
void setOwner (Component* componentToFollow);
private:
//==============================================================================
void componentMovedOrResized (Component&, bool, bool) override;
void componentBroughtToFront (Component&) override;
void componentChildrenChanged (Component&) override;
void componentParentHierarchyChanged (Component&) override;
void componentVisibilityChanged (Component&) override;
void updateParent();
void updateShadows();
class ShadowWindow;
WeakReference<Component> owner;
OwnedArray<Component> shadowWindows;
DropShadow shadow;
bool reentrant = false;
WeakReference<Component> lastParentComp;
class ParentVisibilityChangedListener;
std::unique_ptr<ParentVisibilityChangedListener> visibilityChangedListener;
class VirtualDesktopWatcher;
std::unique_ptr<VirtualDesktopWatcher> virtualDesktopWatcher;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DropShadower)
JUCE_DECLARE_WEAK_REFERENCEABLE (DropShadower)
};
} // namespace juce
@@ -0,0 +1,194 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
struct OutlineWindowComponent final : public Component
{
OutlineWindowComponent (Component* c, FocusOutline::OutlineWindowProperties& p)
: target (c), props (p)
{
setVisible (true);
setInterceptsMouseClicks (false, false);
if (target->isOnDesktop())
{
setSize (1, 1);
addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
}
else if (auto* parent = target->getParentComponent())
{
auto targetIndex = parent->getIndexOfChildComponent (target);
parent->addChildComponent (this, targetIndex + 1);
}
}
void paint (Graphics& g) override
{
if (target != nullptr)
props.drawOutline (g, getWidth(), getHeight());
}
void resized() override
{
repaint();
}
float getDesktopScaleFactor() const override
{
return target != nullptr ? target->getDesktopScaleFactor()
: Component::getDesktopScaleFactor();
}
private:
WeakReference<Component> target;
FocusOutline::OutlineWindowProperties& props;
JUCE_DECLARE_NON_COPYABLE (OutlineWindowComponent)
};
//==============================================================================
FocusOutline::FocusOutline (std::unique_ptr<OutlineWindowProperties> props)
: properties (std::move (props))
{
}
FocusOutline::~FocusOutline()
{
if (owner != nullptr)
owner->removeComponentListener (this);
if (lastParentComp != nullptr)
lastParentComp->removeComponentListener (this);
}
void FocusOutline::setOwner (Component* componentToFollow)
{
if (componentToFollow != owner)
{
if (owner != nullptr)
owner->removeComponentListener (this);
owner = componentToFollow;
if (owner != nullptr)
owner->addComponentListener (this);
updateParent();
updateOutlineWindow();
}
}
void FocusOutline::componentMovedOrResized (Component& c, bool, bool)
{
if (owner == &c)
updateOutlineWindow();
}
void FocusOutline::componentBroughtToFront (Component& c)
{
if (owner == &c)
updateOutlineWindow();
}
void FocusOutline::componentParentHierarchyChanged (Component& c)
{
if (owner == &c)
{
updateParent();
updateOutlineWindow();
}
}
void FocusOutline::componentVisibilityChanged (Component& c)
{
if (owner == &c)
updateOutlineWindow();
}
void FocusOutline::updateParent()
{
lastParentComp = (owner != nullptr ? owner->getParentComponent()
: nullptr);
}
void FocusOutline::updateOutlineWindow()
{
if (reentrant)
return;
const ScopedValueSetter<bool> setter (reentrant, true);
if (owner == nullptr)
{
outlineWindow = nullptr;
return;
}
if (owner->isShowing()
&& owner->getWidth() > 0 && owner->getHeight() > 0)
{
if (outlineWindow == nullptr)
outlineWindow = std::make_unique<OutlineWindowComponent> (owner, *properties);
WeakReference<Component> deletionChecker (outlineWindow.get());
outlineWindow->setAlwaysOnTop (owner->isAlwaysOnTop());
if (deletionChecker == nullptr)
return;
const auto windowBounds = [this]
{
const auto bounds = properties->getOutlineBounds (*owner);
if (lastParentComp != nullptr)
return lastParentComp->getLocalArea (nullptr, bounds);
return bounds;
}();
outlineWindow->setBounds (windowBounds);
}
else
{
outlineWindow = nullptr;
}
}
} // namespace juce
@@ -0,0 +1,109 @@
/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
/**
Adds a focus outline to a component.
This object creates and manages a component that sits on top of a target
component. It will track the position of the target component and will be
brought to the front with the tracked component.
Use the Component::setHasFocusOutline() method to indicate that a component
should have a focus outline drawn around it, and when it receives keyboard
focus one of these objects will be created using the
LookAndFeel::createFocusOutlineForComponent() method. You can override this
method in your own LookAndFeel classes to draw a custom outline if required.
@tags{GUI}
*/
class JUCE_API FocusOutline : private ComponentListener
{
public:
//==============================================================================
/** Defines the focus outline window properties.
Pass an instance of one of these to the FocusOutline constructor to control
the bounds for the outline window and how it is drawn.
*/
struct JUCE_API OutlineWindowProperties
{
virtual ~OutlineWindowProperties() = default;
/** Return the bounds for the outline window in screen coordinates. */
virtual Rectangle<int> getOutlineBounds (Component& focusedComponent) = 0;
/** This method will be called to draw the focus outline. */
virtual void drawOutline (Graphics&, int width, int height) = 0;
};
//==============================================================================
/** Creates a FocusOutline.
Call setOwner to attach it to a component.
*/
FocusOutline (std::unique_ptr<OutlineWindowProperties> props);
/** Destructor. */
~FocusOutline() override;
/** Attaches the outline to a component. */
void setOwner (Component* componentToFollow);
private:
//==============================================================================
void componentMovedOrResized (Component&, bool, bool) override;
void componentBroughtToFront (Component&) override;
void componentParentHierarchyChanged (Component&) override;
void componentVisibilityChanged (Component&) override;
void updateOutlineWindow();
void updateParent();
//==============================================================================
std::unique_ptr<OutlineWindowProperties> properties;
WeakReference<Component> owner;
std::unique_ptr<Component> outlineWindow;
WeakReference<Component> lastParentComp;
bool reentrant = false;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FocusOutline)
};
} // namespace juce