2 * consumer_sdl_osx.m -- An OS X compatibility shim for SDL
\r
3 * Copyright (C) 2010 Ushodaya Enterprises Limited
\r
4 * Author: Dan Dennedy
\r
6 * This library is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU Lesser General Public
\r
8 * License as published by the Free Software Foundation; either
\r
9 * version 2.1 of the License, or (at your option) any later version.
\r
11 * This library is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
14 * Lesser General Public License for more details.
\r
16 * You should have received a copy of the GNU Lesser General Public
\r
17 * License along with this library; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
21 #import <Cocoa/Cocoa.h>
\r
23 void* mlt_cocoa_autorelease_init()
\r
25 return [[NSAutoreleasePool alloc] init];
\r
28 void mlt_cocoa_autorelease_close( void* p )
\r
30 NSAutoreleasePool* pool = ( NSAutoreleasePool* ) p;
\r
35 /* The code below is not used at this time - could not get it to work, but
\r
36 * it is based on code from gruntster on the avidemux project team.
\r
39 #import <Carbon/Carbon.h>
\r
41 static NSWindow* nsWindow = nil;
\r
42 static NSQuickDrawView* nsView = nil;
\r
44 void sdl_cocoa_init(void* parent, int x, int y, int width, int height)
\r
47 contentRect = NSMakeRect(x, y, width, height);
\r
51 // initWithWindowRef always returns the same result for the same WindowRef
\r
52 nsWindow = [[NSWindow alloc] initWithWindowRef:(WindowRef)parent];
\r
53 [nsWindow setContentView:[[[NSView alloc] initWithFrame:contentRect] autorelease]];
\r
58 nsView = [[NSQuickDrawView alloc] initWithFrame:contentRect];
\r
59 [[nsWindow contentView] addSubview:nsView];
\r
61 [nsWindow orderOut:nil]; // very important, otherwise window won't be placed correctly on repeat showings
\r
62 [nsWindow orderFront:nil];
\r
66 [nsView setFrame:contentRect];
\r
67 [[nsWindow contentView] setFrame:contentRect];
\r
70 // finally, set SDL environment variables with all this nonsense
\r
71 char SDL_windowhack[20];
\r
72 sprintf(SDL_windowhack, "%d", (int)nsWindow);
\r
73 setenv("SDL_NSWindowPointer", SDL_windowhack, 1);
\r
74 sprintf(SDL_windowhack,"%d", (int)nsView);
\r
75 setenv("SDL_NSQuickDrawViewPointer", SDL_windowhack, 1);
\r
78 void sdl_cocoa_close(void)
\r
82 // Reference count cannot fall below 2 because SDL releases the window when closing
\r
83 // and again when reinitialising (even though this is our own window...).
\r
84 if ([nsWindow retainCount] > 2)
\r
87 // SDL takes care of all the destroying...a little too much, so make sure our Carbon
\r
88 // window is still displayed (via its Cocoa wrapper)
\r
89 [nsWindow makeKeyAndOrderFront:nil];
\r