diff options
Diffstat (limited to 'src/ui/util.c')
-rw-r--r-- | src/ui/util.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index a6329180..5d283742 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -127,6 +127,39 @@ iRangei union_Rangei(iRangei a, iRangei b) { | |||
127 | return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) }; | 127 | return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) }; |
128 | } | 128 | } |
129 | 129 | ||
130 | /*----------------------------------------------------------------------------------------------*/ | ||
131 | |||
132 | iBool isFinished_Anim(const iAnim *d) { | ||
133 | return frameTime_Window(get_Window()) >= d->due; | ||
134 | } | ||
135 | |||
136 | void init_Anim(iAnim *d, float value) { | ||
137 | d->due = d->when = frameTime_Window(get_Window()); | ||
138 | d->from = d->to = value; | ||
139 | } | ||
140 | |||
141 | void setValue_Anim(iAnim *d, float to, uint32_t span) { | ||
142 | if (fabsf(to - d->to) > 0.00001f) { | ||
143 | const uint32_t now = frameTime_Window(get_Window()); | ||
144 | d->from = value_Anim(d); | ||
145 | d->to = to; | ||
146 | d->when = now; | ||
147 | d->due = now + span; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | float value_Anim(const iAnim *d) { | ||
152 | const uint32_t now = frameTime_Window(get_Window()); | ||
153 | if (now >= d->due) { | ||
154 | return d->to; | ||
155 | } | ||
156 | if (now <= d->when) { | ||
157 | return d->from; | ||
158 | } | ||
159 | const float pos = (float) (now - d->when) / (float) (d->due - d->when); | ||
160 | return d->from * (1.0f - pos) + d->to * pos; | ||
161 | } | ||
162 | |||
130 | /*-----------------------------------------------------------------------------------------------*/ | 163 | /*-----------------------------------------------------------------------------------------------*/ |
131 | 164 | ||
132 | void init_Click(iClick *d, iAnyObject *widget, int button) { | 165 | void init_Click(iClick *d, iAnyObject *widget, int button) { |