\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: "bubble.png" COMP;
      image: "bubble-blue.png" COMP;
   \}

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

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

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

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

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