1 /*****************************************************************************
2 * fspanel.m: MacOS X full screen panel
3 *****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Jérôme Decoodt <djc at videolan dot org>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #import "CoreInteraction.h"
30 #import "MainWindow.h"
34 @interface VLCFSPanel ()
38 /*****************************************************************************
40 *****************************************************************************/
41 @implementation VLCFSPanel
42 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
43 - (id)initWithContentRect:(NSRect)contentRect
44 styleMask:(NSUInteger)aStyle
45 backing:(NSBackingStoreType)bufferingType
48 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
50 [win setHasShadow: NO];
51 [win setBackgroundColor:[NSColor clearColor]];
53 /* let the window sit on top of everything else and start out completely transparent */
54 [win setLevel:NSModalPanelWindowLevel];
57 hideAgainTimer = fadeTimer = nil;
58 [self setNonActive:nil];
64 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
65 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
66 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
68 [self mouseEntered:NULL];
70 [self mouseExited:NULL];
72 /* get a notification if VLC isn't the active app anymore */
73 [[NSNotificationCenter defaultCenter]
75 selector: @selector(setNonActive:)
76 name: NSApplicationDidResignActiveNotification
79 /* get a notification if VLC is the active app again */
80 [[NSNotificationCenter defaultCenter]
82 selector: @selector(setActive:)
83 name: NSApplicationDidBecomeActiveNotification
87 /* make sure that we don't become key, since we can't handle hotkeys */
88 - (BOOL)canBecomeKeyWindow
93 - (BOOL)mouseDownCanMoveWindow
100 [[NSNotificationCenter defaultCenter] removeObserver: self];
104 [hideAgainTimer invalidate];
105 [hideAgainTimer release];
107 [self setFadeTimer:nil];
113 /* centre the panel in the lower third of the screen */
114 NSPoint theCoordinate;
115 NSRect theScreensFrame;
116 NSRect theWindowsFrame;
119 /* user-defined screen */
120 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
124 /* invalid preferences or none specified, using main screen */
125 screen = [NSScreen mainScreen];
128 theScreensFrame = [screen frame];
130 theWindowsFrame = [self frame];
132 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
133 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
134 [self setFrameTopLeftPoint: theCoordinate];
139 [[self contentView] setPlay];
144 [[self contentView] setPause];
147 - (void)setStreamTitle:(NSString *)o_title
149 [[self contentView] setStreamTitle: o_title];
152 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
154 [[self contentView] setStreamPos:f_pos andTime: o_time];
157 - (void)setSeekable:(BOOL) b_seekable
159 [[self contentView] setSeekable: b_seekable];
162 - (void)setVolumeLevel: (float)f_volumeLevel
164 [[self contentView] setVolumeLevel: f_volumeLevel];
167 - (void)setNonActive:(id)noData
170 [self orderOut: self];
172 /* here's fadeOut, just without visibly fading */
174 [self setAlphaValue:0.0];
175 [self setFadeTimer:nil];
179 - (void)setActive:(id)noData
181 vout_thread_t *p_vout = getVout();
184 if (var_GetBool( p_vout, "fullscreen" ))
189 vlc_object_release( p_vout );
193 /* This routine is called repeatedly to fade in the window */
194 - (void)focus:(NSTimer *)timer
196 /* we need to push ourselves to front if the vout window was closed since our last display */
197 if( b_voutWasUpdated )
199 [self orderFront: self];
200 b_voutWasUpdated = NO;
203 if( [self alphaValue] < 1.0 )
204 [self setAlphaValue:[self alphaValue]+0.1];
205 if( [self alphaValue] >= 1.0 )
208 [self setAlphaValue: 1.0];
209 [self setFadeTimer:nil];
213 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
218 /* This routine is called repeatedly to hide the window */
219 - (void)unfocus:(NSTimer *)timer
225 [self setFadeTimer: NULL];
229 if( [self alphaValue] > 0.0 )
230 [self setAlphaValue:[self alphaValue]-0.05];
231 if( [self alphaValue] <= 0.05 )
234 [self setAlphaValue:0.0];
235 [self setFadeTimer:nil];
240 [NSTimer scheduledTimerWithTimeInterval:0.1
242 selector:@selector(focus:)
249 - (void)mouseExited:(NSEvent *)theEvent
251 /* give up our focus, so the vout may show us again without letting the user clicking it */
252 vout_thread_t *p_vout = getVout();
255 if (var_GetBool( p_vout, "fullscreen" ))
256 [[[[VLCMainWindow sharedInstance] videoView] window] makeKeyWindow];
257 vlc_object_release( p_vout );
263 [NSCursor setHiddenUntilMouseMoves: YES];
268 /* in case that the user don't want us to appear, make sure we hide the mouse */
270 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
272 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
273 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
280 [self orderFront: nil];
282 if( [self alphaValue] < 1.0 || b_displayed != YES )
284 if (![self fadeTimer])
285 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
286 else if ([[[self fadeTimer] userInfo] shortValue]==0)
294 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
297 if( ( [self alphaValue] > 0.0 ) )
299 if (![self fadeTimer])
300 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
301 else if ([[[self fadeTimer] userInfo] shortValue]==1)
306 /* triggers a timer to autoHide us again after some seconds of no activity */
309 /* this will tell the timer to start over again or to start at all */
312 /* get us a valid timer */
313 if(! b_alreadyCounting )
315 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
318 [hideAgainTimer invalidate];
319 [hideAgainTimer autorelease];
321 /* released in -autoHide and -dealloc */
322 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
324 selector: @selector(keepVisible:)
326 repeats: YES] retain];
327 b_alreadyCounting = YES;
331 - (void)keepVisible:(NSTimer *)timer
333 /* if the user triggered an action, start over again */
337 /* count down until we hide ourselfes again and do so if necessary */
338 if( --i_timeToKeepVisibleInSec < 1 )
342 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
343 b_alreadyCounting = NO;
347 /* A getter and setter for our main timer that handles window fading */
348 - (NSTimer *)fadeTimer
353 - (void)setFadeTimer:(NSTimer *)timer
356 [fadeTimer invalidate];
357 [fadeTimer autorelease];
361 - (void)mouseDown:(NSEvent *)theEvent
363 mouseClic = [theEvent locationInWindow];
366 - (void)mouseDragged:(NSEvent *)theEvent
368 NSPoint point = [NSEvent mouseLocation];
369 point.x -= mouseClic.x;
370 point.y -= mouseClic.y;
371 [self setFrameOrigin:point];
379 - (void)setVoutWasUpdated: (int)i_newdevice;
381 b_voutWasUpdated = YES;
382 if( i_newdevice != i_device )
384 i_device = i_newdevice;
390 /*****************************************************************************
392 *****************************************************************************/
393 @implementation VLCFSPanelView
395 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
396 s_rc.origin.x = _x; \
397 s_rc.origin.y = _y; \
398 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
399 [o_button setButtonType: NSMomentaryChangeButton]; \
400 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
401 [o_button setBordered: NO]; \
402 [o_button setFont:[NSFont systemFontOfSize:0]]; \
403 [o_button setImage:[NSImage imageNamed:imageOff]]; \
404 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
405 [o_button sizeToFit]; \
406 [o_button setTarget: self]; \
407 [o_button setAction: @selector(action:)]; \
408 [self addSubview:o_button];
410 #define addTextfield( class, o_text, align, font, color, size ) \
411 o_text = [[class alloc] initWithFrame: s_rc]; \
412 [o_text setDrawsBackground: NO]; \
413 [o_text setBordered: NO]; \
414 [o_text setEditable: NO]; \
415 [o_text setSelectable: NO]; \
416 [o_text setStringValue: _NS("(no item is being played)")]; \
417 [o_text setAlignment: align]; \
418 [o_text setTextColor: [NSColor color]]; \
419 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
420 [self addSubview:o_text];
422 - (id)initWithFrame:(NSRect)frameRect
424 id view = [super initWithFrame:frameRect];
425 fillColor = [[NSColor clearColor] retain];
426 NSRect s_rc = [self frame];
427 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
428 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
429 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
430 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
431 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
432 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
434 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
441 s_rc.size.width = 518;
442 s_rc.size.height = 9;
443 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
444 [o_fs_timeSlider setMinValue:0];
445 [o_fs_timeSlider setMaxValue:10000];
446 [o_fs_timeSlider setFloatValue: 0];
447 [o_fs_timeSlider setContinuous: YES];
448 [o_fs_timeSlider setTarget: self];
449 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
450 [self addSubview: o_fs_timeSlider];
455 s_rc.origin.y = 17.5;
456 s_rc.size.width = 95;
457 s_rc.size.height = 10;
458 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
459 [o_fs_volumeSlider setMinValue:0];
460 [o_fs_volumeSlider setMaxValue:32];
461 [o_fs_volumeSlider setFloatValue: 0];
462 [o_fs_volumeSlider setContinuous: YES];
463 [o_fs_volumeSlider setTarget: self];
464 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
465 [self addSubview: o_fs_volumeSlider];
467 /* time counter and stream title output fields */
471 s_rc.size.width = 352;
472 s_rc.size.height = 14;
473 addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
476 s_rc.size.width = 55;
477 addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
484 [o_fs_timeSlider release];
485 [o_fs_volumeSlider release];
491 [o_fullscreen release];
492 [o_streamTitle_txt release];
493 [o_streamPosition_txt release];
499 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
500 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
505 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
506 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
509 - (void)setStreamTitle:(NSString *)o_title
511 [o_streamTitle_txt setStringValue: o_title];
514 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
516 [o_streamPosition_txt setStringValue: o_time];
517 [o_fs_timeSlider setFloatValue: f_pos];
520 - (void)setSeekable:(BOOL)b_seekable
522 [o_bwd setEnabled: b_seekable];
523 [o_fwd setEnabled: b_seekable];
524 [o_fs_timeSlider setEnabled: b_seekable];
527 - (void)setVolumeLevel: (float)f_volumeLevel
529 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
532 - (IBAction)play:(id)sender
534 [[[VLCMain sharedInstance] controls] play: sender];
537 - (IBAction)forward:(id)sender
539 [[[VLCMain sharedInstance] controls] forward: sender];
542 - (IBAction)backward:(id)sender
544 [[[VLCMain sharedInstance] controls] backward: sender];
547 - (IBAction)prev:(id)sender
549 [[[VLCMain sharedInstance] controls] prev: sender];
552 - (IBAction)next:(id)sender
554 [[[VLCMain sharedInstance] controls] next: sender];
557 - (IBAction)windowAction:(id)sender
559 [[[VLCMain sharedInstance] controls] windowAction: sender];
562 - (IBAction)fsTimeSliderUpdate:(id)sender
564 input_thread_t * p_input;
565 p_input = pl_CurrentInput( VLCIntf );
566 if( p_input != NULL )
570 pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
571 var_Set( p_input, "position", pos );
572 vlc_object_release( p_input );
574 [[VLCMain sharedInstance] updatePlaybackPosition];
577 - (IBAction)fsVolumeSliderUpdate:(id)sender
579 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
582 #define addImage(image, _x, _y, mode, _width) \
583 img = [NSImage imageNamed:image]; \
584 image_rect.size = [img size]; \
585 image_rect.origin.x = 0; \
586 image_rect.origin.y = 0; \
587 frame.origin.x = _x; \
588 frame.origin.y = _y; \
589 frame.size = [img size]; \
590 if( _width ) frame.size.width = _width; \
591 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
593 - (void)drawRect:(NSRect)rect
595 NSRect frame = [self frame];
598 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
599 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
600 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
601 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
602 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
607 /*****************************************************************************
609 *****************************************************************************/
610 @implementation VLCFSTimeSlider
611 - (void)drawKnobInRect:(NSRect)knobRect
614 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
615 image_rect.size = [img size];
616 image_rect.origin.x = 0;
617 image_rect.origin.y = 0;
618 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
619 knobRect.size.width = image_rect.size.width;
620 knobRect.size.height = image_rect.size.height;
621 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
624 - (void)drawRect:(NSRect)rect
626 /* Draw default to make sure the slider behaves correctly */
627 [[NSGraphicsContext currentContext] saveGraphicsState];
628 NSRectClip(NSZeroRect);
629 [super drawRect:rect];
630 [[NSGraphicsContext currentContext] restoreGraphicsState];
632 NSRect knobRect = [[self cell] knobRectFlipped:NO];
633 knobRect.origin.y+=7.5;
634 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
635 [self drawKnobInRect: knobRect];
640 /*****************************************************************************
642 *****************************************************************************/
643 @implementation VLCFSVolumeSlider
644 - (void)drawKnobInRect:(NSRect) knobRect
647 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
648 image_rect.size = [img size];
649 image_rect.origin.x = 0;
650 image_rect.origin.y = 0;
651 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
652 knobRect.size.width = image_rect.size.width;
653 knobRect.size.height = image_rect.size.height;
654 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
657 - (void)drawRect:(NSRect)rect
659 /* Draw default to make sure the slider behaves correctly */
660 [[NSGraphicsContext currentContext] saveGraphicsState];
661 NSRectClip(NSZeroRect);
662 [super drawRect:rect];
663 [[NSGraphicsContext currentContext] restoreGraphicsState];
665 NSRect knobRect = [[self cell] knobRectFlipped:NO];
666 knobRect.origin.y+=6;
667 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
668 [self drawKnobInRect: knobRect];