Skip to content

Commit

Permalink
relative scroll is working; some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Jul 12, 2007
1 parent 45424fc commit f231104
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 61 deletions.
51 changes: 12 additions & 39 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer da
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)
Expand Down Expand Up @@ -1302,44 +1301,6 @@ void image_change_from_image(ImageWindow *imd, ImageWindow *source)
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)
Expand All @@ -1365,6 +1326,18 @@ void image_scroll_to_point(ImageWindow *imd, gint x, gint y,
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;
Expand Down
7 changes: 2 additions & 5 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ void image_change_from_image(ImageWindow *imd, ImageWindow *source);

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 */
Expand Down
20 changes: 3 additions & 17 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ gint layout_image_get_index(LayoutWindow *lw)

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);
Expand Down Expand Up @@ -1557,8 +1557,8 @@ static void layout_image_drag_cb(ImageWindow *imd, gint button, guint32 time,
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);
}
Expand All @@ -1573,13 +1573,6 @@ static void layout_image_drag_cb(ImageWindow *imd, gint button, guint32 time,
}
}

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)
{
Expand All @@ -1589,7 +1582,6 @@ static void layout_image_button_inactive_cb(ImageWindow *imd, gint button, guint

if (i != -1)
{
printf("image activate %d\n", i);
layout_image_activate(lw, i);
}

Expand All @@ -1616,10 +1608,8 @@ static void layout_image_drag_inactive_cb(ImageWindow *imd, gint button, guint32

gint i = image_idx(lw, imd);

printf("drag inacive\n");
if (i != -1)
{
printf("image activate %d\n", i);
layout_image_activate(lw, i);
}

Expand Down Expand Up @@ -1661,10 +1651,6 @@ GtkWidget *layout_image_new(LayoutWindow *lw, gint i)

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);
Expand Down
27 changes: 27 additions & 0 deletions src/pixbuf-renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,33 @@ void pixbuf_renderer_scroll_to_point(PixbufRenderer *pr, gint x, gint y,
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
Expand Down
5 changes: 5 additions & 0 deletions src/pixbuf-renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct _PixbufRenderer
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) */
Expand Down Expand Up @@ -182,6 +185,8 @@ void pixbuf_renderer_scroll(PixbufRenderer *pr, gint x, gint y);
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);
Expand Down

0 comments on commit f231104

Please sign in to comment.