summaryrefslogtreecommitdiff
path: root/legacy/edje/doc/examples/lua_script.edc
diff options
context:
space:
mode:
authorDavide Andreoli <dave@gurumeditation.it>2010-10-08 20:14:14 +0000
committerDavide Andreoli <dave@gurumeditation.it>2010-10-08 20:14:14 +0000
commitd50b2efd9caf5e05e1ac25a034694bca051cb2bb (patch)
tree90eaff4b4cdb7edf485e9fc8930c4687a93d55ef /legacy/edje/doc/examples/lua_script.edc
parent6656e77c9c1205a4cef559b4230212a72dcbd8c8 (diff)
Copy the lua script-only example (by raster) from edje doxy to doc/examples.
SVN revision: 53203
Diffstat (limited to '')
-rw-r--r--legacy/edje/doc/examples/lua_script.edc146
1 files changed, 146 insertions, 0 deletions
diff --git a/legacy/edje/doc/examples/lua_script.edc b/legacy/edje/doc/examples/lua_script.edc
new file mode 100644
index 0000000000..be0bafe88d
--- /dev/null
+++ b/legacy/edje/doc/examples/lua_script.edc
@@ -0,0 +1,146 @@
1collections {
2 group { name: "example";
3 lua_script_only: 1;
4 lua_script {
5 --// stick object private/local vars here
6 local D;
7 local count = 0;
8 local fndata = 99;
9
10 local function mycb3 (v)
11 print("lua::callback transition " .. D.val .. " v: " .. v);
12 d = {};
13 edje.size(d);
14 print("lua::objsize= " .. d.w .. " , " .. d.h);
15 sz = {w=v * 80, h=v * 40};
16 D.rect:geom(((d.w / 2) * math.sin(v * 2 * math.pi)) + ((d.w - sz.w) / 2),
17 ((d.h / 2) * math.cos(v * 2 * math.pi)) + ((d.h - sz.h) / 2),
18 sz.w, sz.h);
19 D.rect:color(255, 128, v * 255, 255);
20 D.rect:move(d);
21 print("lua::pos= " .. d.x .. " , " .. d.y);
22
23 r = D.rect:above();
24 if (r ~= nil) then
25 print("lua::rcol");
26 r:color(20, v * 255, 60, 255);
27 else
28 print("lua::r none!!!!!!!!!!!!!!1");
29 end
30 d = edje.size();
31 D.clip:geom(10, 10, d.w - 20, d.h - 20);
32 c = D.clip:clipees();
33 for i=1,table.getn(c),1 do
34 d = c[i]:geom();
35 print("lua::" .. i .. " geom = " .. d.x .. "," .. d.y .. " " .. d.w .. "x" .. d.h);
36 end
37 return true; --// repeat the timer
38 end
39
40 local function mycb2 ()
41 print("lua::callback animator " .. count);
42 print("lua:: seconds: " .. edje.seconds());
43 print("lua:: looptime: " .. edje.looptime());
44 local date = edje.date();
45 print("lua:: date: " ..
46 date.year .. "|" ..
47 date.month .. "|" ..
48 date.day .. "|" ..
49 date.yearday .. "|" ..
50 date.weekday .. "|" ..
51 date.hour .. "|" ..
52 date.min .. "|" ..
53 date.sec
54 );
55 return true; --// repeat the timer
56 end
57
58 local function mycb ()
59 print("lua::callback " .. count .. " fndata = " .. fndata);
60 count = count + 1; --// keep count of calls - object data
61 fndata = fndata + 3; --// play with object vars to see if they persist
62 D.tim = edje.timer(0.25, mycb); --// inside cb add new timer
63 D.ani = edje.animator(mycb2);
64 return false; --// cease repeating the timer
65 end
66
67 --// init object here
68 D = {}; --// data is empty table to start
69 D.val = math.random(); --// start with some random value so
70 fndata = fndata + D.val; --// func data start point
71 print("lua::init ... " .. D.val);
72 edje.echo("lua::echo('hello world')");
73
74 --// actually add the timer to call mycb in 1.23 sec
75 D.tim = edje.timer(1.23, mycb);
76 D.tra = edje.transition(5.0, mycb3);
77
78 if (edje.spanky) then edje.spanky(); end
79
80 --// send some random edje message
81 edje.messagesend(7, "none" );
82 edje.messagesend(7, "sig", "signal", "source");
83 edje.messagesend(7, "str", "hello world");
84 edje.messagesend(7, "int", 987);
85 edje.messagesend(7, "float", 987.321);
86 edje.messagesend(7, "strset", {"hello", "there", "world"});
87 edje.messagesend(7, "intset", {1, 2, 3});
88 edje.messagesend(7, "floatset", {1.1, 2.2, 3.3});
89 edje.messagesend(7, "strint", "hello world", 7);
90 edje.messagesend(7, "strfloat", "hello world", 7.654);
91 edje.messagesend(7, "strintset","hello world", {1, 2, 3});
92
93 D.rect = edje.rect();
94 D.rect:geom (5, 10, 50, 30);
95 D.rect:color (255, 128, 60, 255);
96 D.rect:show ();
97
98 D.rect2 = edje.rect();
99 D.rect2:geom (50, 50, 50, 50);
100 D.rect2:color (20, 30, 60, 120);
101 D.rect2:show ();
102
103 D.clip = edje.rect();
104 D.clip:geom (10, 10, 150, 150);
105 D.clip:color (200, 200, 50, 200);
106 D.clip:show ();
107
108 D.rect2:clip(D.clip);
109 D.rect:clip(D.clip);
110
111 --// example of deleting something
112 --// D.tim:del();
113
114 --// shutdown func - generally empty or not there. everything gcd for you
115 function shutdown ()
116 print("lua::shutdown ... " .. D.val);
117 end
118 function show ()
119 print("lua::show ... " .. D.val);
120 end
121 function hide ()
122 print("lua::hide ... " .. D.val);
123 end
124 function move (x, y)
125 print("lua::move ... " .. D.val);
126 print(" x=" .. x .. " x=" .. y);
127 end
128 function resize (w, h)
129 print("lua::resize ... " .. D.val);
130 print(" w=" .. w .. " h=" .. h);
131 end
132 function message (id, type, v1, v2)
133 print("lua::message ... " .. D.val);
134 print(" id=" .. id .. " type=" .. type);
135 --// handle youre message type here. chekc id + type then use v1
136 --// and/or v2 (or neither) appropriately. they are the same as
137 --// the 2nd and 3rd param passed to edje.messagesend() (if any
138 --// are passed at all)
139 end
140 function signal (sig, src)
141 print("lua::signal ... " .. D.val);
142 print(" sig=" .. sig .. " src=" .. src);
143 end
144 }
145 }
146}