\hypertarget{evas-stacking_8c-example}{\section{evas-\/stacking.\+c}
}

\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#else}
\textcolor{preprocessor}{#define PACKAGE\_EXAMPLES\_DIR "."}
\textcolor{preprocessor}{#endif}

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

\textcolor{preprocessor}{#include <stdlib.h>}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <string.h>}

\textcolor{preprocessor}{#define WIDTH  320}
\textcolor{preprocessor}{#define HEIGHT 320}

\textcolor{keyword}{struct }test\_data
\{
   Ecore\_Evas  *ee;
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}        *canvas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *rects[3]; \textcolor{comment}{/* red, green, blue */}
   \textcolor{keywordtype}{int}          layers[3]; \textcolor{comment}{/* default, below it, above it */}
   \textcolor{keywordtype}{int}          cur\_rect, cur\_layer;
\};

\textcolor{keyword}{static} \textcolor{keyword}{struct }test\_data d = \{0\};

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *commands = \(\backslash\)
  \textcolor{stringliteral}{"commands are:\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tc - change the target rectangle to operate on\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)ta - stack target rectangle one level above\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tb - stack target rectangle one level below\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tt - stack target rectangle up to the top of its layer\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tm - stack target rectangle down to the bottom of its layer\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tp - toggle target rectangle's 'pass events' property\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tr - toggle target rectangle's 'repeat events' property\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)ts - print current stacking information\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tl - change background rectangle's layer\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)th - print help\(\backslash\)n"};

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *
\_name\_get(\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *o)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *s = evas\_object\_name\_get(o);
   \textcolor{keywordflow}{if} (!s) s = \textcolor{stringliteral}{"(null)"};
   \textcolor{keywordflow}{return} s;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_mouse\_down(\textcolor{keywordtype}{void}        *data EINA\_UNUSED,
               \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}        *\hyperlink{namespaceevas}{evas} EINA\_UNUSED,
               \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *o,
               \textcolor{keywordtype}{void}        *einfo EINA\_UNUSED)
\{
   fprintf(stdout, \textcolor{stringliteral}{"Mouse down on rectangle %s!\(\backslash\)n"}, \_name\_get(o));
\}

\textcolor{comment}{/* here just to keep our example's window size and background image's}
\textcolor{comment}{ * size in synchrony */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_canvas\_resize\_cb(Ecore\_Evas *ee)
\{
   \textcolor{keywordtype}{int} w, h;

   \hyperlink{group__Ecore__Evas__Group_ga931aadf4603731e73e8a84e4b14f1493}{ecore\_evas\_geometry\_get}(ee, NULL, NULL, &w, &h);
   evas\_object\_resize(d.bg, w, h);
\}

\textcolor{comment}{/* use the following commands to interact with this example - 'h' is}
\textcolor{comment}{ * the key for help */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_keydown(\textcolor{keywordtype}{void}        *data EINA\_UNUSED,
            \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas}        *\hyperlink{namespaceevas}{evas} EINA\_UNUSED,
            \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *o EINA\_UNUSED,
            \textcolor{keywordtype}{void}        *einfo)
\{
   \hyperlink{struct__Evas__Event__Key__Down}{Evas\_Event\_Key\_Down} *ev = einfo;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name = \_name\_get(d.rects[d.cur\_rect]);

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"h"}) == 0)  \textcolor{comment}{/* print help */}
     \{
        fprintf(stdout, commands);
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"s"}) == 0)  \textcolor{comment}{/* get status of the}
\textcolor{comment}{                                        * rectangles WRT size}
\textcolor{comment}{                                        * hints */}
     \{
        \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *rect;

        fprintf(stdout, \textcolor{stringliteral}{"Order of stacking, from top to bottom, is: "});

        rect = evas\_object\_top\_get(\hyperlink{namespaceevas}{evas});
        fprintf(stdout, \textcolor{stringliteral}{"%s"}, \_name\_get(rect));

        rect = evas\_object\_below\_get(rect);
        \textcolor{keywordflow}{while} (rect)
          \{
             fprintf(stdout, \textcolor{stringliteral}{", %s"}, \_name\_get(rect));
             rect = evas\_object\_below\_get(rect);
          \}

        fprintf(stdout, \textcolor{stringliteral}{".\(\backslash\)n"});

        fprintf(stdout, \textcolor{stringliteral}{"Current target rectangle is %s\(\backslash\)n"},
                \_name\_get(d.rects[d.cur\_rect]));

        fprintf(stdout, \textcolor{stringliteral}{"Background rectangle's layer is %d\(\backslash\)n"},
                evas\_object\_layer\_get(d.bg));

        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"l"}) == 0)  \textcolor{comment}{/* change background rectangle's layer */}
     \{
        d.cur\_layer = (d.cur\_layer + 1) % 3;
        evas\_object\_layer\_set(d.bg, d.layers[d.cur\_layer]);

        fprintf(stdout, \textcolor{stringliteral}{"Changing background rectangle's layer to %d\(\backslash\)n"},
                d.layers[d.cur\_layer]);
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"c"}) == 0)  \textcolor{comment}{/* change rectangle to operate on */}
     \{
        d.cur\_rect = (d.cur\_rect + 1) % 3;

        fprintf(stdout, \textcolor{stringliteral}{"Changing target rectangle to the %s one\(\backslash\)n"},
                \_name\_get(d.rects[d.cur\_rect]));
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"t"}) == 0)  \textcolor{comment}{/* bring target to top */}
     \{
        \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *neighbour;

        evas\_object\_raise(d.rects[d.cur\_rect]);

        fprintf(stdout, \textcolor{stringliteral}{"%s rectangle was re-stacked to the top if its layer\(\backslash\)n"},
                name);

        neighbour = evas\_object\_below\_get(d.rects[d.cur\_rect]);
        fprintf(stdout, \textcolor{stringliteral}{"Below of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"m"}) == 0)  \textcolor{comment}{/* bring target to bottom */}
     \{
        \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *neighbour;

        evas\_object\_lower(d.rects[d.cur\_rect]);

        fprintf(stdout,
                \textcolor{stringliteral}{"%s rectangle was re-stacked to the bottom if its layer\(\backslash\)n"},
                name);

        neighbour = evas\_object\_below\_get(d.rects[d.cur\_rect]);
        fprintf(stdout, \textcolor{stringliteral}{"Below of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"p"}) == 0)  \textcolor{comment}{/* toggle pass events */}
     \{
        \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} pass = evas\_object\_pass\_events\_get(d.rects[d.cur\_rect]);

        evas\_object\_pass\_events\_set(d.rects[d.cur\_rect], !pass);

        fprintf(stdout, \textcolor{stringliteral}{"%s rectangle is now set to%s pass (ignore) events\(\backslash\)n"},
                name, pass ? \textcolor{stringliteral}{" NOT"} : \textcolor{stringliteral}{""});

        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"r"}) == 0)  \textcolor{comment}{/* toggle repeat events */}
     \{
        \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} repeat = evas\_object\_repeat\_events\_get(d.rects[d.cur\_rect]);

        evas\_object\_repeat\_events\_set(d.rects[d.cur\_rect], !repeat);

        fprintf(stdout, \textcolor{stringliteral}{"%s rectangle is now set to%s repeat events\(\backslash\)n"},
                name, repeat ? \textcolor{stringliteral}{" NOT"} : \textcolor{stringliteral}{""});

        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"a"}) == 0)  \textcolor{comment}{/* stack target above */}
     \{
        \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *neighbour = evas\_object\_above\_get(d.rects[d.cur\_rect]);

        \textcolor{keywordflow}{if} (!neighbour || (evas\_object\_layer\_get(d.rects[d.cur\_rect]) !=
                           evas\_object\_layer\_get(neighbour)))
          \textcolor{keywordflow}{return};

        evas\_object\_stack\_above(d.rects[d.cur\_rect], neighbour);

        fprintf(stdout, \textcolor{stringliteral}{"%s rectangle was re-stacked one level above\(\backslash\)n"}, name);

        neighbour = evas\_object\_above\_get(d.rects[d.cur\_rect]);
        fprintf(stdout, \textcolor{stringliteral}{"Above of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});

        neighbour = evas\_object\_below\_get(d.rects[d.cur\_rect]);
        fprintf(stdout, \textcolor{stringliteral}{"Below of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"b"}) == 0)  \textcolor{comment}{/* stack target below */}
     \{
        \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *neighbour = evas\_object\_below\_get(d.rects[d.cur\_rect]);

        \textcolor{keywordflow}{if} (!neighbour || (evas\_object\_layer\_get(d.rects[d.cur\_rect]) !=
                           evas\_object\_layer\_get(neighbour)))
          \textcolor{keywordflow}{return};

        evas\_object\_stack\_below(d.rects[d.cur\_rect], neighbour);

        fprintf(stdout, \textcolor{stringliteral}{"%s rectangle was re-stacked one level below\(\backslash\)n"}, name);

        neighbour = evas\_object\_above\_get(d.rects[d.cur\_rect]);
        fprintf(stdout, \textcolor{stringliteral}{"Above of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});

        neighbour = evas\_object\_below\_get(d.rects[d.cur\_rect]);

        fprintf(stdout, \textcolor{stringliteral}{"Below of %s rect is %s\(\backslash\)n"}, name,
                neighbour ? \_name\_get(neighbour) : \textcolor{stringliteral}{"no object"});
        \textcolor{keywordflow}{return};
     \}
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_destroy(Ecore\_Evas *ee EINA\_UNUSED)
\{
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \textcolor{keywordflow}{if} (!\hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}())
     \textcolor{keywordflow}{return} EXIT\_FAILURE;

   \textcolor{comment}{/* this will give you a window with an Evas canvas under the first}
\textcolor{comment}{    * engine available */}
   d.ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   \textcolor{keywordflow}{if} (!d.ee)
     \textcolor{keywordflow}{goto} \hyperlink{namespaceefl_1_1eina_1_1log__level_a0eec9fe47d243634f680b56a7d768ec7}{error};

   \hyperlink{group__Ecore__Evas__Group_ga3680b5c89157167318192157a5d24ec4}{ecore\_evas\_callback\_destroy\_set}(d.ee, \_on\_destroy);
   \hyperlink{group__Ecore__Evas__Group_gaac67f679c9027059a34519fbdea360df}{ecore\_evas\_callback\_resize\_set}(d.ee, \_canvas\_resize\_cb);
   \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\_evas\_show}(d.ee);

   \textcolor{comment}{/* the canvas pointer, de facto */}
   d.canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(d.ee);

   d.bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(d.canvas);
   evas\_object\_name\_set(d.bg, \textcolor{stringliteral}{"background"});  \textcolor{comment}{/* white bg */}
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(d.bg, 255, 255, 255, 255);
   evas\_object\_move(d.bg, 0, 0);
   evas\_object\_resize(d.bg, WIDTH, HEIGHT);

   d.layers[0] = evas\_object\_layer\_get(d.bg);
   d.layers[1] = d.layers[0] - 1;
   d.layers[2] = d.layers[0] + 1;

   d.cur\_layer = 1;
   evas\_object\_layer\_set(d.bg, d.layers[d.cur\_layer]);  \textcolor{comment}{/* let's start with it}
\textcolor{comment}{                                                         * below the default}
\textcolor{comment}{                                                         * layer */}

   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(d.bg);

   evas\_object\_focus\_set(d.bg, \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(
     d.bg, \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa336b86bad4f145f84c155e4922335584}{EVAS\_CALLBACK\_KEY\_DOWN}, \_on\_keydown, NULL);

   d.rects[2] = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(d.canvas);
   evas\_object\_name\_set(d.rects[2], \textcolor{stringliteral}{"blue"});
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(d.rects[2], 0, 0, 255, 255);

   evas\_object\_resize(d.rects[2], WIDTH / 2.2, WIDTH / 2.2);
   evas\_object\_move(d.rects[2], WIDTH / 6, WIDTH / 4.5);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(d.rects[2]);
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(
     d.rects[2], \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa9fa52651ccf7e47cd3b7785fc4cf393f}{EVAS\_CALLBACK\_MOUSE\_DOWN}, \_on\_mouse\_down, NULL);

   d.rects[1] = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(d.canvas);
   evas\_object\_name\_set(d.rects[1], \textcolor{stringliteral}{"green"});
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(d.rects[1], 0, 255, 0, 255);

   evas\_object\_resize(d.rects[1], WIDTH / 2.2, WIDTH / 2.2);
   evas\_object\_move(d.rects[1], WIDTH / 2.5, WIDTH / 7);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(d.rects[1]);
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(
     d.rects[1], \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa9fa52651ccf7e47cd3b7785fc4cf393f}{EVAS\_CALLBACK\_MOUSE\_DOWN}, \_on\_mouse\_down, NULL);

   d.rects[0] = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(d.canvas);
   evas\_object\_name\_set(d.rects[0], \textcolor{stringliteral}{"red"});
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(d.rects[0], 255, 0, 0, 255);

   evas\_object\_resize(d.rects[0], WIDTH / 2.2, WIDTH / 2.2);
   evas\_object\_move(d.rects[0], WIDTH / 3, WIDTH / 2.5);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(d.rects[0]);
   \hyperlink{group__Evas__Object__Group__Events_ga23be30ac5cdfb780f1ff82e9108ec26b}{evas\_object\_event\_callback\_add}(
     d.rects[0], \hyperlink{Evas__Common_8h_a99e208e463a20499aabe6faac8a8cb8aa9fa52651ccf7e47cd3b7785fc4cf393f}{EVAS\_CALLBACK\_MOUSE\_DOWN}, \_on\_mouse\_down, NULL);

   fprintf(stdout, commands);
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();
   \textcolor{keywordflow}{return} 0;

\hyperlink{namespaceefl_1_1eina_1_1log__level_a0eec9fe47d243634f680b56a7d768ec7}{error}:
   fprintf(stderr, \textcolor{stringliteral}{"you got to have at least one evas engine built and linked"}
                   \textcolor{stringliteral}{" up to ecore-evas for this example to run properly.\(\backslash\)n"});
   \textcolor{keywordflow}{return} -1;
\}
\end{DoxyCodeInclude}
 