Skip to content

Commit

Permalink
Changed the Mac CPTGraphHostingView so it can act as either a layer h…
Browse files Browse the repository at this point in the history
…osting view or a layer backed view as required. Fixed issue #167.
  • Loading branch information
eskroch committed Aug 16, 2015
1 parent cc05e59 commit 71a09cd
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions framework/MacOnly/CPTGraphHostingView.m
Expand Up @@ -74,12 +74,18 @@ -(instancetype)initWithFrame:(NSRect)frame
locationInWindow = NSZeroPoint;
scrollOffset = CGPointZero;

CPTLayer *mainLayer = [[CPTLayer alloc] initWithFrame:NSRectToCGRect(frame)];
self.layer = mainLayer;
if ( !self.superview.wantsLayer ) {
self.layer = [self makeBackingLayer];
}
}
return self;
}

-(CALayer *)makeBackingLayer
{
return [[CPTLayer alloc] initWithFrame:NSRectToCGRect(self.bounds)];
}

-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
Expand Down Expand Up @@ -189,6 +195,13 @@ -(void)drawRect:(NSRect)dirtyRect
}
}

/// @endcond

#pragma mark -
#pragma mark Printing

/// @cond

-(BOOL)knowsPageRange:(NSRangePointer)rangePointer
{
rangePointer->location = 1;
Expand Down Expand Up @@ -477,6 +490,22 @@ -(void)plotAreaBoundsChanged
[self.window invalidateCursorRectsForView:self];
}

-(void)viewWillMoveToSuperview:(NSView *)newSuperview
{
if ( self.superview.wantsLayer != newSuperview.wantsLayer ) {
self.wantsLayer = NO;
self.layer = nil;

if ( newSuperview.wantsLayer ) {
self.wantsLayer = YES;
}
else {
self.layer = [self makeBackingLayer];
self.wantsLayer = YES;
}
}
}

/// @endcond

#pragma mark -
Expand Down

0 comments on commit 71a09cd

Please sign in to comment.