[aseprite] 43/64: Enable Edit > Copy Merged only when there is a visible selection

Tobias Hansen thansen at moszumanska.debian.org
Tue Jun 21 14:43:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 47f4cb13134107678208bd7c18a725b012b679b2
Author: David Capello <davidcapello at gmail.com>
Date:   Thu May 19 13:19:02 2016 -0300

    Enable Edit > Copy Merged only when there is a visible selection
    
    This fix a crash using copy merged when there is no selection.
---
 src/app/commands/cmd_copy_merged.cpp |  3 ++-
 src/app/util/new_image_from_mask.cpp | 20 ++++++++++++--------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/app/commands/cmd_copy_merged.cpp b/src/app/commands/cmd_copy_merged.cpp
index ad4a78f..c8cdfba 100644
--- a/src/app/commands/cmd_copy_merged.cpp
+++ b/src/app/commands/cmd_copy_merged.cpp
@@ -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)
diff --git a/src/app/util/new_image_from_mask.cpp b/src/app/util/new_image_from_mask.cpp
index a836a73..b37ac20 100644
--- a/src/app/util/new_image_from_mask.cpp
+++ b/src/app/util/new_image_from_mask.cpp
@@ -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()))

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list