SANDAL2
A SDL2 Wrapper in C
Action.h
Go to the documentation of this file.
1 #ifndef ACTIONSDL2_SANDAL2_KLEVH
2 #define ACTIONSDL2_SANDAL2_KLEVH
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 // macro to prevent auto tabulation
9 #if 1 < 0
10 }
11 #endif
12 
19 struct Element;
20 typedef struct Action{
21  double timing;
23  double timeSpent;
25  void (*action)(struct Element *, void *, double);
27  void * data;
31 } Action;
32 
33 
34 
35 struct ActionNode;
36 typedef struct ListAction{
37  struct ActionNode * first;
41  int isForever;
43 } ListAction;
44 
45 
46 
47 typedef struct ActionNode {
48  union{
49  Action action;
50  ListAction list;
51  } action;
53  int isList;
57  struct ActionNode * next;
59 } ActionNode;
60 
61 
62 
63 
64 /* -------------------------------------------------------
65  * Action functions
66  */
73 ListAction * initAction(void (*action)(struct Element *, void *, double), double timing);
82 /* ------------------------------------------------------- */
83 
84 
85 
86 
87 
88 /* -------------------------------------------------------
89  * ListAction functions
90  */
103 int executeListAction(ListAction * action, struct Element * e, double time);
122 ListAction * setForeverAction(ListAction * action, int isForever);
129 long long addActionAtEndAction(ListAction * action, ListAction * toAdd);
136 int delActionToAction(ListAction * action, long long index);
137 /* ------------------------------------------------------- */
138 
139 
140 
141 
142 
143 /* -------------------------------------------------------
144  * Action pre made action functions
145  */
155 void moveByActionFunction(struct Element * e, void * data, double spentTime);
165 void moveToActionFunction(struct Element * e, void * data, double spentTime);
175 void scaleByActionFunction(struct Element * e, void * data, double spentTime);
185 void scaleToActionFunction(struct Element * e, void * data, double spentTime);
195 void rotateByActionFunction(struct Element * e, void * data, double spentTime);
205 void rotateToActionFunction(struct Element * e, void * data, double spentTime);
215 void fadeInActionFunction(struct Element * e, void * data, double spentTime);
225 void fadeOutActionFunction(struct Element * e, void * data, double spentTime);
226 /* ------------------------------------------------------- */
227 
228 
229 
230 
231 
232 /* -------------------------------------------------------
233  * Action pre made actions
234  */
242 ListAction * moveByAction(double x, double y, double time);
250 ListAction * moveToAction(double x, double y, double time);
258 ListAction * scaleByAction(double x, double y, double time);
266 ListAction * scaleToAction(double w, double h, double time);
273 ListAction * rotateByAction(double angle, double time);
280 ListAction * rotateToAction(double angle, double time);
287 ListAction * fadeInAction(int alpha, double time);
294 ListAction * fadeOutAction(int alpha, double time);
295 /* ------------------------------------------------------- */
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif
struct ActionNode * first
Definition: Action.h:37
ListAction * setDataAction(ListAction *action, void *data, int shouldBeFreed)
Set the data bound to an action, if the action list contains more than one action, this call will fail.
Definition: Action.c:71
void fadeInActionFunction(struct Element *e, void *data, double spentTime)
function used by fadeInAction() and left public to be used in self made action functions ...
Definition: Action.c:533
ListAction * moveToAction(double x, double y, double time)
Generate a ListAction doing a translation during a given time.
Definition: Action.c:601
ListAction * scaleToAction(double w, double h, double time)
Generate a ListAction doing a scale XY (only X if y == 0, only Y if x == 0) during a given time...
Definition: Action.c:641
long long addActionAtEndAction(ListAction *action, ListAction *toAdd)
add an action at the end of another one
Definition: Action.c:302
void freeListAction(ListAction *action)
Free the memory of a list action.
Definition: Action.c:88
void * data
Definition: Action.h:27
ListAction * rotateToAction(double angle, double time)
Generate a ListAction doing a rotation during a given time.
Definition: Action.c:681
ListAction * generateChainedAction(ListAction *action,...)
Generate a list of chained action (the nth action execute after the (n - 1)th ended) ...
Definition: Action.c:272
ListAction * fadeOutAction(int alpha, double time)
Generate a ListAction doing a fade out during a given time.
Definition: Action.c:717
int isParallel
Definition: Action.h:39
Definition: Action.h:47
ListAction * generateParallelAction(ListAction *action,...)
Generate a list of parallel action.
Definition: Action.c:283
int executeListAction(ListAction *action, struct Element *e, double time)
Execute a list action.
Definition: Action.c:135
void fadeOutActionFunction(struct Element *e, void *data, double spentTime)
function used by fadeOutAction() and left public to be used in self made action functions ...
Definition: Action.c:551
int isFinished
Definition: Action.h:55
All the informations of an element.
Definition: Element.h:108
ListAction * scaleByAction(double x, double y, double time)
Generate a ListAction doing a scale XY (only X if y == 0, only Y if x == 0) during a given time...
Definition: Action.c:621
double timing
Definition: Action.h:21
ListAction * rotateByAction(double angle, double time)
Generate a ListAction doing a rotation during a given time.
Definition: Action.c:661
Definition: Action.h:20
void moveByActionFunction(struct Element *e, void *data, double spentTime)
function used by moveByAction() and left public to be used in self made action functions ...
Definition: Action.c:373
ListAction * initAction(void(*action)(struct Element *, void *, double), double timing)
Create an action based on its behavior and the time it should take.
Definition: Action.c:12
void scaleToActionFunction(struct Element *e, void *data, double spentTime)
function used by scaleToAction() and left public to be used in self made action functions ...
Definition: Action.c:464
void scaleByActionFunction(struct Element *e, void *data, double spentTime)
function used by scaleByAction() and left public to be used in self made action functions ...
Definition: Action.c:437
ListAction * fadeInAction(int alpha, double time)
Generate a ListAction doing a fade in during a given time.
Definition: Action.c:699
void rotateByActionFunction(struct Element *e, void *data, double spentTime)
function used by rotateByAction() and left public to be used in self made action functions ...
Definition: Action.c:491
ListAction * moveByAction(double x, double y, double time)
Generate a ListAction doing a translation during a given time.
Definition: Action.c:578
int shouldBeFreed
Definition: Action.h:29
void rotateToActionFunction(struct Element *e, void *data, double spentTime)
function used by rotateToAction() and left public to be used in self made action functions ...
Definition: Action.c:516
int isList
Definition: Action.h:53
double timeSpent
Definition: Action.h:23
void(* action)(struct Element *, void *, double)
Definition: Action.h:25
struct ActionNode * next
Definition: Action.h:57
Definition: Action.h:36
void moveToActionFunction(struct Element *e, void *data, double spentTime)
function used by moveToAction() and left public to be used in self made action functions ...
Definition: Action.c:410
int delActionToAction(ListAction *action, long long index)
remove an action inside another
Definition: Action.c:336
int isForever
Definition: Action.h:41
ListAction * setForeverAction(ListAction *action, int isForever)
Tells that the action should run forever or not (by default, an action does not run forever) ...
Definition: Action.c:294