Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Because we all need to find our center sometimes.
- Loading branch information
1 parent
ee596ae
commit 65931e7
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// NSWindow+CenterOnScreen.h | ||
// Hyperspaces | ||
// | ||
// Created by Tony Arnold on 8/01/10. | ||
// Copyright 2010 The CocoaBots. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface NSWindow (CenterOnScreen) | ||
|
||
- (void)centerWindowOnScreen; | ||
- (void)centerWindowOnScreen:(NSScreen *)screen; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// NSWindow+CenterOnScreen.m | ||
// Hyperspaces | ||
// | ||
// Created by Tony Arnold on 8/01/10. | ||
// Copyright 2010 The CocoaBots. All rights reserved. | ||
// | ||
|
||
#import "NSWindow+CenterOnScreen.h" | ||
|
||
|
||
@implementation NSWindow (CenterOnScreen) | ||
|
||
- (void)centerWindowOnScreen { | ||
[self centerWindowOnScreen:[self screen]]; | ||
} | ||
|
||
- (void)centerWindowOnScreen:(NSScreen *)screen { | ||
if (screen == nil) { | ||
screen = [self screen]; | ||
} | ||
|
||
NSRect windowFrame = [self frame]; | ||
NSRect visibleFrame = [screen visibleFrame]; | ||
|
||
windowFrame.origin.x = visibleFrame.origin.x + (NSWidth(visibleFrame) - NSWidth(windowFrame)) * 0.5f; | ||
windowFrame.origin.y = visibleFrame.origin.y + (NSHeight(visibleFrame) - NSHeight(windowFrame)) * 0.8f; | ||
|
||
[self setFrameOrigin:windowFrame.origin]; | ||
} | ||
|
||
@end |