Selaa lähdekoodia

strikethrough and underline in textblock

Patbox 5 vuotta sitten
vanhempi
commit
74bf9e9709
1 muutettua tiedostoa jossa 61 lisäystä ja 4 poistoa
  1. 61 4
      gui/src/2D/controls/textBlock.ts

+ 61 - 4
gui/src/2D/controls/textBlock.ts

@@ -35,10 +35,12 @@ export class TextBlock extends Control {
     private _textVerticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
 
     private _lines: any[];
-    private _resizeToFit: boolean = false;
+	private _resizeToFit: boolean = false;
     private _lineSpacing: ValueAndUnit = new ValueAndUnit(0);
     private _outlineWidth: number = 0;
-    private _outlineColor: string = "white";
+	private _outlineColor: string = "white";
+	private _underline: boolean = false;
+	private _strikethrough: boolean = false;
     /**
     * An event triggered after the text is changed
     */
@@ -196,6 +198,42 @@ export class TextBlock extends Control {
     }
 
     /**
+     * Gets or sets an boolean indicating that text must have underline
+     */
+    public get underline(): boolean {
+        return this._underline;
+    }
+
+    /**
+     * Gets or setsan boolean indicating that text must have underline
+     */
+    public set underline(value: boolean) {
+        if (this._underline === value) {
+            return;
+        }
+        this._underline = value;
+        this._markAsDirty();
+	}
+
+	    /**
+     * Gets or sets an boolean indicating that text must have underline
+     */
+    public get strikethrough(): boolean {
+        return this._strikethrough;
+    }
+
+    /**
+     * Gets or setsan boolean indicating that text must be strikethrough
+     */
+    public set strikethrough(value: boolean) {
+        if (this._strikethrough === value) {
+            return;
+        }
+        this._strikethrough = value;
+        this._markAsDirty();
+	}
+	
+	/**
      * Gets or sets outlineColor of the text to display
      */
     public get outlineColor(): string {
@@ -307,8 +345,27 @@ export class TextBlock extends Control {
         if (this.outlineWidth) {
             context.strokeText(text, this._currentMeasure.left + x, y);
         }
-        context.fillText(text, this._currentMeasure.left + x, y);
-    }
+		context.fillText(text, this._currentMeasure.left + x, y);
+	
+
+		if (this._underline) {
+			context.beginPath();
+			context.lineWidth = Math.round(this.fontSizeInPixels * 0.05);
+			context.moveTo(this._currentMeasure.left + x, y + 3);
+			context.lineTo(this._currentMeasure.left + x + textWidth, y + 3);
+			context.stroke();
+			context.closePath();
+		}
+
+		if (this._strikethrough) {
+			context.beginPath();
+			context.lineWidth = Math.round(this.fontSizeInPixels * 0.05);
+			context.moveTo(this._currentMeasure.left + x, y - this.fontSizeInPixels / 3);
+			context.lineTo(this._currentMeasure.left + x + textWidth, y - this.fontSizeInPixels / 3);
+			context.stroke();
+			context.closePath();
+		}
+	}
 
     /** @hidden */
     public _draw(context: CanvasRenderingContext2D, invalidatedRectangle?: Nullable<Measure>): void {