-
Notifications
You must be signed in to change notification settings - Fork 92
/
OSXWindowFrameView.m
191 lines (142 loc) · 5.89 KB
/
OSXWindowFrameView.m
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#import "OSXWindowFrameView.h"
#import "OSXWindow.h"
@implementation OSXWindowFrameView
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-(void)updateTrackingAreas
{
if(trackingArea != nil) {
[self removeTrackingArea:trackingArea];
[trackingArea release];
}
int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
trackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds]
options:opts
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)drawRect:(NSRect)rect
{
(void)rect;
CGContextRef context = [[NSGraphicsContext currentContext] CGContext];
printf("drawRect\n");
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL);
CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little,
provider, NULL, false, kCGRenderingIntentDefault);
CGColorSpaceRelease(space);
CGDataProviderRelease(provider);
CGContextDrawImage(context, CGRectMake(0, 0, width * scale, height * scale), img);
CGImageRelease(img);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
- (BOOL)wantsUpdateLayer
{
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-(void)updateLayer
{
printf("update layer\n");
// Force the graphics context to clear to black so we don't get a flash of
// white until the app is ready to draw. In practice on modern macOS, this
// only gets called for window creation and other extraordinary events.
self.layer.backgroundColor = NSColor.blackColor.CGColor;
//NSGraphicsContext* context = [NSGraphicsContext currentContext];
//[context scheduleUpdate];
//(void)rect;
CGContextRef context = [[NSGraphicsContext currentContext] CGContext];
//printf("drawRect\n");
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, draw_buffer, width * height * 4, NULL);
CGImageRef img = CGImageCreate(width, height, 8, 32, width * 4, space, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little,
provider, NULL, false, kCGRenderingIntentDefault);
CGColorSpaceRelease(space);
CGDataProviderRelease(provider);
CGContextDrawImage(context, CGRectMake(0, 0, width * scale, height * scale), img);
CGImageRelease(img);
//ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
//SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
//[context scheduleUpdate];
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)mouseDown:(NSEvent*)event
{
(void)event;
OSXWindow* window = (OSXWindow*)[self window];
window->shared_data->mouse_state[0] = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)mouseUp:(NSEvent*)event
{
(void)event;
OSXWindow* window = (OSXWindow*)[self window];
window->shared_data->mouse_state[0] = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)rightMouseDown:(NSEvent*)event
{
(void)event;
OSXWindow* window = (OSXWindow*)[self window];
window->shared_data->mouse_state[2] = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)rightMouseUp:(NSEvent*)event
{
(void)event;
OSXWindow* window = (OSXWindow*)[self window];
window->shared_data->mouse_state[2] = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)scrollWheel:(NSEvent *)event
{
OSXWindow* window = (OSXWindow*)[self window];
window->shared_data->scroll_x = [event deltaX];
window->shared_data->scroll_y = [event deltaY];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)canBecomeKeyView
{
return YES;
}
- (NSView *)nextValidKeyView
{
return self;
}
- (NSView *)previousValidKeyView
{
return self;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)acceptsFirstResponder
{
return YES;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidMoveToWindow
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowResized:) name:NSWindowDidResizeNotification
object:[self window]];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (void)windowResized:(NSNotification *)notification
{
(void)notification;
NSSize size = [self bounds].size;
OSXWindow* window = (OSXWindow*)[self window];
if (window->shared_data) {
window->shared_data->width = (int)(size.width);
window->shared_data->height = (int)(size.height);
}
}
@end