Browse Source

Added method Drawable::replaceColour

tags/2021-05-28
jules 12 years ago
parent
commit
8ee40273f2
4 changed files with 37 additions and 0 deletions
  1. +12
    -0
      modules/juce_gui_basics/drawables/juce_Drawable.cpp
  2. +5
    -0
      modules/juce_gui_basics/drawables/juce_Drawable.h
  3. +18
    -0
      modules/juce_gui_basics/drawables/juce_DrawableShape.cpp
  4. +2
    -0
      modules/juce_gui_basics/drawables/juce_DrawableShape.h

+ 12
- 0
modules/juce_gui_basics/drawables/juce_Drawable.cpp 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)
{


+ 5
- 0
modules/juce_gui_basics/drawables/juce_Drawable.h 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


+ 18
- 0
modules/juce_gui_basics/drawables/juce_DrawableShape.cpp 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;
}

+ 2
- 0
modules/juce_gui_basics/drawables/juce_DrawableShape.h 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:
//==============================================================================


Loading…
Cancel
Save