aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/examples/lua_script.edc
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/edje/src/examples/lua_script.edc')
-rw-r--r--libraries/edje/src/examples/lua_script.edc405
1 files changed, 405 insertions, 0 deletions
diff --git a/libraries/edje/src/examples/lua_script.edc b/libraries/edje/src/examples/lua_script.edc
new file mode 100644
index 0000000..24e8ebe
--- /dev/null
+++ b/libraries/edje/src/examples/lua_script.edc
@@ -0,0 +1,405 @@
1color_classes {
2 color_class { name: "test_colour"; color: 255 255 255 255; }
3}
4
5fonts {
6 font: "Vera.ttf" "default";
7}
8
9images {
10 image: "bubble.png" COMP;
11 image: "test.png" COMP;
12}
13
14collections {
15 group {
16 name: "main";
17 lua_script_only: 1;
18 lua_script {
19 --// stick object private/local vars here
20 local D;
21 local count = 0;
22 local fndata = 99;
23 local text_geom;
24
25 --// Functions to print tables.
26 local print_table, print_table_start;
27
28 function print_table_start(table, space, name)
29 print(space .. name .. ": ");
30 print(space .. "{");
31 print_table(table, space .. " ");
32 print(space .. "}");
33 end
34
35 function print_table(table, space)
36 for k, v in pairs(table) do
37 if type(v) == "table" then
38 print_table_start(v, space, k);
39 elseif type(v) == "string" then
40 print(space .. k .. ': "' .. v .. '";')
41 else
42 print(space .. k .. ": " .. v .. ";")
43 end
44 end
45 end
46
47 local function mycb3 (v)
48 print("lua::callback transition " .. D.val .. " v: " .. v);
49 d = {};
50 d = edje.size(d);
51 print("lua::objsize= " .. d.w .. " , " .. d.h);
52 sz = {w=v * 80, h=v * 40};
53 D.rect:geom(((d.w / 2) * math.sin(v * 2 * math.pi)) + ((d.w - sz.w) / 2),
54 ((d.h / 2) * math.cos(v * 2 * math.pi)) + ((d.h - sz.h) / 2),
55 sz.w, sz.h);
56 D.rect:color(255, 128, v * 255, 255);
57 d = D.rect:move(d);
58 print("lua::pos= " .. d.x .. " , " .. d.y);
59
60 r = D.rect:above();
61 if (r ~= nil) then
62 print("lua::rcol");
63 r:color(20, v * 255, 60, 255);
64 else
65 print("lua::r none!!!!!!!!!!!!!!1");
66 end
67 d = edje.size();
68 D.clip:geom(10, 10, d.w - 20, d.h - 20);
69 c = D.clip:clipees();
70 for i=1,table.getn(c),1 do
71 d = c[i]:geom();
72 print("lua::" .. i .. " geom = " .. d.x .. "," .. d.y .. " " .. d.w .. "x" .. d.h);
73 end
74 return true; --// repeat the timer
75 end
76
77 local function mycb2 ()
78 print("lua::callback animator " .. count .. " seconds: " .. edje.seconds() .. " looptime: " .. edje.looptime());
79 edje.color_class("test_colour", 255, (count * 10) % 255, 255, 255);
80 edje.text_class("test_text_class", "Sans:style=Bold", ((count * 3) % 100) + 8);
81 if (5 > (count % 10)) then
82 D.text:font("default", 32);
83 else
84 D.text:font("Sans:style=Bold", 32);
85 end
86 edje_geom = edje.geom();
87 text_geom = D.text:geom();
88 D.text:move((edje_geom.w - text_geom.w) / 2, (edje_geom.h - text_geom.h) / 8);
89 return true; --// repeat the timer
90 end
91
92 local function mycb ()
93 print("lua::callback timer " .. count .. " fndata = " .. fndata);
94 count = count + 1; --// keep count of calls - object data
95 fndata = fndata + 3; --// play with object vars to see if they persist
96 D.tim = edje.timer(0.25, mycb); --// inside cb add new timer
97 return false; --// cease repeating the timer
98 end
99
100 --// init object here
101 D = {}; --// data is empty table to start
102 D.val = math.random(); --// start with some random value so
103 fndata = fndata + D.val; --// func data start point
104 print("lua::init ... " .. D.val);
105 edje.echo("lua::echo('hello world')");
106
107 --// actually add the timer to call mycb in 1.23 sec
108 D.tim = edje.timer(1.23, mycb);
109 D.tra = edje.transition(5.0, mycb3);
110 D.ani = edje.animator(mycb2);
111 edje_geom = edje.geom();
112
113 if (edje.spanky) then edje.spanky(); end
114
115 local date = edje.date();
116 print("lua:: date: " ..
117 date.year .. "|" ..
118 date.month .. "|" ..
119 date.day .. "|" ..
120 date.yearday .. "|" ..
121 date.weekday .. "|" ..
122 date.hour .. "|" ..
123 date.min .. "|" ..
124 date.sec
125 );
126
127 --// send some random edje message
128 edje.messagesend(7, "none" );
129 edje.messagesend(7, "sig", "signal", "source");
130 edje.messagesend(7, "str", "hello world");
131 edje.messagesend(7, "int", 987);
132 edje.messagesend(7, "float", 987.321);
133 edje.messagesend(7, "strset", {"hello", "there", "world"});
134 edje.messagesend(7, "intset", {1, 2, 3});
135 edje.messagesend(7, "floatset", {1.1, 2.2, 3.3});
136 edje.messagesend(7, "strint", "hello world", 7);
137 edje.messagesend(7, "strfloat", "hello world", 7.654);
138 edje.messagesend(7, "strintset","hello world", {1, 2, 3});
139
140 D.edje = edje.edje();
141 D.edje:file("plain/edje/group");
142 D.edje:show();
143
144 D.rect = edje.rect();
145 D.rect:geom (5, 10, 50, 30);
146 D.rect:color (255, 128, 60, 255);
147 D.rect:show ();
148
149 D.rect2 = edje.rect();
150 D.rect2:geom (50, 50, 50, 50);
151 D.rect2:color (20, 30, 60, 120);
152 D.rect2:show ();
153
154 D.clip = edje.rect();
155 D.clip:geom (10, 10, 150, 150);
156 D.clip:color (200, 200, 50, 200);
157 D.clip:show ();
158
159 D.rect2:clip(D.clip);
160 D.rect:clip(D.clip);
161
162 D.text = edje.text();
163 D.text:geom (50, 5, 150, 50);
164 D.text:color (255, 0, 0, 255);
165 D.text:font("Sans:style=Bold", 32);
166 D.text:text("Lua rocks!");
167 text_geom = D.text:geom();
168 print(D.text:text());
169 D.text:show();
170
171 --// Fun with maps!
172 D.map = edje.map(4); --// 4 is the only supported map size at the moment.
173 --// These all do the same thing.
174 --// Note, lua likes to start at 1, C (and thus evas) at 0. I choose to agree with C.
175 D.map:coord(0, 50, 50, 0);
176 D.map:coord(1, 100, 50, 0);
177 D.map:coord(2, 100, 100, 0);
178 D.map:coord(3, 50, 100, 0);
179 D.map:populate(50, 50, 50, 50, 0);
180 D.map:populate(D.rect2, 0);
181 D.map:populate(D.rect2);
182
183 --// print the results
184 D.coord = D.map:coord(0);
185 print("lua::map coords for point 0 x=" .. D.coord.x .. " y=" .. D.coord.y .. " z=" .. D.coord.z);
186 D.coord = D.map:coord(1);
187 print("lua::map coords for point 1 x=" .. D.coord.x .. " y=" .. D.coord.y .. " z=" .. D.coord.z);
188 D.coord = D.map:coord(2);
189 print("lua::map coords for point 2 x=" .. D.coord.x .. " y=" .. D.coord.y .. " z=" .. D.coord.z);
190 D.coord = D.map:coord(3);
191 print("lua::map coords for point 3 x=" .. D.coord.x .. " y=" .. D.coord.y .. " z=" .. D.coord.z);
192
193 D.map:smooth(false);
194 D.map:alpha(true);
195
196 if (D.map:alpha()) then
197 print("lua::map is alpha");
198 end
199
200 if (D.map:smooth()) then
201 print("lua::map is smooooth");
202 end
203
204 if (D.map:clockwise()) then
205 print("lua::map is clockwise");
206 end
207
208 D.map:color(255, 255, 255, 255); // set all points to this colour.
209 D.map:color(1, 255, 0, 255, 255); // set just one point to this colour.
210
211 D.map:lighting(75, 75, 10, 255, 255, 255, 0, 255, 0); // Ambient light and a 3D light source.
212
213 --// Toss it around.
214 D.map:rotate(45.0, 75, 75);
215 D.map:zoom(1.5, 1.5, 75, 75);
216 D.map:rotate3d(10.0, 20.0, 30.0, 75, 75, 0);
217 D.map:perspective(200, 200, 0, 20);
218
219 --// For image UV mapping.
220 D.map:uv(0, 0.0, 0.0);
221 D.map:uv(1, 50.0, 0.0);
222 D.map:uv(2, 50.0, 50.0);
223 D.map:uv(3, 0.0, 50.0);
224
225 --// Actually apply the resulting transformations.
226 D.rect2:map(D.map);
227 D.rect2:map_enable(true);
228 if (D.rect2:map_enable()) then
229 print("lua::map enabled");
230 end
231
232 D.rect2:map_source(D.rect); --// Don't think this is actually implemented in evas.
233
234--// D.map:dup();
235--// D.map:size(); --// perhaps overide the # operator? For now it's only gonna return 4 anyway.
236
237 --// example of deleting something
238 --// D.tim:del();
239
240 --// test the color_class stuff
241 colour = edje.color_class("test_colour");
242 print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
243 colour = edje.color_class("test_colour", 32, 64, 255, 128);
244 print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
245 colour = edje.color_class("test_colour", { r=255, g=0, b=255, a=255 });
246 print("lua::color_class= " .. colour.r .. "," .. colour.g .. "," .. colour.b .. "," .. colour.a);
247 text = edje.text_class("test_text_class", "Sans:style=Bold", 8);
248 print("lua::text_class= " .. text.font .. " size " .. text.size);
249
250 --// Do something bad, just to see what happens.
251--// edje.color_class(nil);
252
253 --// shutdown func - generally empty or not there. everything garbage collected for you
254 function shutdown ()
255 print("lua::shutdown ... " .. D.val);
256 end
257
258 function show ()
259 print("lua::show ... " .. D.val);
260 end
261
262 function hide ()
263 print("lua::hide ... " .. D.val);
264 end
265
266 function move (x, y)
267 print("lua::move x=" .. x .. " x=" .. y);
268 D.edje:move(0, 0);
269 end
270
271 function resize (w, h)
272 print("lua::resize w=" .. w .. " h=" .. h);
273 D.text:move((w - text_geom.w) / 2, (h - text_geom.h) / 8);
274 D.edje:resize(w, h);
275 end
276
277 function message (id, type, ...)
278 print("lua::message id=" .. id .. " type=" .. type);
279 --// handle your message type here. check id + type then use the
280 --// vararg appropriately. they are the same as the params passed
281 --// to edje:messagesend() (if any are passed at all). Any array
282 --// arguments are passed as a single table.
283
284 if ("none" == type) then
285 print("lua::message no args");
286 elseif ("strset" == type) then
287 strs = ... ;
288 print_table_start(strs, "", "lua::message strings");
289 elseif ("intset" == type) then
290 ints = ... ;
291 print_table_start(ints, "", "lua::message ints");
292 elseif ("floatset" == type) then
293 floats = ... ;
294 print_table_start(floats, "", "lua::message floats");
295 elseif ("strintset" == type) then
296 str, ints = ... ;
297 print("lua::message " .. str);
298 print_table_start(ints, "", "lua::message ints");
299 elseif ("strfloatset" == type) then
300 str, floats = ... ;
301 print("lua::message " .. str);
302 print_table_start(floats, "", "lua::message floats");
303 else
304 print("lua::message " .. ... );
305 end
306 end
307
308 function signal (sig, src)
309 print("lua::signal sig= " .. sig .. " src= " .. src);
310 end
311 }
312 }
313
314 // The group name NEEDS a / in it,
315 // or the part below that tries to swallow it won't work.
316 // Leaving just the lua part visible.
317 group {
318 name: "bubbles/lua";
319 lua_script_only: 1;
320 lua_script {
321 local bubbles = { };
322 local bubbleCols = 8;
323 local bubbleRows = 6;
324
325 for i = 1, bubbleRows do
326 row = { };
327 for j = 1, bubbleCols do
328 image = edje.image();
329 image:image("bubble.png");
330 image:show();
331 table.insert(row, image);
332 end
333 table.insert(bubbles, row);
334 end
335
336 function resize (w, h)
337 for i = 1, bubbleRows do
338 for j = 1, bubbleCols do
339 w1 = w / bubbleCols;
340 h1 = h / bubbleRows;
341 bubbles[i][j]:geom((j - 1) * w1, (i - 1) * h1, w1, h1);
342 if ((1 == i) or (1 == j) or (bubbleRows == i) or (bubbleCols == j)) then
343 bubbles[i][j]:color(0, 255, 0, 200);
344 else
345 bubbles[i][j]:color(math.random(200) + 55, 0, math.random(255) + 55, 200);
346 end
347 end
348 end
349 end
350 }
351 }
352
353 group {
354 name: "plain/edje/group";
355 parts {
356 part {
357 name: "background";
358 type: RECT;
359 mouse_events: 0;
360 description {
361 state: "default" 0.0;
362 color: 0 0 0 255;
363 }
364 }
365
366 // A lua group embedded in an edje group.
367 part {
368 name: "bubbles_lua";
369 type: GROUP;
370 source: "bubbles/lua";
371 mouse_events: 0;
372 description { state: "default" 0.0; }
373 }
374
375 part {
376 name: "background_image";
377 type: IMAGE;
378 mouse_events: 0;
379 description {
380 state: "default" 0.0;
381 aspect_preference: HORIZONTAL;
382 color_class: "test_colour";
383 image { normal: "test.png"; }
384 }
385 }
386
387 part {
388 name: "some_text";
389 type: TEXT;
390 mouse_events: 0;
391 description {
392 state: "default" 0;
393 text
394 {
395 text: "This is test text.";
396 text_class: "test_text_class";
397 }
398 }
399 }
400
401 }
402 }
403
404}
405