1
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
4
* This program is free software: you can redistribute it and/or modify
5
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
6
* the Free Software Foundation; either version 3 of the License, or
7
7
* (at your option) any later version.
9
9
* This program is distributed in the hope that it will be useful,
12
12
* GNU General Public License for more details.
14
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.
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
18
#include "config.h"
21
21
#include <gtk/gtk.h>
23
#include "libgimpbase/gimpbase.h"
23
24
#include "libgimpmath/gimpmath.h"
25
#include "libgimpwidgets/gimpwidgets.h"
25
27
#include "display-types.h"
29
31
#include "core/gimp.h"
30
32
#include "core/gimpimage.h"
31
#include "core/gimpunit.h"
33
34
#include "gimpdisplay.h"
34
35
#include "gimpdisplayshell.h"
35
36
#include "gimpdisplayshell-draw.h"
37
#include "gimpdisplayshell-expose.h"
36
38
#include "gimpdisplayshell-scale.h"
37
39
#include "gimpdisplayshell-scroll.h"
38
40
#include "gimpdisplayshell-title.h"
39
41
#include "gimpdisplayshell-transform.h"
42
#include "gimpimagewindow.h"
42
45
#define SCALE_TIMEOUT 2
109
108
gimp_display_shell_scale_update_scrollbars (GimpDisplayShell *shell)
110
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
115
112
if (! shell->display)
118
image = shell->display->image;
122
image_width = gimp_image_get_width (image);
123
image_height = gimp_image_get_height (image);
127
image_width = shell->disp_width;
128
image_height = shell->disp_height;
132
115
/* Horizontal scrollbar */
134
shell->hsbdata->value = shell->offset_x;
135
shell->hsbdata->page_size = shell->disp_width;
136
shell->hsbdata->page_increment = shell->disp_width / 2;
117
g_object_freeze_notify (G_OBJECT (shell->hsbdata));
119
/* Update upper and lower value before we set the new value */
138
120
gimp_display_shell_scroll_setup_hscrollbar (shell, shell->offset_x);
140
gtk_adjustment_changed (shell->hsbdata);
122
g_object_set (shell->hsbdata,
123
"value", (gdouble) shell->offset_x,
124
"page-size", (gdouble) shell->disp_width,
125
"page-increment", (gdouble) shell->disp_width / 2,
128
g_object_thaw_notify (G_OBJECT (shell->hsbdata)); /* emits "changed" */
143
131
/* Vertcal scrollbar */
145
shell->vsbdata->value = shell->offset_y;
146
shell->vsbdata->page_size = shell->disp_height;
147
shell->vsbdata->page_increment = shell->disp_height / 2;
133
g_object_freeze_notify (G_OBJECT (shell->vsbdata));
135
/* Update upper and lower value before we set the new value */
149
136
gimp_display_shell_scroll_setup_vscrollbar (shell, shell->offset_y);
151
gtk_adjustment_changed (shell->vsbdata);
138
g_object_set (shell->vsbdata,
139
"value", (gdouble) shell->offset_y,
140
"page-size", (gdouble) shell->disp_height,
141
"page-increment", (gdouble) shell->disp_height / 2,
144
g_object_thaw_notify (G_OBJECT (shell->vsbdata)); /* emits "changed" */
162
155
GimpImage *image;
163
156
gint image_width;
164
157
gint image_height;
158
gdouble resolution_x = 1.0;
159
gdouble resolution_y = 1.0;
165
160
gdouble horizontal_lower;
166
161
gdouble horizontal_upper;
167
162
gdouble horizontal_max_size;
172
167
if (! shell->display)
175
image = shell->display->image;
170
image = gimp_display_get_image (shell->display);
179
174
image_width = gimp_image_get_width (image);
180
175
image_height = gimp_image_get_height (image);
177
gimp_image_get_resolution (image, &resolution_x, &resolution_y);
196
horizontal_upper = img2real (shell, TRUE,
197
FUNSCALEX (shell, shell->disp_width));
198
horizontal_max_size = img2real (shell, TRUE,
199
MAX (image_width, image_height));
193
horizontal_upper = gimp_pixels_to_units (FUNSCALEX (shell,
197
horizontal_max_size = gimp_pixels_to_units (MAX (image_width,
201
vertical_upper = img2real (shell, FALSE,
202
FUNSCALEY (shell, shell->disp_height));
203
vertical_max_size = img2real (shell, FALSE,
204
MAX (image_width, image_height));
202
vertical_upper = gimp_pixels_to_units (FUNSCALEY (shell,
206
vertical_max_size = gimp_pixels_to_units (MAX (image_width,
220
horizontal_lower += img2real (shell, TRUE,
222
(gdouble) shell->offset_x));
223
horizontal_upper += img2real (shell, TRUE,
225
(gdouble) shell->offset_x));
227
vertical_lower += img2real (shell, FALSE,
229
(gdouble) shell->offset_y));
230
vertical_upper += img2real (shell, FALSE,
232
(gdouble) shell->offset_y));
228
offset_x = gimp_pixels_to_units (FUNSCALEX (shell,
229
(gdouble) shell->offset_x),
233
offset_y = gimp_pixels_to_units (FUNSCALEX (shell,
234
(gdouble) shell->offset_y),
238
horizontal_lower += offset_x;
239
horizontal_upper += offset_x;
241
vertical_lower += offset_y;
242
vertical_upper += offset_y;
235
245
/* Finally setup the actual rulers */
341
gimp_display_shell_get_screen_resolution (GimpDisplayShell *shell,
347
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
349
if (shell->dot_for_dot)
351
gimp_image_get_resolution (gimp_display_get_image (shell->display),
356
x = shell->monitor_xres;
357
y = shell->monitor_yres;
331
365
* gimp_display_shell_scale:
332
366
* @shell: the #GimpDisplayShell
366
400
if (shell->display->config->resize_windows_on_zoom)
402
GimpImageWindow *window = gimp_display_shell_get_window (shell);
368
404
/* If the window is resized on zoom, simply do the zoom and
369
405
* get things rolling
371
407
gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, real_new_scale);
372
408
gimp_display_shell_scaled (shell);
374
gimp_display_shell_shrink_wrap (shell, FALSE);
410
if (window && gimp_image_window_get_active_shell (window) == shell)
412
gimp_image_window_shrink_wrap (window, FALSE);
449
488
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
451
image = shell->display->image;
490
image = gimp_display_get_image (shell->display);
453
492
image_width = gimp_image_get_width (image);
454
493
image_height = gimp_image_get_height (image);
525
564
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
527
image = shell->display->image;
566
image = gimp_display_get_image (shell->display);
529
568
image_width = gimp_image_get_width (image);
530
569
image_height = gimp_image_get_height (image);
656
695
gimp_display_shell_pause (shell);
658
697
if (resize_window)
659
gimp_display_shell_shrink_wrap (shell, grow_only);
699
GimpImageWindow *window = gimp_display_shell_get_window (shell);
701
if (window && gimp_image_window_get_active_shell (window) == shell)
703
gimp_image_window_shrink_wrap (window, grow_only);
661
707
gimp_display_shell_scroll_clamp_and_update (shell);
662
708
gimp_display_shell_scaled (shell);
679
gimp_display_shell_calculate_scale_x_and_y (const GimpDisplayShell *shell,
725
gimp_display_shell_calculate_scale_x_and_y (GimpDisplayShell *shell,
687
736
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
688
g_return_if_fail (GIMP_IS_IMAGE (shell->display->image));
690
gimp_image_get_resolution (shell->display->image, &xres, &yres);
692
if (scale_x) *scale_x = scale * SCREEN_XRES (shell) / xres;
693
if (scale_y) *scale_y = scale * SCREEN_YRES (shell) / yres;
738
image = gimp_display_get_image (shell->display);
740
g_return_if_fail (GIMP_IS_IMAGE (image));
742
gimp_image_get_resolution (image, &xres, &yres);
743
gimp_display_shell_get_screen_resolution (shell, &screen_xres, &screen_yres);
745
if (scale_x) *scale_x = scale * screen_xres / xres;
746
if (scale_y) *scale_y = scale * screen_yres / yres;
710
764
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
766
image = gimp_display_get_image (shell->display);
712
768
screen = gtk_widget_get_screen (GTK_WIDGET (shell));
714
image_width = gimp_image_get_width (shell->display->image);
715
image_height = gimp_image_get_height (shell->display->image);
770
image_width = gimp_image_get_width (image);
771
image_height = gimp_image_get_height (image);
717
773
screen_width = gdk_screen_get_width (screen) * 0.75;
718
774
screen_height = gdk_screen_get_height (screen) * 0.75;
830
* gimp_display_shell_push_zoom_focus_pointer_pos:
835
* When the zoom focus mechanism asks for the pointer the next time,
839
gimp_display_shell_push_zoom_focus_pointer_pos (GimpDisplayShell *shell,
843
GdkPoint *point = g_slice_new (GdkPoint);
847
g_queue_push_head (shell->zoom_focus_pointer_queue,
774
852
* gimp_display_shell_scale_to:
954
1031
/* Calculate other focus point */
957
gboolean event_looks_sane;
958
gboolean cursor_within_canvas;
959
gint canvas_pointer_x, canvas_pointer_y;
1035
gboolean event_looks_sane;
1036
gboolean cursor_within_canvas;
1037
gint canvas_pointer_x, canvas_pointer_y;
1039
window = GTK_WIDGET (gimp_display_shell_get_window (shell));
961
1041
/* Center on the mouse position instead of the display center if
962
1042
* one of the following conditions are fulfilled and pointer is
965
1045
* (1) there's no current event (the action was triggered by an
966
1046
* input controller)
967
1047
* (2) the event originates from the canvas (a scroll event)
968
* (3) the event originates from the shell (a key press event)
1048
* (3) the event originates from the window (a key press event)
970
1050
* Basically the only situation where we don't want to center on
971
1051
* mouse position is if the action is being called from a menu.
974
1054
event = gtk_get_current_event ();
976
event_looks_sane = ! event ||
977
gtk_get_event_widget (event) == shell->canvas ||
978
gtk_get_event_widget (event) == GTK_WIDGET (shell);
981
gtk_widget_get_pointer (shell->canvas,
1056
event_looks_sane = (! event ||
1057
gtk_get_event_widget (event) == shell->canvas ||
1058
gtk_get_event_widget (event) == window);
1061
if (g_queue_peek_head (shell->zoom_focus_pointer_queue) == NULL)
1063
gtk_widget_get_pointer (shell->canvas,
1069
GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
1071
canvas_pointer_x = point->x;
1072
canvas_pointer_y = point->y;
1074
g_slice_free (GdkPoint, point);
985
1077
cursor_within_canvas = canvas_pointer_x >= 0 &&
986
1078
canvas_pointer_y >= 0 &&
1057
/* scale image coord to realworld units (cm, inches, pixels)
1059
* 27/Feb/1999 I tried inlining this, but the result was slightly
1060
* slower (poorer cache locality, probably) -- austin
1063
img2real (GimpDisplayShell *shell,
1071
if (shell->unit == GIMP_UNIT_PIXEL)
1074
gimp_image_get_resolution (shell->display->image, &xres, &yres);
1081
return len * _gimp_unit_get_factor (shell->display->gimp, shell->unit) / res;