drawRect troubles

  • When a custom view receives two drawRect's in succession with the
    same argument, can it be assumed that what was drawn the first time
    will still be there and displayed the next time around?  This is all
    happening in the top app, in the top window, in the top view.  The
    view receives drawRect because of stuff happening in the app and
    setNeedsDisplay:YES messages (not because the view was uncovered, etc.)

    For performance reasons I am trying to do incremental drawing -- draw/
    erase only small amounts of stuff that has changed -- but it seems
    that the view contents is "erased" between successive calls to
    drawRect.  After each drawRect, I only see the incremental drawing --
    the small stuff added/removed -- but not what was there before.

    Am I doing something wrong, or is this expected behavior.  If what I
    am seeing is expected behavior, does anyone have suggestions for how
    to achieve what I want?

    Cheers,

    --
    ivan
  • On Oct 28, 2006, at 8:05 PM, Ivan Kourtev wrote:

    > For performance reasons I am trying to do incremental drawing --
    > draw/erase only small amounts of stuff that has changed -- but it
    > seems that the view contents is "erased" between successive calls
    > to drawRect.  After each drawRect, I only see the incremental
    > drawing -- the small stuff added/removed -- but not what was there
    > before.

    Have you tried playing with Quartz Debug's "flash updates" checkbox?

    Should show you which areas are considered invalid at which points.
    Might help.

        - Scott
  • On Oct 28, 2006, at 11:11 PM, Scott Stevenson wrote:

    > On Oct 28, 2006, at 8:05 PM, Ivan Kourtev wrote:
    >
    >> For performance reasons I am trying to do incremental drawing --
    >> draw/erase only small amounts of stuff that has changed -- but it
    >> seems that the view contents is "erased" between successive calls
    >> to drawRect.  After each drawRect, I only see the incremental
    >> drawing -- the small stuff added/removed -- but not what was there
    >> before.
    >>
    > Have you tried playing with Quartz Debug's "flash updates" checkbox?
    > Should show you which areas are considered invalid at which points.
    > Might help.
    >
    > - Scott
    >

    Yes, I've been doing this.  All the update areas seem to be correct.
    The problem is that the drawing I see in the view contains only what
    was done explicitly in drawRect.

    I was under the impression that what's been drawn in the view so far
    is there, and if I don't want it, I have to erase it.  So I am only
    adding small pieces of stuff in drawRect -- and they do appear on
    screen.  All of the previous drawing is gone.

    Since I am issuing the [self setNeedsDisplay:YES] is there any way to
    also specify which particular parts of the view should be
    invalidated?  Right now, the argument to drawRect is always the
    entire view area.

    -- ivan
  • > Since I am issuing the [self setNeedsDisplay:YES] is there any way
    > to also specify which particular parts of the view should be
    > invalidated?  Right now, the argument to drawRect is always the
    > entire view area.

    - (void)setNeedsDisplayInRect:(NSRect)invalidRect
  • Thanks, that did it.

    --
    ivan

    On Oct 28, 2006, at 11:58 PM, Chris Suter wrote:

    >> Since I am issuing the [self setNeedsDisplay:YES] is there any way
    >> to also specify which particular parts of the view should be
    >> invalidated?  Right now, the argument to drawRect is always the
    >> entire view area.
    >
    > - (void)setNeedsDisplayInRect:(NSRect)invalidRect
    >
  • Am 29.10.2006 um 04:33 schrieb Ivan Kourtev:
    > I was under the impression that what's been drawn in the view so
    > far is there, and if I don't want it, I have to erase it.  So I am
    > only adding small pieces of stuff in drawRect -- and they do appear
    > on screen.  All of the previous drawing is gone.

      That impression isn't quite correct. You get an update message for
    what you invalidate. Invalidate less if you need to redraw less.

    > Since I am issuing the [self setNeedsDisplay:YES] is there any way
    > to also specify which particular parts of the view should be
    > invalidated?

    -setNeedsDisplayInRect: -- it really helps to read the headers,
    related methods are usually next to each other, so you could have
    seen that method and option-doubleclicked it to see the docs.

    > Right now, the argument to drawRect is always the entire view area.

      Note that, if this is a case where drawing is really slow, you can
    get a list of the actual "sub-rectangles" that really need updating
    from NSView and only update those, because for the cases where you
    have e.g. a small rect in the top left and another in the bottom
    right of your view, drawRect:'s parameter will be the union of the
    two rectangles.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
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