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

Added method Drawable::replaceColour

This commit is contained in:
jules 2014-02-12 14:50:24 +00:00
parent 14906d2293
commit 8ee40273f2
4 changed files with 37 additions and 0 deletions

View file

@ -107,6 +107,18 @@ void Drawable::setBoundsToEnclose (const Rectangle<float>& area)
setBounds (newBounds);
}
//==============================================================================
bool Drawable::replaceColour (Colour original, Colour replacement)
{
bool changed = false;
for (int i = getNumChildComponents(); --i >= 0;)
if (Drawable* d = dynamic_cast<Drawable*> (getChildComponent(i)))
changed = d->replaceColour (original, replacement) || changed;
return changed;
}
//==============================================================================
void Drawable::setOriginWithOriginalSize (Point<float> originWithinParent)
{

View file

@ -175,6 +175,11 @@ public:
*/
virtual Rectangle<float> getDrawableBounds() const = 0;
/** Recursively replaces a colour that might be used for filling or stroking.
return true if any instances of this colour were found.
*/
virtual bool replaceColour (Colour originalColour, Colour replacementColour);
//==============================================================================
/** Internal class used to manage ValueTrees that represent Drawables. */
class ValueTreeWrapperBase

View file

@ -452,3 +452,21 @@ void DrawableShape::FillAndStrokeState::setStrokeType (const PathStrokeType& new
state.setProperty (capStyle, newStrokeType.getEndStyle() == PathStrokeType::butt
? "butt" : (newStrokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), undoManager);
}
static bool replaceColourInFill (DrawableShape::RelativeFillType& fill, Colour original, Colour replacement)
{
if (fill.fill.colour == original && fill.fill.isColour())
{
fill = FillType (replacement);
return true;
}
return false;
}
bool DrawableShape::replaceColour (Colour original, Colour replacement)
{
bool changed1 = replaceColourInFill (mainFill, original, replacement);
bool changed2 = replaceColourInFill (strokeFill, original, replacement);
return changed1 || changed2;
}

View file

@ -147,6 +147,8 @@ public:
void paint (Graphics&) override;
/** @internal */
bool hitTest (int x, int y) override;
/** @internal */
bool replaceColour (Colour originalColour, Colour replacementColour) override;
protected:
//==============================================================================