UNPKG

@daign/2d-graphics

Version:

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

112 lines (111 loc) 4.8 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.ControlObject = void 0; var basic_elements_1 = require("../basic-elements"); var buttonControl_1 = require("./buttonControl"); var controlPoint_1 = require("./controlPoint"); /** * Abstract class for drawing elements that are defined by interactive control points. */ var ControlObject = /** @class */ (function (_super) { __extends(ControlObject, _super); /** * Constructor. */ function ControlObject() { var _this = _super.call(this) || this; // Modifiers that restrict drawing actions. _this.controlModifier = null; // Array of control guide objects for displaying custom drawing elements on the control layer. _this.controlGuides = []; // Array of custom shapes to be used for control points. _this.controlPointShapes = []; // Array of button objects. _this.buttons = []; _this.redraw(); // Redraw method is automatically called when the points array changes. _this.points.subscribeToChanges(function () { _this.redraw(); }); return _this; } /** * The redraw method to extend which should create the shape of the element. */ ControlObject.prototype.redraw = function () { this.clearChildren(); this.buttons = []; }; ; /** * Construct the shapes to be displayed on the control layer. * @param activePoint - The selected point of the active object. * @param application - The corresponding application. * @returns A node containing the content for the control layer. */ ControlObject.prototype.redrawControlObjects = function (activePoint, application) { var _this = this; var group = new basic_elements_1.Group(); /* TODO: To enable simultaneous rendering into multiple views get the correct presentation node * that corresponds to the application's view. */ var transformation = this.presentationNodes[0].projectNodeToView; // Add the control guide objects. this.controlGuides.forEach(function (controlGuide) { var node = controlGuide.redraw(_this, activePoint); if (node) { group.appendChild(node); } }); // Add the control points. this.points.iterate(function (point, index) { var controlPoint = new controlPoint_1.ControlPoint(point, transformation, application, _this, index, _this.controlPointShapes[index]); group.appendChild(controlPoint); if (point === activePoint) { controlPoint.addClass('active'); } }); // Add the button controls. this.buttons.forEach(function (button) { var buttonControl = new buttonControl_1.ButtonControl(button, transformation); group.appendChild(buttonControl); }); return group; }; /** * Get a deep copy of the control points. * The ControlPoint uses this method for the ControlModifiers. The method will be overwritten by * ControlObjects that extend the Vector2 class with additional properties. * @returns A deep copy of the control points. */ ControlObject.prototype.getDeepCopyOfPoints = function () { return this.points.cloneDeep().elements; }; /** * Copy updated coordinates back to the control points of this control. * The ControlPoint uses this method for the ControlModifiers. The method will be overwritten by * ControlObjects that extend the Vector2 class with additional properties. * @param updatedPoints - The new coordinates to apply. */ ControlObject.prototype.writeUpdatesToPoints = function (updatedPoints) { this.points.iterate(function (element, index) { element.copy(updatedPoints[index]); }); }; return ControlObject; }(basic_elements_1.Group)); exports.ControlObject = ControlObject;