scene.nim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # author: Ethosa
  2. import
  3. node,
  4. ../thirdparty/opengl,
  5. ../core/enums,
  6. ../core/input
  7. type
  8. SceneObj* {.final.} = object of NodeObj
  9. ScenePtr* = ptr SceneObj
  10. proc Scene*(name: string, variable: var SceneObj): ScenePtr =
  11. ## Creates a new Scene pointer.
  12. nodepattern(SceneObj)
  13. variable.pausemode = PAUSE
  14. proc Scene*(variable: var SceneObj): ScenePtr {.inline.} =
  15. Scene("Scene", variable)
  16. method drawScene*(scene: ScenePtr, w, h: GLfloat, paused: bool) {.base.} =
  17. ## Draws scene
  18. ## This used in the window.nim.
  19. for child in scene.getChildIter():
  20. if paused and child.getPauseMode() != PROCESS:
  21. continue
  22. if child.visible:
  23. if not child.is_ready:
  24. child.ready()
  25. child.is_ready = true
  26. child.process()
  27. child.draw(w, h)
  28. method enter*(scene: ScenePtr) {.base.} =
  29. for child in scene.getChildIter():
  30. child.enter()
  31. child.is_ready = false
  32. method exit*(scene: ScenePtr) {.base.} =
  33. for child in scene.getChildIter():
  34. child.enter()
  35. child.is_ready = false
  36. method handleScene*(scene: ScenePtr, event: InputEvent, mouse_on: var NodePtr, paused: bool) {.base.} =
  37. var childs = scene.getChildIter()
  38. for i in countdown(childs.len()-1, 0):
  39. if paused and childs[i].getPauseMode() != PROCESS:
  40. continue
  41. if childs[i].visible:
  42. childs[i].handle(event, mouse_on)
  43. childs[i].input(event)
  44. method reAnchorScene*(scene: ScenePtr, w, h: GLfloat, paused: bool) {.base.} =
  45. scene.rect_size.x = w
  46. scene.rect_size.y = h
  47. for child in scene.getChildIter():
  48. if paused and child.getPauseMode() != PROCESS:
  49. continue
  50. if child.visible and child.anchor != nil:
  51. child.calcPositionAnchor()