mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
swap color : initial implementation
This commit is contained in:
parent
707a69182f
commit
304a5c06da
|
@ -20,10 +20,22 @@
|
||||||
ns.ColorPicker.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
ns.ColorPicker.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
||||||
if (frame.containsPixel(col, row)) {
|
if (frame.containsPixel(col, row)) {
|
||||||
var sampledColor = frame.getPixel(col, row);
|
var sampledColor = frame.getPixel(col, row);
|
||||||
if (event.button == Constants.LEFT_BUTTON) {
|
if (event.ctrlKey) {
|
||||||
$.publish(Events.SELECT_PRIMARY_COLOR, [sampledColor]);
|
pskl.app.piskelController.getPiskel().getLayers().forEach(function (l) {
|
||||||
} else if (event.button == Constants.RIGHT_BUTTON) {
|
l.getFrames().forEach(function (f) {
|
||||||
$.publish(Events.SELECT_SECONDARY_COLOR, [sampledColor]);
|
f.forEachPixel(function (pixelColor,x,y) {
|
||||||
|
if (pixelColor === sampledColor) {
|
||||||
|
f.setPixel(x, y, pskl.app.paletteController.getPrimaryColor());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (event.button == Constants.LEFT_BUTTON) {
|
||||||
|
$.publish(Events.SELECT_PRIMARY_COLOR, [sampledColor]);
|
||||||
|
} else if (event.button == Constants.RIGHT_BUTTON) {
|
||||||
|
$.publish(Events.SELECT_SECONDARY_COLOR, [sampledColor]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,19 +84,19 @@
|
||||||
return [this.id, this.version].join('-');
|
return [this.id, this.version].join('-');
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.setPixel = function (col, row, color) {
|
ns.Frame.prototype.setPixel = function (x, y, color) {
|
||||||
if (this.containsPixel(col, row)) {
|
if (this.containsPixel(x, y)) {
|
||||||
var p = this.pixels[col][row];
|
var p = this.pixels[x][y];
|
||||||
if (p !== color) {
|
if (p !== color) {
|
||||||
this.pixels[col][row] = color;
|
this.pixels[x][y] = color;
|
||||||
this.version++;
|
this.version++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.getPixel = function (col, row) {
|
ns.Frame.prototype.getPixel = function (x, y) {
|
||||||
if (this.containsPixel(col, row)) {
|
if (this.containsPixel(x, y)) {
|
||||||
return this.pixels[col][row];
|
return this.pixels[x][y];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user