Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
feat: Add setTagStyle() and deleteTagStyle()
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
bluepichu authored and tleunen committed Jan 16, 2017
1 parent 7783dc1 commit 588f21b
Showing 1 changed file with 50 additions and 26 deletions.
76 changes: 50 additions & 26 deletions pixi-multistyle-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ interface TextData {
}

export default class MultiStyleText extends PIXI.Text {
private static DEFAULT_TAG_STYLE: ExtendedTextStyle = {
align: "left",
breakWords: false,
dropShadow: false,
dropShadowAngle: Math.PI / 6,
dropShadowBlur: 0,
dropShadowColor: "#000000",
dropShadowDistance: 5,
fill: "black",
fillGradientType: PIXI.TEXT_GRADIENT.LINEAR_VERTICAL,
fontFamily: "Arial",
fontSize: 26,
fontStyle: "normal",
fontVariant: "normal",
fontWeight: "normal",
letterSpacing: 0,
lineHeight: 0,
lineJoin: "miter",
miterLimit: 10,
padding: 0,
stroke: "black",
strokeThickness: 0,
textBaseline: "alphabetic",
wordWrap: false,
wordWrapWidth: 100
};

private textStyles: TextStyleSet;

constructor(text: string, styles: TextStyleSet) {
Expand All @@ -36,32 +63,7 @@ export default class MultiStyleText extends PIXI.Text {
public set styles(styles: TextStyleSet) {
this.textStyles = {};

this.textStyles["default"] = {
align: "left",
breakWords: false,
dropShadow: false,
dropShadowAngle: Math.PI / 6,
dropShadowBlur: 0,
dropShadowColor: "#000000",
dropShadowDistance: 5,
fill: "black",
fillGradientType: PIXI.TEXT_GRADIENT.LINEAR_VERTICAL,
fontFamily: "Arial",
fontSize: 26,
fontStyle: "normal",
fontVariant: "normal",
fontWeight: "normal",
letterSpacing: 0,
lineHeight: 0,
lineJoin: "miter",
miterLimit: 10,
padding: 0,
stroke: "black",
strokeThickness: 0,
textBaseline: "alphabetic",
wordWrap: false,
wordWrapWidth: 100
};
this.textStyles["default"] = this.assign({}, MultiStyleText.DEFAULT_TAG_STYLE);

for (let style in styles) {
if (style === "default") {
Expand All @@ -75,6 +77,28 @@ export default class MultiStyleText extends PIXI.Text {
this.dirty = true;
}

public setTagStyle(tag: string, style: ExtendedTextStyle): void {
if (tag in this.textStyles) {
this.assign(this.textStyles[tag], style);
} else {
this.textStyles[tag] = this.assign({}, style);
}

this._style = new PIXI.TextStyle(this.textStyles["default"]);
this.dirty = true;
}

public deleteTagStyle(tag: string): void {
if (tag === "default") {
this.textStyles["default"] = this.assign({}, MultiStyleText.DEFAULT_TAG_STYLE);
} else {
delete this.textStyles[tag];
}

this._style = new PIXI.TextStyle(this.textStyles["default"]);
this.dirty = true;
}

private _getTextDataPerLine (lines: string[]) {
let outputTextData: TextData[][] = [];
let tags = Object.keys(this.textStyles).join("|");
Expand Down

0 comments on commit 588f21b

Please sign in to comment.