Enable Edit > Copy Merged only when there is a visible selection

This fix a crash using copy merged when there is no selection.
This commit is contained in:
David Capello 2016-05-19 13:19:02 -03:00
parent b21f5df2d6
commit 47f4cb1313
2 changed files with 14 additions and 9 deletions

View File

@ -34,7 +34,8 @@ CopyMergedCommand::CopyMergedCommand()
bool CopyMergedCommand::onEnabled(Context* ctx)
{
return ctx->checkFlags(ContextFlags::ActiveDocumentIsReadable);
return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable |
ContextFlags::HasVisibleMask);
}
void CopyMergedCommand::onExecute(Context* ctx)

View File

@ -34,11 +34,14 @@ doc::Image* new_image_from_mask(const doc::Site& site,
bool merged)
{
const Sprite* srcSprite = site.sprite();
const Image* srcMaskBitmap = (srcMask ? srcMask->bitmap(): nullptr);
gfx::Rect srcBounds = (srcMask ? srcMask->bounds(): srcSprite->bounds());
int x, y, u, v, getx, gety;
ASSERT(srcSprite);
ASSERT(srcMask);
const Image* srcMaskBitmap = srcMask->bitmap();
const gfx::Rect& srcBounds = srcMask->bounds();
ASSERT(srcMaskBitmap);
ASSERT(!srcBounds.isEmpty());
base::UniquePtr<Image> dst(Image::create(srcSprite->pixelFormat(), srcBounds.w, srcBounds.h));
if (!dst)
@ -49,6 +52,7 @@ doc::Image* new_image_from_mask(const doc::Site& site,
clear_image(dst, dst->maskColor());
const Image* src = nullptr;
int x = 0, y = 0;
if (merged) {
render::Render render;
render.renderSprite(dst, srcSprite, site.frame(),
@ -67,14 +71,14 @@ doc::Image* new_image_from_mask(const doc::Site& site,
const LockImageBits<BitmapTraits> maskBits(srcMaskBitmap, gfx::Rect(0, 0, srcBounds.w, srcBounds.h));
LockImageBits<BitmapTraits>::const_iterator mask_it = maskBits.begin();
for (v=0; v<srcBounds.h; ++v) {
for (u=0; u<srcBounds.w; ++u, ++mask_it) {
for (int v=0; v<srcBounds.h; ++v) {
for (int u=0; u<srcBounds.w; ++u, ++mask_it) {
ASSERT(mask_it != maskBits.end());
if (src != dst) {
if (*mask_it) {
getx = u+srcBounds.x-x;
gety = v+srcBounds.y-y;
int getx = u+srcBounds.x-x;
int gety = v+srcBounds.y-y;
if ((getx >= 0) && (getx < src->width()) &&
(gety >= 0) && (gety < src->height()))