1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11    Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12 
13    End User License Agreement: www.juce.com/juce-6-licence
14    Privacy Policy: www.juce.com/juce-privacy-policy
15 
16    Or: You may also use this code under the terms of the GPL v3 (see
17    www.gnu.org/licenses).
18 
19    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21    DISCLAIMED.
22 
23   ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
FillType()29 FillType::FillType() noexcept
30     : colour (0xff000000)
31 {
32 }
33 
FillType(Colour c)34 FillType::FillType (Colour c) noexcept
35     : colour (c)
36 {
37 }
38 
FillType(const ColourGradient & g)39 FillType::FillType (const ColourGradient& g)
40     : colour (0xff000000), gradient (new ColourGradient (g))
41 {
42 }
43 
FillType(ColourGradient && g)44 FillType::FillType (ColourGradient&& g)
45     : colour (0xff000000), gradient (new ColourGradient (std::move (g)))
46 {
47 }
48 
FillType(const Image & im,const AffineTransform & t)49 FillType::FillType (const Image& im, const AffineTransform& t) noexcept
50     : colour (0xff000000), image (im), transform (t)
51 {
52 }
53 
FillType(const FillType & other)54 FillType::FillType (const FillType& other)
55     : colour (other.colour),
56       gradient (createCopyIfNotNull (other.gradient.get())),
57       image (other.image),
58       transform (other.transform)
59 {
60 }
61 
operator =(const FillType & other)62 FillType& FillType::operator= (const FillType& other)
63 {
64     if (this != &other)
65     {
66         colour = other.colour;
67         gradient.reset (createCopyIfNotNull (other.gradient.get()));
68         image = other.image;
69         transform = other.transform;
70     }
71 
72     return *this;
73 }
74 
FillType(FillType && other)75 FillType::FillType (FillType&& other) noexcept
76     : colour (other.colour),
77       gradient (std::move (other.gradient)),
78       image (std::move (other.image)),
79       transform (other.transform)
80 {
81 }
82 
operator =(FillType && other)83 FillType& FillType::operator= (FillType&& other) noexcept
84 {
85     jassert (this != &other); // hopefully the compiler should make this situation impossible!
86 
87     colour = other.colour;
88     gradient = std::move (other.gradient);
89     image = std::move (other.image);
90     transform = other.transform;
91     return *this;
92 }
93 
~FillType()94 FillType::~FillType() noexcept
95 {
96 }
97 
operator ==(const FillType & other) const98 bool FillType::operator== (const FillType& other) const
99 {
100     return colour == other.colour && image == other.image
101             && transform == other.transform
102             && (gradient == other.gradient
103                  || (gradient != nullptr && other.gradient != nullptr && *gradient == *other.gradient));
104 }
105 
operator !=(const FillType & other) const106 bool FillType::operator!= (const FillType& other) const
107 {
108     return ! operator== (other);
109 }
110 
setColour(Colour newColour)111 void FillType::setColour (Colour newColour) noexcept
112 {
113     gradient.reset();
114     image = {};
115     colour = newColour;
116 }
117 
setGradient(const ColourGradient & newGradient)118 void FillType::setGradient (const ColourGradient& newGradient)
119 {
120     if (gradient != nullptr)
121     {
122         *gradient = newGradient;
123     }
124     else
125     {
126         image = {};
127         gradient.reset (new ColourGradient (newGradient));
128         colour = Colours::black;
129     }
130 }
131 
setTiledImage(const Image & newImage,const AffineTransform & newTransform)132 void FillType::setTiledImage (const Image& newImage, const AffineTransform& newTransform) noexcept
133 {
134     gradient.reset();
135     image = newImage;
136     transform = newTransform;
137     colour = Colours::black;
138 }
139 
setOpacity(const float newOpacity)140 void FillType::setOpacity (const float newOpacity) noexcept
141 {
142     colour = colour.withAlpha (newOpacity);
143 }
144 
isInvisible() const145 bool FillType::isInvisible() const noexcept
146 {
147     return colour.isTransparent() || (gradient != nullptr && gradient->isInvisible());
148 }
149 
transformed(const AffineTransform & t) const150 FillType FillType::transformed (const AffineTransform& t) const
151 {
152     FillType f (*this);
153     f.transform = f.transform.followedBy (t);
154     return f;
155 }
156 
157 } // namespace juce
158