Re: NSRulerView flexibility

  • Hello again,

    Thanks a lot for the suggestion, it really got us started on implementing ruler views the way we envision them.

    It's very interesting (although poorly documented) how NSRulerView's drawRect method copies and shifts* the contents up or down implicitly such that the rectangle passed into drawRect is only the small rectangle at the bottom or top that needs "filling."  By dynamically adjusting the origin of the ruler views, we were able to eliminate the strange artifact drawing that occurs when attempting to redraw the whole ruler.

    Now our problem is the lack of communication between the NSScrollView and its rulerViews.  Due to the fact that we have found autoscroll's default behavior insufficient, we implemented an overridden autoscroll method that actually scrolls the clipview while the mouse is still inside the clipview, depending on the distance to the edge of the view.  We do this by creating an NSTimer with an arbitrary interval and updating a class variable representing scroll speed depending on the mouse drag's location.

    with the following 3 lines of code...

    NSScrollView *s = [self enclosingScrollView];
    [[s contentView] scrollToPoint:o2];
    [s reflectScrolledClipView:[s contentView]];

    ... we were able to get the scroll bars to correspond to the result of the autoscroll.  However, the RULERS are not updated when autoscrolling occurs.  The scrollview knows about the rulerviews, and the rulerviews' clientview are set to the scrollview's clipview.

    I would expect that the scrollview, since it contains the rulerviews, would take care of updating the rulerviews' positions in reflectScrolledClipView by appropriately scrolling and updating the rulerview.  This is not the case.

    I've tried calling setNeedsDisplayInRect:r where r is the rectangle containing bottom or top dy pixels of the view where dy is the amount scrolled, but this doesn't work either, because it seems that drawRect is invoked only after the shifting (see * above) has already occured.

    Any ideas Steve?

    I really appreciate the help so far.  Thanks again,

    -Dave H.

    Steve Shepard <steveshep...> wrote: It is possible to do what you are asking (see the rulers in Storyist),
    but there is some work involved. The class to subclass is NSRulerView
    and you'll do most of your custom drawing in
    drawHashMarksAndLabelsInRect:

    I had to override some private methods to get this to draw without
    artifacts when scrolled.

    -Steve
    www.storyist.com
previous month october 2007 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