Mercurial > geeqie
changeset 131:b1acdfc7271b
relative scroll is working; some cleanup
author | nadvornik |
---|---|
date | Thu, 12 Jul 2007 20:46:28 +0000 |
parents | 7ea9fbcff664 |
children | 661cd91e5a7e |
files | src/image.c src/image.h src/layout_image.c src/pixbuf-renderer.c src/pixbuf-renderer.h |
diffstat | 5 files changed, 49 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/src/image.c Wed Jul 11 21:10:25 2007 +0000 +++ b/src/image.c Thu Jul 12 20:46:28 2007 +0000 @@ -69,7 +69,6 @@ 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) @@ -1302,44 +1301,6 @@ pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr)); } -void image_get_scroll_center(ImageWindow *imd, gfloat *x, gfloat *y) -{ - gint src_width, src_height; - gint src_x, src_y; - GdkRectangle src_rect; - - 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; - - *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); - - 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)); -} - - - /* manipulation */ void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height) @@ -1365,6 +1326,18 @@ pixbuf_renderer_scroll_to_point((PixbufRenderer *)imd->pr, x, y, x_align, y_align); } +void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y) +{ + pixbuf_renderer_get_scroll_center(PIXBUF_RENDERER(imd->pr), x, y); +} + +void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y) +{ + pixbuf_renderer_set_scroll_center(PIXBUF_RENDERER(imd->pr), x, y); +} + + + void image_alter(ImageWindow *imd, AlterType type) { if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
--- a/src/image.h Wed Jul 11 21:10:25 2007 +0000 +++ b/src/image.h Thu Jul 12 20:46:28 2007 +0000 @@ -59,17 +59,14 @@ GdkPixbuf *image_get_pixbuf(ImageWindow *imd); - -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); void image_reload(ImageWindow *imd); void image_scroll(ImageWindow *imd, gint x, gint y); void image_scroll_to_point(ImageWindow *imd, gint x, gint y, gdouble x_align, gdouble y_align); +void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y); +void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y); void image_alter(ImageWindow *imd, AlterType type); /* zoom */
--- a/src/layout_image.c Wed Jul 11 21:10:25 2007 +0000 +++ b/src/layout_image.c Thu Jul 12 20:46:28 2007 +0000 @@ -1144,7 +1144,7 @@ void layout_image_set_path(LayoutWindow *lw, const gchar *path) { - gfloat sx, sy; + gdouble sx, sy; if (!layout_valid(&lw)) return; image_get_scroll_center(lw->image, &sx, &sy); @@ -1557,8 +1557,8 @@ if (lw->split_images[i] && lw->split_images[i] != imd) if (lw->connect_scroll) { - gfloat sx, sy; - if (!(state & GDK_CONTROL_MASK)) + gdouble sx, sy; + if (state & GDK_CONTROL_MASK) { image_get_scroll_center(imd, &sx, &sy); } @@ -1573,13 +1573,6 @@ } } -static gint layout_image_mouse_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) -{ - - printf("mouse press\n"); - -} - static void layout_image_button_inactive_cb(ImageWindow *imd, gint button, guint32 time, gdouble x, gdouble y, guint state, gpointer data) { @@ -1589,7 +1582,6 @@ if (i != -1) { - printf("image activate %d\n", i); layout_image_activate(lw, i); } @@ -1616,10 +1608,8 @@ gint i = image_idx(lw, imd); - printf("drag inacive\n"); if (i != -1) { - printf("image activate %d\n", i); layout_image_activate(lw, i); } @@ -1661,10 +1651,6 @@ gtk_widget_ref(lw->split_images[i]->widget); - g_signal_connect(G_OBJECT(lw->split_images[i]->widget), "button_press_event", - G_CALLBACK(layout_image_mouse_press_cb), lw); - - if (black_window_background) image_background_set_black(lw->split_images[i], TRUE); image_auto_refresh(lw->image, 0);
--- a/src/pixbuf-renderer.c Wed Jul 11 21:10:25 2007 +0000 +++ b/src/pixbuf-renderer.c Thu Jul 12 20:46:28 2007 +0000 @@ -2973,6 +2973,33 @@ pixbuf_renderer_scroll(pr, px, py); } +/* get or set coordinates of viewport center in the image, in range 0.0 - 1.0 */ + +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; + + *x = (gdouble)src_x / pr->width; + *y = (gdouble)src_y / pr->height; +} + +void pixbuf_renderer_set_scroll_center(PixbufRenderer *pr, gdouble x, gdouble y) +{ + gdouble dst_x, dst_y; + + dst_x = x * pr->width - pr->vis_width / 2 - pr->x_scroll + CLAMP(pr->subpixel_x_scroll, -1.0, 1.0); + dst_y = y * pr->height - pr->vis_height / 2 - pr->y_scroll + CLAMP(pr->subpixel_y_scroll, -1.0, 1.0); + + pr->subpixel_x_scroll = dst_x - (int)dst_x; + pr->subpixel_y_scroll = dst_y - (int)dst_y; + + pixbuf_renderer_scroll(pr, (int)dst_x, (int)dst_y); +} + + /* *------------------------------------------------------------------- * mouse
--- a/src/pixbuf-renderer.h Wed Jul 11 21:10:25 2007 +0000 +++ b/src/pixbuf-renderer.h Thu Jul 12 20:46:28 2007 +0000 @@ -62,6 +62,9 @@ gint x_scroll; /* scroll offset of image (into width, height to start drawing) */ gint y_scroll; + gdouble subpixel_x_scroll; /* subpixel scroll alignment, used to prevent acumulation of rounding errors */ + gdouble subpixel_y_scroll; + gdouble zoom_min; gdouble zoom_max; gdouble zoom; /* zoom we want (0 is auto) */ @@ -182,6 +185,8 @@ void pixbuf_renderer_scroll_to_point(PixbufRenderer *pr, gint x, gint y, gdouble x_align, gdouble y_align); +void pixbuf_renderer_get_scroll_center(PixbufRenderer *pr, gdouble *x, gdouble *y); +void pixbuf_renderer_set_scroll_center(PixbufRenderer *pr, gdouble x, gdouble y); /* zoom */ void pixbuf_renderer_zoom_adjust(PixbufRenderer *pr, gdouble increment);