Jelajahi Sumber

Change text drawing starting location to the right place in case of multi-line

nockawa 9 tahun lalu
induk
melakukan
4a981f2937
1 mengubah file dengan 4 tambahan dan 1 penghapusan
  1. 4 1
      src/Canvas2d/babylon.text2d.ts

+ 4 - 1
src/Canvas2d/babylon.text2d.ts

@@ -180,8 +180,9 @@
         public get textSize(): Size {
             if (!this._textSize && this.owner) {
                 let newSize = this.fontTexture.measureText(this._text, this._tabulationSize);
-                if (newSize !== this._textSize) {
+                if (!newSize.equals(this._textSize)) {
                     this.onPrimitivePropertyDirty(Prim2DBase.sizeProperty.flagId);
+                    this._positioningDirty();
                 }
                 this._textSize = newSize;
             }
@@ -353,6 +354,8 @@
                 let texture = this.fontTexture;
                 let ts = texture.getSize();
                 let offset = Vector2.Zero();
+                let lh = this.fontTexture.lineHeight;
+                offset.y = ((this.textSize.height/lh)-1) * lh;  // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
                 let charxpos = 0;
                 d.dataElementCount = this._charCount;
                 d.curElement = 0;