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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://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>
|
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"
|
|
|
|
|
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
|
|
|
|
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"
|
2008-08-10 18:54:00 +08:00
|
|
|
#include "gimpdisplayshell-draw.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-08-21 04:01:45 +08:00
|
|
|
#define OVERPAN_FACTOR 0.5
|
|
|
|
#define MINIMUM_STEP_AMOUNT 1.0
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
|
2008-08-17 02:50:38 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gboolean vertically;
|
|
|
|
gboolean horizontally;
|
|
|
|
} SizeAllocateCallbackData;
|
|
|
|
|
|
|
|
|
2008-07-12 22:26:49 +08:00
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_center_image_coordinate:
|
2008-07-12 22:26:49 +08:00
|
|
|
* @shell:
|
|
|
|
* @image_x:
|
|
|
|
* @image_y:
|
|
|
|
*
|
|
|
|
* Center the viewport around the passed image coordinate
|
|
|
|
*
|
|
|
|
**/
|
2008-07-12 22:20:54 +08:00
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_center_image_coordinate (GimpDisplayShell *shell,
|
2008-07-12 22:20:54 +08:00
|
|
|
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-08-10 19:11:19 +08:00
|
|
|
gimp_display_shell_scroll (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-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
|
|
|
|
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
|
|
|
|
2008-08-22 23:57:41 +08:00
|
|
|
gimp_canvas_scroll (GIMP_CANVAS (shell->canvas), -x_offset, -y_offset);
|
2003-03-07 20:34:40 +08:00
|
|
|
|
2003-03-22 00:28:06 +08:00
|
|
|
/* Update scrollbars and rulers */
|
2008-08-10 19:56:29 +08:00
|
|
|
gimp_display_shell_update_scrollbars_and_rulers (shell);
|
2003-03-22 00:28:06 +08:00
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
gimp_display_shell_scale_handle_zoom_revert (shell);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2008-08-10 21:09:24 +08:00
|
|
|
gimp_display_shell_scrolled (shell);
|
|
|
|
|
|
|
|
gimp_display_shell_expose_full (shell);
|
|
|
|
|
|
|
|
/* re-enable the active tool */
|
|
|
|
gimp_display_shell_resume (shell);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2008-07-13 22:48:44 +08:00
|
|
|
|
|
|
|
/* Handle scrollbar stepper sensitiity */
|
|
|
|
|
|
|
|
gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->hsb),
|
|
|
|
min_offset_x < shell->offset_x ?
|
|
|
|
GTK_SENSITIVITY_ON :
|
|
|
|
GTK_SENSITIVITY_OFF);
|
|
|
|
|
|
|
|
gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->hsb),
|
|
|
|
max_offset_x > shell->offset_x ?
|
|
|
|
GTK_SENSITIVITY_ON :
|
|
|
|
GTK_SENSITIVITY_OFF);
|
|
|
|
|
|
|
|
gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->vsb),
|
|
|
|
min_offset_y < shell->offset_y ?
|
|
|
|
GTK_SENSITIVITY_ON :
|
|
|
|
GTK_SENSITIVITY_OFF);
|
|
|
|
|
|
|
|
gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->vsb),
|
|
|
|
max_offset_y > shell->offset_y ?
|
|
|
|
GTK_SENSITIVITY_ON :
|
|
|
|
GTK_SENSITIVITY_OFF);
|
|
|
|
|
|
|
|
|
|
|
|
/* Clamp */
|
|
|
|
|
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
|
|
|
|
2008-08-14 22:41:29 +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)
|
|
|
|
{
|
|
|
|
gimp_display_shell_scroll_clamp_offsets (shell);
|
|
|
|
gimp_display_shell_update_scrollbars_and_rulers (shell);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gimp_display_shell_draw_get_scaled_image_size (shell, &sw, &sh);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
*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)
|
|
|
|
{
|
2008-08-27 02:59:23 +08:00
|
|
|
gint min_offset = sh - shell->disp_height;
|
2008-08-27 02:50:54 +08:00
|
|
|
|
|
|
|
*out_offset_y = MIN (in_offset_y,
|
|
|
|
MAX (0, min_offset - shell->offset_y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
gint sw, sh;
|
|
|
|
gint target_offset_x, target_offset_y;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-08-10 22:26:29 +08:00
|
|
|
if (! shell->display ||
|
2008-08-15 03:23:28 +08:00
|
|
|
! shell->display->image ||
|
|
|
|
(! vertically && ! horizontally))
|
2008-08-10 15:23:14 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
target_offset_x = shell->offset_x;
|
|
|
|
target_offset_y = shell->offset_y;
|
|
|
|
|
2008-08-10 18:54:00 +08:00
|
|
|
gimp_display_shell_draw_get_scaled_image_size (shell, &sw, &sh);
|
2008-08-10 15:23:14 +08:00
|
|
|
|
|
|
|
if (horizontally)
|
|
|
|
{
|
2008-08-10 15:26:35 +08:00
|
|
|
target_offset_x = (sw - shell->disp_width) / 2;
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vertically)
|
|
|
|
{
|
2008-08-10 15:26:35 +08:00
|
|
|
target_offset_y = (sh - shell->disp_height) / 2;
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
2008-08-10 21:09:24 +08:00
|
|
|
gimp_display_shell_scroll_set_offset (shell,
|
|
|
|
target_offset_x,
|
|
|
|
target_offset_y);
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-08-17 02:50:38 +08:00
|
|
|
gimp_display_shell_scroll_center_image_callback (GtkWidget *canvas,
|
|
|
|
GtkAllocation *allocation,
|
|
|
|
SizeAllocateCallbackData *data)
|
2008-08-10 15:23:14 +08:00
|
|
|
{
|
2008-08-17 02:50:38 +08:00
|
|
|
gimp_display_shell_scroll_center_image (data->shell,
|
|
|
|
data->horizontally,
|
|
|
|
data->vertically);
|
2008-08-10 15:23:14 +08:00
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (canvas,
|
|
|
|
gimp_display_shell_scroll_center_image_callback,
|
2008-08-17 02:50:38 +08:00
|
|
|
data);
|
|
|
|
|
|
|
|
g_slice_free (SizeAllocateCallbackData, data);
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_display_shell_scroll_center_image_on_next_size_allocate:
|
|
|
|
* @shell:
|
|
|
|
*
|
|
|
|
* Centers the image in the display as soon as the canvas has got its
|
2008-08-17 02:25:32 +08:00
|
|
|
* new size.
|
|
|
|
*
|
|
|
|
* Only call this if you are sure the canvas size will change.
|
|
|
|
* (Otherwise the signal connection and centering will lurk until the
|
|
|
|
* canvas size is changed e.g. by toggling the rulers.)
|
2008-08-10 15:23:14 +08:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-17 02:50:38 +08:00
|
|
|
gimp_display_shell_scroll_center_image_on_next_size_allocate (GimpDisplayShell *shell,
|
2008-08-17 03:18:31 +08:00
|
|
|
gboolean horizontally,
|
|
|
|
gboolean vertically)
|
2008-08-10 15:23:14 +08:00
|
|
|
{
|
2008-08-17 02:50:38 +08:00
|
|
|
SizeAllocateCallbackData *data;
|
|
|
|
|
2008-08-10 15:23:14 +08:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-08-17 02:50:38 +08:00
|
|
|
data = g_slice_new (SizeAllocateCallbackData);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
data->shell = shell;
|
|
|
|
data->horizontally = horizontally;
|
|
|
|
data->vertically = vertically;
|
2008-09-04 16:37:32 +08:00
|
|
|
|
2008-08-17 02:50:38 +08:00
|
|
|
g_signal_connect (shell->canvas, "size-allocate",
|
|
|
|
G_CALLBACK (gimp_display_shell_scroll_center_image_callback),
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
2008-08-10 15:23:14 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* the image
|
2008-07-11 11:20:17 +08:00
|
|
|
*
|
2008-07-11 04:19:17 +08:00
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_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: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:
|
|
|
|
*
|
|
|
|
* Gets the viewport in image coordinates
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_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-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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_get_disp_offset:
|
2008-07-12 15:00:46 +08:00
|
|
|
* @shell:
|
|
|
|
* @disp_xoffset:
|
|
|
|
* @disp_yoffset:
|
|
|
|
*
|
|
|
|
* In viewport coordinates, get the offset of where to start rendering
|
|
|
|
* the scaled image.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_get_disp_offset (const GimpDisplayShell *shell,
|
|
|
|
gint *disp_xoffset,
|
|
|
|
gint *disp_yoffset)
|
2008-07-12 15:00:46 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_get_render_start_offset:
|
2008-07-12 15:00:46 +08:00
|
|
|
* @shell:
|
|
|
|
* @offset_x:
|
|
|
|
* @offset_y:
|
|
|
|
*
|
|
|
|
* Get the offset into the scaled image that we should start render
|
|
|
|
* from
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_get_render_start_offset (const GimpDisplayShell *shell,
|
|
|
|
gint *offset_x,
|
|
|
|
gint *offset_y)
|
2008-07-12 15:00:46 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
2008-11-14 07:16:11 +08:00
|
|
|
*offset_x = MAX (0, shell->offset_x);
|
|
|
|
*offset_y = MAX (0, shell->offset_y);
|
2008-07-12 03:31:45 +08:00
|
|
|
}
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_setup_hscrollbar:
|
2008-07-12 22:48:09 +08:00
|
|
|
* @shell:
|
|
|
|
* @value:
|
|
|
|
*
|
|
|
|
* Setup the limits of the horizontal scrollbar
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_setup_hscrollbar (GimpDisplayShell *shell,
|
|
|
|
gdouble value)
|
2008-07-12 22:48:09 +08:00
|
|
|
{
|
|
|
|
gint sw;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! shell->display ||
|
|
|
|
! shell->display->image)
|
|
|
|
return;
|
|
|
|
|
2008-08-10 18:54:00 +08:00
|
|
|
gimp_display_shell_draw_get_scaled_image_size (shell, &sw, NULL);
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
if (shell->disp_width < sw)
|
|
|
|
{
|
|
|
|
shell->hsbdata->lower = MIN (value,
|
|
|
|
0);
|
2008-07-13 22:33:04 +08:00
|
|
|
|
|
|
|
shell->hsbdata->upper = MAX (value + shell->disp_width,
|
|
|
|
sw);
|
2008-07-12 22:48:09 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2008-08-06 01:17:27 +08:00
|
|
|
|
2008-08-21 04:01:45 +08:00
|
|
|
shell->hsbdata->step_increment = MAX (shell->scale_x, MINIMUM_STEP_AMOUNT);
|
2008-07-12 22:48:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-10 17:08:11 +08:00
|
|
|
* gimp_display_shell_scroll_setup_vscrollbar:
|
2008-07-12 22:48:09 +08:00
|
|
|
* @shell:
|
|
|
|
* @value:
|
|
|
|
*
|
|
|
|
* Setup the limits of the vertical scrollbar
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
void
|
2008-08-10 17:08:11 +08:00
|
|
|
gimp_display_shell_scroll_setup_vscrollbar (GimpDisplayShell *shell,
|
|
|
|
gdouble value)
|
2008-07-12 22:48:09 +08:00
|
|
|
{
|
|
|
|
gint sh;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
|
|
|
|
|
|
|
if (! shell->display ||
|
|
|
|
! shell->display->image)
|
|
|
|
return;
|
|
|
|
|
2008-08-10 18:54:00 +08:00
|
|
|
gimp_display_shell_draw_get_scaled_image_size (shell, NULL, &sh);
|
2008-07-12 22:48:09 +08:00
|
|
|
|
|
|
|
if (shell->disp_height < sh)
|
|
|
|
{
|
|
|
|
shell->vsbdata->lower = MIN (value,
|
|
|
|
0);
|
2008-07-13 22:33:04 +08:00
|
|
|
|
|
|
|
shell->vsbdata->upper = MAX (value + shell->disp_height,
|
|
|
|
sh);
|
2008-07-12 22:48:09 +08:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2008-08-06 01:17:27 +08:00
|
|
|
|
2008-08-21 04:01:45 +08:00
|
|
|
shell->vsbdata->step_increment = MAX (shell->scale_y, MINIMUM_STEP_AMOUNT);
|
2008-07-12 22:48:09 +08:00
|
|
|
}
|