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
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
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>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
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-07-13 15:40:11 +08:00
|
|
|
#include "base/tile-manager.h"
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "core/gimpimage.h"
|
2008-07-13 15:40:11 +08:00
|
|
|
#include "core/gimpprojection.h"
|
2001-07-08 01:36:00 +08:00
|
|
|
|
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"
|
2008-07-11 03:23:22 +08:00
|
|
|
#include "gimpdisplayshell-private.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"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2008-07-12 22:48:09 +08:00
|
|
|
#define OVERPAN_FACTOR 0.5
|
|
|
|
|
|
|
|
|
2008-07-12 22:26:49 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_center_around_image_coordinate:
|
|
|
|
* @shell:
|
|
|
|
* @image_x:
|
|
|
|
* @image_y:
|
|
|
|
*
|
|
|
|
* Center the viewport around the passed image coordinate
|
|
|
|
*
|
|
|
|
**/
|
2008-07-12 22:20:54 +08:00
|
|
|
void
|
|
|
|
gimp_display_shell_center_around_image_coordinate (GimpDisplayShell *shell,
|
|
|
|
gdouble image_x,
|
|
|
|
gdouble image_y)
|
2008-07-11 03:23:22 +08:00
|
|
|
{
|
2008-07-12 22:20:54 +08:00
|
|
|
gint scaled_image_x;
|
|
|
|
gint scaled_image_y;
|
|
|
|
gint offset_to_apply_x;
|
|
|
|
gint offset_to_apply_y;
|
|
|
|
|
|
|
|
scaled_image_x = RINT (image_x * shell->scale_x);
|
|
|
|
scaled_image_y = RINT (image_y * shell->scale_y);
|
2008-07-11 03:23:22 +08:00
|
|
|
|
2008-07-12 22:20:54 +08:00
|
|
|
offset_to_apply_x = scaled_image_x - shell->disp_width / 2 - shell->offset_x;
|
|
|
|
offset_to_apply_y = scaled_image_y - shell->disp_height / 2 - shell->offset_y;
|
2008-07-11 03:23:22 +08:00
|
|
|
|
2008-07-12 22:20:54 +08:00
|
|
|
gimp_display_shell_scroll_private (shell,
|
|
|
|
offset_to_apply_x,
|
|
|
|
offset_to_apply_y);
|
2008-07-11 03:23:22 +08:00
|
|
|
}
|
|
|
|
|
2008-07-11 02:44:30 +08:00
|
|
|
void
|
2008-07-11 03:23:22 +08:00
|
|
|
gimp_display_shell_scroll_private (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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_scroll_clamp_offsets (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)
|
|
|
|
{
|
|
|
|
/* reset the old values so that the tool can accurately redraw */
|
2001-11-02 17:31:21 +08:00
|
|
|
shell->offset_x = old_x;
|
|
|
|
shell->offset_y = old_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-09-12 06:24:30 +08:00
|
|
|
gimp_display_shell_pause (shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* set the offsets back to the new values */
|
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
|
|
|
|
2003-03-22 00:28:06 +08:00
|
|
|
gdk_window_scroll (shell->canvas->window, -x_offset, -y_offset);
|
|
|
|
|
2003-03-07 20:34:40 +08:00
|
|
|
/* Make sure expose events are processed before scrolling again */
|
|
|
|
gdk_window_process_updates (shell->canvas->window, FALSE);
|
|
|
|
|
2003-03-22 00:28:06 +08:00
|
|
|
/* Update scrollbars and rulers */
|
|
|
|
gimp_display_shell_scale_setup (shell);
|
|
|
|
|
2003-09-12 06:24:30 +08:00
|
|
|
gimp_display_shell_resume (shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-02-21 20:16:43 +08:00
|
|
|
gimp_display_shell_scrolled (shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
2001-10-13 20:52:30 +08:00
|
|
|
|
|
|
|
void
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell)
|
2001-10-13 20:52:30 +08:00
|
|
|
{
|
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
|
|
|
|
2008-03-19 05:22:21 +08:00
|
|
|
if (shell->display->image)
|
|
|
|
{
|
2008-07-05 23:43:39 +08:00
|
|
|
gint sw, sh;
|
2008-07-12 22:48:09 +08:00
|
|
|
gint min_offset_x;
|
|
|
|
gint max_offset_x;
|
|
|
|
gint min_offset_y;
|
|
|
|
gint max_offset_y;
|
2008-03-19 05:22:21 +08:00
|
|
|
|
2008-07-05 23:43:39 +08:00
|
|
|
sw = SCALEX (shell, gimp_image_get_width (shell->display->image));
|
|
|
|
sh = SCALEY (shell, gimp_image_get_height (shell->display->image));
|
2001-10-13 20:52:30 +08:00
|
|
|
|
2008-07-12 22:48:09 +08:00
|
|
|
if (shell->disp_width < sw)
|
2008-07-12 15:00:46 +08:00
|
|
|
{
|
2008-07-12 22:48:09 +08:00
|
|
|
min_offset_x = 0 - shell->disp_width * OVERPAN_FACTOR;
|
|
|
|
max_offset_x = sw - shell->disp_width * (1.0 - OVERPAN_FACTOR);
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-12 22:48:09 +08:00
|
|
|
gint overpan_amount;
|
|
|
|
|
|
|
|
overpan_amount = shell->disp_width - sw * (1.0 - OVERPAN_FACTOR);
|
2008-07-12 15:00:46 +08:00
|
|
|
|
2008-07-12 22:48:09 +08:00
|
|
|
min_offset_x = 0 - overpan_amount;
|
|
|
|
max_offset_x = sw + overpan_amount - shell->disp_width;
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|
|
|
|
|
2008-07-12 22:48:09 +08:00
|
|
|
if (shell->disp_height < sh)
|
2008-07-12 15:00:46 +08:00
|
|
|
{
|
2008-07-12 22:48:09 +08:00
|
|
|
min_offset_y = 0 - shell->disp_height * OVERPAN_FACTOR;
|
|
|
|
max_offset_y = sh - shell->disp_height * (1.0 - OVERPAN_FACTOR);
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-12 22:48:09 +08:00
|
|
|
gint overpan_amount;
|
2008-07-12 15:00:46 +08:00
|
|
|
|
2008-07-12 22:48:09 +08:00
|
|
|
overpan_amount = shell->disp_height - sh * (1.0 - OVERPAN_FACTOR);
|
|
|
|
|
|
|
|
min_offset_y = 0 - overpan_amount;
|
|
|
|
max_offset_y = sh + overpan_amount - shell->disp_height;
|
2008-07-12 15:00:46 +08:00
|
|
|
}
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x);
|
|
|
|
shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y);
|
2008-03-19 05:22:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell->offset_x = 0;
|
|
|
|
shell->offset_y = 0;
|
|
|
|
}
|
2001-10-13 20:52:30 +08:00
|
|
|
}
|
2008-07-11 04:19:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_scaled_viewport:
|
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
* @w:
|
|
|
|
* @h:
|
|
|
|
*
|
|
|
|
* Gets the viewport in screen coordinates, with origin at (0, 0) in
|
|
|
|
* the image
|
2008-07-11 11:20:17 +08:00
|
|
|
*
|
2008-07-11 04:19:17 +08:00
|
|
|
**/
|
|
|
|
void
|
2008-07-12 04:03:36 +08:00
|
|
|
gimp_display_shell_get_scaled_viewport (const GimpDisplayShell *shell,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gint *w,
|
|
|
|
gint *h)
|
2008-07-11 04:19:17 +08:00
|
|
|
{
|
2008-07-12 04:28:37 +08:00
|
|
|
gint scaled_image_viewport_offset_x;
|
|
|
|
gint scaled_image_viewport_offset_y;
|
|
|
|
|
2008-07-12 04:03:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-07-12 04:28:37 +08:00
|
|
|
gimp_display_shell_get_scaled_image_viewport_offset (shell,
|
|
|
|
&scaled_image_viewport_offset_x,
|
|
|
|
&scaled_image_viewport_offset_y);
|
|
|
|
if (x) *x = -scaled_image_viewport_offset_x;
|
|
|
|
if (y) *y = -scaled_image_viewport_offset_y;
|
2008-07-11 04:19:17 +08:00
|
|
|
if (w) *w = shell->disp_width;
|
|
|
|
if (h) *h = shell->disp_height;
|
|
|
|
}
|
2008-07-11 11:20:17 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_viewport:
|
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
* @w:
|
|
|
|
* @h:
|
|
|
|
*
|
|
|
|
* Gets the viewport in image coordinates
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-07-12 04:03:36 +08:00
|
|
|
gimp_display_shell_get_viewport (const 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-07-11 11:20:17 +08:00
|
|
|
if (x) *x = shell->offset_x / shell->scale_x;
|
|
|
|
if (y) *y = shell->offset_y / shell->scale_y;
|
|
|
|
if (w) *w = shell->disp_width / shell->scale_x;
|
|
|
|
if (h) *h = shell->disp_height / shell->scale_y;
|
|
|
|
}
|
2008-07-12 03:31:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_scaled_image_viewport_offset:
|
|
|
|
* @shell:
|
|
|
|
* @x:
|
|
|
|
* @y:
|
|
|
|
*
|
|
|
|
* Gets the scaled image offset in viewport coordinates
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-07-12 04:03:36 +08:00
|
|
|
gimp_display_shell_get_scaled_image_viewport_offset (const GimpDisplayShell *shell,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
2008-07-12 03:31:45 +08:00
|
|
|
{
|
2008-07-12 04:03:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-07-12 15:00:46 +08:00
|
|
|
if (x) *x = -shell->offset_x;
|
|
|
|
if (y) *y = -shell->offset_y;
|
|
|
|
}
|
|
|
|
|
2008-07-13 15:40:11 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_scaled_image_size:
|
|
|
|
* @shell:
|
|
|
|
* @w:
|
|
|
|
* @h:
|
|
|
|
*
|
|
|
|
* Gets the size of the rendered image after it has been scaled.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_get_scaled_image_size (const GimpDisplayShell *shell,
|
|
|
|
gint *w,
|
|
|
|
gint *h)
|
|
|
|
{
|
|
|
|
GimpProjection *proj;
|
|
|
|
TileManager *tiles;
|
|
|
|
gint level;
|
|
|
|
gint level_width;
|
|
|
|
gint level_height;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (shell->display->image));
|
|
|
|
|
|
|
|
proj = shell->display->image->projection;
|
|
|
|
|
|
|
|
level = gimp_projection_get_level (proj, shell->scale_x, shell->scale_y);
|
|
|
|
|
|
|
|
tiles = gimp_projection_get_tiles_at_level (proj, level, NULL);
|
|
|
|
|
|
|
|
level_width = tile_manager_width (tiles);
|
|
|
|
level_height = tile_manager_height (tiles);
|
|
|
|
|
|
|
|
if (w) *w = PROJ_ROUND (level_width * (shell->scale_x * (1 << level)));
|
|
|
|
if (h) *h = PROJ_ROUND (level_height * (shell->scale_y * (1 << level)));
|
|
|
|
}
|
|
|
|
|
2008-07-12 15:00:46 +08:00
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_disp_offset:
|
|
|
|
* @shell:
|
|
|
|
* @disp_xoffset:
|
|
|
|
* @disp_yoffset:
|
|
|
|
*
|
|
|
|
* In viewport coordinates, get the offset of where to start rendering
|
|
|
|
* the scaled image.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_get_disp_offset (const GimpDisplayShell *shell,
|
|
|
|
gint *disp_xoffset,
|
|
|
|
gint *disp_yoffset)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (disp_xoffset)
|
|
|
|
{
|
|
|
|
if (shell->offset_x < 0)
|
|
|
|
{
|
|
|
|
*disp_xoffset = -shell->offset_x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*disp_xoffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disp_yoffset)
|
|
|
|
{
|
|
|
|
if (shell->offset_y < 0)
|
|
|
|
{
|
|
|
|
*disp_yoffset = -shell->offset_y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*disp_yoffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_get_render_start_offset:
|
|
|
|
* @shell:
|
|
|
|
* @offset_x:
|
|
|
|
* @offset_y:
|
|
|
|
*
|
|
|
|
* Get the offset into the scaled image that we should start render
|
|
|
|
* from
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_get_render_start_offset (const GimpDisplayShell *shell,
|
|
|
|
gint *offset_x,
|
|
|
|
gint *offset_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (offset_x) *offset_x = MAX (0, shell->offset_x);
|
|
|
|
if (offset_y) *offset_y = MAX (0, shell->offset_y);
|
2008-07-12 03:31:45 +08:00
|
|
|
}
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_setup_hscrollbar_with_value:
|
|
|
|
* @shell:
|
|
|
|
* @value:
|
|
|
|
*
|
|
|
|
* Setup the limits of the horizontal scrollbar
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_setup_hscrollbar_with_value (GimpDisplayShell *shell,
|
|
|
|
gdouble value)
|
|
|
|
{
|
|
|
|
gint sw;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! shell->display ||
|
|
|
|
! shell->display->image)
|
|
|
|
return;
|
|
|
|
|
2008-07-13 20:22:10 +08:00
|
|
|
gimp_display_shell_get_scaled_image_size (shell, &sw, NULL);
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
if (shell->disp_width < sw)
|
|
|
|
{
|
|
|
|
shell->hsbdata->upper = MAX (value + shell->disp_width,
|
|
|
|
sw);
|
|
|
|
|
|
|
|
shell->hsbdata->lower = MIN (value,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell->hsbdata->lower = MIN (value,
|
|
|
|
-(shell->disp_width - sw) / 2);
|
|
|
|
|
|
|
|
shell->hsbdata->upper = MAX (value + shell->disp_width,
|
|
|
|
sw + (shell->disp_width - sw) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_setup_vscrollbar_with_value:
|
|
|
|
* @shell:
|
|
|
|
* @value:
|
|
|
|
*
|
|
|
|
* Setup the limits of the vertical scrollbar
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_display_shell_setup_vscrollbar_with_value (GimpDisplayShell *shell,
|
|
|
|
gdouble value)
|
|
|
|
{
|
|
|
|
gint sh;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! shell->display ||
|
|
|
|
! shell->display->image)
|
|
|
|
return;
|
|
|
|
|
2008-07-13 20:22:10 +08:00
|
|
|
gimp_display_shell_get_scaled_image_size (shell, NULL, &sh);
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
if (shell->disp_height < sh)
|
|
|
|
{
|
|
|
|
shell->vsbdata->upper = MAX (value + shell->disp_height,
|
|
|
|
sh);
|
|
|
|
|
|
|
|
shell->vsbdata->lower = MIN (value,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shell->vsbdata->lower = MIN (value,
|
|
|
|
-(shell->disp_height - sh) / 2);
|
|
|
|
|
|
|
|
shell->vsbdata->upper = MAX (value + shell->disp_height,
|
|
|
|
sh + (shell->disp_height - sh) / 2);
|
|
|
|
}
|
|
|
|
}
|