bsnes/hiro/cocoa/application.cpp
Tim Allen 47d4bd4d81 Update to v096r01 release.
byuu says:

Changelog:

- restructured the project and removed a whole bunch of old/dead
  directives from higan/GNUmakefile
- huge amounts of work on hiro/cocoa (compiles but ~70% of the
  functionality is commented out)
- fixed a masking error in my ARM CPU disassembler [Lioncash]
- SFC: decided to change board cic=(411,413) back to board
  region=(ntsc,pal) ... the former was too obtuse

If you rename Boolean (it's a problem with an include from ruby, not
from hiro) and disable all the ruby drivers, you can compile an
OS X binary, but obviously it's not going to do anything.

It's a boring WIP, I just wanted to push out the project structure
change now at the start of this WIP cycle.
2015-12-30 17:54:59 +11:00

96 lines
2.8 KiB
C++

#if defined(Hiro_Application)
@implementation CocoaDelegate : NSObject
-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender {
using hiro::Application;
if(Application::state.cocoa.onQuit) Application::Cocoa::doQuit();
else Application::quit();
return NSTerminateCancel;
}
-(BOOL) applicationShouldHandleReopen:(NSApplication*)application hasVisibleWindows:(BOOL)flag {
using hiro::Application;
if(Application::state.cocoa.onActivate) Application::Cocoa::doActivate();
return NO;
}
-(void) run:(NSTimer*)timer {
using hiro::Application;
if(Application::state.onMain) Application::doMain();
}
-(void) updateInDock:(NSTimer*)timer {
NSArray* windows = [NSApp windows];
for(uint n = 0; n < [windows count]; n++) {
NSWindow* window = [windows objectAtIndex:n];
if([window isMiniaturized]) {
[window updateInDock];
}
}
}
@end
CocoaDelegate* cocoaDelegate = nullptr;
namespace hiro {
auto pApplication::run() -> void {
//NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.1667 target:cocoaDelegate selector:@selector(updateInDock:) userInfo:nil repeats:YES];
if(Application::state.onMain) {
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:cocoaDelegate selector:@selector(run:) userInfo:nil repeats:YES];
//below line is needed to run application during window resize; however it has a large performance penalty on the resize smoothness
//[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
}
@autoreleasepool {
[NSApp run];
}
}
auto pApplication::pendingEvents() -> bool {
bool result = false;
@autoreleasepool {
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:NO];
if(event != nil) result = true;
}
return result;
}
auto pApplication::processEvents() -> void {
@autoreleasepool {
while(!Application::state.quit) {
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
if(event == nil) break;
[event retain];
[NSApp sendEvent:event];
[event release];
}
}
}
auto pApplication::quit() -> void {
@autoreleasepool {
[NSApp stop:nil];
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0];
[NSApp postEvent:event atStart:true];
}
}
auto pApplication::initialize() -> void {
@autoreleasepool {
[NSApplication sharedApplication];
cocoaDelegate = [[CocoaDelegate alloc] init];
[NSApp setDelegate:cocoaDelegate];
//every window has the default application menu; call this so it is displayed at startup
// [NSApp setMainMenu:[pWindow::none().p.cocoaWindow menu]];
}
}
}
#endif