Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: cocoa/quartz clipping problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cocoa/quartz clipping problem



On Sep 10, 2008, at 2:49 AM, Niels Bogaards wrote:

In my app, I use Cocoa as application framework, Quartz as drawing library and C++ for my general infrastructure and the app's specific functionality. The three come together in this class :

class DrawContext{

	CGContextRef	mNativeContext;
};

where the mNativeContext variable is filled with

NSGraphicsContext* nativeContext = [NSGraphicsContext graphicsContextWithWindow:myNSWindow];
mNativeContext = (CGContextRef) [nativeContext graphicsPort];

Why do you feel the need to cache this context? Compared to drawing its fairly cheap to refetch it every time your -drawRect: is called. As an expression of the API, there is no guarantee that the context you get is the same for every invocation of -drawRect:.


In the -(void)drawRect:(NSRect)aRect function of my NSViews, I get this stored nativecontext and draw on it, doing a CGContextSaveGState first, and a CGContextRestoreGState when I'm done. Inside the drawRect, I clip to the aRect, using CGContextClipToRect.

The drawing should already be clipped to the area of aRect, so you shouldn't have to clip it yourself.


--
David Duncan
Apple DTS Animation and Printing

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >cocoa/quartz clipping problem (From: Niels Bogaards <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.