\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}
1 collections \{
2    images \{
3       image: "bubble.png" COMP;
4       image: "bubble-blue.png" COMP;
5    \}
6 
7    group \{ name: "main";
8       script \{
9          /* define 3 global vars to hold the rotation values */
10          public rotx;
11          public roty;
12          public rotz;
13 
14          public change\_image(part[], img[]) \{
15                new imgid;
16                new partid;
17 
18                partid = get\_part\_id(part);
19                imgid = get\_image\_id(img);
20 
21                custom\_state(partid, "default", 0.0);
22                /* change the rotation in the custom state */
23                set\_state\_val(partid, STATE\_IMAGE, imgid);
24                /* apply the custom state */
25                set\_state(partid, "custom", 0.0);
26         \}
27       \}
28       parts \{
29          part \{ name: "bg";
30             type: RECT;
31             description \{ state: "default" 0.0;
32                color: 255 255 255 255;
33             \}
34          \}
35          part \{ name: "img";
36             type: IMAGE;
37             description \{ state: "default" 0.0;
38               image \{ normal: "bubble.png"; \}
39             \}
40             /* Dummy state - otherwise edje\_cc discards bubble-blue.png
41                as it thinks it's unused */
42             description \{ state: "foo" 0.0;
43               image \{ normal: "bubble-blue.png"; \}
44             \}
45          \}
46             
47          part \{ name: "title";
48             type: TEXT;
49             description \{ state: "default" 0.0;
50                color: 0 0 0 255;
51                text \{
52                   text: "Click labels to rotate";
53                   font: "Sans";
54                   size: 12;
55                   align: 0.5 0.0;
56                \}
57             \}
58          \}
59          part \{ name: "X";
60             type: TEXT;
61             description \{ state: "default" 0.0;
62                color: 0 0 0 255;
63                text \{
64                   text: "Rot X (0)";
65                   font: "Sans";
66                   size: 12;
67                   align: 0.1 0.5;
68                \}
69             \}
70          \}
71          part \{ name: "Y";
72             type: TEXT;
73             description \{ state: "default" 0.0;
74                color: 0 0 0 255;
75                text \{
76                   text: "Rot Y (0)";
77                   font: "Sans";
78                   size: 12;
79                   align: 0.5 0.9;
80                \}
81             \}
82          \}
83          part \{ name: "Z";
84             type: TEXT;
85             description \{ state: "default" 0.0;
86                color: 0 0 0 255;
87                text \{
88                   text: "Rot Z (0)";
89                   font: "Sans";
90                   size: 12;
91                   align: 0.9 0.5;
92                \}
93             \}
94          \}
95          part \{ name: "setimg";
96             type: TEXT;
97             description \{ state: "default" 0.0;
98               color: 0 0 0 255;
99               text \{
100                 text: "Change image";
101                 font: "Sans";
102                   size: 12;
103                   align: 0.5 1;
104                \}
105             \}
106          \}
107          part \{ name: "rect";
108             type: RECT;
109             mouse\_events: 0;
110             description \{ state: "default" 0.0;
111                color: 255 0 0 150;
112                max: 150 150;
113                align: 0.5 0.5;
114                map \{
115                   on: 1;
116                   perspective\_on: 1;
117                   smooth: 1;
118                   alpha: 1;
119                \}
120             \}
121          \}
122       \}
123       programs \{
124          program \{
125             signal: "mouse,down,1";
126             source: "X";
127             script \{
128                /* define local vars */
129                new buf[32];
130                new Float:x;
131 
132                /* get global var (and increment) */
133                x = get\_int(rotx) + 10;
134                /* set global var */
135                set\_int(rotx, round(x));
136                /* crete a new custom state (inherit from default 0.0) */
137                custom\_state(PART:"rect", "default", 0.0);
138                /* change the rotation in the custom state */
139                set\_state\_val(PART:"rect", STATE\_MAP\_ROT\_X, x);
140                /* apply the custom state */
141                set\_state(PART:"rect", "custom", 0.0);
142                /* update the label to show the current value */
143                snprintf(buf, sizeof(buf), "Rot X (%d)", round(x));
144                set\_text(PART:"X", buf);
145             \}
146          \}
147          program \{
148             signal: "mouse,down,1";
149             source: "Y";
150             script \{
151                new buf[32];
152                new Float:y = get\_int(roty) + 10;
153                set\_int(roty, round(y));
154                custom\_state(PART:"rect", "default", 0.0);
155                set\_state\_val(PART:"rect", STATE\_MAP\_ROT\_Y, y);
156                set\_state(PART:"rect", "custom", 0.0);
157                snprintf(buf, sizeof(buf), "Rot Y (%d)", round(y));
158                set\_text(PART:"Y", buf);
159             \}
160          \}
161          program \{
162             signal: "mouse,down,1";
163             source: "Z";
164             script \{
165                new buf[32];
166                new Float:z = get\_int(rotz) + 10;
167                set\_int(rotz, round(z));
168                custom\_state(PART:"rect", "default", 0.0);
169                set\_state\_val(PART:"rect", STATE\_MAP\_ROT\_Z, z);
170                set\_state(PART:"rect", "custom", 0.0);
171                snprintf(buf, sizeof(buf), "Rot Z (%d)", round(z));
172                set\_text(PART:"Z", buf);
173             \}
174          \}
175          program \{
176             signal: "mouse,down,1";
177             source: "setimg";
178             script \{
179                change\_image("img", "bubble-blue.png");
180             \}
181          \}
182       \}
183    \}
184 \}
\end{DoxyCodeInclude}
 