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"
33 #import "MainWindow.h"
35 @interface VLCFSPanel ()
39 /*****************************************************************************
41 *****************************************************************************/
42 @implementation VLCFSPanel
43 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
44 - (id)initWithContentRect:(NSRect)contentRect
45 styleMask:(NSUInteger)aStyle
46 backing:(NSBackingStoreType)bufferingType
49 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
51 [win setHasShadow: NO];
52 [win setBackgroundColor:[NSColor clearColor]];
54 /* let the window sit on top of everything else and start out completely transparent */
55 [win setLevel:NSModalPanelWindowLevel];
58 hideAgainTimer = fadeTimer = nil;
59 [self setNonActive:nil];
65 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
66 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
67 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
69 [self mouseEntered:NULL];
71 [self mouseExited:NULL];
73 /* get a notification if VLC isn't the active app anymore */
74 [[NSNotificationCenter defaultCenter]
76 selector: @selector(setNonActive:)
77 name: NSApplicationDidResignActiveNotification
80 /* get a notification if VLC is the active app again */
81 [[NSNotificationCenter defaultCenter]
83 selector: @selector(setActive:)
84 name: NSApplicationDidBecomeActiveNotification
88 /* make sure that we don't become key, since we can't handle hotkeys */
89 - (BOOL)canBecomeKeyWindow
94 - (BOOL)mouseDownCanMoveWindow
101 [[NSNotificationCenter defaultCenter] removeObserver: self];
105 [hideAgainTimer invalidate];
106 [hideAgainTimer release];
108 [self setFadeTimer:nil];
114 /* centre the panel in the lower third of the screen */
115 NSPoint theCoordinate;
116 NSRect theScreensFrame;
117 NSRect theWindowsFrame;
120 /* user-defined screen */
121 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
125 /* invalid preferences or none specified, using main screen */
126 screen = [NSScreen mainScreen];
129 theScreensFrame = [screen frame];
131 theWindowsFrame = [self frame];
133 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
134 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
135 [self setFrameTopLeftPoint: theCoordinate];
140 [[self contentView] setPlay];
145 [[self contentView] setPause];
148 - (void)setStreamTitle:(NSString *)o_title
150 [[self contentView] setStreamTitle: o_title];
153 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
155 [[self contentView] setStreamPos:f_pos andTime: o_time];
158 - (void)setSeekable:(BOOL) b_seekable
160 [[self contentView] setSeekable: b_seekable];
163 - (void)setVolumeLevel: (float)f_volumeLevel
165 [[self contentView] setVolumeLevel: f_volumeLevel];
168 - (void)setNonActive:(id)noData
171 [self orderOut: self];
173 /* here's fadeOut, just without visibly fading */
175 [self setAlphaValue:0.0];
176 [self setFadeTimer:nil];
180 - (void)setActive:(id)noData
182 if( [[VLCCoreInteraction sharedInstance] voutView] != nil )
184 if( [[[VLCCoreInteraction sharedInstance] voutView] isFullscreen] )
192 /* This routine is called repeatedly to fade in the window */
193 - (void)focus:(NSTimer *)timer
195 /* we need to push ourselves to front if the vout window was closed since our last display */
196 if( b_voutWasUpdated )
198 [self orderFront: self];
199 b_voutWasUpdated = NO;
202 if( [self alphaValue] < 1.0 )
203 [self setAlphaValue:[self alphaValue]+0.1];
204 if( [self alphaValue] >= 1.0 )
207 [self setAlphaValue: 1.0];
208 [self setFadeTimer:nil];
212 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
217 /* This routine is called repeatedly to hide the window */
218 - (void)unfocus:(NSTimer *)timer
224 [self setFadeTimer: NULL];
228 if( [self alphaValue] > 0.0 )
229 [self setAlphaValue:[self alphaValue]-0.05];
230 if( [self alphaValue] <= 0.05 )
233 [self setAlphaValue:0.0];
234 [self setFadeTimer:nil];
239 [NSTimer scheduledTimerWithTimeInterval:0.1
241 selector:@selector(focus:)
248 - (void)mouseExited:(NSEvent *)theEvent
250 /* give up our focus, so the vout may show us again without letting the user clicking it */
251 if( [[[VLCCoreInteraction sharedInstance] voutView] isFullscreen] )
252 [[[[VLCCoreInteraction sharedInstance] voutView] window] makeKeyWindow];
257 [NSCursor setHiddenUntilMouseMoves: YES];
262 /* in case that the user don't want us to appear, make sure we hide the mouse */
264 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
266 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
267 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
274 [self orderFront: nil];
276 if( [self alphaValue] < 1.0 || b_displayed != YES )
278 if (![self fadeTimer])
279 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
280 else if ([[[self fadeTimer] userInfo] shortValue]==0)
288 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
291 if( ( [self alphaValue] > 0.0 ) )
293 if (![self fadeTimer])
294 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
295 else if ([[[self fadeTimer] userInfo] shortValue]==1)
300 /* triggers a timer to autoHide us again after some seconds of no activity */
303 /* this will tell the timer to start over again or to start at all */
306 /* get us a valid timer */
307 if(! b_alreadyCounting )
309 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
312 [hideAgainTimer invalidate];
313 [hideAgainTimer autorelease];
315 /* released in -autoHide and -dealloc */
316 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
318 selector: @selector(keepVisible:)
320 repeats: YES] retain];
321 b_alreadyCounting = YES;
325 - (void)keepVisible:(NSTimer *)timer
327 /* if the user triggered an action, start over again */
331 /* count down until we hide ourselfes again and do so if necessary */
332 if( --i_timeToKeepVisibleInSec < 1 )
336 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
337 b_alreadyCounting = NO;
341 /* A getter and setter for our main timer that handles window fading */
342 - (NSTimer *)fadeTimer
347 - (void)setFadeTimer:(NSTimer *)timer
350 [fadeTimer invalidate];
351 [fadeTimer autorelease];
355 - (void)mouseDown:(NSEvent *)theEvent
357 mouseClic = [theEvent locationInWindow];
360 - (void)mouseDragged:(NSEvent *)theEvent
362 NSPoint point = [NSEvent mouseLocation];
363 point.x -= mouseClic.x;
364 point.y -= mouseClic.y;
365 [self setFrameOrigin:point];
373 - (void)setVoutWasUpdated: (int)i_newdevice;
375 b_voutWasUpdated = YES;
376 if( i_newdevice != i_device )
378 i_device = i_newdevice;
384 /*****************************************************************************
386 *****************************************************************************/
387 @implementation VLCFSPanelView
389 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
390 s_rc.origin.x = _x; \
391 s_rc.origin.y = _y; \
392 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
393 [o_button setButtonType: NSMomentaryChangeButton]; \
394 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
395 [o_button setBordered: NO]; \
396 [o_button setFont:[NSFont systemFontOfSize:0]]; \
397 [o_button setImage:[NSImage imageNamed:imageOff]]; \
398 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
399 [o_button sizeToFit]; \
400 [o_button setTarget: self]; \
401 [o_button setAction: @selector(action:)]; \
402 [self addSubview:o_button];
404 #define addTextfield( class, o_text, align, font, color, size ) \
405 o_text = [[class alloc] initWithFrame: s_rc]; \
406 [o_text setDrawsBackground: NO]; \
407 [o_text setBordered: NO]; \
408 [o_text setEditable: NO]; \
409 [o_text setSelectable: NO]; \
410 [o_text setStringValue: _NS("(no item is being played)")]; \
411 [o_text setAlignment: align]; \
412 [o_text setTextColor: [NSColor color]]; \
413 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
414 [self addSubview:o_text];
416 - (id)initWithFrame:(NSRect)frameRect
418 id view = [super initWithFrame:frameRect];
419 fillColor = [[NSColor clearColor] retain];
420 NSRect s_rc = [self frame];
421 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
422 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
423 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
424 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
425 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
426 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
428 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
435 s_rc.size.width = 518;
436 s_rc.size.height = 9;
437 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
438 [o_fs_timeSlider setMinValue:0];
439 [o_fs_timeSlider setMaxValue:10000];
440 [o_fs_timeSlider setFloatValue: 0];
441 [o_fs_timeSlider setContinuous: YES];
442 [o_fs_timeSlider setTarget: self];
443 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
444 [self addSubview: o_fs_timeSlider];
449 s_rc.origin.y = 17.5;
450 s_rc.size.width = 95;
451 s_rc.size.height = 10;
452 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
453 [o_fs_volumeSlider setMinValue:0];
454 [o_fs_volumeSlider setMaxValue:32];
455 [o_fs_volumeSlider setFloatValue: 0];
456 [o_fs_volumeSlider setContinuous: YES];
457 [o_fs_volumeSlider setTarget: self];
458 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
459 [self addSubview: o_fs_volumeSlider];
461 /* time counter and stream title output fields */
465 s_rc.size.width = 352;
466 s_rc.size.height = 14;
467 addTextfield( NSTextField, o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
470 s_rc.size.width = 55;
471 addTextfield( VLCTimeField, o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
478 [o_fs_timeSlider release];
479 [o_fs_volumeSlider release];
485 [o_fullscreen release];
486 [o_streamTitle_txt release];
487 [o_streamPosition_txt release];
493 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
494 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
499 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
500 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
503 - (void)setStreamTitle:(NSString *)o_title
505 [o_streamTitle_txt setStringValue: o_title];
508 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
510 [o_streamPosition_txt setStringValue: o_time];
511 [o_fs_timeSlider setFloatValue: f_pos];
514 - (void)setSeekable:(BOOL)b_seekable
516 [o_bwd setEnabled: b_seekable];
517 [o_fwd setEnabled: b_seekable];
518 [o_fs_timeSlider setEnabled: b_seekable];
521 - (void)setVolumeLevel: (float)f_volumeLevel
523 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
526 - (IBAction)play:(id)sender
528 [[[VLCMain sharedInstance] controls] play: sender];
531 - (IBAction)forward:(id)sender
533 [[[VLCMain sharedInstance] controls] forward: sender];
536 - (IBAction)backward:(id)sender
538 [[[VLCMain sharedInstance] controls] backward: sender];
541 - (IBAction)prev:(id)sender
543 [[[VLCMain sharedInstance] controls] prev: sender];
546 - (IBAction)next:(id)sender
548 [[[VLCMain sharedInstance] controls] next: sender];
551 - (IBAction)windowAction:(id)sender
553 [[[VLCMain sharedInstance] controls] windowAction: sender];
556 - (IBAction)fsTimeSliderUpdate:(id)sender
558 [[VLCMainWindow sharedInstance] updateTimeSlider];
561 - (IBAction)fsVolumeSliderUpdate:(id)sender
563 [[VLCCoreInteraction sharedInstance] setVolume: [sender intValue]];
566 #define addImage(image, _x, _y, mode, _width) \
567 img = [NSImage imageNamed:image]; \
568 image_rect.size = [img size]; \
569 image_rect.origin.x = 0; \
570 image_rect.origin.y = 0; \
571 frame.origin.x = _x; \
572 frame.origin.y = _y; \
573 frame.size = [img size]; \
574 if( _width ) frame.size.width = _width; \
575 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
577 - (void)drawRect:(NSRect)rect
579 NSRect frame = [self frame];
582 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
583 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
584 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
585 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
586 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
591 /*****************************************************************************
593 *****************************************************************************/
594 @implementation VLCFSTimeSlider
595 - (void)drawKnobInRect:(NSRect)knobRect
598 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
599 image_rect.size = [img size];
600 image_rect.origin.x = 0;
601 image_rect.origin.y = 0;
602 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
603 knobRect.size.width = image_rect.size.width;
604 knobRect.size.height = image_rect.size.height;
605 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
608 - (void)drawRect:(NSRect)rect
610 /* Draw default to make sure the slider behaves correctly */
611 [[NSGraphicsContext currentContext] saveGraphicsState];
612 NSRectClip(NSZeroRect);
613 [super drawRect:rect];
614 [[NSGraphicsContext currentContext] restoreGraphicsState];
616 NSRect knobRect = [[self cell] knobRectFlipped:NO];
617 knobRect.origin.y+=7.5;
618 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
619 [self drawKnobInRect: knobRect];
624 /*****************************************************************************
626 *****************************************************************************/
627 @implementation VLCFSVolumeSlider
628 - (void)drawKnobInRect:(NSRect) knobRect
631 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
632 image_rect.size = [img size];
633 image_rect.origin.x = 0;
634 image_rect.origin.y = 0;
635 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
636 knobRect.size.width = image_rect.size.width;
637 knobRect.size.height = image_rect.size.height;
638 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
641 - (void)drawRect:(NSRect)rect
643 /* Draw default to make sure the slider behaves correctly */
644 [[NSGraphicsContext currentContext] saveGraphicsState];
645 NSRectClip(NSZeroRect);
646 [super drawRect:rect];
647 [[NSGraphicsContext currentContext] restoreGraphicsState];
649 NSRect knobRect = [[self cell] knobRectFlipped:NO];
650 knobRect.origin.y+=6;
651 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
652 [self drawKnobInRect: knobRect];