Changeset 654 for gtkimageview

Show
Ignore:
Timestamp:
04/02/09 18:57:02 (4 years ago)
Author:
bjourne
Message:

Use ints instead of gdoubles to store the view offsets. This should
solve #31 and all other weird rounding and truncation issues. Note
that the offsets are rounded in gtk_image_view_set_zoom_with_center()
to avoid double->int problems with (int)449.9999... = 449.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gtkimageview/src/gtkimageview.c

    r627 r654  
    351351 
    352352static void 
    353 gtk_image_view_clamp_offset (GtkImageView *view, gdouble *x, gdouble *y) 
     353gtk_image_view_clamp_offset (GtkImageView *view, int *x, int *y) 
    354354{ 
    355355    Size alloc = gtk_image_view_get_allocated_size (view); 
     
    430430    Size alloc = gtk_image_view_get_allocated_size (view); 
    431431 
    432     gdouble offset_x, offset_y; 
    433     offset_x = (view->offset_x + center_x) * zoom_ratio - alloc.width / 2.0; 
    434     offset_y = (view->offset_y + center_y) * zoom_ratio - alloc.height / 2.0; 
     432    int offset_x, offset_y; 
     433 
     434    offset_x = (int) round ((gdouble) ((gdouble)view->offset_x + center_x) * zoom_ratio - 
     435                            (gdouble) alloc.width / 2.0); 
     436    offset_y = (int) round ((gdouble) ((gdouble)view->offset_y + center_y) * zoom_ratio - 
     437                            (gdouble) alloc.height / 2.0); 
    435438    view->zoom = zoom; 
    436439 
    437440    gtk_image_view_clamp_offset (view, &offset_x, &offset_y); 
     441 
    438442    view->offset_x = offset_x; 
    439443    view->offset_y = offset_y; 
     444 
    440445    gtk_image_view_update_cursor (view); 
    441446 
     
    561566            interp = GDK_INTERP_NEAREST; 
    562567 
    563         // Fix for #31. Value must be rounded or double -> int 
    564         // conversion can introduce error. 
    565         int src_x = (int)((view->offset_x + 
    566                            (gdouble) paint_area.x - 
    567                            (gdouble) image_area.x) + 0.5); 
    568         int src_y = (int)((view->offset_y + 
    569                            (gdouble) paint_area.y - 
    570                            (gdouble) image_area.y) + 0.5); 
     568        int src_x = view->offset_x + paint_area.x - image_area.x;  
     569        int src_y = view->offset_y + paint_area.y - image_area.y;  
    571570 
    572571        GdkPixbufDrawOpts opts = { 
     
    695694static void 
    696695gtk_image_view_scroll_to (GtkImageView *view, 
    697                           gdouble       offset_x, 
    698                           gdouble       offset_y, 
     696                          int           offset_x, 
     697                          int           offset_y, 
    699698                          gboolean      set_adjustments, 
    700699                          gboolean      invalidate) 
     
    702701    gtk_image_view_clamp_offset (view, &offset_x, &offset_y); 
    703702 
    704     /* Round avoids floating point to integer conversion errors. See 
    705        #31. */ 
    706     int delta_x = round (offset_x - view->offset_x); 
    707     int delta_y = round (offset_y - view->offset_y); 
     703    int delta_x = offset_x - view->offset_x; 
     704    int delta_y = offset_y - view->offset_y; 
    708705 
    709706    /* Exit early if the scroll was smaller than one (zoom space) 
     
    884881                                GtkImageView *view) 
    885882{ 
    886     gdouble offset_x = GTK_ADJUSTMENT (adj)->value; 
     883    int offset_x = GTK_ADJUSTMENT (adj)->value; 
    887884    gtk_image_view_scroll_to (view, offset_x, view->offset_y, FALSE, FALSE); 
    888885    return FALSE; 
     
    968965    view->pixbuf = NULL; 
    969966    view->zoom = 1.0; 
    970     view->offset_x = 0.0
    971     view->offset_y = 0.0
     967    view->offset_x = 0
     968    view->offset_y = 0
    972969    view->is_rendering = FALSE; 
    973970    view->show_frame = TRUE; 
  • gtkimageview/src/gtkimageview.h

    r590 r654  
    8383    /* Offset in zoom space coordinates of the image area in the 
    8484       widget. */ 
    85     gdouble          offset_x; 
    86     double           offset_y; 
     85    int              offset_x; 
     86    int              offset_y; 
    8787    gboolean         show_frame; 
    8888    gboolean         show_cursor;