адаптация s13bby/osc под vst и gui. (вайбкод)
вайбкод потому что мне в моменте стало понятно. что проще было сразу писать на фреймворке JUCE, чем адаптировать консольное приложение на MiniAudio. обновляться данный репозиторий не будет. СmakeLists адаптирован онли под linux.
This commit is contained in:
@@ -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-9-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-9-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,140 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
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-9-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
|
||||
{
|
||||
|
||||
DrawableComponent::DrawableComponent (Drawable& drawableIn, BoundsToEnclose boundsToEncloseIn)
|
||||
: drawable (drawableIn), boundsToEnclose (boundsToEncloseIn)
|
||||
{
|
||||
drawable.addListener (this);
|
||||
resetComponentBoundsTo (boundsToEnclose == BoundsToEnclose::drawableBounds ? drawable.getDrawableBounds()
|
||||
: drawable.getContentBounds());
|
||||
|
||||
setInterceptsMouseClicks (false, false);
|
||||
setPaintingIsUnclipped (true);
|
||||
setAccessible (false);
|
||||
}
|
||||
|
||||
DrawableComponent::DrawableComponent (Drawable& drawableIn)
|
||||
: DrawableComponent (drawableIn, BoundsToEnclose::drawableBounds)
|
||||
{
|
||||
}
|
||||
|
||||
DrawableComponent::~DrawableComponent()
|
||||
{
|
||||
drawable.removeListener (this);
|
||||
}
|
||||
|
||||
void DrawableComponent::setTransformToFit (const Rectangle<float>& areaInParent, RectanglePlacement placement)
|
||||
{
|
||||
if (areaInParent.isEmpty())
|
||||
return;
|
||||
|
||||
const auto boundsToFit = boundsToEnclose == BoundsToEnclose::drawableBounds ? drawable.getDrawableBounds()
|
||||
: drawable.getContentBounds();
|
||||
setTransform (placement.getTransformToFit (boundsToFit, areaInParent));
|
||||
}
|
||||
|
||||
Path DrawableComponent::getOutlineAsPath() const
|
||||
{
|
||||
auto p = drawable.getOutlineAsPath();
|
||||
p.applyTransform (getTransform());
|
||||
return p;
|
||||
}
|
||||
|
||||
void DrawableComponent::paint (Graphics& g)
|
||||
{
|
||||
g.setOrigin (originRelativeToComponent);
|
||||
drawable.draw (g, 1.0f);
|
||||
}
|
||||
|
||||
bool DrawableComponent::hitTest (int x, int y)
|
||||
{
|
||||
if (Component::hitTest (x, y))
|
||||
return true;
|
||||
|
||||
bool allowsClicksOnThisComponent, allowsClicksOnChildComponents;
|
||||
getInterceptsMouseClicks (allowsClicksOnThisComponent, allowsClicksOnChildComponents);
|
||||
|
||||
if (! allowsClicksOnChildComponents)
|
||||
return false;
|
||||
|
||||
const Point<int> p { x - originRelativeToComponent.x, y - originRelativeToComponent.y };
|
||||
return drawable.hitTest (p.toFloat());
|
||||
}
|
||||
|
||||
class DrawableTextAccessibilityHandler final : public AccessibilityHandler
|
||||
{
|
||||
public:
|
||||
DrawableTextAccessibilityHandler (Component& c, const String& textToWrap)
|
||||
: AccessibilityHandler (c, AccessibilityRole::staticText),
|
||||
text (textToWrap)
|
||||
{
|
||||
}
|
||||
|
||||
String getTitle() const override
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
private:
|
||||
String text;
|
||||
};
|
||||
|
||||
std::unique_ptr<AccessibilityHandler> DrawableComponent::createAccessibilityHandler()
|
||||
{
|
||||
if (drawable.isImage())
|
||||
return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::image);
|
||||
|
||||
if (auto t = drawable.getContainedText(); t.has_value())
|
||||
return std::make_unique<DrawableTextAccessibilityHandler> (*this, *t);
|
||||
|
||||
return Component::createAccessibilityHandler();
|
||||
}
|
||||
|
||||
void DrawableComponent::resetComponentBoundsTo (Rectangle<float> bounds)
|
||||
{
|
||||
const auto drawableBounds = bounds.getSmallestIntegerContainer();
|
||||
originRelativeToComponent = -drawableBounds.getPosition();
|
||||
setBounds (drawableBounds);
|
||||
}
|
||||
|
||||
void DrawableComponent::drawableBoundsChanged (Drawable* d)
|
||||
{
|
||||
if (boundsToEnclose == BoundsToEnclose::drawableBounds)
|
||||
resetComponentBoundsTo (d->getDrawableBounds());
|
||||
}
|
||||
|
||||
} // namespace juce
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
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-9-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
|
||||
{
|
||||
|
||||
/** Specifies the source bounds that a DrawableComponent should fit itself around.
|
||||
|
||||
New projects should use contentBounds, as this will respect the designer's intent when
|
||||
specifying a viewBox in an SVG file. Even better, avoid using DrawableComponent
|
||||
entirely, which is meant as a backwards compatibility class for projects migrating from
|
||||
JUCE 8.
|
||||
|
||||
@see DrawableComponent
|
||||
*/
|
||||
enum class BoundsToEnclose
|
||||
{
|
||||
drawableBounds, ///< The bounds returned by Drawable::getDrawableBounds(). These are the
|
||||
///< smallest rectangular bounds covering visible features of the Drawable.
|
||||
///< The Drawable class prior to JUCE 9 used these bounds for fitting.
|
||||
contentBounds ///< The bounds returned by Drawable::getContentBounds(). For Drawables
|
||||
///< that were created by parsing an SVG, this will return the viewBox, which
|
||||
///< expresses the designer's intent for fitting purposes. The fallback
|
||||
///< value is the same as the one returned by Drawable::getDrawableBounds().
|
||||
};
|
||||
|
||||
class JUCE_API DrawableComponent : public Component,
|
||||
private Drawable::Listener
|
||||
{
|
||||
public:
|
||||
/** Wraps a Drawable object in a Component. */
|
||||
explicit DrawableComponent (Drawable& drawableIn);
|
||||
|
||||
/** Wraps a Drawable object in a Component. */
|
||||
DrawableComponent (Drawable& drawableIn, BoundsToEnclose boundsToEnclose);
|
||||
|
||||
/** Destructor. */
|
||||
~DrawableComponent() override;
|
||||
|
||||
/** Sets a transform for this drawable that will position it within the specified
|
||||
area of its parent component.
|
||||
*/
|
||||
void setTransformToFit (const Rectangle<float>& areaInParent, RectanglePlacement placement);
|
||||
|
||||
/** Creates a path that describes the outline of this DrawableComponent. */
|
||||
Path getOutlineAsPath() const;
|
||||
|
||||
/** Returns a reference to the Drawable object displayed by this Component. */
|
||||
Drawable& getDrawable()
|
||||
{
|
||||
return drawable;
|
||||
}
|
||||
|
||||
/** Returns a reference to the Drawable object displayed by this Component. */
|
||||
const Drawable& getDrawable() const
|
||||
{
|
||||
return drawable;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void paint (Graphics& g) override;
|
||||
|
||||
bool hitTest (int x, int y) override;
|
||||
|
||||
std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
|
||||
|
||||
//==============================================================================
|
||||
/** @internal
|
||||
|
||||
Intended to replace Drawable::setBoundsToEnclose which is only ever called in conjunction
|
||||
with getDrawableBounds().
|
||||
*/
|
||||
void resetComponentBoundsTo (Rectangle<float> bounds);
|
||||
|
||||
private:
|
||||
void drawableBoundsChanged (Drawable*) override;
|
||||
|
||||
Drawable& drawable;
|
||||
Point<int> originRelativeToComponent;
|
||||
BoundsToEnclose boundsToEnclose;
|
||||
};
|
||||
|
||||
} // namespace juce
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
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-9-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)
|
||||
{
|
||||
if (comp == nullptr)
|
||||
{
|
||||
jassertfalse;
|
||||
return;
|
||||
}
|
||||
|
||||
setVisible (true);
|
||||
setAccessible (false);
|
||||
setInterceptsMouseClicks (false, false);
|
||||
|
||||
if (comp->isOnDesktop())
|
||||
{
|
||||
#if JUCE_WINDOWS
|
||||
const ScopedThreadDPIAwarenessSetter scope { comp != nullptr ? comp->getWindowHandle() : nullptr };
|
||||
#endif
|
||||
|
||||
setSize (1, 1); // to keep the OS happy by not having zero-size windows
|
||||
addToDesktop (DesktopWindowOptions().withStyleFlags (ComponentPeer::windowIgnoresMouseClicks
|
||||
| ComponentPeer::windowIsTemporary
|
||||
| ComponentPeer::windowIgnoresKeyPresses)
|
||||
.withAssociatedComponent (comp));
|
||||
|
||||
if (auto* compPeer = comp->getPeer())
|
||||
if (auto* selfPeer = getPeer())
|
||||
selfPeer->setCustomPlatformScaleFactor (compPeer->getPlatformScaleFactor());
|
||||
}
|
||||
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()));
|
||||
}
|
||||
|
||||
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::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::invoke ([&]
|
||||
{
|
||||
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)
|
||||
};
|
||||
|
||||
class DropShadower::ScaleWatcher
|
||||
{
|
||||
public:
|
||||
explicit ScaleWatcher (DropShadower& shadower)
|
||||
{
|
||||
if (shadower.owner == nullptr)
|
||||
return;
|
||||
|
||||
notifier.emplace (shadower.owner.get(), [&shadower] (auto x)
|
||||
{
|
||||
for (auto sw : shadower.shadowWindows)
|
||||
{
|
||||
if (! sw->isOnDesktop())
|
||||
continue;
|
||||
|
||||
if (auto* peer = sw->getPeer())
|
||||
peer->setCustomPlatformScaleFactor (x);
|
||||
}
|
||||
|
||||
shadower.updateShadows();
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<NativeScaleFactorNotifier> notifier;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
DropShadower::DropShadower (const DropShadow& ds) : shadow (ds) {}
|
||||
|
||||
DropShadower::~DropShadower()
|
||||
{
|
||||
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));
|
||||
|
||||
scaleWatcher = std::make_unique<ScaleWatcher> (*this);
|
||||
|
||||
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))
|
||||
{
|
||||
while (shadowWindows.size() < 4)
|
||||
shadowWindows.add (new ShadowWindow (owner, shadow));
|
||||
|
||||
const auto shadowEdge = jmax (shadow.offset.x, shadow.offset.y) + shadow.radius;
|
||||
const auto w = owner->getWidth();
|
||||
const auto h = owner->getHeight();
|
||||
|
||||
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
|
||||
const WeakReference sw (shadowWindows[i]);
|
||||
|
||||
if (sw != nullptr)
|
||||
{
|
||||
sw->setAlwaysOnTop (owner->isAlwaysOnTop());
|
||||
|
||||
if (sw == nullptr)
|
||||
return;
|
||||
|
||||
const auto shadowBounds = std::invoke ([&]
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0: return Rectangle { shadowEdge, h + shadowEdge + shadowEdge }.withPosition ({ -shadowEdge, -shadowEdge });
|
||||
case 1: return Rectangle { shadowEdge, h + shadowEdge + shadowEdge }.withPosition ({ w, -shadowEdge });
|
||||
case 2: return Rectangle { w, shadowEdge }.withPosition ({ 0, -shadowEdge });
|
||||
case 3: return Rectangle { w, shadowEdge }.withPosition ({ 0, h });
|
||||
default: break;
|
||||
}
|
||||
|
||||
return Rectangle<int>{};
|
||||
});
|
||||
|
||||
{
|
||||
using Scope = decltype (std::declval<ComponentPeer>().setMultimonitorPositionOverride ({}));
|
||||
const auto scope = std::invoke ([&]() -> std::optional<Scope>
|
||||
{
|
||||
auto* peer = owner->isOnDesktop() ? owner->getPeer() : nullptr;
|
||||
|
||||
if (peer == nullptr)
|
||||
return std::nullopt;
|
||||
|
||||
auto* shadowPeer = sw->getPeer();
|
||||
|
||||
if (shadowPeer == nullptr)
|
||||
return std::nullopt;
|
||||
|
||||
using SH = detail::ScalingHelpers;
|
||||
const auto localPos = SH::scaledScreenPosToUnscaled (*owner, shadowBounds.getPosition().toFloat());
|
||||
const auto multimonitorPos = peer->localToMultimonitor (localPos);
|
||||
|
||||
return shadowPeer->setMultimonitorPositionOverride (multimonitorPos.roundToInt());
|
||||
});
|
||||
|
||||
sw->setBounds (shadowBounds + owner->getPosition());
|
||||
}
|
||||
|
||||
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-9-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 ScaleWatcher;
|
||||
std::unique_ptr<ScaleWatcher> scaleWatcher;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DropShadower)
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (DropShadower)
|
||||
};
|
||||
|
||||
} // namespace juce
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
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-9-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 (DesktopWindowOptions().withStyleFlags (ComponentPeer::windowIgnoresMouseClicks
|
||||
| ComponentPeer::windowIsTemporary
|
||||
| ComponentPeer::windowIgnoresKeyPresses)
|
||||
.withAssociatedComponent (c));
|
||||
}
|
||||
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-9-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
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
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-9-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
|
||||
{
|
||||
|
||||
/**
|
||||
Helper class that owns a Drawable object and exposes it as a DrawableComponent. This class is
|
||||
meant to ease the transition from JUCE 8 to JUCE 9, where Drawable no longer inherits from
|
||||
Component and DrawableComponent takes no ownership of the Drawable object.
|
||||
|
||||
New projects should avoid using this class if possible.
|
||||
|
||||
The new suggested way to work with Drawable objects is to use them directly and draw them using
|
||||
the Drawable::draw() method. This way a heavy dependency on the Component class, and potentially
|
||||
the juce_gui_basics module can be avoided.
|
||||
|
||||
@see Drawable
|
||||
|
||||
@tags{GUI}
|
||||
*/
|
||||
class JUCE_API OwningDrawableComponent : private std::unique_ptr<Drawable>,
|
||||
public DrawableComponent
|
||||
{
|
||||
public:
|
||||
/** Creates an OwningDrawableComponent that takes ownership of the underlying Drawable object.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> create (std::unique_ptr<Drawable> d, BoundsToEnclose boundsToEnclose)
|
||||
{
|
||||
if (d == nullptr)
|
||||
return {};
|
||||
|
||||
return rawToUniquePtr (new OwningDrawableComponent (std::move (d), boundsToEnclose));
|
||||
}
|
||||
|
||||
/** Creates an OwningDrawableComponent that takes ownership of the underlying Drawable object.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> create (std::unique_ptr<Drawable> d)
|
||||
{
|
||||
return create (std::move (d), BoundsToEnclose::drawableBounds);
|
||||
}
|
||||
|
||||
/** Creates an OwningDrawableComponent that copies a Drawable and takes ownership of the copied
|
||||
object.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> createFromCopy (const Drawable* const d, BoundsToEnclose boundsToEnclose)
|
||||
{
|
||||
if (d == nullptr)
|
||||
return {};
|
||||
|
||||
auto copy = d->createCopy();
|
||||
|
||||
if (copy == nullptr)
|
||||
return {};
|
||||
|
||||
return rawToUniquePtr (new OwningDrawableComponent (std::move (copy), boundsToEnclose));
|
||||
}
|
||||
|
||||
/** Creates an OwningDrawableComponent that copies a Drawable and takes ownership of the copied
|
||||
object.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> createFromCopy (const Drawable* const d)
|
||||
{
|
||||
return createFromCopy (d, BoundsToEnclose::drawableBounds);
|
||||
}
|
||||
|
||||
/** Attempts to parse an SVG (Scalable Vector Graphics) document from a file.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> createFromSVGFile (const File& svgFile)
|
||||
{
|
||||
return create (Drawable::createFromSVGFile (svgFile));
|
||||
}
|
||||
|
||||
/** Attempts to parse an SVG (Scalable Vector Graphics) document from a string.
|
||||
*/
|
||||
static std::unique_ptr<OwningDrawableComponent> createFromSVGString (const String& svgString)
|
||||
{
|
||||
return create (Drawable::createFromSVGString (svgString));
|
||||
}
|
||||
|
||||
private:
|
||||
OwningDrawableComponent (std::unique_ptr<Drawable> drawableIn, BoundsToEnclose boundsToEncloseIn)
|
||||
: unique_ptr (std::move (drawableIn)),
|
||||
DrawableComponent (*get(), boundsToEncloseIn)
|
||||
{
|
||||
}
|
||||
|
||||
OwningDrawableComponent (std::unique_ptr<Drawable> drawableIn)
|
||||
: OwningDrawableComponent (std::move (drawableIn), BoundsToEnclose::drawableBounds)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace juce
|
||||
Reference in New Issue
Block a user