1#ifndef NEFORCE_TUI_DOM_LINEAR_GRADIENT_HPP__
2#define NEFORCE_TUI_DOM_LINEAR_GRADIENT_HPP__
14NEFORCE_BEGIN_NAMESPACE__
44 position(
move(pos)) {}
56 stops_.push_back(color_stop(_NEFORCE
color::black(), 1.0F));
65 stops_.push_back(color_stop(
begin, 0.0F));
66 stops_.push_back(color_stop(
end, 1.0F));
86 stops_.push_back(color_stop(c, pos));
97 return _NEFORCE
color{};
99 if (stops_.size() == 1) {
100 return stops_[0].color;
104 for (
size_t i = 0; i < stops_.size() - 1; ++i) {
105 const float p1 = stops_[i].position.value_or(0.0F);
106 const float p2 = stops_[i + 1].position.value_or(1.0F);
107 if (t >= p1 && t <= p2) {
113 const color_stop& s1 = stops_[idx];
114 const color_stop& s2 = stops_[idx + 1];
115 const float p1 = s1.position.
value_or(0.0F);
116 const float p2 = s2.position.
value_or(1.0F);
117 const float range = p2 - p1;
118 const float factor = (range > 0.0F) ? (t - p1) / range : 0.0F;
127NEFORCE_END_NAMESPACE__
static constexpr color lerp(const color &from, const color &to, double t) noexcept
线性插值两个颜色
static constexpr color black() noexcept
黑色
static constexpr color transparent() noexcept
完全透明
constexpr value_type value_or(value_type value) const &noexcept(is_nothrow_copy_constructible_v< value_type >)
取出存储的值的拷贝值
constexpr none_t none
默认空表示
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
decorator color(color c)
前景色装饰器
constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
constexpr decltype(auto) begin(Container &cont) noexcept(noexcept(cont.begin()))
获取容器的起始迭代器
linear_gradient & add_stop(const struct color &c, optional< float > pos=none)
添加色标
linear_gradient(_NEFORCE color begin, struct color end)
从起止颜色构造
linear_gradient & angle(const float a)
设置渐变角度
_NEFORCE color sample(float t) const
在指定位置采样颜色