88 class i_gradient_sampler
90 friend class gradient_manager;
92 virtual ~i_gradient_sampler() =
default;
94 virtual i_shader_array<avec4u8>
const& sampler()
const = 0;
95 virtual uint32_t sampler_row()
const = 0;
96 virtual bool used_by(gradient_id aGradient)
const = 0;
97 virtual void add_ref(gradient_id aGradient)
const = 0;
98 virtual void release(gradient_id aGradient)
const = 0;
99 virtual void release_all()
const = 0;
102 class i_gradient_filter
104 friend class gradient_manager;
106 virtual ~i_gradient_filter() =
default;
108 virtual i_shader_array<float>
const& sampler()
const = 0;
110 virtual i_shader_array<float>& sampler() = 0;
113 enum class gradient_sharing
119 class i_gradient :
public i_reference_counted
121 template <gradient_sharing>
122 friend class basic_gradient;
125 struct bad_position : std::logic_error { bad_position() :
std::logic_error(
"neogfx::i_gradient::bad_position") {} };
128 static const std::uint32_t MaxStops = 256;
131 typedef i_gradient abstract_type;
138 virtual ~i_gradient() =
default;
142 virtual i_gradient& operator=(
const i_gradient& aOther) = 0;
146 virtual bool is_singular()
const = 0;
149 virtual color_stop_list
const& color_stops()
const = 0;
150 virtual color_stop_list& color_stops() = 0;
151 virtual alpha_stop_list
const& alpha_stops()
const = 0;
152 virtual alpha_stop_list& alpha_stops() = 0;
153 virtual color_stop_list::const_iterator find_color_stop(scalar aPos,
bool aToInsert =
false)
const = 0;
154 virtual color_stop_list::const_iterator find_color_stop(scalar aPos, scalar aStart, scalar aEnd,
bool aToInsert =
false)
const = 0;
155 virtual alpha_stop_list::const_iterator find_alpha_stop(scalar aPos,
bool aToInsert =
false)
const = 0;
156 virtual alpha_stop_list::const_iterator find_alpha_stop(scalar aPos, scalar aStart, scalar aEnd,
bool aToInsert =
false)
const = 0;
157 virtual color_stop_list::iterator find_color_stop(scalar aPos,
bool aToInsert =
false) = 0;
158 virtual color_stop_list::iterator find_color_stop(scalar aPos, scalar aStart, scalar aEnd,
bool aToInsert =
false) = 0;
159 virtual alpha_stop_list::iterator find_alpha_stop(scalar aPos,
bool aToInsert =
false) = 0;
160 virtual alpha_stop_list::iterator find_alpha_stop(scalar aPos, scalar aStart, scalar aEnd,
bool aToInsert =
false) = 0;
161 virtual color_stop_list::iterator insert_color_stop(scalar aPos) = 0;
162 virtual color_stop_list::iterator insert_color_stop(scalar aPos, scalar aStart, scalar aEnd) = 0;
163 virtual alpha_stop_list::iterator insert_alpha_stop(scalar aPos) = 0;
164 virtual alpha_stop_list::iterator insert_alpha_stop(scalar aPos, scalar aStart, scalar aEnd) = 0;
165 virtual sRGB_color at(scalar aPos)
const = 0;
166 virtual sRGB_color at(scalar aPos, scalar aStart, scalar aEnd)
const = 0;
167 virtual sRGB_color color_at(scalar aPos)
const = 0;
168 virtual sRGB_color color_at(scalar aPos, scalar aStart, scalar aEnd)
const = 0;
169 virtual sRGB_color::view_component alpha_at(scalar aPos)
const = 0;
170 virtual sRGB_color::view_component alpha_at(scalar aPos, scalar aStart, scalar aEnd)
const = 0;
171 virtual i_gradient& reverse() = 0;
172 virtual i_gradient& set_alpha(sRGB_color::view_component aAlpha) = 0;
173 virtual i_gradient& set_combined_alpha(sRGB_color::view_component aAlpha) = 0;
175 virtual i_gradient& set_direction(gradient_direction aDirection) = 0;
177 virtual i_gradient& set_orientation(gradient_orientation aOrientation) = 0;
179 virtual i_gradient& set_shape(gradient_shape aShape) = 0;
181 virtual i_gradient& set_size(gradient_size aSize) = 0;
183 virtual i_gradient& set_exponents(
const optional_vec2& aExponents) = 0;
185 virtual i_gradient& set_center(
const optional_point& aCenter) = 0;
186 virtual const std::optional<gradient_tile>& tile()
const = 0;
187 virtual i_gradient& set_tile(
const std::optional<gradient_tile>& aTile) = 0;
188 virtual scalar smoothness()
const = 0;
189 virtual i_gradient& set_smoothness(scalar aSmoothness) = 0;
191 virtual i_gradient& set_bounding_box(
const optional_rect& aBoundingBox) = 0;
192 virtual i_gradient& set_bounding_box_if_none(
const optional_rect& aBoundingBox) = 0;
195 virtual const i_gradient_sampler& colors()
const = 0;
196 virtual const i_gradient_filter& filter()
const = 0;
199 virtual void share_object(i_ref_ptr<i_gradient>& aRef)
const = 0;
210 auto result = clone();
216 auto result = clone();
217 result->set_alpha(aAlpha);
220 template <
typename T>
223 return with_alpha(sRGB_color::convert<sRGB_color::view_component>(aAlpha));
227 auto result = clone();
228 result->set_combined_alpha(aAlpha);
231 template <
typename T>
232 neolib::ref_ptr<i_gradient> with_combined_alpha(T aAlpha, std::enable_if_t<!std::is_same_v<T, sRGB_color::view_component>, sfinae> = {})
const
234 return with_combined_alpha(sRGB_color::convert<sRGB_color::view_component>(aAlpha));
238 auto result = clone();
239 result->set_direction(aDirection);
244 auto result = clone();
245 result->set_orientation(aOrientation);
250 auto result = clone();
251 result->set_shape(aShape);
256 auto result = clone();
257 result->set_size(aSize);
262 auto result = clone();
263 result->set_exponents(aExponents);
268 auto result = clone();
269 result->set_center(aCenter);
274 auto result = clone();
275 result->set_tile(aTile);
280 auto result = clone();
281 result->set_smoothness(aSmoothness);
285 static scalar normalized_position(scalar aPos, scalar aStart, scalar aEnd)
288 return std::max(0.0, std::min(1.0, (aPos - aStart) / (aEnd - aStart)));
294 inline bool operator==(
const i_gradient& aLhs,
const i_gradient& aRhs)
296 if (aLhs.is_singular() != aRhs.is_singular())
298 else if (aLhs.is_singular())
300 else if (aLhs.id() == aRhs.id())
303 return std::forward_as_tuple(aLhs.color_stops(), aLhs.alpha_stops(), aLhs.direction(), aLhs.orientation(), aLhs.shape(), aLhs.size(), aLhs.exponents(), aLhs.center(), aLhs.tile(), aLhs.smoothness()) ==
304 std::forward_as_tuple(aRhs.color_stops(), aRhs.alpha_stops(), aRhs.direction(), aRhs.orientation(), aRhs.shape(), aRhs.size(), aRhs.exponents(), aRhs.center(), aRhs.tile(), aRhs.smoothness());
307 inline std::partial_ordering
operator<=>(
const i_gradient& aLhs,
const i_gradient& aRhs)
309 if (aLhs.is_singular() || aRhs.is_singular())
311 if (aLhs.is_singular() == aRhs.is_singular())
312 return std::partial_ordering::unordered;
313 if (aLhs.is_singular() < aRhs.is_singular())
314 return std::partial_ordering::less;
316 return std::partial_ordering::greater;
318 else if (aLhs.id() == aRhs.id())
319 return std::partial_ordering::equivalent;
321 return std::forward_as_tuple(aLhs.color_stops(), aLhs.alpha_stops(), aLhs.direction(), aLhs.orientation(), aLhs.shape(), aLhs.size(), aLhs.exponents(), aLhs.center(), aLhs.tile(), aLhs.smoothness()) <=>
322 std::forward_as_tuple(aRhs.color_stops(), aRhs.alpha_stops(), aRhs.direction(), aRhs.orientation(), aRhs.shape(), aRhs.size(), aRhs.exponents(), aRhs.center(), aRhs.tile(), aRhs.smoothness());
#define end_declare_enum(enumName)
#define declare_enum_string(enumName, enumEnumerator)
#define begin_declare_enum(enumName)
optional< rect > optional_rect
optional< point > optional_point
text_direction direction(glyph_char const &g)
neolib::variant< corner, scalar > gradient_orientation
bool operator==(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)
std::partial_ordering operator<=>(const gradient &aLhs, const gradient &aRhs)
basic_size< coordinate > size
optional< vec2 > optional_vec2
auto operator<=>(const gradient_tile &) const =default