app: simplify gimp_display_shell_scale_get_zoom_focus()
The logic should be exactly as before, just less convoluted.
This commit is contained in:
@ -1061,101 +1061,86 @@ 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
|
||||||
|
* 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 ();
|
||||||
|
|
||||||
/* Center on the mouse position instead of the display center if
|
if (! event ||
|
||||||
* one of the following conditions are fulfilled and pointer is
|
gtk_get_event_widget (event) == shell->canvas ||
|
||||||
* within the canvas:
|
gtk_get_event_widget (event) == window)
|
||||||
*
|
{
|
||||||
* (1) there's no current event (the action was triggered by an
|
GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
|
||||||
* input controller)
|
gint canvas_pointer_x;
|
||||||
* (2) the event originates from the canvas (a scroll event)
|
gint canvas_pointer_y;
|
||||||
* (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 ();
|
if (point)
|
||||||
|
{
|
||||||
|
canvas_pointer_x = point->x;
|
||||||
|
canvas_pointer_y = point->y;
|
||||||
|
|
||||||
event_looks_sane = (! event ||
|
g_slice_free (GdkPoint, point);
|
||||||
gtk_get_event_widget (event) == shell->canvas ||
|
}
|
||||||
gtk_get_event_widget (event) == window);
|
else
|
||||||
|
{
|
||||||
|
gtk_widget_get_pointer (shell->canvas,
|
||||||
|
&canvas_pointer_x,
|
||||||
|
&canvas_pointer_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (canvas_pointer_x >= 0 &&
|
||||||
if (g_queue_peek_head (shell->zoom_focus_pointer_queue) == NULL)
|
canvas_pointer_y >= 0 &&
|
||||||
{
|
canvas_pointer_x < shell->disp_width &&
|
||||||
gint px, py;
|
canvas_pointer_y < shell->disp_height)
|
||||||
|
{
|
||||||
gtk_widget_get_pointer (shell->canvas, &px, &py);
|
other_x = canvas_pointer_x;
|
||||||
|
other_y = canvas_pointer_y;
|
||||||
canvas_pointer_x = px;
|
}
|
||||||
canvas_pointer_y = py;
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GdkPoint *point = g_queue_pop_head (shell->zoom_focus_pointer_queue);
|
|
||||||
|
|
||||||
canvas_pointer_x = point->x;
|
|
||||||
canvas_pointer_y = point->y;
|
|
||||||
|
|
||||||
g_slice_free (GdkPoint, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor_within_canvas = canvas_pointer_x >= 0 &&
|
|
||||||
canvas_pointer_y >= 0 &&
|
|
||||||
canvas_pointer_x < shell->disp_width &&
|
|
||||||
canvas_pointer_y < shell->disp_height;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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,
|
||||||
|
image_center_x,
|
||||||
centered = gimp_display_shell_scale_viewport_coord_almost_centered (shell,
|
image_center_y,
|
||||||
image_center_x,
|
NULL,
|
||||||
image_center_y,
|
NULL))
|
||||||
NULL,
|
{
|
||||||
NULL);
|
zoom_focus = GIMP_ZOOM_FOCUS_IMAGE_CENTER;
|
||||||
real_zoom_focus = (centered ?
|
}
|
||||||
GIMP_ZOOM_FOCUS_IMAGE_CENTER :
|
else
|
||||||
GIMP_ZOOM_FOCUS_BEST_GUESS);
|
{
|
||||||
}
|
zoom_focus = GIMP_ZOOM_FOCUS_BEST_GUESS;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
real_zoom_focus = zoom_focus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (real_zoom_focus)
|
switch (zoom_focus)
|
||||||
{
|
{
|
||||||
case GIMP_ZOOM_FOCUS_POINTER:
|
case GIMP_ZOOM_FOCUS_POINTER:
|
||||||
*x = other_x;
|
*x = other_x;
|
||||||
|
Reference in New Issue
Block a user