1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "display-types.h"
25
#include "core/gimpimage.h"
27
#include "gimpdisplay.h"
28
#include "gimpdisplayshell.h"
29
#include "gimpdisplayshell-autoscroll.h"
30
#include "gimpdisplayshell-coords.h"
31
#include "gimpdisplayshell-scroll.h"
32
#include "gimpdisplayshell-transform.h"
34
#include "tools/tools-types.h"
35
#include "tools/tool_manager.h"
36
#include "tools/gimptool.h"
37
#include "tools/gimptoolcontrol.h"
40
#define AUTOSCROLL_DT 20
41
#define AUTOSCROLL_DX 0.1
46
GdkEventMotion *mevent;
49
GdkModifierType state;
54
/* local function prototypes */
56
static gboolean gimp_display_shell_autoscroll_timeout (gpointer data);
59
/* public functions */
62
gimp_display_shell_autoscroll_start (GimpDisplayShell *shell,
63
GdkModifierType state,
64
GdkEventMotion *mevent)
68
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
70
if (shell->scroll_info)
73
info = g_new0 (ScrollInfo, 1);
75
info->mevent = mevent;
76
info->device = mevent->device;
77
info->time = gdk_event_get_time ((GdkEvent *) mevent);
79
info->timeout_id = g_timeout_add (AUTOSCROLL_DT,
80
gimp_display_shell_autoscroll_timeout,
83
shell->scroll_info = info;
87
gimp_display_shell_autoscroll_stop (GimpDisplayShell *shell)
91
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
93
if (! shell->scroll_info)
96
info = shell->scroll_info;
100
g_source_remove (info->timeout_id);
101
info->timeout_id = 0;
105
shell->scroll_info = NULL;
109
/* private functions */
112
gimp_display_shell_autoscroll_timeout (gpointer data)
114
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
115
ScrollInfo *info = shell->scroll_info;
116
GimpCoords device_coords;
117
GimpCoords image_coords;
121
gimp_display_shell_get_device_coords (shell, info->device, &device_coords);
123
if (device_coords.x < 0)
124
dx = device_coords.x;
125
else if (device_coords.x > shell->disp_width)
126
dx = device_coords.x - shell->disp_width;
128
if (device_coords.y < 0)
129
dy = device_coords.y;
130
else if (device_coords.y > shell->disp_height)
131
dy = device_coords.y - shell->disp_height;
135
GimpDisplay *display = shell->display;
136
GimpTool *active_tool = tool_manager_get_active (display->image->gimp);
138
info->time += AUTOSCROLL_DT;
140
gimp_display_shell_scroll (shell,
141
AUTOSCROLL_DX * (gdouble) dx,
142
AUTOSCROLL_DX * (gdouble) dy);
144
gimp_display_shell_untransform_coordinate (shell,
148
if (gimp_tool_control_get_snap_to (active_tool->control))
150
gint x, y, width, height;
152
gimp_tool_control_get_snap_offsets (active_tool->control,
153
&x, &y, &width, &height);
155
gimp_display_shell_snap_coords (shell,
158
x, y, width, height);
161
tool_manager_motion_active (display->image->gimp,
163
info->time, info->state,
171
shell->scroll_info = NULL;