UNPKG

6.06 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var Module_1 = require("./../Module");
14var Tool_1 = require("./../Tool");
15var index_1 = require("./../index");
16var Text = (function (_super) {
17 __extends(Text, _super);
18 /* CONSTRUCTOR */
19 function Text() {
20 var _this = _super.call(this) || this;
21 /**
22 * The last offset in x axis provided by the centering property
23 * @private
24 */
25 _this._centerOffsetX = 0;
26 /**
27 * The last offset in y axis provided by the centering property
28 * @private
29 */
30 _this._centerOffsetY = 0;
31 _this.setProps({
32 text: "",
33 align: "left",
34 breakWords: false,
35 dropShadow: false,
36 dropShadowAlpha: 1,
37 dropShadowAngle: 80,
38 dropShadowColor: Tool_1.Color.black,
39 dropShadowDistance: 0,
40 dropShadowBlur: 2,
41 fill: Tool_1.Color.black,
42 fontFamily: "Verdana",
43 fontSize: 20,
44 fontStyle: "normal",
45 fontVariant: "normal",
46 fontWeight: "normal",
47 letterSpacing: 0,
48 lineHeight: null,
49 padding: 0,
50 stroke: Tool_1.Color.black,
51 strokeThickness: 0,
52 textBaseline: "alphabetic",
53 wordWrap: false,
54 wordWrapWidth: 100
55 });
56 _this.container = new index_1.PIXI.Text(_this.props.text);
57 _this.connect(_this.signals.propChange, "centered", _this.onCenteredChange.bind(_this))
58 .connect(_this.signals.propChange, "text", function () { return (_this.container.text = _this.props.text); })
59 .connect(_this.signals.propChange, ["align", "breakWords", "dropShadow", "dropShadowAlpha", "dropShadowAngle", "dropShadowColor", "dropShadowDistance", "fill", "fontFamily", "fontSize", "fontStyle", "fontVariant",
60 "fontWeight", "letterSpacing", "lineHeight", "padding", "stroke", "strokeThickness", "textBaseline", "wordWrap", "wordWrapWidth"], _this._onStyleChange.bind(_this));
61 return _this;
62 }
63 Text.prototype.update = function (tick) {
64 _super.prototype.update.call(this, tick);
65 if (this.container) {
66 this.props.width = this.container.width;
67 this.props.height = this.container.height;
68 }
69 };
70 /* EVENTS */
71 /**
72 * When "width" or "height" properties has changed
73 */
74 Text.prototype.onSizeChange = function () {
75 _super.prototype.onSizeChange.call(this);
76 this.onCenteredChange();
77 /*
78 if (this.props.centered) {
79 console.log("centered");
80 const midWidth = this.props.width / 2,
81 midHeight = this.props.height / 2;
82
83 this.props.x = this.props.x - midWidth;
84 this.props.y = this.props.y - midHeight;
85 this._centerOffsetX = midWidth;
86 this._centerOffsetY = midHeight;
87 }
88 */
89 };
90 /**
91 * When "centered" property has changed
92 */
93 Text.prototype.onCenteredChange = function () {
94 if (this.props.centered) {
95 this.props.x -= this.props.width / 2;
96 this.props.y -= this.props.height / 2;
97 }
98 else if (!this.props.centered && this.last.centered) {
99 this.props.x += this.props.width / 2;
100 this.props.y += this.props.height / 2;
101 }
102 };
103 /**
104 * When a font style property has changed
105 */
106 Text.prototype._onStyleChange = function () {
107 var _a = this.props, align = _a.align, breakWords = _a.breakWords, dropShadow = _a.dropShadow, dropShadowAlpha = _a.dropShadowAlpha, dropShadowAngle = _a.dropShadowAngle, dropShadowBlur = _a.dropShadowBlur, dropShadowColor = _a.dropShadowColor, dropShadowDistance = _a.dropShadowDistance, fill = _a.fill, fontFamily = _a.fontFamily, fontSize = _a.fontSize, fontStyle = _a.fontStyle, fontVariant = _a.fontVariant, fontWeight = _a.fontWeight, letterSpacing = _a.letterSpacing, lineHeight = _a.lineHeight, padding = _a.padding, stroke = _a.stroke, strokeThickness = _a.strokeThickness, textBaseline = _a.textBaseline, wordWrap = _a.wordWrap, wordWrapWidth = _a.wordWrapWidth;
108 this.container.style.align = align;
109 this.container.style.breakWords = breakWords;
110 this.container.style.dropShadow = dropShadow;
111 this.container.style.dropShadowAlpha = dropShadowAlpha;
112 this.container.style.dropShadowAngle = Tool_1.Util.toRadians(dropShadowAngle);
113 this.container.style.dropShadowColor = dropShadowColor;
114 this.container.style.dropShadowBlur = dropShadowBlur;
115 this.container.style.dropShadowDistance = dropShadowDistance;
116 this.container.style.fill = fill;
117 this.container.style.fontFamily = fontFamily;
118 this.container.style.fontSize = fontSize;
119 this.container.style.fontStyle = fontStyle;
120 this.container.style.fontVariant = fontVariant;
121 this.container.style.fontWeight = fontWeight;
122 this.container.style.letterSpacing = letterSpacing;
123 this.container.style.lineHeight = lineHeight;
124 this.container.style.padding = padding;
125 this.container.style.stroke = stroke;
126 this.container.style.strokeThickness = strokeThickness;
127 this.container.style.textBaseline = textBaseline;
128 this.container.style.wordWrap = wordWrap;
129 this.container.style.wordWrapWidth = wordWrapWidth;
130 };
131 return Text;
132}(Module_1.Module));
133exports.Text = Text;