From 697f270d786474fc1d8ed651d903ee4c960d071d Mon Sep 17 00:00:00 2001 From: Vince Date: Sat, 15 Sep 2012 00:17:08 +0200 Subject: [PATCH] Injecting framesheet model in SelectionManager singleton --- js/piskel.js | 2 +- js/selection/SelectionManager.js | 35 ++++++++++---------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/js/piskel.js b/js/piskel.js index ab587525..0622825f 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -62,7 +62,7 @@ $.namespace("pskl"); // All listerners will be hook in a first step, then all event triggering inits will be called // in a second batch. this.selectionManager = - new pskl.selection.SelectionManager(this.drawingController.overlayFrame); + new pskl.selection.SelectionManager(frameSheet, this.drawingController.overlayFrame); frameSheet.setCurrentFrameIndex(0); diff --git a/js/selection/SelectionManager.js b/js/selection/SelectionManager.js index 7ad01567..8cb7a2cc 100644 --- a/js/selection/SelectionManager.js +++ b/js/selection/SelectionManager.js @@ -2,16 +2,13 @@ var ns = $.namespace("pskl.selection"); - ns.SelectionManager = function (overlayFrame) { + ns.SelectionManager = function (framesheet, overlayFrame) { this.framesheet = framesheet; this.overlayFrame = overlayFrame; this.currentSelection = null; - this.currentFrame = null; - $.subscribe(Events.CURRENT_FRAME_SET, $.proxy(this.onCurrentFrameChanged_, this)); - $.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)); @@ -33,23 +30,11 @@ this.overlayFrame.clear(); }; - /** - * @private - */ - ns.SelectionManager.prototype.onCurrentFrameChanged_ = function(evt, currentFrame) { - if(currentFrame) { - this.currentFrame = currentFrame; - } - else { - throw "Bad current frame set in SelectionManager"; - } - }; - /** * @private */ ns.SelectionManager.prototype.onToolSelected_ = function(evt, tool) { - var isSelectionTool = (tool instanceof pskl.drawingtools.RectangleSelect) || (tool instanceof pskl.drawingtools.ShapeSelect); + var isSelectionTool = tool instanceof pskl.drawingtools.BaseSelect; if(!isSelectionTool) { this.cleanSelection_(); } @@ -66,14 +51,15 @@ * @private */ ns.SelectionManager.prototype.onCut_ = function(evt) { - if(this.currentSelection && this.currentFrame) { + if(this.currentSelection) { // Put cut target into the selection: - this.currentSelection.fillSelectionFromFrame(this.currentFrame); + this.currentSelection.fillSelectionFromFrame(this.framesheet.getCurrentFrame()); var pixels = this.currentSelection.pixels; + var currentFrame = this.framesheet.getCurrentFrame(); for(var i=0, l=pixels.length; i