Issue #258 : Simplify Lighten & update test

This commit is contained in:
jdescottes 2015-11-26 00:04:03 +01:00
parent 12ac85f0f6
commit 27061291a3
2 changed files with 292 additions and 1205 deletions

View File

@ -19,26 +19,10 @@
{key : 'ctrl', description : 'Darken'},
{key : 'shift', description : 'Apply only once per pixel'}
];
this.usedPixels_ = {
darken : {},
lighten : {}
};
};
pskl.utils.inherit(ns.Lighten, ns.SimplePen);
/**
* @Override
*/
ns.Lighten.prototype.resetUsedPixels_ = function() {
this.usedPixels_ = {
darken : {},
lighten : {}
};
this.superclass.resetUsedPixels_.call(this);
};
/**
* @Override
*/
@ -54,29 +38,32 @@
};
ns.Lighten.prototype.getModifiedColor_ = function(col, row, frame, overlay, event) {
// get colors in overlay and in frame
var overlayColor = overlay.getPixel(col, row);
var frameColor = frame.getPixel(col, row);
var pixelColor = overlayColor === Constants.TRANSPARENT_COLOR ? frameColor : overlayColor;
var isDarken = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
var isTransparent = pixelColor === Constants.TRANSPARENT_COLOR;
var isSinglePass = event.shiftKey;
var usedPixels = isDarken ? this.usedPixels_.darken : this.usedPixels_.lighten;
var key = col + '-' + row;
var doNotModify = isTransparent || (isSinglePass && usedPixels[key]);
var isPixelModified = overlayColor !== Constants.TRANSPARENT_COLOR;
var pixelColor = isPixelModified ? overlayColor : frameColor;
var isTransparent = pixelColor === Constants.TRANSPARENT_COLOR;
if (isTransparent) {
return Constants.TRANSPARENT_COLOR;
}
var oncePerPixel = event.shiftKey;
if (oncePerPixel && isPixelModified) {
return pixelColor;
}
var step = oncePerPixel ? DEFAULT_STEP * 2 : DEFAULT_STEP;
var isDarken = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
var color;
if (doNotModify) {
color = window.tinycolor(pixelColor);
if (isDarken) {
color = window.tinycolor.darken(pixelColor, step);
} else {
var step = isSinglePass ? DEFAULT_STEP * 2 : DEFAULT_STEP;
if (isDarken) {
color = window.tinycolor.darken(pixelColor, step);
} else {
color = window.tinycolor.lighten(pixelColor, step);
}
color = window.tinycolor.lighten(pixelColor, step);
}
usedPixels[key] = true;
// Convert tinycolor color to string format.
return color.toHexString();

File diff suppressed because it is too large Load Diff