implement save request on OSX, add Quick Look extentions

This commit is contained in:
2018-07-31 00:38:10 +02:00
parent 87fcea61b8
commit 5a37f578cb
18 changed files with 814 additions and 20 deletions

View File

@@ -13,6 +13,32 @@
#include <OpenGL/OpenGL.h>
#import "objc_utils.h"
void global_exception_handler(NSException* e)
{
NSAlert *alert = [NSAlert alertWithMessageText:@"Recovery"
defaultButton:@"OK" alternateButton:@"Cancel"
otherButton:nil informativeTextWithFormat:@"Exception"];
[alert runModal];
if (App::I.canvas && App::I.canvas->m_canvas)
App::I.canvas->m_canvas->project_save_thread(App::I.data_path + "/recovery.pano");
std::terminate();
}
void global_signal_handler(int e)
{
NSAlert *alert = [NSAlert alertWithMessageText:@"Recovery"
defaultButton:@"OK" alternateButton:@"Cancel"
otherButton:nil informativeTextWithFormat:@"Signal"];
[alert runModal];
if (App::I.canvas && App::I.canvas->m_canvas)
App::I.canvas->m_canvas->project_save_thread(App::I.data_path + "/recovery.pano");
std::terminate();
}
@implementation View
- (void)async_lock
{
@@ -27,6 +53,10 @@
{
CGLFlushDrawable([glctx CGLContextObj]);
}
- (void)close
{
[[NSApplication sharedApplication] terminate:nil];
}
- (std::string)pick_file
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
@@ -307,32 +337,67 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
CGLLockContext([[self openGLContext] CGLContextObj]);
auto keyCode = [theEvent keyCode];
auto chars = [theEvent characters];
App::I.key_down(convert_key(keyCode));
if (const char* cstr = [chars cStringUsingEncoding:NSASCIIStringEncoding])
App::I.key_char(cstr[0]);
if (App::I.keys[(int)kKey::KeyCtrl])
{
App::I.key_down(convert_key(keyCode));
App::I.key_up(convert_key(keyCode));
}
else
{
App::I.key_down(convert_key(keyCode));
if (const char* cstr = [chars cStringUsingEncoding:NSASCIIStringEncoding])
App::I.key_char(cstr[0]);
}
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
- (void)keyUp:(NSEvent *)theEvent
{
CGLLockContext([[self openGLContext] CGLContextObj]);
auto keyCode = [theEvent keyCode];
auto chars = [theEvent characters];
//auto chars = [theEvent characters];
App::I.key_up(convert_key(keyCode));
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
- (void)flagsChanged:(NSEvent *)event
{
[super flagsChanged:event];
CGLLockContext([[self openGLContext] CGLContextObj]);
static bool pressed_shift = false;
if (pressed_shift != ([event modifierFlags] & NSShiftKeyMask))
{
pressed_shift = ([event modifierFlags] & NSShiftKeyMask);
pressed_shift ? App::I.key_down(kKey::KeyShift) : App::I.key_up(kKey::KeyShift);
}
static bool pressed_alt = false;
if (pressed_alt != ([event modifierFlags] & NSAlternateKeyMask))
{
pressed_alt = ([event modifierFlags] & NSAlternateKeyMask);
pressed_alt ? App::I.key_down(kKey::KeyAlt) : App::I.key_up(kKey::KeyAlt);
}
static bool pressed_cmd = false;
if (pressed_cmd != ([event modifierFlags] & NSCommandKeyMask))
{
pressed_cmd = ([event modifierFlags] & NSCommandKeyMask);
pressed_cmd ? App::I.key_down(kKey::KeyCtrl) : App::I.key_up(kKey::KeyCtrl);
}
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
@end
@interface Window : NSWindow
@end @implementation Window
@implementation Window
@end
@interface Controller : NSWindowController<NSWindowDelegate>
@end @implementation Controller
@implementation Controller
- (void)windowWillClose:(NSNotification *)notification
{
App::I.terminate();
[[NSApplication sharedApplication] terminate:nil];
}
-(BOOL)windowShouldClose:(NSWindow *)sender
{
return App::I.request_close();
}
@end
@interface AppOSX : NSApplication<NSApplicationDelegate>
@@ -356,6 +421,9 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
if (!App::I.check_license())
return;
App::I.initLog();
App::I.create();
NSRect r = NSMakeRect(0, 0, App::I.width, App::I.height);
@@ -373,6 +441,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
[window setContentView:view];
[window setAcceptsMouseMovedEvents:true];
[window makeFirstResponder:view];
view->wnd = window;
auto menubar = [NSMenu new];
auto appMenuItem = [NSMenuItem new];
@@ -394,6 +463,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
int main(int argc, const char * argv[])
{
AppOSX* app = [AppOSX sharedApplication];
NSSetUncaughtExceptionHandler(&global_exception_handler);
signal(SIGFPE, global_signal_handler);
[app run];
return 0;
}