\hypertarget{ecore_evas_window_sizes_example_8c-example}{}\section{ecore\+\_\+evas\+\_\+window\+\_\+sizes\+\_\+example.\+c}

\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}

\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#else}
\textcolor{preprocessor}{#define EINA\_UNUSED}
\textcolor{preprocessor}{#endif}

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

\textcolor{preprocessor}{#define WIDTH  (300)}
\textcolor{preprocessor}{#define HEIGHT (300)}

\textcolor{keyword}{static} Ecore\_Evas *ee;
\textcolor{keyword}{static} \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *text, *bg;
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} min\_set = \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} max\_set = \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} base\_set = \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};
\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} step\_set = \hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE};

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} commands[] = \(\backslash\)
  \textcolor{stringliteral}{"commands are:\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tm - impose a minumum size to the window\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tx - impose a maximum size to the window\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tb - impose a base size to the window\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)ts - impose a step size (different than 1 px) to the window\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)tg - get the screen geometry\(\backslash\)n"}
  \textcolor{stringliteral}{"\(\backslash\)th - print help\(\backslash\)n"};

\textcolor{comment}{/* to inform current window's size */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_canvas\_resize\_cb(Ecore\_Evas *ee\_)
\{
   \textcolor{keywordtype}{int} w, h;
   \textcolor{keywordtype}{char} buf[1024];

   \hyperlink{group__Ecore__Evas__Group_ga931aadf4603731e73e8a84e4b14f1493}{ecore\_evas\_geometry\_get}(ee\_, NULL, NULL, &w, &h);
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%d x %d"}, w, h);
   \hyperlink{group__Evas__Object__Text_gabe57fc428ee4db9e9d7feb9e3a108fb3}{evas\_object\_text\_text\_set}(text, buf);
   \hyperlink{group__Evas__Font__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}(text, (w - 150) / 2, (h - 50) / 2);

   \hyperlink{group__Evas__Font__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}(bg, w, h);
\}

\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{keyword}{static} \textcolor{keywordtype}{void}
\_on\_keydown(\textcolor{keywordtype}{void} *data EINA\_UNUSED,
            \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *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{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}{"m"}) == 0) \textcolor{comment}{/* impose a minimum size on the window */}
     \{
        min\_set = !min\_set;

        \textcolor{keywordflow}{if} (min\_set)
          \{
             \hyperlink{group__Ecore__Evas__Group_ga63abcee3b625bd6410fe8eb46b2a5d9c}{ecore\_evas\_size\_min\_set}(ee, WIDTH / 2, HEIGHT / 2);
             fprintf(stdout, \textcolor{stringliteral}{"Imposing a minimum size of %d x %d\(\backslash\)n"},
                     WIDTH / 2, HEIGHT / 2);
          \}
        \textcolor{keywordflow}{else}
          \{
             \hyperlink{group__Ecore__Evas__Group_ga63abcee3b625bd6410fe8eb46b2a5d9c}{ecore\_evas\_size\_min\_set}(ee, 0, 0);
             fprintf(stdout, \textcolor{stringliteral}{"Taking off minimum size restriction from the"}
                             \textcolor{stringliteral}{" window\(\backslash\)n"});
          \}
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"x"}) == 0) \textcolor{comment}{/* impose a maximum size on the window */}
     \{
        max\_set = !max\_set;

        \textcolor{keywordflow}{if} (max\_set)
          \{
             \hyperlink{group__Ecore__Evas__Group_gac9ad3e25ab3f2bea8be726d24df62902}{ecore\_evas\_size\_max\_set}(ee, WIDTH * 2, HEIGHT * 2);
             fprintf(stdout, \textcolor{stringliteral}{"Imposing a maximum size of %d x %d\(\backslash\)n"},
                     WIDTH * 2, HEIGHT * 2);
          \}
        \textcolor{keywordflow}{else}
          \{
             \hyperlink{group__Ecore__Evas__Group_gac9ad3e25ab3f2bea8be726d24df62902}{ecore\_evas\_size\_max\_set}(ee, 0, 0);
             fprintf(stdout, \textcolor{stringliteral}{"Taking off maximum size restriction from the"}
                             \textcolor{stringliteral}{" window\(\backslash\)n"});
          \}
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"b"}) == 0) \textcolor{comment}{/* impose a base size on the window */}
     \{
        base\_set = !base\_set;

        \textcolor{keywordflow}{if} (base\_set)
          \{
             \hyperlink{group__Ecore__Evas__Group_ga540886b523486b791729d5d3f62f9fce}{ecore\_evas\_size\_base\_set}(ee, WIDTH * 2, HEIGHT * 2);
             fprintf(stdout, \textcolor{stringliteral}{"Imposing a base size of %d x %d\(\backslash\)n"},
                     WIDTH * 2, HEIGHT * 2);
          \}
        \textcolor{keywordflow}{else}
          \{
             \hyperlink{group__Ecore__Evas__Group_ga540886b523486b791729d5d3f62f9fce}{ecore\_evas\_size\_base\_set}(ee, 0, 0);
             fprintf(stdout, \textcolor{stringliteral}{"Taking off base size restriction from the"}
                             \textcolor{stringliteral}{" window\(\backslash\)n"});
          \}
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"s"}) == 0) \textcolor{comment}{/* impose a step size on the window */}
     \{
        step\_set = !step\_set;

        \textcolor{keywordflow}{if} (step\_set)
          \{
             \hyperlink{group__Ecore__Evas__Group_gab794b84a4f53e7fc36d5e87882185dc5}{ecore\_evas\_size\_step\_set}(ee, 40, 40);
             fprintf(stdout, \textcolor{stringliteral}{"Imposing a step size of %d x %d\(\backslash\)n"}, 40, 40);
          \}
        \textcolor{keywordflow}{else}
          \{
             \hyperlink{group__Ecore__Evas__Group_gab794b84a4f53e7fc36d5e87882185dc5}{ecore\_evas\_size\_step\_set}(ee, 0, 0);
             fprintf(stdout, \textcolor{stringliteral}{"Taking off step size restriction from the"}
                             \textcolor{stringliteral}{" window\(\backslash\)n"});
          \}
        \textcolor{keywordflow}{return};
     \}

   \textcolor{keywordflow}{if} (strcmp(ev->\hyperlink{struct__Evas__Event__Key__Down_a70473bba88a1afaee180a54150513824}{key}, \textcolor{stringliteral}{"g"}) == 0) \textcolor{comment}{/* get screen geometry */}
     \{
        \textcolor{keywordtype}{int} x, y, w, h;
        \hyperlink{group__Ecore__Evas__Group_gad537a5714784cb0ca1d62878a522642f}{ecore\_evas\_screen\_geometry\_get}(ee, &x, &y, &w, &h);
        fprintf(stdout, \textcolor{stringliteral}{"screen geometry: %d,%d, %dx%d\(\backslash\)n"}, x, y, w, h);
        \textcolor{keywordflow}{return};
     \}
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *evas;

   \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 */}
   ee = \hyperlink{group__Ecore__Evas__Group_gac7f2cdbcb79635c34317c1183dd04cb0}{ecore\_evas\_new}(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} \hyperlink{namespaceefl_1_1eina_1_1log__level_a0eec9fe47d243634f680b56a7d768ec7}{error};

   \hyperlink{group__Ecore__Evas__Group_ga3d478e975e2101b9b821ef24baf3dd9e}{ecore\_evas\_callback\_delete\_request\_set}(ee, \_on\_destroy);
   \hyperlink{group__Ecore__Evas__Group_ga3b2832e0373bbafae2bb7143618535c1}{ecore\_evas\_title\_set}(ee, \textcolor{stringliteral}{"Ecore\_Evas window sizes example"});
   \hyperlink{group__Ecore__Evas__Group_gaac67f679c9027059a34519fbdea360df}{ecore\_evas\_callback\_resize\_set}(ee, \_canvas\_resize\_cb);
   \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);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 255, 255, 255, 255);  \textcolor{comment}{/* white bg */}
   \hyperlink{group__Evas__Font__Group_ga02da8091bbac768b8e86c7b74b2a94f9}{evas\_object\_move}(bg, 0, 0);  \textcolor{comment}{/* at canvas' origin */}
   \hyperlink{group__Evas__Font__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}(bg, WIDTH, HEIGHT);  \textcolor{comment}{/* covers full canvas */}
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);

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

   text = \hyperlink{group__Evas__Object__Text_ga72224822cf1772ef16b1554f0a6205d5}{evas\_object\_text\_add}(evas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(text, 0, 0, 0, 255);
   \hyperlink{group__Evas__Font__Group_ga21e8604c0e4a93e469bff4bd069e82b5}{evas\_object\_resize}(text, 150, 50);
   \hyperlink{group__Evas__Object__Text_ga1813cea2c010c923d31787caec5dc857}{evas\_object\_text\_font\_set}(text, \textcolor{stringliteral}{"Sans"}, 20);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(text);

   \_canvas\_resize\_cb(ee);
   fprintf(stdout, commands);
   \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}();

   \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"}
                   \textcolor{stringliteral}{" and linked up to ecore-evas for this example to run"}
                   \textcolor{stringliteral}{" properly.\(\backslash\)n"});
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();
   \textcolor{keywordflow}{return} -1;
\}

\end{DoxyCodeInclude}
 