easing.gui_script 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local function update_index_text(index, total)
  2. local index_text = gui.get_node("index_text")
  3. gui.set_text(index_text, index .."/".. total)
  4. end
  5. local function update_easing_text(easing_name)
  6. local easing_text = gui.get_node("easing_text")
  7. gui.set_text(easing_text, "go.".. easing_name)
  8. end
  9. local function change_function_graph(easing_name)
  10. local node = gui.get_node("function_graph")
  11. gui.play_flipbook(node, string.lower(easing_name))
  12. end
  13. local function prev_button_clicked(self)
  14. msg.post("/demo#controller", "prev_easing_demo")
  15. end
  16. local function next_button_clicked(self)
  17. msg.post("/demo#controller", "next_easing_demo")
  18. end
  19. function init(self)
  20. msg.post(".", "acquire_input_focus")
  21. end
  22. function final(self)
  23. msg.post(".", "release_input_focus")
  24. end
  25. function on_message(self, message_id, message)
  26. if message_id == hash("demo_changed") then
  27. update_index_text(message.index, message.total)
  28. update_easing_text(message.easing_name)
  29. change_function_graph(message.easing_name)
  30. end
  31. end
  32. function on_input(self, action_id, action)
  33. if not action_id then return end -- ignore mouse/finger position
  34. if action_id == hash("touch") and action.pressed then
  35. local prev = gui.get_node("prev_button")
  36. local next = gui.get_node("next_button")
  37. if gui.pick_node(prev, action.x, action.y) then
  38. prev_button_clicked(self)
  39. elseif gui.pick_node(next, action.x, action.y) then
  40. next_button_clicked(self)
  41. end
  42. end
  43. end