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