qxLib
easing_element.h
Go to the documentation of this file.
1 /**
2 
3  @file easing_element.h
4  @author Khrapov
5  @date 4.05.2021
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
13 
14 namespace qx
15 {
16 
17 /**
18 
19  @class base_easing_element
20  @brief An updatable element representing the value of the easing function
21  at a given time
22  @tparam T - floating point ish value
23  @author Khrapov
24  @date 04.05.2021
25 
26 **/
27 template<class T>
29 {
30 public:
31  enum class status
32  {
33  not_started,
34  started,
35  paused,
36  finished
37  };
38 
39  using type = T;
40 
41 public:
42  QX_COPYMOVABLE(base_easing_element);
43 
44  /**
45  @brief base_easing_element object constructor
46  @param func - easing function
47  @param fStart - start value
48  @param fEnd - end value
49  @param fSpeed - speed of updating
50  **/
51  base_easing_element(const easing::func<T>& func, T fStart = T(0.f), T fEnd = T(1.f), T fSpeed = T(1.f)) noexcept;
52 
53  /**
54  @brief Mark element as active and let it update
55  **/
56  void start() noexcept;
57 
58  /**
59  @brief Pause element if started
60  **/
61  void pause() noexcept;
62 
63  /**
64  @brief Resume updating if paused
65  **/
66  void resume() noexcept;
67 
68  /**
69  @brief Mark element as finished
70  **/
71  void finish() noexcept;
72 
73  /**
74  @brief Mark element as inactive
75  **/
76  void reset() noexcept;
77 
78  /**
79  @brief Update element corresponding to easing function
80  @param fDeltaTime - delta time
81  @retval - the portion of time that was not used
82  **/
83  [[nodiscard]] T update(T fDeltaTime) noexcept;
84 
85  /**
86  @brief Set speed value
87  @param fSpeed - new speed value
88  **/
89  void set_speed(T fSpeed) noexcept;
90 
91  /**
92  @brief Get current value of element
93  @retval - current value of element
94  **/
95  [[nodiscard]] T get() const noexcept;
96 
97  /**
98  @brief Get a fraction indicating how much of the element has played
99  @retval - fraction [0.0, 1.0]
100  **/
101  [[nodiscard]] T get_fraction() const noexcept;
102 
103  /**
104  @brief Get speed value
105  @retval - speed value
106  **/
107  [[nodiscard]] T get_speed() const noexcept;
108 
109  /**
110  @brief Get element status
111  @retval - element status
112  **/
113  [[nodiscard]] status get_status() const noexcept;
114 
115  /**
116  @brief Check if element is not started
117  @retval - true if element is not started
118  **/
119  [[nodiscard]] bool is_not_started() const noexcept;
120 
121  /**
122  @brief Check if element is started
123  @retval - true if element is started
124  **/
125  [[nodiscard]] bool is_started() const noexcept;
126 
127  /**
128  @brief Check if element is paused
129  @retval - true if element is paused
130  **/
131  [[nodiscard]] bool is_paused() const noexcept;
132 
133  /**
134  @brief Check if element is finished
135  @retval - true if element is finished
136  **/
137  [[nodiscard]] bool is_finished() const noexcept;
138 
139 private:
140  easing::func<T> m_EasingFunc;
141  status m_eStatus = status::not_started;
142  T m_fSpeed = T(1.f);
143  T m_fCurrentX = T(0.f);
144  T m_fCurrentY = T(0.f);
145  T m_fStartY = T(0.f);
146  T m_fEndY = T(1.f);
147 };
148 
150 
151 } // namespace qx
152 
An updatable element representing the value of the easing function at a given time.
T get() const noexcept
Get current value of element.
void set_speed(T fSpeed) noexcept
Set speed value.
bool is_not_started() const noexcept
Check if element is not started.
T update(T fDeltaTime) noexcept
Update element corresponding to easing function.
status get_status() const noexcept
Get element status.
void finish() noexcept
Mark element as finished.
void reset() noexcept
Mark element as inactive.
void pause() noexcept
Pause element if started.
bool is_paused() const noexcept
Check if element is paused.
T get_fraction() const noexcept
Get a fraction indicating how much of the element has played.
void resume() noexcept
Resume updating if paused.
bool is_started() const noexcept
Check if element is started.
T get_speed() const noexcept
Get speed value.
base_easing_element(const easing::func< T > &func, T fStart=T(0.f), T fEnd=T(1.f), T fSpeed=T(1.f)) noexcept
base_easing_element object constructor
bool is_finished() const noexcept
Check if element is finished.
void start() noexcept
Mark element as active and let it update.
File contains easing functions.