

For this example we are going to animate a rectangle growing, moving and changing color, and then move it back to it\textquotesingle{}s initial state with a different animation. We are also going to have a second rectangle moving along the bottom of the screen. To do this we are going to use ecore\+\_\+evas, but since that is not the focus here we won\textquotesingle{}t going into detail about it.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include\ <\mbox{\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}}>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_advance\_frame(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{double}\ pos);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_advance\_frame2(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{double}\ pos);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_advance\_frame3(\textcolor{keywordtype}{void}\ *data);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_start\_second\_anim(\textcolor{keywordtype}{void}\ *data);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_freeze\_third\_anim(\textcolor{keywordtype}{void}\ *data);}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}\ \_thaw\_third\_anim(\textcolor{keywordtype}{void}\ *data);}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *rect,\ *bg,\ *rect2;}
\DoxyCodeLine{\ \ \ Ecore\_Evas\ *ee;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}}\ *evas;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{structEcore__Animator}{Ecore\_Animator}}\ *anim;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ ee\ =\ \mbox{\hyperlink{group__Ecore__Evas__Group_gaaa770b6f2f1395f9eeb0e50e26c3f933}{ecore\_evas\_new}}(NULL,\ 0,\ 0,\ 300,\ 400,\ NULL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}}(ee);}
\DoxyCodeLine{\ \ \ evas\ =\ \mbox{\hyperlink{group__Ecore__Evas__Group_ga6f8d214cd55bc940d7cc62fecd8dbc06}{ecore\_evas\_get}}(ee);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bg\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(evas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(bg,\ 300,\ 400);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ rect\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(evas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(rect,\ 0,\ 0,\ 255,\ 255);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(rect,\ 50,\ 50);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(rect);}

\end{DoxyCodeInclude}
All of this is just setup, not what we\textquotesingle{}re interested in right now.

Now we are going to set the frametime for our animation to one fiftieth of a second, this will make our program consume more resources but should make our animation extra smooth\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ rect2\ =\ \mbox{\hyperlink{group__Evas__Object__Rectangle_ga1b7a9d8e6ce240590c1734da5f3449d2}{evas\_object\_rectangle\_add}}(evas);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(rect2,\ 0,\ 55,\ 0,\ 255);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(rect2,\ 50,\ 50);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(rect2);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_ga2c7aa7e621cd68562519066ad87a3fa1}{ecore\_animator\_frametime\_set}}(1.\ /\ 50);}

\end{DoxyCodeInclude}
 And now we get right to the business of creating our ecore\+\_\+animator\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_gaf05c3472d3ef2e62939ad55f70947177}{ecore\_animator\_timeline\_add}}(5,\ \_advance\_frame,\ rect);}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
We are telling our animation to last 10 second and to call \+\_\+advance\+\_\+frame with rect as data.
\end{DoxyNote}
So far we setup the first and second animations, the third one however is a bit different, this time we won\textquotesingle{}t use a timeline animation, that\textquotesingle{}s because we don\textquotesingle{}t want our animation to stop\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ anim\ =\ \mbox{\hyperlink{group__Ecore__Animator__Group_ga0eca52138288075de4487d31dd3942ff}{ecore\_animator\_add}}(\_advance\_frame3,\ rect2);}

\end{DoxyCodeInclude}
 Next we set a few timers to execute \+\_\+start\+\_\+second\+\_\+anim, \+\_\+freeze\+\_\+third\+\_\+anim and \+\_\+thaw\+\_\+thir\+\_\+anim in 10, 5 and 10 seconds respectively\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Timer__Group_ga926423e464d7ef71105dd822d90e1187}{ecore\_timer\_add}}(10,\ \_start\_second\_anim,\ rect);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Timer__Group_ga926423e464d7ef71105dd822d90e1187}{ecore\_timer\_add}}(5,\ \_freeze\_third\_anim,\ anim);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Timer__Group_ga926423e464d7ef71105dd822d90e1187}{ecore\_timer\_add}}(10,\ \_thaw\_third\_anim,\ anim);}

\end{DoxyCodeInclude}
 And now we tell ecore to begin the main loop and free some resources once it leaves the main loop\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9217cf1d90690dbd1960db155d1c7476}{evas\_object\_del}}(rect);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}}(ee);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_gac1b19c4289efbb15193077098a13b30e}{ecore\_animator\_del}}(anim);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Here we have the callback function for our first animation, which first takes {\ttfamily pos(where in the timeline we are)}, maps it to a SPRING curve that which will wobble 15 times and will decay by a factor of 1.\+2\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_advance\_frame(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{double}\ pos)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ frame\ =\ pos;}
\DoxyCodeLine{\ \ \ frame\ =\ \mbox{\hyperlink{group__Ecore__Animator__Group_ga5d4c42b9fdb22748943efa9ae6ba0a47}{ecore\_animator\_pos\_map}}(pos,\ \mbox{\hyperlink{group__Ecore__Animator__Group_gga1047011623d9e2ea31b7e5678b451016ac8cbb42f58cabb5db04f52cede85dacd}{ECORE\_POS\_MAP\_SPRING}},\ 1.2,\ 15);}

\end{DoxyCodeInclude}
 Now that we have the frame we can adjust the rectangle to its appropriate state\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(data,\ 50\ *\ (1\ +\ frame),\ 50\ *\ (1\ +\ frame));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(data,\ 100\ *\ frame,\ 100\ *\ frame);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(data,\ 255\ *\ frame,\ 0,\ 255\ *\ (1\ -\/\ frame),\ 255);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 And now the callback that will run 10 seconds after the program starts(5 seconds after the first animation finishes) and starts our second animation\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_start\_second\_anim(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_ga2c7aa7e621cd68562519066ad87a3fa1}{ecore\_animator\_frametime\_set}}(1.\ /\ 10);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_gaf05c3472d3ef2e62939ad55f70947177}{ecore\_animator\_timeline\_add}}(20,\ \_advance\_frame2,\ data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
\begin{DoxyNote}{Note}
For this animation we made the frametime much larger which means our animation might get \char`\"{}jerky\char`\"{}.
\end{DoxyNote}
The callback for our second animation, our savvy reader no doubt noted that it\textquotesingle{}s very similar to the callback for the first animation. What we change for this one is the type of animation to BOUNCE and the number of times it will bounce to 50\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_advance\_frame2(\textcolor{keywordtype}{void}\ *data,\ \textcolor{keywordtype}{double}\ pos)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{double}\ frame\ =\ pos;}
\DoxyCodeLine{\ \ \ frame\ =\ \mbox{\hyperlink{group__Ecore__Animator__Group_ga5d4c42b9fdb22748943efa9ae6ba0a47}{ecore\_animator\_pos\_map}}(pos,\ \mbox{\hyperlink{group__Ecore__Animator__Group_gga1047011623d9e2ea31b7e5678b451016a2eb0a9af74a33bf88fc19d350f703f5e}{ECORE\_POS\_MAP\_BOUNCE}},\ 1.2,\ 50);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(data,\ 100\ -\/\ (50\ *\ frame),\ 100\ -\/\ (50\ *\ frame));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(data,\ 100\ *\ (1\ -\/\ frame),\ 100\ *\ (1\ -\/\ frame));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(data,\ 255\ *\ (1\ -\/\ frame),\ 0,\ 255\ *\ frame,\ 255);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 And for our last animation callback something simpler, we just move our rectangle right by one pixel until it reaches the end of the screen and then start at the beginning again\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_advance\_frame3(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{int}\ x\ =\ 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (x\ >=\ 250)}
\DoxyCodeLine{\ \ \ \ \ x\ =\ 0;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(data,\ ++x,\ 350);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Our next two functions respectively freezes and thaw our third animation, so that it won\textquotesingle{}t happen for the 5 seconds after the first animation ends and the second animation begins\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_freeze\_third\_anim(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_gaff76e892f893610f9360aa6fddd810ef}{ecore\_animator\_freeze}}(data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_thaw\_third\_anim(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Animator__Group_ga11c89906f136e3132e23527e412ccc69}{ecore\_animator\_thaw}}(data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL}};}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
