Bläddra i källkod

add anchor test.

Ethosa 5 år sedan
förälder
incheckning
e299a2d29c
4 ändrade filer med 43 tillägg och 3 borttagningar
  1. 3 1
      src/nodesnim/nodes/scene.nim
  2. 2 2
      src/nodesnim/window.nim
  3. 1 0
      tests/README.md
  4. 37 0
      tests/test6.nim

+ 3 - 1
src/nodesnim/nodes/scene.nim

@@ -52,7 +52,9 @@ method handleScene*(scene: ScenePtr, event: InputEvent, mouse_on: var NodePtr, p
       childs[i].handle(event, mouse_on)
       childs[i].input(event)
 
-method reAnchorScene*(scene: ScenePtr, paused: bool) {.base.} =
+method reAnchorScene*(scene: ScenePtr, w, h: GLfloat, paused: bool) {.base.} =
+  scene.rect_size.x = w
+  scene.rect_size.y = h
   for child in scene.getChildIter():
     if paused and child.getPauseMode() != PROCESS:
       continue

+ 2 - 2
src/nodesnim/window.nim

@@ -64,7 +64,7 @@ proc reshape(w, h: cint) {.cdecl.} =
     height = h
 
     if current_scene != nil:
-      current_scene.reAnchorScene(paused)
+      current_scene.reAnchorScene(w.GLfloat, h.GLfloat, paused)
 
 template check(event, condition, conditionelif: untyped): untyped =
   if last_event is `event` and `condition`:
@@ -147,7 +147,7 @@ proc changeScene*(name: string): bool {.discardable.} =
       current_scene = nil
       current_scene = scene
       current_scene.enter()
-      current_scene.reAnchorScene(paused)
+      current_scene.reAnchorScene(width.GLfloat, height.GLfloat, paused)
       result = true
       break
 

+ 1 - 0
tests/README.md

@@ -5,3 +5,4 @@
 3. [Window events handling.](https://github.com/Ethosa/nodesnim/blob/master/tests/test3.nim)
 4. [Use ColorRect node.](https://github.com/Ethosa/nodesnim/blob/master/tests/test4.nim)
 5. [Handle Control node events.](https://github.com/Ethosa/nodesnim/blob/master/tests/test5.nim)
+6. [Anchor setting.](https://github.com/Ethosa/nodesnim/blob/master/tests/test6.nim)

+ 37 - 0
tests/test6.nim

@@ -0,0 +1,37 @@
+# --- Test 6. Anchor setting. --- #
+import nodesnim
+
+
+Window("hello world")
+
+var
+  mainobj: SceneObj
+  main = Scene("Main", mainobj)
+
+  colorrectobj: ColorRectObj
+  colorrect = ColorRect(colorrectobj)
+
+  colorrect1obj: ColorRectObj
+  colorrect1 = ColorRect(colorrect1obj)
+
+main.addChild(colorrect)
+colorrect.addChild(colorrect1)
+
+
+colorrect1.anchor = Anchor(  # Try to change it! ^^
+  0.5,  # parent anchor at X axis.
+  0.5,  # parent anchor at Y axis.
+  0.5,  # anchor at X axis.
+  0.5   # anchor at Y axis.
+)
+colorrect.anchor = Anchor(1, 1, 1, 1)
+
+colorrect.resize(256, 128)
+colorrect.move(128, 64)
+colorrect.color = Color(0xaaccffff'u32)
+colorrect1.color = Color(0xccaaffff'u32)
+
+
+addScene(main)
+setMainScene("Main")
+windowLaunch()