Changed: #947 added mac menu, force redraw after buffer swap, some cleanup

This commit is contained in:
rti 2010-06-24 21:39:18 +02:00
parent bf742eaf11
commit bba512990d

View file

@ -34,27 +34,90 @@
namespace NL3D { namespace MAC { namespace NL3D { namespace MAC {
static NSApplication* g_app = nil;
static NSAutoreleasePool* g_pool = nil; static NSAutoreleasePool* g_pool = nil;
/*
TODO move to event emitter class
*/
static bool g_emulateRawMode = false; static bool g_emulateRawMode = false;
static int g_bufferSize[2] = { 0, 0 }; static int g_bufferSize[2] = { 0, 0 };
static void setupApplicationMenu()
{
NSMenu* menu;
NSMenuItem* menuItem;
NSString* title;
NSString* appName;
// get the applications name from it's process info
appName = [[NSProcessInfo processInfo] processName];
// create an empty menu object
menu = [[NSMenu alloc] initWithTitle:@""];
// add the about menu item
title = [@"About " stringByAppendingString:appName];
[menu addItemWithTitle:title
action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
// separator
[menu addItem:[NSMenuItem separatorItem]];
// add the hide application menu item
title = [@"Hide " stringByAppendingString:appName];
[menu addItemWithTitle:title
action:@selector(hide:) keyEquivalent:@"h"];
// add the hide others menu item
menuItem = [menu addItemWithTitle:@"Hide Others"
action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
// add the show all menu item
[menu addItemWithTitle:@"Show All"
action:@selector(unhideAllApplications:) keyEquivalent:@""];
// separator
[menu addItem:[NSMenuItem separatorItem]];
/*
TODO on quit send EventDestroyWindowId
*/
// add the quit menu item
title = [@"Quit " stringByAppendingString:appName];
[menu addItemWithTitle:title
action:@selector(terminate:) keyEquivalent:@"q"];
// create an empty menu item and put the new menu into it as a subitem
menuItem = [[NSMenuItem alloc] initWithTitle:@""
action:nil keyEquivalent:@""];
[menuItem setSubmenu:menu];
// create a menu for the application
[NSApp setMainMenu:[[NSMenu alloc] initWithTitle:@""]];
// attach the new menu to the applications menu
[[NSApp mainMenu] addItem:menuItem];
}
void ctor() void ctor()
{ {
// create a pool, cocoa code would leak memory otherwise // create a pool, cocoa code would leak memory otherwise
g_pool = [[NSAutoreleasePool alloc] init]; g_pool = [[NSAutoreleasePool alloc] init];
// init the application object // init the application object
g_app = [NSApplication sharedApplication]; [NSApplication sharedApplication];
// create the menu in the top screen bar
setupApplicationMenu();
// tell the application that we are running now // tell the application that we are running now
[g_app finishLaunching]; [NSApp finishLaunching];
} }
void dtor() void dtor()
{ {
// shut down the application // shut down the application
[g_app terminate:nil]; [NSApp terminate:nil];
// release the pool // release the pool
[g_pool release]; [g_pool release];
@ -106,7 +169,10 @@ bool destroyWindow(nlWindow wnd)
NSWindow* window = (NSWindow*)wnd; NSWindow* window = (NSWindow*)wnd;
NSOpenGLView* view = [window contentView]; NSOpenGLView* view = [window contentView];
// release the view we alloced
[view release]; [view release];
// release the window we alloced
[window release]; [window release];
return true; return true;
@ -119,10 +185,6 @@ nlWindow setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeabl
call showWindow() call showWindow()
*/ */
/*
TODO add menu, on quit send EventDestroyWindowId
*/
NSWindow* window = (NSWindow*)wnd; NSWindow* window = (NSWindow*)wnd;
if(wnd == EmptyWindow) if(wnd == EmptyWindow)
@ -405,10 +467,12 @@ bool activate(nlWindow wnd)
void swapBuffers(nlWindow wnd) void swapBuffers(nlWindow wnd)
{ {
NSWindow* window = (NSWindow*)wnd; NSWindow* window = (NSWindow*)wnd;
NSOpenGLContext* ctx = [[window contentView] openGLContext]; NSOpenGLView* view = [window contentView];
NSOpenGLContext* ctx = [view openGLContext];
// make cocoa draw buffer contents to the view // make cocoa draw buffer contents to the view
[ctx flushBuffer]; [ctx flushBuffer];
[view display];
} }
void setCapture(bool capture) void setCapture(bool capture)
@ -686,7 +750,7 @@ void submitEvents(NLMISC::CEventServer& server,
while(true) while(true)
{ {
// get the next event to handle // get the next event to handle
NSEvent* event = [g_app nextEventMatchingMask:NSAnyEventMask NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:nil /*[NSDate distantFuture]*/ untilDate:nil /*[NSDate distantFuture]*/
inMode:NSDefaultRunLoopMode dequeue:YES]; inMode:NSDefaultRunLoopMode dequeue:YES];
@ -705,8 +769,8 @@ void submitEvents(NLMISC::CEventServer& server,
if((mouseX < 0.0 || mouseX > 1.0 || mouseY < 0.0 || mouseY > 1.0) && if((mouseX < 0.0 || mouseX > 1.0 || mouseY < 0.0 || mouseY > 1.0) &&
event.type != NSKeyDown && event.type != NSKeyUp) event.type != NSKeyDown && event.type != NSKeyUp)
{ {
[g_app sendEvent:event]; [NSApp sendEvent:event];
[g_app updateWindows]; [NSApp updateWindows];
continue; continue;
} }
@ -880,8 +944,8 @@ void submitEvents(NLMISC::CEventServer& server,
} }
} }
[g_app sendEvent:event]; [NSApp sendEvent:event];
[g_app updateWindows]; [NSApp updateWindows];
} }
} }