-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNC_Window.mm
More file actions
84 lines (63 loc) · 2.29 KB
/
Copy pathCNC_Window.mm
File metadata and controls
84 lines (63 loc) · 2.29 KB
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
#include <AppKit/AppKit.h>
#include <CoreVideo/CoreVideo.h>
#include "CNC_Types.h"
@interface MainWindowDelegate : NSObject< NSWindowDelegate >
{
@public
bool* m_running;
}
- (instancetype)initWithBool:(bool*)running;
@end
@implementation MainWindowDelegate
- (instancetype)initWithBool:(bool*)running
{
self = [super init];
m_running = running;
return self;
}
- (BOOL)windowShouldClose:(NSWindow*)sender
{
*m_running = false;
return true;
}
@end
@interface MainWindow : NSWindow
{
@public
NSCondition* m_displayLinkSignal;
CVDisplayLinkRef m_displayLink;
}
@end
@implementation MainWindow
- (BOOL)canBecomeKeyWindow { return true; }
- (BOOL)canBecomeMainWindow { return true; }
@end
CVReturn DisplayLinkCallback( CVDisplayLinkRef displayLink,
const CVTimeStamp* inNow,
const CVTimeStamp* inOutputTime,
CVOptionFlags flagsIn,
CVOptionFlags* flagsOut,
void* context )
{
MainWindow* window = (MainWindow*)context;
[window->m_displayLinkSignal signal];
return kCVReturnSuccess;
}
MainWindow* CreateMainWindow( bool* running )
{
MainWindowDelegate* delegate = [[MainWindowDelegate alloc] initWithBool:running];
NSRect contentRect = NSMakeRect( 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT );
MainWindow* window = [[MainWindow alloc] initWithContentRect: contentRect
styleMask: NSWindowStyleMaskClosable |
NSWindowStyleMaskTitled |
NSWindowStyleMaskResizable
backing: NSBackingStoreBuffered defer: false];
[window setTitle: @"synthesizer by cnc" ];
[window setDelegate: delegate];
[window makeKeyAndOrderFront: NULL];
window->m_displayLinkSignal = [NSCondition new];
CVDisplayLinkCreateWithActiveCGDisplays( &window->m_displayLink );
CVDisplayLinkSetOutputCallback( window->m_displayLink, DisplayLinkCallback, (void*)window );
CVDisplayLinkStart( window->m_displayLink );
return window;
}