Re: Simple question - Subclassing NSView
Re: Simple question - Subclassing NSView
- Subject: Re: Simple question - Subclassing NSView
- From: Jens Alfke <email@hidden>
- Date: Thu, 12 Jun 2008 11:33:04 -0700
On 12 Jun '08, at 10:54 AM, Vikas wrote:
How the function knows about the drawing surface, in which window/
surface to paint?
There's always a current graphics context; it's global to each thread.
(See NSGraphicsContext if you want to look at its API; but if you're
looking for the low-level drawing primitives, they're defined in the
CoreGraphics framework as CGContext functions. AppKit's drawing code
is all wrappers around those.)
So basically, any code that wants to draw or alter the drawing state
calls [NSGraphicsContext currentContext] to get the current context.
This is different than, say, Java, where the graphics context is
associated with each view/component. Graphics contexts turn out to be
expensive objects, and AppKit just uses one, and adjusts its state
depending on what needs to be drawn. Mostly you don't need to worry
about this. When a view's -drawReect: method is called, the graphics
context has already been set up for drawing into that view.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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