mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fix : dont modify transparent color
This commit is contained in:
parent
93f3526f4b
commit
da9cd78b56
@ -71,6 +71,8 @@
|
||||
* @private
|
||||
*/
|
||||
ns.BaseTool.prototype.getLinePixels_ = function(x0, x1, y0, y1) {
|
||||
x1 = pskl.utils.normalize(x1, 0);
|
||||
y1 = pskl.utils.normalize(y1, 0);
|
||||
|
||||
var pixels = [];
|
||||
var dx = Math.abs(x1-x0);
|
||||
@ -78,7 +80,7 @@
|
||||
var sx = (x0 < x1) ? 1 : -1;
|
||||
var sy = (y0 < y1) ? 1 : -1;
|
||||
var err = dx-dy;
|
||||
|
||||
var it = 0;
|
||||
while(true){
|
||||
|
||||
// Do what you need to for this
|
||||
|
@ -6,12 +6,12 @@
|
||||
*/
|
||||
(function() {
|
||||
var ns = $.namespace("pskl.drawingtools");
|
||||
var DEFAULT_STEP = 3;
|
||||
|
||||
ns.Lighten = function() {
|
||||
this.superclass.constructor.call(this);
|
||||
this.toolId = "tool-lighten";
|
||||
this.helpText = "Lighten (hold ctrl for Darken)";
|
||||
this.step = 3;
|
||||
this.resetUsedPixels_();
|
||||
};
|
||||
|
||||
@ -27,22 +27,25 @@
|
||||
* @override
|
||||
*/
|
||||
ns.Lighten.prototype.applyToolAt = function(col, row, color, frame, overlay, event, mouseButton) {
|
||||
var pixelColor = frame.getPixel(col, row);
|
||||
|
||||
var isDarken = event.ctrlKey || event.cmdKey;
|
||||
var isSinglePass = event.shiftKey;
|
||||
|
||||
var isTransparent = pixelColor === Constants.TRANSPARENT_COLOR;
|
||||
var usedPixels = isDarken ? this.usedPixels_.darken : this.usedPixels_.lighten;
|
||||
|
||||
var key = col+'-'+row;
|
||||
if (isSinglePass && usedPixels[key]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var step = isSinglePass ? this.step * 2 : this.step;
|
||||
var pixelColor = frame.getPixel(col, row);
|
||||
if (isDarken) {
|
||||
color = window.tinycolor.darken(pixelColor, step);
|
||||
var doNotModify = isTransparent || (isSinglePass && usedPixels[key]);
|
||||
if (doNotModify) {
|
||||
color = pixelColor;
|
||||
} else {
|
||||
color = window.tinycolor.lighten(pixelColor, step);
|
||||
var step = isSinglePass ? DEFAULT_STEP * 2 : DEFAULT_STEP;
|
||||
if (isDarken) {
|
||||
color = window.tinycolor.darken(pixelColor, step);
|
||||
} else {
|
||||
color = window.tinycolor.lighten(pixelColor, step);
|
||||
}
|
||||
}
|
||||
|
||||
if (color) {
|
||||
|
@ -41,6 +41,14 @@ if (typeof Function.prototype.bind !== "function") {
|
||||
return ((r << 16) | (g << 8) | b).toString(16);
|
||||
};
|
||||
|
||||
ns.normalize = function (value, def) {
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
return def;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
ns.inherit = function(extendedObject, inheritFrom) {
|
||||
extendedObject.prototype = Object.create(inheritFrom.prototype);
|
||||
extendedObject.prototype.constructor = extendedObject;
|
||||
|
Loading…
Reference in New Issue
Block a user