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