瀏覽代碼

fix text rendering.

Ethosa 5 年之前
父節點
當前提交
fdebfb6610
共有 3 個文件被更改,包括 43 次插入10 次删除
  1. 15 4
      src/nodesnim/nodescontrol/edittext.nim
  2. 14 3
      src/nodesnim/nodescontrol/label.nim
  3. 14 3
      src/nodesnim/nodescontrol/rich_label.nim

+ 15 - 4
src/nodesnim/nodescontrol/edittext.nim

@@ -90,18 +90,29 @@ method draw*(self: EditTextPtr, w, h: GLfloat) =
     var tx = x + self.rect_size.x*self.text_align.x1 - tw * self.text_align.x2
     for c in line:
       glColor4f(color.r, color.g, color.b, color.a)
-      let cw = self.font.glutBitmapWidth(c.int).float
-      if tx >= x and tx < x + self.rect_size.x - cw and ty <= y and ty > y - self.rect_size.y:
+      let
+        cw = self.font.glutBitmapWidth(c.int).float
+        right =
+          if self.text_align.x2 > 0.9 and self.text_align.x1 > 0.9:
+            1f
+          else:
+            0f
+        bottom =
+          if self.text_align.y2 > 0.9 and self.text_align.y1 > 0.9:
+            1f
+          else:
+            0f
+      if tx >= x and tx < x + self.rect_size.x+right and ty <= y and ty > y - self.rect_size.y+bottom:
         glRasterPos2f(tx, ty)  # set char position
         self.font.glutBitmapCharacter(c.int)  # render char
-        tx += cw
 
         inc char_num
         if char_num == self.caret_position and self.blit_caret and self.blit_time > 1f:
           glColor4f(self.caret_color.r, self.caret_color.g, self.caret_color.b, self.caret_color.a)
-          glRectf(tx, ty, tx+2, ty+self.size)
+          glRectf(tx+cw, ty, tx+cw+2, ty+self.size)
           if self.blit_time > 2f:
             self.blit_time = 0f
+      tx += cw
     inc char_num
     ty -= self.spacing + self.size
 

+ 14 - 3
src/nodesnim/nodescontrol/label.nim

@@ -66,11 +66,22 @@ method draw*(self: LabelPtr, w, h: GLfloat) =
     # Draw text:
     var tx = x + self.rect_size.x*self.text_align.x1 - tw * self.text_align.x2
     for c in line:
-      let cw = self.font.glutBitmapWidth(c.int).float
-      if tx >= x and tx < x + self.rect_size.x - cw and ty <= y and ty > y - self.rect_size.y:
+      let
+        cw = self.font.glutBitmapWidth(c.int).float
+        right =
+          if self.text_align.x2 > 0.9 and self.text_align.x1 > 0.9:
+            1f
+          else:
+            0f
+        bottom =
+          if self.text_align.y2 > 0.9 and self.text_align.y1 > 0.9:
+            1f
+          else:
+            0f
+      if tx >= x and tx < x + self.rect_size.x+right and ty <= y and ty > y - self.rect_size.y+bottom:
         glRasterPos2f(tx, ty)  # set char position
         self.font.glutBitmapCharacter(c.int)  # render char
-        tx += cw
+      tx += cw
     ty -= self.spacing + self.size
 
   # Press

+ 14 - 3
src/nodesnim/nodescontrol/rich_label.nim

@@ -63,12 +63,23 @@ method draw*(self: RichLabelPtr, w, h: GLfloat) =
     # Draw text:
     var tx = x + self.rect_size.x*self.text_align.x1 - tw * self.text_align.x2
     for c in line.chars:
-      let cw = self.font.glutBitmapWidth(c.c.int).float
-      if tx >= x and tx < x + self.rect_size.x - cw and ty <= y and ty > y - self.rect_size.y:
+      let
+        cw = self.font.glutBitmapWidth(c.c.int).float
+        right =
+          if self.text_align.x2 > 0.9 and self.text_align.x1 > 0.9:
+            1f
+          else:
+            0f
+        bottom =
+          if self.text_align.y2 > 0.9 and self.text_align.y1 > 0.9:
+            1f
+          else:
+            0f
+      if tx >= x and tx < x + self.rect_size.x+right and ty <= y and ty > y - self.rect_size.y+bottom:
         glColor4f(c.color.r, c.color.g, c.color.b, c.color.a)
         glRasterPos2f(tx, ty)  # set char position
         self.font.glutBitmapCharacter(c.c.int)  # render char
-        tx += cw
+      tx += cw
     ty -= self.spacing + self.size
 
   # Press