\hypertarget{embryo_custom_state_8edc-example}{\section{embryo\-\_\-custom\-\_\-state.\-edc}
}
This example shows how to create a custom state from embryo. Clicking on the 3 labels will rotate the object in the given direction.


\begin{DoxyCodeInclude}
collections \{
   images \{
      image: \textcolor{stringliteral}{"bubble.png"} COMP;
      image: \textcolor{stringliteral}{"bubble-blue.png"} COMP;
   \}

   group \{ name: \textcolor{stringliteral}{"main"};
      script \{
         \textcolor{comment}{/* define 3 global vars to hold the rotation values */}
         \textcolor{keyword}{public} rotx;
         \textcolor{keyword}{public} roty;
         \textcolor{keyword}{public} rotz;

         \textcolor{keyword}{public} change\_image(part[], img[]) \{
               \textcolor{keyword}{new} imgid;
               \textcolor{keyword}{new} partid;

               partid = get\_part\_id(part);
               imgid = get\_image\_id(img);

               custom\_state(partid, \textcolor{stringliteral}{"default"}, 0.0);
               \textcolor{comment}{/* change the rotation in the custom state */}
               set\_state\_val(partid, STATE\_IMAGE, imgid);
               \textcolor{comment}{/* apply the custom state */}
               set\_state(partid, \textcolor{stringliteral}{"custom"}, 0.0);
        \}
      \}
      parts \{
         part \{ name: \textcolor{stringliteral}{"bg"};
            type: RECT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 255 255 255 255;
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"img"};
            type: IMAGE;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
              image \{ normal: \textcolor{stringliteral}{"bubble.png"}; \}
            \}
            \textcolor{comment}{/* Dummy state - otherwise edje\_cc discards bubble-blue.png}
\textcolor{comment}{               as it thinks it's unused */}
            description \{ state: \textcolor{stringliteral}{"foo"} 0.0;
              image \{ normal: \textcolor{stringliteral}{"bubble-blue.png"}; \}
            \}
         \}
            
         part \{ name: \textcolor{stringliteral}{"title"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  text: \textcolor{stringliteral}{"Click labels to rotate"};
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.5 0.0;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"X"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  text: \textcolor{stringliteral}{"Rot X (0)"};
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.1 0.5;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"Y"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  text: \textcolor{stringliteral}{"Rot Y (0)"};
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.5 0.9;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"Z"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 0 0 0 255;
               text \{
                  text: \textcolor{stringliteral}{"Rot Z (0)"};
                  font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.9 0.5;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"setimg"};
            type: TEXT;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
              color: 0 0 0 255;
              text \{
                text: \textcolor{stringliteral}{"Change image"};
                font: \textcolor{stringliteral}{"Sans"};
                  size: 12;
                  align: 0.5 1;
               \}
            \}
         \}
         part \{ name: \textcolor{stringliteral}{"rect"};
            type: RECT;
            mouse\_events: 0;
            description \{ state: \textcolor{stringliteral}{"default"} 0.0;
               color: 255 0 0 150;
               max: 150 150;
               align: 0.5 0.5;
               map \{
                  on: 1;
                  perspective\_on: 1;
                  smooth: 1;
                  alpha: 1;
               \}
            \}
         \}
      \}
      programs \{
         program \{
            signal: \textcolor{stringliteral}{"mouse,down,1"};
            source: \textcolor{stringliteral}{"X"};
            script \{
               \textcolor{comment}{/* define local vars */}
               \textcolor{keyword}{new} buf[32];
               \textcolor{keyword}{new} Float:x;

               \textcolor{comment}{/* get global var (and increment) */}
               x = get\_int(rotx) + 10;
               \textcolor{comment}{/* set global var */}
               set\_int(rotx, round(x));
               \textcolor{comment}{/* crete a new custom state (inherit from default 0.0) */}
               custom\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"default"}, 0.0);
               \textcolor{comment}{/* change the rotation in the custom state */}
               set\_state\_val(PART:\textcolor{stringliteral}{"rect"}, STATE\_MAP\_ROT\_X, x);
               \textcolor{comment}{/* apply the custom state */}
               set\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"custom"}, 0.0);
               \textcolor{comment}{/* update the label to show the current value */}
               snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Rot X (%d)"}, round(x));
               set\_text(PART:\textcolor{stringliteral}{"X"}, buf);
            \}
         \}
         program \{
            signal: \textcolor{stringliteral}{"mouse,down,1"};
            source: \textcolor{stringliteral}{"Y"};
            script \{
               \textcolor{keyword}{new} buf[32];
               \textcolor{keyword}{new} Float:y = get\_int(roty) + 10;
               set\_int(roty, round(y));
               custom\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"default"}, 0.0);
               set\_state\_val(PART:\textcolor{stringliteral}{"rect"}, STATE\_MAP\_ROT\_Y, y);
               set\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"custom"}, 0.0);
               snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Rot Y (%d)"}, round(y));
               set\_text(PART:\textcolor{stringliteral}{"Y"}, buf);
            \}
         \}
         program \{
            signal: \textcolor{stringliteral}{"mouse,down,1"};
            source: \textcolor{stringliteral}{"Z"};
            script \{
               \textcolor{keyword}{new} buf[32];
               \textcolor{keyword}{new} Float:z = get\_int(rotz) + 10;
               set\_int(rotz, round(z));
               custom\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"default"}, 0.0);
               set\_state\_val(PART:\textcolor{stringliteral}{"rect"}, STATE\_MAP\_ROT\_Z, z);
               set\_state(PART:\textcolor{stringliteral}{"rect"}, \textcolor{stringliteral}{"custom"}, 0.0);
               snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Rot Z (%d)"}, round(z));
               set\_text(PART:\textcolor{stringliteral}{"Z"}, buf);
            \}
         \}
         program \{
            signal: \textcolor{stringliteral}{"mouse,down,1"};
            source: \textcolor{stringliteral}{"setimg"};
            script \{
               change\_image(\textcolor{stringliteral}{"img"}, \textcolor{stringliteral}{"bubble-blue.png"});
            \}
         \}
      \}
   \}
\}
\end{DoxyCodeInclude}
 