79 std::vector<sk_sp<RangeSelector>> selectors;
84 selectors.reserve(jselectors->size());
87 selectors.push_back(std::move(sel));
93 selectors.push_back(std::move(sel));
98 new TextAnimator(std::move(selectors), *jprops, abuilder, acontainer));
103 const auto initial_coverage = fSelectors.empty() ? 1.f : 0.f;
106 for (
auto& mod : buf) {
107 mod.coverage = initial_coverage;
111 for (
const auto& selector : fSelectors) {
112 selector->modulateCoverage(maps, buf);
116 for (
auto& mod : buf) {
122 float amount)
const {
123 auto modulated_props = props;
126 modulated_props.position +=
static_cast<SkV3>(fTextProps.
position) * amount;
127 modulated_props.rotation += fTextProps.
rotation * amount;
128 modulated_props.tracking += fTextProps.
tracking * amount;
129 modulated_props.scale *=
SkV3{1,1,1} +
130 (
static_cast<SkV3>(fTextProps.
scale) * 0.01f -
SkV3{1,1,1}) * amount;
133 modulated_props.blur += fTextProps.
blur * amount;
134 modulated_props.line_spacing += fTextProps.
line_spacing * amount;
135 modulated_props.stroke_width += fTextProps.
stroke_width * amount;
137 const auto lerp = [](
float v0,
float v1,
float t) {
138 return v0 + (v1 - v0)*t;
143 c_4f = c0_4f + (c1_4f - c0_4f) * t;
149 const auto clamped_amount =
std::max(amount, 0.0f);
151 modulated_props.fill_color = lerp_color(props.fill_color,
155 if (fHasStrokeColor) {
156 modulated_props.stroke_color = lerp_color(props.stroke_color,
160 if (fHasFillOpacity) {
165 modulated_props.fill_color =
SkColorSetA(modulated_props.fill_color,
168 if (fHasStrokeOpacity) {
173 modulated_props.stroke_color =
SkColorSetA(modulated_props.stroke_color,
177 modulated_props.opacity =
lerp(props.opacity, fTextProps.
opacity*0.01f, clamped_amount);
180 return modulated_props;
185 const AnimationBuilder* abuilder,
186 AnimatablePropertyContainer* acontainer)
187 : fSelectors(
std::move(selectors))
188 , fRequiresAnchorPoint(
false)
189 , fRequiresLineAdjustments(
false) {
191 acontainer->bind(*abuilder, jprops[
"p" ], fTextProps.
position);
194 fRequiresLineAdjustments |= acontainer->bind(*abuilder, jprops[
"t" ], fTextProps.
tracking);
195 fRequiresLineAdjustments |= acontainer->bind(*abuilder, jprops[
"ls"], fTextProps.
line_spacing);
198 fRequiresAnchorPoint |= acontainer->bind(*abuilder, jprops[
"s"], fTextProps.
scale);
202 fRequiresAnchorPoint |= acontainer->bind(*abuilder, jprops[
"rx"], fTextProps.
rotation.
x);
203 fRequiresAnchorPoint |= acontainer->bind(*abuilder, jprops[
"ry"], fTextProps.
rotation.
y);
204 fRequiresAnchorPoint |= acontainer->bind(*abuilder, jprops[
"r" ], fTextProps.
rotation.
z);
206 fHasFillColor = acontainer->bind(*abuilder, jprops[
"fc"], fTextProps.
fill_color );
207 fHasStrokeColor = acontainer->bind(*abuilder, jprops[
"sc"], fTextProps.
stroke_color );
208 fHasFillOpacity = acontainer->bind(*abuilder, jprops[
"fo"], fTextProps.
fill_opacity );
209 fHasStrokeOpacity = acontainer->bind(*abuilder, jprops[
"so"], fTextProps.
stroke_opacity);
210 fHasOpacity = acontainer->bind(*abuilder, jprops[
"o" ], fTextProps.
opacity );
211 fHasBlur = acontainer->bind(*abuilder, jprops[
"bl"], fTextProps.
blur );
213 acontainer->bind(*abuilder, jprops[
"sw"], fTextProps.
stroke_width);
SkPoint lerp(const SkPoint &a, const SkPoint &b, float t)
static void round(SkPoint *p)
static constexpr SkColor SkColorSetA(SkColor c, U8CPU a)
#define SkColorGetA(color)
static skvx::float4 Sk4f_fromL32(uint32_t px)
static uint32_t Sk4f_toL32(const skvx::float4 &px)
static sk_sp< RangeSelector > Make(const skjson::ObjectValue *, const AnimationBuilder *, AnimatablePropertyContainer *)
void modulateProps(const DomainMaps &, ModulatorBuffer &) const
std::vector< AnimatedPropsModulator > ModulatorBuffer
static sk_sp< TextAnimator > Make(const skjson::ObjectValue *, const AnimationBuilder *, AnimatablePropertyContainer *acontainer)
static float max(float r, float g, float b)
ScalarValue stroke_opacity