[aseprite] 223/250: Don't overwrite clipboard content on Edit > Insert Text (fix #839)

Tobias Hansen thansen at moszumanska.debian.org
Sun Dec 20 15:27:33 UTC 2015


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

thansen pushed a commit to branch master
in repository aseprite.

commit 91af58dbb0e5686d9ccfd3832bd41184cec3c63e
Author: David Capello <davidcapello at gmail.com>
Date:   Mon Nov 2 17:47:56 2015 -0300

    Don't overwrite clipboard content on Edit > Insert Text (fix #839)
---
 src/app/commands/cmd_paste_text.cpp | 13 +++++++++----
 src/app/ui/editor/editor.cpp        | 15 ++++++++++++++-
 src/app/ui/editor/editor.h          |  2 +-
 src/app/util/clipboard.cpp          | 11 -----------
 4 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/app/commands/cmd_paste_text.cpp b/src/app/commands/cmd_paste_text.cpp
index 043d329..e2127d4 100644
--- a/src/app/commands/cmd_paste_text.cpp
+++ b/src/app/commands/cmd_paste_text.cpp
@@ -14,16 +14,18 @@
 #include "app/console.h"
 #include "app/context.h"
 #include "app/file_selector.h"
+#include "app/modules/editors.h"
 #include "app/pref/preferences.h"
 #include "app/ui/drop_down_button.h"
+#include "app/ui/editor/editor.h"
 #include "app/ui/font_popup.h"
-#include "app/util/clipboard.h"
 #include "app/util/freetype_utils.h"
 #include "base/bind.h"
 #include "base/path.h"
 #include "base/string.h"
 #include "base/unique_ptr.h"
 #include "doc/image.h"
+#include "doc/image_ref.h"
 
 #include "paste_text.xml.h"
 
@@ -138,6 +140,10 @@ private:
 
 void PasteTextCommand::onExecute(Context* ctx)
 {
+  Editor* editor = current_editor;
+  if (editor == NULL)
+    return;
+
   Preferences& pref = Preferences::instance();
   PasteTextWindow window(pref.textTool.fontFace(),
                          pref.textTool.fontSize(),
@@ -165,10 +171,9 @@ void PasteTextCommand::onExecute(Context* ctx)
                                    appColor.getBlue(),
                                    appColor.getAlpha());
 
-    doc::Image* image = render_text(faceName, size, text, color);
+    doc::ImageRef image(render_text(faceName, size, text, color));
     if (image) {
-      clipboard::copy_image(image, nullptr, nullptr);
-      clipboard::paste();
+      editor->pasteImage(image.get());
     }
   }
   catch (const std::exception& ex) {
diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp
index c24d04d..e20b022 100644
--- a/src/app/ui/editor/editor.cpp
+++ b/src/app/ui/editor/editor.cpp
@@ -1494,7 +1494,20 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom,
 void Editor::pasteImage(const Image* image, const Mask* mask)
 {
   ASSERT(image);
-  ASSERT(mask);
+
+  base::UniquePtr<Mask> temp_mask;
+  if (!mask) {
+    gfx::Rect visibleBounds = getVisibleSpriteBounds();
+    gfx::Rect imageBounds = image->bounds();
+
+    temp_mask.reset(new Mask);
+    temp_mask->replace(
+      gfx::Rect(visibleBounds.x + visibleBounds.w/2 - imageBounds.w/2,
+                visibleBounds.y + visibleBounds.h/2 - imageBounds.h/2,
+                imageBounds.w, imageBounds.h));
+
+    mask = temp_mask.get();
+  }
 
   // Change to a selection tool: it's necessary for PixelsMovement
   // which will use the extra cel for transformation preview, and is
diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h
index 862faf0..9fe525d 100644
--- a/src/app/ui/editor/editor.h
+++ b/src/app/ui/editor/editor.h
@@ -185,7 +185,7 @@ namespace app {
     void setZoomAndCenterInMouse(const render::Zoom& zoom,
       const gfx::Point& mousePos, ZoomBehavior zoomBehavior);
 
-    void pasteImage(const Image* image, const Mask* mask);
+    void pasteImage(const Image* image, const Mask* mask = nullptr);
 
     void startSelectionTransformation(const gfx::Point& move, double angle);
 
diff --git a/src/app/util/clipboard.cpp b/src/app/util/clipboard.cpp
index c9dda7f..879edc4 100644
--- a/src/app/util/clipboard.cpp
+++ b/src/app/util/clipboard.cpp
@@ -262,17 +262,6 @@ void clipboard::paste()
       if (!clipboard_image)
         return;
 
-      if (!clipboard_mask) {
-        gfx::Rect visibleBounds = editor->getVisibleSpriteBounds();
-        gfx::Rect imageBounds = clipboard_image->bounds();
-
-        clipboard_mask.reset(new Mask);
-        clipboard_mask->replace(
-          gfx::Rect(visibleBounds.x + visibleBounds.w/2 - imageBounds.w/2,
-                    visibleBounds.y + visibleBounds.h/2 - imageBounds.h/2,
-                    imageBounds.w, imageBounds.h));
-      }
-
       Palette* dst_palette = dstSpr->palette(editor->frame());
 
       // Source image (clipboard or a converted copy to the destination 'imgtype')

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