summaryrefslogtreecommitdiff
path: root/legacy/edje/doc/examples/lua_script.edc
blob: be0bafe88df890e55f262a1d2861a339b1956830 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
collections {
   group { name: "example";
      lua_script_only: 1;
      lua_script {
         --// stick object private/local vars here
         local D;
         local count = 0;
         local fndata = 99;
 
         local function mycb3 (v)
            print("lua::callback transition " .. D.val .. " v: " .. v);
            d = {};
            edje.size(d);
            print("lua::objsize= " .. d.w .. " , " .. d.h);
            sz = {w=v * 80, h=v * 40};
            D.rect:geom(((d.w / 2) * math.sin(v * 2 * math.pi)) + ((d.w - sz.w) / 2),
                        ((d.h / 2) * math.cos(v * 2 * math.pi)) + ((d.h - sz.h) / 2),
                        sz.w, sz.h);
            D.rect:color(255, 128, v * 255, 255);
            D.rect:move(d);
            print("lua::pos= " .. d.x .. " , " .. d.y);
 
            r = D.rect:above();
            if (r ~= nil) then
               print("lua::rcol");
               r:color(20, v * 255, 60, 255);
            else
               print("lua::r none!!!!!!!!!!!!!!1");
            end
            d = edje.size();
            D.clip:geom(10, 10, d.w - 20, d.h - 20);
            c = D.clip:clipees();
            for i=1,table.getn(c),1 do
               d = c[i]:geom();
               print("lua::" .. i .. " geom = " .. d.x .. "," .. d.y .. " " .. d.w .. "x" .. d.h);
            end
            return true;  --// repeat the timer
         end
 
         local function mycb2 ()
            print("lua::callback animator " .. count);
            print("lua:: seconds: " .. edje.seconds());
            print("lua:: looptime: " .. edje.looptime());
            local date = edje.date();
            print("lua:: date: " ..
                  date.year .. "|" ..
                  date.month .. "|" ..
                  date.day .. "|" ..
                  date.yearday .. "|" ..
                  date.weekday .. "|" ..
                  date.hour .. "|" ..
                  date.min .. "|" ..
                  date.sec
                 );
            return true;  --// repeat the timer
         end
 
         local function mycb ()
            print("lua::callback " .. count .. " fndata = " .. fndata);
            count = count + 1; --// keep count of calls - object data
            fndata = fndata + 3; --// play with object vars to see if they persist
            D.tim = edje.timer(0.25, mycb); --// inside cb add new timer
            D.ani = edje.animator(mycb2);
            return false; --// cease repeating the timer
         end
 
         --// init object here
         D = {}; --// data is empty table to start
         D.val = math.random(); --// start with some random value so
         fndata = fndata + D.val; --// func data start point
         print("lua::init ... " .. D.val);
         edje.echo("lua::echo('hello world')");

         --// actually add the timer to call mycb in 1.23 sec
         D.tim = edje.timer(1.23, mycb);
         D.tra = edje.transition(5.0, mycb3);
 
         if (edje.spanky) then edje.spanky(); end

         --// send some random edje message
         edje.messagesend(7, "none"      );
         edje.messagesend(7, "sig",      "signal", "source");
         edje.messagesend(7, "str",      "hello world");
         edje.messagesend(7, "int",      987);
         edje.messagesend(7, "float",    987.321);
         edje.messagesend(7, "strset",   {"hello", "there", "world"});
         edje.messagesend(7, "intset",   {1, 2, 3});
         edje.messagesend(7, "floatset", {1.1, 2.2, 3.3});
         edje.messagesend(7, "strint",   "hello world", 7);
         edje.messagesend(7, "strfloat", "hello world", 7.654);
         edje.messagesend(7, "strintset","hello world", {1, 2, 3});
                  
         D.rect = edje.rect();
         D.rect:geom  (5, 10, 50, 30);
         D.rect:color (255, 128, 60, 255);
         D.rect:show  ();
                  
         D.rect2 = edje.rect();
         D.rect2:geom  (50, 50, 50, 50);
         D.rect2:color (20, 30, 60, 120);
         D.rect2:show  ();

         D.clip = edje.rect();
         D.clip:geom  (10, 10, 150, 150);
         D.clip:color (200, 200, 50, 200);
         D.clip:show  ();
 
         D.rect2:clip(D.clip);
         D.rect:clip(D.clip);

         --// example of deleting something
         --// D.tim:del();
 
         --// shutdown func - generally empty or not there. everything gcd for you
         function shutdown ()
            print("lua::shutdown ... " .. D.val);
         end
         function show ()
            print("lua::show ... " .. D.val);
         end
         function hide ()
            print("lua::hide ... " .. D.val);
         end
         function move (x, y)
            print("lua::move ... " .. D.val);
            print("  x=" .. x .. " x=" .. y);
         end
         function resize (w, h)
            print("lua::resize ... " .. D.val);
            print("  w=" .. w .. " h=" .. h);
         end
         function message (id, type, v1, v2)
            print("lua::message ... " .. D.val);
            print("  id=" .. id .. " type=" .. type);
            --// handle youre message type here. chekc id + type then use v1
            --// and/or v2 (or neither) appropriately. they are the same as
            --// the 2nd and 3rd param passed to edje.messagesend() (if any
            --// are passed at all)
         end
         function signal (sig, src)
            print("lua::signal ... " .. D.val);
            print("  sig=" .. sig .. " src=" .. src);
         end
      }
   }
}