• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stopping a NSView from drawing in -drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stopping a NSView from drawing in -drawRect


  • Subject: Re: Stopping a NSView from drawing in -drawRect
  • From: Phillip Hutchings <email@hidden>
  • Date: Sat, 7 Feb 2004 11:30:18 +1300

A -drawRect: method should not call -lockFocus / -unlockFocus. AppKit automatically locks focus before calling your view's -drawRect: method, and unlocks it on return.

Oops, a slight leftover from earlier when I was doing something very weird there :P

Sending -display from inside a -drawRect: method is also not a practice I'd recommend. What is trackTextView's relationship to the present view? If you make it a subview, AppKit will draw it automatically. If you need to composite an image on top of the TextView's content, you could add an ImageView as a subview of the TextView, or subclass NSTextView to draw the image.

It is a subview, and I've now removed it. I think it was there because I was doing something odd and flushing the display when I shouldn't somehow. Anyway, it works fine without it.

If you do all your drawing in response to receiving -drawRect: messages, request drawing via -setNeedsDisplay: and/or -setNeedsDisplayInRect: instead of -display, and eliminate the redundant -lockFocus/-unlockFocus, this should I think eliminate the flickering, as AppKit will flush once at the end of each window drawing pass. Let me know if that doesn't fix the problem for some reason; maybe I don't fully understand what you're trying to do.

It has worked fine, my drawing is now:
- (void)drawRect:(NSRect)rect
{
[bgColour set];
[NSBezierPath fillRect:rect];
[fgColour set];
if (gotImage == YES) {
[theArtwork compositeToPoint:imagePoint operation:NSCompositeCopy];
}
}

I think my problem was calling [self drawRect: [self bounds]] instead of [self setNeedsDisplay:YES] in -animateOneFrame (this is a screeensaver) for some reason.

Well, I'll learn ;)
--
Phillip Hutchings
email@hidden
http://www.sitharus.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Stopping a NSView from drawing in -drawRect
      • From: Troy Stephens <email@hidden>
References: 
 >Stopping a NSView from drawing in -drawRect (From: Phillip Hutchings <email@hidden>)
 >Re: Stopping a NSView from drawing in -drawRect (From: James Chen <email@hidden>)
 >Re: Stopping a NSView from drawing in -drawRect (From: Phillip Hutchings <email@hidden>)
 >Re: Stopping a NSView from drawing in -drawRect (From: Troy Stephens <email@hidden>)

  • Prev by Date: Re: Stopping a NSView from drawing in -drawRect
  • Next by Date: Re: Stopping a NSView from drawing in -drawRect
  • Previous by thread: Re: Stopping a NSView from drawing in -drawRect
  • Next by thread: Re: Stopping a NSView from drawing in -drawRect
  • Index(es):
    • Date
    • Thread