clutterdemo.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /usr/bin/env lua
  2. --
  3. -- Basic clutter demo.
  4. --
  5. local lgi = require('lgi')
  6. local Clutter = lgi.require('Clutter', '1.0')
  7. local GObject = lgi.require('GObject', '2.0')
  8. local Gio = lgi.require('Gio', '2.0')
  9. local app = Gio.Application { application_id = 'org.lgi.samples.Clutter' }
  10. local stage = Clutter.Stage.get_default()
  11. stage.color = Clutter.Color(0, 0, 0, 255)
  12. stage.width = 512
  13. stage.height = 512
  14. stage.title = 'LGI Clutter Demo'
  15. local rects = {}
  16. for i = 1, 6 do
  17. rects[i] = Clutter.Rectangle {
  18. color = Clutter.Color(
  19. 256 / 6 * ((i - 1) % 6),
  20. 256 / 6 * ((i + 3) % 6),
  21. 256 / 6 * ((-i + 8) % 6),
  22. 128),
  23. width = 100, height = 100,
  24. fixed_x = 200, fixed_y = 200,
  25. anchor_x = 128, anchor_y = 64,
  26. reactive = true,
  27. on_button_press_event = function(rect) rect:raise_top() return true end,
  28. }
  29. stage:add_actor(rects[i])
  30. rects[i]:show()
  31. end
  32. local timeline = Clutter.Timeline { duration = 60, loop = true }
  33. local rotation, rotation_delta = 0, 0.01
  34. local scale, scale_delta = 1, 0.001
  35. function timeline:on_new_frame(frame_num)
  36. rotation = rotation + rotation_delta
  37. scale = scale + scale_delta
  38. if scale > 2 or scale < 1 then scale_delta = -scale_delta end
  39. for i = 1, #rects do
  40. rects[i]:set_rotation(Clutter.RotateAxis.Z_AXIS, rotation * (#rects - i),
  41. 0, 0, 0)
  42. rects[i]:set_scale(scale, 3 - scale)
  43. end
  44. -- A bug in clutter? If following line is not present, stage stops
  45. -- redrawing itself after a while...
  46. stage:queue_redraw()
  47. end
  48. function stage:on_button_press_event(event)
  49. app:release()
  50. return true
  51. end
  52. function app:on_activate()
  53. self:hold()
  54. stage:show()
  55. timeline:start()
  56. end
  57. return app:run { arg[0], ... }