UNPKG

3.12 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 Graphic_1 = require("./../Graphic");
14var Tool_1 = require("./../Tool");
15var Dialog = (function (_super) {
16 __extends(Dialog, _super);
17 /* LIFECYCLE */
18 function Dialog() {
19 var _this = _super.call(this) || this;
20 _this.setProps({
21 offsetX: 0,
22 offsetY: 0
23 });
24 _this.signals.propChange.bind(["width", "height"], _this.onLabelSizeChange.bind(_this));
25 return _this;
26 }
27 Dialog.prototype.initialize = function (props) {
28 var _this = this;
29 _super.prototype.initialize.call(this, props);
30 this.shape("shape", {
31 width: this.props.width,
32 height: this.props.height,
33 stroke: Tool_1.Color.cyan400,
34 strokeThickness: 2,
35 fill: Tool_1.Color.black,
36 fillAlpha: 0.7
37 }).text("label", function (label) {
38 label.signals.propChange.bind("width", _this.onLabelSizeChange.bind(_this));
39 return {
40 fill: Tool_1.Color.white,
41 y: 10
42 };
43 });
44 this.context.scene.signals.propChange.bind(["width", "height"], this.onScreenSizeChange.bind(this));
45 this.onScreenSizeChange();
46 };
47 /* EVENTS */
48 /**
49 * When the label width attributes has changed
50 */
51 Dialog.prototype.onLabelSizeChange = function () {
52 var _this = this;
53 this.text("label", function (label) {
54 return {
55 x: (_this.props.width / 2) - (label.props.width / 2)
56 };
57 });
58 };
59 Dialog.prototype.onScreenSizeChange = function () {
60 var scene = this.context.scene, _a = scene.props, width = _a.width, height = _a.height, _b = this.props, centerScreen = _b.centerScreen, fullScreen = _b.fullScreen, offsetX = _b.offsetX, offsetY = _b.offsetY;
61 if (!fullScreen && !centerScreen) {
62 return null;
63 }
64 var pos = this.getRelativePosition();
65 if (fullScreen) {
66 this.props.x = pos.x + offsetX;
67 this.props.y = pos.y + offsetY;
68 this.props.width = width;
69 this.props.height = height;
70 this.shape("shape", {
71 width: width,
72 height: height
73 });
74 }
75 else if (centerScreen) {
76 this.props.x = pos.x + offsetX + (width / 2) - (this.props.width / 2);
77 this.props.y = pos.y + offsetY + (height / 2) - (this.props.height / 2);
78 }
79 };
80 return Dialog;
81}(Graphic_1.Graphic));
82exports.Dialog = Dialog;