Ethosa 3 år sedan
förälder
incheckning
44460587bb

+ 11 - 8
README.md

@@ -1,5 +1,5 @@
 <div align="center">
-  <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/icon.svg" width="240">
+  <img src="https://github.com/Ethosa/nodesnim/blob/nightly/icon.svg" width="240">
 
 The Nim GUI/2D framework based on OpenGL and SDL2.
 
@@ -103,25 +103,28 @@ Also use [`niminst`](https://github.com/nim-lang/niminst) tool for generate an i
 ## Screenshots
 <div align="center">
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/hello_world">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/1.png" width="380" height="220" alt="Hello world example">
+    <img src="https://user-images.githubusercontent.com/49402667/138453889-ea538f86-2fc4-4947-843f-ca100561b05d.png" width="380" height="220" alt="Hello world example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/calculator">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/2.png" width="380" height="220" alt="Calculator example">
+    <img src="https://user-images.githubusercontent.com/49402667/138453360-6b701b6a-8695-4ace-bf9f-25d5ae8c68c2.png" width="380" height="220" alt="Calculator example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/snake">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/3.png" width="380" height="220" alt="Snake game example">
+    <img src="https://user-images.githubusercontent.com/49402667/138456143-292a5b73-7a52-4d29-9769-1c8101db9f85.png" width="380" height="220" alt="Snake game example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/screensaver">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/4.png" width="380" height="220" alt="Screensaver example">
+    <img src="https://user-images.githubusercontent.com/49402667/138455275-3df817ae-275d-4164-afc1-92fbdbbb4a6c.png" width="380" height="220" alt="Screensaver example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/novel">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/5.png" width="380" height="220" alt="Novel game example">
+    <img src="https://user-images.githubusercontent.com/49402667/138454518-376b40ba-44d0-458a-9b2b-48a5ea53ff64.png" width="380" height="220" alt="Novel game example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/roguelike">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/6.png" width="380" height="220" alt="Roguelike game example">
+    <img src="https://user-images.githubusercontent.com/49402667/138454722-e2b2766d-29cd-412a-92d2-29393d442775.png" width="380" height="220" alt="Roguelike game example">
   </a>
   <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/sample_messenger">
-    <img src="https://github.com/Ethosa/nodesnim/blob/nightly/screenshots/7.png" width="240" height="480" alt="sample messenger">
+    <img src="https://user-images.githubusercontent.com/49402667/138455176-d38ea0b3-274d-41c6-b877-2a9be39a7b90.png" width="240" height="480" alt="sample messenger">
+  </a>
+  <a href="https://github.com/Ethosa/nodesnim/tree/nightly/examples/calculator">
+    <img src="https://user-images.githubusercontent.com/49402667/138453719-0b4d50a9-b4a3-40c5-b017-1e0e0dd4892b.png" width="360" height="480" alt="Material Calculator example">
   </a>
 </div>
 

+ 0 - 0
screenshots/icon.svg → icon.svg


BIN
screenshots/1.png


BIN
screenshots/2.png


BIN
screenshots/3.png


BIN
screenshots/4.png


BIN
screenshots/5.png


BIN
screenshots/6.png


BIN
screenshots/7.png


+ 3 - 3
src/nodesnim/core/font.nim

@@ -261,9 +261,9 @@ proc getCharUnderPoint*(text: StyleText, global_pos, text_pos: Vector2Obj,
                         text_align: AnchorObj = Anchor(0, 0, 0, 0)): tuple[c: StyleUnicode, pos: uint32] =
   let pos = text.getPosUnderPoint(global_pos, text_pos, text_align)
   if pos > 0:
-    (c: text.chars[pos-1], pos: pos-1)
-  else:
-    (c: text.chars[pos], pos: pos)
+    return (c: text.chars[pos-1], pos: pos-1)
+  elif text.chars.len > 0:
+    return (c: text.chars[pos], pos: pos)
 
 
 # ------ Render ------ #

+ 3 - 3
src/nodesnim/core/polygon2.nim

@@ -32,7 +32,7 @@ proc Polygon2*(pnts: var seq[Vector2Obj]): Polygon2Obj =
   result = pnts[0..^1]
 
 
-proc contains*(self: Polygon2Obj, x, y: float): bool =
+proc hasPoint*(self: Polygon2Obj, x, y: float): bool =
   ## Returns true, if point `x`, `y` in the Polygon2.
   result = false
   var next = 1
@@ -47,9 +47,9 @@ proc contains*(self: Polygon2Obj, x, y: float): bool =
     if ((a.y >= y and b.y < y) or (a.y < y and b.y >= y)) and (x < (b.x-a.x)*(y-a.y) / (b.y-a.y)+a.x):
       result = not result
 
-proc contains*(self: Polygon2Obj, vec2: Vector2Obj): bool {.inline.} =
+proc hasPoint*(self: Polygon2Obj, vec2: Vector2Obj): bool {.inline.} =
   ## Returns true, if point `vec2` in the Polygon2.
-  self.contains(vec2.x, vec2.y)
+  self.hasPoint(vec2.x, vec2.y)
 
 
 proc intersects*(self, other: Polygon2Obj): bool =

+ 1 - 1
src/nodesnim/core/scene_builder.nim

@@ -30,7 +30,7 @@ proc addNode(level: var seq[NimNode], code: NimNode): NimNode {.compileTime.} =
             else:
               discard
 
-          if line[1][1].kind == nnkObjConstr:  # - Node node(...)
+          if line[1][1].kind in [nnkPar, nnkCall, nnkObjConstr]:  # - Node node(...)
             level.add(line[1][1][0])
             let nodes = addNode(level, line[1][1])
             for i in nodes.children():

+ 11 - 9
src/nodesnim/nodescontrol/edittext.nim

@@ -65,6 +65,7 @@ proc EditText*(name: string = "EditText", hint: string = "Edit text ..."): EditT
 
 method draw*(self: EditTextRef, w, h: Glfloat) =
   ## This method uses for redraw Label object.
+  {.warning[LockLevel]: off.}
   procCall self.ControlRef.draw(w, h)
   let
     x = -w/2 + self.global_position.x
@@ -84,7 +85,7 @@ method draw*(self: EditTextRef, w, h: Glfloat) =
     self.blink_time = BLINK_TIME
     self.is_blink = not self.is_blink
 
-  if self.text.chars.len() == 0:
+  if self.text.chars.len == 0:
     self.hint.renderTo(Vector2(x+self.padding.x1, y-self.padding.y1), self.rect_size, self.text_align)
   else:
     self.text.renderTo(Vector2(x+self.padding.x1, y-self.padding.y1), self.rect_size, self.text_align)
@@ -92,23 +93,24 @@ method draw*(self: EditTextRef, w, h: Glfloat) =
   for line in lines:
     discard self.text.font.sizeUtf8(($line).cstring, addr w, addr h)
     x1 = self.rect_min_size.x*self.text_align.x1 - w.Glfloat*self.text_align.x2
+    let coords = [xalign+x1, yalign-y1]
     for c in line.chars:
       discard self.text.font.sizeUtf8(($c).cstring, addr w, addr h)
       if self.is_select and (i >= self.caret_pos[0] and i < self.caret_pos[1]) or (i >= self.caret_pos[1] and i < self.caret_pos[0]):
         glColor4f(0.4, 0.4, 0.7, 0.5)
         glBegin(GL_QUADS)
-        glVertex2f(xalign+x1, yalign-y1)
-        glVertex2f(xalign+x1+w.Glfloat, yalign-y1)
-        glVertex2f(xalign+x1+w.Glfloat, yalign-y1-h.Glfloat)
-        glVertex2f(xalign+x1, yalign-y1-h.Glfloat)
+        glVertex2f(coords[0], coords[1])
+        glVertex2f(coords[0]+w.Glfloat, coords[1])
+        glVertex2f(coords[0]+w.Glfloat, coords[1]-h.Glfloat)
+        glVertex2f(coords[0], coords[1]-h.Glfloat)
         glEnd()
       if self.is_blink and i == self.caret_pos[0]:
         glColor4f(self.caret_color.r, self.caret_color.g, self.caret_color.b, self.caret_color.a)
         glBegin(GL_QUADS)
-        glVertex2f(xalign+x1, yalign-y1)
-        glVertex2f(xalign+x1+BLINK_WIDTH, yalign-y1)
-        glVertex2f(xalign+x1+BLINK_WIDTH, yalign-y1-h.Glfloat)
-        glVertex2f(xalign+x1, yalign-y1-h.Glfloat)
+        glVertex2f(coords[0], coords[1])
+        glVertex2f(coords[0]+BLINK_WIDTH, coords[1])
+        glVertex2f(coords[0]+BLINK_WIDTH, coords[1]-h.Glfloat)
+        glVertex2f(coords[0], coords[1]-h.Glfloat)
         glEnd()
       x1 += w.float
       inc i

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

@@ -80,7 +80,7 @@ method handle*(self: LabelRef, event: InputEvent, mouse_on: var NodeRef) =
       self.getGlobalMousePosition(), self.global_position + self.rect_size/2 - self.text.getTextSize()/2,
       self.text_align)
 
-    if c.is_url:
+    if not c.isNil() and c.is_url:
       var (i, j) = (pos.int, pos.int)
       while i - 1 > 0 and self.text.chars[i - 1].is_url:
         dec i