29 template <gradient_sharing Sharing>
105 const std::optional<gradient_tile>&
tile()
const override;
117 result.set_bounding_box(aBoundingBox);
123 if (result.bounding_box() == std::nullopt)
124 result.set_bounding_box(aBoundingBox);
129 const i_gradient_sampler&
colors()
const override;
130 const i_gradient_filter&
filter()
const override;
136 i_gradient
const&
object()
const;
154 if (std::holds_alternative<gradient>(aColorOrGradient))
155 static_variant_cast<gradient>(aColorOrGradient).set_bounding_box(aBoundingBox);
160 if (aColorOrGradient != std::nullopt)
166 if (std::holds_alternative<gradient>(aColorOrGradient))
168 auto const& g = static_variant_cast<gradient const&>(aColorOrGradient);
169 if (!aOnlyIfTiled || (g.tile() != std::nullopt && !g.tile()->aligned))
170 return g.with_bounding_box(aBoundingBox);
172 return aColorOrGradient;
182 else if (aLhs.
id() == aRhs.
id())
194 return std::partial_ordering::unordered;
196 return std::partial_ordering::less;
198 return std::partial_ordering::greater;
200 else if (aLhs.
id() == aRhs.
id())
201 return std::partial_ordering::equivalent;
209 if (aColorOrGradient != std::nullopt)
211 return aColorOrGradient;
214 template <
typename Elem,
typename Traits>
215 inline std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& aStream,
const i_gradient& aGradient)
217 aStream << std::setprecision(4) <<
"[";
219 for (
auto const& stop : aGradient.color_stops())
220 aStream << (&stop != &aGradient.color_stops()[0] ?
", " :
"") << stop.first() <<
", " << sRGB_color{ stop.second() };
223 for (
auto const& stop : aGradient.alpha_stops())
224 aStream << (&stop != &aGradient.alpha_stops()[0] ?
", " :
"") << stop.first() <<
", " << stop.second() * 1.0 /
std::numeric_limits<sRGB_color::view_component>::max();
226 aStream <<
", " << enum_to_string(aGradient.direction());
227 if (std::holds_alternative<scalar>(aGradient.orientation()))
228 aStream <<
", " << std::get<scalar>(aGradient.orientation());
230 aStream <<
", " << enum_to_string(std::get<corner>(aGradient.orientation()));
231 aStream <<
", " << enum_to_string(aGradient.shape());
232 aStream <<
", " << enum_to_string(aGradient.size());
234 if (aGradient.exponents())
235 aStream << aGradient.exponents()->x <<
", " << aGradient.exponents()->y;
238 if (aGradient.center())
239 aStream << aGradient.center()->x <<
", " << aGradient.center()->y;
242 if (aGradient.tile())
243 aStream << aGradient.tile()->extents.cx <<
", " << aGradient.tile()->extents.cy <<
", " << aGradient.tile()->aligned;
245 aStream <<
", " << aGradient.smoothness();
250 template <
typename Elem,
typename Traits>
251 inline std::basic_istream<Elem, Traits>&
operator>>(std::basic_istream<Elem, Traits>& aStream, i_gradient& aGradient)
253 auto previousImbued = aStream.getloc();
257 std::string tempString;
259 aStream >> ignore >> ignore;
264 aStream >> colorStop.
first() >> colorStop.
second();
269 aStream >> ignore >> ignore;
274 aStream >> alphaStop.
first() >> tempScalar;
282 aStream >> tempString;
285 if (aStream >> tempScalar)
287 orientation = tempScalar;
292 aStream >> tempString;
296 aStream >> tempString;
299 aStream >> tempString;
303 if (aStream >> tempScalar)
307 exponents.
emplace(tempScalar, y);
314 if (aStream >> tempScalar)
324 std::optional<gradient_tile> tile;
325 if (aStream >> tempScalar)
337 aStream >> smoothness;
340 aGradient.set_orientation(orientation);
341 aGradient.set_shape(shape);
342 aGradient.set_size(
size);
343 aGradient.set_exponents(exponents);
344 aGradient.set_center(center);
345 aGradient.set_tile(tile);
346 aGradient.set_smoothness(smoothness);
347 aStream.imbue(previousImbued);
351 template <
typename Elem,
typename Traits>
352 inline std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& aStream,
const color_or_gradient& aColorOrGradient)
355 aStream << aColorOrGradient.index();
356 if (aColorOrGradient.index() != 0)
359 if (std::holds_alternative<color>(aColorOrGradient))
360 aStream << static_variant_cast<color const&>(aColorOrGradient);
361 else if (std::holds_alternative<gradient>(aColorOrGradient))
362 aStream << static_variant_cast<gradient const&>(aColorOrGradient);
368 template <
typename Elem,
typename Traits>
371 auto previousImbued = aStream.getloc();
384 aColorOrGradient = temp;
391 aColorOrGradient = temp;
395 aStream.imbue(previousImbued);
ViewComponent view_component
const optional_rect & bounding_box() const override
self_type & set_combined_alpha(sRGB_color::view_component aAlpha) override
alpha_stop_list::abstract_type abstract_alpha_stop_list
basic_gradient(const i_string &aCssDeclaration)
const i_gradient_sampler & colors() const override
void clone(neolib::i_ref_ptr< i_gradient > &aResult) const override
basic_gradient< Sharing > self_type
sRGB_color color_at(scalar aPos, scalar aStart, scalar aEnd) const override
basic_gradient(const i_gradient &aOther)
self_type & set_size(gradient_size aSize) override
basic_gradient(const abstract_color_stop_list &aColorStops, const abstract_alpha_stop_list &aAlphaStops, gradient_direction aDirection=gradient_direction::Vertical)
self_type with_bounding_box_if_none(const optional_rect &aBoundingBox) const
gradient_id id() const override
abstract_alpha_stop_list::const_iterator find_alpha_stop(scalar aPos, bool aToInsert=false) const override
self_type & set_bounding_box(const optional_rect &aBoundingBox) override
gradient_orientation orientation() const override
abstract_color_stop_list::iterator insert_color_stop(scalar aPos) override
basic_gradient(const sRGB_color &aColor)
self_type & set_shape(gradient_shape aShape) override
self_type & set_center(const optional_point &aCenter) override
abstract_alpha_stop_list::iterator insert_alpha_stop(scalar aPos) override
basic_gradient(const basic_gradient &aOther, const abstract_color_stop_list &aColorStops)
abstract_alpha_stop_list const & alpha_stops() const override
basic_gradient(const neolib::i_vector< sRGB_color::abstract_type > &aColors, gradient_direction aDirection=gradient_direction::Vertical)
basic_gradient(const i_ref_ptr< i_gradient > &aObject)
self_type & set_smoothness(scalar aSmoothness) override
abstract_alpha_stop_list::iterator find_alpha_stop(scalar aPos, bool aToInsert=false) override
color_stop_list::abstract_type abstract_color_stop_list
sRGB_color color_at(scalar aPos) const override
self_type & set_direction(gradient_direction aDirection) override
abstract_color_stop_list::const_iterator find_color_stop(scalar aPos, scalar aStart, scalar aEnd, bool aToInsert=false) const override
self_type with_bounding_box(const optional_rect &aBoundingBox) const
basic_gradient(const sRGB_color &aColor1, const sRGB_color &aColor2, gradient_direction aDirection=gradient_direction::Vertical)
abstract_alpha_stop_list & alpha_stops() override
gradient_size size() const override
sRGB_color::view_component alpha_at(scalar aPos, scalar aStart, scalar aEnd) const override
basic_gradient(const abstract_color_stop_list &aColorStops, gradient_direction aDirection=gradient_direction::Vertical)
neolib::pair< scalar, sRGB_color > color_stop
const i_gradient_filter & filter() const override
abstract_color_stop_list const & color_stops() const override
self_type & reverse() override
bool is_singular() const override
basic_gradient(const basic_gradient &aOther)
self_type & set_tile(const std::optional< gradient_tile > &aTile) override
gradient_shape shape() const override
gradient_direction direction() const override
sRGB_color::view_component alpha_at(scalar aPos) const override
abstract_color_stop_list & color_stops() override
basic_gradient & operator=(const i_gradient &aOther) override
self_type & set_exponents(const optional_vec2 &aExponents) override
basic_gradient(const std::initializer_list< sRGB_color > &aColors, gradient_direction aDirection=gradient_direction::Vertical)
self_type & set_alpha(sRGB_color::view_component aAlpha) override
const std::optional< gradient_tile > & tile() const override
sRGB_color at(scalar aPos) const override
basic_gradient(const basic_gradient &aOther, const abstract_color_stop_list &aColorStops, const abstract_alpha_stop_list &aAlphaStops)
abstract_color_stop_list::iterator find_color_stop(scalar aPos, scalar aStart, scalar aEnd, bool aToInsert=false) override
abstract_color_stop_list::iterator find_color_stop(scalar aPos, bool aToInsert=false) override
sRGB_color at(scalar aPos, scalar aStart, scalar aEnd) const override
abstract_color_stop_list::const_iterator find_color_stop(scalar aPos, bool aToInsert=false) const override
neolib::pair< scalar, sRGB_color::view_component > alpha_stop
neolib::vector< color_stop > color_stop_list
basic_gradient(const sRGB_color &aColor, gradient_direction aDirection)
self_type & set_orientation(gradient_orientation aOrientation) override
abstract_alpha_stop_list::iterator find_alpha_stop(scalar aPos, scalar aStart, scalar aEnd, bool aToInsert=false) override
neolib::vector< alpha_stop > alpha_stop_list
const optional_point & center() const override
self_type & set_bounding_box_if_none(const optional_rect &aBoundingBox) override
scalar smoothness() const override
abstract_color_stop_list::iterator insert_color_stop(scalar aPos, scalar aStart, scalar aEnd) override
const optional_vec2 & exponents() const override
abstract_alpha_stop_list::iterator insert_alpha_stop(scalar aPos, scalar aStart, scalar aEnd) override
abstract_alpha_stop_list::const_iterator find_alpha_stop(scalar aPos, scalar aStart, scalar aEnd, bool aToInsert=false) const override
offset_iterator< value_type > iterator
offset_iterator< const value_type > const_iterator
reference & emplace(Args &&... args)
const second_type & second() const final
const first_type & first() const final
void push_back(abstract_value_type const &aValue) final
#define define_setting_type_as(T, Name)
color_or_gradient with_bounding_box(color_or_gradient const &aColorOrGradient, rect const &aBoundingBox, bool aOnlyIfTiled=false)
text_direction direction(glyph_char const &g)
std::basic_istream< Elem, Traits > & operator>>(std::basic_istream< Elem, Traits > &aStream, basic_point< T > &aPoint)
neolib::optional< gradient > optional_gradient
neolib::variant< color, gradient > color_or_gradient
basic_gradient< gradient_sharing::Shared > shared_gradient
bool operator==(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)
neolib::optional< color_or_gradient > optional_color_or_gradient
void apply_bounding_box(color_or_gradient &aColorOrGradient, rect const &aBoundingBox)
std::partial_ordering operator<=>(const gradient &aLhs, const gradient &aRhs)
basic_size< coordinate > size
ref_ptr< ConcreteType > make_ref(Args &&... args)