

For this example we are going to animate a rectangle growing, moving and changing color, and then move it back to it'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't going into detail about it.


\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}>}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_advance\_frame(\textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{double} pos);
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_advance\_frame2(\textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{double} pos);
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_advance\_frame3(\textcolor{keywordtype}{void} *data);
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_start\_second\_anim(\textcolor{keywordtype}{void} *data);
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_freeze\_third\_anim(\textcolor{keywordtype}{void} *data);
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} \_thaw\_third\_anim(\textcolor{keywordtype}{void} *data);

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *rect, *bg, *rect2;
   Ecore\_Evas *ee;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *evas;
   Ecore\_Animator *anim;

   \hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}();

   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, 300, 400, NULL);
   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);
   evas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(evas);
   evas\_object\_resize(bg, 300, 400);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);

   rect = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(evas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(rect, 0, 0, 255, 255);
   evas\_object\_resize(rect, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(rect);

\end{DoxyCodeInclude}
 All of this is just setup, not what we'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}

   rect2 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(evas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(rect2, 0, 55, 0, 255);
   evas\_object\_resize(rect2, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(rect2);

   \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}
   \hyperlink{group__Ecore__Animator__Group_ga523a0e9716bcc6573eb9f4b310067ed1}{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't use a timeline animation, that's because we don't want our animation to stop\+: 
\begin{DoxyCodeInclude}

   anim = \hyperlink{group__Ecore__Animator__Group_gaa1e33b8be9117a26918823c535e429ea}{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}

   ecore\_timer\_add(10, \_start\_second\_anim, rect);
   ecore\_timer\_add(5, \_freeze\_third\_anim, anim);
   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}
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}(rect);
   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Ecore__Animator__Group_gaadfa590f3c1638035393ed9d7aa10e2f}{ecore\_animator\_del}(anim);
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\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 S\+P\+R\+I\+N\+G curve that which will wobble 15 times and will decay by a factor of 1.\+2\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_advance\_frame(\textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{double} pos)
\{
   \textcolor{keywordtype}{double} frame = pos;
   frame = \hyperlink{group__Ecore__Animator__Group_ga5d4c42b9fdb22748943efa9ae6ba0a47}{ecore\_animator\_pos\_map}(pos, 
      \hyperlink{group__Ecore__Animator__Group_gga2db0d0f0f3973829c7f700e5af3e041cac8cbb42f58cabb5db04f52cede85dacd}{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}

   evas\_object\_resize(data, 50 * (1 + frame), 50 * (1 + frame));
   evas\_object\_move(data, 100 * frame, 100 * frame);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(data, 255 * frame, 0, 255 * (1 - frame), 255);
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\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}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_start\_second\_anim(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{group__Ecore__Animator__Group_ga2c7aa7e621cd68562519066ad87a3fa1}{ecore\_animator\_frametime\_set}(1. / 10);
   \hyperlink{group__Ecore__Animator__Group_ga523a0e9716bcc6573eb9f4b310067ed1}{ecore\_animator\_timeline\_add}(20, \_advance\_frame2, data);
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL};
\}

\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's very similar to the callback for the first animation. What we change for this one is the type of animation to B\+O\+U\+N\+C\+E and the number of times it will bounce to 50\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_advance\_frame2(\textcolor{keywordtype}{void} *data, \textcolor{keywordtype}{double} pos)
\{
   \textcolor{keywordtype}{double} frame = pos;
   frame = \hyperlink{group__Ecore__Animator__Group_ga5d4c42b9fdb22748943efa9ae6ba0a47}{ecore\_animator\_pos\_map}(pos, 
      \hyperlink{group__Ecore__Animator__Group_gga2db0d0f0f3973829c7f700e5af3e041ca2eb0a9af74a33bf88fc19d350f703f5e}{ECORE\_POS\_MAP\_BOUNCE}, 1.2, 50);

   evas\_object\_resize(data, 100 - (50 * frame), 100 - (50 * frame));
   evas\_object\_move(data, 100 * (1 - frame), 100 * (1 - frame));
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(data, 255 * (1 - frame), 0, 255 * frame, 255);
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\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}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_advance\_frame3(\textcolor{keywordtype}{void} *data)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{int} x = 0;

   \textcolor{keywordflow}{if} (x >= 250)
     x = 0;
   evas\_object\_move(data, ++x, 350);

   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\end{DoxyCodeInclude}


Our next two functions respectively freezes and thaw our third animation, so that it won't happen for the 5 seconds after the first animation ends and the second animation begins\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_freeze\_third\_anim(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{group__Ecore__Animator__Group_gaff76e892f893610f9360aa6fddd810ef}{ecore\_animator\_freeze}(data);
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL};
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_thaw\_third\_anim(\textcolor{keywordtype}{void} *data)
\{
   \hyperlink{group__Ecore__Animator__Group_ga11c89906f136e3132e23527e412ccc69}{ecore\_animator\_thaw}(data);
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL};
\}

\end{DoxyCodeInclude}
 