UNPKG

@daign/2d-graphics

Version:

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

55 lines (54 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UpdateManager = void 0; var observable_1 = require("@daign/observable"); /** * Class that manages the steps to update and redraw the graphic. */ var UpdateManager = /** @class */ (function () { /** * Constructor. */ function UpdateManager() { // Event that other components can use to get informed about a redraw. this.redrawEvent = new observable_1.EventEmitter(); // The event that lets the control layer know when to redraw the controls. this.redrawControlsSignal = new observable_1.UnicastEventEmitter(); // The event that the render function subscribes to. this.renderSignal = new observable_1.UnicastEventEmitter(); } /** * Set a callback that gets informed when a redraw event was started. * @param callback - The callback that will be called when a redraw event was started. */ UpdateManager.prototype.subscribeToRedrawEvent = function (callback) { this.redrawEvent.subscribeToChanges(callback); }; /** * Set the callback that redraws the control layer. * @param callback - The callback that redraws the control layer. */ UpdateManager.prototype.setRedrawControlsFunction = function (callback) { this.redrawControlsSignal.setObserver(callback); }; /** * Set the callback that renders the graphic. * @param callback - The callback that renders the graphic. */ UpdateManager.prototype.setRenderFunction = function (callback) { this.renderSignal.setObserver(callback); }; /** * Redraw and render the application. */ UpdateManager.prototype.redraw = function () { // Notify components that want to be informed about a redraw event. this.redrawEvent.emit(); // Redraw the controls. this.redrawControlsSignal.emit(); // Render the graphic. this.renderSignal.emit(); }; return UpdateManager; }()); exports.UpdateManager = UpdateManager;