From 2d6e80b8ed060bbfe524ef9fce3bd153dd0403fa Mon Sep 17 00:00:00 2001 From: Ell Date: Sun, 15 Sep 2019 16:22:06 +0300 Subject: [PATCH] app: behave as if "show all" is disabled in scroll/zoom actions when keeping padding --- app/display/gimpdisplayshell-appearance.c | 9 +++- app/display/gimpdisplayshell-callbacks.c | 2 +- app/display/gimpdisplayshell-handlers.c | 2 +- app/display/gimpdisplayshell-scale.c | 51 +++++++++++++++++++++-- app/display/gimpdisplayshell-scale.h | 6 +++ app/display/gimpdisplayshell-scroll.c | 21 +++++++--- app/display/gimpdisplayshell-scrollbars.c | 30 ++++++++++--- app/display/gimpdisplayshell.c | 9 ++++ app/display/gimpdisplayshell.h | 2 + app/display/gimpimagewindow.c | 14 +++++-- 10 files changed, 125 insertions(+), 21 deletions(-) diff --git a/app/display/gimpdisplayshell-appearance.c b/app/display/gimpdisplayshell-appearance.c index 80aedc9b8b..6952f7bfe4 100644 --- a/app/display/gimpdisplayshell-appearance.c +++ b/app/display/gimpdisplayshell-appearance.c @@ -38,6 +38,8 @@ #include "gimpdisplayshell-appearance.h" #include "gimpdisplayshell-expose.h" #include "gimpdisplayshell-selection.h" +#include "gimpdisplayshell-scroll.h" +#include "gimpdisplayshell-scrollbars.h" #include "gimpimagewindow.h" #include "gimpstatusbar.h" @@ -541,7 +543,12 @@ gimp_display_shell_set_padding_in_show_all (GimpDisplayShell *shell, g_object_set (options, "padding-in-show-all", keep, NULL); if (shell->display) - gimp_display_shell_expose_full (shell); + { + gimp_display_shell_scroll_clamp_and_update (shell); + gimp_display_shell_scrollbars_update (shell); + + gimp_display_shell_expose_full (shell); + } gimp_display_shell_set_action_active (shell, "view-padding-color-in-show-all", diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index aed9e92e91..2891bf4e8a 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -190,7 +190,7 @@ gimp_display_shell_canvas_tick (GtkWidget *widget, center_horizontally = sw <= shell->disp_width; center_vertically = sh <= shell->disp_height; - if (! shell->show_all) + if (! gimp_display_shell_get_infinite_canvas (shell)) { gimp_display_shell_scroll_center_image (shell, center_horizontally, diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c index 5ce0184a5f..2d7e65e89b 100644 --- a/app/display/gimpdisplayshell-handlers.c +++ b/app/display/gimpdisplayshell-handlers.c @@ -885,7 +885,7 @@ gimp_display_shell_size_changed_detailed_handler (GimpImage *image, shell->offset_x + scaled_previous_origin_x, shell->offset_y + scaled_previous_origin_y); - if (! shell->show_all) + if (! gimp_display_shell_get_infinite_canvas (shell)) { gimp_display_shell_scroll_center_image (shell, horizontally, vertically); diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index a44b6d9fc7..8e61eb47ae 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -275,6 +275,36 @@ gimp_display_shell_scale_get_image_bounds (GimpDisplayShell *shell, if (h) *h = y2 - y1; } +/** + * gimp_display_shell_scale_get_image_unrotated_bounds: + * @shell: + * @x: + * @y: + * @w: + * @h: + * + * Gets the screen-space boudning box of the image, after it has + * been scaled and scrolled, but before it has been rotated. + **/ +void +gimp_display_shell_scale_get_image_unrotated_bounds (GimpDisplayShell *shell, + gint *x, + gint *y, + gint *w, + gint *h) +{ + GimpImage *image; + + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + image = gimp_display_get_image (shell->display); + + if (x) *x = -shell->offset_x; + if (y) *y = -shell->offset_y; + if (w) *w = floor (gimp_image_get_width (image) * shell->scale_x); + if (h) *h = floor (gimp_image_get_height (image) * shell->scale_y); +} + /** * gimp_display_shell_scale_get_image_bounding_box: * @shell: @@ -406,7 +436,7 @@ gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell, if (! horizontally) horizontally = &horizontally_dummy; if (! vertically) vertically = &vertically_dummy; - if (! shell->show_all) + if (! gimp_display_shell_get_infinite_canvas (shell)) { gint sx, sy; gint sw, sh; @@ -1130,7 +1160,19 @@ gimp_display_shell_scale_fit_or_fill (GimpDisplayShell *shell, gdouble current_scale; gdouble zoom_factor; - bounding_box = gimp_display_shell_get_bounding_box (shell); + if (! gimp_display_shell_get_infinite_canvas (shell)) + { + GimpImage *image = gimp_display_get_image (shell->display); + + bounding_box.x = 0; + bounding_box.y = 0; + bounding_box.width = gimp_image_get_width (image); + bounding_box.height = gimp_image_get_height (image); + } + else + { + bounding_box = gimp_display_shell_get_bounding_box (shell); + } gimp_display_shell_transform_bounds (shell, bounding_box.x, @@ -1180,7 +1222,8 @@ gimp_display_shell_scale_image_starts_to_fit (GimpDisplayShell *shell, if (! horizontally) horizontally = &horizontally_dummy; /* The image can only start to fit if we zoom out */ - if (new_scale > current_scale || shell->show_all) + if (new_scale > current_scale || + gimp_display_shell_get_infinite_canvas (shell)) { *vertically = FALSE; *horizontally = FALSE; @@ -1246,7 +1289,7 @@ gimp_display_shell_scale_viewport_coord_almost_centered (GimpDisplayShell *shell gint center_x = shell->disp_width / 2; gint center_y = shell->disp_height / 2; - if (! shell->show_all) + if (! gimp_display_shell_get_infinite_canvas (shell)) { local_horizontally = (x > center_x - ALMOST_CENTERED_THRESHOLD && x < center_x + ALMOST_CENTERED_THRESHOLD); diff --git a/app/display/gimpdisplayshell-scale.h b/app/display/gimpdisplayshell-scale.h index 7f38eb0264..b97f9fb509 100644 --- a/app/display/gimpdisplayshell-scale.h +++ b/app/display/gimpdisplayshell-scale.h @@ -34,6 +34,12 @@ void gimp_display_shell_scale_get_image_bounds (GimpDisplayShell *shell, gint *y, gint *w, gint *h); +void gimp_display_shell_scale_get_image_unrotated_bounds + (GimpDisplayShell *shell, + gint *x, + gint *y, + gint *w, + gint *h); void gimp_display_shell_scale_get_image_bounding_box (GimpDisplayShell *shell, gint *x, diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c index 453574b2f7..0c340d74a3 100644 --- a/app/display/gimpdisplayshell-scroll.c +++ b/app/display/gimpdisplayshell-scroll.c @@ -480,11 +480,22 @@ gimp_display_shell_scroll_center_content (GimpDisplayShell *shell, (! vertically && ! horizontally)) return; - gimp_display_shell_scale_get_image_bounding_box (shell, - &content_x, - &content_y, - &content_width, - &content_height); + if (! gimp_display_shell_get_infinite_canvas (shell)) + { + gimp_display_shell_scale_get_image_bounds (shell, + &content_x, + &content_y, + &content_width, + &content_height); + } + else + { + gimp_display_shell_scale_get_image_bounding_box (shell, + &content_x, + &content_y, + &content_width, + &content_height); + } if (shell->disp_width > content_width) { diff --git a/app/display/gimpdisplayshell-scrollbars.c b/app/display/gimpdisplayshell-scrollbars.c index 58d964eb8a..3696e01843 100644 --- a/app/display/gimpdisplayshell-scrollbars.c +++ b/app/display/gimpdisplayshell-scrollbars.c @@ -110,9 +110,18 @@ gimp_display_shell_scrollbars_setup_horizontal (GimpDisplayShell *shell, &bounds_x, NULL, &bounds_width, NULL); - gimp_display_shell_scale_get_image_bounding_box (shell, - &bounding_box_x, NULL, - &bounding_box_width, NULL); + if (! gimp_display_shell_get_infinite_canvas (shell)) + { + bounding_box_x = bounds_x; + bounding_box_width = bounds_width; + } + else + { + gimp_display_shell_scale_get_image_bounding_box ( + shell, + &bounding_box_x, NULL, + &bounding_box_width, NULL); + } x1 = bounding_box_x; x2 = bounding_box_x + bounding_box_width; @@ -162,9 +171,18 @@ gimp_display_shell_scrollbars_setup_vertical (GimpDisplayShell *shell, NULL, &bounds_y, NULL, &bounds_height); - gimp_display_shell_scale_get_image_bounding_box (shell, - NULL, &bounding_box_y, - NULL, &bounding_box_height); + if (! gimp_display_shell_get_infinite_canvas (shell)) + { + bounding_box_y = bounds_y; + bounding_box_height = bounds_height; + } + else + { + gimp_display_shell_scale_get_image_bounding_box ( + shell, + NULL, &bounding_box_y, + NULL, &bounding_box_height); + } y1 = bounding_box_y; y2 = bounding_box_y + bounding_box_height; diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 779d1bda91..7128562b04 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -1846,6 +1846,15 @@ gimp_display_shell_get_bounding_box (GimpDisplayShell *shell) return bounding_box; } +gboolean +gimp_display_shell_get_infinite_canvas (GimpDisplayShell *shell) +{ + g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); + + return shell->show_all && + ! gimp_display_shell_get_padding_in_show_all (shell); +} + void gimp_display_shell_update_priority_rect (GimpDisplayShell *shell) { diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index 52df072758..ff3a7d3048 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -319,6 +319,8 @@ void gimp_display_shell_set_show_all (GimpDisplayShell *shell, GimpPickable * gimp_display_shell_get_pickable (GimpDisplayShell *shell); GeglRectangle gimp_display_shell_get_bounding_box (GimpDisplayShell *shell); +gboolean gimp_display_shell_get_infinite_canvas + (GimpDisplayShell *shell); void gimp_display_shell_update_priority_rect (GimpDisplayShell *shell); diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c index f8d206264c..c0df5b276f 100644 --- a/app/display/gimpimagewindow.c +++ b/app/display/gimpimagewindow.c @@ -1472,9 +1472,17 @@ gimp_image_window_shrink_wrap (GimpImageWindow *window, gdk_monitor_get_workarea (monitor, &rect); - gimp_display_shell_scale_get_image_bounding_box (active_shell, - NULL, NULL, - &width, &height); + if (! gimp_display_shell_get_infinite_canvas (active_shell)) + { + gimp_display_shell_scale_get_image_size (active_shell, + &width, &height); + } + else + { + gimp_display_shell_scale_get_image_bounding_box (active_shell, + NULL, NULL, + &width, &height); + } disp_width = active_shell->disp_width; disp_height = active_shell->disp_height;