Skip to content

Commit

Permalink
[Fixes tleunen#34] Add setTagStyle() and updateTagStyle()
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepichu committed Jan 5, 2017
1 parent 7783dc1 commit ab8aa33
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 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,21 @@ export default class MultiStyleText extends PIXI.Text {
this.dirty = true;
}

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

this.dirty = true;
}

public updateTagStyle(tag: string, style: ExtendedTextStyle): void {
this.assign(this.textStyles[tag], style);
this.dirty = true;
}

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

0 comments on commit ab8aa33

Please sign in to comment.