1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* 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
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "tools/gimptool.h"
|
2001-02-21 20:18:09 +08:00
|
|
|
#include "tools/tool_manager.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-09-26 07:23:09 +08:00
|
|
|
#include "gimpdisplay-scale.h"
|
|
|
|
#include "gimpdisplay-scroll.h"
|
|
|
|
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "gimprc.h"
|
1999-08-13 06:21:04 +08:00
|
|
|
#include "nav_window.h"
|
2001-01-22 09:46:28 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
gboolean
|
2001-10-13 20:52:30 +08:00
|
|
|
gimp_display_scroll (GimpDisplay *gdisp,
|
|
|
|
gint x_offset,
|
|
|
|
gint y_offset)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-23 04:46:50 +08:00
|
|
|
gint old_x, old_y;
|
|
|
|
gint src_x, src_y;
|
|
|
|
gint dest_x, dest_y;
|
1997-12-18 14:30:11 +08:00
|
|
|
GdkEvent *event;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-13 20:52:30 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (gdisp), FALSE);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
old_x = gdisp->offset_x;
|
|
|
|
old_y = gdisp->offset_y;
|
|
|
|
|
|
|
|
gdisp->offset_x += x_offset;
|
|
|
|
gdisp->offset_y += y_offset;
|
|
|
|
|
2001-10-13 20:52:30 +08:00
|
|
|
gimp_display_scroll_clamp_offsets (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the actual changes in offset */
|
|
|
|
x_offset = (gdisp->offset_x - old_x);
|
|
|
|
y_offset = (gdisp->offset_y - old_y);
|
|
|
|
|
|
|
|
if (x_offset || y_offset)
|
|
|
|
{
|
2001-10-13 20:52:30 +08:00
|
|
|
/* FIXME: I'm sure this is useless if all other places are correct --mitch
|
|
|
|
*/
|
|
|
|
gimp_display_scale_setup (gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
src_x = (x_offset < 0) ? 0 : x_offset;
|
|
|
|
src_y = (y_offset < 0) ? 0 : y_offset;
|
|
|
|
dest_x = (x_offset < 0) ? -x_offset : 0;
|
|
|
|
dest_y = (y_offset < 0) ? -y_offset : 0;
|
|
|
|
|
|
|
|
/* reset the old values so that the tool can accurately redraw */
|
|
|
|
gdisp->offset_x = old_x;
|
|
|
|
gdisp->offset_y = old_y;
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
/* freeze the active tool */
|
|
|
|
tool_manager_control_active (gdisp->gimage->gimp, PAUSE, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* set the offsets back to the new values */
|
|
|
|
gdisp->offset_x += x_offset;
|
|
|
|
gdisp->offset_y += y_offset;
|
|
|
|
|
2001-08-31 22:01:47 +08:00
|
|
|
gdk_draw_drawable (gdisp->canvas->window,
|
|
|
|
gdisp->scroll_gc,
|
|
|
|
gdisp->canvas->window,
|
|
|
|
src_x, src_y,
|
|
|
|
dest_x, dest_y,
|
|
|
|
(gdisp->disp_width - abs (x_offset)),
|
|
|
|
(gdisp->disp_height - abs (y_offset)));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
/* re-enable the active tool */
|
|
|
|
tool_manager_control_active (gdisp->gimage->gimp, RESUME, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* scale the image into the exposed regions */
|
|
|
|
if (x_offset)
|
|
|
|
{
|
|
|
|
src_x = (x_offset < 0) ? 0 : gdisp->disp_width - x_offset;
|
|
|
|
src_y = 0;
|
|
|
|
gdisplay_expose_area (gdisp,
|
|
|
|
src_x, src_y,
|
|
|
|
abs (x_offset), gdisp->disp_height);
|
|
|
|
}
|
|
|
|
if (y_offset)
|
|
|
|
{
|
|
|
|
src_x = 0;
|
|
|
|
src_y = (y_offset < 0) ? 0 : gdisp->disp_height - y_offset;
|
|
|
|
gdisplay_expose_area (gdisp,
|
|
|
|
src_x, src_y,
|
|
|
|
gdisp->disp_width, abs (y_offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x_offset || y_offset)
|
|
|
|
gdisplays_flush ();
|
|
|
|
|
2001-06-18 21:10:03 +08:00
|
|
|
nav_dialog_update_window_marker (gdisp->window_nav_dialog);
|
|
|
|
|
|
|
|
if (gdisp->nav_popup)
|
|
|
|
nav_dialog_update_window_marker (gdisp->nav_popup);
|
1997-12-18 14:30:11 +08:00
|
|
|
|
|
|
|
/* Make sure graphics expose events are processed before scrolling
|
2001-06-18 21:10:03 +08:00
|
|
|
* again
|
|
|
|
*/
|
|
|
|
while ((event = gdk_event_get_graphics_expose (gdisp->canvas->window)))
|
|
|
|
{
|
|
|
|
gtk_widget_event (gdisp->canvas, event);
|
|
|
|
|
|
|
|
if (event->expose.count == 0)
|
|
|
|
{
|
|
|
|
gdk_event_free (event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_event_free (event);
|
|
|
|
}
|
1997-12-18 14:30:11 +08:00
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
return TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-01-23 04:46:50 +08:00
|
|
|
return FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-10-13 20:52:30 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
gimp_display_scroll_clamp_offsets (GimpDisplay *gdisp)
|
|
|
|
{
|
|
|
|
gint sx, sy;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
|
|
|
|
|
|
|
|
sx = SCALEX (gdisp, gdisp->gimage->width);
|
|
|
|
sy = SCALEY (gdisp, gdisp->gimage->height);
|
|
|
|
|
|
|
|
gdisp->offset_x = CLAMP (gdisp->offset_x, 0,
|
|
|
|
LOWPASS (sx - gdisp->disp_width));
|
|
|
|
|
|
|
|
gdisp->offset_y = CLAMP (gdisp->offset_y, 0,
|
|
|
|
LOWPASS (sy - gdisp->disp_height));
|
|
|
|
}
|
|
|
|
|