mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-25 01:43:36 +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/app.h"
|
||||||
#include "app/cmd/set_mask.h"
|
#include "app/cmd/set_mask.h"
|
||||||
|
#include "app/color_picker.h"
|
||||||
|
#include "app/color_utils.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
@ -22,6 +24,7 @@
|
|||||||
#include "doc/algorithm/shrink_bounds.h"
|
#include "doc/algorithm/shrink_bounds.h"
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
@ -58,14 +61,23 @@ void MaskContentCommand::onExecute(Context* context)
|
|||||||
if (!cel)
|
if (!cel)
|
||||||
return;
|
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;
|
Mask newMask;
|
||||||
gfx::Rect imgBounds = cel->image()->bounds();
|
gfx::Rect imgBounds = cel->image()->bounds();
|
||||||
if (algorithm::shrink_bounds(cel->image(), imgBounds,
|
if (algorithm::shrink_bounds(cel->image(), imgBounds, color)) {
|
||||||
cel->image()->maskColor())) {
|
|
||||||
|
|
||||||
newMask.copyFrom(document->mask());
|
|
||||||
newMask.replace(imgBounds.offset(cel->bounds().getOrigin()));
|
newMask.replace(imgBounds.offset(cel->bounds().getOrigin()));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
newMask.replace(cel->bounds());
|
||||||
|
}
|
||||||
|
|
||||||
Transaction transaction(writer.context(), "Select Content", DoesntModifyDocument);
|
Transaction transaction(writer.context(), "Select Content", DoesntModifyDocument);
|
||||||
transaction.execute(new cmd::SetMask(document, &newMask));
|
transaction.execute(new cmd::SetMask(document, &newMask));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user