mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Add possibility to use New Layer via Cut/Copy with ranges
Requested here: https://community.aseprite.org/t/5222
This commit is contained in:
parent
fb68407e04
commit
e56cc15326
@ -23,12 +23,14 @@
|
|||||||
#include "app/i18n/strings.h"
|
#include "app/i18n/strings.h"
|
||||||
#include "app/load_widget.h"
|
#include "app/load_widget.h"
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
|
#include "app/restore_visible_layers.h"
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "app/ui/main_window.h"
|
#include "app/ui/main_window.h"
|
||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
#include "app/util/clipboard.h"
|
#include "app/util/clipboard.h"
|
||||||
#include "app/util/new_image_from_mask.h"
|
#include "app/util/new_image_from_mask.h"
|
||||||
|
#include "app/util/range_utils.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/primitives.h"
|
#include "doc/primitives.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
@ -357,28 +359,54 @@ void NewLayerCommand::onExecute(Context* context)
|
|||||||
#endif // ENABLE_UI
|
#endif // ENABLE_UI
|
||||||
// Paste new layer from selection
|
// Paste new layer from selection
|
||||||
else if ((params().viaCut() || params().viaCopy())
|
else if ((params().viaCut() || params().viaCopy())
|
||||||
&& layer->isImage()
|
|
||||||
&& document->isMaskVisible()) {
|
&& document->isMaskVisible()) {
|
||||||
const doc::Mask* mask = document->mask();
|
const doc::Mask* mask = document->mask();
|
||||||
ASSERT(mask);
|
ASSERT(mask);
|
||||||
ImageRef image(new_image_from_mask(site, mask, true));
|
|
||||||
if (image) {
|
RestoreVisibleLayers restore;
|
||||||
Cel* cel = api.addCel(static_cast<LayerImage*>(layer),
|
SelectedLayers layers;
|
||||||
site.frame(), image);
|
SelectedFrames frames;
|
||||||
if (cel) {
|
bool merged;
|
||||||
gfx::Point pos = mask->bounds().origin();
|
if (site.range().enabled()) {
|
||||||
cel->setPosition(pos.x, pos.y);
|
merged = true;
|
||||||
|
layers = site.range().selectedLayers();
|
||||||
|
frames = site.range().selectedFrames();
|
||||||
|
restore.showSelectedLayers(site.sprite(), layers);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
merged = false;
|
||||||
|
layers.insert(site.layer());
|
||||||
|
frames.insert(site.frame());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params().viaCut() &&
|
for (frame_t frame : frames) {
|
||||||
site.cel() && site.layer()) {
|
ImageRef newImage(new_image_from_mask(site, mask, true, merged));
|
||||||
tx(new cmd::ClearMask(site.cel()));
|
if (!newImage)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (site.layer()->isTransparent()) {
|
Cel* newCel = api.addCel(static_cast<LayerImage*>(layer),
|
||||||
|
frame, newImage);
|
||||||
|
if (newCel) {
|
||||||
|
gfx::Point pos = mask->bounds().origin();
|
||||||
|
newCel->setPosition(pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Layer* layer : layers) {
|
||||||
|
if (!layer->isImage() ||
|
||||||
|
!layer->isEditable()) // Locked layers will not be modified
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Cel* origCel = layer->cel(site.frame());
|
||||||
|
if (origCel &&
|
||||||
|
params().viaCut()) {
|
||||||
|
tx(new cmd::ClearMask(origCel));
|
||||||
|
|
||||||
|
if (layer->isTransparent()) {
|
||||||
// If the cel wasn't deleted by cmd::ClearMask, we trim it.
|
// If the cel wasn't deleted by cmd::ClearMask, we trim it.
|
||||||
cel = site.layer()->cel(site.frame());
|
origCel = layer->cel(frame);
|
||||||
if (cel)
|
if (origCel)
|
||||||
tx(new cmd::TrimCel(cel));
|
tx(new cmd::TrimCel(origCel));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user