Injecting framesheet model in SelectionManager singleton

This commit is contained in:
Vince 2012-09-15 00:17:08 +02:00
parent 7613bb18b3
commit 697f270d78
2 changed files with 12 additions and 25 deletions

View File

@ -62,7 +62,7 @@ $.namespace("pskl");
// All listerners will be hook in a first step, then all event triggering inits will be called // All listerners will be hook in a first step, then all event triggering inits will be called
// in a second batch. // in a second batch.
this.selectionManager = this.selectionManager =
new pskl.selection.SelectionManager(this.drawingController.overlayFrame); new pskl.selection.SelectionManager(frameSheet, this.drawingController.overlayFrame);
frameSheet.setCurrentFrameIndex(0); frameSheet.setCurrentFrameIndex(0);

View File

@ -2,15 +2,12 @@
var ns = $.namespace("pskl.selection"); var ns = $.namespace("pskl.selection");
ns.SelectionManager = function (overlayFrame) { ns.SelectionManager = function (framesheet, overlayFrame) {
this.framesheet = framesheet; this.framesheet = framesheet;
this.overlayFrame = overlayFrame; this.overlayFrame = overlayFrame;
this.currentSelection = null; 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_CREATED, $.proxy(this.onSelectionCreated_, this));
$.subscribe(Events.SELECTION_DISMISSED, $.proxy(this.onSelectionDismissed_, this)); $.subscribe(Events.SELECTION_DISMISSED, $.proxy(this.onSelectionDismissed_, this));
@ -33,23 +30,11 @@
this.overlayFrame.clear(); 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 * @private
*/ */
ns.SelectionManager.prototype.onToolSelected_ = function(evt, tool) { 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) { if(!isSelectionTool) {
this.cleanSelection_(); this.cleanSelection_();
} }
@ -66,14 +51,15 @@
* @private * @private
*/ */
ns.SelectionManager.prototype.onCut_ = function(evt) { ns.SelectionManager.prototype.onCut_ = function(evt) {
if(this.currentSelection && this.currentFrame) { if(this.currentSelection) {
// Put cut target into the selection: // Put cut target into the selection:
this.currentSelection.fillSelectionFromFrame(this.currentFrame); this.currentSelection.fillSelectionFromFrame(this.framesheet.getCurrentFrame());
var pixels = this.currentSelection.pixels; var pixels = this.currentSelection.pixels;
var currentFrame = this.framesheet.getCurrentFrame();
for(var i=0, l=pixels.length; i<l; i++) { for(var i=0, l=pixels.length; i<l; i++) {
try { try {
this.currentFrame.setPixel(pixels[i].col, pixels[i].row, Constants.TRANSPARENT_COLOR); currentFrame.setPixel(pixels[i].col, pixels[i].row, Constants.TRANSPARENT_COLOR);
} }
catch(e) { catch(e) {
// Catchng out of frame's bound pixels without testing // Catchng out of frame's bound pixels without testing
@ -86,11 +72,12 @@
}; };
ns.SelectionManager.prototype.onPaste_ = function(evt) { ns.SelectionManager.prototype.onPaste_ = function(evt) {
if(this.currentSelection && this.currentFrame) { if(this.currentSelection) {
var pixels = this.currentSelection.pixels; var pixels = this.currentSelection.pixels;
var currentFrame = this.framesheet.getCurrentFrame();
for(var i=0, l=pixels.length; i<l; i++) { for(var i=0, l=pixels.length; i<l; i++) {
try { try {
this.currentFrame.setPixel( currentFrame.setPixel(
pixels[i].col, pixels[i].row, pixels[i].col, pixels[i].row,
pixels[i].copiedColor); pixels[i].copiedColor);
} }
@ -108,8 +95,8 @@
* @private * @private
*/ */
ns.SelectionManager.prototype.onCopy_ = function(evt) { ns.SelectionManager.prototype.onCopy_ = function(evt) {
if(this.currentSelection && this.currentFrame) { if(this.currentSelection && this.framesheet.getCurrentFrame()) {
this.currentSelection.fillSelectionFromFrame(this.currentFrame); this.currentSelection.fillSelectionFromFrame(this.framesheet.getCurrentFrame());
} }
else { else {
throw "Bad state for CUT callback in SelectionManager"; throw "Bad state for CUT callback in SelectionManager";