2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_Application)
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaDelegate : NSObject
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender {
|
2015-12-30 06:41:46 +00:00
|
|
|
using hiro::Application;
|
2018-08-05 09:00:15 +00:00
|
|
|
if(Application::state().cocoa.onQuit) Application::Cocoa::doQuit();
|
2013-03-15 13:11:33 +00:00
|
|
|
else Application::quit();
|
|
|
|
return NSTerminateCancel;
|
|
|
|
}
|
|
|
|
|
2013-03-21 12:59:01 +00:00
|
|
|
-(BOOL) applicationShouldHandleReopen:(NSApplication*)application hasVisibleWindows:(BOOL)flag {
|
2015-12-30 06:41:46 +00:00
|
|
|
using hiro::Application;
|
2018-08-05 09:00:15 +00:00
|
|
|
if(Application::state().cocoa.onActivate) Application::Cocoa::doActivate();
|
2013-03-21 12:59:01 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) run:(NSTimer*)timer {
|
2015-12-30 06:41:46 +00:00
|
|
|
using hiro::Application;
|
2018-08-05 09:00:15 +00:00
|
|
|
if(Application::state().onMain) Application::doMain();
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 13:31:46 +00:00
|
|
|
-(void) updateInDock:(NSTimer*)timer {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSArray* windows = [NSApp windows];
|
2015-12-30 06:41:46 +00:00
|
|
|
for(uint n = 0; n < [windows count]; n++) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSWindow* window = [windows objectAtIndex:n];
|
2013-04-09 13:31:46 +00:00
|
|
|
if([window isMiniaturized]) {
|
|
|
|
[window updateInDock];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@end
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
CocoaDelegate* cocoaDelegate = nullptr;
|
2017-10-07 07:28:12 +00:00
|
|
|
NSTimer* applicationTimer = nullptr;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
2013-03-15 13:11:33 +00:00
|
|
|
|
Update to 20180809 release.
byuu says:
The Windows port can now run the emulation while navigating menus,
moving windows, and resizing windows. The main window also doesn't try
so hard to constantly clear itself. This may leave a bit of unwelcome
residue behind in some video drivers during resize, but under most
drivers, it lets you resize without a huge amount of flickering.
On all platforms, I now also run the emulation during MessageWindow
modal events, where I didn't before.
I'm thinking we should probably mute the audio during modal periods,
since it can generate a good deal of distortion.
The tooltip timeout was increased to ten seconds.
On Windows, the enter key can now activate buttons, so you can more
quickly dismiss MessageDialog windows. This part may not actually work
... I'm in the middle of trying to get messages out of the global
`Application_windowProc` hook and into the individual `Widget_windowProc`
hooks, so I need to do some testing.
I fixed a bug where changing the input driver wouldn't immediately
reload the input/hotkey settings lists properly.
I also went from disabling the driver "Change" button when the currently
active driver is selected in the list, to instead setting it to say
"Reload", and I also added a tool tip to the input driver reload button,
advising that if you're using DirectInput or SDL, you can hit "Reload"
to rescan for hotplugged gamepads without needing to restart the
emulator. XInput and udev have auto hotswap support. If we can ever get
that into DirectInput and SDL, then I'll remove the tooltip. But
regardless, the reload functionality is nice to have for all drivers.
I'm not sure what should happen when a user changes their driver
selection while a game is loaded, gets the warning dialog, chooses not
to change it, and then closes the emulator. Currently, it will make the
change happen the next time you start the emulator. This feels a bit
unexpected, but when you change the selection without a game loaded, it
takes immediate effect. So I'm not really sure what's best here.
2018-08-10 05:02:59 +00:00
|
|
|
auto pApplication::modal() -> bool {
|
|
|
|
return Application::state().modal > 0;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pApplication::run() -> void {
|
2017-10-07 07:28:12 +00:00
|
|
|
//applicationTimer = [NSTimer scheduledTimerWithTimeInterval:0.1667 target:cocoaDelegate selector:@selector(updateInDock:) userInfo:nil repeats:YES];
|
2013-04-09 13:31:46 +00:00
|
|
|
|
2018-08-05 09:00:15 +00:00
|
|
|
if(Application::state().onMain) {
|
2017-10-07 07:28:12 +00:00
|
|
|
applicationTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:cocoaDelegate selector:@selector(run:) userInfo:nil repeats:YES];
|
2013-03-21 12:59:01 +00:00
|
|
|
|
|
|
|
//below line is needed to run application during window resize; however it has a large performance penalty on the resize smoothness
|
2017-10-07 07:28:12 +00:00
|
|
|
//[[NSRunLoop currentRunLoop] addTimer:applicationTimer forMode:NSEventTrackingRunLoopMode];
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
2013-04-09 13:31:46 +00:00
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[NSApp run];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pApplication::pendingEvents() -> bool {
|
2013-03-15 13:11:33 +00:00
|
|
|
bool result = false;
|
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:NO];
|
2013-03-15 13:11:33 +00:00
|
|
|
if(event != nil) result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pApplication::processEvents() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2018-08-05 09:00:15 +00:00
|
|
|
while(!Application::state().quit) {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
|
2013-03-15 13:11:33 +00:00
|
|
|
if(event == nil) break;
|
|
|
|
[event retain];
|
|
|
|
[NSApp sendEvent:event];
|
|
|
|
[event release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pApplication::quit() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2017-10-07 07:28:12 +00:00
|
|
|
[applicationTimer invalidate];
|
2013-03-15 13:11:33 +00:00
|
|
|
[NSApp stop:nil];
|
2013-05-02 11:25:45 +00:00
|
|
|
NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 windowNumber:0 context:nil subtype:0 data1:0 data2:0];
|
2013-03-15 13:11:33 +00:00
|
|
|
[NSApp postEvent:event atStart:true];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 13:41:41 +00:00
|
|
|
auto pApplication::setScreenSaver(bool screenSaver) -> void {
|
|
|
|
//TODO: not implemented
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pApplication::initialize() -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
cocoaDelegate = [[CocoaDelegate alloc] init];
|
|
|
|
[NSApp setDelegate:cocoaDelegate];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-30 06:41:46 +00:00
|
|
|
|
|
|
|
#endif
|