gimp r26560 - in trunk: . app/display



Author: martinn
Date: Thu Aug 14 17:41:38 2008
New Revision: 26560
URL: http://svn.gnome.org/viewvc/gimp?rev=26560&view=rev

Log:
2008-08-14  Martin Nordholts  <martinn svn gnome org>

	* app/display/gimpdisplayshell-scale.c
	(gimp_display_shell_scale_get_zoom_focus): If the image is within
	the viewport and we are zooming out, make the focus point be the
	center of the image.


Modified:
   trunk/ChangeLog
   trunk/app/display/gimpdisplayshell-scale.c

Modified: trunk/app/display/gimpdisplayshell-scale.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-scale.c	(original)
+++ trunk/app/display/gimpdisplayshell-scale.c	Thu Aug 14 17:41:38 2008
@@ -74,6 +74,7 @@
                                                       gdouble           x,
                                                       gdouble           y);
 static void gimp_display_shell_scale_get_zoom_focus  (GimpDisplayShell *shell,
+                                                      gdouble           new_scale,
                                                       gint             *x,
                                                       gint             *y);
 
@@ -363,7 +364,7 @@
 
   if (! SCALE_EQUALS (real_new_scale, current_scale))
     {
-      gimp_display_shell_scale_get_zoom_focus (shell, &x, &y);
+      gimp_display_shell_scale_get_zoom_focus (shell, real_new_scale, &x, &y);
 
       gimp_display_shell_scale_to (shell, real_new_scale, x, y);
     }
@@ -888,6 +889,7 @@
 /**
  * gimp_display_shell_scale_get_zoom_focus:
  * @shell:
+ * @new_scale:
  * @x:
  * @y:
  *
@@ -895,47 +897,66 @@
  **/
 static void
 gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
+                                         gdouble           new_scale,
                                          gint             *x,
                                          gint             *y)
 {
   GdkEvent *event;
+  gdouble   current_scale = gimp_zoom_model_get_factor (shell->zoom);
 
-  *x = shell->disp_width  / 2;
-  *y = shell->disp_height / 2;
+  if (new_scale < current_scale &&
+      gimp_display_shell_scale_image_is_within_viewport (shell))
+    {
+      /* If the image is within the viewport and we are zooming out, put
+       * the zoom focus in the center of the image
+       */
+      gint sw, sh;
 
-  /*  Center on the mouse position instead of the display center if
-   *  one of the following conditions are fulfilled and pointer is
-   *  within the canvas:
-   *
-   *   (1) there's no current event (the action was triggered by an
-   *       input controller)
-   *   (2) the event originates from the canvas (a scroll event)
-   *   (3) the event originates from the shell (a key press event)
-   *
-   *  Basically the only situation where we don't want to center on
-   *  mouse position is if the action is being called from a menu.
-   */
+      gimp_display_shell_draw_get_scaled_image_size (shell,
+                                                     &sw,
+                                                     &sh);
+      *x = -shell->offset_x + sw / 2;
+      *y = -shell->offset_y + sh / 2;
+    }
+  else
+    {
+      *x = shell->disp_width  / 2;
+      *y = shell->disp_height / 2;
+
+      /*  Center on the mouse position instead of the display center if
+       *  one of the following conditions are fulfilled and pointer is
+       *  within the canvas:
+       *
+       *   (1) there's no current event (the action was triggered by an
+       *       input controller)
+       *   (2) the event originates from the canvas (a scroll event)
+       *   (3) the event originates from the shell (a key press event)
+       *
+       *  Basically the only situation where we don't want to center on
+       *  mouse position is if the action is being called from a menu.
+       */
 
-  event = gtk_get_current_event ();
+      event = gtk_get_current_event ();
 
-  if (! event ||
-      gtk_get_event_widget (event) == shell->canvas ||
-      gtk_get_event_widget (event) == GTK_WIDGET (shell))
-    {
-      gint canvas_pointer_x;
-      gint canvas_pointer_y;
-
-      gtk_widget_get_pointer (shell->canvas,
-                              &canvas_pointer_x,
-                              &canvas_pointer_y);
-
-      if (canvas_pointer_x >= 0 &&
-          canvas_pointer_y >= 0 &&
-          canvas_pointer_x < shell->disp_width &&
-          canvas_pointer_y < shell->disp_height)
+      if (! event ||
+          gtk_get_event_widget (event) == shell->canvas ||
+          gtk_get_event_widget (event) == GTK_WIDGET (shell))
         {
-          *x = canvas_pointer_x;
-          *y = canvas_pointer_y;
+          gint canvas_pointer_x;
+          gint canvas_pointer_y;
+
+          gtk_widget_get_pointer (shell->canvas,
+                                  &canvas_pointer_x,
+                                  &canvas_pointer_y);
+
+          if (canvas_pointer_x >= 0 &&
+              canvas_pointer_y >= 0 &&
+              canvas_pointer_x < shell->disp_width &&
+              canvas_pointer_y < shell->disp_height)
+            {
+              *x = canvas_pointer_x;
+              *y = canvas_pointer_y;
+            }
         }
     }
 }



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