• 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: Troy Stephens <email@hidden>
  • Date: Fri, 6 Feb 2004 14:18:59 -0800

On Feb 6, 2004, at 3:45 AM, Phillip Hutchings wrote:
That's what I thought, my current code is:

- (void)drawRect:(NSRect)rect
{
NSDisableScreenUpdates();
[self lockFocus];

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

[bgColour set];
[NSBezierPath fillRect:rect];
[fgColour set];

[trackTextView display];
if (gotImage == YES) {
[theArtwork compositeToPoint:imagePoint operation:NSCompositeCopy];
}

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.

[self unlockFocus];
NSEnableScreenUpdates();
}

I never call display explicitly, only setNeedsDisplay. This is in a screensaver if it makes any difference.

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.

Troy Stephens
Cocoa frameworks, Apple
_______________________________________________
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: Phillip Hutchings <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>)

  • Prev by Date: Sorting NSTableView
  • 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