Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (46 sloc) 1.6 KB
//
// ClippingNode.m
//
#import "ClippingNode.h"
@interface ClippingNode (PrivateMethods)
-(void) deviceOrientationChanged:(NSNotification*)notification;
@end
@implementation ClippingNode
-(id) initWithRect:(CGRect) rect {
if ( (self = [super init]) ) {
[self setClippingRegion:rect];
}
return self;
}
+(id) clippingNodeWithRect:(CGRect) rect {
return [[self alloc] initWithRect:rect];
}
-(CGRect) clippingRegion {
return clippingRegionInNodeCoordinates;
}
-(void) setClippingRegion:(CGRect)region {
// keep the original region coordinates in case the user wants them back unchanged
clippingRegionInNodeCoordinates = region;
self.contentSize = clippingRegionInNodeCoordinates.size;
// convert to retina coordinates if needed
region = CC_RECT_POINTS_TO_PIXELS(region);
// respect scaling
clippingRegion = CGRectMake(region.origin.x * _scaleX, region.origin.y * _scaleY,
region.size.width * _scaleX, region.size.height * _scaleY);
}
-(void) setScale:(float)newScale {
[super setScale:newScale];
[self setClippingRegion:clippingRegionInNodeCoordinates];
}
-(void) visit {
glEnable(GL_SCISSOR_TEST);
CGPoint worldPosition = [self convertToWorldSpace:CGPointZero];
const CGFloat s = [[CCDirector sharedDirector] contentScaleFactor];
glScissor(clippingRegion.origin.x + (worldPosition.x * s),
clippingRegion.origin.y + (worldPosition.y * s),
clippingRegion.size.width,
clippingRegion.size.height);
[super visit];
glDisable(GL_SCISSOR_TEST);
}
@end
You can’t perform that action at this time.