Branch
Hash :
752330a5
Author :
Thomas de Grivel
Date :
2024-08-08T17:20:11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/* c3
* Copyright 2022,2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#import "window_cairo_quartz_app_delegate.h"
#import "window_cairo_quartz_view.h"
#import "window_cairo_quartz_view_controller.h"
@implementation WindowCairoQuartzAppDelegate
- (instancetype) initWithWindowCairo:(s_window_cairo *)window_cairo {
self = [super init];
if (self) {
self.window_cairo = window_cairo;
}
return self;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSRect frame = NSMakeRect(self.window_cairo->x, self.window_cairo->y,
self.window_cairo->w, self.window_cairo->h);
self.window = [[NSWindow alloc]
initWithContentRect:frame
styleMask:(NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskResizable)
backing:NSBackingStoreBuffered
defer:NO];
[self.window setDelegate:self];
[self.window makeKeyAndOrderFront:nil];
[self.window
setTitle:[NSString
stringWithUTF8String:self.window_cairo->title]];
WindowCairoQuartzView *view =
[[WindowCairoQuartzView alloc]
initWithWindowCairo:self.window_cairo];
WindowCairoQuartzViewController *view_controller =
[[WindowCairoQuartzViewController alloc]
initWithCairoView:view];
self.view = view;
[self.window setContentView:view_controller.view];
[self.window setAcceptsMouseMovedEvents:YES];
if (! self.window_cairo->load(self.window_cairo)) {
[self.window close];
[self.window release];
[[NSApplication sharedApplication] stop:nil];
exit(1);
}
[NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(redrawWindow)
userInfo:nil
repeats:YES];
}
- (void)redrawWindow {
[self.view setNeedsDisplay:YES];
}
- (void)windowDidResize:(NSNotification *)notification {
printf("windowDidResize\n");
NSWindow *window = (NSWindow *)notification.object;
NSSize size = window.frame.size;
[self.view setFrameSize:size];
if (! self.window_cairo->resize(self.window_cairo, (uw) size.width,
size.height))
[NSApp stop:nil];
self.window_cairo->w = size.width;
self.window_cairo->h = size.height;
}
- (void)windowWillClose:(NSNotification *)notification {
[NSApp stop:nil];
}
@end