Fixed: #1011 Switch nlWindow from NSWindow* to NSView*

This commit is contained in:
rti 2010-07-07 00:06:46 +02:00
parent 5339fbc01a
commit acc6b6ecf1

View file

@ -149,30 +149,17 @@ static void setupGLView(NSView* superview)
// free the pixel format object // free the pixel format object
[format release]; [format release];
// let this view receive be target of events
[view becomeFirstResponder];
} }
void ctor() void ctor()
{ {
// create a pool, cocoa code would leak memory otherwise
g_pool = [[NSAutoreleasePool alloc] init];
// init the application object
[NSApplication sharedApplication];
// create the menu in the top screen bar
setupApplicationMenu();
// tell the application that we are running now
[NSApp finishLaunching];
} }
void dtor() void dtor()
{ {
// shut down the application
[NSApp terminate:nil];
// release the pool
[g_pool release];
} }
bool init(uint windowIcon, emptyProc exitFunc) bool init(uint windowIcon, emptyProc exitFunc)
@ -187,6 +174,19 @@ bool unInit()
nlWindow createWindow(const GfxMode& mode) nlWindow createWindow(const GfxMode& mode)
{ {
// create a pool, cocoa code would leak memory otherwise
g_pool = [[NSAutoreleasePool alloc] init];
// init the application object
[NSApplication sharedApplication];
// create the menu in the top screen bar
setupApplicationMenu();
// tell the application that we are running now
[NSApp finishLaunching];
// describe how the window should look like and behave
unsigned int styleMask = NSTitledWindowMask | NSClosableWindowMask | unsigned int styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSResizableWindowMask; NSMiniaturizableWindowMask | NSResizableWindowMask;
@ -227,6 +227,12 @@ bool destroyWindow(nlWindow wnd)
// release the window // release the window
[[view window] release]; [[view window] release];
// shut down the application
[NSApp terminate:nil];
// release the pool
[g_pool release];
return true; return true;
} }
@ -383,6 +389,10 @@ void setWindowSize(nlWindow wnd, uint32 width, uint32 height)
CGLErrorString(error)); CGLErrorString(error));
} }
else else
{
// there is only a pool if nel created the window itself assuming that
// nel is also in charge of the main loop
if(g_pool)
{ {
NSWindow* window = [view window]; NSWindow* window = [view window];
@ -396,6 +406,7 @@ void setWindowSize(nlWindow wnd, uint32 width, uint32 height)
// update window dimensions // update window dimensions
[window setFrame:rect display:YES]; [window setFrame:rect display:YES];
} }
}
// store the size // store the size
g_bufferSize[0] = width; g_bufferSize[0] = width;
@ -752,9 +763,14 @@ void emulateMouseRawMode(bool enable)
void submitEvents(NLMISC::CEventServer& server, void submitEvents(NLMISC::CEventServer& server,
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter) bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter)
{ {
// there is only a pool if nel created the window itself assuming that
// nel is also in charge of the main loop
if(g_pool)
{
// cocoa style memory cleanup // cocoa style memory cleanup
[g_pool release]; [g_pool release];
g_pool = [[NSAutoreleasePool alloc] init]; g_pool = [[NSAutoreleasePool alloc] init];
}
// we break if there was no event to handle // we break if there was no event to handle
/* TODO maximum number of events processed in one update? */ /* TODO maximum number of events processed in one update? */
@ -959,7 +975,6 @@ void submitEvents(NLMISC::CEventServer& server,
} }
[NSApp sendEvent:event]; [NSApp sendEvent:event];
[NSApp updateWindows];
} }
} }