From bc78b2f5244c2c6374770e1894ce2152cf037eed Mon Sep 17 00:00:00 2001 From: jules Date: Tue, 25 Apr 2017 11:52:33 +0100 Subject: [PATCH] Added a constructor to ColourGradient that takes Point arguments --- .../colour/juce_ColourGradient.cpp | 15 +++++++++++-- .../colour/juce_ColourGradient.h | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/juce_graphics/colour/juce_ColourGradient.cpp b/modules/juce_graphics/colour/juce_ColourGradient.cpp index 360d0008c2..f465ff6afa 100644 --- a/modules/juce_graphics/colour/juce_ColourGradient.cpp +++ b/modules/juce_graphics/colour/juce_ColourGradient.cpp @@ -43,6 +43,17 @@ ColourGradient::ColourGradient (Colour colour1, const float x1, const float y1, colours.add (ColourPoint (1.0, colour2)); } +ColourGradient::ColourGradient (Colour colour1, Point p1, + Colour colour2, Point p2, + const bool radial) + : point1 (p1), + point2 (p2), + isRadial (radial) +{ + colours.add (ColourPoint (0.0, colour1)); + colours.add (ColourPoint (1.0, colour2)); +} + ColourGradient::~ColourGradient() { } @@ -141,12 +152,12 @@ Colour ColourGradient::getColourAtPosition (const double position) const noexcep while (position < colours.getReference(i).position) --i; - const ColourPoint& p1 = colours.getReference (i); + auto& p1 = colours.getReference (i); if (i >= colours.size() - 1) return p1.colour; - const ColourPoint& p2 = colours.getReference (i + 1); + auto& p2 = colours.getReference (i + 1); return p1.colour.interpolatedWith (p2.colour, (float) ((position - p1.position) / (p2.position - p1.position))); } diff --git a/modules/juce_graphics/colour/juce_ColourGradient.h b/modules/juce_graphics/colour/juce_ColourGradient.h index 360950be7d..607f6aa2c9 100644 --- a/modules/juce_graphics/colour/juce_ColourGradient.h +++ b/modules/juce_graphics/colour/juce_ColourGradient.h @@ -56,6 +56,27 @@ public: Colour colour2, float x2, float y2, bool isRadial); + /** Creates a gradient object. + + point1 is the location to draw with colour1. Likewise point2 is where + colour2 should be. In between them there's a gradient. + + If isRadial is true, the colours form a circular gradient with point1 at + its centre. + + The alpha transparencies of the colours are used, so note that + if you blend from transparent to a solid colour, the RGB of the transparent + colour will become visible in parts of the gradient. e.g. blending + from Colour::transparentBlack to Colours::white will produce a + muddy grey colour midway, but Colour::transparentWhite to Colours::white + will be white all the way across. + + @see ColourGradient + */ + ColourGradient (Colour colour1, Point point1, + Colour colour2, Point point2, + bool isRadial); + /** Creates an uninitialised gradient. If you use this constructor instead of the other one, be sure to set all the