~ubuntu-branches/ubuntu/saucy/gimp/saucy-security

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
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.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
12
12
 * GNU General Public License for more details.
13
13
 *
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/>.
17
16
 */
18
17
 
19
18
#include "config.h"
20
19
 
 
20
#include <gegl.h>
21
21
#include <gtk/gtk.h>
22
22
 
 
23
#include "libgimpbase/gimpbase.h"
23
24
#include "libgimpmath/gimpmath.h"
 
25
#include "libgimpwidgets/gimpwidgets.h"
24
26
 
25
27
#include "display-types.h"
26
28
 
28
30
 
29
31
#include "core/gimp.h"
30
32
#include "core/gimpimage.h"
31
 
#include "core/gimpunit.h"
32
33
 
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"
40
43
 
41
44
 
42
45
#define SCALE_TIMEOUT             2
79
82
                                                          gint             *y,
80
83
                                                          GimpZoomFocus     zoom_focus);
81
84
 
82
 
static gdouble   img2real                                (GimpDisplayShell *shell,
83
 
                                                          gboolean          xdir,
84
 
                                                          gdouble           a);
85
 
 
86
85
 
87
86
/*  public functions  */
88
87
 
108
107
void
109
108
gimp_display_shell_scale_update_scrollbars (GimpDisplayShell *shell)
110
109
{
111
 
  GimpImage *image;
112
 
  gint       image_width;
113
 
  gint       image_height;
 
110
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
114
111
 
115
112
  if (! shell->display)
116
113
    return;
117
114
 
118
 
  image = shell->display->image;
119
 
 
120
 
  if (image)
121
 
    {
122
 
      image_width  = gimp_image_get_width  (image);
123
 
      image_height = gimp_image_get_height (image);
124
 
    }
125
 
  else
126
 
    {
127
 
      image_width  = shell->disp_width;
128
 
      image_height = shell->disp_height;
129
 
    }
130
 
 
131
 
 
132
115
  /* Horizontal scrollbar */
133
116
 
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));
137
118
 
 
119
  /* Update upper and lower value before we set the new value */
138
120
  gimp_display_shell_scroll_setup_hscrollbar (shell, shell->offset_x);
139
121
 
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,
 
126
                NULL);
 
127
 
 
128
  g_object_thaw_notify (G_OBJECT (shell->hsbdata)); /* emits "changed" */
141
129
 
142
130
 
143
131
  /* Vertcal scrollbar */
144
132
 
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));
148
134
 
 
135
  /* Update upper and lower value before we set the new value */
149
136
  gimp_display_shell_scroll_setup_vscrollbar (shell, shell->offset_y);
150
137
 
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,
 
142
                NULL);
 
143
 
 
144
  g_object_thaw_notify (G_OBJECT (shell->vsbdata)); /* emits "changed" */
152
145
}
153
146
 
154
147
/**
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)
173
168
    return;
174
169
 
175
 
  image = shell->display->image;
 
170
  image = gimp_display_get_image (shell->display);
176
171
 
177
172
  if (image)
178
173
    {
179
174
      image_width  = gimp_image_get_width  (image);
180
175
      image_height = gimp_image_get_height (image);
 
176
 
 
177
      gimp_image_get_resolution (image, &resolution_x, &resolution_y);
181
178
    }
182
179
  else
183
180
    {
193
190
 
194
191
  if (image)
195
192
    {
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,
 
194
                                                             shell->disp_width),
 
195
                                                  shell->unit,
 
196
                                                  resolution_x);
 
197
      horizontal_max_size = gimp_pixels_to_units (MAX (image_width,
 
198
                                                       image_height),
 
199
                                                  shell->unit,
 
200
                                                  resolution_x);
200
201
 
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,
 
203
                                                             shell->disp_height),
 
204
                                                  shell->unit,
 
205
                                                  resolution_y);
 
206
      vertical_max_size   = gimp_pixels_to_units (MAX (image_width,
 
207
                                                       image_height),
 
208
                                                  shell->unit,
 
209
                                                  resolution_y);
205
210
    }
206
211
  else
207
212
    {
217
222
 
218
223
  if (image)
219
224
    {
220
 
      horizontal_lower += img2real (shell, TRUE,
221
 
                                    FUNSCALEX (shell,
222
 
                                               (gdouble) shell->offset_x));
223
 
      horizontal_upper += img2real (shell, TRUE,
224
 
                                    FUNSCALEX (shell,
225
 
                                               (gdouble) shell->offset_x));
226
 
 
227
 
      vertical_lower   += img2real (shell, FALSE,
228
 
                                    FUNSCALEY (shell,
229
 
                                               (gdouble) shell->offset_y));
230
 
      vertical_upper   += img2real (shell, FALSE,
231
 
                                    FUNSCALEY (shell,
232
 
                                               (gdouble) shell->offset_y));
 
225
      gdouble offset_x;
 
226
      gdouble offset_y;
 
227
 
 
228
      offset_x = gimp_pixels_to_units (FUNSCALEX (shell,
 
229
                                                  (gdouble) shell->offset_x),
 
230
                                       shell->unit,
 
231
                                       resolution_x);
 
232
 
 
233
      offset_y = gimp_pixels_to_units (FUNSCALEX (shell,
 
234
                                                  (gdouble) shell->offset_y),
 
235
                                       shell->unit,
 
236
                                       resolution_y);
 
237
 
 
238
      horizontal_lower += offset_x;
 
239
      horizontal_upper += offset_x;
 
240
 
 
241
      vertical_lower   += offset_y;
 
242
      vertical_upper   += offset_y;
233
243
    }
234
244
 
235
245
  /* Finally setup the actual rulers */
327
337
    }
328
338
}
329
339
 
 
340
void
 
341
gimp_display_shell_get_screen_resolution (GimpDisplayShell *shell,
 
342
                                          gdouble          *xres,
 
343
                                          gdouble          *yres)
 
344
{
 
345
  gdouble x, y;
 
346
 
 
347
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
 
348
 
 
349
  if (shell->dot_for_dot)
 
350
    {
 
351
      gimp_image_get_resolution (gimp_display_get_image (shell->display),
 
352
                                 &x, &y);
 
353
    }
 
354
  else
 
355
    {
 
356
      x = shell->monitor_xres;
 
357
      y = shell->monitor_yres;
 
358
    }
 
359
 
 
360
  if (xres) *xres = x;
 
361
  if (yres) *yres = y;
 
362
}
 
363
 
330
364
/**
331
365
 * gimp_display_shell_scale:
332
366
 * @shell:     the #GimpDisplayShell
365
399
    {
366
400
      if (shell->display->config->resize_windows_on_zoom)
367
401
        {
 
402
          GimpImageWindow *window = gimp_display_shell_get_window (shell);
 
403
 
368
404
          /* If the window is resized on zoom, simply do the zoom and
369
405
           * get things rolling
370
406
           */
371
407
          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, real_new_scale);
372
408
          gimp_display_shell_scaled (shell);
373
409
 
374
 
          gimp_display_shell_shrink_wrap (shell, FALSE);
 
410
          if (window && gimp_image_window_get_active_shell (window) == shell)
 
411
            {
 
412
              gimp_image_window_shrink_wrap (window, FALSE);
 
413
            }
375
414
        }
376
415
      else
377
416
        {
448
487
 
449
488
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
450
489
 
451
 
  image = shell->display->image;
 
490
  image = gimp_display_get_image (shell->display);
452
491
 
453
492
  image_width  = gimp_image_get_width  (image);
454
493
  image_height = gimp_image_get_height (image);
524
563
 
525
564
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
526
565
 
527
 
  image = shell->display->image;
 
566
  image = gimp_display_get_image (shell->display);
528
567
 
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);
657
696
 
658
697
  if (resize_window)
659
 
    gimp_display_shell_shrink_wrap (shell, grow_only);
 
698
    {
 
699
      GimpImageWindow *window = gimp_display_shell_get_window (shell);
 
700
 
 
701
      if (window && gimp_image_window_get_active_shell (window) == shell)
 
702
        {
 
703
          gimp_image_window_shrink_wrap (window, grow_only);
 
704
        }
 
705
    }
660
706
 
661
707
  gimp_display_shell_scroll_clamp_and_update (shell);
662
708
  gimp_display_shell_scaled (shell);
676
722
 *
677
723
 **/
678
724
void
679
 
gimp_display_shell_calculate_scale_x_and_y (const GimpDisplayShell *shell,
680
 
                                            gdouble                 scale,
681
 
                                            gdouble                *scale_x,
682
 
                                            gdouble                *scale_y)
 
725
gimp_display_shell_calculate_scale_x_and_y (GimpDisplayShell *shell,
 
726
                                            gdouble           scale,
 
727
                                            gdouble          *scale_x,
 
728
                                            gdouble          *scale_y)
683
729
{
684
 
  gdouble xres;
685
 
  gdouble yres;
 
730
  GimpImage *image;
 
731
  gdouble    xres;
 
732
  gdouble    yres;
 
733
  gdouble    screen_xres;
 
734
  gdouble    screen_yres;
686
735
 
687
736
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
688
 
  g_return_if_fail (GIMP_IS_IMAGE (shell->display->image));
689
 
 
690
 
  gimp_image_get_resolution (shell->display->image, &xres, &yres);
691
 
 
692
 
  if (scale_x) *scale_x = scale * SCREEN_XRES (shell) / xres;
693
 
  if (scale_y) *scale_y = scale * SCREEN_YRES (shell) / yres;
 
737
 
 
738
  image = gimp_display_get_image (shell->display);
 
739
 
 
740
  g_return_if_fail (GIMP_IS_IMAGE (image));
 
741
 
 
742
  gimp_image_get_resolution (image, &xres, &yres);
 
743
  gimp_display_shell_get_screen_resolution (shell, &screen_xres, &screen_yres);
 
744
 
 
745
  if (scale_x) *scale_x = scale * screen_xres / xres;
 
746
  if (scale_y) *scale_y = scale * screen_yres / yres;
694
747
}
695
748
 
696
749
void
699
752
                                      gint             *display_width,
700
753
                                      gint             *display_height)
701
754
{
 
755
  GimpImage *image;
702
756
  GdkScreen *screen;
703
757
  gint       image_width;
704
758
  gint       image_height;
709
763
 
710
764
  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
711
765
 
 
766
  image = gimp_display_get_image (shell->display);
 
767
 
712
768
  screen = gtk_widget_get_screen (GTK_WIDGET (shell));
713
769
 
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);
716
772
 
717
773
  screen_width  = gdk_screen_get_width (screen)  * 0.75;
718
774
  screen_height = gdk_screen_get_height (screen) * 0.75;
771
827
}
772
828
 
773
829
/**
 
830
 * gimp_display_shell_push_zoom_focus_pointer_pos:
 
831
 * @shell:
 
832
 * @x:
 
833
 * @y:
 
834
 *
 
835
 * When the zoom focus mechanism asks for the pointer the next time,
 
836
 * use @x and @y.
 
837
 **/
 
838
void
 
839
gimp_display_shell_push_zoom_focus_pointer_pos (GimpDisplayShell *shell,
 
840
                                                gint              x,
 
841
                                                gint              y)
 
842
{
 
843
  GdkPoint *point = g_slice_new (GdkPoint);
 
844
  point->x = x;
 
845
  point->y = y;
 
846
 
 
847
  g_queue_push_head (shell->zoom_focus_pointer_queue,
 
848
                     point);
 
849
}
 
850
 
 
851
/**
774
852
 * gimp_display_shell_scale_to:
775
853
 * @shell:
776
854
 * @scale:
799
877
                                       viewport_x,
800
878
                                       viewport_y,
801
879
                                       &image_focus_x,
802
 
                                       &image_focus_y,
803
 
                                       FALSE);
 
880
                                       &image_focus_y);
804
881
 
805
882
  gimp_display_shell_calculate_scale_x_and_y (shell, scale, &scale_x, &scale_y);
806
883
 
953
1030
 
954
1031
  /* Calculate other focus point */
955
1032
  {
956
 
    GdkEvent *event;
957
 
    gboolean  event_looks_sane;
958
 
    gboolean  cursor_within_canvas;
959
 
    gint      canvas_pointer_x, canvas_pointer_y;
 
1033
    GdkEvent  *event;
 
1034
    GtkWidget *window;
 
1035
    gboolean   event_looks_sane;
 
1036
    gboolean   cursor_within_canvas;
 
1037
    gint       canvas_pointer_x, canvas_pointer_y;
 
1038
 
 
1039
    window = GTK_WIDGET (gimp_display_shell_get_window (shell));
960
1040
 
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)
969
1049
     *
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.
973
1053
 
974
1054
    event = gtk_get_current_event ();
975
1055
 
976
 
    event_looks_sane = ! event ||
977
 
                       gtk_get_event_widget (event) == shell->canvas ||
978
 
                       gtk_get_event_widget (event) == GTK_WIDGET (shell);
979
 
 
980
 
 
981
 
    gtk_widget_get_pointer (shell->canvas,
982
 
                            &canvas_pointer_x,
983
 
                            &canvas_pointer_y);
 
1056
    event_looks_sane = (! event ||
 
1057
                        gtk_get_event_widget (event) == shell->canvas ||
 
1058
                        gtk_get_event_widget (event) == window);
 
1059
 
 
1060
 
 
1061
    if (g_queue_peek_head (shell->zoom_focus_pointer_queue) == NULL)
 
1062
      {
 
1063
        gtk_widget_get_pointer (shell->canvas,
 
1064
                                &canvas_pointer_x,
 
1065
                                &canvas_pointer_y);
 
1066
      }
 
1067
    else
 
1068
      {
 
1069
        GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
 
1070
 
 
1071
        canvas_pointer_x = point->x;
 
1072
        canvas_pointer_y = point->y;
 
1073
 
 
1074
        g_slice_free (GdkPoint, point);
 
1075
      }
984
1076
 
985
1077
    cursor_within_canvas = canvas_pointer_x >= 0 &&
986
1078
                           canvas_pointer_y >= 0 &&
1053
1145
      break;
1054
1146
    }
1055
1147
}
1056
 
 
1057
 
/* scale image coord to realworld units (cm, inches, pixels)
1058
 
 *
1059
 
 * 27/Feb/1999 I tried inlining this, but the result was slightly
1060
 
 * slower (poorer cache locality, probably) -- austin
1061
 
 */
1062
 
static gdouble
1063
 
img2real (GimpDisplayShell *shell,
1064
 
          gboolean          xdir,
1065
 
          gdouble           len)
1066
 
{
1067
 
  gdouble xres;
1068
 
  gdouble yres;
1069
 
  gdouble res;
1070
 
 
1071
 
  if (shell->unit == GIMP_UNIT_PIXEL)
1072
 
    return len;
1073
 
 
1074
 
  gimp_image_get_resolution (shell->display->image, &xres, &yres);
1075
 
 
1076
 
  if (xdir)
1077
 
    res = xres;
1078
 
  else
1079
 
    res = yres;
1080
 
 
1081
 
  return len * _gimp_unit_get_factor (shell->display->gimp, shell->unit) / res;
1082
 
}