Kaynağa Gözat

small update

Ethosa 4 yıl önce
ebeveyn
işleme
db015d072c

+ 16 - 10
README.md

@@ -97,20 +97,26 @@ Use the [`Nim compiler user guide`](https://nim-lang.org/docs/nimc.html#dynlibov
 
 ## Screenshots
 <div align="center">
-  <a href="https://github.com/Ethosa/nodesnim/blob/master/examples/hello_world">
-    <img src="https://github.com/Ethosa/nodesnim/blob/master/screenshots/1.png" width="380" height="220" alt="Hello world example">
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/hello_world">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/1.png" width="380" height="220" alt="Hello world example">
   </a>
-  <a href="https://github.com/Ethosa/nodesnim/blob/master/examples/calculator">
-    <img src="https://github.com/Ethosa/nodesnim/blob/master/screenshots/2.png" width="380" height="220" alt="Calculator example">
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/calculator">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/2.png" width="380" height="220" alt="Calculator example">
   </a>
-  <a href="https://github.com/Ethosa/nodesnim/blob/master/examples/snake">
-    <img src="https://github.com/Ethosa/nodesnim/blob/master/screenshots/3.png" width="380" height="220" alt="Snake game example">
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/snake">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/3.png" width="380" height="220" alt="Snake game example">
   </a>
-  <a href="https://github.com/Ethosa/nodesnim/blob/master/examples/screensaver">
-    <img src="https://github.com/Ethosa/nodesnim/blob/master/screenshots/4.png" width="380" height="220" alt="Screensaver example">
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/screensaver">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/4.png" width="380" height="220" alt="Screensaver example">
   </a>
-  <a href="https://github.com/Ethosa/nodesnim/blob/master/examples/novel">
-    <img src="https://github.com/Ethosa/nodesnim/blob/master/screenshots/5.png" width="380" height="220" alt="Novel game example">
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/novel">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/5.png" width="380" height="220" alt="Novel game example">
+  </a>
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/roguelike">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/6.png" width="380" height="220" alt="Roguelike game example">
+  </a>
+  <a href="https://github.com/Ethosa/nodesnim/blob/nightly/examples/sample messenger">
+    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/8.png" width="380" height="220" alt="sample messenger">
   </a>
 </div>
 

+ 9 - 10
examples/calculator/main.nim

@@ -43,28 +43,27 @@ proc on_sign(self: ButtonRef, x, y: float) =
 build:
   - Scene main:
     - Vbox vbox:
-      call setChildAnchor(0.5, 0.5, 0.5, 0.5)
       call setSizeAnchor(1, 1)
+      call setChildAnchor(0.5, 0.5, 0.5, 0.5)
       - Label result:
         call setTextAlign(1, 0, 1, 0)
         call resize(160, 32)
       - GridBox buttons:
         call setRow(4)
-        - Button button_7(text: stext"7", on_touch: number)
-        - Button button_8(text: stext"8", on_touch: number)
-        - Button button_9(text: stext"9", on_touch: number)
-        - Button button_4(text: stext"4", on_touch: number)
-        - Button button_5(text: stext"5", on_touch: number)
-        - Button button_6(text: stext"6", on_touch: number)
         - Button button_1(text: stext"1", on_touch: number)
         - Button button_2(text: stext"2", on_touch: number)
         - Button button_3(text: stext"3", on_touch: number)
-        - Button button_0(text: stext"0")
-        - Button button_00(text: stext"00")
         - Button button_add(text: stext"+", on_touch: on_sign)
-        # Signs
+        - Button button_4(text: stext"4", on_touch: number)
+        - Button button_5(text: stext"5", on_touch: number)
+        - Button button_6(text: stext"6", on_touch: number)
         - Button button_sub(text: stext"-", on_touch: on_sign)
+        - Button button_7(text: stext"7", on_touch: number)
+        - Button button_8(text: stext"8", on_touch: number)
+        - Button button_9(text: stext"9", on_touch: number)
         - Button button_mul(text: stext"x", on_touch: on_sign)
+        - Button button_0(text: stext"0")
+        - Button button_00(text: stext"00")
         - Button button_div(text: stext"/", on_touch: on_sign)
         - Button button_eq:
           text: stext"="

+ 20 - 7
examples/readme.md

@@ -1,9 +1,22 @@
 # Examples
 
-1. [Hello world](https://github.com/Ethosa/nodesnim/blob/master/examples/hello_world)
-2. [Calculator](https://github.com/Ethosa/nodesnim/blob/master/examples/calculator)
-3. [Novel](https://github.com/Ethosa/nodesnim/blob/master/examples/novel)
-4. [Snake game](https://github.com/Ethosa/nodesnim/blob/master/examples/snake)
-5. [Screen saver](https://github.com/Ethosa/nodesnim/blob/master/examples/screensaver)
-6. [Roguelike](https://github.com/Ethosa/nodesnim/blob/nightly/examples/roguelike)
-7. [Sample messenger](https://github.com/Ethosa/nodesnim/blob/nightly/examples/sample_messenger)
+## [Hello world](https://github.com/Ethosa/nodesnim/blob/master/examples/hello_world)
+![Hello world](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/1.png)
+
+## [Calculator](https://github.com/Ethosa/nodesnim/blob/master/examples/calculator)
+![Calculator](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/2.png)
+
+## [Snake game](https://github.com/Ethosa/nodesnim/blob/master/examples/snake)
+![Snake game](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/3.png)
+
+## [Screen saver](https://github.com/Ethosa/nodesnim/blob/master/examples/screensaver)
+![Screen saver](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/4.png)
+
+## [Novel](https://github.com/Ethosa/nodesnim/blob/master/examples/novel)
+![Novel](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/5.png)
+
+## [Roguelike](https://github.com/Ethosa/nodesnim/blob/master/examples/roguelike)
+![Roguelike](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/6.png)
+
+## [Sample messenger](https://github.com/Ethosa/nodesnim/blob/master/examples/sample_messenger)
+![Sample messenger](https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/7.png)

+ 5 - 5
examples/snake/main.nim

@@ -107,16 +107,16 @@ canvas@on_process(self):
     changeScene("GameOverScene")
   # draw
   for i in snake.body:
-    canvas.rect(i.x, i.y, i.x+snake.size.x, i.y+snake.size.y, Color(1f, 1f, 1f))
+    canvas.fillRect(i.x, i.y, snake.size.x, snake.size.y, Color(1f, 1f, 1f))
   # head
-  canvas.rect(
+  canvas.fillRect(
     snake.body[0].x, snake.body[0].y,
-    snake.body[0].x+snake.size.x, snake.body[0].y+snake.size.y,
+    snake.size.x, snake.size.y,
     Color(0xaaccffff'u32))
   # food
-  canvas.rect(
+  canvas.fillRect(
     snake.food.x, snake.food.y,
-    snake.food.x+snake.size.x, snake.food.y+snake.size.y,
+    snake.size.x, snake.size.y,
     Color(0xffccaaff'u32))
   time = 0
 

BIN
screenshots/1.png


BIN
screenshots/2.png


BIN
screenshots/3.png


BIN
screenshots/5.png


BIN
screenshots/6.png


BIN
screenshots/7.png


+ 14 - 0
src/nodesnim/nodes/canvas.nim

@@ -249,6 +249,20 @@ proc rect*(canvas: CanvasRef, x1, y1, x2, y2: GLfloat, color: ColorRef) =
   canvas.renderer.drawRect(rectangle)
   loadGL(canvas)
 
+proc fillRect*(canvas: CanvasRef, x1, y1, x2, y2: GLfloat, color: ColorRef) =
+  ## Draws a line in the canvas.
+  ##
+  ## Arguments:
+  ## - `x1` - first position at X axis.
+  ## - `y1` - first position at Y axis.
+  ## - `x2` - second position at X axis.
+  ## - `y2` - second position at Y axis.
+  ## - `color` - rectangle color.
+  loadColor(color)
+  var rectangle = rect(x1.cint, y1.cint, x2.cint, y2.cint)
+  canvas.renderer.fillRect(rectangle)
+  loadGL(canvas)
+
 proc point*(canvas: CanvasRef, x, y: GLfloat, color: ColorRef) =
   ## Draws a point in the canvas.
   ##

+ 1 - 1
src/nodesnim/nodescontrol/grid_box.nim

@@ -74,7 +74,7 @@ method addChild*(self: GridBoxRef, child: NodeRef) =
   ## - `child`: other node.
   self.children.add(child)
   child.parent = self
-  self.resize(self.rect_size.x, self.rect_size.y)
+  self.resize(self.rect_size.x, self.rect_size.y, true)
 
 
 method draw*(self: GridBoxRef, w, h: GLfloat) =

+ 1 - 1
src/nodesnim/nodescontrol/hbox.nim

@@ -60,7 +60,7 @@ method addChild*(self: HBoxRef, child: NodeRef) =
   ## - `child`: other node.
   self.children.add(child)
   child.parent = self
-  self.resize(self.rect_size.x, self.rect_size.y)
+  self.resize(self.rect_size.x, self.rect_size.y, true)
 
 
 method draw*(self: HBoxRef, w, h: GLfloat) =

+ 1 - 1
src/nodesnim/nodescontrol/vbox.nim

@@ -61,7 +61,7 @@ method addChild*(self: VBoxRef, child: NodeRef) =
   ## - `child`: other node.
   self.children.add(child)
   child.parent = self
-  self.resize(self.rect_size.x, self.rect_size.y)
+  self.resize(self.rect_size.x, self.rect_size.y, true)
 
 
 method draw*(self: VBoxRef, w, h: GLfloat) =