UNPKG

@daign/2d-graphics

Version:

Two dimensional graphics library that implements the daign-2d-pipeline.

63 lines (62 loc) 2.65 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ButtonControl = void 0; var _2d_pipeline_1 = require("@daign/2d-pipeline"); var basic_elements_1 = require("../basic-elements"); /** * Interactive button control which displays a button object. */ var ButtonControl = /** @class */ (function (_super) { __extends(ButtonControl, _super); /** * Constructor. * @param buttonObject - The button object to display. * @param targetTransformation - The transformation matrix of the control object. * @param application - The corresponding application. */ function ButtonControl(buttonObject, targetTransformation) { var _this = _super.call(this) || this; _this.callback = buttonObject.callback; /* The anchor position is used to calculate an offset transformation that gets applied to all * child elements of the button control group. */ var center = buttonObject.anchor.clone().transform(targetTransformation); var offset = new _2d_pipeline_1.MatrixTransform(); offset.matrix.setTranslation(center); _this.transformation.push(offset); _this.baseClass = 'buttonControl'; if (buttonObject.buttonShape) { _this.appendChild(buttonObject.buttonShape); } else { // The default shape to display for a button control. // Center is (0,0) because the whole group is shifted into position. var defaultShape = new basic_elements_1.FixedRadiusCircle(); defaultShape.radius = 15; _this.appendChild(defaultShape); } return _this; } /** * Button click event. */ ButtonControl.prototype.click = function () { this.callback(); }; return ButtonControl; }(basic_elements_1.Group)); exports.ButtonControl = ButtonControl;