From 6bf1c773c8669f28b88b634c667394cfd5ed0766 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 16:50:29 +0200 Subject: [PATCH 1/7] Fixed undo/redo bug --- js/model/Frame.js | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/js/model/Frame.js b/js/model/Frame.js index 72fcdd04..a94d1a5b 100644 --- a/js/model/Frame.js +++ b/js/model/Frame.js @@ -3,7 +3,7 @@ ns.Frame = function (pixels) { this.pixels = pixels; - this.previousStates = [this._clonePixels()]; + this.previousStates = [this.getPixels()]; this.stateIndex = 0; }; @@ -27,12 +27,30 @@ return new ns.Frame(this._clonePixels()); }; - ns.Frame.prototype._clonePixels = function () { - var pixels = []; - for (var col = 0 ; col < this.getWidth() ; col++) { - pixels[col] = this.pixels[col].slice(0 , this.getHeight()); + /** + * Returns a copy of the pixels used by the frame + */ + ns.Frame.prototype.getPixels = function () { + return this.clonePixels_(this.pixels) + }; + + /** + * Copies the passed pixels into the frame. + */ + ns.Frame.prototype.setPixels = function (pixels) { + this.pixels = this.clonePixels_(pixels); + }; + + /** + * Clone a set of pixels. Should be static utility method + * @private + */ + ns.Frame.prototype.clonePixels_ = function (pixels) { + var clonedPixels = []; + for (var col = 0 ; col < pixels.length ; col++) { + clonedPixels[col] = pixels[col].slice(0 , this.getHeight()); } - return pixels; + return clonedPixels; }; ns.Frame.prototype.serialize = function () { @@ -63,7 +81,7 @@ // remove all states past current state this.previousStates.length = this.stateIndex + 1; // push new state - this.previousStates.push(this._clonePixels()); + this.previousStates.push(this.getPixels()); // set the stateIndex to latest saved state this.stateIndex = this.previousStates.length - 1; }; @@ -71,14 +89,14 @@ ns.Frame.prototype.loadPreviousState = function () { if (this.stateIndex > 0) { this.stateIndex--; - this.pixels = this.previousStates[this.stateIndex]; + this.setPixels(this.previousStates[this.stateIndex]); } }; ns.Frame.prototype.loadNextState = function () { if (this.stateIndex < this.previousStates.length - 1) { this.stateIndex++; - this.pixels = this.previousStates[this.stateIndex]; + this.setPixels(this.previousStates[this.stateIndex]); } }; })(); \ No newline at end of file From a9b01cd7c25cead99f9670885dafa8c2c2ccbbcd Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 17:31:19 +0200 Subject: [PATCH 2/7] Resize is now bound to height and width, and also avoids overlap with preview --- js/piskel.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/js/piskel.js b/js/piskel.js index af4f7a79..8ed33461 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -112,8 +112,37 @@ $.namespace("pskl"); * @private */ calculateDPIsForDrawingCanvas_ : function() { - var availableViewportHeight = $('.main-panel').height(); - return Math.floor(availableViewportHeight / framePixelHeight); + var availableViewportHeight = $('.main-panel').height(), + availableViewportWidth = $('.main-panel').width(), + previewHeight = $(".preview-container").height(), + previewWidth = $(".preview-container").width(); + + var heightBoundDpi = Math.floor(availableViewportHeight / framePixelHeight), + widthBoundDpi = Math.floor(availableViewportWidth / framePixelWidth); + + var dpi = Math.min(heightBoundDpi, widthBoundDpi); + + var drawingCanvasHeight = dpi * framePixelHeight; + var drawingCanvasWidth = dpi * framePixelWidth; + + // Check if preview and drawing canvas overlap + var heightGap = drawingCanvasHeight + previewHeight - availableViewportHeight, + widthGap = drawingCanvasWidth + previewWidth - availableViewportWidth; + if (heightGap > 0 && widthGap > 0) { + // Calculate the DPI change needed to bridge height and width gap + var heightGapDpi = Math.ceil(heightGap / framePixelHeight), + widthGapDpi = Math.ceil(widthGap / framePixelWidth); + + // substract smallest dpi change to initial dpi + dpi -= Math.min(heightGapDpi, widthGapDpi); + } + + // var drawingCanvasWidth = dpi * framePixelWidth; + // if (availableViewportWidth - drawingCanvasWidth < previewWidth) { + // dpi -= Math.floor(previewWidth / framePixelWidth); + // } + + return dpi; }, finishInit : function () { From 506b54e27bdbbf4ff4000bcaa00cce8559ab6b02 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 17:31:48 +0200 Subject: [PATCH 3/7] removed commented code --- js/piskel.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/js/piskel.js b/js/piskel.js index 8ed33461..ba77acbf 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -136,11 +136,6 @@ $.namespace("pskl"); // substract smallest dpi change to initial dpi dpi -= Math.min(heightGapDpi, widthGapDpi); } - - // var drawingCanvasWidth = dpi * framePixelWidth; - // if (availableViewportWidth - drawingCanvasWidth < previewWidth) { - // dpi -= Math.floor(previewWidth / framePixelWidth); - // } return dpi; }, From 93e479fa1161978abcde37298efb1aed236bd508 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 17:41:09 +0200 Subject: [PATCH 4/7] Fixed bug with removed _clonePixels method in Frame.js --- js/model/Frame.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/model/Frame.js b/js/model/Frame.js index a94d1a5b..04790344 100644 --- a/js/model/Frame.js +++ b/js/model/Frame.js @@ -2,7 +2,7 @@ var ns = $.namespace("pskl.model"); ns.Frame = function (pixels) { - this.pixels = pixels; + this.pixels = this.clonePixels_(pixels); this.previousStates = [this.getPixels()]; this.stateIndex = 0; }; @@ -24,7 +24,7 @@ }; ns.Frame.prototype.clone = function () { - return new ns.Frame(this._clonePixels()); + return new ns.Frame(this.getPixels()); }; /** From 07369af9df8ad5ee39fbe15d9904cfb4f65894f3 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 17:44:55 +0200 Subject: [PATCH 5/7] Fixed bug on clonePixels_ need to stop commiting and pushing without testing ... --- js/model/Frame.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/model/Frame.js b/js/model/Frame.js index 04790344..bef3e94c 100644 --- a/js/model/Frame.js +++ b/js/model/Frame.js @@ -48,7 +48,7 @@ ns.Frame.prototype.clonePixels_ = function (pixels) { var clonedPixels = []; for (var col = 0 ; col < pixels.length ; col++) { - clonedPixels[col] = pixels[col].slice(0 , this.getHeight()); + clonedPixels[col] = pixels[col].slice(0 , pixels[col].length-1); } return clonedPixels; }; From 869f3d2e005ca0e9debffe51ed897e1e9b7f78b7 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 17:57:21 +0200 Subject: [PATCH 6/7] fixed bug when resizing --- js/controller/DrawingController.js | 2 +- js/drawingtools/Move.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/js/controller/DrawingController.js b/js/controller/DrawingController.js index f6043669..d6803593 100644 --- a/js/controller/DrawingController.js +++ b/js/controller/DrawingController.js @@ -26,7 +26,7 @@ this.overlayRenderer.updateDPI(newDPI); this.renderer.render(this.frame); - this.overlayRenderer.render(this.frame); + this.overlayRenderer.render(this.overlayFrame); }; ns.DrawingController.prototype.renderFrame = function () { diff --git a/js/drawingtools/Move.js b/js/drawingtools/Move.js index 8a36e36f..2ff9ca73 100644 --- a/js/drawingtools/Move.js +++ b/js/drawingtools/Move.js @@ -12,8 +12,6 @@ // Stroke's first point coordinates (set in applyToolAt) this.startCol = null; this.startRow = null; - - this.canvasOverlay = null; }; pskl.utils.inherit(ns.Move, ns.BaseTool); From df405d917fe35a484d117ddf31185160cff1378e Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Sat, 8 Sep 2012 18:15:53 +0200 Subject: [PATCH 7/7] Clone pixels pug --- js/model/Frame.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/model/Frame.js b/js/model/Frame.js index bef3e94c..b8c7a5eb 100644 --- a/js/model/Frame.js +++ b/js/model/Frame.js @@ -48,7 +48,7 @@ ns.Frame.prototype.clonePixels_ = function (pixels) { var clonedPixels = []; for (var col = 0 ; col < pixels.length ; col++) { - clonedPixels[col] = pixels[col].slice(0 , pixels[col].length-1); + clonedPixels[col] = pixels[col].slice(0 , pixels[col].length); } return clonedPixels; };