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"
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 if( [[VLCCoreInteraction sharedInstance] voutView] != nil )
183 if( [[[VLCCoreInteraction sharedInstance] voutView] isFullscreen] )
191 /* This routine is called repeatedly to fade in the window */
192 - (void)focus:(NSTimer *)timer
194 /* we need to push ourselves to front if the vout window was closed since our last display */
195 if( b_voutWasUpdated )
197 [self orderFront: self];
198 b_voutWasUpdated = NO;
201 if( [self alphaValue] < 1.0 )
202 [self setAlphaValue:[self alphaValue]+0.1];
203 if( [self alphaValue] >= 1.0 )
206 [self setAlphaValue: 1.0];
207 [self setFadeTimer:nil];
211 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
216 /* This routine is called repeatedly to hide the window */
217 - (void)unfocus:(NSTimer *)timer
223 [self setFadeTimer: NULL];
227 if( [self alphaValue] > 0.0 )
228 [self setAlphaValue:[self alphaValue]-0.05];
229 if( [self alphaValue] <= 0.05 )
232 [self setAlphaValue:0.0];
233 [self setFadeTimer:nil];
238 [NSTimer scheduledTimerWithTimeInterval:0.1
240 selector:@selector(focus:)
247 - (void)mouseExited:(NSEvent *)theEvent
249 /* give up our focus, so the vout may show us again without letting the user clicking it */
250 if( [[[VLCCoreInteraction sharedInstance] voutView] isFullscreen] )
251 [[[[VLCCoreInteraction sharedInstance] voutView] window] makeKeyWindow];
256 [NSCursor setHiddenUntilMouseMoves: YES];
261 /* in case that the user don't want us to appear, make sure we hide the mouse */
263 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
265 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
266 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
273 [self orderFront: nil];
275 if( [self alphaValue] < 1.0 || b_displayed != YES )
277 if (![self fadeTimer])
278 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
279 else if ([[[self fadeTimer] userInfo] shortValue]==0)
287 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
290 if( ( [self alphaValue] > 0.0 ) )
292 if (![self fadeTimer])
293 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
294 else if ([[[self fadeTimer] userInfo] shortValue]==1)
299 /* triggers a timer to autoHide us again after some seconds of no activity */
302 /* this will tell the timer to start over again or to start at all */
305 /* get us a valid timer */
306 if(! b_alreadyCounting )
308 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
311 [hideAgainTimer invalidate];
312 [hideAgainTimer autorelease];
314 /* released in -autoHide and -dealloc */
315 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
317 selector: @selector(keepVisible:)
319 repeats: YES] retain];
320 b_alreadyCounting = YES;
324 - (void)keepVisible:(NSTimer *)timer
326 /* if the user triggered an action, start over again */
330 /* count down until we hide ourselfes again and do so if necessary */
331 if( --i_timeToKeepVisibleInSec < 1 )
335 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
336 b_alreadyCounting = NO;
340 /* A getter and setter for our main timer that handles window fading */
341 - (NSTimer *)fadeTimer
346 - (void)setFadeTimer:(NSTimer *)timer
349 [fadeTimer invalidate];
350 [fadeTimer autorelease];
354 - (void)mouseDown:(NSEvent *)theEvent
356 mouseClic = [theEvent locationInWindow];
359 - (void)mouseDragged:(NSEvent *)theEvent
361 NSPoint point = [NSEvent mouseLocation];
362 point.x -= mouseClic.x;
363 point.y -= mouseClic.y;
364 [self setFrameOrigin:point];
372 - (void)setVoutWasUpdated: (int)i_newdevice;
374 b_voutWasUpdated = YES;
375 if( i_newdevice != i_device )
377 i_device = i_newdevice;
383 /*****************************************************************************
385 *****************************************************************************/
386 @implementation VLCFSPanelView
388 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
389 s_rc.origin.x = _x; \
390 s_rc.origin.y = _y; \
391 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
392 [o_button setButtonType: NSMomentaryChangeButton]; \
393 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
394 [o_button setBordered: NO]; \
395 [o_button setFont:[NSFont systemFontOfSize:0]]; \
396 [o_button setImage:[NSImage imageNamed:imageOff]]; \
397 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
398 [o_button sizeToFit]; \
399 [o_button setTarget: self]; \
400 [o_button setAction: @selector(action:)]; \
401 [self addSubview:o_button];
403 #define addTextfield( class, o_text, align, font, color, size ) \
404 o_text = [[class alloc] initWithFrame: s_rc]; \
405 [o_text setDrawsBackground: NO]; \
406 [o_text setBordered: NO]; \
407 [o_text setEditable: NO]; \
408 [o_text setSelectable: NO]; \
409 [o_text setStringValue: _NS("(no item is being played)")]; \
410 [o_text setAlignment: align]; \
411 [o_text setTextColor: [NSColor color]]; \
412 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
413 [self addSubview:o_text];
415 - (id)initWithFrame:(NSRect)frameRect
417 id view = [super initWithFrame:frameRect];
418 fillColor = [[NSColor clearColor] retain];
419 NSRect s_rc = [self frame];
420 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
421 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
422 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
423 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
424 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
425 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
427 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
434 s_rc.size.width = 518;
435 s_rc.size.height = 9;
436 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
437 [o_fs_timeSlider setMinValue:0];
438 [o_fs_timeSlider setMaxValue:10000];
439 [o_fs_timeSlider setFloatValue: 0];
440 [o_fs_timeSlider setContinuous: YES];
441 [o_fs_timeSlider setTarget: self];
442 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
443 [self addSubview: o_fs_timeSlider];
448 s_rc.origin.y = 17.5;
449 s_rc.size.width = 95;
450 s_rc.size.height = 10;
451 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
452 [o_fs_volumeSlider setMinValue:0];
453 [o_fs_volumeSlider setMaxValue:32];
454 [o_fs_volumeSlider setFloatValue: 0];
455 [o_fs_volumeSlider setContinuous: YES];
456 [o_fs_volumeSlider setTarget: self];
457 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
458 [self addSubview: o_fs_volumeSlider];
460 /* time counter and stream title output fields */
464 s_rc.size.width = 352;
465 s_rc.size.height = 14;
466 addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
469 s_rc.size.width = 55;
470 addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
477 [o_fs_timeSlider release];
478 [o_fs_volumeSlider release];
484 [o_fullscreen release];
485 [o_streamTitle_txt release];
486 [o_streamPosition_txt release];
492 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
493 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
498 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
499 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
502 - (void)setStreamTitle:(NSString *)o_title
504 [o_streamTitle_txt setStringValue: o_title];
507 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
509 [o_streamPosition_txt setStringValue: o_time];
510 [o_fs_timeSlider setFloatValue: f_pos];
513 - (void)setSeekable:(BOOL)b_seekable
515 [o_bwd setEnabled: b_seekable];
516 [o_fwd setEnabled: b_seekable];
517 [o_fs_timeSlider setEnabled: b_seekable];
520 - (void)setVolumeLevel: (float)f_volumeLevel
522 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
525 - (IBAction)play:(id)sender
527 [[[VLCMain sharedInstance] controls] play: sender];
530 - (IBAction)forward:(id)sender
532 [[[VLCMain sharedInstance] controls] forward: sender];
535 - (IBAction)backward:(id)sender
537 [[[VLCMain sharedInstance] controls] backward: sender];
540 - (IBAction)prev:(id)sender
542 [[[VLCMain sharedInstance] controls] prev: sender];
545 - (IBAction)next:(id)sender
547 [[[VLCMain sharedInstance] controls] next: sender];
550 - (IBAction)windowAction:(id)sender
552 [[[VLCMain sharedInstance] controls] windowAction: sender];
555 - (IBAction)fsTimeSliderUpdate:(id)sender
557 input_thread_t * p_input;
558 p_input = pl_CurrentInput( VLCIntf );
559 if( p_input != NULL )
563 pos.f_float = [o_fs_timeSlider floatValue] / 10000.;
564 var_Set( p_input, "position", pos );
565 vlc_object_release( p_input );
567 [[VLCMain sharedInstance] updatePlaybackPosition];
570 - (IBAction)fsVolumeSliderUpdate:(id)sender
572 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
575 #define addImage(image, _x, _y, mode, _width) \
576 img = [NSImage imageNamed:image]; \
577 image_rect.size = [img size]; \
578 image_rect.origin.x = 0; \
579 image_rect.origin.y = 0; \
580 frame.origin.x = _x; \
581 frame.origin.y = _y; \
582 frame.size = [img size]; \
583 if( _width ) frame.size.width = _width; \
584 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
586 - (void)drawRect:(NSRect)rect
588 NSRect frame = [self frame];
591 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
592 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
593 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
594 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
595 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
600 /*****************************************************************************
602 *****************************************************************************/
603 @implementation VLCFSTimeSlider
604 - (void)drawKnobInRect:(NSRect)knobRect
607 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
608 image_rect.size = [img size];
609 image_rect.origin.x = 0;
610 image_rect.origin.y = 0;
611 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
612 knobRect.size.width = image_rect.size.width;
613 knobRect.size.height = image_rect.size.height;
614 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
617 - (void)drawRect:(NSRect)rect
619 /* Draw default to make sure the slider behaves correctly */
620 [[NSGraphicsContext currentContext] saveGraphicsState];
621 NSRectClip(NSZeroRect);
622 [super drawRect:rect];
623 [[NSGraphicsContext currentContext] restoreGraphicsState];
625 NSRect knobRect = [[self cell] knobRectFlipped:NO];
626 knobRect.origin.y+=7.5;
627 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
628 [self drawKnobInRect: knobRect];
633 /*****************************************************************************
635 *****************************************************************************/
636 @implementation VLCFSVolumeSlider
637 - (void)drawKnobInRect:(NSRect) knobRect
640 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
641 image_rect.size = [img size];
642 image_rect.origin.x = 0;
643 image_rect.origin.y = 0;
644 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
645 knobRect.size.width = image_rect.size.width;
646 knobRect.size.height = image_rect.size.height;
647 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
650 - (void)drawRect:(NSRect)rect
652 /* Draw default to make sure the slider behaves correctly */
653 [[NSGraphicsContext currentContext] saveGraphicsState];
654 NSRectClip(NSZeroRect);
655 [super drawRect:rect];
656 [[NSGraphicsContext currentContext] restoreGraphicsState];
658 NSRect knobRect = [[self cell] knobRectFlipped:NO];
659 knobRect.origin.y+=6;
660 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
661 [self drawKnobInRect: knobRect];