• 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: Drawing in a NSView out side of drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing in a NSView out side of drawRect


  • Subject: Re: Drawing in a NSView out side of drawRect
  • From: Graham Cox <email@hidden>
  • Date: Sat, 20 Dec 2008 12:01:14 +1100


On 20 Dec 2008, at 11:20 am, David Alter wrote:

I want to draw in a NSView but not when drawRect is called.

Why? There are very few situations when this is required or appropriate.

To do this I
understand that I need to call lockFocus before drawing and unlockFocus
after. The drawing appears to happen but it is not until I deactivate the
window do I see my results. How can I get it to refresh once I have done my
drawing?

You need to flush it to the screen. But don't - it's just not the right way to do drawing.


To test this out I have sub classed NSView and overloaded mouseDown. I added
the following code.


Store the rects to be drawn in a list - your view could own this list for simplicity while you are experimenting. Then invalidate the rect you need to repaint in mouse down. -drawRect: then just iterates over the list and draws those rects that intersect the update area.

This is way, way easier than trying to fudge around drawing in a non- standard manner. Learn it and love it.

hth,


Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Drawing in a NSView out side of drawRect (From: "David Alter" <email@hidden>)

  • Prev by Date: Using runtime functions to match up object types safely when setting properties
  • Next by Date: Re: Using runtime functions to match up object types safely when setting properties
  • Previous by thread: Re: Drawing in a NSView out side of drawRect
  • Next by thread: Re: Drawing in a NSView out side of drawRect
  • Index(es):
    • Date
    • Thread