Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Curve.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorAnimation/phosphoranimation_export.h>
8
9#include <QString>
10#include <QtGlobal>
11
12#include <memory>
13
14namespace PhosphorAnimation {
15
19struct PHOSPHORANIMATION_EXPORT CurveState
20{
21 qreal value = 0.0;
22 qreal velocity = 0.0;
23 qreal time = 0.0;
27 qreal startValue = 0.0;
29 qreal duration = 1.0;
30};
31
44class PHOSPHORANIMATION_EXPORT Curve
45{
46public:
47 virtual ~Curve() = default;
48
50 virtual QString typeId() const = 0;
51
53 virtual qreal evaluate(qreal t) const = 0;
54
59 virtual void step(qreal dt, CurveState& state, qreal target) const;
60
62 virtual bool isStateful() const
63 {
64 return false;
65 }
66
68 virtual bool overshoots() const
69 {
70 return false;
71 }
72
85 virtual qreal settleTime() const
86 {
87 return 1.0;
88 }
89
92 virtual QString toString() const = 0;
93
95 virtual std::unique_ptr<Curve> clone() const = 0;
96
99 virtual bool equals(const Curve& other) const;
100
101protected:
102 // Protected copy/move prevents slicing outside the hierarchy while
103 // allowing subclasses to default their own copy/move for value semantics.
104 Curve() = default;
105 Curve(const Curve&) = default;
106 Curve& operator=(const Curve&) = default;
107 Curve(Curve&&) = default;
108 Curve& operator=(Curve&&) = default;
109};
110
118inline qreal boundCurveProgress(qreal progress)
119{
120 return qBound(qreal(Limits::MinCurveProgress), progress, qreal(Limits::MaxCurveProgress));
121}
122
123} // namespace PhosphorAnimation
Animation-wide UI bounds (duration, stagger interval).
Polymorphic base for all animation curves.
Definition Curve.h:45
virtual void step(qreal dt, CurveState &state, qreal target) const
Advance state by dt real seconds toward target.
virtual QString toString() const =0
Serialize to "typeId:params" or bare "x1,y1,x2,y2" for cubic-bezier.
virtual qreal settleTime() const
Approximate settle time in seconds.
Definition Curve.h:85
Curve(Curve &&)=default
Curve(const Curve &)=default
virtual std::unique_ptr< Curve > clone() const =0
Deep copy with identical parameters.
Curve & operator=(Curve &&)=default
virtual ~Curve()=default
virtual bool overshoots() const
True if this curve may evaluate outside [0,1] during progression.
Definition Curve.h:68
Curve & operator=(const Curve &)=default
virtual QString typeId() const =0
Stable identifier for this curve subclass (e.g. "bezier", "spring").
virtual qreal evaluate(qreal t) const =0
Evaluate at normalized time t in [0,1]. May overshoot by design.
virtual bool equals(const Curve &other) const
Same typeId + same parameters.
virtual bool isStateful() const
True if this curve requires persistent CurveState across frames.
Definition Curve.h:62
constexpr double MaxCurveProgress
Definition AnimationLimits.h:198
constexpr double MinCurveProgress
Overshoot envelope for a curve's OUTPUT.
Definition AnimationLimits.h:197
Definition AnimatedValue.h:32
qreal boundCurveProgress(qreal progress)
Bound a curve's output to the overshoot envelope [Limits::MinCurveProgress, Limits::MaxCurveProgress]...
Definition Curve.h:118
Mutable state for stateful curve progression (springs carry position+velocity across frames; stateles...
Definition Curve.h:20