gimp r27104 - in trunk: . app/actions app/display



Author: martinn
Date: Thu Oct  2 14:53:35 2008
New Revision: 27104
URL: http://svn.gnome.org/viewvc/gimp?rev=27104&view=rev

Log:
Bug 553534 â centering issues after image scaling and setting zoom
to 100%

* app/display/display-enums.h: Added a GimpZoomFocus enum with
'best guess', 'pointer' or 'image center' values.

* app/display/gimpdisplayshell-scale.[ch]
(gimp_display_shell_scale): Take a GimpZoomFocus parameter and
pass it on to

(gimp_display_shell_scale_get_zoom_focus): which returns the
requested zoom focus point if one was given, else makes a best
guess.

* app/actions/view-commands.c
* app/display/gimpstatusbar.c
* app/display/gimpnavigationeditor.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-scale-dialog.c: For explicit-zoom
commands like "zoom to 100%", always use the image center as the
zoom focus point. For all other zooming, continue to use the
best-guess method.

* app/display/display-enums.c: Regenerated.


Modified:
   trunk/ChangeLog
   trunk/app/actions/view-commands.c
   trunk/app/display/display-enums.c
   trunk/app/display/display-enums.h
   trunk/app/display/gimpdisplayshell-callbacks.c
   trunk/app/display/gimpdisplayshell-scale-dialog.c
   trunk/app/display/gimpdisplayshell-scale.c
   trunk/app/display/gimpdisplayshell-scale.h
   trunk/app/display/gimpnavigationeditor.c
   trunk/app/display/gimpstatusbar.c

Modified: trunk/app/actions/view-commands.c
==============================================================================
--- trunk/app/actions/view-commands.c	(original)
+++ trunk/app/actions/view-commands.c	Thu Oct  2 14:53:35 2008
@@ -134,27 +134,45 @@
   switch ((GimpActionSelectType) value)
     {
     case GIMP_ACTION_SELECT_FIRST:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_OUT_MAX, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_OUT_MAX,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     case GIMP_ACTION_SELECT_LAST:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_IN_MAX, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_IN_MAX,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     case GIMP_ACTION_SELECT_PREVIOUS:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_OUT, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_OUT,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     case GIMP_ACTION_SELECT_NEXT:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_IN, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_IN,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     case GIMP_ACTION_SELECT_SKIP_PREVIOUS:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_OUT_MORE, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_OUT_MORE,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     case GIMP_ACTION_SELECT_SKIP_NEXT:
-      gimp_display_shell_scale (shell, GIMP_ZOOM_IN_MORE, 0.0);
+      gimp_display_shell_scale (shell,
+                                GIMP_ZOOM_IN_MORE,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
       break;
 
     default:
@@ -171,7 +189,10 @@
         /* scale = min *  (max / min)**(i/n), i = 0..n  */
         scale = pow (65536.0, scale / 512.0) / 256.0;
 
-        gimp_display_shell_scale (shell, GIMP_ZOOM_TO, scale);
+        gimp_display_shell_scale (shell,
+                                  GIMP_ZOOM_TO,
+                                  scale,
+                                  GIMP_ZOOM_FOCUS_BEST_GUESS);
         break;
       }
     }
@@ -194,7 +215,10 @@
   if (value != 0 /* not Other... */)
     {
       if (fabs (value - gimp_zoom_model_get_factor (shell->zoom)) > 0.0001)
-        gimp_display_shell_scale (shell, GIMP_ZOOM_TO, (gdouble) value / 10000);
+        gimp_display_shell_scale (shell,
+                                  GIMP_ZOOM_TO,
+                                  (gdouble) value / 10000,
+                                  GIMP_ZOOM_FOCUS_IMAGE_CENTER);
     }
 }
 

Modified: trunk/app/display/display-enums.c
==============================================================================
--- trunk/app/display/display-enums.c	(original)
+++ trunk/app/display/display-enums.c	Thu Oct  2 14:53:35 2008
@@ -158,6 +158,36 @@
   return type;
 }
 
+GType
+gimp_zoom_focus_get_type (void)
+{
+  static const GEnumValue values[] =
+  {
+    { GIMP_ZOOM_FOCUS_BEST_GUESS, "GIMP_ZOOM_FOCUS_BEST_GUESS", "best-guess" },
+    { GIMP_ZOOM_FOCUS_POINTER, "GIMP_ZOOM_FOCUS_POINTER", "pointer" },
+    { GIMP_ZOOM_FOCUS_IMAGE_CENTER, "GIMP_ZOOM_FOCUS_IMAGE_CENTER", "image-center" },
+    { 0, NULL, NULL }
+  };
+
+  static const GimpEnumDesc descs[] =
+  {
+    { GIMP_ZOOM_FOCUS_BEST_GUESS, "GIMP_ZOOM_FOCUS_BEST_GUESS", NULL },
+    { GIMP_ZOOM_FOCUS_POINTER, "GIMP_ZOOM_FOCUS_POINTER", NULL },
+    { GIMP_ZOOM_FOCUS_IMAGE_CENTER, "GIMP_ZOOM_FOCUS_IMAGE_CENTER", NULL },
+    { 0, NULL, NULL }
+  };
+
+  static GType type = 0;
+
+  if (! type)
+    {
+      type = g_enum_register_static ("GimpZoomFocus", values);
+      gimp_enum_set_value_descriptions (type, descs);
+    }
+
+  return type;
+}
+
 
 /* Generated data ends here */
 

Modified: trunk/app/display/display-enums.h
==============================================================================
--- trunk/app/display/display-enums.h	(original)
+++ trunk/app/display/display-enums.h	Thu Oct  2 14:53:35 2008
@@ -81,4 +81,16 @@
 } GimpZoomQuality;
 
 
+#define GIMP_TYPE_ZOOM_FOCUS (gimp_zoom_focus_get_type ())
+
+GType gimp_zoom_focus_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+  GIMP_ZOOM_FOCUS_BEST_GUESS,    /* Make a best guess                       */
+  GIMP_ZOOM_FOCUS_POINTER,       /* Use the mouse cursor (if within canvas) */
+  GIMP_ZOOM_FOCUS_IMAGE_CENTER   /* Use the image center                    */
+} GimpZoomFocus;
+
+
 #endif /* __DISPLAY_ENUMS_H__ */

Modified: trunk/app/display/gimpdisplayshell-callbacks.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-callbacks.c	(original)
+++ trunk/app/display/gimpdisplayshell-callbacks.c	Thu Oct  2 14:53:35 2008
@@ -1040,11 +1040,17 @@
             switch (direction)
               {
               case GDK_SCROLL_UP:
-                gimp_display_shell_scale (shell, GIMP_ZOOM_IN, 0.0);
+                gimp_display_shell_scale (shell,
+                                          GIMP_ZOOM_IN,
+                                          0.0,
+                                          GIMP_ZOOM_FOCUS_BEST_GUESS);
                 break;
 
               case GDK_SCROLL_DOWN:
-                gimp_display_shell_scale (shell, GIMP_ZOOM_OUT, 0.0);
+                gimp_display_shell_scale (shell,
+                                          GIMP_ZOOM_OUT,
+                                          0.0,
+                                          GIMP_ZOOM_FOCUS_BEST_GUESS);
                 break;
 
               default:

Modified: trunk/app/display/gimpdisplayshell-scale-dialog.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale-dialog.c	(original)
+++ trunk/app/display/gimpdisplayshell-scale-dialog.c	Thu Oct  2 14:53:35 2008
@@ -217,7 +217,10 @@
 
       scale = gtk_adjustment_get_value (GTK_ADJUSTMENT (dialog->scale_adj));
 
-      gimp_display_shell_scale (dialog->shell, GIMP_ZOOM_TO, scale / 100.0);
+      gimp_display_shell_scale (dialog->shell,
+                                GIMP_ZOOM_TO,
+                                scale / 100.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
     }
   else
     {

Modified: trunk/app/display/gimpdisplayshell-scale.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale.c	(original)
+++ trunk/app/display/gimpdisplayshell-scale.c	Thu Oct  2 14:53:35 2008
@@ -70,7 +70,8 @@
                                                           gdouble           new_scale,
                                                           gdouble           current_scale,
                                                           gint             *x,
-                                                          gint             *y);
+                                                          gint             *y,
+                                                          GimpZoomFocus     zoom_focus);
 
 static gdouble   img2real                                (GimpDisplayShell *shell,
                                                           gboolean          xdir,
@@ -334,7 +335,8 @@
 void
 gimp_display_shell_scale (GimpDisplayShell *shell,
                           GimpZoomType      zoom_type,
-                          gdouble           new_scale)
+                          gdouble           new_scale,
+                          GimpZoomFocus     zoom_focus)
 {
   gint    x, y;
   gdouble current_scale;
@@ -375,7 +377,8 @@
                                                    real_new_scale,
                                                    current_scale,
                                                    &x,
-                                                   &y);
+                                                   &y,
+                                                   zoom_focus);
 
           gimp_display_shell_scale_to (shell, real_new_scale, x, y);
 
@@ -438,7 +441,11 @@
   zoom_factor = MIN ((gdouble) shell->disp_width  / (gdouble) image_width,
                      (gdouble) shell->disp_height / (gdouble) image_height);
 
-  gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
+  gimp_display_shell_scale (shell,
+                            GIMP_ZOOM_TO,
+                            zoom_factor,
+                            GIMP_ZOOM_FOCUS_BEST_GUESS);
+  
   gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
 }
 
@@ -510,7 +517,11 @@
   zoom_factor = MAX ((gdouble) shell->disp_width  / (gdouble) image_width,
                      (gdouble) shell->disp_height / (gdouble) image_height);
 
-  gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
+  gimp_display_shell_scale (shell,
+                            GIMP_ZOOM_TO,
+                            zoom_factor,
+                            GIMP_ZOOM_FOCUS_BEST_GUESS);
+
   gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
 }
 
@@ -883,7 +894,8 @@
                                          gdouble           new_scale,
                                          gdouble           current_scale,
                                          gint             *x,
-                                         gint             *y)
+                                         gint             *y,
+                                         GimpZoomFocus     zoom_focus)
 {
   gint image_center_x, image_center_y;
   gint other_x, other_y;
@@ -949,23 +961,39 @@
   }
 
   /* Decide which one to use for each axis */
-  {
-    gboolean within_horizontally, within_vertically;
-    gboolean stops_horizontally, stops_vertically;
+  switch (zoom_focus)
+    {
+    case GIMP_ZOOM_FOCUS_POINTER:
+      *x = other_x;
+      *y = other_y;
+      break;
+
+    case GIMP_ZOOM_FOCUS_IMAGE_CENTER:
+      *x = image_center_x;
+      *y = image_center_y;
+      break;
+
+    case GIMP_ZOOM_FOCUS_BEST_GUESS:
+    default:
+      {
+        gboolean within_horizontally, within_vertically;
+        gboolean stops_horizontally, stops_vertically;
 
-    gimp_display_shell_scale_image_is_within_viewport (shell,
-                                                       &within_horizontally,
-                                                       &within_vertically);
-
-    gimp_display_shell_scale_image_stops_to_fit (shell,
-                                                 new_scale,
-                                                 current_scale,
-                                                 &stops_horizontally,
-                                                 &stops_vertically);
+        gimp_display_shell_scale_image_is_within_viewport (shell,
+                                                           &within_horizontally,
+                                                           &within_vertically);
+
+        gimp_display_shell_scale_image_stops_to_fit (shell,
+                                                     new_scale,
+                                                     current_scale,
+                                                     &stops_horizontally,
+                                                     &stops_vertically);
 
-    *x = within_horizontally && ! stops_horizontally ? image_center_x : other_x;
-    *y = within_vertically   && ! stops_vertically   ? image_center_y : other_y;
-  }
+        *x = within_horizontally && ! stops_horizontally ? image_center_x : other_x;
+        *y = within_vertically   && ! stops_vertically   ? image_center_y : other_y;
+      }
+      break;
+    }
 }
 
 /* scale image coord to realworld units (cm, inches, pixels)

Modified: trunk/app/display/gimpdisplayshell-scale.h
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale.h	(original)
+++ trunk/app/display/gimpdisplayshell-scale.h	Thu Oct  2 14:53:35 2008
@@ -32,7 +32,8 @@
 
 void     gimp_display_shell_scale                          (GimpDisplayShell       *shell,
                                                             GimpZoomType            zoom_type,
-                                                            gdouble                 scale);
+                                                            gdouble                 scale,
+                                                            GimpZoomFocus           zoom_focus);
 void     gimp_display_shell_scale_fit_in                   (GimpDisplayShell       *shell);
 gboolean gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell       *shell,
                                                             gboolean               *horizontally,

Modified: trunk/app/display/gimpnavigationeditor.c
==============================================================================
--- trunk/app/display/gimpnavigationeditor.c	(original)
+++ trunk/app/display/gimpnavigationeditor.c	Thu Oct  2 14:53:35 2008
@@ -534,7 +534,10 @@
 
   if (editor->shell)
     {
-      gimp_display_shell_scale (editor->shell, direction, 0.0);
+      gimp_display_shell_scale (editor->shell,
+                                direction,
+                                0.0,
+                                GIMP_ZOOM_FOCUS_BEST_GUESS);
     }
 }
 
@@ -588,8 +591,10 @@
 gimp_navigation_editor_zoom_adj_changed (GtkAdjustment        *adj,
                                          GimpNavigationEditor *editor)
 {
-  gimp_display_shell_scale (editor->shell, GIMP_ZOOM_TO,
-                            pow (2.0, gtk_adjustment_get_value (adj)));
+  gimp_display_shell_scale (editor->shell,
+                            GIMP_ZOOM_TO,
+                            pow (2.0, gtk_adjustment_get_value (adj)),
+                            GIMP_ZOOM_FOCUS_BEST_GUESS);
 }
 
 static void

Modified: trunk/app/display/gimpstatusbar.c
==============================================================================
--- trunk/app/display/gimpstatusbar.c	(original)
+++ trunk/app/display/gimpstatusbar.c	Thu Oct  2 14:53:35 2008
@@ -1386,7 +1386,8 @@
 {
   gimp_display_shell_scale (statusbar->shell,
                             GIMP_ZOOM_TO,
-                            gimp_scale_combo_box_get_scale (combo));
+                            gimp_scale_combo_box_get_scale (combo),
+                            GIMP_ZOOM_FOCUS_BEST_GUESS);
 }
 
 static guint



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]