~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/display/gimpdisplayshell-autoscroll.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20070502163303-6wchheivjxgjtlna
Tags: upstream-2.3.16
ImportĀ upstreamĀ versionĀ 2.3.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "display-types.h"
 
24
 
 
25
#include "core/gimpimage.h"
 
26
 
 
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"
 
33
 
 
34
#include "tools/tools-types.h"
 
35
#include "tools/tool_manager.h"
 
36
#include "tools/gimptool.h"
 
37
#include "tools/gimptoolcontrol.h"
 
38
 
 
39
 
 
40
#define AUTOSCROLL_DT  20
 
41
#define AUTOSCROLL_DX  0.1
 
42
 
 
43
 
 
44
typedef struct
 
45
{
 
46
  GdkEventMotion  *mevent;
 
47
  GdkDevice       *device;
 
48
  guint32          time;
 
49
  GdkModifierType  state;
 
50
  guint            timeout_id;
 
51
} ScrollInfo;
 
52
 
 
53
 
 
54
/*  local function prototypes  */
 
55
 
 
56
static gboolean gimp_display_shell_autoscroll_timeout (gpointer data);
 
57
 
 
58
 
 
59
/*  public functions  */
 
60
 
 
61
void
 
62
gimp_display_shell_autoscroll_start (GimpDisplayShell *shell,
 
63
                                     GdkModifierType   state,
 
64
                                     GdkEventMotion   *mevent)
 
65
{
 
66
  ScrollInfo *info;
 
67
 
 
68
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
69
 
 
70
  if (shell->scroll_info)
 
71
    return;
 
72
 
 
73
  info = g_new0 (ScrollInfo, 1);
 
74
 
 
75
  info->mevent     = mevent;
 
76
  info->device     = mevent->device;
 
77
  info->time       = gdk_event_get_time ((GdkEvent *) mevent);
 
78
  info->state      = state;
 
79
  info->timeout_id = g_timeout_add (AUTOSCROLL_DT,
 
80
                                    gimp_display_shell_autoscroll_timeout,
 
81
                                    shell);
 
82
 
 
83
  shell->scroll_info = info;
 
84
}
 
85
 
 
86
void
 
87
gimp_display_shell_autoscroll_stop (GimpDisplayShell *shell)
 
88
{
 
89
  ScrollInfo *info;
 
90
 
 
91
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
92
 
 
93
  if (! shell->scroll_info)
 
94
    return;
 
95
 
 
96
  info = shell->scroll_info;
 
97
 
 
98
  if (info->timeout_id)
 
99
    {
 
100
      g_source_remove (info->timeout_id);
 
101
      info->timeout_id = 0;
 
102
    }
 
103
 
 
104
  g_free (info);
 
105
  shell->scroll_info = NULL;
 
106
}
 
107
 
 
108
 
 
109
/*  private functions  */
 
110
 
 
111
static gboolean
 
112
gimp_display_shell_autoscroll_timeout (gpointer data)
 
113
{
 
114
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
 
115
  ScrollInfo       *info  = shell->scroll_info;
 
116
  GimpCoords        device_coords;
 
117
  GimpCoords        image_coords;
 
118
  gint              dx = 0;
 
119
  gint              dy = 0;
 
120
 
 
121
  gimp_display_shell_get_device_coords (shell, info->device, &device_coords);
 
122
 
 
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;
 
127
 
 
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;
 
132
 
 
133
  if (dx || dy)
 
134
    {
 
135
      GimpDisplay *display     = shell->display;
 
136
      GimpTool    *active_tool = tool_manager_get_active (display->image->gimp);
 
137
 
 
138
      info->time += AUTOSCROLL_DT;
 
139
 
 
140
      gimp_display_shell_scroll (shell,
 
141
                                 AUTOSCROLL_DX * (gdouble) dx,
 
142
                                 AUTOSCROLL_DX * (gdouble) dy);
 
143
 
 
144
      gimp_display_shell_untransform_coordinate (shell,
 
145
                                                 &device_coords,
 
146
                                                 &image_coords);
 
147
 
 
148
      if (gimp_tool_control_get_snap_to (active_tool->control))
 
149
        {
 
150
          gint x, y, width, height;
 
151
 
 
152
          gimp_tool_control_get_snap_offsets (active_tool->control,
 
153
                                              &x, &y, &width, &height);
 
154
 
 
155
          gimp_display_shell_snap_coords (shell,
 
156
                                          &image_coords,
 
157
                                          &image_coords,
 
158
                                          x, y, width, height);
 
159
        }
 
160
 
 
161
      tool_manager_motion_active (display->image->gimp,
 
162
                                  &image_coords,
 
163
                                  info->time, info->state,
 
164
                                  display);
 
165
 
 
166
      return TRUE;
 
167
    }
 
168
  else
 
169
    {
 
170
      g_free (info);
 
171
      shell->scroll_info = NULL;
 
172
 
 
173
      return FALSE;
 
174
    }
 
175
}