1 /*****************************************************************************
\r
2 * fspanel.m: MacOS X full screen panel
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2006-2007 the VideoLAN team
\r
7 * Authors: Jérôme Decoodt <djc at videolan dot org>
\r
8 * Felix Kühne <fkuehne at videolan dot org>
\r
10 * This program is free software; you can redistribute it and/or modify
\r
11 * it under the terms of the GNU General Public License as published by
\r
12 * the Free Software Foundation; either version 2 of the License, or
\r
13 * (at your option) any later version.
\r
15 * This program is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 * GNU General Public License for more details.
\r
20 * You should have received a copy of the GNU General Public License
\r
21 * along with this program; if not, write to the Free Software
\r
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
\r
23 *****************************************************************************/
\r
25 /*****************************************************************************
\r
27 *****************************************************************************/
\r
29 #import "controls.h"
\r
34 #define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after a user's action */
\r
36 /*****************************************************************************
\r
38 *****************************************************************************/
\r
39 @implementation VLCFSPanel
\r
40 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
\r
41 - (id)initWithContentRect:(NSRect)contentRect
\r
42 styleMask:(unsigned int)aStyle
\r
43 backing:(NSBackingStoreType)bufferingType
\r
46 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
\r
48 [win setHasShadow: NO];
\r
49 [win setBackgroundColor:[NSColor clearColor]];
\r
51 /* let the window sit on top of everything else and start out completely transparent */
\r
52 [win setLevel:NSModalPanelWindowLevel];
\r
55 [self setNonActive:nil];
\r
60 - (void)awakeFromNib
\r
62 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
\r
63 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
\r
64 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
\r
66 [self mouseEntered:NULL];
\r
68 [self mouseExited:NULL];
\r
70 /* get a notification if VLC isn't the active app anymore */
\r
71 [[NSNotificationCenter defaultCenter]
\r
73 selector: @selector(setNonActive:)
\r
74 name: NSApplicationDidResignActiveNotification
\r
77 /* get a notification if VLC is the active app again */
\r
78 [[NSNotificationCenter defaultCenter]
\r
80 selector: @selector(setActive:)
\r
81 name: NSApplicationDidBecomeActiveNotification
\r
85 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
86 - (BOOL)canBecomeKeyWindow
\r
91 - (BOOL)mouseDownCanMoveWindow
\r
98 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
100 if( hideAgainTimer )
\r
101 [hideAgainTimer release];
\r
102 [self setFadeTimer:nil];
\r
108 /* centre the panel in the lower third of the screen */
\r
109 NSPoint theCoordinate;
\r
110 NSRect theScreensFrame;
\r
111 NSRect theWindowsFrame;
\r
114 /* user-defined screen */
\r
115 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
\r
119 /* invalid preferences or none specified, using main screen */
\r
120 screen = [NSScreen mainScreen];
\r
123 theScreensFrame = [screen frame];
\r
125 theWindowsFrame = [self frame];
\r
127 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
\r
128 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
\r
129 [self setFrameTopLeftPoint: theCoordinate];
\r
134 [[self contentView] setPlay];
\r
139 [[self contentView] setPause];
\r
142 - (void)setStreamTitle:(NSString *)o_title
\r
144 [[self contentView] setStreamTitle: o_title];
\r
147 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
149 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
152 - (void)setSeekable:(BOOL) b_seekable
\r
154 [[self contentView] setSeekable: b_seekable];
\r
157 - (void)setVolumeLevel: (float)f_volumeLevel
\r
159 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
162 - (void)setNonActive:(id)noData
\r
165 [self orderOut: self];
\r
167 /* here's fadeOut, just without visibly fading */
\r
169 [self setAlphaValue:0.0];
\r
170 [self setFadeTimer:nil];
\r
174 - (void)setActive:(id)noData
\r
176 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
183 /* This routine is called repeatedly to fade in the window */
\r
184 - (void)focus:(NSTimer *)timer
\r
186 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
187 if( b_voutWasUpdated )
\r
189 [self orderFront: self];
\r
190 b_voutWasUpdated = NO;
\r
193 if( [self alphaValue] < 1.0 )
\r
194 [self setAlphaValue:[self alphaValue]+0.1];
\r
195 if( [self alphaValue] >= 1.0 )
\r
198 [self setAlphaValue: 1.0];
\r
199 [self setFadeTimer:nil];
\r
203 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
208 /* This routine is called repeatedly to hide the window */
\r
209 - (void)unfocus:(NSTimer *)timer
\r
211 if( b_keptVisible )
\r
213 b_keptVisible = NO;
\r
215 [self setFadeTimer: NULL];
\r
219 if( [self alphaValue] > 0.0 )
\r
220 [self setAlphaValue:[self alphaValue]-0.05];
\r
221 if( [self alphaValue] <= 0.05 )
\r
224 [self setAlphaValue:0.0];
\r
225 [self setFadeTimer:nil];
\r
229 [self setFadeTimer:
\r
230 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
232 selector:@selector(focus:)
\r
239 - (void)mouseExited:(NSEvent *)theEvent
\r
241 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
242 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
243 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
248 /* in case that the user don't want us to appear, just return here */
\r
249 if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
\r
252 [self orderFront: nil];
\r
254 if( [self alphaValue] < 1.0 || b_displayed != YES )
\r
256 if (![self fadeTimer])
\r
257 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
258 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
266 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
\r
269 if( ( [self alphaValue] > 0.0 ) )
\r
271 if (![self fadeTimer])
\r
272 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
273 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
278 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
281 /* this will tell the timer to start over again or to start at all */
\r
282 b_keptVisible = YES;
\r
284 /* get us a valid timer */
\r
285 if(! b_alreadyCounting )
\r
287 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
289 selector: @selector(keepVisible:)
\r
292 [hideAgainTimer fire];
\r
293 [hideAgainTimer retain];
\r
294 b_alreadyCounting = YES;
\r
298 - (void)keepVisible:(NSTimer *)timer
\r
300 /* if the user triggered an action, start over again */
\r
301 if( b_keptVisible )
\r
303 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
304 b_keptVisible = NO;
\r
307 /* count down until we hide ourselfes again and do so if necessary */
\r
308 i_timeToKeepVisibleInSec -= 1;
\r
309 if( i_timeToKeepVisibleInSec < 1 )
\r
311 [NSCursor setHiddenUntilMouseMoves: YES];
\r
313 [timer invalidate];
\r
315 b_alreadyCounting = NO;
\r
320 /* A getter and setter for our main timer that handles window fading */
\r
321 - (NSTimer *)fadeTimer
\r
326 - (void)setFadeTimer:(NSTimer *)timer
\r
329 [fadeTimer invalidate];
\r
330 [fadeTimer release];
\r
334 - (void)mouseDown:(NSEvent *)theEvent
\r
336 mouseClic = [theEvent locationInWindow];
\r
339 - (void)mouseDragged:(NSEvent *)theEvent
\r
341 NSPoint point = [NSEvent mouseLocation];
\r
342 point.x -= mouseClic.x;
\r
343 point.y -= mouseClic.y;
\r
344 [self setFrameOrigin:point];
\r
347 - (BOOL)isDisplayed
\r
349 return b_displayed;
\r
352 - (void)setVoutWasUpdated: (int)i_newdevice;
\r
354 b_voutWasUpdated = YES;
\r
355 if( i_newdevice != i_device )
\r
357 i_device = i_newdevice;
\r
363 /*****************************************************************************
\r
365 *****************************************************************************/
\r
366 @implementation VLCFSPanelView
\r
368 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
369 s_rc.origin.x = _x; \
\r
370 s_rc.origin.y = _y; \
\r
371 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
372 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
373 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
374 [o_button setBordered: NO]; \
\r
375 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
376 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
377 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
378 [o_button sizeToFit]; \
\r
379 [o_button setTarget: self]; \
\r
380 [o_button setAction: @selector(action:)]; \
\r
381 [self addSubview:o_button];
\r
383 #define addTextfield( o_text, align, font, color, size ) \
\r
384 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
385 [o_text setDrawsBackground: NO]; \
\r
386 [o_text setBordered: NO]; \
\r
387 [o_text setEditable: NO]; \
\r
388 [o_text setSelectable: NO]; \
\r
389 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
390 [o_text setAlignment: align]; \
\r
391 [o_text setTextColor: [NSColor color]]; \
\r
392 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
393 [self addSubview:o_text];
\r
395 - (id)initWithFrame:(NSRect)frameRect
\r
397 id view = [super initWithFrame:frameRect];
\r
398 fillColor = [[NSColor clearColor] retain];
\r
399 NSRect s_rc = [self frame];
\r
400 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
401 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
\r
402 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
403 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
\r
404 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
405 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
407 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
411 s_rc = [self frame];
\r
412 s_rc.origin.x = 15;
\r
413 s_rc.origin.y = 53;
\r
414 s_rc.size.width = 518;
\r
415 s_rc.size.height = 9;
\r
416 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
417 [o_fs_timeSlider setMinValue:0];
\r
418 [o_fs_timeSlider setMaxValue:10000];
\r
419 [o_fs_timeSlider setFloatValue: 0];
\r
420 [o_fs_timeSlider setContinuous: YES];
\r
421 [o_fs_timeSlider setTarget: self];
\r
422 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
423 [self addSubview: o_fs_timeSlider];
\r
425 /* volume slider */
\r
426 s_rc = [self frame];
\r
427 s_rc.origin.x = 26;
\r
428 s_rc.origin.y = 17.5;
\r
429 s_rc.size.width = 95;
\r
430 s_rc.size.height = 10;
\r
431 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
432 [o_fs_volumeSlider setMinValue:0];
\r
433 [o_fs_volumeSlider setMaxValue:32];
\r
434 [o_fs_volumeSlider setFloatValue: 0];
\r
435 [o_fs_volumeSlider setContinuous: YES];
\r
436 [o_fs_volumeSlider setTarget: self];
\r
437 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
438 [self addSubview: o_fs_volumeSlider];
\r
440 /* time counter and stream title output fields */
\r
441 s_rc = [self frame];
\r
442 s_rc.origin.x = 98;
\r
443 s_rc.origin.y = 64;
\r
444 s_rc.size.width = 352;
\r
445 s_rc.size.height = 14;
\r
446 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
447 s_rc.origin.x = 486;
\r
448 s_rc.origin.y = 64;
\r
449 s_rc.size.width = 50;
\r
450 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
457 [o_fs_timeSlider release];
\r
458 [o_fs_volumeSlider release];
\r
464 [o_fullscreen release];
\r
465 [o_streamTitle_txt release];
\r
466 [o_streamPosition_txt release];
\r
472 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
\r
473 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
\r
478 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
\r
479 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
\r
482 - (void)setStreamTitle:(NSString *)o_title
\r
484 [o_streamTitle_txt setStringValue: o_title];
\r
487 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
489 [o_streamPosition_txt setStringValue: o_time];
\r
490 [o_fs_timeSlider setFloatValue: f_pos];
\r
493 - (void)setSeekable:(BOOL)b_seekable
\r
495 [o_bwd setEnabled: b_seekable];
\r
496 [o_fwd setEnabled: b_seekable];
\r
497 [o_fs_timeSlider setEnabled: b_seekable];
\r
500 - (void)setVolumeLevel: (float)f_volumeLevel
\r
502 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
505 - (IBAction)play:(id)sender
\r
507 [[[VLCMain sharedInstance] getControls] play: sender];
\r
510 - (IBAction)forward:(id)sender
\r
512 [[[VLCMain sharedInstance] getControls] forward: sender];
\r
515 - (IBAction)backward:(id)sender
\r
517 [[[VLCMain sharedInstance] getControls] backward: sender];
\r
520 - (IBAction)prev:(id)sender
\r
522 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
525 - (IBAction)next:(id)sender
\r
527 [[[VLCMain sharedInstance] getControls] next: sender];
\r
530 - (IBAction)windowAction:(id)sender
\r
532 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
535 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
537 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
540 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
542 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
545 #define addImage(image, _x, _y, mode, _width) \
\r
546 img = [NSImage imageNamed:image]; \
\r
547 image_rect.size = [img size]; \
\r
548 image_rect.origin.x = 0; \
\r
549 image_rect.origin.y = 0; \
\r
550 frame.origin.x = _x; \
\r
551 frame.origin.y = _y; \
\r
552 frame.size = [img size]; \
\r
553 if( _width ) frame.size.width = _width; \
\r
554 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
556 - (void)drawRect:(NSRect)rect
\r
558 NSRect frame = [self frame];
\r
561 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
562 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
563 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
564 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
565 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
570 /*****************************************************************************
\r
572 *****************************************************************************/
\r
573 @implementation VLCFSTimeSlider
\r
574 - (void)drawKnobInRect:(NSRect)knobRect
\r
577 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
578 image_rect.size = [img size];
\r
579 image_rect.origin.x = 0;
\r
580 image_rect.origin.y = 0;
\r
581 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
582 knobRect.size.width = image_rect.size.width;
\r
583 knobRect.size.height = image_rect.size.height;
\r
584 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
587 - (void)drawRect:(NSRect)rect
\r
589 /* Draw default to make sure the slider behaves correctly */
\r
590 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
591 NSRectClip(NSZeroRect);
\r
592 [super drawRect:rect];
\r
593 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
595 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
596 knobRect.origin.y+=7.5;
\r
597 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
598 [self drawKnobInRect: knobRect];
\r
603 /*****************************************************************************
\r
604 * VLCFSVolumeSlider
\r
605 *****************************************************************************/
\r
606 @implementation VLCFSVolumeSlider
\r
607 - (void)drawKnobInRect:(NSRect) knobRect
\r
610 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
611 image_rect.size = [img size];
\r
612 image_rect.origin.x = 0;
\r
613 image_rect.origin.y = 0;
\r
614 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
615 knobRect.size.width = image_rect.size.width;
\r
616 knobRect.size.height = image_rect.size.height;
\r
617 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
620 - (void)drawRect:(NSRect)rect
\r
622 /* Draw default to make sure the slider behaves correctly */
\r
623 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
624 NSRectClip(NSZeroRect);
\r
625 [super drawRect:rect];
\r
626 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
628 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
629 knobRect.origin.y+=6;
\r
630 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
631 [self drawKnobInRect: knobRect];
\r