Skip to content

Commit

Permalink
Fix #1588: center of view is moving when zoomed in and switching betw…
Browse files Browse the repository at this point in the history
…een images

#1588

The computation requires integer division and not floating point
division. I do not know why.

The change to floating point was in 0028df2.
This patch reverts to the original.
  • Loading branch information
caclark committed Jan 8, 2025
1 parent f41bec4 commit 21973ab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/pixbuf-renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1730,19 +1730,23 @@ static void pr_zoom_sync(PixbufRenderer *pr, gdouble zoom,
(void) pr_size_clamp(pr);
(void) pr_parent_window_resize(pr, pr->width, pr->height);

/* NOLINT(bugprone-integer-division) is required due to
* https://github.com/BestImageViewer/geeqie/issues/1588
* The reason is not known.
*/
if (force && new_z)
{
switch (pr->scroll_reset)
{
case ScrollReset::NOCHANGE:
/* maintain old scroll position */
pr->x_scroll = (static_cast<gdouble>(pr->image_width) * old_center_x * pr->scale) - pr->vis_width / 2.0;
pr->y_scroll = (static_cast<gdouble>(pr->image_height) * old_center_y * pr->scale * pr->aspect_ratio) - pr->vis_height / 2.0;
pr->x_scroll = (static_cast<gdouble>(pr->image_width) * old_center_x * pr->scale) - pr->vis_width / 2; // NOLINT(bugprone-integer-division)
pr->y_scroll = (static_cast<gdouble>(pr->image_height) * old_center_y * pr->scale * pr->aspect_ratio) - pr->vis_height / 2; // NOLINT(bugprone-integer-division)
break;
case ScrollReset::CENTER:
/* center new image */
pr->x_scroll = (static_cast<gdouble>(pr->image_width) / 2.0 * pr->scale) - pr->vis_width / 2.0;
pr->y_scroll = (static_cast<gdouble>(pr->image_height) / 2.0 * pr->scale * pr->aspect_ratio) - pr->vis_height / 2.0;
pr->x_scroll = (static_cast<gdouble>(pr->image_width) / 2 * pr->scale) - pr->vis_width / 2; // NOLINT(bugprone-integer-division)
pr->y_scroll = (static_cast<gdouble>(pr->image_height) / 2 * pr->scale * pr->aspect_ratio) - pr->vis_height / 2; // NOLINT(bugprone-integer-division)
break;
case ScrollReset::TOPLEFT:
default:
Expand All @@ -1762,8 +1766,8 @@ static void pr_zoom_sync(PixbufRenderer *pr, gdouble zoom,
}
else
{
pr->x_scroll = old_cx / old_scale * pr->scale - (pr->vis_width / 2.0);
pr->y_scroll = old_cy / old_scale * pr->scale * pr->aspect_ratio - (pr->vis_height / 2.0);
pr->x_scroll = old_cx / old_scale * pr->scale - (pr->vis_width / 2); // NOLINT(bugprone-integer-division)
pr->y_scroll = old_cy / old_scale * pr->scale * pr->aspect_ratio - (pr->vis_height / 2); // NOLINT(bugprone-integer-division)
}
}

Expand Down

0 comments on commit 21973ab

Please sign in to comment.