test6.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # --- Test 6. Events handling. --- #
  2. import nodesnim
  3. var
  4. window = newWindow("hello world", 640, 360)
  5. mainobj: SceneObj
  6. main_scene = Scene("Main", mainobj)
  7. colorrectobj: ColorRectObj
  8. colorrect = ColorRect(colorrectobj)
  9. main_scene.addChild(colorrect)
  10. # for every node
  11. colorrect.enter =
  12. proc() = # This called when scene changed.
  13. echo "Hello!"
  14. colorrect.ready =
  15. proc() = # This called when the scene changed and the `enter` was called.
  16. echo "I'm ready."
  17. colorrect.input =
  18. proc(event: InputEvent) = # This called on user input.
  19. discard
  20. colorrect.process =
  21. proc() = # This called every frame.
  22. discard
  23. colorrect.exit =
  24. proc() = # This called when exit from the scene.
  25. echo "bye :("
  26. # only for control nodes:
  27. colorrect.mouse_enter =
  28. proc(x, y: float) = # This called when a mouse enters the node.
  29. echo "Entered in color rect."
  30. colorrect.mouse_exit =
  31. proc() = # This called when a mouse exits from the node.
  32. echo "Outed from color rect."
  33. window.setMainScene(main_scene)
  34. window.launch()