mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-20 04:20:49 +00:00
Shrink bounds when MaskContentCommand is used in the background layer
So we can select the important part of the background layer when we use Ctrl+T on it.
This commit is contained in:
parent
0cb4b2234d
commit
b630565188
@ -11,6 +11,8 @@
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/cmd/set_mask.h"
|
||||
#include "app/color_picker.h"
|
||||
#include "app/color_utils.h"
|
||||
#include "app/commands/command.h"
|
||||
#include "app/context_access.h"
|
||||
#include "app/modules/editors.h"
|
||||
@ -22,6 +24,7 @@
|
||||
#include "doc/algorithm/shrink_bounds.h"
|
||||
#include "doc/cel.h"
|
||||
#include "doc/image.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/mask.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
@ -58,14 +61,23 @@ void MaskContentCommand::onExecute(Context* context)
|
||||
if (!cel)
|
||||
return;
|
||||
|
||||
gfx::Color color;
|
||||
if (writer.layer()->isBackground()) {
|
||||
ColorPicker picker;
|
||||
picker.pickColor(*writer.location(), gfx::Point(0, 0), ColorPicker::FromComposition);
|
||||
color = color_utils::color_for_layer(picker.color(), writer.layer());
|
||||
}
|
||||
else
|
||||
color = cel->image()->maskColor();
|
||||
|
||||
Mask newMask;
|
||||
gfx::Rect imgBounds = cel->image()->bounds();
|
||||
if (algorithm::shrink_bounds(cel->image(), imgBounds,
|
||||
cel->image()->maskColor())) {
|
||||
|
||||
newMask.copyFrom(document->mask());
|
||||
if (algorithm::shrink_bounds(cel->image(), imgBounds, color)) {
|
||||
newMask.replace(imgBounds.offset(cel->bounds().getOrigin()));
|
||||
}
|
||||
else {
|
||||
newMask.replace(cel->bounds());
|
||||
}
|
||||
|
||||
Transaction transaction(writer.context(), "Select Content", DoesntModifyDocument);
|
||||
transaction.execute(new cmd::SetMask(document, &newMask));
|
||||
|
Loading…
x
Reference in New Issue
Block a user