Skip to content

Commit

Permalink
-[NSWindow backingScaleFactor] is 10.7+ so guard our uses of it
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed Apr 6, 2012
1 parent 269aeb7 commit 2b6966c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/UIKit/TUINSView.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ - (void)setRootView:(TUIView *)v
[layer setDelegate:self];
[layer addSublayer:rootView.layer];

if([self window] != nil) {
self.layer.contentsScale = [[self window] backingScaleFactor];
}
[self _updateLayerScaleFactor];
}

- (void)setNextResponder:(NSResponder *)r
Expand Down Expand Up @@ -177,16 +175,25 @@ - (void)viewWillMoveToWindow:(NSWindow *)newWindow {

- (void)viewDidMoveToWindow
{
if([self window] != nil) {
self.layer.contentsScale = [[self window] backingScaleFactor];
}
[self _updateLayerScaleFactor];

[self.rootView didMoveToWindow];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self.window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:self.window];
}

- (void)_updateLayerScaleFactor {
if([self window] != nil) {
CGFloat scale = 1.0f;
if([[self window] respondsToSelector:@selector(backingScaleFactor)]) {
scale = [[self window] backingScaleFactor];
}

self.layer.contentsScale = scale;
}
}

- (TUIView *)viewForLocalPoint:(NSPoint)p
{
return [rootView hitTest:p withEvent:nil];
Expand Down
9 changes: 7 additions & 2 deletions lib/UIKit/TUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,13 @@ - (void)willMoveToWindow:(TUINSWindow *)newWindow {
[[NSNotificationCenter defaultCenter] postNotificationName:TUIViewWillMoveToWindowNotification object:self userInfo:newWindow != nil ? [NSDictionary dictionaryWithObject:newWindow forKey:TUIViewWindow] : nil];
}
- (void)didMoveToWindow {
if(self.nsWindow != nil) {
self.layer.contentsScale = [self.nsWindow backingScaleFactor];
if([self nsWindow] != nil) {
CGFloat scale = 1.0f;
if([[self nsWindow] respondsToSelector:@selector(backingScaleFactor)]) {
scale = [[self nsWindow] backingScaleFactor];
}

self.layer.contentsScale = scale;
}

for(TUIView *subview in self.subviews) {
Expand Down

0 comments on commit 2b6966c

Please sign in to comment.