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