mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Enhancement : preview copied selection + paste only opaque
This commit is contained in:
parent
98aad13f1e
commit
cf2c0e7045
@ -76,18 +76,24 @@
|
|||||||
*/
|
*/
|
||||||
ns.BaseSelect.prototype.moveUnactiveToolAt = function(col, row, color, frame, overlay, event) {
|
ns.BaseSelect.prototype.moveUnactiveToolAt = function(col, row, color, frame, overlay, event) {
|
||||||
if (overlay.containsPixel(col, row)) {
|
if (overlay.containsPixel(col, row)) {
|
||||||
if(overlay.getPixel(col, row) != Constants.SELECTION_TRANSPARENT_COLOR) {
|
if(this.isInSelection(col, row)) {
|
||||||
// We're hovering the selection, show the move tool:
|
// We're hovering the selection, show the move tool:
|
||||||
this.BodyRoot.addClass(this.toolId);
|
|
||||||
this.BodyRoot.removeClass(this.secondaryToolId);
|
|
||||||
} else {
|
|
||||||
// We're not hovering the selection, show create selection tool:
|
|
||||||
this.BodyRoot.addClass(this.secondaryToolId);
|
this.BodyRoot.addClass(this.secondaryToolId);
|
||||||
this.BodyRoot.removeClass(this.toolId);
|
this.BodyRoot.removeClass(this.toolId);
|
||||||
|
} else {
|
||||||
|
// We're not hovering the selection, show create selection tool:
|
||||||
|
this.BodyRoot.addClass(this.toolId);
|
||||||
|
this.BodyRoot.removeClass(this.secondaryToolId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.BaseSelect.prototype.isInSelection = function (col, row) {
|
||||||
|
return this.selection && this.selection.pixels.some(function (pixel) {
|
||||||
|
return pixel.col === col && pixel.row === row;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
ns.BaseSelect.prototype.hideHighlightedPixel = function() {
|
ns.BaseSelect.prototype.hideHighlightedPixel = function() {
|
||||||
// there is no highlighted pixel for selection tools, do nothing
|
// there is no highlighted pixel for selection tools, do nothing
|
||||||
};
|
};
|
||||||
@ -99,10 +105,20 @@
|
|||||||
ns.BaseSelect.prototype.drawSelectionOnOverlay_ = function (overlay) {
|
ns.BaseSelect.prototype.drawSelectionOnOverlay_ = function (overlay) {
|
||||||
var pixels = this.selection.pixels;
|
var pixels = this.selection.pixels;
|
||||||
for(var i=0, l=pixels.length; i<l; i++) {
|
for(var i=0, l=pixels.length; i<l; i++) {
|
||||||
overlay.setPixel(pixels[i].col, pixels[i].row, Constants.SELECTION_TRANSPARENT_COLOR);
|
var pixel = pixels[i];
|
||||||
|
var hasColor = pixel.color && pixel.color !== Constants.TRANSPARENT_COLOR ;
|
||||||
|
var color = hasColor ? this.getTransparentVariant(pixel.color) : Constants.SELECTION_TRANSPARENT_COLOR;
|
||||||
|
|
||||||
|
overlay.setPixel(pixels[i].col, pixels[i].row, color);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.BaseSelect.prototype.getTransparentVariant = function (colorStr) {
|
||||||
|
var color = window.tinycolor(colorStr);
|
||||||
|
color = window.tinycolor.lighten(color, 10);
|
||||||
|
color.setAlpha(0.5);
|
||||||
|
return color.toRgbString();
|
||||||
|
};
|
||||||
|
|
||||||
// The list of callbacks to implement by specialized tools to implement the selection creation behavior.
|
// The list of callbacks to implement by specialized tools to implement the selection creation behavior.
|
||||||
/** @protected */
|
/** @protected */
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
$.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this));
|
$.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this));
|
||||||
|
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
|
||||||
|
pskl.app.shortcutService.addShortcut('shift+V', this.pasteOpaqueOnly.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('del', this.erase.bind(this));
|
pskl.app.shortcutService.addShortcut('del', this.erase.bind(this));
|
||||||
@ -93,23 +94,37 @@
|
|||||||
ns.SelectionManager.prototype.paste = function() {
|
ns.SelectionManager.prototype.paste = function() {
|
||||||
if(this.currentSelection && this.currentSelection.hasPastedContent) {
|
if(this.currentSelection && this.currentSelection.hasPastedContent) {
|
||||||
var pixels = this.currentSelection.pixels;
|
var pixels = this.currentSelection.pixels;
|
||||||
var currentFrame = this.piskelController.getCurrentFrame();
|
this.pastePixels(pixels);
|
||||||
|
|
||||||
$.publish(Events.PISKEL_SAVE_STATE, {
|
|
||||||
type : pskl.service.HistoryService.REPLAY,
|
|
||||||
scope : this,
|
|
||||||
replay : {
|
|
||||||
type : SELECTION_REPLAY.PASTE,
|
|
||||||
pixels : JSON.parse(JSON.stringify(pixels.slice(0)))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
pixels.forEach(function (pixel) {
|
|
||||||
currentFrame.setPixel(pixel.col,pixel.row,pixel.color);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.SelectionManager.prototype.pasteOpaqueOnly = function() {
|
||||||
|
if(this.currentSelection && this.currentSelection.hasPastedContent) {
|
||||||
|
var pixels = this.currentSelection.pixels;
|
||||||
|
var opaquePixels = pixels.filter(function (p) {
|
||||||
|
return p.color !== Constants.TRANSPARENT_COLOR;
|
||||||
|
});
|
||||||
|
this.pastePixels(opaquePixels);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectionManager.prototype.pastePixels = function(pixels) {
|
||||||
|
var currentFrame = this.piskelController.getCurrentFrame();
|
||||||
|
|
||||||
|
$.publish(Events.PISKEL_SAVE_STATE, {
|
||||||
|
type : pskl.service.HistoryService.REPLAY,
|
||||||
|
scope : this,
|
||||||
|
replay : {
|
||||||
|
type : SELECTION_REPLAY.PASTE,
|
||||||
|
pixels : JSON.parse(JSON.stringify(pixels.slice(0)))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pixels.forEach(function (pixel) {
|
||||||
|
currentFrame.setPixel(pixel.col,pixel.row,pixel.color);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
ns.SelectionManager.prototype.replay = function (frame, replayData) {
|
ns.SelectionManager.prototype.replay = function (frame, replayData) {
|
||||||
var pixels = replayData.pixels;
|
var pixels = replayData.pixels;
|
||||||
pixels.forEach(function (pixel) {
|
pixels.forEach(function (pixel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user