From 829bcb8ad1c7d3fb7525d8231ecf79af56513d71 Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sun, 13 Jul 2014 21:01:50 +0200 Subject: [PATCH] Simplified lighten + fixed frame caching bug --- src/js/drawingtools/Lighten.js | 21 +++++++++------------ src/js/model/frame/CachedFrameProcessor.js | 12 ++++++------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/js/drawingtools/Lighten.js b/src/js/drawingtools/Lighten.js index ff388c46..cd704bc6 100644 --- a/src/js/drawingtools/Lighten.js +++ b/src/js/drawingtools/Lighten.js @@ -19,11 +19,17 @@ {key : 'shift', description : 'Apply only once per pixel'} ]; - this.resetUsedPixels_(); + this.usedPixels_ = { + darken : {}, + lighten : {} + }; }; pskl.utils.inherit(ns.Lighten, ns.SimplePen); + /** + * @Override + */ ns.Lighten.prototype.resetUsedPixels_ = function() { this.usedPixels_ = { darken : {}, @@ -31,8 +37,9 @@ }; this.superclass.resetUsedPixels_.call(this); }; + /** - * @override + * @Override */ ns.Lighten.prototype.applyToolAt = function(col, row, color, frame, overlay, event, mouseButton) { var overlayColor = overlay.getPixel(col, row); @@ -63,14 +70,4 @@ } }; - - ns.Lighten.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) { - this.setPixelsToFrame_(frame, this.pixels); - - $.publish(Events.PISKEL_SAVE_STATE, { - type : pskl.service.HistoryService.SNAPSHOT - }); - - this.resetUsedPixels_(); - }; })(); \ No newline at end of file diff --git a/src/js/model/frame/CachedFrameProcessor.js b/src/js/model/frame/CachedFrameProcessor.js index 3c0c07aa..4f884b91 100644 --- a/src/js/model/frame/CachedFrameProcessor.js +++ b/src/js/model/frame/CachedFrameProcessor.js @@ -62,17 +62,17 @@ var cache = this.cache_[namespace]; var cacheKey = frame.getHash(); - if (this.cache_[cacheKey]) { - processedFrame = this.cache_[cacheKey]; + if (cache[cacheKey]) { + processedFrame = cache[cacheKey]; } else { var frameAsString = JSON.stringify(frame.getPixels()); - if (this.cache_[frameAsString]) { - processedFrame = this.outputCloner(this.cache_[frameAsString], frame); + if (cache[frameAsString]) { + processedFrame = this.outputCloner(cache[frameAsString], frame); } else { processedFrame = this.frameProcessor(frame); - this.cache_[frameAsString] = processedFrame; + cache[frameAsString] = processedFrame; } - this.cache_[cacheKey] = processedFrame; + cache[cacheKey] = processedFrame; } return processedFrame; };