Files
gimp/app/display/gimpdisplayshell-scroll.c
Michael Natterer d162376d47 app/display/Makefile.am app/display/gimpdisplay-callbacks.[ch]
2001-11-01  Michael Natterer  <mitch@gimp.org>

	* app/display/Makefile.am
	* app/display/gimpdisplay-callbacks.[ch]
	* app/display/gimpdisplay-render.[ch]
	* app/display/gimpdisplay-scale.[ch]
	* app/display/gimpdisplay-scroll.[ch]: removed and added as
	gimpdisplayshell-foo.[ch] because they are all methods of the
	shell.

	* app/display/gimpdisplay.[ch]
	* app/display/gimpdisplayshell.[ch]: moved the "offset" and "size"
	variables from GimpDisplay to GimpDisplayShell. GimpDisplay
	should know nothing about screen coordinates.

	The gdisplay_[un]transform_foo() methods are still part of
	GimpDisplay but will be moved to GimpDisplayShell as soon as the
	tools' vitrual functions speak in image coordinates instead of
	GdkEvents.

	* app/display/gimpdisplayshell-callbacks.[ch]: prefixed all
	functions with gimp_display_shell_*. Moved some stuff to a
	"realize" callback File still has to be renamed.

	* app/display/gimpdisplay-foreach.[ch]: removed
	gdisplays_shrink_wrap().

	* app/gui/menus.c
	* app/gui/view-commands.[ch]
	* app/display/gimpdisplayshell-scale.[ch]: implemented "Zoom to
	Fit Window" function (#57670).

	* app/nav_window.c
	* app/display/gimpdisplay-handlers.c
	* app/display/gimpdisplayshell-render.[ch]
	* app/display/gimpdisplayshell-scale.[ch]
	* app/display/gimpdisplayshell-scroll.[ch]
	* app/gui/colormap-dialog.c
	* app/gui/gui.c
	* app/gui/preferences-dialog.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmovetool.c
	* app/widgets/gimppreview.c: changed according to variable
	and filename changes.

	* app/tools/tool_manager.c: tool_manager_select_tool(): send the
	active tool a "HALT" command before selecting the new one. Fixes
	stale tool dialogs which were there because some other hack was
	removed (This is IMHO the right place to shut down the active
	tool).

	* app/tools/gimpcroptool.c: don't shrink wrap after cropping but
	let gimprc.allow_resize_windows decide.

	* app/tools/gimpselectiontool.c: gimage_mask_value() takes image,
	not screen coordinates. A good example of how braindead it is to
	pass GdkEvents to tools :-) Fixes incorrect cursor and oper
	update of the selection tools.

	* app/tools/gimptransformtool.c
	* app/undo.c: removed (#if 0 for now) some strange code which did
	manual exposing of GimpDisplayShell areas. This was definitely a
	hack and should not be there given the image emits correct
	"update" signals.
2001-11-02 09:31:21 +00:00

171 lines
4.7 KiB
C

/* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdlib.h>
#include <gtk/gtk.h>
#include "display-types.h"
#include "core/gimpimage.h"
#include "tools/gimptool.h"
#include "tools/tool_manager.h"
#include "gimpdisplay.h"
#include "gimpdisplay-foreach.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scroll.h"
#include "gimprc.h"
#include "nav_window.h"
gboolean
gimp_display_shell_scroll (GimpDisplayShell *shell,
gint x_offset,
gint y_offset)
{
gint old_x, old_y;
gint src_x, src_y;
gint dest_x, dest_y;
GdkEvent *event;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
old_x = shell->offset_x;
old_y = shell->offset_y;
shell->offset_x += x_offset;
shell->offset_y += y_offset;
gimp_display_shell_scroll_clamp_offsets (shell);
/* the actual changes in offset */
x_offset = (shell->offset_x - old_x);
y_offset = (shell->offset_y - old_y);
if (x_offset || y_offset)
{
/* FIXME: I'm sure this is useless if all other places are correct --mitch
*/
gimp_display_shell_scale_setup (shell);
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 */
shell->offset_x = old_x;
shell->offset_y = old_y;
/* freeze the active tool */
tool_manager_control_active (shell->gdisp->gimage->gimp, PAUSE,
shell->gdisp);
/* set the offsets back to the new values */
shell->offset_x += x_offset;
shell->offset_y += y_offset;
gdk_draw_drawable (shell->canvas->window,
shell->scroll_gc,
shell->canvas->window,
src_x, src_y,
dest_x, dest_y,
(shell->disp_width - abs (x_offset)),
(shell->disp_height - abs (y_offset)));
/* re-enable the active tool */
tool_manager_control_active (shell->gdisp->gimage->gimp, RESUME,
shell->gdisp);
/* scale the image into the exposed regions */
if (x_offset)
{
src_x = (x_offset < 0) ? 0 : shell->disp_width - x_offset;
src_y = 0;
gimp_display_shell_add_expose_area (shell,
src_x, src_y,
abs (x_offset),
shell->disp_height);
}
if (y_offset)
{
src_x = 0;
src_y = (y_offset < 0) ? 0 : shell->disp_height - y_offset;
gimp_display_shell_add_expose_area (shell,
src_x, src_y,
shell->disp_width,
abs (y_offset));
}
if (x_offset || y_offset)
gdisplay_flush (shell->gdisp);
nav_dialog_update_window_marker (shell->nav_dialog);
if (shell->nav_popup)
nav_dialog_update_window_marker (shell->nav_popup);
/* Make sure graphics expose events are processed before scrolling
* again
*/
while ((event = gdk_event_get_graphics_expose (shell->canvas->window)))
{
gtk_widget_event (shell->canvas, event);
if (event->expose.count == 0)
{
gdk_event_free (event);
break;
}
gdk_event_free (event);
}
return TRUE;
}
return FALSE;
}
void
gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell)
{
gint sx, sy;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
sx = SCALEX (shell->gdisp, shell->gdisp->gimage->width);
sy = SCALEY (shell->gdisp, shell->gdisp->gimage->height);
shell->offset_x = CLAMP (shell->offset_x, 0,
MAX (sx - shell->disp_width, 0));
shell->offset_y = CLAMP (shell->offset_y, 0,
MAX (sy - shell->disp_height, 0));
}