\hypertarget{embryo_custom_state_8edc-example}{}\doxysection{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}{0}
\DoxyCodeLine{collections \{}
\DoxyCodeLine{   images \{}
\DoxyCodeLine{      image: "{}bubble.png"{} COMP;}
\DoxyCodeLine{      image: "{}bubble-\/blue.png"{} COMP;}
\DoxyCodeLine{   \}}
\DoxyCodeLine{}
\DoxyCodeLine{   group \{ name: "{}main"{};}
\DoxyCodeLine{      script \{}
\DoxyCodeLine{         /* define 3 global vars to hold the rotation values */}
\DoxyCodeLine{         public rotx;}
\DoxyCodeLine{         public roty;}
\DoxyCodeLine{         public rotz;}
\DoxyCodeLine{}
\DoxyCodeLine{         public change\_image(part[], img[]) \{}
\DoxyCodeLine{               new imgid;}
\DoxyCodeLine{               new partid;}
\DoxyCodeLine{}
\DoxyCodeLine{               partid = get\_part\_id(part);}
\DoxyCodeLine{               imgid = get\_image\_id(img);}
\DoxyCodeLine{}
\DoxyCodeLine{               custom\_state(partid, "{}default"{}, 0.0);}
\DoxyCodeLine{               /* change the rotation in the custom state */}
\DoxyCodeLine{               set\_state\_val(partid, STATE\_IMAGE, imgid);}
\DoxyCodeLine{               /* apply the custom state */}
\DoxyCodeLine{               set\_state(partid, "{}custom"{}, 0.0);}
\DoxyCodeLine{        \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{      parts \{}
\DoxyCodeLine{         part \{ name: "{}bg"{};}
\DoxyCodeLine{            type: RECT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 255 255 255 255;}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}img"{};}
\DoxyCodeLine{            type: IMAGE;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{              image \{ normal: "{}bubble.png"{}; \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{            /* Dummy state -\/ otherwise edje\_cc discards bubble-\/blue.png}
\DoxyCodeLine{               as it thinks it's unused */}
\DoxyCodeLine{            description \{ state: "{}foo"{} 0.0;}
\DoxyCodeLine{              image \{ normal: "{}bubble-\/blue.png"{}; \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{            }
\DoxyCodeLine{         part \{ name: "{}title"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  text: "{}Click labels to rotate"{};}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.5 0.0;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}X"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  text: "{}Rot X (0)"{};}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.1 0.5;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}Y"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  text: "{}Rot Y (0)"{};}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.5 0.9;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}Z"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 0 0 0 255;}
\DoxyCodeLine{               text \{}
\DoxyCodeLine{                  text: "{}Rot Z (0)"{};}
\DoxyCodeLine{                  font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.9 0.5;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}setimg"{};}
\DoxyCodeLine{            type: TEXT;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{              color: 0 0 0 255;}
\DoxyCodeLine{              text \{}
\DoxyCodeLine{                text: "{}Change image"{};}
\DoxyCodeLine{                font: "{}Sans"{};}
\DoxyCodeLine{                  size: 12;}
\DoxyCodeLine{                  align: 0.5 1;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         part \{ name: "{}rect"{};}
\DoxyCodeLine{            type: RECT;}
\DoxyCodeLine{            mouse\_events: 0;}
\DoxyCodeLine{            description \{ state: "{}default"{} 0.0;}
\DoxyCodeLine{               color: 255 0 0 150;}
\DoxyCodeLine{               max: 150 150;}
\DoxyCodeLine{               align: 0.5 0.5;}
\DoxyCodeLine{               map \{}
\DoxyCodeLine{                  on: 1;}
\DoxyCodeLine{                  perspective\_on: 1;}
\DoxyCodeLine{                  smooth: 1;}
\DoxyCodeLine{                  alpha: 1;}
\DoxyCodeLine{               \}}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{      programs \{}
\DoxyCodeLine{         program \{}
\DoxyCodeLine{            signal: "{}mouse,down,1"{};}
\DoxyCodeLine{            source: "{}X"{};}
\DoxyCodeLine{            script \{}
\DoxyCodeLine{               /* define local vars */}
\DoxyCodeLine{               new buf[32];}
\DoxyCodeLine{               new Float:x;}
\DoxyCodeLine{}
\DoxyCodeLine{               /* get global var (and increment) */}
\DoxyCodeLine{               x = get\_int(rotx) + 10;}
\DoxyCodeLine{               /* set global var */}
\DoxyCodeLine{               set\_int(rotx, round(x));}
\DoxyCodeLine{               /* crete a new custom state (inherit from default 0.0) */}
\DoxyCodeLine{               custom\_state(PART:"{}rect"{}, "{}default"{}, 0.0);}
\DoxyCodeLine{               /* change the rotation in the custom state */}
\DoxyCodeLine{               set\_state\_val(PART:"{}rect"{}, STATE\_MAP\_ROT\_X, x);}
\DoxyCodeLine{               /* apply the custom state */}
\DoxyCodeLine{               set\_state(PART:"{}rect"{}, "{}custom"{}, 0.0);}
\DoxyCodeLine{               /* update the label to show the current value */}
\DoxyCodeLine{               snprintf(buf, sizeof(buf), "{}Rot X (\%d)"{}, round(x));}
\DoxyCodeLine{               set\_text(PART:"{}X"{}, buf);}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         program \{}
\DoxyCodeLine{            signal: "{}mouse,down,1"{};}
\DoxyCodeLine{            source: "{}Y"{};}
\DoxyCodeLine{            script \{}
\DoxyCodeLine{               new buf[32];}
\DoxyCodeLine{               new Float:y = get\_int(roty) + 10;}
\DoxyCodeLine{               set\_int(roty, round(y));}
\DoxyCodeLine{               custom\_state(PART:"{}rect"{}, "{}default"{}, 0.0);}
\DoxyCodeLine{               set\_state\_val(PART:"{}rect"{}, STATE\_MAP\_ROT\_Y, y);}
\DoxyCodeLine{               set\_state(PART:"{}rect"{}, "{}custom"{}, 0.0);}
\DoxyCodeLine{               snprintf(buf, sizeof(buf), "{}Rot Y (\%d)"{}, round(y));}
\DoxyCodeLine{               set\_text(PART:"{}Y"{}, buf);}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         program \{}
\DoxyCodeLine{            signal: "{}mouse,down,1"{};}
\DoxyCodeLine{            source: "{}Z"{};}
\DoxyCodeLine{            script \{}
\DoxyCodeLine{               new buf[32];}
\DoxyCodeLine{               new Float:z = get\_int(rotz) + 10;}
\DoxyCodeLine{               set\_int(rotz, round(z));}
\DoxyCodeLine{               custom\_state(PART:"{}rect"{}, "{}default"{}, 0.0);}
\DoxyCodeLine{               set\_state\_val(PART:"{}rect"{}, STATE\_MAP\_ROT\_Z, z);}
\DoxyCodeLine{               set\_state(PART:"{}rect"{}, "{}custom"{}, 0.0);}
\DoxyCodeLine{               snprintf(buf, sizeof(buf), "{}Rot Z (\%d)"{}, round(z));}
\DoxyCodeLine{               set\_text(PART:"{}Z"{}, buf);}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{         program \{}
\DoxyCodeLine{            signal: "{}mouse,down,1"{};}
\DoxyCodeLine{            source: "{}setimg"{};}
\DoxyCodeLine{            script \{}
\DoxyCodeLine{               change\_image("{}img"{}, "{}bubble-\/blue.png"{});}
\DoxyCodeLine{            \}}
\DoxyCodeLine{         \}}
\DoxyCodeLine{      \}}
\DoxyCodeLine{   \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 