From be9a9d1d18e2df526924e3674973471455959c78 Mon Sep 17 00:00:00 2001 From: Harald Reingruber Date: Tue, 7 Apr 2020 20:34:58 +0200 Subject: [PATCH 1/3] Fix symbols dropped outside of canvas are inserted in the center --- src/desktop.cpp | 20 +++++++++++++++----- src/desktop.h | 5 ++++- src/display/sp-canvas.cpp | 6 ++++++ src/display/sp-canvas.h | 1 + src/ui/clipboard.cpp | 4 ++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/desktop.cpp b/src/desktop.cpp index 5cedbbc815..116b670ced 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -814,14 +814,13 @@ SPItem *SPDesktop::getGroupAtPoint(Geom::Point const &p) const * Returns the mouse point in document coordinates; if mouse is * outside the canvas, returns the center of canvas viewpoint. */ -Geom::Point SPDesktop::point(bool outside_canvas) const +Geom::Point SPDesktop::point(bool also_if_outside_canvas) const { - Geom::Point p = _widget->getPointer(); - Geom::Point pw = sp_canvas_window_to_world (canvas, p); + Geom::Point pw = getMousePointInWorld(); Geom::Rect const r = canvas->getViewbox(); - if (r.interiorContains(pw) || outside_canvas) { - p = w2d(pw); + if (also_if_outside_canvas || canvas->containsWorldPoint(pw)) { + Geom::Point p = w2d(pw); return p; } Geom::Point r0 = w2d(r.min()); @@ -829,6 +828,17 @@ Geom::Point SPDesktop::point(bool outside_canvas) const return (r0 + r1) / 2.0; } +Geom::Point SPDesktop::getMousePointInWorld() const +{ + Geom::Point p = _widget->getPointer(); + return sp_canvas_window_to_world(canvas, p); +} + +bool SPDesktop::isMouseInsideCanvas() const +{ + Geom::Point pw = getMousePointInWorld(); + return canvas->containsWorldPoint(pw); +} /** * Revert back to previous transform if possible. Note: current transform is diff --git a/src/desktop.h b/src/desktop.h index 74245d71d8..0c8cf3f1db 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -337,7 +337,8 @@ public: SPItem *getItemFromListAtPointBottom(const std::vector &list, Geom::Point const &p) const; SPItem *getItemAtPoint(Geom::Point const &p, bool into_groups, SPItem *upto = nullptr) const; SPItem *getGroupAtPoint(Geom::Point const &p) const; - Geom::Point point(bool outside_canvas = false) const; + Geom::Point point(bool also_if_outside_canvas = false) const; + bool isMouseInsideCanvas() const; void prev_transform(); void next_transform(); @@ -622,6 +623,8 @@ private: void onDocumentURISet (gchar const* uri) override; void onDocumentResized (double, double) override; + Geom::Point getMousePointInWorld() const; + static void _onActivate (SPDesktop* dt); static void _onDeactivate (SPDesktop* dt); static void _onSelectionModified (Inkscape::Selection *selection, guint flags, SPDesktop *dt); diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 9b01342431..110881aef3 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -2903,6 +2903,12 @@ Geom::IntRect SPCanvas::getViewboxIntegers() const return Geom::IntRect::from_xywh(_x0, _y0, allocation.width, allocation.height); } +bool SPCanvas::containsWorldPoint(Geom::Point pw) const +{ + Geom::Rect const r = getViewbox(); + return r.interiorContains(pw); +} + inline int sp_canvas_tile_floor(int x) { return (x & (~(TILE_SIZE - 1))) / TILE_SIZE; diff --git a/src/display/sp-canvas.h b/src/display/sp-canvas.h index 5bf88d28db..7842dd3508 100644 --- a/src/display/sp-canvas.h +++ b/src/display/sp-canvas.h @@ -89,6 +89,7 @@ struct SPCanvas { Geom::Rect getViewbox() const; Geom::IntRect getViewboxIntegers() const; + bool containsWorldPoint(Geom::Point pw) const; SPCanvasGroup *getRoot(); void setBackgroundColor(guint32 rgba); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 58b1b0a3bd..ec3e5eb1e9 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -395,6 +395,10 @@ bool ClipboardManagerImpl::paste(SPDesktop *desktop, bool in_place) return false; } + // don't insert symbol if mouse is outside of canvas + if (!desktop->isMouseInsideCanvas()) + return false; + sp_import_document(desktop, tempdoc.get(), in_place); return true; -- GitLab From 215fde5fb6c59d4307ae289af4eb8a2540c9fecc Mon Sep 17 00:00:00 2001 From: Harald Reingruber Date: Tue, 7 Apr 2020 20:50:12 +0200 Subject: [PATCH 2/3] Add myself as author --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2986f3dcf3..f7f6c84c59 100644 --- a/AUTHORS +++ b/AUTHORS @@ -179,3 +179,4 @@ David Yip Masatake Yamato Moritz Eberl Sebastian Faubel +Harald Reingruber -- GitLab From 83be0cf097b9941fd4ea7cc5706716751fb712f6 Mon Sep 17 00:00:00 2001 From: Harald Reingruber Date: Tue, 21 Apr 2020 09:59:55 +0200 Subject: [PATCH 3/3] Fix regression when pasting something (e.g. via "Edit > Paste") while the mouse pointer is outside the menu --- src/ui/clipboard.cpp | 4 ---- src/ui/drag-and-drop.cpp | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index ec3e5eb1e9..58b1b0a3bd 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -395,10 +395,6 @@ bool ClipboardManagerImpl::paste(SPDesktop *desktop, bool in_place) return false; } - // don't insert symbol if mouse is outside of canvas - if (!desktop->isMouseInsideCanvas()) - return false; - sp_import_document(desktop, tempdoc.get(), in_place); return true; diff --git a/src/ui/drag-and-drop.cpp b/src/ui/drag-and-drop.cpp index 3519da6f0b..083306d602 100644 --- a/src/ui/drag-and-drop.cpp +++ b/src/ui/drag-and-drop.cpp @@ -337,6 +337,11 @@ ink_drag_data_received(GtkWidget *widget, case APP_X_INK_PASTE: { Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get(); + + // don't insert if mouse is outside of canvas + if (!desktop->isMouseInsideCanvas()) + return; + cm->paste(desktop); DocumentUndo::done( doc, SP_VERB_NONE, _("Drop Symbol") ); break; -- GitLab