1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/* 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 <stdlib.h>
#include "appenv.h"
#include "scale.h"
#include "scroll.h"
#include "cursorutil.h"
#include "tools.h"
/* This is the delay before dithering begins
* for example, after an operation such as scrolling
*/
#define DITHER_DELAY 250 /* milliseconds */
/* Locally defined functions */
static int scroll_display (GDisplay *, int, int);
/* STATIC variables */
/* These are the values of the initial pointer grab */
static int startx, starty;
gint
scrollbar_vert_update (GtkAdjustment *adjustment,
gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
scroll_display (gdisp, 0, (adjustment->value - gdisp->offset_y));
return FALSE;
}
gint
scrollbar_horz_update (GtkAdjustment *adjustment,
gpointer data)
{
GDisplay *gdisp;
gdisp = (GDisplay *) data;
scroll_display (gdisp, (adjustment->value - gdisp->offset_x), 0);
return FALSE;
}
void
start_grab_and_scroll (GDisplay *gdisp,
GdkEventButton *bevent)
{
GdkCursor *cursor;
startx = bevent->x + gdisp->offset_x;
starty = bevent->y + gdisp->offset_y;
cursor = gdk_cursor_new (GDK_FLEUR);
gdk_window_set_cursor (gdisp->canvas->window, cursor);
gdk_cursor_destroy (cursor);
}
void
end_grab_and_scroll (GDisplay *gdisp,
GdkEventButton *bevent)
{
GdkCursor *cursor;
cursor = gdk_cursor_new (gdisp->current_cursor);
gdk_window_set_cursor (gdisp->canvas->window, cursor);
gdk_cursor_destroy (cursor);
}
void
grab_and_scroll (GDisplay *gdisp,
GdkEventMotion *mevent)
{
scroll_display (gdisp, (startx - mevent->x - gdisp->offset_x),
(starty - mevent->y - gdisp->offset_y));
}
void
scroll_to_pointer_position (GDisplay *gdisp,
GdkEventMotion *mevent)
{
int child_x, child_y;
int off_x, off_y;
off_x = off_y = 0;
/* The cases for scrolling */
if (mevent->x < 0)
off_x = mevent->x;
else if (mevent->x > gdisp->disp_width)
off_x = mevent->x - gdisp->disp_width;
if (mevent->y < 0)
off_y = mevent->y;
else if (mevent->y > gdisp->disp_height)
off_y = mevent->y - gdisp->disp_height;
if (scroll_display (gdisp, off_x, off_y))
{
gdk_window_get_pointer (gdisp->canvas->window, &child_x, &child_y, NULL);
if (child_x == mevent->x && child_y == mevent->y)
/* Put this event back on the queue -- so it keeps scrolling */
gdk_event_put ((GdkEvent *) mevent);
}
}
static int
scroll_display (GDisplay *gdisp,
int x_offset,
int y_offset)
{
int old_x, old_y;
int src_x, src_y;
int dest_x, dest_y;
GdkEvent *event;
old_x = gdisp->offset_x;
old_y = gdisp->offset_y;
gdisp->offset_x += x_offset;
gdisp->offset_y += y_offset;
bounds_checking (gdisp);
/* the actual changes in offset */
x_offset = (gdisp->offset_x - old_x);
y_offset = (gdisp->offset_y - old_y);
if (x_offset || y_offset)
{
setup_scale (gdisp);
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;
/* stop the currently active tool */
active_tool_control (PAUSE, (void *) gdisp);
/* set the offsets back to the new values */
gdisp->offset_x += x_offset;
gdisp->offset_y += y_offset;
gdk_draw_pixmap (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)));
/* resume the currently active tool */
active_tool_control (RESUME, (void *) gdisp);
/* 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 ();
/* Make sure graphics expose events are processed before scrolling
* again */
while ((event = gdk_event_get_graphics_expose (gdisp->canvas->window))
!= NULL)
{
gtk_widget_event (gdisp->canvas, event);
if (event->expose.count == 0)
{
gdk_event_free (event);
break;
}
gdk_event_free (event);
}
return 1;
}
return 0;
}
|