Commit 5530ef63 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

turn nested if()s into a switch(release_type).

2008-10-28  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimpmagnifytool.c (gimp_magnify_tool_button_release):
	turn nested if()s into a switch(release_type).


svn path=/trunk/; revision=27455
parent df6ab7d2
2008-10-28 Michael Natterer <mitch@gimp.org>
* app/tools/gimpmagnifytool.c (gimp_magnify_tool_button_release):
turn nested if()s into a switch(release_type).
2008-10-28 Martin Nordholts <martinn@svn.gnome.org>
Bug 556603 – Zoom region always zooms in center of image
......
......@@ -168,125 +168,128 @@ gimp_magnify_tool_button_release (GimpTool *tool,
gimp_tool_control_halt (tool->control);
if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
switch (release_type)
{
gdouble x1, y1, x2, y2;
gdouble width, height;
gdouble current_scale;
gdouble new_scale;
x1 = (magnify->w < 0) ? magnify->x + magnify->w : magnify->x;
y1 = (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);
if (release_type == GIMP_BUTTON_RELEASE_CLICK ||
release_type == GIMP_BUTTON_RELEASE_NO_MOTION)
{
gimp_display_shell_scale (shell,
options->zoom_type,
0.0,
GIMP_ZOOM_FOCUS_BEST_GUESS);
}
else
{
gdouble display_width;
gdouble display_height;
gdouble factor = 1.0;
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)
{
gdouble xres;
gdouble yres;
gint offset_x = 0;
gint offset_y = 0;
gimp_image_get_resolution (display->image, &xres, &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 (shell) / xres -
(shell->disp_width / 2.0));
offset_y = RINT (new_scale * ((y1 + y2) / 2.0) *
SCREEN_YRES (shell) / 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 (shell) / 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 (shell) / 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);
}
}
case GIMP_BUTTON_RELEASE_CLICK:
case GIMP_BUTTON_RELEASE_NO_MOTION:
gimp_display_shell_scale (shell,
options->zoom_type,
0.0,
GIMP_ZOOM_FOCUS_POINTER);
break;
case GIMP_BUTTON_RELEASE_NORMAL:
{
gdouble x1, y1, x2, y2;
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;
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)
{
gdouble xres;
gdouble yres;
gint offset_x = 0;
gint offset_y = 0;
gimp_image_get_resolution (display->image, &xres, &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 (shell) / xres -
(shell->disp_width / 2.0));
offset_y = RINT (new_scale * ((y1 + y2) / 2.0) *
SCREEN_YRES (shell) / 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 (shell) / 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 (shell) / 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);
}
}
break;
default:
break;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment