UNPKG

@daign/2d-graphics

Version:

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

73 lines (72 loc) 3.17 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.Application = void 0; var group_1 = require("../basic-elements/group"); var controlLayer_1 = require("./controlLayer"); var interactiveViewport_1 = require("./interactiveViewport"); var selectionManager_1 = require("./selectionManager"); var viewport_1 = require("./viewport"); var updateManager_1 = require("./updateManager"); /** * Application consisting of a drawing layer and a control layer. */ var Application = /** @class */ (function (_super) { __extends(Application, _super); /** * Constructor. * @param context - The target context. * @param interactive - Whether the application is responding to user actions. Default false. */ function Application(context, interactive) { if (interactive === void 0) { interactive = false; } var _this = _super.call(this) || this; /* The control layer. It lies above the drawing layer and is not affected by zooming and panning * of the viewport. So its coordinates are always in screen coordinates. */ _this.controlLayer = null; _this.selectionManager = new selectionManager_1.SelectionManager(); _this.updateManager = new updateManager_1.UpdateManager(); if (interactive) { // If interactive then use the InteractiveViewPort and ControlLayer. _this.drawingLayer = new interactiveViewport_1.InteractiveViewport(context, _this); _this.appendChild(_this.drawingLayer); _this.controlLayer = new controlLayer_1.ControlLayer(_this); _this.appendChild(_this.controlLayer); } else { // If not interactive then use the normal Viewport and no ControlLayer. _this.drawingLayer = new viewport_1.Viewport(context, _this); _this.appendChild(_this.drawingLayer); } return _this; } /** * Zoom and pan content to fit viewport. * @param margin - The margin to leave around the content. Optional. */ Application.prototype.fitToContent = function (margin) { this.drawingLayer.fitToContent(margin); }; /** * Redraw and render the application. */ Application.prototype.redraw = function () { this.updateManager.redraw(); }; return Application; }(group_1.Group)); exports.Application = Application;