app: simplify gimp_display_shell_scale_get_zoom_focus()

The logic should be exactly as before, just less convoluted.
This commit is contained in:
Michael Natterer
2016-01-14 23:57:40 +01:00
parent e3f88fc4ef
commit dd1809bc21

View File

@ -1061,24 +1061,21 @@ gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
gdouble *y, gdouble *y,
GimpZoomFocus zoom_focus) GimpZoomFocus zoom_focus)
{ {
GimpZoomFocus real_zoom_focus = zoom_focus; GtkWidget *window = GTK_WIDGET (gimp_display_shell_get_window (shell));
gint image_center_x, image_center_y; GdkEvent *event;
gint other_x, other_y; gint image_center_x;
gint image_center_y;
gint other_x;
gint other_y;
/* Calculate stops-to-fit focus point */ /* Calculate stops-to-fit focus point */
gimp_display_shell_scale_get_image_center_viewport (shell, gimp_display_shell_scale_get_image_center_viewport (shell,
&image_center_x, &image_center_x,
&image_center_y); &image_center_y);
/* Calculate other focus point */ /* Calculate other focus point, default is the canvas center */
{ other_x = shell->disp_width / 2;
GdkEvent *event; other_y = shell->disp_height / 2;
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 /* Center on the mouse position instead of the display center if
* one of the following conditions are fulfilled and pointer is * one of the following conditions are fulfilled and pointer is
@ -1092,70 +1089,58 @@ gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
* Basically the only situation where we don't want to center on * Basically the only situation where we don't want to center on
* mouse position is if the action is being called from a menu. * mouse position is if the action is being called from a menu.
*/ */
event = gtk_get_current_event (); event = gtk_get_current_event ();
event_looks_sane = (! event || if (! event ||
gtk_get_event_widget (event) == shell->canvas || gtk_get_event_widget (event) == shell->canvas ||
gtk_get_event_widget (event) == window); 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); GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
gint canvas_pointer_x;
gint canvas_pointer_y;
if (point)
{
canvas_pointer_x = point->x; canvas_pointer_x = point->x;
canvas_pointer_y = point->y; canvas_pointer_y = point->y;
g_slice_free (GdkPoint, point); g_slice_free (GdkPoint, point);
} }
else
{
gtk_widget_get_pointer (shell->canvas,
&canvas_pointer_x,
&canvas_pointer_y);
}
cursor_within_canvas = canvas_pointer_x >= 0 && if (canvas_pointer_x >= 0 &&
canvas_pointer_y >= 0 && canvas_pointer_y >= 0 &&
canvas_pointer_x < shell->disp_width && canvas_pointer_x < shell->disp_width &&
canvas_pointer_y < shell->disp_height; canvas_pointer_y < shell->disp_height)
if (event_looks_sane && cursor_within_canvas)
{ {
other_x = canvas_pointer_x; other_x = canvas_pointer_x;
other_y = canvas_pointer_y; other_y = canvas_pointer_y;
} }
else
{
other_x = shell->disp_width / 2;
other_y = shell->disp_height / 2;
}
} }
/* Decide which one to use for each axis */ /* Decide which one to use for each axis */
if (zoom_focus == GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS) if (zoom_focus == GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS)
{ {
gboolean centered; if (gimp_display_shell_scale_viewport_coord_almost_centered (shell,
centered = gimp_display_shell_scale_viewport_coord_almost_centered (shell,
image_center_x, image_center_x,
image_center_y, image_center_y,
NULL, NULL,
NULL); NULL))
real_zoom_focus = (centered ? {
GIMP_ZOOM_FOCUS_IMAGE_CENTER : zoom_focus = GIMP_ZOOM_FOCUS_IMAGE_CENTER;
GIMP_ZOOM_FOCUS_BEST_GUESS);
} }
else else
{ {
real_zoom_focus = zoom_focus; zoom_focus = GIMP_ZOOM_FOCUS_BEST_GUESS;
}
} }
switch (real_zoom_focus) switch (zoom_focus)
{ {
case GIMP_ZOOM_FOCUS_POINTER: case GIMP_ZOOM_FOCUS_POINTER:
*x = other_x; *x = other_x;