relative scroll is working; some cleanup
authorVladimir Nadvornik <nadvornik@suse.cz>
Thu, 12 Jul 2007 20:46:28 +0000 (20:46 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Thu, 12 Jul 2007 20:46:28 +0000 (20:46 +0000)
src/image.c
src/image.h
src/layout_image.c
src/pixbuf-renderer.c
src/pixbuf-renderer.h

index 7cf78e8..e7c460d 100644 (file)
@@ -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)
@@ -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)
@@ -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;
index 5f30b89..e665b7f 100644 (file)
@@ -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 */
index 0ccfc50..986fba5 100644 (file)
@@ -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);
@@ -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);
                                        }
@@ -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)
 {
@@ -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);
                }
 
@@ -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);
                }
 
@@ -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);
index 07269ea..f5ff80e 100644 (file)
@@ -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
index bd6619b..7d2b70f 100644 (file)
@@ -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) */
@@ -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);