minimal redraw with scrollPoint

  • I have a grab-mode in my program, where the user can hold
    down the SHIFT-modifier and scroll by doing click-drag-release.

    If I scroll diagonally then getRectsBeingDrawn tells me that
    everything is changed. However scrolling either only-horizontally
    or only-vertically then getRectsBeingDrawn gives me the delta-changes.

    I have made an adhoc solution for scrolling diagonally with
    minimal redraw:
    At odd times I scroll horizontally.
    At even times I scroll vertically.

    Is there something better around?

    float dx = [event deltaX];
    float dy = [event deltaY];
    NSClipView *cv = (NSClipView*)[self superview];
    NSPoint orig  = [cv bounds].origin;
    if(scroll_x_if_odd & 1) {
    NSPoint new_orig = NSMakePoint(
      round(orig.x - dx - accum_x),
      orig.y
    );
    [self scrollPoint: new_orig];
    accum_y += dy;
    accum_x = 0;
    } else {
    NSPoint new_orig = NSMakePoint(
      orig.x,
      round(orig.y - dy - accum_y)
    );
    [self scrollPoint: new_orig];
    accum_x += dx;
    accum_y = 0;
    }
    scroll_x_if_odd++;

    --
    Simon Strandgaard
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today