mirror of https://github.com/GNOME/gimp.git
app: add gimp_display_shell_scale_to_rectangle()
and move the magnify tool's rectangle zoom logic to the new function.
This commit is contained in:
parent
b7f471b1a3
commit
ded7c8f585
|
@ -496,6 +496,133 @@ gimp_display_shell_scale (GimpDisplayShell *shell,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_display_shell_scale_to_rectangle:
|
||||
* @shell: the #GimpDisplayShell
|
||||
* @zoom_type: whether to zoom in or out
|
||||
* @x: retangle's x in image coordinates
|
||||
* @y: retangle's y in image coordinates
|
||||
* @width: retangle's width in image coordinates
|
||||
* @height: retangle's height in image coordinates
|
||||
* @resize_window: whether the display window should be resized
|
||||
*
|
||||
* Scales and scrolls to a specific image rectangle
|
||||
**/
|
||||
void
|
||||
gimp_display_shell_scale_to_rectangle (GimpDisplayShell *shell,
|
||||
GimpZoomType zoom_type,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble width,
|
||||
gdouble height,
|
||||
gboolean resize_window)
|
||||
{
|
||||
gdouble current_scale;
|
||||
gdouble new_scale;
|
||||
gdouble display_width;
|
||||
gdouble display_height;
|
||||
gdouble factor = 1.0;
|
||||
|
||||
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
|
||||
|
||||
width = MAX (1.0, width);
|
||||
height = MAX (1.0, height);
|
||||
|
||||
current_scale = gimp_zoom_model_get_factor (shell->zoom);
|
||||
|
||||
display_width = FUNSCALEX (shell, shell->disp_width);
|
||||
display_height = FUNSCALEY (shell, shell->disp_height);
|
||||
|
||||
switch (zoom_type)
|
||||
{
|
||||
case GIMP_ZOOM_IN:
|
||||
factor = MIN ((display_width / width),
|
||||
(display_height / height));
|
||||
break;
|
||||
|
||||
case GIMP_ZOOM_OUT:
|
||||
factor = MAX ((width / display_width),
|
||||
(height / display_height));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
new_scale = current_scale * factor;
|
||||
|
||||
if (new_scale != current_scale)
|
||||
{
|
||||
GimpImage *image = gimp_display_get_image (shell->display);
|
||||
gint offset_x = 0;
|
||||
gint offset_y = 0;
|
||||
gdouble xres;
|
||||
gdouble yres;
|
||||
gdouble screen_xres;
|
||||
gdouble screen_yres;
|
||||
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
gimp_display_shell_get_screen_resolution (shell,
|
||||
&screen_xres, &screen_yres);
|
||||
|
||||
switch (zoom_type)
|
||||
{
|
||||
case GIMP_ZOOM_IN:
|
||||
/* move the center of the rectangle to the center of the
|
||||
* viewport:
|
||||
*
|
||||
* new_offset = center of rectangle in new scale screen coords
|
||||
* including offset
|
||||
* -
|
||||
* center of viewport in screen coords without
|
||||
* offset
|
||||
*/
|
||||
offset_x = RINT (new_scale * (x + width / 2.0) *
|
||||
screen_xres / xres -
|
||||
(shell->disp_width / 2.0));
|
||||
|
||||
offset_y = RINT (new_scale * (y + height / 2.0) *
|
||||
screen_yres / yres -
|
||||
(shell->disp_height / 2.0));
|
||||
break;
|
||||
|
||||
case GIMP_ZOOM_OUT:
|
||||
/* move the center of the viewport to the center of the
|
||||
* rectangle:
|
||||
*
|
||||
* new_offset = center of viewport in new scale screen coords
|
||||
* including offset
|
||||
* -
|
||||
* center of rectangle in screen coords without
|
||||
* offset
|
||||
*/
|
||||
offset_x = RINT (new_scale * UNSCALEX (shell,
|
||||
shell->offset_x +
|
||||
shell->disp_width / 2.0) *
|
||||
screen_xres / xres -
|
||||
(SCALEX (shell, x + width / 2.0) -
|
||||
shell->offset_x));
|
||||
|
||||
offset_y = RINT (new_scale * UNSCALEY (shell,
|
||||
shell->offset_y +
|
||||
shell->disp_height / 2.0) *
|
||||
screen_yres / yres -
|
||||
(SCALEY (shell, y + height / 2.0) -
|
||||
shell->offset_y));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gimp_display_shell_scale_by_values (shell,
|
||||
new_scale,
|
||||
offset_x, offset_y,
|
||||
resize_window);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_display_shell_scale_fit_in:
|
||||
* @shell: the #GimpDisplayShell
|
||||
|
|
|
@ -43,6 +43,13 @@ void gimp_display_shell_scale (GimpDisplayShell *sh
|
|||
GimpZoomType zoom_type,
|
||||
gdouble scale,
|
||||
GimpZoomFocus zoom_focus);
|
||||
void gimp_display_shell_scale_to_rectangle (GimpDisplayShell *shell,
|
||||
GimpZoomType zoom_type,
|
||||
gdouble x,
|
||||
gdouble y,
|
||||
gdouble width,
|
||||
gdouble height,
|
||||
gboolean resize_window);
|
||||
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
|
||||
gboolean gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell,
|
||||
gboolean *horizontally,
|
||||
|
|
|
@ -183,116 +183,18 @@ gimp_magnify_tool_button_release (GimpTool *tool,
|
|||
|
||||
case GIMP_BUTTON_RELEASE_NORMAL:
|
||||
{
|
||||
gdouble x1, y1, x2, y2;
|
||||
gdouble x, y;
|
||||
gdouble width, height;
|
||||
gdouble current_scale;
|
||||
gdouble new_scale;
|
||||
gdouble display_width;
|
||||
gdouble display_height;
|
||||
gdouble factor = 1.0;
|
||||
|
||||
x1 = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
|
||||
y1 = (magnify->h < 0) ? magnify->y + magnify->h : magnify->y;
|
||||
x = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
|
||||
y = (magnify->h < 0) ? magnify->y + magnify->h : magnify->y;
|
||||
width = (magnify->w < 0) ? -magnify->w : magnify->w;
|
||||
height = (magnify->h < 0) ? -magnify->h : magnify->h;
|
||||
x2 = x1 + width;
|
||||
y2 = y1 + height;
|
||||
|
||||
width = MAX (1.0, width);
|
||||
height = MAX (1.0, height);
|
||||
|
||||
current_scale = gimp_zoom_model_get_factor (shell->zoom);
|
||||
|
||||
display_width = FUNSCALEX (shell, shell->disp_width);
|
||||
display_height = FUNSCALEY (shell, shell->disp_height);
|
||||
|
||||
switch (options->zoom_type)
|
||||
{
|
||||
case GIMP_ZOOM_IN:
|
||||
factor = MIN ((display_width / width),
|
||||
(display_height / height));
|
||||
break;
|
||||
|
||||
case GIMP_ZOOM_OUT:
|
||||
factor = MAX ((width / display_width),
|
||||
(height / display_height));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
new_scale = current_scale * factor;
|
||||
|
||||
if (new_scale != current_scale)
|
||||
{
|
||||
gint offset_x = 0;
|
||||
gint offset_y = 0;
|
||||
gdouble xres;
|
||||
gdouble yres;
|
||||
gdouble screen_xres;
|
||||
gdouble screen_yres;
|
||||
|
||||
gimp_image_get_resolution (gimp_display_get_image (display),
|
||||
&xres, &yres);
|
||||
gimp_display_shell_get_screen_resolution (shell,
|
||||
&screen_xres, &screen_yres);
|
||||
|
||||
switch (options->zoom_type)
|
||||
{
|
||||
case GIMP_ZOOM_IN:
|
||||
/* move the center of the rectangle to the center of the
|
||||
* viewport:
|
||||
*
|
||||
* new_offset = center of rectangle in new scale screen coords
|
||||
* including offset
|
||||
* -
|
||||
* center of viewport in screen coords without
|
||||
* offset
|
||||
*/
|
||||
offset_x = RINT (new_scale * ((x1 + x2) / 2.0) *
|
||||
screen_xres / xres -
|
||||
(shell->disp_width / 2.0));
|
||||
|
||||
offset_y = RINT (new_scale * ((y1 + y2) / 2.0) *
|
||||
screen_yres / yres -
|
||||
(shell->disp_height / 2.0));
|
||||
break;
|
||||
|
||||
case GIMP_ZOOM_OUT:
|
||||
/* move the center of the viewport to the center of the
|
||||
* rectangle:
|
||||
*
|
||||
* new_offset = center of viewport in new scale screen coords
|
||||
* including offset
|
||||
* -
|
||||
* center of rectangle in screen coords without
|
||||
* offset
|
||||
*/
|
||||
offset_x = RINT (new_scale * UNSCALEX (shell,
|
||||
shell->offset_x +
|
||||
shell->disp_width / 2.0) *
|
||||
screen_xres / xres -
|
||||
(SCALEX (shell, (x1 + x2) / 2.0) -
|
||||
shell->offset_x));
|
||||
|
||||
offset_y = RINT (new_scale * UNSCALEY (shell,
|
||||
shell->offset_y +
|
||||
shell->disp_height / 2.0) *
|
||||
screen_yres / yres -
|
||||
(SCALEY (shell, (y1 + y2) / 2.0) -
|
||||
shell->offset_y));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
gimp_display_shell_scale_by_values (shell,
|
||||
new_scale,
|
||||
offset_x, offset_y,
|
||||
options->auto_resize);
|
||||
}
|
||||
gimp_display_shell_scale_to_rectangle (shell,
|
||||
options->zoom_type,
|
||||
x, y, width, height,
|
||||
options->auto_resize);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue