44-- Basic clutter demo.
55--
66
7- local lgi = require (' lgi ' )
8- local Clutter = lgi .require (' Clutter' , ' 1.0' )
9- local GObject = lgi .require (' GObject' , ' 2.0' )
10- local Gio = lgi .require (' Gio' , ' 2.0' )
7+ local LuaGObject = require (' LuaGObject ' )
8+ local Clutter = LuaGObject .require (' Clutter' , ' 1.0' )
9+ local GObject = LuaGObject .require (' GObject' , ' 2.0' )
10+ local Gio = LuaGObject .require (' Gio' , ' 2.0' )
1111
12- local app = Gio .Application { application_id = ' org.lgi .samples.Clutter' }
12+ local app = Gio .Application { application_id = ' org.LuaGObject .samples.Clutter' }
1313
1414local stage = Clutter .Stage .get_default ()
1515stage .color = Clutter .Color (0 , 0 , 0 , 255 )
@@ -19,49 +19,47 @@ stage.title = 'LGI Clutter Demo'
1919
2020local rects = {}
2121for i = 1 , 6 do
22- rects [i ] = Clutter .Rectangle {
23- color = Clutter .Color (
24- 256 / 6 * ((i - 1 ) % 6 ),
25- 256 / 6 * ((i + 3 ) % 6 ),
26- 256 / 6 * ((- i + 8 ) % 6 ),
27- 128 ),
28- width = 100 , height = 100 ,
29- fixed_x = 200 , fixed_y = 200 ,
30- anchor_x = 128 , anchor_y = 64 ,
31- reactive = true ,
32- on_button_press_event = function (rect ) rect :raise_top () return true end ,
33- }
34- stage :add_actor (rects [i ])
35- rects [i ]:show ()
22+ rects [i ] = Clutter .Rectangle {
23+ color = Clutter .Color (
24+ 256 / 6 * ((i - 1 ) % 6 ),
25+ 256 / 6 * ((i + 3 ) % 6 ),
26+ 256 / 6 * ((- i + 8 ) % 6 ),
27+ 128 ),
28+ width = 100 , height = 100 ,
29+ fixed_x = 200 , fixed_y = 200 ,
30+ anchor_x = 128 , anchor_y = 64 ,
31+ reactive = true ,
32+ on_button_press_event = function (rect ) rect :raise_top () return true end ,
33+ }
34+ stage :add_actor (rects [i ])
35+ rects [i ]:show ()
3636end
3737
3838local timeline = Clutter .Timeline { duration = 60 , loop = true }
3939local rotation , rotation_delta = 0 , 0.01
4040local scale , scale_delta = 1 , 0.001
4141function timeline :on_new_frame (frame_num )
42- rotation = rotation + rotation_delta
43- scale = scale + scale_delta
44- if scale > 2 or scale < 1 then scale_delta = - scale_delta end
45- for i = 1 , # rects do
46- rects [i ]:set_rotation (Clutter .RotateAxis .Z_AXIS , rotation * (# rects - i ),
47- 0 , 0 , 0 )
48- rects [i ]:set_scale (scale , 3 - scale )
49- end
42+ rotation = rotation + rotation_delta
43+ scale = scale + scale_delta
44+ if scale > 2 or scale < 1 then scale_delta = - scale_delta end
45+ for i = 1 , # rects do
46+ rects [i ]:set_rotation (Clutter .RotateAxis .Z_AXIS , rotation * (# rects - i ), 0 , 0 , 0 )
47+ rects [i ]:set_scale (scale , 3 - scale )
48+ end
5049
51- -- A bug in clutter? If following line is not present, stage stops
52- -- redrawing itself after a while...
53- stage :queue_redraw ()
50+ -- A bug in clutter? If following line is not present, stage stops redrawing itself after a while...
51+ stage :queue_redraw ()
5452end
5553
5654function stage :on_button_press_event (event )
57- app :release ()
58- return true
55+ app :release ()
56+ return true
5957end
6058
6159function app :on_activate ()
62- self :hold ()
63- stage :show ()
64- timeline :start ()
60+ self :hold ()
61+ stage :show ()
62+ timeline :start ()
6563end
6664
6765return app :run { arg [0 ], ... }
0 commit comments