test5.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # --- Test 5. Handle Control node events. --- #
  2. import nodesnim
  3. Window("hello world")
  4. var
  5. mainobj: SceneObj
  6. main = Scene("Main", mainobj)
  7. colorrectobj: ColorRectObj
  8. colorrect = ColorRect(colorrectobj)
  9. colorrect1obj: ColorRectObj
  10. colorrect1 = ColorRect(colorrect1obj)
  11. main.addChild(colorrect)
  12. colorrect.addChild(colorrect1)
  13. colorrect1.on_click =
  14. proc(self: ControlPtr, x, y: float) = # This called when the user clicks on the Control node (ColorRect in this case).
  15. colorrect1.move(3, 3)
  16. colorrect.on_press =
  17. proc(self: ControlPtr, x, y: float) = # This called when the user holds on the mouse on the Control node.
  18. colorrect.color.r -= 0.001
  19. colorrect.on_release =
  20. proc(self: ControlPtr, x, y: float) = # This called when the user no more holds on the mouse.
  21. colorrect.color.r = 1
  22. colorrect.on_focus =
  23. proc(self: ControlPtr) = # This called when the Control node gets focus.
  24. echo "hello ^^."
  25. colorrect.on_unfocus =
  26. proc(self: ControlPtr) = # This called when the Control node loses focus.
  27. echo "bye :("
  28. colorrect1.on_mouse_enter =
  29. proc(self: ControlPtr, x, y: float) = # This called when the mouse enters the Control node.
  30. colorrect1.color = Color(1, 0.6, 1, 0.5)
  31. colorrect1.on_mouse_exit =
  32. proc(self: ControlPtr, x, y: float) = # This called when the mouse exit from the Control node.
  33. colorrect1.color = Color(1f, 1f, 1f)
  34. addScene(main)
  35. setMainScene("Main")
  36. windowLaunch()