mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some methods ColourGradient::vertical and ColourGradient::horizontal, and also some missing move operators for that class
This commit is contained in:
parent
8589f38cfb
commit
c3a218ab49
10 changed files with 110 additions and 55 deletions
|
|
@ -27,7 +27,7 @@
|
|||
namespace juce
|
||||
{
|
||||
|
||||
ColourGradient::ColourGradient() noexcept
|
||||
ColourGradient::ColourGradient() noexcept : isRadial (false)
|
||||
{
|
||||
#if JUCE_DEBUG
|
||||
point1.setX (987654.0f);
|
||||
|
|
@ -37,6 +37,33 @@ ColourGradient::ColourGradient() noexcept
|
|||
#endif
|
||||
}
|
||||
|
||||
ColourGradient::ColourGradient (const ColourGradient& other)
|
||||
: point1 (other.point1), point2 (other.point2), isRadial (other.isRadial), colours (other.colours)
|
||||
{}
|
||||
|
||||
ColourGradient::ColourGradient (ColourGradient&& other) noexcept
|
||||
: point1 (other.point1), point2 (other.point2), isRadial (other.isRadial),
|
||||
colours (static_cast<Array<ColourPoint>&&> (other.colours))
|
||||
{}
|
||||
|
||||
ColourGradient& ColourGradient::operator= (const ColourGradient& other)
|
||||
{
|
||||
point1 = other.point1;
|
||||
point2 = other.point2;
|
||||
isRadial = other.isRadial;
|
||||
colours = other.colours;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColourGradient& ColourGradient::operator= (ColourGradient&& other) noexcept
|
||||
{
|
||||
point1 = other.point1;
|
||||
point2 = other.point2;
|
||||
isRadial = other.isRadial;
|
||||
colours = static_cast<Array<ColourPoint>&&> (other.colours);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ColourGradient::ColourGradient (Colour colour1, float x1, float y1,
|
||||
Colour colour2, float x2, float y2, bool radial)
|
||||
: ColourGradient (colour1, Point<float> (x1, y1),
|
||||
|
|
@ -50,12 +77,20 @@ ColourGradient::ColourGradient (Colour colour1, Point<float> p1,
|
|||
point2 (p2),
|
||||
isRadial (radial)
|
||||
{
|
||||
colours.add (ColourPoint (0.0, colour1));
|
||||
colours.add (ColourPoint (1.0, colour2));
|
||||
colours.add ({ 0.0, colour1 });
|
||||
colours.add ({ 1.0, colour2 });
|
||||
}
|
||||
|
||||
ColourGradient::~ColourGradient()
|
||||
ColourGradient::~ColourGradient() {}
|
||||
|
||||
ColourGradient ColourGradient::vertical (Colour c1, float y1, Colour c2, float y2)
|
||||
{
|
||||
return { c1, 0, y1, c2, 0, y2, false };
|
||||
}
|
||||
|
||||
ColourGradient ColourGradient::horizontal (Colour c1, float x1, Colour c2, float x2)
|
||||
{
|
||||
return { c1, x1, 0, c2, x2, 0, false };
|
||||
}
|
||||
|
||||
bool ColourGradient::operator== (const ColourGradient& other) const noexcept
|
||||
|
|
@ -116,7 +151,7 @@ int ColourGradient::getNumColours() const noexcept
|
|||
return colours.size();
|
||||
}
|
||||
|
||||
double ColourGradient::getColourPosition (const int index) const noexcept
|
||||
double ColourGradient::getColourPosition (int index) const noexcept
|
||||
{
|
||||
if (isPositiveAndBelow (index, colours.size()))
|
||||
return colours.getReference (index).position;
|
||||
|
|
@ -124,7 +159,7 @@ double ColourGradient::getColourPosition (const int index) const noexcept
|
|||
return 0;
|
||||
}
|
||||
|
||||
Colour ColourGradient::getColour (const int index) const noexcept
|
||||
Colour ColourGradient::getColour (int index) const noexcept
|
||||
{
|
||||
if (isPositiveAndBelow (index, colours.size()))
|
||||
return colours.getReference (index).colour;
|
||||
|
|
@ -138,7 +173,7 @@ void ColourGradient::setColour (int index, Colour newColour) noexcept
|
|||
colours.getReference (index).colour = newColour;
|
||||
}
|
||||
|
||||
Colour ColourGradient::getColourAtPosition (const double position) const noexcept
|
||||
Colour ColourGradient::getColourAtPosition (double position) const noexcept
|
||||
{
|
||||
jassert (colours.getReference(0).position == 0.0); // the first colour specified has to go at position 0
|
||||
|
||||
|
|
@ -223,12 +258,12 @@ bool ColourGradient::isInvisible() const noexcept
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ColourGradient::ColourPoint::operator== (const ColourPoint& other) const noexcept
|
||||
bool ColourGradient::ColourPoint::operator== (ColourPoint other) const noexcept
|
||||
{
|
||||
return position == other.position && colour == other.colour;
|
||||
}
|
||||
|
||||
bool ColourGradient::ColourPoint::operator!= (const ColourPoint& other) const noexcept
|
||||
bool ColourGradient::ColourPoint::operator!= (ColourPoint other) const noexcept
|
||||
{
|
||||
return position != other.position || colour != other.colour;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,18 @@ namespace juce
|
|||
class JUCE_API ColourGradient final
|
||||
{
|
||||
public:
|
||||
/** Creates an uninitialised gradient.
|
||||
|
||||
If you use this constructor instead of the other one, be sure to set all the
|
||||
object's public member variables before using it!
|
||||
*/
|
||||
ColourGradient() noexcept;
|
||||
|
||||
ColourGradient (const ColourGradient&);
|
||||
ColourGradient (ColourGradient&&) noexcept;
|
||||
ColourGradient& operator= (const ColourGradient&);
|
||||
ColourGradient& operator= (ColourGradient&&) noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Creates a gradient object.
|
||||
|
||||
|
|
@ -79,12 +91,13 @@ public:
|
|||
Colour colour2, Point<float> point2,
|
||||
bool isRadial);
|
||||
|
||||
/** Creates an uninitialised gradient.
|
||||
/** Creates a vertical linear gradient between two Y coordinates */
|
||||
static ColourGradient vertical (Colour colour1, float y1,
|
||||
Colour colour2, float y2);
|
||||
|
||||
If you use this constructor instead of the other one, be sure to set all the
|
||||
object's public member variables before using it!
|
||||
*/
|
||||
ColourGradient() noexcept;
|
||||
/** Creates a horizontal linear gradient between two X coordinates */
|
||||
static ColourGradient horizontal (Colour colour1, float x1,
|
||||
Colour colour2, float x2);
|
||||
|
||||
/** Destructor */
|
||||
~ColourGradient();
|
||||
|
|
@ -182,13 +195,10 @@ private:
|
|||
struct ColourPoint
|
||||
{
|
||||
ColourPoint() noexcept {}
|
||||
ColourPoint (double pos, Colour col) noexcept : position (pos), colour (col) {}
|
||||
|
||||
ColourPoint (const double pos, Colour col) noexcept
|
||||
: position (pos), colour (col)
|
||||
{}
|
||||
|
||||
bool operator== (const ColourPoint&) const noexcept;
|
||||
bool operator!= (const ColourPoint&) const noexcept;
|
||||
bool operator== (ColourPoint) const noexcept;
|
||||
bool operator!= (ColourPoint) const noexcept;
|
||||
|
||||
double position;
|
||||
Colour colour;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ FillType::FillType (const ColourGradient& g)
|
|||
{
|
||||
}
|
||||
|
||||
FillType::FillType (ColourGradient&& g)
|
||||
: colour (0xff000000), gradient (new ColourGradient (static_cast<ColourGradient&&> (g)))
|
||||
{
|
||||
}
|
||||
|
||||
FillType::FillType (const Image& im, const AffineTransform& t) noexcept
|
||||
: colour (0xff000000), image (im), transform (t)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ public:
|
|||
*/
|
||||
FillType (const ColourGradient& gradient);
|
||||
|
||||
/** Creates a gradient fill type.
|
||||
@see setGradient
|
||||
*/
|
||||
FillType (ColourGradient&& gradient);
|
||||
|
||||
/** Creates a tiled image fill type. The transform allows you to set the scaling, offset
|
||||
and rotation of the pattern.
|
||||
@see setTiledImage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue