Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Easing.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
12namespace PhosphorAnimation {
13
17class PHOSPHORANIMATION_EXPORT Easing final : public Curve
18{
19public:
20 enum class Type {
21 CubicBezier,
22 ElasticIn,
23 ElasticOut,
24 ElasticInOut,
25 BounceIn,
26 BounceOut,
27 BounceInOut,
28 };
29
30 Easing() = default;
31
32 Easing(const Easing&) = default;
33 Easing& operator=(const Easing&) = default;
34 Easing(Easing&&) = default;
35 Easing& operator=(Easing&&) = default;
36
37 QString typeId() const override;
38 qreal evaluate(qreal x) const override;
39 QString toString() const override;
40 std::unique_ptr<Curve> clone() const override;
41 bool overshoots() const override;
42 bool equals(const Curve& other) const override;
43
45 static Easing fromString(const QString& str);
46
47 Type type = Type::CubicBezier;
48
50 qreal x1 = 0.33;
51 qreal y1 = 1.0;
52 qreal x2 = 0.68;
53 qreal y2 = 1.0;
54
56 qreal amplitude = 1.0;
58 qreal period = 0.3;
60 int bounces = 3;
61
62 bool operator==(const Easing& other) const;
63 bool operator!=(const Easing& other) const
64 {
65 return !(*this == other);
66 }
67
68private:
69 static qreal evaluateElasticOut(qreal t, qreal amp, qreal per);
70 static qreal evaluateBounceOut(qreal t, qreal amp, int n);
71};
72
73} // namespace PhosphorAnimation
Polymorphic base for all animation curves.
Definition Curve.h:44
Parametric easing curve: cubic bezier, elastic, or bounce.
Definition Easing.h:18
Easing(Easing &&)=default
bool equals(const Curve &other) const override
Same typeId + same parameters.
static Easing fromString(const QString &str)
Parse from config string. Returns default OutCubic on failure.
qreal evaluate(qreal x) const override
Evaluate at normalized time t in [0,1]. May overshoot by design.
bool overshoots() const override
True if this curve may evaluate outside [0,1] during progression.
std::unique_ptr< Curve > clone() const override
Deep copy with identical parameters.
QString toString() const override
Serialize to "typeId:params" or bare "x1,y1,x2,y2" for cubic-bezier.
QString typeId() const override
Stable identifier for this curve subclass (e.g. "bezier", "spring").
bool operator==(const Easing &other) const
Type
Definition Easing.h:20
bool operator!=(const Easing &other) const
Definition Easing.h:63
Easing & operator=(Easing &&)=default
Easing & operator=(const Easing &)=default
Easing(const Easing &)=default
Definition AnimatedValue.h:31