* amplitude * ^ * 255 ────────────────────────────────────── * / * / * / * / * 0 ────────────┴ --> time (ms) * t0 t1 * * * */
| 113 | * |
| 114 | */ |
| 115 | class TimeClampedTransition : public TimeAlpha { |
| 116 | public: |
| 117 | TimeClampedTransition(u32 duration) FL_NOEXCEPT : mDuration(duration) {} |
| 118 | |
| 119 | void trigger(u32 now) FL_NOEXCEPT override { |
| 120 | mStart = now; |
| 121 | mEnd = now + mDuration; |
| 122 | } |
| 123 | |
| 124 | bool isActive(u32 now) const FL_NOEXCEPT override { |
| 125 | bool not_started = (mEnd == 0) && (mStart == 0); |
| 126 | if (not_started) { |
| 127 | // if we have not started, we are not active |
| 128 | return false; |
| 129 | } |
| 130 | if (now < mStart) { |
| 131 | // if the time is before the start, we are not active |
| 132 | return false; |
| 133 | } |
| 134 | if (now > mEnd) { |
| 135 | // if the time is after the finished rising, we are not active |
| 136 | return false; |
| 137 | } |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | u8 update8(u32 now) FL_NOEXCEPT override { |
| 142 | bool not_started = (mEnd == 0) && (mStart == 0); |
| 143 | if (not_started) { |
| 144 | // if we have not started, we are not active |
| 145 | return 0; |
| 146 | } |
| 147 | u8 out = time_alpha8(now, mStart, mEnd); |
| 148 | return out; |
| 149 | } |
| 150 | |
| 151 | float updatef(u32 now) FL_NOEXCEPT override { |
| 152 | bool not_started = (mEnd == 0) && (mStart == 0); |
| 153 | if (not_started) { |
| 154 | return 0; |
| 155 | } |
| 156 | float out = time_alphaf(now, mStart, mEnd); |
| 157 | if (mMaxClamp > 0.f) { |
| 158 | out = fl::min(out, mMaxClamp); |
| 159 | } |
| 160 | return out; |
| 161 | } |
| 162 | |
| 163 | void set_max_clamp(float max) FL_NOEXCEPT { mMaxClamp = max; } |
| 164 | |
| 165 | private: |
| 166 | u32 mStart = 0; |
| 167 | u32 mDuration = 0; |
| 168 | u32 mEnd = 0; |
| 169 | float mMaxClamp = -1.f; // default disabled. |
| 170 | }; |
| 171 | |
| 172 | } // namespace fl |
nothing calls this directly
no test coverage detected