[aseprite] 08/64: script: Sprite.crop() works with selection or x, y, w, h params

Tobias Hansen thansen at moszumanska.debian.org
Tue Jun 21 14:43:00 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 76eca942f007ef577ff2b71d54627cd6aa757293
Author: David Capello <davidcapello at gmail.com>
Date:   Fri May 6 16:52:29 2016 -0300

    script: Sprite.crop() works with selection or x,y,w,h params
---
 src/app/script/sprite_class.cpp | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/app/script/sprite_class.cpp b/src/app/script/sprite_class.cpp
index 856fb27..5fa353c 100644
--- a/src/app/script/sprite_class.cpp
+++ b/src/app/script/sprite_class.cpp
@@ -112,18 +112,32 @@ script::result_t Sprite_resize(script::ContextHandle handle)
 script::result_t Sprite_crop(script::ContextHandle handle)
 {
   script::Context ctx(handle);
-  int x = ctx.requireInt(0);
-  int y = ctx.requireInt(1);
-  int w = ctx.requireInt(2);
-  int h = ctx.requireInt(3);
+  gfx::Rect bounds;
 
   auto wrap = (SpriteWrap*)ctx.getThis();
   if (wrap) {
     wrap->commitImages();
 
     Document* doc = wrap->document();
-    DocumentApi api(doc, wrap->transaction());
-    api.cropSprite(doc->sprite(), gfx::Rect(x, y, w, h));
+
+    // Use mask bounds
+    if (ctx.isUndefined(0)) {
+      if (doc->isMaskVisible())
+        bounds = doc->mask()->bounds();
+      else
+        bounds = doc->sprite()->bounds();
+    }
+    else {
+      bounds.x = ctx.requireInt(0);
+      bounds.y = ctx.requireInt(1);
+      bounds.w = ctx.requireInt(2);
+      bounds.h = ctx.requireInt(3);
+    }
+
+    if (!bounds.isEmpty()) {
+      DocumentApi api(doc, wrap->transaction());
+      api.cropSprite(doc->sprite(), bounds);
+    }
   }
 
   return 0;

-- 
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