From 788b136bbf3e0f6b11c0e7bd99103a0c797733a7 Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 4 Sep 2019 16:02:58 +0300 Subject: [PATCH] app: add "clip" parameter to gimp_display_shell_untransform_viewport() ... which specifies whether to clip the viewport to the canvas (previously, it would always be clipped). Use the appropriate value in all callers, depending on the shell's "show all" mode. In particular, this commit avoids clipping the image projection's priority rect to the canvas in "show all" mode. --- app/actions/buffers-commands.c | 2 +- app/actions/edit-commands.c | 3 ++- app/display/gimpdisplayshell-dnd.c | 10 +++++++--- app/display/gimpdisplayshell-transform.c | 25 +++++++++++------------- app/display/gimpdisplayshell-transform.h | 1 + app/display/gimpdisplayshell.c | 5 ++++- app/tools/gimpfiltertool.c | 2 +- app/tools/gimpseamlessclonetool.c | 3 ++- 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/actions/buffers-commands.c b/app/actions/buffers-commands.c index 4151b53c67..ef8f29212c 100644 --- a/app/actions/buffers-commands.c +++ b/app/actions/buffers-commands.c @@ -74,7 +74,7 @@ buffers_paste_cmd_callback (GimpAction *action, { GimpDisplayShell *shell = gimp_display_get_shell (display); - gimp_display_shell_untransform_viewport (shell, + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, &x, &y, &width, &height); image = gimp_display_get_image (display); diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c index 8e43e3f473..a6a740b057 100644 --- a/app/actions/edit-commands.c +++ b/app/actions/edit-commands.c @@ -610,7 +610,8 @@ edit_paste (GimpDisplay *display, /* the actual paste-type conversion happens in gimp_edit_paste() */ } - gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, + &x, &y, &width, &height); if (gimp_edit_paste (image, drawable, paste, paste_type, x, y, width, height)) diff --git a/app/display/gimpdisplayshell-dnd.c b/app/display/gimpdisplayshell-dnd.c index dd550513e5..3d7366d80e 100644 --- a/app/display/gimpdisplayshell-dnd.c +++ b/app/display/gimpdisplayshell-dnd.c @@ -179,7 +179,8 @@ gimp_display_shell_dnd_position_item (GimpDisplayShell *shell, gint x, y; gint width, height; - gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, + &x, &y, &width, &height); off_x = x + (width - item_width) / 2; off_y = y + (height - item_height) / 2; @@ -493,7 +494,8 @@ gimp_display_shell_drop_buffer (GtkWidget *widget, buffer = GIMP_BUFFER (viewable); - gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, + &x, &y, &width, &height); /* FIXME: popup a menu for selecting "Paste Into" */ @@ -565,7 +567,9 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, gint height = gimp_image_get_height (image); if (gimp_display_get_image (shell->display)) - gimp_display_shell_untransform_viewport (shell, &x, &y, + gimp_display_shell_untransform_viewport (shell, + ! shell->show_all, + &x, &y, &width, &height); gimp_image_add_layers (image, new_layers, diff --git a/app/display/gimpdisplayshell-transform.c b/app/display/gimpdisplayshell-transform.c index 9f810811c6..f9cd2e56da 100644 --- a/app/display/gimpdisplayshell-transform.c +++ b/app/display/gimpdisplayshell-transform.c @@ -956,6 +956,7 @@ gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell *shell, /** * gimp_display_shell_untransform_viewport: * @shell: a #GimpDisplayShell + * @clip: whether to clip the result to the image bounds * @x: returns image x coordinate of display upper left corner * @y: returns image y coordinate of display upper left corner * @width: returns width of display measured in image coordinates @@ -966,13 +967,13 @@ gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell *shell, **/ void gimp_display_shell_untransform_viewport (GimpDisplayShell *shell, + gboolean clip, gint *x, gint *y, gint *width, gint *height) { - GimpImage *image; - gdouble x1, y1, x2, y2; + gdouble x1, y1, x2, y2; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); @@ -987,19 +988,15 @@ gimp_display_shell_untransform_viewport (GimpDisplayShell *shell, x2 = ceil (x2); y2 = ceil (y2); - image = gimp_display_get_image (shell->display); + if (clip) + { + GimpImage *image = gimp_display_get_image (shell->display); - if (x1 < 0) - x1 = 0; - - if (y1 < 0) - y1 = 0; - - if (x2 > gimp_image_get_width (image)) - x2 = gimp_image_get_width (image); - - if (y2 > gimp_image_get_height (image)) - y2 = gimp_image_get_height (image); + x1 = MAX (x1, 0); + y1 = MAX (y1, 0); + x2 = MIN (x2, gimp_image_get_width (image)); + y2 = MIN (y2, gimp_image_get_height (image)); + } if (x) *x = x1; if (y) *y = y1; diff --git a/app/display/gimpdisplayshell-transform.h b/app/display/gimpdisplayshell-transform.h index 5a1ccba4ca..1877b13f03 100644 --- a/app/display/gimpdisplayshell-transform.h +++ b/app/display/gimpdisplayshell-transform.h @@ -190,6 +190,7 @@ void gimp_display_shell_untransform_bounds_with_scale (GimpDisplayShell *shel gdouble *ny2); void gimp_display_shell_untransform_viewport (GimpDisplayShell *shell, + gboolean clip, gint *x, gint *y, gint *width, diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 54c78488a1..1100371ead 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -973,7 +973,8 @@ gimp_display_shell_set_priority_viewport (GimpDisplayShell *shell) gint x, y; gint width, height; - gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, + &x, &y, &width, &height); gimp_projection_set_priority_rect (projection, x, y, width, height); } } @@ -1788,6 +1789,8 @@ gimp_display_shell_set_show_all (GimpDisplayShell *shell, gimp_display_update_bounding_box (shell->display); + gimp_display_shell_set_priority_viewport (shell); + gimp_display_shell_expose_full (shell); g_object_notify (G_OBJECT (shell), "show-all"); diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c index 78584107bd..f596758f2e 100644 --- a/app/tools/gimpfiltertool.c +++ b/app/tools/gimpfiltertool.c @@ -729,7 +729,7 @@ gimp_filter_tool_options_notify (GimpTool *tool, GimpItem *item = GIMP_ITEM (tool->drawable); gint x, y, width, height; - gimp_display_shell_untransform_viewport (shell, + gimp_display_shell_untransform_viewport (shell, TRUE, &x, &y, &width, &height); if (gimp_rectangle_intersect (gimp_item_get_offset_x (item), diff --git a/app/tools/gimpseamlessclonetool.c b/app/tools/gimpseamlessclonetool.c index 4848c702a5..79a97806d3 100644 --- a/app/tools/gimpseamlessclonetool.c +++ b/app/tools/gimpseamlessclonetool.c @@ -792,7 +792,8 @@ gimp_seamless_clone_tool_filter_update (GimpSeamlessCloneTool *sc) /* Find out at which x,y is the top left corner of the currently * displayed part */ - gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h); + gimp_display_shell_untransform_viewport (shell, ! shell->show_all, + &x, &y, &w, &h); /* Find out where is our drawable positioned */ gimp_item_get_offset (item, &off_x, &off_y);