Mercurial > mplayer.hg
annotate libvo/vo_macosx.m @ 25337:6a7cf06be2e8
allow osd menu being controlled by joystick
author | ben |
---|---|
date | Tue, 11 Dec 2007 21:58:42 +0000 |
parents | 48fe4b6e3bab |
children | 8368ae92c092 |
rev | line source |
---|---|
15289 | 1 /* |
2 vo_macosx.m | |
3 by Nicolas Plourde <nicolasplourde@gmail.com> | |
4 | |
5 MPlayer Mac OSX video out module. | |
6 Copyright (c) Nicolas Plourde - 2005 | |
7 */ | |
8 | |
9 #import "vo_macosx.h" | |
16385 | 10 #include <sys/types.h> |
11 #include <sys/ipc.h> | |
12 #include <sys/shm.h> | |
15289 | 13 |
14 //MPLAYER | |
15 #include "config.h" | |
16 #include "fastmemcpy.h" | |
17 #include "video_out.h" | |
18 #include "video_out_internal.h" | |
19 #include "aspect.h" | |
20 #include "mp_msg.h" | |
21 #include "m_option.h" | |
22 | |
23 #include "input/input.h" | |
24 #include "input/mouse.h" | |
25 | |
26 #include "osdep/keycodes.h" | |
27 | |
28 //Cocoa | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
29 NSDistantObject *mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
30 id <MPlayerOSXVOProto> mplayerosxProto; |
15611 | 31 MPlayerOpenGLView *mpGLView; |
15289 | 32 NSAutoreleasePool *autoreleasepool; |
33 OSType pixelFormat; | |
34 | |
16385 | 35 //shared memory |
36 int shm_id; | |
37 struct shmid_ds shm_desc; | |
38 BOOL shared_buffer = false; | |
39 | |
15728 | 40 //Screen |
41 int screen_id; | |
42 BOOL screen_force; | |
43 NSRect screen_frame; | |
44 NSScreen *screen_handle; | |
45 NSArray *screen_array; | |
15289 | 46 |
47 //image | |
48 unsigned char *image_data; | |
25180 | 49 // For double buffering |
50 static uint8_t image_page = 0; | |
51 static unsigned char *image_datas[2]; | |
52 | |
15289 | 53 static uint32_t image_width; |
54 static uint32_t image_height; | |
55 static uint32_t image_depth; | |
56 static uint32_t image_bytes; | |
57 static uint32_t image_format; | |
58 | |
59 //vo | |
60 static int isFullscreen; | |
15320 | 61 static int isOntop; |
15327 | 62 static int isRootwin; |
15289 | 63 extern float monitor_aspect; |
64 extern float movie_aspect; | |
65 static float old_movie_aspect; | |
66 | |
15731 | 67 static float winAlpha = 1; |
15289 | 68 static int int_pause = 0; |
69 | |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
70 static BOOL isLeopardOrLater; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
71 |
15289 | 72 static vo_info_t info = |
73 { | |
74 "Mac OSX Core Video", | |
75 "macosx", | |
76 "Nicolas Plourde <nicolas.plourde@gmail.com>", | |
77 "" | |
78 }; | |
79 | |
80 LIBVO_EXTERN(macosx) | |
81 | |
82 extern void mplayer_put_key(int code); | |
83 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)); | |
84 | |
85 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
86 { | |
87 switch (image_format) | |
88 { | |
89 case IMGFMT_RGB32: | |
90 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width); | |
91 break; | |
92 case IMGFMT_YUY2: | |
93 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | |
94 break; | |
95 } | |
96 } | |
97 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
98 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
15289 | 99 { |
16385 | 100 |
15728 | 101 //init screen |
102 screen_array = [NSScreen screens]; | |
103 if(screen_id < [screen_array count]) | |
15289 | 104 { |
15728 | 105 screen_handle = [screen_array objectAtIndex:screen_id]; |
15289 | 106 } |
15728 | 107 else |
108 { | |
109 mp_msg(MSGT_VO, MSGL_FATAL, "Get device error: Device ID %d do not exist, falling back to main device.\n", screen_id); | |
110 screen_handle = [screen_array objectAtIndex:0]; | |
111 screen_id = 0; | |
112 } | |
113 screen_frame = [screen_handle frame]; | |
16385 | 114 |
15289 | 115 //misc mplayer setup |
116 image_width = width; | |
117 image_height = height; | |
118 switch (image_format) | |
119 { | |
120 case IMGFMT_BGR32: | |
121 case IMGFMT_RGB32: | |
122 image_depth = 32; | |
123 break; | |
16385 | 124 case IMGFMT_YUY2: |
15289 | 125 image_depth = 16; |
126 break; | |
127 } | |
128 image_bytes = (image_depth + 7) / 8; | |
16385 | 129 |
130 if(!shared_buffer) | |
131 { | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
132 image_data = malloc(image_width*image_height*image_bytes); |
25180 | 133 image_datas[0] = image_data; |
134 if (vo_doublebuffering) | |
135 image_datas[1] = malloc(image_width*image_height*image_bytes); | |
136 image_page = 0; | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
137 |
16385 | 138 monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; |
139 | |
140 //set aspect | |
141 panscan_init(); | |
142 aspect_save_orig(width,height); | |
143 aspect_save_prescale(d_width,d_height); | |
144 aspect_save_screenres(screen_frame.size.width, screen_frame.size.height); | |
145 aspect((int *)&d_width,(int *)&d_height,A_NOZOOM); | |
146 | |
147 movie_aspect = (float)d_width/(float)d_height; | |
148 old_movie_aspect = movie_aspect; | |
15726 | 149 |
16385 | 150 vo_fs = flags & VOFLAG_FULLSCREEN; |
151 | |
152 //config OpenGL View | |
153 [mpGLView config]; | |
154 [mpGLView reshape]; | |
155 } | |
156 else | |
157 { | |
158 movie_aspect = (float)d_width/(float)d_height; | |
159 | |
160 shm_id = shmget(9849, image_width*image_height*image_bytes, IPC_CREAT | 0666); | |
161 if (shm_id == -1) | |
162 { | |
163 perror("vo_mplayer shmget: "); | |
164 return 1; | |
165 } | |
166 | |
167 image_data = shmat(shm_id, NULL, 0); | |
168 if (!image_data) | |
169 { | |
170 perror("vo_mplayer shmat: "); | |
171 return 1; | |
172 } | |
173 | |
174 //connnect to mplayerosx | |
175 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil]; | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
176 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
177 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
178 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
179 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
180 } |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
181 else { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
182 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
183 mplayerosxProxy = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
184 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
185 } |
16385 | 186 } |
15289 | 187 return 0; |
188 } | |
189 | |
190 static void check_events(void) | |
191 { | |
15611 | 192 [mpGLView check_events]; |
15289 | 193 } |
194 | |
195 static void draw_osd(void) | |
196 { | |
197 vo_draw_text(image_width, image_height, draw_alpha); | |
198 } | |
199 | |
200 static void flip_page(void) | |
201 { | |
16385 | 202 if(shared_buffer) |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
203 [mplayerosxProto render]; |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
204 else { |
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
205 [mpGLView setCurrentTexture]; |
16385 | 206 [mpGLView render]; |
25180 | 207 if (vo_doublebuffering) { |
208 image_page = 1 - image_page; | |
209 image_data = image_datas[image_page]; | |
210 } | |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
211 } |
15289 | 212 } |
213 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
214 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
15289 | 215 { |
216 return 0; | |
217 } | |
218 | |
219 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
220 static int draw_frame(uint8_t *src[]) |
15289 | 221 { |
222 switch (image_format) | |
223 { | |
224 case IMGFMT_BGR32: | |
225 case IMGFMT_RGB32: | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
226 fast_memcpy(image_data, src[0], image_width*image_height*image_bytes); |
15289 | 227 break; |
228 | |
229 case IMGFMT_YUY2: | |
230 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2); | |
231 break; | |
232 } | |
16385 | 233 |
15289 | 234 return 0; |
235 } | |
236 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
237 static int query_format(uint32_t format) |
15289 | 238 { |
239 image_format = format; | |
240 | |
241 switch(format) | |
242 { | |
243 case IMGFMT_YUY2: | |
244 pixelFormat = kYUVSPixelFormat; | |
245 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
246 | |
247 case IMGFMT_RGB32: | |
248 case IMGFMT_BGR32: | |
249 pixelFormat = k32ARGBPixelFormat; | |
250 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
251 } | |
252 return 0; | |
253 } | |
254 | |
255 static void uninit(void) | |
256 { | |
16385 | 257 if(shared_buffer) |
258 { | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
259 [mplayerosxProto stop]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
260 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
261 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
262 mplayerosxProxy = nil; |
16385 | 263 |
264 if (shmdt(image_data) == -1) | |
265 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmdt failed\n"); | |
266 | |
267 if (shmctl(shm_id, IPC_RMID, &shm_desc) == -1) | |
268 mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmctl failed\n"); | |
269 } | |
270 | |
21551 | 271 SetSystemUIMode( kUIModeNormal, 0); |
272 CGDisplayShowCursor(kCGDirectMainDisplay); | |
273 | |
274 if(mpGLView) | |
275 { | |
25136 | 276 NSAutoreleasePool *finalPool; |
24742
0bef706332b5
Fix deallocate bug which sometimes causes a crash when reinitializing.
nplourde
parents:
24698
diff
changeset
|
277 mpGLView = nil; |
21551 | 278 [autoreleasepool release]; |
25136 | 279 finalPool = [[NSAutoreleasePool alloc] init]; |
25078
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
280 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; |
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
281 [finalPool release]; |
21551 | 282 } |
25121 | 283 if (!shared_buffer) |
284 { | |
25180 | 285 free(image_datas[0]); |
286 if (vo_doublebuffering) | |
287 free(image_datas[1]); | |
288 image_datas[0] = NULL; | |
289 image_datas[1] = NULL; | |
25121 | 290 image_data = NULL; |
291 } | |
15289 | 292 } |
293 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
294 static int preinit(const char *arg) |
15289 | 295 { |
296 int parse_err = 0; | |
297 | |
15728 | 298 if(arg) |
299 { | |
300 char *parse_pos = (char *)&arg[0]; | |
301 while (parse_pos[0] && !parse_err) | |
302 { | |
303 if (strncmp (parse_pos, "device_id=", 10) == 0) | |
304 { | |
305 parse_pos = &parse_pos[10]; | |
306 screen_id = strtol(parse_pos, &parse_pos, 0); | |
307 screen_force = YES; | |
308 } | |
16385 | 309 if (strncmp (parse_pos, "shared_buffer", 13) == 0) |
310 { | |
311 parse_pos = &parse_pos[13]; | |
312 shared_buffer = YES; | |
313 } | |
15728 | 314 if (parse_pos[0] == ':') parse_pos = &parse_pos[1]; |
315 else if (parse_pos[0]) parse_err = 1; | |
316 } | |
317 } | |
318 | |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
319 NSApplicationLoad(); |
15289 | 320 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
15737
0c3939433cef
set nsapp and setup cocoa with NSApplicationLoad
nplourde
parents:
15736
diff
changeset
|
321 NSApp = [NSApplication sharedApplication]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
322 isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; |
15726 | 323 |
16385 | 324 if(!shared_buffer) |
16144 | 325 { |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
326 #if !defined (MACOSX_FINDER_SUPPORT) || !defined (HAVE_SDL) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
327 //this chunk of code is heavily based off SDL_macosx.m from SDL |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
328 //it uses an Apple private function to request foreground operation |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
329 void CPSEnableForegroundOperation(ProcessSerialNumber* psn); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
330 ProcessSerialNumber myProc, frProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
331 Boolean sameProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
332 |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
333 if (GetFrontProcess(&frProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
334 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
335 if (GetCurrentProcess(&myProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
336 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
337 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
338 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
339 CPSEnableForegroundOperation(&myProc); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
340 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
341 SetFrontProcess(&myProc); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
342 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
343 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
344 #endif |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
345 |
16385 | 346 if(!mpGLView) |
347 { | |
348 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
349 [mpGLView autorelease]; | |
350 } | |
351 | |
352 [mpGLView display]; | |
353 [mpGLView preinit]; | |
16144 | 354 } |
355 | |
15289 | 356 return 0; |
357 } | |
358 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
359 static int control(uint32_t request, void *data, ...) |
15289 | 360 { |
361 switch (request) | |
362 { | |
363 case VOCTRL_PAUSE: return (int_pause=1); | |
364 case VOCTRL_RESUME: return (int_pause=0); | |
365 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
366 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
15611 | 367 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
368 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; |
15289 | 369 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
15611 | 370 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
15289 | 371 } |
372 return VO_NOTIMPL; | |
373 } | |
374 | |
375 ////////////////////////////////////////////////////////////////////////// | |
376 // NSOpenGLView Subclass | |
377 ////////////////////////////////////////////////////////////////////////// | |
15611 | 378 @implementation MPlayerOpenGLView |
24076 | 379 - (void) preinit |
15289 | 380 { |
15726 | 381 //init menu |
382 [self initMenu]; | |
383 | |
384 //create window | |
15747
fbf14e1ab725
osx 10.3 dont like to have a window init with no size
nplourde
parents:
15737
diff
changeset
|
385 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) |
15726 | 386 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask |
387 backing:NSBackingStoreBuffered defer:NO]; | |
388 | |
16144 | 389 [window autorelease]; |
15726 | 390 [window setDelegate:mpGLView]; |
391 [window setContentView:mpGLView]; | |
392 [window setInitialFirstResponder:mpGLView]; | |
393 [window setAcceptsMouseMovedEvents:YES]; | |
394 [window setTitle:@"MPlayer - The Movie Player"]; | |
395 | |
396 isFullscreen = 0; | |
15855 | 397 winSizeMult = 1; |
15726 | 398 } |
399 | |
24076 | 400 - (void) config |
15726 | 401 { |
402 uint32_t d_width; | |
403 uint32_t d_height; | |
404 | |
25137 | 405 GLint swapInterval = 1; |
15726 | 406 |
407 NSRect frame; | |
15289 | 408 CVReturn error = kCVReturnSuccess; |
409 | |
15728 | 410 //config window |
15726 | 411 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); |
412 frame = NSMakeRect(0, 0, d_width, d_height); | |
413 [window setContentSize: frame.size]; | |
15570 | 414 |
15289 | 415 //create OpenGL Context |
416 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; | |
15647 | 417 |
15289 | 418 [self setOpenGLContext:glContext]; |
15647 | 419 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
15289 | 420 [glContext setView:self]; |
421 [glContext makeCurrentContext]; | |
422 | |
25180 | 423 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); |
15289 | 424 if(error != kCVReturnSuccess) |
425 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Buffer(%d)\n", error); | |
25180 | 426 if (vo_doublebuffering) { |
427 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); | |
428 if(error != kCVReturnSuccess) | |
429 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create Pixel Double Buffer(%d)\n", error); | |
430 } | |
15289 | 431 |
432 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); | |
433 if(error != kCVReturnSuccess) | |
434 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture Cache(%d)\n", error); | |
435 | |
25180 | 436 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 437 if(error != kCVReturnSuccess) |
438 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
439 | |
15728 | 440 //show window |
441 [window center]; | |
442 [window makeKeyAndOrderFront:mpGLView]; | |
443 | |
15726 | 444 if(vo_rootwin) |
445 [mpGLView rootwin]; | |
446 | |
447 if(vo_fs) | |
448 [mpGLView fullscreen: NO]; | |
449 | |
450 if(vo_ontop) | |
451 [mpGLView ontop]; | |
15289 | 452 } |
453 | |
454 /* | |
15570 | 455 Init Menu |
456 */ | |
457 - (void)initMenu | |
458 { | |
21395 | 459 NSMenu *menu, *aspectMenu; |
15570 | 460 NSMenuItem *menuItem; |
461 | |
462 [NSApp setMainMenu:[[NSMenu alloc] init]]; | |
463 | |
464 //Create Movie Menu | |
465 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
466 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
467 kHalfScreenCmd = menuItem; | |
468 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
469 kNormalScreenCmd = menuItem; | |
470 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
471 kDoubleScreenCmd = menuItem; | |
472 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
473 kFullScreenCmd = menuItem; | |
15909 | 474 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
15570 | 475 |
476 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; | |
477 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
478 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
479 kKeepAspectCmd = menuItem; | |
480 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
481 if(vo_panscan) [menuItem setState:NSOnState]; | |
482 kPanScanCmd = menuItem; | |
15909 | 483 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem]; |
15570 | 484 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
485 kAspectOrgCmd = menuItem; | |
486 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
487 kAspectFullCmd = menuItem; | |
488 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
489 kAspectWideCmd = menuItem; | |
490 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
491 [menuItem setSubmenu:aspectMenu]; | |
492 [menu addItem:menuItem]; | |
493 [aspectMenu release]; | |
494 | |
495 //Add to menubar | |
496 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
497 [menuItem setSubmenu:menu]; | |
498 [[NSApp mainMenu] addItem:menuItem]; | |
499 | |
500 //Create Window Menu | |
501 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
502 | |
503 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; | |
504 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
505 | |
506 //Add to menubar | |
507 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
508 [menuItem setSubmenu:menu]; | |
509 [[NSApp mainMenu] addItem:menuItem]; | |
510 [NSApp setWindowsMenu:menu]; | |
511 | |
512 [menu release]; | |
513 [menuItem release]; | |
514 } | |
515 | |
516 /* | |
517 Menu Action | |
518 */ | |
519 - (void)menuAction:(id)sender | |
520 { | |
521 uint32_t d_width; | |
522 uint32_t d_height; | |
523 NSRect frame; | |
524 | |
525 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | |
15731 | 526 |
527 if(sender == kQuitCmd) | |
528 { | |
529 mplayer_put_key(KEY_ESC); | |
530 } | |
15570 | 531 |
532 if(sender == kHalfScreenCmd) | |
533 { | |
534 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
535 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 536 } |
537 | |
15855 | 538 winSizeMult = 0.5; |
539 frame.size.width = (d_width*winSizeMult); | |
540 frame.size.height = ((d_width/movie_aspect)*winSizeMult); | |
15570 | 541 [window setContentSize: frame.size]; |
542 [self reshape]; | |
543 } | |
544 if(sender == kNormalScreenCmd) | |
545 { | |
546 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
547 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 548 } |
549 | |
15855 | 550 winSizeMult = 1; |
15570 | 551 frame.size.width = d_width; |
552 frame.size.height = d_width/movie_aspect; | |
553 [window setContentSize: frame.size]; | |
554 [self reshape]; | |
555 } | |
556 if(sender == kDoubleScreenCmd) | |
557 { | |
558 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
559 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 560 } |
561 | |
15855 | 562 winSizeMult = 2; |
563 frame.size.width = d_width*winSizeMult; | |
564 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
15570 | 565 [window setContentSize: frame.size]; |
566 [self reshape]; | |
567 } | |
568 if(sender == kFullScreenCmd) | |
569 { | |
570 vo_fs = (!(vo_fs)); | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
571 [self fullscreen:NO]; |
15570 | 572 } |
573 | |
574 if(sender == kKeepAspectCmd) | |
575 { | |
576 vo_keepaspect = (!(vo_keepaspect)); | |
577 if(vo_keepaspect) | |
578 [kKeepAspectCmd setState:NSOnState]; | |
579 else | |
580 [kKeepAspectCmd setState:NSOffState]; | |
15909 | 581 |
582 [self reshape]; | |
15570 | 583 } |
584 | |
585 if(sender == kPanScanCmd) | |
586 { | |
587 vo_panscan = (!(vo_panscan)); | |
588 if(vo_panscan) | |
589 [kPanScanCmd setState:NSOnState]; | |
590 else | |
591 [kPanScanCmd setState:NSOffState]; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
592 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
593 [self panscan]; |
15570 | 594 } |
595 | |
596 if(sender == kAspectOrgCmd) | |
597 { | |
598 movie_aspect = old_movie_aspect; | |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
599 |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
600 if(isFullscreen) |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
601 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
602 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
603 } |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
604 else |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
605 { |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
606 frame.size.width = d_width*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
607 frame.size.height = (d_width/movie_aspect)*winSizeMult; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
608 [window setContentSize: frame.size]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
609 [self reshape]; |
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
610 } |
15570 | 611 } |
612 | |
613 if(sender == kAspectFullCmd) | |
614 { | |
615 movie_aspect = 4.0f/3.0f; | |
15882 | 616 |
617 if(isFullscreen) | |
618 { | |
619 [self reshape]; | |
620 } | |
621 else | |
622 { | |
623 frame.size.width = d_width*winSizeMult; | |
624 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
625 [window setContentSize: frame.size]; | |
626 [self reshape]; | |
627 } | |
15570 | 628 } |
629 | |
630 if(sender == kAspectWideCmd) | |
631 { | |
632 movie_aspect = 16.0f/9.0f; | |
15882 | 633 |
634 if(isFullscreen) | |
635 { | |
636 [self reshape]; | |
637 } | |
638 else | |
639 { | |
640 frame.size.width = d_width*winSizeMult; | |
641 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
642 [window setContentSize: frame.size]; | |
643 [self reshape]; | |
644 } | |
15570 | 645 } |
646 } | |
647 | |
648 /* | |
15289 | 649 Setup OpenGL |
650 */ | |
651 - (void)prepareOpenGL | |
652 { | |
15339 | 653 glEnable(GL_BLEND); |
15289 | 654 glDisable(GL_DEPTH_TEST); |
655 glDepthMask(GL_FALSE); | |
656 glDisable(GL_CULL_FACE); | |
657 [self reshape]; | |
658 } | |
659 | |
660 /* | |
661 reshape OpenGL viewport | |
662 */ | |
663 - (void)reshape | |
664 { | |
665 uint32_t d_width; | |
666 uint32_t d_height; | |
667 float aspectX; | |
668 float aspectY; | |
669 int padding = 0; | |
670 | |
671 NSRect frame = [self frame]; | |
672 | |
673 glViewport(0, 0, frame.size.width, frame.size.height); | |
674 glMatrixMode(GL_PROJECTION); | |
675 glLoadIdentity(); | |
676 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
677 glMatrixMode(GL_MODELVIEW); | |
678 glLoadIdentity(); | |
679 | |
15729 | 680 //set texture frame |
15289 | 681 if(vo_keepaspect) |
682 { | |
15571 | 683 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); |
15289 | 684 d_height = ((float)d_width/movie_aspect); |
685 | |
686 aspectX = (float)((float)frame.size.width/(float)d_width); | |
687 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
688 | |
689 if((d_height*aspectX)>(frame.size.height)) | |
690 { | |
691 padding = (frame.size.width - d_width*aspectY)/2; | |
15729 | 692 textureFrame = NSMakeRect(padding, 0, d_width*aspectY+padding, d_height*aspectY); |
15289 | 693 } |
694 else | |
695 { | |
696 padding = ((frame.size.height) - d_height*aspectX)/2; | |
15729 | 697 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX+padding); |
15289 | 698 } |
699 } | |
700 else | |
701 { | |
15729 | 702 textureFrame = frame; |
15289 | 703 } |
704 } | |
705 | |
706 /* | |
707 Render frame | |
708 */ | |
709 - (void) render | |
710 { | |
21395 | 711 int curTime; |
24953
aca7d0259d90
Fix the prevent system idle code. Original code also works, but not as expected.
ulion
parents:
24742
diff
changeset
|
712 static int lastTime = 0; |
21395 | 713 |
15289 | 714 glClear(GL_COLOR_BUFFER_BIT); |
715 | |
716 glEnable(CVOpenGLTextureGetTarget(texture)); | |
717 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
718 | |
719 glColor3f(1,1,1); | |
720 glBegin(GL_QUADS); | |
15729 | 721 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
722 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
723 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.size.height+(vo_panscan_y >> 1)); | |
724 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i( textureFrame.size.width+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 725 glEnd(); |
15339 | 726 glDisable(CVOpenGLTextureGetTarget(texture)); |
727 | |
728 //render resize box | |
729 if(!isFullscreen) | |
730 { | |
731 NSRect frame = [self frame]; | |
732 | |
733 glBegin(GL_LINES); | |
734 glColor4f(0.2, 0.2, 0.2, 0.5); | |
735 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
736 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
737 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
738 | |
739 glColor4f(0.4, 0.4, 0.4, 0.5); | |
740 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
741 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
742 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
743 | |
744 glColor4f(0.6, 0.6, 0.6, 0.5); | |
745 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
746 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
747 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
748 glEnd(); | |
749 } | |
15289 | 750 |
751 glFlush(); | |
752 | |
753 //auto hide mouse cursor and futur on-screen control? | |
15327 | 754 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 755 { |
18057 | 756 int curTime = TickCount()/60; |
757 static int lastTime = 0; | |
15289 | 758 |
759 if( ((curTime - lastTime) >= 5) || (lastTime == 0) ) | |
760 { | |
18057 | 761 CGDisplayHideCursor(kCGDirectMainDisplay); |
15289 | 762 mouseHide = YES; |
763 lastTime = curTime; | |
764 } | |
765 } | |
17546 | 766 |
17725 | 767 //update activity every 30 seconds to prevent |
17546 | 768 //screensaver from starting up. |
21395 | 769 curTime = TickCount()/60; |
18057 | 770 |
771 if( ((curTime - lastTime) >= 30) || (lastTime == 0) ) | |
17546 | 772 { |
773 UpdateSystemActivity(UsrActivity); | |
774 lastTime = curTime; | |
775 } | |
15289 | 776 } |
777 | |
778 /* | |
779 Create OpenGL texture from current frame & set texco | |
780 */ | |
781 - (void) setCurrentTexture | |
782 { | |
783 CVReturn error = kCVReturnSuccess; | |
784 | |
25180 | 785 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 786 if(error != kCVReturnSuccess) |
787 mp_msg(MSGT_VO, MSGL_ERR,"Failed to create OpenGL texture(%d)\n", error); | |
788 | |
789 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
790 } | |
791 | |
792 /* | |
793 redraw win rect | |
794 */ | |
795 - (void) drawRect: (NSRect *) bounds | |
796 { | |
797 [self render]; | |
798 } | |
799 | |
800 /* | |
801 Toggle Fullscreen | |
802 */ | |
803 - (void) fullscreen: (BOOL) animate | |
804 { | |
805 static NSRect old_frame; | |
806 static NSRect old_view_frame; | |
15728 | 807 |
808 if(screen_force) | |
809 screen_frame = [screen_handle frame]; | |
810 else | |
811 screen_frame = [[window screen] frame]; | |
15289 | 812 |
15573 | 813 panscan_calc(); |
814 | |
15289 | 815 //go fullscreen |
816 if(vo_fs) | |
817 { | |
15327 | 818 if(!isRootwin) |
819 { | |
15882 | 820 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
18057 | 821 CGDisplayHideCursor(kCGDirectMainDisplay); |
15327 | 822 mouseHide = YES; |
823 } | |
15289 | 824 |
825 old_frame = [window frame]; //save main window size & position | |
15728 | 826 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 827 old_view_frame = [self bounds]; |
828 | |
829 //fix origin for multi screen setup | |
15728 | 830 screen_frame.origin.x = 0; |
831 screen_frame.origin.y = 0; | |
832 [self setFrame:screen_frame]; | |
15289 | 833 [self setNeedsDisplay:YES]; |
834 [window setHasShadow:NO]; | |
835 isFullscreen = 1; | |
836 } | |
837 else | |
15882 | 838 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
839 SetSystemUIMode( kUIModeNormal, 0); |
15882 | 840 |
15289 | 841 isFullscreen = 0; |
18057 | 842 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 843 mouseHide = NO; |
844 | |
845 //revert window to previous setting | |
846 [self setFrame:old_view_frame]; | |
847 [self setNeedsDisplay:YES]; | |
16081
72c352edce8f
restore window shadow when quitting fullscreen mode
nplourde
parents:
15909
diff
changeset
|
848 [window setHasShadow:YES]; |
15289 | 849 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx |
850 } | |
851 } | |
852 | |
853 /* | |
854 Toggle ontop | |
855 */ | |
856 - (void) ontop | |
857 { | |
15320 | 858 if(vo_ontop) |
859 { | |
860 [window setLevel:NSScreenSaverWindowLevel]; | |
861 isOntop = YES; | |
862 } | |
863 else | |
864 { | |
865 [window setLevel:NSNormalWindowLevel]; | |
866 isOntop = NO; | |
867 } | |
15289 | 868 } |
869 | |
870 /* | |
871 Toggle panscan | |
872 */ | |
873 - (void) panscan | |
874 { | |
15331 | 875 panscan_calc(); |
15289 | 876 } |
877 | |
878 /* | |
15327 | 879 Toggle rootwin |
880 */ | |
881 - (void) rootwin | |
882 { | |
883 if(vo_rootwin) | |
884 { | |
885 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
886 [window orderBack:self]; | |
887 isRootwin = YES; | |
888 } | |
889 else | |
890 { | |
891 [window setLevel:NSNormalWindowLevel]; | |
892 isRootwin = NO; | |
893 } | |
894 } | |
895 | |
896 /* | |
15289 | 897 Check event for new event |
898 */ | |
899 - (void) check_events | |
900 { | |
901 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
25178 | 902 if (event == nil) |
903 return; | |
15289 | 904 [NSApp sendEvent:event]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
905 // Without SDL's bootstrap code (include SDL.h in mplayer.c), |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
906 // on Leopard, we got trouble to get the play window auto focused |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
907 // when app is actived. Following code fix this problem. |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
908 #ifndef HAVE_SDL |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
909 if (isLeopardOrLater && [event type] == NSAppKitDefined |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
910 && [event subtype] == NSApplicationActivatedEventType) { |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
911 [window makeMainWindow]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
912 [window makeKeyAndOrderFront:mpGLView]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
913 } |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
914 #endif |
15289 | 915 } |
916 | |
917 /* | |
15731 | 918 From NSView, respond to key equivalents. |
919 */ | |
920 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
921 { | |
922 switch([theEvent keyCode]) | |
923 { | |
924 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
925 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
926 } | |
927 return NO; | |
928 } | |
929 | |
930 /* | |
15289 | 931 Process key event |
932 */ | |
933 - (void) keyDown: (NSEvent *) theEvent | |
934 { | |
935 unsigned int key; | |
936 | |
937 switch([theEvent keyCode]) | |
938 { | |
939 case 0x34: | |
940 case 0x24: key = KEY_ENTER; break; | |
941 case 0x35: key = KEY_ESC; break; | |
942 case 0x33: key = KEY_BACKSPACE; break; | |
943 case 0x3A: key = KEY_BACKSPACE; break; | |
944 case 0x3B: key = KEY_BACKSPACE; break; | |
945 case 0x38: key = KEY_BACKSPACE; break; | |
946 case 0x7A: key = KEY_F+1; break; | |
947 case 0x78: key = KEY_F+2; break; | |
948 case 0x63: key = KEY_F+3; break; | |
949 case 0x76: key = KEY_F+4; break; | |
950 case 0x60: key = KEY_F+5; break; | |
951 case 0x61: key = KEY_F+6; break; | |
952 case 0x62: key = KEY_F+7; break; | |
953 case 0x64: key = KEY_F+8; break; | |
954 case 0x65: key = KEY_F+9; break; | |
955 case 0x6D: key = KEY_F+10; break; | |
956 case 0x67: key = KEY_F+11; break; | |
957 case 0x6F: key = KEY_F+12; break; | |
958 case 0x72: key = KEY_INSERT; break; | |
959 case 0x75: key = KEY_DELETE; break; | |
960 case 0x73: key = KEY_HOME; break; | |
961 case 0x77: key = KEY_END; break; | |
962 case 0x45: key = '+'; break; | |
963 case 0x4E: key = '-'; break; | |
964 case 0x30: key = KEY_TAB; break; | |
965 case 0x74: key = KEY_PAGE_UP; break; | |
966 case 0x79: key = KEY_PAGE_DOWN; break; | |
967 case 0x7B: key = KEY_LEFT; break; | |
968 case 0x7C: key = KEY_RIGHT; break; | |
969 case 0x7D: key = KEY_DOWN; break; | |
970 case 0x7E: key = KEY_UP; break; | |
971 case 0x43: key = '*'; break; | |
972 case 0x4B: key = '/'; break; | |
24107 | 973 case 0x4C: key = KEY_KPENTER; break; |
15289 | 974 case 0x41: key = KEY_KPDEC; break; |
975 case 0x52: key = KEY_KP0; break; | |
976 case 0x53: key = KEY_KP1; break; | |
977 case 0x54: key = KEY_KP2; break; | |
978 case 0x55: key = KEY_KP3; break; | |
979 case 0x56: key = KEY_KP4; break; | |
980 case 0x57: key = KEY_KP5; break; | |
981 case 0x58: key = KEY_KP6; break; | |
982 case 0x59: key = KEY_KP7; break; | |
983 case 0x5B: key = KEY_KP8; break; | |
984 case 0x5C: key = KEY_KP9; break; | |
985 default: key = *[[theEvent characters] UTF8String]; break; | |
986 } | |
987 mplayer_put_key(key); | |
988 } | |
989 | |
990 /* | |
991 Process mouse button event | |
992 */ | |
993 - (void) mouseMoved: (NSEvent *) theEvent | |
994 { | |
15327 | 995 if(isFullscreen && !isRootwin) |
15289 | 996 { |
18057 | 997 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 998 mouseHide = NO; |
999 } | |
1000 } | |
1001 | |
1002 - (void) mouseDown: (NSEvent *) theEvent | |
1003 { | |
1004 [self mouseEvent: theEvent]; | |
1005 } | |
1006 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1007 - (void) mouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1008 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1009 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1010 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1011 |
15289 | 1012 - (void) rightMouseDown: (NSEvent *) theEvent |
1013 { | |
1014 [self mouseEvent: theEvent]; | |
1015 } | |
1016 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1017 - (void) rightMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1018 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1019 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1020 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1021 |
15289 | 1022 - (void) otherMouseDown: (NSEvent *) theEvent |
1023 { | |
1024 [self mouseEvent: theEvent]; | |
1025 } | |
1026 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1027 - (void) otherMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1028 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1029 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1030 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1031 |
15289 | 1032 - (void) scrollWheel: (NSEvent *) theEvent |
1033 { | |
1034 if([theEvent deltaY] > 0) | |
1035 mplayer_put_key(MOUSE_BTN3); | |
1036 else | |
1037 mplayer_put_key(MOUSE_BTN4); | |
1038 } | |
1039 | |
1040 - (void) mouseEvent: (NSEvent *) theEvent | |
1041 { | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1042 if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 ) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1043 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1044 switch([theEvent type]) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1045 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1046 case NSLeftMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1047 case NSRightMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1048 case NSOtherMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1049 mplayer_put_key((MOUSE_BTN0 + [theEvent buttonNumber]) | MP_KEY_DOWN); |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1050 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1051 case NSLeftMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1052 case NSRightMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1053 case NSOtherMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1054 mplayer_put_key(MOUSE_BTN0 + [theEvent buttonNumber]); |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1055 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1056 } |
15289 | 1057 } |
1058 } | |
1059 | |
1060 /* | |
1061 NSResponder | |
1062 */ | |
1063 - (BOOL) acceptsFirstResponder | |
1064 { | |
1065 return YES; | |
1066 } | |
1067 | |
1068 - (BOOL) becomeFirstResponder | |
1069 { | |
1070 return YES; | |
1071 } | |
1072 | |
1073 - (BOOL) resignFirstResponder | |
1074 { | |
1075 return YES; | |
1076 } | |
15325 | 1077 |
1078 - (void)windowWillClose:(NSNotification *)aNotification | |
1079 { | |
21551 | 1080 mpGLView = NULL; |
15325 | 1081 mplayer_put_key(KEY_ESC); |
1082 } | |
1083 @end |