~ubuntu-branches/debian/sid/x42-plugins/sid

« back to all changes in this revision

Viewing changes to robtk/pugl/pugl_osx.m

  • Committer: Package Import Robot
  • Author(s): Jaromír Mikeš
  • Date: 2015-03-23 18:26:21 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20150323182621-bxlw3w09u72u4ned
Tags: 20141101-1
* Imported Upstream version 20141101
* Bump Standards.
* Patch refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "pugl_internal.h"
26
26
 
 
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)
 
32
 
27
33
__attribute__ ((visibility ("hidden")))
28
34
@interface RobTKPuglWindow : NSWindow
29
35
{
55
61
                                              backing:NSBackingStoreBuffered defer:NO];
56
62
 
57
63
        [result setAcceptsMouseMovedEvents:YES];
58
 
        [result setLevel: CGShieldingWindowLevel() + 1];
59
 
 
60
 
        return result;
 
64
        return (RobTKPuglWindow *)result;
61
65
}
62
66
 
63
67
- (void)setPuglview:(PuglView*)view
96
100
__attribute__ ((visibility ("hidden")))
97
101
@interface RobTKPuglOpenGLView : NSOpenGLView
98
102
{
99
 
        int colorBits;
100
 
        int depthBits;
101
103
@public
102
104
        PuglView* puglview;
103
105
 
104
106
        NSTrackingArea* trackingArea;
105
107
}
106
108
 
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
126
126
 
127
127
- (id) initWithFrame:(NSRect)frame
128
 
           colorBits:(int)numColorBits
129
 
           depthBits:(int)numDepthBits
130
128
{
131
 
        colorBits = numColorBits;
132
 
        depthBits = numDepthBits;
133
 
 
134
129
        NSOpenGLPixelFormatAttribute pixelAttribs[16] = {
135
130
                NSOpenGLPFADoubleBuffer,
136
131
                NSOpenGLPFAAccelerated,
137
 
                NSOpenGLPFAColorSize,
138
 
                colorBits,
139
 
                NSOpenGLPFADepthSize,
140
 
                depthBits,
 
132
                NSOpenGLPFAColorSize, 32,
 
133
                NSOpenGLPFADepthSize, 32,
141
134
                0
142
135
        };
143
 
 
144
136
        NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc]
145
137
                              initWithAttributes:pixelAttribs];
146
138
 
147
139
        if (pixelFormat) {
148
140
                self = [super initWithFrame:frame pixelFormat:pixelFormat];
149
141
                [pixelFormat release];
150
 
                if (self) {
151
 
                        [[self openGLContext] makeCurrentContext];
152
 
                        [self reshape];
153
 
                }
154
142
        } else {
155
 
                self = nil;
 
143
                self = [super initWithFrame:frame];
156
144
        }
157
145
 
 
146
        if (self) {
 
147
                [[self openGLContext] makeCurrentContext];
 
148
                [self reshape];
 
149
        }
158
150
        return self;
159
151
}
160
152
 
233
225
- (void) mouseMoved:(NSEvent*)event
234
226
{
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);
239
231
        }
242
234
- (void) mouseDragged:(NSEvent*)event
243
235
{
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);
248
240
        }
251
243
- (void) rightMouseDragged:(NSEvent*)event
252
244
{
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);
256
248
        }
257
249
}
259
251
- (void) mouseDown:(NSEvent*)event
260
252
{
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);
265
257
        }
268
260
- (void) mouseUp:(NSEvent*)event
269
261
{
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);
274
266
        }
278
270
- (void) rightMouseDown:(NSEvent*)event
279
271
{
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);
284
276
        }
287
279
- (void) rightMouseUp:(NSEvent*)event
288
280
{
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);
293
285
        }
296
288
- (void) scrollWheel:(NSEvent*)event
297
289
{
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]);
302
294
        }
352
344
           int              min_height,
353
345
           int              width,
354
346
           int              height,
355
 
           bool             resizable)
 
347
           bool             resizable,
 
348
           bool             ontop,
 
349
           unsigned long    transientId)
356
350
{
357
351
        PuglView*      view = (PuglView*)calloc(1, sizeof(PuglView));
358
352
        PuglInternals* impl = (PuglInternals*)calloc(1, sizeof(PuglInternals));
363
357
        view->impl   = impl;
364
358
        view->width  = width;
365
359
        view->height = height;
 
360
        view->ontop  = ontop;
 
361
        view->user_resizable = resizable; // unused
366
362
 
367
363
        [NSAutoreleasePool new];
368
364
        [NSApplication sharedApplication];
369
365
 
370
 
        NSString* titleString = [[NSString alloc]
371
 
                                        initWithBytes:title
372
 
                                               length:strlen(title)
373
 
                                             encoding:NSUTF8StringEncoding];
374
 
 
375
 
        id window = [[RobTKPuglWindow new]retain];
376
 
 
377
 
        [window setPuglview:view];
378
 
        [window setTitle:titleString];
379
 
 
380
 
        impl->glview     = [RobTKPuglOpenGLView new];
381
 
        impl->window     = window;
 
366
        impl->glview = [RobTKPuglOpenGLView new];
382
367
        impl->glview->puglview = view;
383
368
 
384
 
        [window setContentView:impl->glview];
385
 
        [NSApp activateIgnoringOtherApps:YES];
386
 
        [window makeFirstResponder:impl->glview];
387
 
 
388
 
        [window makeKeyAndOrderFront:window];
389
 
 
390
 
        if (!parent) {
391
 
                [window setIsVisible:NO];
 
369
        if (parent) {
 
370
                NSView* pview = (NSView*) parent;
 
371
                [pview addSubview:impl->glview];
 
372
                [impl->glview setHidden:NO];
 
373
        } else {
 
374
                NSString* titleString = [[NSString alloc]
 
375
                        initWithBytes:title
 
376
                               length:strlen(title)
 
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)];
 
382
                if (ontop) {
 
383
                        [window setLevel: CGShieldingWindowLevel() + 1];
 
384
                }
 
385
                impl->window = window;
 
386
#if 0
 
387
                if (resizable) {
 
388
                        [impl->glview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
 
389
                }
 
390
#endif
 
391
                [window setContentView:impl->glview];
 
392
                [NSApp activateIgnoringOtherApps:YES];
 
393
                [window makeFirstResponder:impl->glview];
 
394
                [window makeKeyAndOrderFront:window];
392
395
        }
393
 
 
394
396
        return view;
395
397
}
396
398
 
398
400
puglDestroy(PuglView* view)
399
401
{
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];
 
406
        }
402
407
        [view->impl->glview release];
403
 
        [view->impl->window release];
 
408
        if (view->impl->window) {
 
409
                [view->impl->window release];
 
410
        }
404
411
        free(view->impl);
405
412
        free(view);
406
413
}
410
417
{
411
418
        [view->impl->glview setNeedsDisplay: YES];
412
419
 
413
 
#if 0
414
 
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
415
 
        NSEvent* event;
416
 
 
417
 
        for (;;) {
418
 
                event = [view->impl->window
419
 
                           nextEventMatchingMask:NSAnyEventMask
420
 
                                       untilDate:[NSDate distantPast]
421
 
                                          inMode:NSDefaultRunLoopMode
422
 
                                         dequeue:YES];
423
 
 
424
 
                if (event == nil)
425
 
                        break;
426
 
 
427
 
                [view->impl->window sendEvent: event];
428
 
        }
429
 
 
430
 
        [pool release];
431
 
#endif
432
 
 
433
420
        return PUGL_SUCCESS;
434
421
}
435
422
 
467
454
puglPostRedisplay(PuglView* view)
468
455
{
469
456
        //view->redisplay = true; // unused
 
457
        [view->impl->glview setNeedsDisplay: YES];
470
458
}
471
459
 
472
460
PuglNativeWindow