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