test13.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # --- Test 13. Clicker. --- #
  2. import nodesnim
  3. var
  4. window = newWindow("hello world", 640, 360)
  5. main: SceneObj
  6. main_scene = Scene("Main", main)
  7. labelobj: LabelObj
  8. label = Label(labelobj)
  9. controlobj: ControlObj
  10. control = Control(controlobj)
  11. score = 0
  12. main_scene.addChild(control)
  13. control.addChild(label)
  14. # --- Set up label and control. --- #
  15. label.resize(128, 64)
  16. label.text = "Press me :3"
  17. label.color = Color(1, 0.6, 1)
  18. label.background_color = Color(1, 0.6, 1, 0.4)
  19. label.text_align = Anchor(0.5, 0.5, 0.5, 0.5)
  20. label.fontdata = openFont("assets/GNUUnifont9FullHintInstrUCSUR.ttf", 16)
  21. control.resize(640, 360)
  22. label.anchor = Anchor(0.5, 0.5, 0.5, 0.5)
  23. # --- Set up actions. --- #
  24. label.mouse_enter =
  25. proc(x, y: float) =
  26. if not label.pressed:
  27. label.background_color.a = 0.5
  28. label.mouse_exit =
  29. proc() =
  30. if not label.pressed:
  31. label.background_color.a = 0.4
  32. label.press =
  33. proc(x, y: float) =
  34. label.background_color.a = 0.6
  35. label.release =
  36. proc() =
  37. if label.hovered:
  38. label.background_color.a = 0.5
  39. else:
  40. label.background_color.a = 0.4
  41. inc score
  42. label.text = "Score: " & $score
  43. window.setMainScene(main_scene)
  44. window.launch()