(function () { var ns = $.namespace("pskl.selection"); ns.SelectionManager = function (piskelController) { this.piskelController = piskelController; this.currentSelection = null; }; ns.SelectionManager.prototype.init = function () { $.subscribe(Events.SELECTION_CREATED, $.proxy(this.onSelectionCreated_, this)); $.subscribe(Events.SELECTION_DISMISSED, $.proxy(this.onSelectionDismissed_, this)); $.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this)); pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this)); pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this)); $.subscribe(Events.TOOL_SELECTED, $.proxy(this.onToolSelected_, this)); }; /** * @private */ ns.SelectionManager.prototype.cleanSelection_ = function() { if(this.currentSelection) { this.currentSelection.reset(); } }; /** * @private */ ns.SelectionManager.prototype.onToolSelected_ = function(evt, tool) { var isSelectionTool = tool instanceof pskl.drawingtools.BaseSelect; if(!isSelectionTool) { this.cleanSelection_(); } }; /** * @private */ ns.SelectionManager.prototype.onSelectionDismissed_ = function(evt) { this.cleanSelection_(); }; ns.SelectionManager.prototype.cut = function() { if(this.currentSelection) { // Put cut target into the selection: this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame()); var pixels = this.currentSelection.pixels; var currentFrame = this.piskelController.getCurrentFrame(); for(var i=0, l=pixels.length; i