25
25
#include "pugl_internal.h"
27
// screw apple, their lack of -fvisibility=internal and namespaces
28
#define CONCAT(A,B) A ## B
29
#define XCONCAT(A,B) CONCAT(A,B)
30
#define RobTKPuglWindow XCONCAT(RobTKPuglWindow, UINQHACK)
31
#define RobTKPuglOpenGLView XCONCAT(RobTKPuglOpenGLView, UINQHACK)
27
33
__attribute__ ((visibility ("hidden")))
28
34
@interface RobTKPuglWindow : NSWindow
55
61
backing:NSBackingStoreBuffered defer:NO];
57
63
[result setAcceptsMouseMovedEvents:YES];
58
[result setLevel: CGShieldingWindowLevel() + 1];
64
return (RobTKPuglWindow *)result;
63
67
- (void)setPuglview:(PuglView*)view
96
100
__attribute__ ((visibility ("hidden")))
97
101
@interface RobTKPuglOpenGLView : NSOpenGLView
102
104
PuglView* puglview;
104
106
NSTrackingArea* trackingArea;
107
- (id) initWithFrame:(NSRect)frame
108
colorBits:(int)numColorBits
109
depthBits:(int)numDepthBits;
109
- (id) initWithFrame:(NSRect)frame;
110
110
- (void) reshape;
111
111
- (void) drawRect:(NSRect)rect;
112
112
- (void) mouseMoved:(NSEvent*)event;
125
125
@implementation RobTKPuglOpenGLView
127
127
- (id) initWithFrame:(NSRect)frame
128
colorBits:(int)numColorBits
129
depthBits:(int)numDepthBits
131
colorBits = numColorBits;
132
depthBits = numDepthBits;
134
129
NSOpenGLPixelFormatAttribute pixelAttribs[16] = {
135
130
NSOpenGLPFADoubleBuffer,
136
131
NSOpenGLPFAAccelerated,
137
NSOpenGLPFAColorSize,
139
NSOpenGLPFADepthSize,
132
NSOpenGLPFAColorSize, 32,
133
NSOpenGLPFADepthSize, 32,
144
136
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc]
145
137
initWithAttributes:pixelAttribs];
147
139
if (pixelFormat) {
148
140
self = [super initWithFrame:frame pixelFormat:pixelFormat];
149
141
[pixelFormat release];
151
[[self openGLContext] makeCurrentContext];
143
self = [super initWithFrame:frame];
147
[[self openGLContext] makeCurrentContext];
233
225
- (void) mouseMoved:(NSEvent*)event
235
227
if (puglview->motionFunc) {
236
NSPoint loc = [event locationInWindow];
228
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
237
229
puglview->mods = getModifiers(puglview, event);
238
230
puglview->motionFunc(puglview, loc.x, puglview->height - loc.y);
242
234
- (void) mouseDragged:(NSEvent*)event
244
236
if (puglview->motionFunc) {
245
NSPoint loc = [event locationInWindow];
237
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
246
238
puglview->mods = getModifiers(puglview, event);
247
239
puglview->motionFunc(puglview, loc.x, puglview->height - loc.y);
251
243
- (void) rightMouseDragged:(NSEvent*)event
253
245
if (puglview->motionFunc) {
254
NSPoint loc = [event locationInWindow];
246
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
255
247
puglview->motionFunc(puglview, loc.x, puglview->height - loc.y);
259
251
- (void) mouseDown:(NSEvent*)event
261
253
if (puglview->mouseFunc) {
262
NSPoint loc = [event locationInWindow];
254
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
263
255
puglview->mods = getModifiers(puglview, event);
264
256
puglview->mouseFunc(puglview, 1, true, loc.x, puglview->height - loc.y);
268
260
- (void) mouseUp:(NSEvent*)event
270
262
if (puglview->mouseFunc) {
271
NSPoint loc = [event locationInWindow];
263
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
272
264
puglview->mods = getModifiers(puglview, event);
273
265
puglview->mouseFunc(puglview, 1, false, loc.x, puglview->height - loc.y);
278
270
- (void) rightMouseDown:(NSEvent*)event
280
272
if (puglview->mouseFunc) {
281
NSPoint loc = [event locationInWindow];
273
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
282
274
puglview->mods = getModifiers(puglview, event);
283
275
puglview->mouseFunc(puglview, 3, true, loc.x, puglview->height - loc.y);
287
279
- (void) rightMouseUp:(NSEvent*)event
289
281
if (puglview->mouseFunc) {
290
NSPoint loc = [event locationInWindow];
282
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
291
283
puglview->mods = getModifiers(puglview, event);
292
284
puglview->mouseFunc(puglview, 3, false, loc.x, puglview->height - loc.y);
296
288
- (void) scrollWheel:(NSEvent*)event
298
290
if (puglview->scrollFunc) {
299
NSPoint loc = [event locationInWindow];
291
NSPoint loc = [self convertPoint:[event locationInWindow] fromView:nil];
300
292
puglview->mods = getModifiers(puglview, event);
301
293
puglview->scrollFunc(puglview, loc.x, puglview->height - loc.y, [event deltaX], [event deltaY]);
363
357
view->impl = impl;
364
358
view->width = width;
365
359
view->height = height;
361
view->user_resizable = resizable; // unused
367
363
[NSAutoreleasePool new];
368
364
[NSApplication sharedApplication];
370
NSString* titleString = [[NSString alloc]
373
encoding:NSUTF8StringEncoding];
375
id window = [[RobTKPuglWindow new]retain];
377
[window setPuglview:view];
378
[window setTitle:titleString];
380
impl->glview = [RobTKPuglOpenGLView new];
381
impl->window = window;
366
impl->glview = [RobTKPuglOpenGLView new];
382
367
impl->glview->puglview = view;
384
[window setContentView:impl->glview];
385
[NSApp activateIgnoringOtherApps:YES];
386
[window makeFirstResponder:impl->glview];
388
[window makeKeyAndOrderFront:window];
391
[window setIsVisible:NO];
370
NSView* pview = (NSView*) parent;
371
[pview addSubview:impl->glview];
372
[impl->glview setHidden:NO];
374
NSString* titleString = [[NSString alloc]
377
encoding:NSUTF8StringEncoding];
378
id window = [[RobTKPuglWindow new]retain];
379
[window setPuglview:view];
380
[window setTitle:titleString];
381
[window setContentMinSize:NSMakeSize(min_width, min_height)];
383
[window setLevel: CGShieldingWindowLevel() + 1];
385
impl->window = window;
388
[impl->glview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
391
[window setContentView:impl->glview];
392
[NSApp activateIgnoringOtherApps:YES];
393
[window makeFirstResponder:impl->glview];
394
[window makeKeyAndOrderFront:window];
398
400
puglDestroy(PuglView* view)
400
402
view->impl->glview->puglview = NULL;
401
[view->impl->window close];
403
[view->impl->glview removeFromSuperview];
404
if (view->impl->window) {
405
[view->impl->window close];
402
407
[view->impl->glview release];
403
[view->impl->window release];
408
if (view->impl->window) {
409
[view->impl->window release];
404
411
free(view->impl);
411
418
[view->impl->glview setNeedsDisplay: YES];
414
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
418
event = [view->impl->window
419
nextEventMatchingMask:NSAnyEventMask
420
untilDate:[NSDate distantPast]
421
inMode:NSDefaultRunLoopMode
427
[view->impl->window sendEvent: event];
433
420
return PUGL_SUCCESS;