TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::GradientF Struct Reference

A gradient of float colors, for data such as a material editor's gradient map: up to kMaxStops stops, each with its own interpolation to the next, blended in colorSpace. More...

#include <gui_core/style/gui_style_gradient.h>

Public Member Functions

bool AddStop (const color4f &color, float offset, StopInterpolation interpolation=StopInterpolation::Linear)
 Adds a stop at offset (clamped to 0..1); false when kMaxStops are in use.
int StopCount () const
 The stops in use: at most kMaxStops.
color4f Sample (float t) const
 The color at t (0..1, clamped), unclamped: HDR stays.
void WriteTo (std::span< color4f > out) const
 Samples the gradient evenly across out, unclamped.
void WriteTo (std::span< color4b > out) const
 As above, clamped to 0..1 and stored as 8 bits, for display.
void Assign (const Gradient &gradient)
 As From, into this one's storage.
Gradient ToGradient () const
 The first Gradient::kMaxStops stops as a linear Gradient: colors clamped to 0..1 and stored as 8 bits; the interpolation of each stop is dropped.
bool operator== (const GradientF &) const =default

Static Public Member Functions

static GradientF From (const Gradient &gradient)
 The same stops as gradient, blending linearly in its color space.

Public Attributes

std::vector< GradientStop > stops
 in any order
ColorSpace colorSpace = ColorSpace::sRGB
 space the stops are blended in

Static Public Attributes

static constexpr int kMaxStops = 64
 stops past this are left out

Detailed Description

A gradient of float colors, for data such as a material editor's gradient map: up to kMaxStops stops, each with its own interpolation to the next, blended in colorSpace.

Gradient (8 stops, 8 bits a channel) is what styles and CSS use; GradientField edits either.

GradientF heat;
heat.AddStop(color4f{ 0.0f, 0.0f, 0.0f, 1.0f }, 0.0f);
heat.AddStop(color4f{ 4.0f, 1.5f, 0.2f, 1.0f }, 1.0f, StopInterpolation::Smooth);   // HDR
const color4f mid = heat.Sample(0.5f); 

Member Function Documentation

◆ AddStop()

bool tachyon::GradientF::AddStop ( const color4f & color,
float offset,
StopInterpolation interpolation = StopInterpolation::Linear )

Adds a stop at offset (clamped to 0..1); false when kMaxStops are in use.

◆ StopCount()

int tachyon::GradientF::StopCount ( ) const
inline

The stops in use: at most kMaxStops.

◆ Sample()

color4f tachyon::GradientF::Sample ( float t) const

The color at t (0..1, clamped), unclamped: HDR stays.

Transparent black without stops; before the first stop its color, after the last that one's.

◆ WriteTo() [1/2]

void tachyon::GradientF::WriteTo ( std::span< color4f > out) const

Samples the gradient evenly across out, unclamped.

◆ WriteTo() [2/2]

void tachyon::GradientF::WriteTo ( std::span< color4b > out) const

As above, clamped to 0..1 and stored as 8 bits, for display.

◆ From()

GradientF tachyon::GradientF::From ( const Gradient & gradient)
static

The same stops as gradient, blending linearly in its color space.

◆ Assign()

void tachyon::GradientF::Assign ( const Gradient & gradient)

As From, into this one's storage.

◆ ToGradient()

Gradient tachyon::GradientF::ToGradient ( ) const

The first Gradient::kMaxStops stops as a linear Gradient: colors clamped to 0..1 and stored as 8 bits; the interpolation of each stop is dropped.

◆ operator==()

bool tachyon::GradientF::operator== ( const GradientF & ) const
default

Member Data Documentation

◆ kMaxStops

int tachyon::GradientF::kMaxStops = 64
staticconstexpr

stops past this are left out

◆ stops

std::vector<GradientStop> tachyon::GradientF::stops

in any order

◆ colorSpace

ColorSpace tachyon::GradientF::colorSpace = ColorSpace::sRGB

space the stops are blended in


The documentation for this struct was generated from the following file: