diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/edje/src/examples/sigtest.edc | 303 |
1 files changed, 303 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/sigtest.edc b/libraries/edje/src/examples/sigtest.edc new file mode 100644 index 0000000..ef2a854 --- /dev/null +++ b/libraries/edje/src/examples/sigtest.edc | |||
@@ -0,0 +1,303 @@ | |||
1 | fonts { | ||
2 | font: "Vera.ttf" "default"; | ||
3 | } | ||
4 | |||
5 | images { | ||
6 | image: "bubble.png" COMP; | ||
7 | } | ||
8 | |||
9 | collections { | ||
10 | group { | ||
11 | name: "lua_base"; | ||
12 | lua_script_only: 1; | ||
13 | lua_script { | ||
14 | --// stick object private/local vars here | ||
15 | local D; | ||
16 | local text_geom; | ||
17 | |||
18 | --// Functions to print tables. | ||
19 | local print_table, print_table_start; | ||
20 | |||
21 | function print_table_start(table, space, name) | ||
22 | print(space .. name .. ": "); | ||
23 | print(space .. "{"); | ||
24 | print_table(table, space .. " "); | ||
25 | print(space .. "}"); | ||
26 | end | ||
27 | |||
28 | function print_table(table, space) | ||
29 | for k, v in pairs(table) do | ||
30 | if type(v) == "table" then | ||
31 | print_table_start(v, space, k); | ||
32 | elseif type(v) == "string" then | ||
33 | print(space .. k .. ': "' .. v .. '";') | ||
34 | else | ||
35 | print(space .. k .. ": " .. v .. ";") | ||
36 | end | ||
37 | end | ||
38 | end | ||
39 | |||
40 | |||
41 | --// init object here | ||
42 | D = {}; --// data is empty table to start | ||
43 | edje_geom = edje.geom(); | ||
44 | |||
45 | D.edje = edje.edje(); | ||
46 | D.edje:file("plain/edje/group"); | ||
47 | D.edje:move(0, 0); | ||
48 | D.edje:resize(edje_geom.w, edje_geom.h); | ||
49 | D.edje:show(); | ||
50 | |||
51 | edje.text_class("test_text_class", "Sans:style=Bold", 10); | ||
52 | |||
53 | --// send some random edje message | ||
54 | edje.messagesend(7, "none" ); | ||
55 | edje.messagesend(7, "sig", "lua message signal", "luaSource"); | ||
56 | edje.messagesend(7, "str", "hello world"); | ||
57 | edje.messagesend(7, "int", 987); | ||
58 | edje.messagesend(7, "float", 987.321); | ||
59 | edje.messagesend(7, "strset", {"hello", "there", "world"}); | ||
60 | edje.messagesend(7, "intset", {1, 2, 3}); | ||
61 | edje.messagesend(7, "floatset", {1.1, 2.2, 3.3}); | ||
62 | edje.messagesend(7, "strint", "hello world", 7); | ||
63 | edje.messagesend(7, "strfloat", "hello world", 7.654); | ||
64 | edje.messagesend(7, "strintset","hello world", {1, 2, 3}); | ||
65 | --// and a signal | ||
66 | edje.emit("lua signal", "luaSource"); | ||
67 | |||
68 | |||
69 | function move (x, y) | ||
70 | print("lua::move x=" .. x .. " x=" .. y); | ||
71 | D.edje:move(0, 0); | ||
72 | end | ||
73 | |||
74 | function resize (w, h) | ||
75 | print("lua::resize w=" .. w .. " h=" .. h); | ||
76 | D.edje:resize(w, h); | ||
77 | end | ||
78 | |||
79 | function message (id, type, ...) | ||
80 | print("lua::message id=" .. id .. " type=" .. type); | ||
81 | --// handle your message type here. check id + type then use the | ||
82 | --// vararg appropriately. they are the same as the params passed | ||
83 | --// to edje:messagesend() (if any are passed at all). Any array | ||
84 | --// arguments are passed as a single table. | ||
85 | |||
86 | if ("none" == type) then | ||
87 | print("lua::message no args"); | ||
88 | elseif ("strset" == type) then | ||
89 | strs = ... ; | ||
90 | print_table_start(strs, "", "lua::message strings"); | ||
91 | elseif ("intset" == type) then | ||
92 | ints = ... ; | ||
93 | print_table_start(ints, "", "lua::message ints"); | ||
94 | elseif ("floatset" == type) then | ||
95 | floats = ... ; | ||
96 | print_table_start(floats, "", "lua::message floats"); | ||
97 | elseif ("strintset" == type) then | ||
98 | str, ints = ... ; | ||
99 | print("lua::message " .. str); | ||
100 | print_table_start(ints, "", "lua::message ints"); | ||
101 | elseif ("strfloatset" == type) then | ||
102 | str, floats = ... ; | ||
103 | print("lua::message " .. str); | ||
104 | print_table_start(floats, "", "lua::message floats"); | ||
105 | else | ||
106 | print("lua::message " .. ... ); | ||
107 | end | ||
108 | end | ||
109 | |||
110 | function signal (sig, src) | ||
111 | print("lua::signal sig=|" .. sig .. "| src=" .. src .. "|"); | ||
112 | end | ||
113 | } | ||
114 | } | ||
115 | |||
116 | // The group name NEEDS a / in it, | ||
117 | // or the part below that tries to swallow it won't work. | ||
118 | // Leaving just the lua part visible. | ||
119 | group { | ||
120 | name: "bubbles/lua"; | ||
121 | lua_script_only: 1; | ||
122 | lua_script { | ||
123 | local bubbles = { }; | ||
124 | local bubbleCols = 8; | ||
125 | local bubbleRows = 6; | ||
126 | |||
127 | --// Functions to print tables. | ||
128 | local print_table, print_table_start; | ||
129 | |||
130 | function print_table_start(table, space, name) | ||
131 | print(space .. name .. ": "); | ||
132 | print(space .. "{"); | ||
133 | print_table(table, space .. " "); | ||
134 | print(space .. "}"); | ||
135 | end | ||
136 | |||
137 | function print_table(table, space) | ||
138 | for k, v in pairs(table) do | ||
139 | if type(v) == "table" then | ||
140 | print_table_start(v, space, k); | ||
141 | elseif type(v) == "string" then | ||
142 | print(space .. k .. ': "' .. v .. '";') | ||
143 | else | ||
144 | print(space .. k .. ": " .. v .. ";") | ||
145 | end | ||
146 | end | ||
147 | end | ||
148 | |||
149 | |||
150 | for i = 1, bubbleRows do | ||
151 | row = { }; | ||
152 | for j = 1, bubbleCols do | ||
153 | image = edje.image(); | ||
154 | image:image("bubble.png"); | ||
155 | image:show(); | ||
156 | table.insert(row, image); | ||
157 | end | ||
158 | table.insert(bubbles, row); | ||
159 | end | ||
160 | |||
161 | function resize (w, h) | ||
162 | for i = 1, bubbleRows do | ||
163 | for j = 1, bubbleCols do | ||
164 | w1 = w / bubbleCols; | ||
165 | h1 = h / bubbleRows; | ||
166 | bubbles[i][j]:geom((j - 1) * w1, (i - 1) * h1, w1, h1); | ||
167 | if ((1 == i) or (1 == j) or (bubbleRows == i) or (bubbleCols == j)) then | ||
168 | bubbles[i][j]:color(0, 255, 0, 200); | ||
169 | else | ||
170 | bubbles[i][j]:color(math.random(200) + 55, 0, math.random(255) + 55, 200); | ||
171 | end | ||
172 | end | ||
173 | end | ||
174 | end | ||
175 | |||
176 | function message (id, type, ...) | ||
177 | print("bubbles::message id=" .. id .. " type=" .. type); | ||
178 | --// handle your message type here. check id + type then use the | ||
179 | --// vararg appropriately. they are the same as the params passed | ||
180 | --// to edje:messagesend() (if any are passed at all). Any array | ||
181 | --// arguments are passed as a single table. | ||
182 | |||
183 | if ("none" == type) then | ||
184 | print("bubbles::message no args"); | ||
185 | elseif ("strset" == type) then | ||
186 | strs = ... ; | ||
187 | print_table_start(strs, "", "bubbles::message strings"); | ||
188 | elseif ("intset" == type) then | ||
189 | ints = ... ; | ||
190 | print_table_start(ints, "", "bubbles::message ints"); | ||
191 | elseif ("floatset" == type) then | ||
192 | floats = ... ; | ||
193 | print_table_start(floats, "", "bubbles::message floats"); | ||
194 | elseif ("strintset" == type) then | ||
195 | str, ints = ... ; | ||
196 | print("bubbles::message " .. str); | ||
197 | print_table_start(ints, "", "bubbles::message ints"); | ||
198 | elseif ("strfloatset" == type) then | ||
199 | str, floats = ... ; | ||
200 | print("bubbles::message " .. str); | ||
201 | print_table_start(floats, "", "bubbles::message floats"); | ||
202 | else | ||
203 | print("bubbles::message " .. ... ); | ||
204 | end | ||
205 | end | ||
206 | |||
207 | function signal (sig, src) | ||
208 | print("bubbles::signal sig=|" .. sig .. "| src=|" .. src .. "|"); | ||
209 | end | ||
210 | } | ||
211 | } | ||
212 | |||
213 | group { | ||
214 | name: "plain/edje/group"; | ||
215 | parts { | ||
216 | part { | ||
217 | name: "background"; | ||
218 | type: RECT; | ||
219 | mouse_events: 0; | ||
220 | description { | ||
221 | state: "default" 0.0; | ||
222 | color: 0 0 0 255; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | // A lua group embedded in an edje group. | ||
227 | part { | ||
228 | name: "bubbles_lua"; | ||
229 | type: GROUP; | ||
230 | source: "bubbles/lua"; | ||
231 | mouse_events: 0; | ||
232 | description { state: "default" 0.0; visible: 1; } | ||
233 | } | ||
234 | |||
235 | part { | ||
236 | name: "some_text"; | ||
237 | type: TEXT; | ||
238 | mouse_events: 0; | ||
239 | description { | ||
240 | state: "default" 0; | ||
241 | visible: 1; | ||
242 | text | ||
243 | { | ||
244 | text: "This is test text."; | ||
245 | text_class: "test_text_class"; | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | |||
250 | program { name: "show_signals"; | ||
251 | signal: "*"; | ||
252 | source: "*"; | ||
253 | script | ||
254 | { | ||
255 | new buf[128]; | ||
256 | |||
257 | snprintf(buf, 128, "edje::signal sig=%s sig=%s", sig, src); | ||
258 | set_text(PART:"some_text", buf); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | script { | ||
263 | public global_str0; | ||
264 | public global_str1; | ||
265 | public global_str2; | ||
266 | public str_idx; | ||
267 | |||
268 | public set_text_string() { | ||
269 | new tmp[1024]; | ||
270 | new idx; | ||
271 | idx = get_int(str_idx); | ||
272 | |||
273 | if (idx == 0) | ||
274 | get_str(global_str0, tmp, 1024); | ||
275 | else if (idx == 1) | ||
276 | get_str(global_str1, tmp, 1024); | ||
277 | else if (idx == 2) | ||
278 | get_str(global_str2, tmp, 1024); | ||
279 | else return; | ||
280 | |||
281 | set_text(PART:"some_text", tmp); | ||
282 | send_message(MSG_STRING, 1, tmp); | ||
283 | } | ||
284 | |||
285 | public message(Msg_Type:type, id, ...) { | ||
286 | if (type == MSG_STRING) { | ||
287 | new text[64]; | ||
288 | new buf[128]; | ||
289 | |||
290 | getsarg(3, text, 64); | ||
291 | snprintf(buf, 128, "embryo::message |%s|", text); | ||
292 | set_text(PART:"some_text", buf); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | |||
297 | } | ||
298 | |||
299 | } | ||
300 | } | ||
301 | |||
302 | } | ||
303 | |||