-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNC_Window.mm
83 lines (66 loc) · 2.27 KB
/
CNC_Window.mm
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>
@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
CVDisplayLinkRef m_displayLink;
NSCondition* m_displayLinkSignal;
bool* m_start;
}
@end
@implementation MainWindow
- (BOOL)windowCanBecomeKey { return true; }
- (BOOL)windowCanBecomeMain { return true; }
- (void)mouseDown:(NSEvent *)event
{
*m_start = true;
}
@end
CVReturn DisplayCallback( CVDisplayLinkRef displayLink,
const CVTimeStamp* inNow,
const CVTimeStamp* inOutputTime,
CVOptionFlags flagsIn,
CVOptionFlags* flagsOut,
void* mainwindow )
{
MainWindow* window = (MainWindow*)mainwindow;
[window->m_displayLinkSignal signal];
return kCVReturnSuccess;
}
MainWindow* CreateMainWindow( bool* running, bool* start )
{
NSRect contentRect = NSMakeRect( 0, 0, 600, 600);
MainWindowDelegate* delegate = [[MainWindowDelegate alloc] initWithBool:running];
MainWindow* window = [[MainWindow alloc] initWithContentRect: contentRect
styleMask: NSWindowStyleMaskClosable | NSWindowStyleMaskTitled
backing: NSBackingStoreBuffered
defer: false];
[window setTitle: @"clock by cnc"];
[window makeKeyAndOrderFront: NULL];
[window setDelegate: delegate];
window->m_start = start;
window->m_displayLinkSignal = [NSCondition new];
CVDisplayLinkCreateWithActiveCGDisplays( &window->m_displayLink );
CVDisplayLinkSetOutputCallback( window->m_displayLink, &DisplayCallback, (void*)window );
CVDisplayLinkStart( window->m_displayLink );
return window;
}