]> git.sesse.net Git - mlt/blob - src/modules/sdl/consumer_sdl_osx.m
Fix doc error for mlt_playlist_is_blank().
[mlt] / src / modules / sdl / consumer_sdl_osx.m
1 /*\r
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
5  *\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
10  *\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
15  *\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
19  */\r
20 \r
21 #import <Cocoa/Cocoa.h>\r
22 \r
23 void* mlt_cocoa_autorelease_init()\r
24 {\r
25         return [[NSAutoreleasePool alloc] init];\r
26 }\r
27 \r
28 void mlt_cocoa_autorelease_close( void* p )\r
29 {\r
30         NSAutoreleasePool* pool = ( NSAutoreleasePool* ) p;\r
31         [pool release];\r
32 }\r
33 \r
34 #if 0\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
37  */\r
38 \r
39 #import <Carbon/Carbon.h>\r
40 \r
41 static NSWindow* nsWindow = nil;\r
42 static NSQuickDrawView* nsView = nil;\r
43 \r
44 void sdl_cocoa_init(void* parent, int x, int y, int width, int height)\r
45 {\r
46         NSRect contentRect;\r
47         contentRect = NSMakeRect(x, y, width, height);          \r
48 \r
49         if (!nsWindow)\r
50         {\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
54         }\r
55 \r
56         if (!nsView)\r
57         {\r
58                 nsView = [[NSQuickDrawView alloc] initWithFrame:contentRect];\r
59                 [[nsWindow contentView] addSubview:nsView];\r
60                 [nsView release];\r
61                 [nsWindow orderOut:nil];        // very important, otherwise window won't be placed correctly on repeat showings\r
62                 [nsWindow orderFront:nil];\r
63         }\r
64         else\r
65         {\r
66                 [nsView setFrame:contentRect];\r
67                 [[nsWindow contentView] setFrame:contentRect];\r
68         }\r
69 \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
76 }\r
77 \r
78 void sdl_cocoa_close(void)\r
79 {\r
80   if (nsWindow)\r
81   {\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
85                   [nsWindow release];\r
86 \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
90          }\r
91 }\r
92 #endif\r