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 *****************************************************************************/
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 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
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( [[[VLCMain sharedInstance] controls] voutView] != nil )
183 if( [[[[VLCMain sharedInstance] controls] 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( [[[[VLCMain sharedInstance] controls] voutView] isFullscreen] )
251 [[[[[VLCMain sharedInstance] controls] 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( o_text, align, font, color, size ) \
404 o_text = [[NSTextField 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( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
469 s_rc.size.width = 50;
470 addTextfield( 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 [[VLCMain sharedInstance] timesliderUpdate: sender];
560 - (IBAction)fsVolumeSliderUpdate:(id)sender
562 [[[VLCMain sharedInstance] controls] volumeSliderUpdated: sender];
565 #define addImage(image, _x, _y, mode, _width) \
566 img = [NSImage imageNamed:image]; \
567 image_rect.size = [img size]; \
568 image_rect.origin.x = 0; \
569 image_rect.origin.y = 0; \
570 frame.origin.x = _x; \
571 frame.origin.y = _y; \
572 frame.size = [img size]; \
573 if( _width ) frame.size.width = _width; \
574 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
576 - (void)drawRect:(NSRect)rect
578 NSRect frame = [self frame];
581 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
582 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
583 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
584 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
585 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
590 /*****************************************************************************
592 *****************************************************************************/
593 @implementation VLCFSTimeSlider
594 - (void)drawKnobInRect:(NSRect)knobRect
597 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
598 image_rect.size = [img size];
599 image_rect.origin.x = 0;
600 image_rect.origin.y = 0;
601 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
602 knobRect.size.width = image_rect.size.width;
603 knobRect.size.height = image_rect.size.height;
604 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
607 - (void)drawRect:(NSRect)rect
609 /* Draw default to make sure the slider behaves correctly */
610 [[NSGraphicsContext currentContext] saveGraphicsState];
611 NSRectClip(NSZeroRect);
612 [super drawRect:rect];
613 [[NSGraphicsContext currentContext] restoreGraphicsState];
615 NSRect knobRect = [[self cell] knobRectFlipped:NO];
616 knobRect.origin.y+=7.5;
617 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
618 [self drawKnobInRect: knobRect];
623 /*****************************************************************************
625 *****************************************************************************/
626 @implementation VLCFSVolumeSlider
627 - (void)drawKnobInRect:(NSRect) knobRect
630 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
631 image_rect.size = [img size];
632 image_rect.origin.x = 0;
633 image_rect.origin.y = 0;
634 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
635 knobRect.size.width = image_rect.size.width;
636 knobRect.size.height = image_rect.size.height;
637 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
640 - (void)drawRect:(NSRect)rect
642 /* Draw default to make sure the slider behaves correctly */
643 [[NSGraphicsContext currentContext] saveGraphicsState];
644 NSRectClip(NSZeroRect);
645 [super drawRect:rect];
646 [[NSGraphicsContext currentContext] restoreGraphicsState];
648 NSRect knobRect = [[self cell] knobRectFlipped:NO];
649 knobRect.origin.y+=6;
650 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
651 [self drawKnobInRect: knobRect];