17#include <egt/detail/meta.h>
18#include <egt/geometry.h>
39# define EGT_PATTERN_CONSTEXPR constexpr
40#elif defined(__GNUC__)
41# if (__GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ < 2))
42# define EGT_PATTERN_CONSTEXPR
44# define EGT_PATTERN_CONSTEXPR constexpr
47# define EGT_PATTERN_CONSTEXPR constexpr
71 using StepArray = std::vector<std::pair<float, Color>>;
136 EGT_PATTERN_CONSTEXPR
operator Color()
const
148 if (m_type != Type::solid)
149 throw std::runtime_error(
"requested solid color in pattern that is not a solid color");
186 const Point& end,
float end_radius);
201 EGT_NODISCARD cairo_pattern_t*
pattern()
const
205 assert(m_pattern.get());
206 return m_pattern.get();
212 void create_pattern()
const;
215 static bool sort_by_first(
const std::pair<float, Color>& a,
216 const std::pair<float, Color>& b)
218 return (a.first < b.first);
229 PatternImpl* m_impl{
nullptr};
235static_assert(detail::rule_of_5<Pattern>(),
"must fulfill rule of 5");
32 bit RGBA color.
Definition color.h:41
A Pattern which can store one or more colors at different offsets (steps) which can be used to create...
Definition pattern.h:55
EGT_NODISCARD Color first() const
Get the first color of the pattern.
float StepScaler
Scalar type for pattern steps.
Definition pattern.h:68
Type
Type of pattern.
Definition pattern.h:60
Pattern() noexcept=default
void radial(const Point &start, float start_radius, const Point &end, float end_radius)
Create a radial gradient from start to end.
std::vector< std::pair< float, Color > > StepArray
Step array type.
Definition pattern.h:71
void linear(const Point &start, const Point &end)
Create a linear gradient from start to end.
bool operator!=(const Pattern &rhs) const
Definition pattern.h:127
Pattern(const StepArray &steps, const Point &start, const Point &end)
Construct a linear pattern with the specified steps.
Color m_color
Solid color of the pattern.
Definition pattern.h:225
EGT_NODISCARD cairo_pattern_t * pattern() const
Get internal pattern representation.
Definition pattern.h:201
Pattern(Type type, const StepArray &steps={})
Construct a pattern with the specified type and steps.
EGT_DEPRECATED EGT_NODISCARD Color color() const
Get the first color of the pattern.
Definition pattern.h:157
EGT_NODISCARD Point ending() const
Get the ending point of the pattern.
EGT_PATTERN_CONSTEXPR Color solid() const
Get the solid color.
Definition pattern.h:146
Pattern & step(StepScaler offset, const Color &color)
Add a step to the gradient.
EGT_NODISCARD const StepArray & steps() const
Get all of the steps of the pattern.
EGT_NODISCARD Type type() const
Get the type of pattern.
Definition pattern.h:175
EGT_NODISCARD float ending_radius() const
Get the ending radius of the pattern.
bool operator==(const Pattern &rhs) const
Compare two patterns.
shared_cairo_pattern_t m_pattern
Internal pattern representation.
Definition pattern.h:232
Pattern(const StepArray &steps, const Point &start, float start_radius, const Point &end, float end_radius)
Construct a radial pattern with the specified steps.
EGT_NODISCARD Point starting() const
Get the starting point of the pattern.
EGT_NODISCARD float starting_radius() const
Get the starting radius of the pattern.
constexpr bool operator==(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:500
std::shared_ptr< cairo_pattern_t > shared_cairo_pattern_t
Shared pointer for a cairo pattern.
Definition types.h:41
EGT framework namespace.
Definition animation.h:24