Refactoring

This commit is contained in:
Hajime Hoshi 2013-12-30 01:55:53 +09:00
parent fbd35ac6a8
commit f82241b56f
2 changed files with 8 additions and 11 deletions

View File

@ -25,18 +25,13 @@ void ebiten_WindowClosed(void* nativeWindow);
styleMask:style]; styleMask:style];
NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
NSSize screenSize = [screen visibleFrame].size; NSSize screenSize = [screen visibleFrame].size;
// Reference: Mac OS X Human Interface Guidelines: UI Element Guidelines: NSRect contentRect = NSMakeRect(0, 0, size.width, size.height);
// Windows
// http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Windows/Windows.html
NSRect contentRect =
NSMakeRect((screenSize.width - windowRect.size.width) / 2,
(screenSize.height - windowRect.size.height) * 2 / 3,
size.width, size.height);
self = [super initWithContentRect:contentRect self = [super initWithContentRect:contentRect
styleMask:style styleMask:style
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]; defer:YES];
if (self != nil) { if (self != nil) {
[self center];
[self setReleasedWhenClosed:YES]; [self setReleasedWhenClosed:YES];
[self setDelegate:self]; [self setDelegate:self];
[self setDocumentEdited:YES]; [self setDocumentEdited:YES];

View File

@ -10,12 +10,16 @@ void initMenu(void) {
NSMenu* menuBar = [NSMenu new]; NSMenu* menuBar = [NSMenu new];
[NSApp setMainMenu: menuBar]; [NSApp setMainMenu: menuBar];
[menuBar release];
NSMenuItem* rootMenuItem = [NSMenuItem new]; NSMenuItem* rootMenuItem = [NSMenuItem new];
[menuBar addItem:rootMenuItem]; [menuBar addItem:rootMenuItem];
[rootMenuItem release];
NSMenu* appMenu = [NSMenu new]; NSMenu* appMenu = [NSMenu new];
[rootMenuItem setSubmenu:appMenu]; [rootMenuItem setSubmenu:appMenu];
[appMenu release];
[appMenu addItemWithTitle:[@"Quit " stringByAppendingString:processName] [appMenu addItemWithTitle:[@"Quit " stringByAppendingString:processName]
action:@selector(performClose:) action:@selector(performClose:)
keyEquivalent:@"q"]; keyEquivalent:@"q"];
@ -49,21 +53,19 @@ void* CreateGLContext(void* sharedGLContext) {
void* CreateWindow(size_t width, size_t height, const char* title, void* glContext_) { void* CreateWindow(size_t width, size_t height, const char* title, void* glContext_) {
NSOpenGLContext* glContext = (NSOpenGLContext*)glContext_; NSOpenGLContext* glContext = (NSOpenGLContext*)glContext_;
NSSize size = NSMakeSize(width, height); NSSize size = NSMakeSize(width, height);
EbitenWindow* window = [[EbitenWindow alloc] EbitenWindow* window = [[EbitenWindow alloc]
initWithSize:size initWithSize:size
glContext:glContext]; glContext:glContext];
[glContext release];
NSString* nsTitle = [[NSString alloc] NSString* nsTitle = [[NSString alloc]
initWithUTF8String:title]; initWithUTF8String:title];
[window setTitle: nsTitle]; [window setTitle: nsTitle];
[nsTitle release]; [nsTitle release];
[window makeKeyAndOrderFront:nil]; [window makeKeyAndOrderFront:nil];
[glContext setView:[window contentView]]; [glContext setView:[window contentView]];
[glContext release];
return window; return window;
} }