[gimp] app: simplify gimp_display_shell_scale_get_zoom_focus()



commit dd1809bc2114c383db367953cd7ebfa525fdfb26
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jan 14 23:57:40 2016 +0100

    app: simplify gimp_display_shell_scale_get_zoom_focus()
    
    The logic should be exactly as before, just less convoluted.

 app/display/gimpdisplayshell-scale.c |  151 +++++++++++++++-------------------
 1 files changed, 68 insertions(+), 83 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 338f11d..499447e 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -1061,101 +1061,86 @@ gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
                                          gdouble          *y,
                                          GimpZoomFocus     zoom_focus)
 {
-  GimpZoomFocus real_zoom_focus = zoom_focus;
-  gint          image_center_x, image_center_y;
-  gint          other_x, other_y;
+  GtkWidget *window = GTK_WIDGET (gimp_display_shell_get_window (shell));
+  GdkEvent  *event;
+  gint       image_center_x;
+  gint       image_center_y;
+  gint       other_x;
+  gint       other_y;
 
   /* Calculate stops-to-fit focus point */
   gimp_display_shell_scale_get_image_center_viewport (shell,
                                                       &image_center_x,
                                                       &image_center_y);
 
-  /* Calculate other focus point */
-  {
-    GdkEvent  *event;
-    GtkWidget *window;
-    gboolean   event_looks_sane;
-    gboolean   cursor_within_canvas;
-    gdouble    canvas_pointer_x, canvas_pointer_y;
-
-    window = GTK_WIDGET (gimp_display_shell_get_window (shell));
-
-    /*  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 window (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_looks_sane = (! event ||
-                        gtk_get_event_widget (event) == shell->canvas ||
-                        gtk_get_event_widget (event) == window);
-
-
-    if (g_queue_peek_head (shell->zoom_focus_pointer_queue) == NULL)
-      {
-        gint px, py;
-
-        gtk_widget_get_pointer (shell->canvas, &px, &py);
-
-        canvas_pointer_x = px;
-        canvas_pointer_y = py;
-      }
-    else
-      {
-        GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
+  /* Calculate other focus point, default is the canvas center */
+  other_x = shell->disp_width  / 2;
+  other_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 window (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 ();
 
-        canvas_pointer_x = point->x;
-        canvas_pointer_y = point->y;
+  if (! event ||
+      gtk_get_event_widget (event) == shell->canvas ||
+      gtk_get_event_widget (event) == window)
+    {
+      GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
+      gint      canvas_pointer_x;
+      gint      canvas_pointer_y;
 
-        g_slice_free (GdkPoint, point);
-      }
+      if (point)
+        {
+          canvas_pointer_x = point->x;
+          canvas_pointer_y = point->y;
 
-    cursor_within_canvas = canvas_pointer_x >= 0 &&
-                           canvas_pointer_y >= 0 &&
-                           canvas_pointer_x <  shell->disp_width &&
-                           canvas_pointer_y <  shell->disp_height;
+          g_slice_free (GdkPoint, point);
+        }
+      else
+        {
+          gtk_widget_get_pointer (shell->canvas,
+                                  &canvas_pointer_x,
+                                  &canvas_pointer_y);
+        }
 
-    if (event_looks_sane && cursor_within_canvas)
-      {
-        other_x = canvas_pointer_x;
-        other_y = canvas_pointer_y;
-      }
-    else
-      {
-        other_x = shell->disp_width  / 2;
-        other_y = shell->disp_height / 2;
-      }
-  }
+      if (canvas_pointer_x >= 0 &&
+          canvas_pointer_y >= 0 &&
+          canvas_pointer_x <  shell->disp_width &&
+          canvas_pointer_y <  shell->disp_height)
+        {
+          other_x = canvas_pointer_x;
+          other_y = canvas_pointer_y;
+        }
+    }
 
   /* Decide which one to use for each axis */
   if (zoom_focus == GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS)
     {
-      gboolean centered;
-
-      centered = gimp_display_shell_scale_viewport_coord_almost_centered (shell,
-                                                                          image_center_x,
-                                                                          image_center_y,
-                                                                          NULL,
-                                                                          NULL);
-      real_zoom_focus = (centered ?
-                         GIMP_ZOOM_FOCUS_IMAGE_CENTER :
-                         GIMP_ZOOM_FOCUS_BEST_GUESS);
-    }
-  else
-    {
-      real_zoom_focus = zoom_focus;
+      if (gimp_display_shell_scale_viewport_coord_almost_centered (shell,
+                                                                   image_center_x,
+                                                                   image_center_y,
+                                                                   NULL,
+                                                                   NULL))
+        {
+          zoom_focus = GIMP_ZOOM_FOCUS_IMAGE_CENTER;
+        }
+      else
+        {
+          zoom_focus = GIMP_ZOOM_FOCUS_BEST_GUESS;
+        }
     }
 
-  switch (real_zoom_focus)
+  switch (zoom_focus)
     {
     case GIMP_ZOOM_FOCUS_POINTER:
       *x = other_x;


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