Skip to content

Commit

Permalink
fixed various problems with preserving viewport on image change,
Browse files Browse the repository at this point in the history
options->image.scroll_reset_method should work again (it needs to be
added to the preferences dialog)
  • Loading branch information
nadvornik committed Sep 4, 2008
1 parent 9050223 commit baedcd2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
8 changes: 0 additions & 8 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,15 +919,10 @@ gint layout_image_get_index(LayoutWindow *lw)

void layout_image_set_fd(LayoutWindow *lw, FileData *fd)
{
gdouble sx, sy;
if (!layout_valid(&lw)) return;

image_get_scroll_center(lw->image, &sx, &sy);

image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));

image_set_scroll_center(lw->image, sx, sy);

layout_list_sync_fd(lw, fd);
layout_image_slideshow_continue_check(lw);
layout_bars_new_image(lw);
Expand Down Expand Up @@ -1045,12 +1040,9 @@ void layout_image_set_collection(LayoutWindow *lw, CollectionData *cd, CollectIn

void layout_image_refresh(LayoutWindow *lw)
{
gdouble sx, sy;
if (!layout_valid(&lw)) return;

image_get_scroll_center(lw->image, &sx, &sy);
image_reload(lw->image);
image_set_scroll_center(lw->image, sx, sy);
}

void layout_image_color_profile_set(LayoutWindow *lw,
Expand Down
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ConfOptions *init_options(ConfOptions *options)
options->image.max_autofit_size = 100;
options->image.max_window_size = 90;
options->image.read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
options->image.scroll_reset_method = SCROLL_RESET_TOPLEFT;
options->image.scroll_reset_method = SCROLL_RESET_NOCHANGE;
options->image.tile_cache_max = 10;
options->image.image_cache_max = 128; /* 4 x 10MPix */
options->image.use_custom_border_color = FALSE;
Expand Down
49 changes: 33 additions & 16 deletions src/pixbuf-renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ static void pixbuf_renderer_init(PixbufRenderer *pr)

pr->orientation = 1;

pr->norm_center_x = 0.5;
pr->norm_center_y = 0.5;

gtk_widget_set_double_buffered(box, FALSE);
g_signal_connect_after(G_OBJECT(box), "size_allocate",
G_CALLBACK(pr_size_cb), pr);
Expand Down Expand Up @@ -3093,6 +3096,19 @@ static void pr_drag_signal(PixbufRenderer *pr, GdkEventButton *bevent)
*-------------------------------------------------------------------
*/

static void pixbuf_renderer_sync_scroll_center(PixbufRenderer *pr)
{
gint src_x, src_y;
if (!pr->width || !pr->height) return;

src_x = pr->x_scroll + pr->vis_width / 2;
src_y = pr->y_scroll + pr->vis_height / 2;

pr->norm_center_x = (gdouble)src_x / pr->width;
pr->norm_center_y = (gdouble)src_y / pr->height;
}


static gint pr_scroll_clamp(PixbufRenderer *pr)
{
gint old_xs;
Expand Down Expand Up @@ -3127,6 +3143,8 @@ static gint pr_scroll_clamp(PixbufRenderer *pr)
pr->y_scroll = CLAMP(pr->y_scroll, 0, pr->height - pr->vis_height);
}

pixbuf_renderer_sync_scroll_center(pr);

return (old_xs != pr->x_scroll || old_ys != pr->y_scroll);
}

Expand Down Expand Up @@ -3159,6 +3177,8 @@ static gint pr_size_clamp(PixbufRenderer *pr)
pr->y_offset = 0;
}

pixbuf_renderer_sync_scroll_center(pr);

return (old_vw != pr->vis_width || old_vh != pr->vis_height);
}

Expand Down Expand Up @@ -3268,6 +3288,8 @@ static gint pr_zoom_clamp(PixbufRenderer *pr, gdouble zoom,
}
if (redrawn) *redrawn = (invalidate || invalid);

pixbuf_renderer_sync_scroll_center(pr);

return TRUE;
}

Expand All @@ -3283,7 +3305,9 @@ static void pr_zoom_sync(PixbufRenderer *pr, gdouble zoom,
gboolean force = !!(flags & PR_ZOOM_FORCE);
gboolean new = !!(flags & PR_ZOOM_NEW);
PrZoomFlags clamp_flags = flags;

gdouble old_center_x = pr->norm_center_x;
gdouble old_center_y = pr->norm_center_y;

old_scale = pr->scale;
if (center_point)
{
Expand All @@ -3310,7 +3334,9 @@ static void pr_zoom_sync(PixbufRenderer *pr, gdouble zoom,
switch (pr->scroll_reset)
{
case PR_SCROLL_RESET_NOCHANGE:
/* maintain old scroll position, do nothing */
/* maintain old scroll position */
pr->x_scroll = ((gdouble)pr->image_width * old_center_x * pr->scale) - pr->vis_width / 2;
pr->y_scroll = ((gdouble)pr->image_height * old_center_y * pr->scale) - pr->vis_height / 2;
break;
case PR_SCROLL_RESET_CENTER:
/* center new image */
Expand Down Expand Up @@ -3461,6 +3487,9 @@ void pixbuf_renderer_scroll(PixbufRenderer *pr, gint x, gint y)
pr->y_scroll += y;

pr_scroll_clamp(pr);

pixbuf_renderer_sync_scroll_center(pr);

if (pr->x_scroll == old_x && pr->y_scroll == old_y) return;

pr_scroll_notify_signal(pr);
Expand Down Expand Up @@ -3576,20 +3605,8 @@ void pixbuf_renderer_scroll_to_point(PixbufRenderer *pr, gint x, gint y,

void pixbuf_renderer_get_scroll_center(PixbufRenderer *pr, gdouble *x, gdouble *y)
{
gint src_x, src_y;

src_x = pr->x_scroll + pr->vis_width / 2;
src_y = pr->y_scroll + pr->vis_height / 2;

if (pr->width)
*x = (gdouble)src_x / pr->width;
else
*x = 0.5; /* center */

if (pr->height)
*y = (gdouble)src_y / pr->height;
else
*y = 0.5; /* center */
*x = pr->norm_center_x;
*y = pr->norm_center_y;
}

void pixbuf_renderer_set_scroll_center(PixbufRenderer *pr, gdouble x, gdouble y)
Expand Down
3 changes: 3 additions & 0 deletions src/pixbuf-renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct _PixbufRenderer
gint x_scroll; /* scroll offset of image (into width, height to start drawing) */
gint y_scroll;

gdouble norm_center_x; /* coordinates of viewport center in the image, in range 0.0 - 1.0 */
gdouble norm_center_y; /* these coordinates are used for PR_SCROLL_RESET_NOCHANGE and should be preserved over periods with NULL pixbuf */

gdouble subpixel_x_scroll; /* subpixel scroll alignment, used to prevent acumulation of rounding errors */
gdouble subpixel_y_scroll;

Expand Down

0 comments on commit baedcd2

Please sign in to comment.