2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2016-07-24 21:01:12 +08:00
|
|
|
#include <math.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-03-09 21:00:01 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2008-08-03 19:35:53 +08:00
|
|
|
#include "config/gimpdisplayconfig.h"
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2008-08-22 23:57:41 +08:00
|
|
|
#include "gimpcanvas.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "gimpdisplay-foreach.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "gimpdisplayshell.h"
|
2009-10-03 05:55:26 +08:00
|
|
|
#include "gimpdisplayshell-expose.h"
|
2019-07-16 05:24:35 +08:00
|
|
|
#include "gimpdisplayshell-render.h"
|
2016-07-17 03:21:56 +08:00
|
|
|
#include "gimpdisplayshell-rotate.h"
|
2016-01-06 01:02:59 +08:00
|
|
|
#include "gimpdisplayshell-rulers.h"
|
2003-03-22 00:28:06 +08:00
|
|
|
#include "gimpdisplayshell-scale.h"
|
2001-11-02 17:31:21 +08:00
|
|
|
#include "gimpdisplayshell-scroll.h"
|
2016-01-06 01:02:59 +08:00
|
|
|
#include "gimpdisplayshell-scrollbars.h"
|
2016-01-05 22:14:08 +08:00
|
|
|
#include "gimpdisplayshell-transform.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-01-06 01:02:59 +08:00
|
|
|
#define OVERPAN_FACTOR 0.5
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
|
2016-01-06 00:33:22 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll:
|
|
|
|
* @shell:
|
|
|
|
* @x_offset:
|
|
|
|
* @y_offset:
|
|
|
|
*
|
|
|
|
* This function scrolls the image in the shell's viewport. It does
|
|
|
|
* actual scrolling of the pixels, so only the newly scrolled-in parts
|
|
|
|
* are freshly redrawn.
|
|
|
|
*
|
|
|
|
* Use it for incremental actual panning.
|
|
|
|
**/
|
2008-07-11 02:44:30 +08:00
|
|
|
void
|
2008-08-10 19:11:19 +08:00
|
|
|
gimp_display_shell_scroll (GimpDisplayShell *shell,
|
|
|
|
gint x_offset,
|
|
|
|
gint y_offset)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-02-21 21:07:15 +08:00
|
|
|
gint old_x;
|
|
|
|
gint old_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-07-11 02:44:30 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2001-10-13 20:52:30 +08:00
|
|
|
|
2008-08-27 01:53:54 +08:00
|
|
|
if (x_offset == 0 && y_offset == 0)
|
|
|
|
return;
|
|
|
|
|
2001-11-02 17:31:21 +08:00
|
|
|
old_x = shell->offset_x;
|
|
|
|
old_y = shell->offset_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-01-06 00:33:22 +08:00
|
|
|
/* freeze the active tool */
|
|
|
|
gimp_display_shell_pause (shell);
|
|
|
|
|
2001-11-02 17:31:21 +08:00
|
|
|
shell->offset_x += x_offset;
|
|
|
|
shell->offset_y += y_offset;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-01-06 00:33:22 +08:00
|
|
|
gimp_display_shell_scroll_clamp_and_update (shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the actual changes in offset */
|
2001-11-02 17:31:21 +08:00
|
|
|
x_offset = (shell->offset_x - old_x);
|
|
|
|
y_offset = (shell->offset_y - old_y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (x_offset || y_offset)
|
|
|
|
{
|
2016-01-06 03:29:54 +08:00
|
|
|
gimp_display_shell_scrolled (shell);
|
|
|
|
|
2009-10-19 04:19:29 +08:00
|
|
|
gimp_overlay_box_scroll (GIMP_OVERLAY_BOX (shell->canvas),
|
|
|
|
-x_offset, -y_offset);
|
2003-03-07 20:34:40 +08:00
|
|
|
|
2019-07-16 05:24:35 +08:00
|
|
|
if (shell->render_cache)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2019-09-12 02:00:32 +08:00
|
|
|
surface = cairo_surface_create_similar_image (
|
|
|
|
shell->render_cache,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
shell->disp_width * shell->render_scale,
|
|
|
|
shell->disp_height * shell->render_scale);
|
2019-07-16 05:24:35 +08:00
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
2019-07-17 06:18:00 +08:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2019-07-16 05:24:35 +08:00
|
|
|
cairo_set_source_surface (cr, shell->render_cache, 0, 0);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
cr = cairo_create (shell->render_cache);
|
2019-07-17 06:18:00 +08:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
2019-07-16 05:24:35 +08:00
|
|
|
cairo_set_source_surface (cr, surface,
|
2019-09-12 02:00:32 +08:00
|
|
|
-x_offset * shell->render_scale,
|
|
|
|
-y_offset * shell->render_scale);
|
2019-07-16 05:24:35 +08:00
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shell->render_cache_valid)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
cairo_region_translate (shell->render_cache_valid,
|
|
|
|
-x_offset, -y_offset);
|
|
|
|
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
|
|
|
rect.width = shell->disp_width;
|
|
|
|
rect.height = shell->disp_height;
|
|
|
|
|
|
|
|
cairo_region_intersect_rectangle (shell->render_cache_valid, &rect);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2016-01-06 00:33:22 +08:00
|
|
|
|
|
|
|
/* re-enable the active tool */
|
|
|
|
gimp_display_shell_resume (shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-10-13 20:52:30 +08:00
|
|
|
|
2016-01-06 00:33:22 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_set_offsets:
|
|
|
|
* @shell:
|
|
|
|
* @offset_x:
|
|
|
|
* @offset_y:
|
|
|
|
*
|
|
|
|
* This function scrolls the image in the shell's viewport. It redraws
|
|
|
|
* the entire canvas.
|
|
|
|
*
|
|
|
|
* Use it for setting the scroll offset on freshly scaled images or
|
|
|
|
* when the window is resized. For panning, use
|
|
|
|
* gimp_display_shell_scroll().
|
|
|
|
**/
|
2008-08-10 21:09:24 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_set_offset (GimpDisplayShell *shell,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (shell->offset_x == offset_x &&
|
|
|
|
shell->offset_y == offset_y)
|
|
|
|
return;
|
|
|
|
|
2016-01-06 02:18:40 +08:00
|
|
|
gimp_display_shell_scale_save_revert_values (shell);
|
2008-08-10 21:09:24 +08:00
|
|
|
|
|
|
|
/* freeze the active tool */
|
|
|
|
gimp_display_shell_pause (shell);
|
|
|
|
|
|
|
|
shell->offset_x = offset_x;
|
|
|
|
shell->offset_y = offset_y;
|
|
|
|
|
2008-08-14 22:41:29 +08:00
|
|
|
gimp_display_shell_scroll_clamp_and_update (shell);
|
|
|
|
|
2016-01-06 00:33:22 +08:00
|
|
|
gimp_display_shell_scrolled (shell);
|
|
|
|
|
2016-01-06 03:29:54 +08:00
|
|
|
gimp_display_shell_expose_full (shell);
|
2019-07-16 05:24:35 +08:00
|
|
|
gimp_display_shell_render_invalidate_full (shell);
|
2016-01-06 03:29:54 +08:00
|
|
|
|
2008-08-10 21:09:24 +08:00
|
|
|
/* re-enable the active tool */
|
|
|
|
gimp_display_shell_resume (shell);
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:38:56 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_clamp_and_update:
|
|
|
|
* @shell:
|
|
|
|
*
|
|
|
|
* Helper function for calling two functions that are commonly called
|
|
|
|
* in pairs.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_clamp_and_update (GimpDisplayShell *shell)
|
2001-10-13 20:52:30 +08:00
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image;
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
2001-10-13 20:52:30 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (shell->display);
|
|
|
|
|
|
|
|
if (image)
|
2008-03-19 05:22:21 +08:00
|
|
|
{
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
if (! shell->show_all)
|
2008-07-12 15:00:46 +08:00
|
|
|
{
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
gint bounds_x;
|
|
|
|
gint bounds_y;
|
|
|
|
gint bounds_width;
|
|
|
|
gint bounds_height;
|
|
|
|
gint min_offset_x;
|
|
|
|
gint max_offset_x;
|
|
|
|
gint min_offset_y;
|
|
|
|
gint max_offset_y;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2008-07-12 22:48:09 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
gimp_display_shell_rotate_update_transform (shell);
|
2008-07-12 15:00:46 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
gimp_display_shell_scale_get_image_bounds (shell,
|
|
|
|
&bounds_x,
|
|
|
|
&bounds_y,
|
|
|
|
&bounds_width,
|
|
|
|
&bounds_height);
|
|
|
|
|
|
|
|
if (shell->disp_width < bounds_width)
|
|
|
|
{
|
|
|
|
min_offset_x = bounds_x -
|
|
|
|
shell->disp_width * OVERPAN_FACTOR;
|
|
|
|
max_offset_x = bounds_x + bounds_width -
|
|
|
|
shell->disp_width * (1.0 - OVERPAN_FACTOR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint overpan_amount;
|
|
|
|
|
|
|
|
overpan_amount = shell->disp_width -
|
|
|
|
bounds_width * (1.0 - OVERPAN_FACTOR);
|
|
|
|
|
|
|
|
min_offset_x = bounds_x -
|
|
|
|
overpan_amount;
|
|
|
|
max_offset_x = bounds_x + bounds_width - shell->disp_width +
|
|
|
|
overpan_amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shell->disp_height < bounds_height)
|
|
|
|
{
|
|
|
|
min_offset_y = bounds_y -
|
|
|
|
shell->disp_height * OVERPAN_FACTOR;
|
|
|
|
max_offset_y = bounds_y + bounds_height -
|
|
|
|
shell->disp_height * (1.0 - OVERPAN_FACTOR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint overpan_amount;
|
|
|
|
|
|
|
|
overpan_amount = shell->disp_height -
|
|
|
|
bounds_height * (1.0 - OVERPAN_FACTOR);
|
|
|
|
|
|
|
|
min_offset_y = bounds_y -
|
|
|
|
overpan_amount;
|
|
|
|
max_offset_y = bounds_y + bounds_height +
|
|
|
|
overpan_amount - shell->disp_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clamp */
|
|
|
|
|
|
|
|
offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x);
|
|
|
|
offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y);
|
|
|
|
|
|
|
|
if (offset_x != shell->offset_x || offset_y != shell->offset_y)
|
|
|
|
{
|
|
|
|
shell->offset_x = offset_x;
|
|
|
|
shell->offset_y = offset_y;
|
|
|
|
|
|
|
|
gimp_display_shell_rotate_update_transform (shell);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set scrollbar stepper sensitiity */
|
|
|
|
|
|
|
|
gimp_display_shell_scrollbars_update_steppers (shell,
|
|
|
|
min_offset_x,
|
|
|
|
max_offset_x,
|
|
|
|
min_offset_y,
|
|
|
|
max_offset_y);
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
/* Set scrollbar stepper sensitiity */
|
2016-07-17 03:21:56 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
gimp_display_shell_scrollbars_update_steppers (shell,
|
|
|
|
G_MININT,
|
|
|
|
G_MAXINT,
|
|
|
|
G_MININT,
|
|
|
|
G_MAXINT);
|
2016-07-17 03:21:56 +08:00
|
|
|
}
|
2008-03-19 05:22:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell->offset_x = 0;
|
|
|
|
shell->offset_y = 0;
|
|
|
|
}
|
2013-04-19 00:45:55 +08:00
|
|
|
|
2016-01-06 01:02:59 +08:00
|
|
|
gimp_display_shell_scrollbars_update (shell);
|
|
|
|
gimp_display_shell_rulers_update (shell);
|
2008-08-14 22:41:29 +08:00
|
|
|
}
|
|
|
|
|
2008-08-27 02:50:54 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_unoverscrollify:
|
|
|
|
* @shell:
|
|
|
|
* @in_offset_x:
|
|
|
|
* @in_offset_y:
|
|
|
|
* @out_offset_x:
|
|
|
|
* @out_offset_y:
|
|
|
|
*
|
|
|
|
* Takes a scroll offset and returns the offset that will not result
|
|
|
|
* in a scroll beyond the image border. If the image is already
|
|
|
|
* overscrolled, the return value is 0 for that given axis.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_unoverscrollify (GimpDisplayShell *shell,
|
|
|
|
gint in_offset_x,
|
|
|
|
gint in_offset_y,
|
|
|
|
gint *out_offset_x,
|
|
|
|
gint *out_offset_y)
|
|
|
|
{
|
|
|
|
gint sw, sh;
|
|
|
|
gint out_offset_x_dummy, out_offset_y_dummy;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! out_offset_x) out_offset_x = &out_offset_x_dummy;
|
|
|
|
if (! out_offset_y) out_offset_y = &out_offset_y_dummy;
|
|
|
|
|
|
|
|
*out_offset_x = in_offset_x;
|
|
|
|
*out_offset_y = in_offset_y;
|
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
if (! shell->show_all)
|
2008-08-27 02:50:54 +08:00
|
|
|
{
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
gimp_display_shell_scale_get_image_size (shell, &sw, &sh);
|
2008-08-27 02:50:54 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
if (in_offset_x < 0)
|
|
|
|
{
|
|
|
|
*out_offset_x = MAX (in_offset_x,
|
|
|
|
MIN (0, 0 - shell->offset_x));
|
|
|
|
}
|
|
|
|
else if (in_offset_x > 0)
|
|
|
|
{
|
|
|
|
gint min_offset = sw - shell->disp_width;
|
2008-08-27 02:50:54 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
*out_offset_x = MIN (in_offset_x,
|
|
|
|
MAX (0, min_offset - shell->offset_x));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_offset_y < 0)
|
|
|
|
{
|
|
|
|
*out_offset_y = MAX (in_offset_y,
|
|
|
|
MIN (0, 0 - shell->offset_y));
|
|
|
|
}
|
|
|
|
else if (in_offset_y > 0)
|
|
|
|
{
|
|
|
|
gint min_offset = sh - shell->disp_height;
|
2008-08-27 02:50:54 +08:00
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
*out_offset_y = MIN (in_offset_y,
|
|
|
|
MAX (0, min_offset - shell->offset_y));
|
|
|
|
}
|
2008-08-27 02:50:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 22:50:09 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_center_image_xy:
|
|
|
|
* @shell:
|
|
|
|
* @image_x:
|
|
|
|
* @image_y:
|
|
|
|
*
|
|
|
|
* Center the viewport around the passed image coordinate
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_center_image_xy (GimpDisplayShell *shell,
|
|
|
|
gdouble image_x,
|
|
|
|
gdouble image_y)
|
|
|
|
{
|
|
|
|
gint viewport_x;
|
|
|
|
gint viewport_y;
|
|
|
|
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
|
|
|
image_x, image_y,
|
|
|
|
&viewport_x, &viewport_y);
|
|
|
|
|
|
|
|
gimp_display_shell_scroll (shell,
|
|
|
|
viewport_x - shell->disp_width / 2,
|
|
|
|
viewport_y - shell->disp_height / 2);
|
|
|
|
}
|
|
|
|
|
2008-08-10 15:23:14 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_center_image:
|
|
|
|
* @shell:
|
|
|
|
* @horizontally:
|
|
|
|
* @vertically:
|
|
|
|
*
|
|
|
|
* Centers the image in the display shell on the desired axes.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_center_image (GimpDisplayShell *shell,
|
|
|
|
gboolean horizontally,
|
|
|
|
gboolean vertically)
|
|
|
|
{
|
2016-07-24 21:01:12 +08:00
|
|
|
gint image_x;
|
|
|
|
gint image_y;
|
|
|
|
gint image_width;
|
|
|
|
gint image_height;
|
|
|
|
gint center_x;
|
|
|
|
gint center_y;
|
|
|
|
gint offset_x = 0;
|
|
|
|
gint offset_y = 0;
|
2008-08-10 15:23:14 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
if (! shell->display ||
|
|
|
|
! gimp_display_get_image (shell->display) ||
|
2008-08-15 03:23:28 +08:00
|
|
|
(! vertically && ! horizontally))
|
2008-08-10 15:23:14 +08:00
|
|
|
return;
|
|
|
|
|
2016-07-24 21:01:12 +08:00
|
|
|
gimp_display_shell_scale_get_image_bounds (shell,
|
|
|
|
&image_x, &image_y,
|
|
|
|
&image_width, &image_height);
|
2008-08-10 15:23:14 +08:00
|
|
|
|
2016-07-24 21:01:12 +08:00
|
|
|
if (shell->disp_width > image_width)
|
|
|
|
{
|
|
|
|
image_x -= (shell->disp_width - image_width) / 2;
|
|
|
|
image_width = shell->disp_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shell->disp_height > image_height)
|
|
|
|
{
|
|
|
|
image_y -= (shell->disp_height - image_height) / 2;
|
|
|
|
image_height = shell->disp_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
center_x = image_x + image_width / 2;
|
|
|
|
center_y = image_y + image_height / 2;
|
2008-08-10 15:23:14 +08:00
|
|
|
|
|
|
|
if (horizontally)
|
2016-07-24 21:01:12 +08:00
|
|
|
offset_x = center_x - shell->disp_width / 2 - shell->offset_x;
|
2008-08-10 15:23:14 +08:00
|
|
|
|
|
|
|
if (vertically)
|
2016-07-24 21:01:12 +08:00
|
|
|
offset_y = center_y - shell->disp_height / 2 - shell->offset_y;
|
2008-08-10 15:23:14 +08:00
|
|
|
|
2016-01-05 22:50:09 +08:00
|
|
|
gimp_display_shell_scroll (shell, offset_x, offset_y);
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
app: improve display scroll/zoom-related behavior in "show all" mode
In "show all" mode, the image is thought to be "infinite"; this
commit improves the overall scrolling/zooming behavior in this mode
according to this assumption. In cases where a specific image size
is needed (e.g., for the scrollbar bounds, fit-image-in-window,
etc.), the image's full bounding box is used; however, in cases
where a center point is needed (e.g., for the zoomed-out scrollbar
bounds, center-image-in-window), the canvas center, rather than the
bounding-box center, is still used.
2019-09-04 21:11:54 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_center_image:
|
|
|
|
* @shell:
|
|
|
|
* @horizontally:
|
|
|
|
* @vertically:
|
|
|
|
*
|
|
|
|
* Centers the image content in the display shell on the desired axes.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_scroll_center_content (GimpDisplayShell *shell,
|
|
|
|
gboolean horizontally,
|
|
|
|
gboolean vertically)
|
|
|
|
{
|
|
|
|
gint content_x;
|
|
|
|
gint content_y;
|
|
|
|
gint content_width;
|
|
|
|
gint content_height;
|
|
|
|
gint center_x;
|
|
|
|
gint center_y;
|
|
|
|
gint offset_x = 0;
|
|
|
|
gint offset_y = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! shell->display ||
|
|
|
|
! gimp_display_get_image (shell->display) ||
|
|
|
|
(! vertically && ! horizontally))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_display_shell_scale_get_image_bounding_box (shell,
|
|
|
|
&content_x,
|
|
|
|
&content_y,
|
|
|
|
&content_width,
|
|
|
|
&content_height);
|
|
|
|
|
|
|
|
if (shell->disp_width > content_width)
|
|
|
|
{
|
|
|
|
content_x -= (shell->disp_width - content_width) / 2;
|
|
|
|
content_width = shell->disp_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shell->disp_height > content_height)
|
|
|
|
{
|
|
|
|
content_y -= (shell->disp_height - content_height) / 2;
|
|
|
|
content_height = shell->disp_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
center_x = content_x + content_width / 2;
|
|
|
|
center_y = content_y + content_height / 2;
|
|
|
|
|
|
|
|
if (horizontally)
|
|
|
|
offset_x = center_x - shell->disp_width / 2 - shell->offset_x;
|
|
|
|
|
|
|
|
if (vertically)
|
|
|
|
offset_y = center_y - shell->disp_height / 2 - shell->offset_y;
|
|
|
|
|
|
|
|
gimp_display_shell_scroll (shell, offset_x, offset_y);
|
|
|
|
}
|
|
|
|
|
2008-07-11 04:19:17 +08:00
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_get_scaled_viewport:
|
2008-07-11 04:19:17 +08:00
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
* @w:
|
|
|
|
* @h:
|
|
|
|
*
|
|
|
|
* Gets the viewport in screen coordinates, with origin at (0, 0) in
|
2016-01-05 22:50:09 +08:00
|
|
|
* the image.
|
2008-07-11 04:19:17 +08:00
|
|
|
**/
|
|
|
|
void
|
2016-01-05 22:50:09 +08:00
|
|
|
gimp_display_shell_scroll_get_scaled_viewport (GimpDisplayShell *shell,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *w,
|
|
|
|
gint *h)
|
2008-07-11 04:19:17 +08:00
|
|
|
{
|
2008-07-12 04:03:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
*x = shell->offset_x;
|
|
|
|
*y = shell->offset_y;
|
|
|
|
*w = shell->disp_width;
|
|
|
|
*h = shell->disp_height;
|
2008-07-11 04:19:17 +08:00
|
|
|
}
|
2008-07-11 11:20:17 +08:00
|
|
|
|
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_get_viewport:
|
2008-07-11 11:20:17 +08:00
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
* @w:
|
|
|
|
* @h:
|
|
|
|
*
|
2016-01-05 22:50:09 +08:00
|
|
|
* Gets the viewport in image coordinates.
|
2008-07-11 11:20:17 +08:00
|
|
|
**/
|
|
|
|
void
|
2016-01-05 22:50:09 +08:00
|
|
|
gimp_display_shell_scroll_get_viewport (GimpDisplayShell *shell,
|
|
|
|
gdouble *x,
|
|
|
|
gdouble *y,
|
|
|
|
gdouble *w,
|
|
|
|
gdouble *h)
|
2008-07-11 11:20:17 +08:00
|
|
|
{
|
2008-07-12 04:03:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
*x = shell->offset_x / shell->scale_x;
|
|
|
|
*y = shell->offset_y / shell->scale_y;
|
|
|
|
*w = shell->disp_width / shell->scale_x;
|
|
|
|
*h = shell->disp_height / shell->scale_y;
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|