\hypertarget{test_camera_8c-example}{\section{test\+\_\+camera.\+c}
}

\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{# include <config.h>}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include "ephysics\_test.h"}

\textcolor{keyword}{typedef} \textcolor{keyword}{struct }\_Camera\_Data Camera\_Data;

\textcolor{keyword}{struct }\_Camera\_Data \{
     Test\_Data base;
     Ecore\_Animator *animator;
     \textcolor{keywordtype}{int} old\_x;
\};

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_update\_floor(\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj, \hyperlink{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord} delta)
\{
   \textcolor{keywordtype}{int} fx, x, y;

   \hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}(floor\_obj, &x, &y, NULL, NULL);
   fx = x + delta;
   \textcolor{keywordflow}{if} (fx < -FLOOR\_WIDTH)
     fx += 2 * FLOOR\_WIDTH;
   evas\_object\_move(floor\_obj, fx, y);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_camera\_moved\_cb(\textcolor{keywordtype}{void} *data, \hyperlink{group__EPhysics__World_ga83c0d22744748525aa2dac11726c58e6}{EPhysics\_World} *world \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info)
\{
   \hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera} *camera = event\_info;
   Camera\_Data *camera\_data = data;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj;
   \textcolor{keywordtype}{int} x;

   \hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}(\textcolor{stringliteral}{"Camera moved"});

   \hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}(camera, &x, NULL);

   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor"});
   \_update\_floor(floor\_obj, camera\_data->old\_x - x);

   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor2"});
   \_update\_floor(floor\_obj, camera\_data->old\_x - x);

   camera\_data->old\_x = x;
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_camera\_move\_cb(\textcolor{keywordtype}{void} *data)
\{
   Camera\_Data *camera\_data = data;
   \hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera} *camera;
   \textcolor{keywordtype}{int} x, y, w;

   \hyperlink{group__EPhysics__World_ga6bc905b2f56aa2a6c567d9a1575f9075}{ephysics\_world\_render\_geometry\_get}(camera\_data->base.world,
                                      NULL, NULL, NULL, &w, NULL, NULL);

   camera = \hyperlink{group__EPhysics__World_ga97fe0c2a98a7998f29f7390cea868ff0}{ephysics\_world\_camera\_get}(camera\_data->base.world);
   \hyperlink{group__EPhysics__Camera_ga5e549e85d0d98a878dc636b6463645d6}{ephysics\_camera\_position\_get}(camera, &x, &y);

   \textcolor{keywordflow}{if} (x + w > WIDTH * 2)
     \{
        camera\_data->animator = NULL;
        \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
     \}

   x += 2;
   \hyperlink{group__EPhysics__Camera_gaed0ba3e4daecc66fca5dc399031da530}{ephysics\_camera\_position\_set}(camera, x, y);

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_world\_populate(Camera\_Data *camera\_data)
\{
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *sphere, *shadow;
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *fall\_body;

   shadow = elm\_layout\_add(camera\_data->base.win);
   elm\_layout\_file\_set(
      shadow, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"shadow-ball"});
   evas\_object\_move(shadow, WIDTH / 3, FLOOR\_Y);
   evas\_object\_resize(shadow, 70, 3);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(shadow);
   camera\_data->base.evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.evas\_objs,
                                                  shadow);

   sphere = elm\_image\_add(camera\_data->base.win);
   elm\_image\_file\_set(
      sphere, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"},
      \textcolor{stringliteral}{"big-blue-ball"});
   evas\_object\_move(sphere, WIDTH / 3, FLOOR\_Y - 70);
   evas\_object\_resize(sphere, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(sphere);
   camera\_data->base.evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.evas\_objs,
                                                  sphere);

   fall\_body = \hyperlink{group__EPhysics__Body_gab26c09b5a98dabfb0323dbdb7f2a64af}{ephysics\_body\_sphere\_add}(camera\_data->base.world);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(fall\_body, sphere, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(fall\_body, 0.2);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(fall\_body, 1);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(fall\_body, 
      \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    update\_object\_cb, shadow);
   camera\_data->base.bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.bodies,
                                               fall\_body);
   \hyperlink{group__EPhysics__Body_ga9109b39047a724640f6a18c683c9eb07}{ephysics\_body\_central\_impulse\_apply}(fall\_body, 300, 0, 0);

   shadow = elm\_layout\_add(camera\_data->base.win);
   elm\_layout\_file\_set(
      shadow, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"shadow-ball"});
   evas\_object\_move(shadow, WIDTH * 4 / 3, FLOOR\_Y);
   evas\_object\_resize(shadow, 70, 3);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(shadow);
   camera\_data->base.evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.evas\_objs,
                                                  shadow);

   sphere = elm\_image\_add(camera\_data->base.win);
   elm\_image\_file\_set(
      sphere, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"big-red-ball"});
   evas\_object\_move(sphere, WIDTH * 4 / 3, FLOOR\_Y - 70);
   evas\_object\_resize(sphere, 70, 70);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(sphere);
   camera\_data->base.evas\_objs = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.evas\_objs,
                                                  sphere);

   fall\_body = \hyperlink{group__EPhysics__Body_gab26c09b5a98dabfb0323dbdb7f2a64af}{ephysics\_body\_sphere\_add}(camera\_data->base.world);
   \hyperlink{group__EPhysics__Body_gaa0915777f634079ca6c088fda5c20e8f}{ephysics\_body\_mass\_set}(fall\_body, 4.6);
   \hyperlink{group__EPhysics__Body_ga39cb9e95bbe1d097926a09365c501db3}{ephysics\_body\_evas\_object\_set}(fall\_body, sphere, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(fall\_body, 0.12);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(fall\_body, 2);
   \hyperlink{group__EPhysics__Body_gada176f4748a4c2fc4ba2042021ea7067}{ephysics\_body\_event\_callback\_add}(fall\_body, 
      \hyperlink{group__EPhysics__Body_gga904d0d1462e71c1f32cb27f540b5277cacb2363cd59bc8642e74ad916c6658e0a}{EPHYSICS\_CALLBACK\_BODY\_UPDATE},
                                    update\_object\_cb, shadow);
   camera\_data->base.bodies = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(camera\_data->base.bodies,
                                               fall\_body);

   camera\_data->animator = \hyperlink{group__Ecore__Animator__Group_gaa1e33b8be9117a26918823c535e429ea}{ecore\_animator\_add}(\_camera\_move\_cb, camera\_data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_win\_del(\textcolor{keywordtype}{void} *data, \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *e \_\_UNUSED\_\_, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info 
      \_\_UNUSED\_\_)
\{
   Camera\_Data *camera\_data = data;

   \textcolor{keywordflow}{if} (camera\_data->animator)
     \hyperlink{group__Ecore__Animator__Group_gaadfa590f3c1638035393ed9d7aa10e2f}{ecore\_animator\_del}(camera\_data->animator);

   test\_clean((Test\_Data *)camera\_data);
   \hyperlink{group__Evas__Object__Group__Basic_ga7e7a625dab7a3890532aa13b43117076}{evas\_object\_del}(camera\_data->base.layout);
   \hyperlink{group__EPhysics__World_ga99ebd1425f258f895c0089d6eb13def9}{ephysics\_world\_del}(camera\_data->base.world);
   free(camera\_data);
   \hyperlink{group__EPhysics_ga07e695074fb4d5d125b36c3a1d963f49}{ephysics\_shutdown}();
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_restart(\textcolor{keywordtype}{void} *data, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission \_\_UNUSED\_\_, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *
      source \_\_UNUSED\_\_)
\{
   Camera\_Data *camera\_data = data;
   \hyperlink{group__EPhysics__Camera_ga945948dcbf4d98beb457c77b6537116f}{EPhysics\_Camera} *camera;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj;

   \hyperlink{group__Eina__File__Group_gae8924623ca601364965e3d88fb7f40fa}{DBG}(\textcolor{stringliteral}{"Restart pressed"});

   \textcolor{keywordflow}{if} (camera\_data->animator)
     \hyperlink{group__Ecore__Animator__Group_gaadfa590f3c1638035393ed9d7aa10e2f}{ecore\_animator\_del}(camera\_data->animator);

   camera = \hyperlink{group__EPhysics__World_ga97fe0c2a98a7998f29f7390cea868ff0}{ephysics\_world\_camera\_get}(camera\_data->base.world);
   \hyperlink{group__EPhysics__Camera_gaed0ba3e4daecc66fca5dc399031da530}{ephysics\_camera\_position\_set}(camera, 50, 40);

   camera\_data->old\_x = 0;
   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor"});
   evas\_object\_move(floor\_obj, 0, FLOOR\_Y - 20);
   floor\_obj = \hyperlink{group__Evas__Object__Group__Extras_gafbad43015793eda4ae50202c0ce0e652}{evas\_object\_data\_get}(camera\_data->base.layout, \textcolor{stringliteral}{"floor2"});
   evas\_object\_move(floor\_obj, FLOOR\_WIDTH, FLOOR\_Y - 20);

   test\_clean((Test\_Data *)camera\_data);
   \_world\_populate(camera\_data);
\}

\textcolor{keywordtype}{void}
test\_camera(\textcolor{keywordtype}{void} *data \_\_UNUSED\_\_, \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *obj \_\_UNUSED\_\_, \textcolor{keywordtype}{void} *event\_info \_\_UNUSED\_\_)
\{
   Camera\_Data *camera\_data;
   \hyperlink{group__EPhysics__Body_gaf39ad724f8a2f81f9139c63263900bf1}{EPhysics\_Body} *boundary;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *floor\_obj;
   \hyperlink{group__EPhysics__World_ga83c0d22744748525aa2dac11726c58e6}{EPhysics\_World} *world;

   \textcolor{keywordflow}{if} (!\hyperlink{group__EPhysics_gaca8fc170d73b3f688349cc4dbaf219fd}{ephysics\_init}())
     \textcolor{keywordflow}{return};

   camera\_data = calloc(1, \textcolor{keyword}{sizeof}(Camera\_Data));
   \textcolor{keywordflow}{if} (!camera\_data)
     \{
        \hyperlink{group__Eina__File__Group_ga24e93be9c5baa3aeab7021b64e290672}{ERR}(\textcolor{stringliteral}{"Failed to create test data"});
        \hyperlink{group__EPhysics_ga07e695074fb4d5d125b36c3a1d963f49}{ephysics\_shutdown}();
        \textcolor{keywordflow}{return};
     \}

   test\_win\_add((Test\_Data *)camera\_data, \textcolor{stringliteral}{"Camera"}, \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE});
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(camera\_data->base.win, 
      \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa4471afbcbb4a754b7b0bbde00fb9a277}{EVAS\_CALLBACK\_DEL},
                                  \_win\_del, camera\_data);

   elm\_layout\_signal\_callback\_add(camera\_data->base.layout, \textcolor{stringliteral}{"restart"},
                                  \textcolor{stringliteral}{"test-theme"}, \_restart, camera\_data);

   floor\_obj = elm\_image\_add(camera\_data->base.win);
   elm\_image\_file\_set(
      floor\_obj, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"floor"});
   evas\_object\_move(floor\_obj, 0, FLOOR\_Y - 20);
   evas\_object\_resize(floor\_obj, FLOOR\_WIDTH, 224);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(floor\_obj);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(camera\_data->base.layout, \textcolor{stringliteral}{"floor"}, floor\_obj);

   floor\_obj = elm\_image\_add(camera\_data->base.win);
   elm\_image\_file\_set(
      floor\_obj, PACKAGE\_DATA\_DIR \textcolor{stringliteral}{"/"} EPHYSICS\_TEST\_THEME \textcolor{stringliteral}{".edj"}, \textcolor{stringliteral}{"floor"});
   evas\_object\_move(floor\_obj, FLOOR\_WIDTH, FLOOR\_Y - 20);
   evas\_object\_resize(floor\_obj, FLOOR\_WIDTH, 224);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(floor\_obj);
   \hyperlink{group__Evas__Object__Group__Extras_ga70134a7068c9bff4107a761abe0a2ad4}{evas\_object\_data\_set}(camera\_data->base.layout, \textcolor{stringliteral}{"floor2"}, floor\_obj);

   world = \hyperlink{group__EPhysics__World_ga108e2d7df8c81321b8d5bde8497f0d45}{ephysics\_world\_new}();
   \hyperlink{group__EPhysics__World_gaabf8abaf9c41b0c1e5daa4acf3df0356}{ephysics\_world\_render\_geometry\_set}(world, 50, 40, -50,
                                      WIDTH - 100, FLOOR\_Y - 40, DEPTH);
   \hyperlink{group__EPhysics__World_ga2b621ffb39920e4619fe2ec2e5508073}{ephysics\_world\_event\_callback\_add}(world,
                                     \hyperlink{group__EPhysics__World_gga0b0aff31f415be24679d4ab703674619aa5f6adbd98bc6599221d12ecfeb1cbc6}{EPHYSICS\_CALLBACK\_WORLD\_CAMERA\_MOVED}
      ,
                                     \_camera\_moved\_cb, camera\_data);
   camera\_data->base.world = world;

   boundary = \hyperlink{group__EPhysics__Body_gaf8f30587da7453114397d64dd9704d7f}{ephysics\_body\_box\_add}(camera\_data->base.world);
   \hyperlink{group__EPhysics__Body_gaa0915777f634079ca6c088fda5c20e8f}{ephysics\_body\_mass\_set}(boundary, 0);
   \hyperlink{group__EPhysics__Body_ga8821fa07fb5be9d956cc090b14223fd2}{ephysics\_body\_geometry\_set}(boundary, 0, FLOOR\_Y, -15, WIDTH * 2, 10, 30);
   \hyperlink{group__EPhysics__Body_ga731c9a6443f7c4294fce23fc1287b778}{ephysics\_body\_restitution\_set}(boundary, 0.65);
   \hyperlink{group__EPhysics__Body_ga986d45060bf6ba1689a56889a2bcabce}{ephysics\_body\_friction\_set}(boundary, 4);

   \_world\_populate(camera\_data);
\}
\end{DoxyCodeInclude}
 