Line data Source code
1 : /**
2 : Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org>
3 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
4 :
5 : Permission is hereby granted, free of charge, to any person obtaining a copy
6 : of this software and associated documentation files (the "Software"), to deal
7 : in the Software without restriction, including without limitation the rights
8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : copies of the Software, and to permit persons to whom the Software is
10 : furnished to do so, subject to the following conditions:
11 :
12 : The above copyright notice and this permission notice shall be included in
13 : all copies or substantial portions of the Software.
14 :
15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : THE SOFTWARE.
22 : **/
23 :
24 : #ifndef XENOLITH_SCENE_ACTIONS_XLACTIONEASE_H_
25 : #define XENOLITH_SCENE_ACTIONS_XLACTIONEASE_H_
26 :
27 : #include "XLAction.h"
28 :
29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::interpolation {
30 :
31 : enum Type {
32 : Linear,
33 :
34 : EaseIn,
35 : EaseOut,
36 : EaseInOut,
37 :
38 : Sine_EaseIn,
39 : Sine_EaseOut,
40 : Sine_EaseInOut,
41 :
42 : Quad_EaseIn,
43 : Quad_EaseOut,
44 : Quad_EaseInOut,
45 :
46 : Cubic_EaseIn,
47 : Cubic_EaseOut,
48 : Cubic_EaseInOut,
49 :
50 : Quart_EaseIn,
51 : Quart_EaseOut,
52 : Quart_EaseInOut,
53 :
54 : Quint_EaseIn,
55 : Quint_EaseOut,
56 : Quint_EaseInOut,
57 :
58 : Expo_EaseIn,
59 : Expo_EaseOut,
60 : Expo_EaseInOut,
61 :
62 : Circ_EaseIn,
63 : Circ_EaseOut,
64 : Circ_EaseInOut,
65 :
66 : Elastic_EaseIn,
67 : Elastic_EaseOut,
68 : Elastic_EaseInOut,
69 :
70 : Back_EaseIn,
71 : Back_EaseOut,
72 : Back_EaseInOut,
73 :
74 : Bounce_EaseIn,
75 : Bounce_EaseOut,
76 : Bounce_EaseInOut,
77 :
78 : Custom,
79 :
80 : Max
81 : };
82 :
83 : float interpolateTo(float time, Type type, float *easingParam);
84 :
85 : float linear(float time);
86 :
87 : float easeIn(float time, float rate);
88 : float easeOut(float time, float rate);
89 : float easeInOut(float time, float rate);
90 :
91 : float bezieratFunction(float t, float a, float b, float c, float d);
92 :
93 : float quadraticIn(float time);
94 : float quadraticOut(float time);
95 : float quadraticInOut(float time);
96 :
97 : float sineEaseIn(float time);
98 : float sineEaseOut(float time);
99 : float sineEaseInOut(float time);
100 :
101 : float quadEaseIn(float time);
102 : float quadEaseOut(float time);
103 : float quadEaseInOut(float time);
104 :
105 : float cubicEaseIn(float time);
106 : float cubicEaseOut(float time);
107 : float cubicEaseInOut(float time);
108 :
109 : float quartEaseIn(float time);
110 : float quartEaseOut(float time);
111 : float quartEaseInOut(float time);
112 :
113 : float quintEaseIn(float time);
114 : float quintEaseOut(float time);
115 : float quintEaseInOut(float time);
116 :
117 : float expoEaseIn(float time);
118 : float expoEaseOut(float time);
119 : float expoEaseInOut(float time);
120 :
121 : float circEaseIn(float time);
122 : float circEaseOut(float time);
123 : float circEaseInOut(float time);
124 :
125 : float elasticEaseIn(float time, float period);
126 : float elasticEaseOut(float time, float period);
127 : float elasticEaseInOut(float time, float period);
128 :
129 : float backEaseIn(float time);
130 : float backEaseOut(float time);
131 : float backEaseInOut(float time);
132 :
133 : float bounceEaseIn(float time);
134 : float bounceEaseOut(float time);
135 : float bounceEaseInOut(float time);
136 :
137 : float customEase(float time, float *easingParam);
138 :
139 : }
140 :
141 : namespace STAPPLER_VERSIONIZED stappler::xenolith {
142 :
143 : class ActionEase : public ActionInterval {
144 : public:
145 : virtual ~ActionEase();
146 :
147 : bool init(ActionInterval *action);
148 :
149 : virtual void startWithTarget(Node *target) override;
150 : virtual void stop() override;
151 : virtual void update(float time) override;
152 :
153 : protected:
154 : Rc<ActionInterval> _inner;
155 : };
156 :
157 : class EaseRateAction : public ActionEase {
158 : public:
159 : virtual ~EaseRateAction();
160 :
161 : bool init(ActionInterval *pAction, float fRate);
162 :
163 : inline void setRate(float rate) { _rate = rate; }
164 : inline float getRate() const { return _rate; }
165 :
166 : protected:
167 : float _rate;
168 : };
169 :
170 : /**
171 : @class EaseIn
172 : @brief EaseIn action with a rate.
173 : @details The timeline of inner action will be changed by:
174 : \f${ time }^{ rate }\f$.
175 : @ingroup Actions
176 : */
177 : class EaseIn : public EaseRateAction {
178 : public:
179 : SP_COVERAGE_TRIVIAL
180 : virtual ~EaseIn() { }
181 :
182 : virtual void update(float time) override;
183 : };
184 :
185 : /**
186 : @class EaseOut
187 : @brief EaseOut action with a rate.
188 : @details The timeline of inner action will be changed by:
189 : \f${ time }^ { (1/rate) }\f$.
190 : @ingroup Actions
191 : */
192 : class EaseOut: public EaseRateAction {
193 : public:
194 : SP_COVERAGE_TRIVIAL
195 : virtual ~EaseOut() { }
196 :
197 : virtual void update(float time) override;
198 : };
199 :
200 : /**
201 : @class EaseInOut
202 : @brief EaseInOut action with a rate
203 : @details If time * 2 < 1, the timeline of inner action will be changed by:
204 : \f$0.5*{ time }^{ rate }\f$.
205 : Else, the timeline of inner action will be changed by:
206 : \f$1.0-0.5*{ 2-time }^{ rate }\f$.
207 : @ingroup Actions
208 : */
209 : class EaseInOut: public EaseRateAction {
210 : public:
211 : SP_COVERAGE_TRIVIAL
212 : virtual ~EaseInOut() { }
213 :
214 : virtual void update(float time) override;
215 : };
216 :
217 : /**
218 : @class EaseExponentialIn
219 : @brief Ease Exponential In action.
220 : @details The timeline of inner action will be changed by:
221 : \f${ 2 }^{ 10*(time-1) }-1*0.001\f$.
222 : @ingroup Actions
223 : */
224 : class EaseExponentialIn: public ActionEase {
225 : public:
226 42 : virtual ~EaseExponentialIn() { }
227 :
228 : virtual void update(float time) override;
229 : };
230 :
231 : /**
232 : @class EaseExponentialOut
233 : @brief Ease Exponential Out
234 : @details The timeline of inner action will be changed by:
235 : \f$1-{ 2 }^{ -10*(time-1) }\f$.
236 : @ingroup Actions
237 : */
238 : class EaseExponentialOut : public ActionEase {
239 : public:
240 42 : virtual ~EaseExponentialOut() { }
241 :
242 : virtual void update(float time) override;
243 : };
244 :
245 : /**
246 : @class EaseExponentialInOut
247 : @brief Ease Exponential InOut
248 : @details If time * 2 < 1, the timeline of inner action will be changed by:
249 : \f$0.5*{ 2 }^{ 10*(time-1) }\f$.
250 : else, the timeline of inner action will be changed by:
251 : \f$0.5*(2-{ 2 }^{ -10*(time-1) })\f$.
252 : @ingroup Actions
253 : */
254 : class EaseExponentialInOut : public ActionEase {
255 : public:
256 42 : virtual ~EaseExponentialInOut() { }
257 :
258 : virtual void update(float time) override;
259 : };
260 :
261 : /**
262 : @class EaseSineIn
263 : @brief Ease Sine In
264 : @details The timeline of inner action will be changed by:
265 : \f$1-cos(time*\frac { \pi }{ 2 } )\f$.
266 : @ingroup Actions
267 : */
268 : class EaseSineIn : public ActionEase {
269 : public:
270 42 : virtual ~EaseSineIn() { }
271 :
272 : virtual void update(float time) override;
273 : };
274 :
275 : /**
276 : @class EaseSineOut
277 : @brief Ease Sine Out
278 : @details The timeline of inner action will be changed by:
279 : \f$sin(time*\frac { \pi }{ 2 } )\f$.
280 : @ingroup Actions
281 : */
282 : class EaseSineOut : public ActionEase {
283 : public:
284 42 : virtual ~EaseSineOut() { }
285 :
286 : virtual void update(float time) override;
287 : };
288 :
289 : /**
290 : @class EaseSineInOut
291 : @brief Ease Sine InOut
292 : @details The timeline of inner action will be changed by:
293 : \f$-0.5*(cos(\pi *time)-1)\f$.
294 : @ingroup Actions
295 : */
296 : class EaseSineInOut : public ActionEase {
297 : public:
298 42 : virtual ~EaseSineInOut() { }
299 :
300 : virtual void update(float time) override;
301 : };
302 :
303 : /**
304 : @class EaseElastic
305 : @brief Ease Elastic abstract class
306 : @since v0.8.2
307 : @ingroup Actions
308 : */
309 : class EaseElastic : public ActionEase {
310 : public:
311 : SP_COVERAGE_TRIVIAL
312 : virtual ~EaseElastic() { }
313 :
314 : bool init(ActionInterval *action, float period = 0.3f);
315 :
316 : inline float getPeriod() const { return _period; }
317 : inline void setPeriod(float fPeriod) { _period = fPeriod; }
318 :
319 : protected:
320 : float _period = 0.3f;
321 : };
322 :
323 : /**
324 : @class EaseElasticIn
325 : @brief Ease Elastic In action.
326 : @details If time == 0 or time == 1, the timeline of inner action will not be changed.
327 : Else, the timeline of inner action will be changed by:
328 : \f$-{ 2 }^{ 10*(time-1) }*sin((time-1-\frac { period }{ 4 } )*\pi *2/period)\f$.
329 :
330 : @warning This action doesn't use a bijective function.
331 : Actions like Sequence might have an unexpected result when used with this action.
332 : @since v0.8.2
333 : @ingroup Actions
334 : */
335 : class EaseElasticIn : public EaseElastic {
336 : public:
337 42 : virtual ~EaseElasticIn() { }
338 :
339 : virtual void update(float time) override;
340 : };
341 :
342 : /**
343 : @class EaseElasticOut
344 : @brief Ease Elastic Out action.
345 : @details If time == 0 or time == 1, the timeline of inner action will not be changed.
346 : Else, the timeline of inner action will be changed by:
347 : \f${ 2 }^{ -10*time }*sin((time-\frac { period }{ 4 } )*\pi *2/period)+1\f$.
348 : @warning This action doesn't use a bijective function.
349 : Actions like Sequence might have an unexpected result when used with this action.
350 : @since v0.8.2
351 : @ingroup Actions
352 : */
353 : class EaseElasticOut : public EaseElastic {
354 : public:
355 42 : virtual ~EaseElasticOut() { }
356 :
357 : virtual void update(float time) override;
358 : };
359 :
360 : /**
361 : @class EaseElasticInOut
362 : @brief Ease Elastic InOut action.
363 : @warning This action doesn't use a bijective function.
364 : Actions like Sequence might have an unexpected result when used with this action.
365 : @since v0.8.2
366 : @ingroup Actions
367 : */
368 : class EaseElasticInOut : public EaseElastic {
369 : public:
370 42 : virtual ~EaseElasticInOut() { }
371 :
372 : virtual void update(float time) override;
373 : };
374 :
375 : /**
376 : @class EaseBounceIn
377 : @brief EaseBounceIn action.
378 : @warning This action doesn't use a bijective function.
379 : Actions like Sequence might have an unexpected result when used with this action.
380 : @since v0.8.2
381 : @ingroup Actions
382 : */
383 : class EaseBounceIn : public ActionEase {
384 : public:
385 42 : virtual ~EaseBounceIn() { }
386 :
387 : virtual void update(float time) override;
388 : };
389 :
390 : /**
391 : @class EaseBounceOut
392 : @brief EaseBounceOut action.
393 : @warning This action doesn't use a bijective function.
394 : Actions like Sequence might have an unexpected result when used with this action.
395 : @since v0.8.2
396 : @ingroup Actions
397 : */
398 : class EaseBounceOut : public ActionEase {
399 : public:
400 42 : virtual ~EaseBounceOut() { }
401 :
402 : virtual void update(float time) override;
403 : };
404 :
405 : /**
406 : @class EaseBounceInOut
407 : @brief EaseBounceInOut action.
408 : @warning This action doesn't use a bijective function.
409 : Actions like Sequence might have an unexpected result when used with this action.
410 : @since v0.8.2
411 : @ingroup Actions
412 : */
413 : class EaseBounceInOut : public ActionEase {
414 : public:
415 42 : virtual ~EaseBounceInOut() { }
416 :
417 : virtual void update(float time) override;
418 : };
419 :
420 : /**
421 : @class EaseBackIn
422 : @brief EaseBackIn action.
423 : @warning This action doesn't use a bijective function.
424 : Actions like Sequence might have an unexpected result when used with this action.
425 : @since v0.8.2
426 : @ingroup Actions
427 : */
428 : class EaseBackIn : public ActionEase {
429 : public:
430 42 : virtual ~EaseBackIn() { }
431 :
432 : virtual void update(float time) override;
433 : };
434 :
435 : /**
436 : @class EaseBackOut
437 : @brief EaseBackOut action.
438 : @warning This action doesn't use a bijective function.
439 : Actions like Sequence might have an unexpected result when used with this action.
440 : @since v0.8.2
441 : @ingroup Actions
442 : */
443 : class EaseBackOut : public ActionEase {
444 : public:
445 42 : virtual ~EaseBackOut() { }
446 :
447 : virtual void update(float time) override;
448 : };
449 :
450 : /**
451 : @class EaseBackInOut
452 : @brief EaseBackInOut action.
453 : @warning This action doesn't use a bijective function.
454 : Actions like Sequence might have an unexpected result when used with this action.
455 : @since v0.8.2
456 : @ingroup Actions
457 : */
458 : class EaseBackInOut : public ActionEase {
459 : public:
460 42 : virtual ~EaseBackInOut() { }
461 :
462 : virtual void update(float time) override;
463 : };
464 :
465 : /**
466 : @class EaseBezierAction
467 : @brief Ease Bezier
468 : @ingroup Actions
469 : */
470 : class EaseBezierAction : public ActionEase {
471 : public:
472 1652 : virtual ~EaseBezierAction() { }
473 :
474 : bool init(ActionInterval *, float p0, float p1, float p2, float p3);
475 :
476 : virtual void update(float time) override;
477 :
478 : protected:
479 : float _p0;
480 : float _p1;
481 : float _p2;
482 : float _p3;
483 : };
484 :
485 : /**
486 : @class EaseQuadraticActionIn
487 : @brief Ease Quadratic In
488 : @ingroup Actions
489 : */
490 : class EaseQuadraticActionIn : public ActionEase {
491 : public:
492 42 : virtual ~EaseQuadraticActionIn() { }
493 :
494 : virtual void update(float time) override;
495 : };
496 :
497 : /**
498 : @class EaseQuadraticActionOut
499 : @brief Ease Quadratic Out
500 : @ingroup Actions
501 : */
502 : class EaseQuadraticActionOut : public ActionEase {
503 : public:
504 42 : virtual ~EaseQuadraticActionOut() { }
505 :
506 : virtual void update(float time) override;
507 : };
508 :
509 : /**
510 : @class EaseQuadraticActionInOut
511 : @brief Ease Quadratic InOut
512 : @ingroup Actions
513 : */
514 : class EaseQuadraticActionInOut : public ActionEase {
515 : public:
516 42 : virtual ~EaseQuadraticActionInOut() { }
517 :
518 : virtual void update(float time) override;
519 : };
520 :
521 : /**
522 : @class EaseQuarticActionIn
523 : @brief Ease Quartic In
524 : @ingroup Actions
525 : */
526 : class EaseQuarticActionIn : public ActionEase {
527 : public:
528 42 : virtual ~EaseQuarticActionIn() { }
529 :
530 : virtual void update(float time) override;
531 : };
532 :
533 : /**
534 : @class EaseQuarticActionOut
535 : @brief Ease Quartic Out
536 : @ingroup Actions
537 : */
538 : class EaseQuarticActionOut : public ActionEase {
539 : public:
540 58 : virtual ~EaseQuarticActionOut() { }
541 :
542 : virtual void update(float time) override;
543 : };
544 :
545 : /**
546 : @class EaseQuarticActionInOut
547 : @brief Ease Quartic InOut
548 : @ingroup Actions
549 : */
550 : class EaseQuarticActionInOut : public ActionEase {
551 : public:
552 42 : virtual ~EaseQuarticActionInOut() { }
553 :
554 : virtual void update(float time) override;
555 : };
556 :
557 : /**
558 : @class EaseQuinticActionIn
559 : @brief Ease Quintic In
560 : @ingroup Actions
561 : */
562 : class EaseQuinticActionIn : public ActionEase {
563 : public:
564 42 : virtual ~EaseQuinticActionIn() { }
565 :
566 : virtual void update(float time) override;
567 : };
568 :
569 : /**
570 : @class EaseQuinticActionOut
571 : @brief Ease Quintic Out
572 : @ingroup Actions
573 : */
574 : class EaseQuinticActionOut : public ActionEase {
575 : public:
576 42 : virtual ~EaseQuinticActionOut() { }
577 :
578 : virtual void update(float time) override;
579 : };
580 :
581 : /**
582 : @class EaseQuinticActionInOut
583 : @brief Ease Quintic InOut
584 : @ingroup Actions
585 : */
586 : class EaseQuinticActionInOut : public ActionEase {
587 : public:
588 42 : virtual ~EaseQuinticActionInOut() { }
589 :
590 : virtual void update(float time) override;
591 : };
592 :
593 : /**
594 : @class EaseCircleActionIn
595 : @brief Ease Circle In
596 : @ingroup Actions
597 : */
598 : class EaseCircleActionIn : public ActionEase {
599 : public:
600 42 : virtual ~EaseCircleActionIn() { }
601 :
602 : virtual void update(float time) override;
603 : };
604 :
605 : /**
606 : @class EaseCircleActionOut
607 : @brief Ease Circle Out
608 : @ingroup Actions
609 : */
610 : class EaseCircleActionOut : public ActionEase {
611 : public:
612 42 : virtual ~EaseCircleActionOut() { }
613 :
614 : virtual void update(float time) override;
615 : };
616 :
617 : /**
618 : @class EaseCircleActionInOut
619 : @brief Ease Circle InOut
620 : @ingroup Actions
621 : */
622 : class EaseCircleActionInOut : public ActionEase {
623 : public:
624 42 : virtual ~EaseCircleActionInOut() {}
625 :
626 : virtual void update(float time) override;
627 : };
628 :
629 : /**
630 : @class EaseCubicActionIn
631 : @brief Ease Cubic In
632 : @ingroup Actions
633 : */
634 : class EaseCubicActionIn : public ActionEase {
635 : public:
636 42 : virtual ~EaseCubicActionIn() { }
637 :
638 : virtual void update(float time) override;
639 : };
640 :
641 : /**
642 : @class EaseCubicActionOut
643 : @brief Ease Cubic Out
644 : @ingroup Actions
645 : */
646 : class EaseCubicActionOut : public ActionEase {
647 : public:
648 42 : virtual ~EaseCubicActionOut() { }
649 :
650 : virtual void update(float time) override;
651 : };
652 :
653 : /**
654 : @class EaseCubicActionInOut
655 : @brief Ease Cubic InOut
656 : @ingroup Actions
657 : */
658 : class EaseCubicActionInOut : public ActionEase {
659 : public:
660 42 : virtual ~EaseCubicActionInOut() { }
661 :
662 : virtual void update(float time) override;
663 : };
664 :
665 : }
666 :
667 : #endif /* XENOLITH_SCENE_ACTIONS_XLACTIONEASE_H_ */
|