# HG changeset patch # User nadvornik # Date 1184184007 0 # Node ID 89fc00ffbce2d296dbe035dbb88ebc6ca1e844ba # Parent 98e2632b5d3d37ebf87dd469350ec70687bba236 started relative scroll, keep scroll position diff -r 98e2632b5d3d -r 89fc00ffbce2 src/image.c --- a/src/image.c Tue Jul 10 21:25:51 2007 +0000 +++ b/src/image.c Wed Jul 11 20:00:07 2007 +0000 @@ -67,12 +67,16 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data) { ImageWindow *imd = data; + gint width, height; + printf("drag_cb %p\n", imd->func_drag); + pixbuf_renderer_get_scaled_size(pr, &width, &height); + if (imd->func_drag) { imd->func_drag(imd, event->button, event->time, event->x, event->y, event->state, - event->x - pr->drag_last_x, event->y - pr->drag_last_y, + (gfloat)(pr->drag_last_x - event->x) / width, (gfloat)(pr->drag_last_y - event->y) / height, imd->data_button); } } @@ -1298,31 +1302,37 @@ pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr)); } -void image_sync_scroll_from_image_absolute(ImageWindow *imd, ImageWindow *source) +void image_get_scroll_center(ImageWindow *imd, gfloat *x, gfloat *y) { - gint src_width, src_height, dst_width, dst_height; + gint src_width, src_height; gint src_x, src_y; - gfloat dst_x, dst_y; GdkRectangle src_rect; - GdkRectangle dst_rect; - gfloat dst_scale = pixbuf_renderer_zoom_get_scale(PIXBUF_RENDERER(imd->pr)); - pixbuf_renderer_get_virtual_rect(PIXBUF_RENDERER(source->pr), &src_rect); - pixbuf_renderer_get_scaled_size(PIXBUF_RENDERER(source->pr), &src_width, &src_height); - pixbuf_renderer_get_virtual_rect(PIXBUF_RENDERER(imd->pr), &dst_rect); - pixbuf_renderer_get_scaled_size(PIXBUF_RENDERER(imd->pr), &dst_width, &dst_height); + pixbuf_renderer_get_virtual_rect(PIXBUF_RENDERER(imd->pr), &src_rect); + pixbuf_renderer_get_scaled_size(PIXBUF_RENDERER(imd->pr), &src_width, &src_height); src_x = src_rect.x + src_rect.width / 2; src_y = src_rect.y + src_rect.height / 2; - dst_x = (gfloat)src_x * dst_width / src_width - dst_rect.width / 2; - dst_y = (gfloat)src_y * dst_height / src_height - dst_rect.height / 2; + *x = (gfloat)src_x / src_width; + *y = (gfloat)src_y / src_height; +} +void image_set_scroll_center(ImageWindow *imd, gfloat x, gfloat y) +{ + gint dst_width, dst_height; + gfloat dst_x, dst_y; + gfloat dst_scale = pixbuf_renderer_zoom_get_scale(PIXBUF_RENDERER(imd->pr)); + pixbuf_renderer_get_scaled_size(PIXBUF_RENDERER(imd->pr), &dst_width, &dst_height); - image_scroll_to_point(imd, dst_x / dst_scale, dst_y / dst_scale, 0, 0); + dst_x = x * dst_width; + dst_y = y * dst_height; + + image_scroll_to_point(imd, dst_x / dst_scale, dst_y / dst_scale, 0.5, 0.5); } + void image_sync_zoom_from_image(ImageWindow *imd, ImageWindow *source) { image_zoom_set(imd, image_zoom_get(source)); diff -r 98e2632b5d3d -r 89fc00ffbce2 src/image.h --- a/src/image.h Tue Jul 10 21:25:51 2007 +0000 +++ b/src/image.h Wed Jul 11 20:00:07 2007 +0000 @@ -60,7 +60,9 @@ GdkPixbuf *image_get_pixbuf(ImageWindow *imd); -void image_sync_scroll_from_image_absolute(ImageWindow *imd, ImageWindow *source); +void image_get_scroll_center(ImageWindow *imd, gfloat *x, gfloat *y); +void image_set_scroll_center(ImageWindow *imd, gfloat x, gfloat y); + void image_sync_zoom_from_image(ImageWindow *imd, ImageWindow *source); /* manipulation */ void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height); diff -r 98e2632b5d3d -r 89fc00ffbce2 src/layout_image.c --- a/src/layout_image.c Tue Jul 10 21:25:51 2007 +0000 +++ b/src/layout_image.c Wed Jul 11 20:00:07 2007 +0000 @@ -1130,10 +1130,15 @@ void layout_image_set_path(LayoutWindow *lw, const gchar *path) { + gfloat sx, sy; if (!layout_valid(&lw)) return; + image_get_scroll_center(lw->image, &sx, &sy); + image_change_path(lw->image, path, image_zoom_get_default(lw->image, zoom_mode)); + image_set_scroll_center(lw->image, sx, sy); + layout_list_sync_path(lw, path); layout_image_slideshow_continue_check(lw); layout_bars_new_image(lw); @@ -1536,10 +1541,21 @@ for (i=0; i < MAX_SPLIT_IMAGES; i++) { if (lw->split_images[i] && lw->split_images[i] != imd) -// if (lw->connect_zoom) -// image_sync_zoom_from_image(lw->split_images[i], imd); - if (lw->connect_scroll) - image_sync_scroll_from_image_absolute(lw->split_images[i], imd); + if (lw->connect_scroll) + { + gfloat sx, sy; + if (!(state & GDK_CONTROL_MASK)) + { + image_get_scroll_center(imd, &sx, &sy); + } + else + { + image_get_scroll_center(lw->split_images[i], &sx, &sy); + sx += dx; + sy += dy; + } + image_set_scroll_center(lw->split_images[i], sx, sy); + } } } @@ -1586,6 +1602,7 @@ gint i = image_idx(lw, imd); + printf("drag inacive\n"); if (i != -1) { printf("image activate %d\n", i); @@ -1593,14 +1610,8 @@ } - for (i=0; i < MAX_SPLIT_IMAGES; i++) - { - if (lw->split_images[i] && lw->split_images[i] != imd) -// if (lw->connect_zoom) -// image_sync_zoom_from_image(lw->split_images[i], imd); - if (lw->connect_scroll) - image_sync_scroll_from_image_absolute(lw->split_images[i], imd); - } + /* continue as with active image */ + layout_image_drag_cb(imd, button, time, x, y, state, dx, dy, data); } @@ -1660,7 +1671,7 @@ if (!lw->split_images[i]) return; image_set_update_func(lw->split_images[i], NULL, NULL); layout_image_set_buttons_inactive(lw, i); - image_set_drag_func(lw->image, layout_image_drag_inactive_cb, lw); + image_set_drag_func(lw->split_images[i], layout_image_drag_inactive_cb, lw); image_attach_window(lw->split_images[i], NULL, NULL, NULL, FALSE); image_select(lw->split_images[i], FALSE);