瀏覽代碼

small update.

SakiKawasaki 4 年之前
父節點
當前提交
04230c0e55

+ 6 - 0
src/nodesnim/core/input.nim

@@ -89,6 +89,12 @@ const
   K_HOME* = 106
   K_END* = 107
   K_INSERT* = 108
+  K_SHIFT* = 112
+  K_RIGHT_SHIFT* = 113
+  K_CTRL* = 114
+  K_RIGHT_CTRL* = 115
+  K_ALT* = 116
+  K_RIGHT_ALT* = 117
   K_DELETE* = 127
 
 

+ 10 - 0
src/nodesnim/nodes2d/collision_shape2d.nim

@@ -70,6 +70,7 @@ method setShapeTypeRect*(self: CollisionShape2DPtr) {.base.} =
   ## Changes shape type to `circle`.
   self.shape_type = COLLISION_SHAPE_2D_RECTANGLE
 
+
 method setShapeTypeCircle*(self: CollisionShape2DPtr, cx, cy, radius: float) {.base.} =
   ## Changes shape type to `rectangle`.
   ##
@@ -82,6 +83,7 @@ method setShapeTypeCircle*(self: CollisionShape2DPtr, cx, cy, radius: float) {.b
   self.y1 = cy
   self.radius = radius
 
+
 method setShapeTypePolygon*(self: CollisionShape2DPtr, positions: varargs[Vector2Ref]) {.base.} =
   ## Changes shape type to `polygon`.
   ##
@@ -95,6 +97,7 @@ method setShapeTypePolygon*(self: CollisionShape2DPtr, positions: varargs[Vector
   for i in positions:
     self.polygon.add(i)
 
+
 method draw*(self: CollisionShape2DPtr, w, h: GLfloat) =
   ## this method uses in the `window.nim`.
   {.warning[LockLevel]: off.}
@@ -133,15 +136,18 @@ method draw*(self: CollisionShape2DPtr, w, h: GLfloat) =
         glVertex3f(x + vec2.x, y - vec2.y, self.z_index_global)
       glEnd()
 
+
 method duplicate*(self: CollisionShape2DPtr, obj: var CollisionShape2DObj): CollisionShape2DPtr {.base.} =
   ## Duplicates CollisionShape2D object and create a new CollisionShape2D pointer.
   obj = self[]
   obj.addr
 
+
 method getGlobalMousePosition*(self: CollisionShape2DPtr): Vector2Ref {.inline.} =
   ## Returns mouse position.
   Vector2Ref(x: last_event.x, y: last_event.y)
 
+
 method isCollide*(self: CollisionShape2DPtr, x, y: float): bool =
   ## Checks collision with point.
   ##
@@ -200,14 +206,18 @@ method isCollide*(self: CollisionShape2DPtr, vec2: Vector2Ref): bool =
       if ((a.y >= vec2.y and b.y < vec2.y) or (a.y < vec2.y and b.y >= vec2.y)) and (vec2.x < (b.x-a.x)*(vec2.y-a.y) / (b.y-a.y)+a.x):
         result = not result
 
+
 method isCollide*(self, other: CollisionShape2DPtr): bool {.base.} =
   ## Checks collision with other CollisionShape2D object.
   self.calcGlobalPosition()
   other.calcGlobalPosition()
+
+  # Return false, if collision shape is disabled.
   if self.disable:
     return false
   elif other.disable:
     return false
+
   case self.shape_type
   of COLLISION_SHAPE_2D_RECTANGLE:
     case other.shape_type:

+ 3 - 0
src/nodesnim/nodes2d/kinematic_body2d.nim

@@ -112,6 +112,9 @@ method isCollide*(self: KinematicBody2DPtr): bool {.base.} =
 
 method moveAndCollide*(self: KinematicBody2DPtr, vel: Vector2Ref) {.base.} =
   ## Moves and checks collision
+  ##
+  ## Arguments:
+  ## - `vel` is a velocity vector.
   if self.has_collision:
     var scene = self.getRootNode()
     self.move(vel)

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

@@ -182,7 +182,7 @@ method getWordPositionUnderMouse*(self: EditTextPtr): tuple[startpos, endpos: in
 method getWordUnderMouse*(self: EditTextPtr): string {.base.} =
   ## Returns words under mouse.
   let (s, e) = self.getWordPositionUnderMouse()
-  if self.text.len() > 0:
+  if self.text.len() > 0 and s > -1:
     return self.text[s..e]
 
 

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

@@ -176,7 +176,7 @@ method getWordPositionUnderMouse*(self: RichEditTextPtr): tuple[startpos, endpos
 method getWordUnderMouse*(self: RichEditTextPtr): ColorTextRef {.base.} =
   ## Returns words under mouse.
   let (s, e) = self.getWordPositionUnderMouse()
-  if self.text.len() > 0:
+  if self.text.len() > 0 and s > -1:
     return self.text[s..e]
 
 

+ 2 - 1
src/nodesnim/window.nim

@@ -11,7 +11,8 @@ import
   nodes/scene,
 
   environment,
-  os
+  os,
+  unicode
 
 when defined(debug):
   import logging