

This example will illustrates the usage of some basic Ecore\+\_\+\+Evas functions. This example will list the available evas engines, check which one we used to create our window and set some data on our Ecore\+\_\+\+Evas. It also allows you to hide/show all windows in this process(we only have one, but if there were more they would be hidden), to hide the windows type 'h' and hit return, to show them, type 's' and hit return.

The very first thing we'll do is initialize ecore\+\_\+evas\+: 
\begin{DoxyCodeInclude}
   \textcolor{keywordflow}{if} (\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}() <= 0)
     \textcolor{keywordflow}{return} 1;

\end{DoxyCodeInclude}


Once inited we query which engines are available\+: 
\begin{DoxyCodeInclude}

   engines = \hyperlink{group__Ecore__Evas__Group_gab05620912f2d3ca276281efa774104d5}{ecore\_evas\_engines\_get}();
   printf(\textcolor{stringliteral}{"Available engines:\(\backslash\)n"});
   \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(engines, l, data)
     printf("%s\(\backslash\)n", data);
   \hyperlink{group__Ecore__Evas__Group_ga85538b892d449f5c7a056ca4d49e72a7}{ecore\_evas\_engines\_free}(engines);

\end{DoxyCodeInclude}


We then create an Ecore\+\_\+\+Evas(window) with the first available engine, on position 0,0 with size 200,200 and no especial flags, set it's title and show it\+: 
\begin{DoxyCodeInclude}

   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, 200, 200, NULL);
   \hyperlink{group__Ecore__Evas__Group_ga3b2832e0373bbafae2bb7143618535c1}{ecore\_evas\_title\_set}(ee, \textcolor{stringliteral}{"Ecore Evas basics Example"});
   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

\end{DoxyCodeInclude}


We now add some important data to our Ecore\+\_\+\+Evas\+: 
\begin{DoxyCodeInclude}

   data = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 6);
   sprintf(data, \textcolor{stringliteral}{"%s"}, \textcolor{stringliteral}{"hello"});
   \hyperlink{group__Ecore__Evas__Group_gaa86c5abd200a02711aced53d27b9ddb2}{ecore\_evas\_data\_set}(ee, \textcolor{stringliteral}{"key"}, data);

\end{DoxyCodeInclude}


And since our data is dynamically allocated we'll need to free it when the Ecore\+\_\+\+Evas dies\+: 
\begin{DoxyCodeInclude}
   \hyperlink{group__Ecore__Evas__Group_ga3d478e975e2101b9b821ef24baf3dd9e}{ecore\_evas\_callback\_delete\_request\_set}(ee, \_on\_delete);

\end{DoxyCodeInclude}
  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_delete(Ecore\_Evas *ee)
\{
   free(\hyperlink{group__Ecore__Evas__Group_gae00d4a4feb8aec5de03e464fe21a1d30}{ecore\_evas\_data\_get}(ee, \textcolor{stringliteral}{"key"}));
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
\}

\end{DoxyCodeInclude}


We now print which Evas engine is being used for our example\+: 
\begin{DoxyCodeInclude}
   printf(\textcolor{stringliteral}{"Using %s engine!\(\backslash\)n"}, \hyperlink{group__Ecore__Evas__Group_ga13b5c10c8b6615f74c9092d6dc66cc97}{ecore\_evas\_engine\_name\_get}(ee));

\end{DoxyCodeInclude}


We are going to add a background to our window but before we can do that we'll need to get the canvas(\+Evas) on which to draw it\+: 
\begin{DoxyCodeInclude}

   canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

\end{DoxyCodeInclude}


We then do a sanity check, verifying if the Ecore\+\_\+\+Evas of the Evas is the Ecore\+\_\+\+Evas from which we got the Evas\+: 
\begin{DoxyCodeInclude}
   \textcolor{keywordflow}{if} (\hyperlink{group__Ecore__Evas__Group_ga81e49472d5b55809952bf9676daf6a82}{ecore\_evas\_ecore\_evas\_get}(canvas) == ee)
     printf(\textcolor{stringliteral}{"Everything is sane!\(\backslash\)n"});

\end{DoxyCodeInclude}


Now we can actually add the background\+: 
\begin{DoxyCodeInclude}

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 0, 0, 255, 255);
   evas\_object\_resize(bg, 200, 200);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);
   \hyperlink{group__Ecore__Evas__Group_gac35627a5c3a766ee42762dbcc9eb733d}{ecore\_evas\_object\_associate}(ee, bg, ECORE\_EVAS\_OBJECT\_ASSOCIATE\_BASE);

\end{DoxyCodeInclude}


To hide and show the windows of this process when the user presses 'h' and 's' respectively we need to know when the user types something, so we register a callback for when we can read something from {\ttfamily stdin\+:} 
\begin{DoxyCodeInclude}

   \hyperlink{group__Ecore__FD__Handler__Group_ga832e68eb7f15912abeadef816bb5d2f5}{ecore\_main\_fd\_handler\_add}(STDIN\_FILENO, ECORE\_FD\_READ, \_stdin\_cb, NULL, NULL, 
      NULL);

\end{DoxyCodeInclude}


The callback that actually does the hiding and showing is pretty simple, it does a {\ttfamily scanf}(which we know won't block since there is something to read on {\ttfamily stdin}) and if the character is an 'h' we iterate over all windows calling {\ttfamily ecore\+\_\+evas\+\_\+hide} on them, if the character is an 's' we call {\ttfamily ecore\+\_\+evas\+\_\+show} instead\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_stdin\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \hyperlink{group__Ecore__FD__Handler__Group_ga225121ed2123da4b52b76aa08d78c220}{Ecore\_Fd\_Handler} *handler EINA\_UNUSED)
\{
   \hyperlink{struct__Eina__List}{Eina\_List} *l;
   Ecore\_Evas *ee;
   \textcolor{keywordtype}{char} c;

   \textcolor{keywordtype}{int} ret = scanf(\textcolor{stringliteral}{"%c"}, &c);
   \textcolor{keywordflow}{if} (ret < 1) \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};

   \textcolor{keywordflow}{if} (c == \textcolor{charliteral}{'h'})
     \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(\hyperlink{group__Ecore__Evas__Group_gae941cd1dca7354ef68e3137e76db6688}{ecore\_evas\_ecore\_evas\_list\_get}(), l, 
      ee)
       \hyperlink{group__Ecore__Evas__Group_ga0c4c806d5873a4528334e398d28940d4}{ecore\_evas\_hide}(ee);
   else if (c == 's')
     \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(ecore\_evas\_ecore\_evas\_list\_get(), l, ee)
       \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

   return ECORE\_CALLBACK\_RENEW;
\}

\end{DoxyCodeInclude}


Once all is done we run our main loop, and when that is done(application is exiting) we free our Ecore\+\_\+\+Evas and shutdown the ecore\+\_\+evas subsystem\+: 
\begin{DoxyCodeInclude}
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

\end{DoxyCodeInclude}


Here you have the full-\/source of the code\+: 
\begin{DoxyCodeInclude}

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

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_stdin\_cb(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \hyperlink{group__Ecore__FD__Handler__Group_ga225121ed2123da4b52b76aa08d78c220}{Ecore\_Fd\_Handler} *handler EINA\_UNUSED)
\{
   \hyperlink{struct__Eina__List}{Eina\_List} *l;
   Ecore\_Evas *ee;
   \textcolor{keywordtype}{char} c;

   \textcolor{keywordtype}{int} ret = scanf(\textcolor{stringliteral}{"%c"}, &c);
   \textcolor{keywordflow}{if} (ret < 1) \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};

   \textcolor{keywordflow}{if} (c == \textcolor{charliteral}{'h'})
     \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(\hyperlink{group__Ecore__Evas__Group_gae941cd1dca7354ef68e3137e76db6688}{ecore\_evas\_ecore\_evas\_list\_get}(), l, 
      ee)
       \hyperlink{group__Ecore__Evas__Group_ga0c4c806d5873a4528334e398d28940d4}{ecore\_evas\_hide}(ee);
   else if (c == 's')
     \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(ecore\_evas\_ecore\_evas\_list\_get(), l, ee)
       \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

   return ECORE\_CALLBACK\_RENEW;
\}

static \textcolor{keywordtype}{void}
\_on\_delete(Ecore\_Evas *ee)
\{
   free(\hyperlink{group__Ecore__Evas__Group_gae00d4a4feb8aec5de03e464fe21a1d30}{ecore\_evas\_data\_get}(ee, \textcolor{stringliteral}{"key"}));
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   Ecore\_Evas *ee;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg;
   \hyperlink{struct__Eina__List}{Eina\_List} *engines, *l;
   \textcolor{keywordtype}{char} *data;

   \textcolor{keywordflow}{if} (\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}() <= 0)
     \textcolor{keywordflow}{return} 1;

   engines = \hyperlink{group__Ecore__Evas__Group_gab05620912f2d3ca276281efa774104d5}{ecore\_evas\_engines\_get}();
   printf(\textcolor{stringliteral}{"Available engines:\(\backslash\)n"});
   \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(engines, l, data)
     printf("%s\(\backslash\)n", data);
   \hyperlink{group__Ecore__Evas__Group_ga85538b892d449f5c7a056ca4d49e72a7}{ecore\_evas\_engines\_free}(engines);

   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, 200, 200, NULL);
   \hyperlink{group__Ecore__Evas__Group_ga3b2832e0373bbafae2bb7143618535c1}{ecore\_evas\_title\_set}(ee, "Ecore \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} basics Example");
   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(ee);

   data = malloc(sizeof(\textcolor{keywordtype}{char}) * 6);
   sprintf(data, "%s", "hello");
   \hyperlink{group__Ecore__Evas__Group_gaa86c5abd200a02711aced53d27b9ddb2}{ecore\_evas\_data\_set}(ee, "key", data);
   \hyperlink{group__Ecore__Evas__Group_ga3d478e975e2101b9b821ef24baf3dd9e}{ecore\_evas\_callback\_delete\_request\_set}(ee, \_on\_delete);

   printf("Using %s engine!\(\backslash\)n", \hyperlink{group__Ecore__Evas__Group_ga13b5c10c8b6615f74c9092d6dc66cc97}{ecore\_evas\_engine\_name\_get}(ee));

   canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);
   if (\hyperlink{group__Ecore__Evas__Group_ga81e49472d5b55809952bf9676daf6a82}{ecore\_evas\_ecore\_evas\_get}(canvas) == ee)
     printf("Everything is sane!\(\backslash\)n");

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 0, 0, 255, 255);
   evas\_object\_resize(bg, 200, 200);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);
   \hyperlink{group__Ecore__Evas__Group_gac35627a5c3a766ee42762dbcc9eb733d}{ecore\_evas\_object\_associate}(ee, bg, ECORE\_EVAS\_OBJECT\_ASSOCIATE\_BASE);

   \hyperlink{group__Ecore__FD__Handler__Group_ga832e68eb7f15912abeadef816bb5d2f5}{ecore\_main\_fd\_handler\_add}(STDIN\_FILENO, ECORE\_FD\_READ, \_stdin\_cb, NULL, NULL, 
      NULL);

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   return 0;
\}

\end{DoxyCodeInclude}
 