Added timeline
This commit is contained in:
35
include/dawn/display/animation/easing.h
Normal file
35
include/dawn/display/animation/easing.h
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Returns the ease time for a given real time duration span.
|
||||
* @param start At what point in time the animation started
|
||||
* @param current The current point in time the animation is at.
|
||||
* @param duration The total duration on the animation.
|
||||
* @returns The easing time (0-1 time) that the animation is at.
|
||||
*/
|
||||
#define easeTimeToEase(start, current, duration) ((current-start)/duration)
|
||||
|
||||
// Easing Functions, most were sourced from https://gist.github.com/gre/1650294
|
||||
#define easeLinear(t) t
|
||||
|
||||
#define easeInQuad(t) (t*t)
|
||||
#define easeOutQuad(t) (t*(2-t))
|
||||
#define easeInOutQuad(t) (t < .5 ? 2*t*t : -1+(4-2*t)*t)
|
||||
|
||||
#define easeInCubic(t) (t*t*t)
|
||||
#define easeOutCubic(t) ((t-1)*(t-1)*(t-1)+1)
|
||||
#define easeInOutCubic(t) (t < .5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1)
|
||||
|
||||
#define easeInQuart(t) (t*t*t*t)
|
||||
#define easeOutQuart(t) (1 - (t-1)*(t-1)*(t-1)*(t-1))
|
||||
#define easeInOutQuart(t) (t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1))
|
||||
|
||||
#define easeInQuint(t) (t*t*t*t*t)
|
||||
#define easeOutQuint(t) (1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1))
|
||||
#define easeInOutQuint(t) (t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1))
|
55
include/dawn/display/animation/timeline.h
Normal file
55
include/dawn/display/animation/timeline.h
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
|
||||
/** Type forwarder for timeline_t */
|
||||
typedef struct _timeline_t timeline_t;
|
||||
|
||||
/** Callback for when a timeline event occurs */
|
||||
typedef void timelinecallback_t(timeline_t*);
|
||||
|
||||
typedef struct test_t {
|
||||
/**
|
||||
* The time that this action should occur within the timeline
|
||||
* set to 0 or less to start immediately.
|
||||
*/
|
||||
float start;
|
||||
|
||||
/**
|
||||
* The duration of the action, this will decide for how long onDuration will
|
||||
* be called for, and when onEnd should be called.
|
||||
* Set to a negative number to have this continue forever.
|
||||
* Set to 0 to only fire the onStart.
|
||||
* onStart can fire with either onDuration and onEnd on the same frame, but
|
||||
* onEnd and onDuration cannot fire the same frame.
|
||||
*/
|
||||
float duration;
|
||||
|
||||
timelinecallback_t *onStart;
|
||||
timelinecallback_t *onDuration;
|
||||
timelinecallback_t *onEnd;
|
||||
} timelineaction_t;
|
||||
|
||||
typedef struct _timeline_t {
|
||||
/** The current time as far as the timeline is concerned */
|
||||
float current;
|
||||
|
||||
/** The time of the last "frame" as far as the timeline is concerned */
|
||||
float previous;
|
||||
|
||||
/** The frame time diff, essentially current = previous + diff */
|
||||
float diff;
|
||||
|
||||
/** User pointer, allows you to point to some other data */
|
||||
void *user;
|
||||
|
||||
/** Actions within the timeline */
|
||||
timelineaction_t actions[128];
|
||||
uint8_t actionCount;
|
||||
} timeline_t;
|
Reference in New Issue
Block a user