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:(unsigned int)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] getControls] getVoutView] isFullscreen] )
188 /* This routine is called repeatedly to fade in the window */
189 - (void)focus:(NSTimer *)timer
191 /* we need to push ourselves to front if the vout window was closed since our last display */
192 if( b_voutWasUpdated )
194 [self orderFront: self];
195 b_voutWasUpdated = NO;
198 if( [self alphaValue] < 1.0 )
199 [self setAlphaValue:[self alphaValue]+0.1];
200 if( [self alphaValue] >= 1.0 )
203 [self setAlphaValue: 1.0];
204 [self setFadeTimer:nil];
208 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
213 /* This routine is called repeatedly to hide the window */
214 - (void)unfocus:(NSTimer *)timer
220 [self setFadeTimer: NULL];
224 if( [self alphaValue] > 0.0 )
225 [self setAlphaValue:[self alphaValue]-0.05];
226 if( [self alphaValue] <= 0.05 )
229 [self setAlphaValue:0.0];
230 [self setFadeTimer:nil];
235 [NSTimer scheduledTimerWithTimeInterval:0.1
237 selector:@selector(focus:)
244 - (void)mouseExited:(NSEvent *)theEvent
246 /* give up our focus, so the vout may show us again without letting the user clicking it */
247 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
248 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
253 [NSCursor setHiddenUntilMouseMoves: YES];
258 /* in case that the user don't want us to appear, make sure we hide the mouse */
260 if( !config_GetInt( VLCIntf, "macosx-fspanel" ) )
262 float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.;
263 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]];
270 [self orderFront: nil];
272 if( [self alphaValue] < 1.0 || b_displayed != YES )
274 if (![self fadeTimer])
275 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
276 else if ([[[self fadeTimer] userInfo] shortValue]==0)
284 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
287 if( ( [self alphaValue] > 0.0 ) )
289 if (![self fadeTimer])
290 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
291 else if ([[[self fadeTimer] userInfo] shortValue]==1)
296 /* triggers a timer to autoHide us again after some seconds of no activity */
299 /* this will tell the timer to start over again or to start at all */
302 /* get us a valid timer */
303 if(! b_alreadyCounting )
305 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
308 [hideAgainTimer invalidate];
309 [hideAgainTimer autorelease];
311 /* released in -autoHide and -dealloc */
312 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
314 selector: @selector(keepVisible:)
316 repeats: YES] retain];
317 b_alreadyCounting = YES;
321 - (void)keepVisible:(NSTimer *)timer
323 /* if the user triggered an action, start over again */
327 /* count down until we hide ourselfes again and do so if necessary */
328 if( --i_timeToKeepVisibleInSec < 1 )
332 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
333 b_alreadyCounting = NO;
337 /* A getter and setter for our main timer that handles window fading */
338 - (NSTimer *)fadeTimer
343 - (void)setFadeTimer:(NSTimer *)timer
346 [fadeTimer invalidate];
347 [fadeTimer autorelease];
351 - (void)mouseDown:(NSEvent *)theEvent
353 mouseClic = [theEvent locationInWindow];
356 - (void)mouseDragged:(NSEvent *)theEvent
358 NSPoint point = [NSEvent mouseLocation];
359 point.x -= mouseClic.x;
360 point.y -= mouseClic.y;
361 [self setFrameOrigin:point];
369 - (void)setVoutWasUpdated: (int)i_newdevice;
371 b_voutWasUpdated = YES;
372 if( i_newdevice != i_device )
374 i_device = i_newdevice;
380 /*****************************************************************************
382 *****************************************************************************/
383 @implementation VLCFSPanelView
385 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
386 s_rc.origin.x = _x; \
387 s_rc.origin.y = _y; \
388 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
389 [o_button setButtonType: NSMomentaryChangeButton]; \
390 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
391 [o_button setBordered: NO]; \
392 [o_button setFont:[NSFont systemFontOfSize:0]]; \
393 [o_button setImage:[NSImage imageNamed:imageOff]]; \
394 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
395 [o_button sizeToFit]; \
396 [o_button setTarget: self]; \
397 [o_button setAction: @selector(action:)]; \
398 [self addSubview:o_button];
400 #define addTextfield( o_text, align, font, color, size ) \
401 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
402 [o_text setDrawsBackground: NO]; \
403 [o_text setBordered: NO]; \
404 [o_text setEditable: NO]; \
405 [o_text setSelectable: NO]; \
406 [o_text setStringValue: _NS("(no item is being played)")]; \
407 [o_text setAlignment: align]; \
408 [o_text setTextColor: [NSColor color]]; \
409 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
410 [self addSubview:o_text];
412 - (id)initWithFrame:(NSRect)frameRect
414 id view = [super initWithFrame:frameRect];
415 fillColor = [[NSColor clearColor] retain];
416 NSRect s_rc = [self frame];
417 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
418 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
419 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
420 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
421 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
422 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
424 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
431 s_rc.size.width = 518;
432 s_rc.size.height = 9;
433 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
434 [o_fs_timeSlider setMinValue:0];
435 [o_fs_timeSlider setMaxValue:10000];
436 [o_fs_timeSlider setFloatValue: 0];
437 [o_fs_timeSlider setContinuous: YES];
438 [o_fs_timeSlider setTarget: self];
439 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
440 [self addSubview: o_fs_timeSlider];
445 s_rc.origin.y = 17.5;
446 s_rc.size.width = 95;
447 s_rc.size.height = 10;
448 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
449 [o_fs_volumeSlider setMinValue:0];
450 [o_fs_volumeSlider setMaxValue:32];
451 [o_fs_volumeSlider setFloatValue: 0];
452 [o_fs_volumeSlider setContinuous: YES];
453 [o_fs_volumeSlider setTarget: self];
454 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
455 [self addSubview: o_fs_volumeSlider];
457 /* time counter and stream title output fields */
461 s_rc.size.width = 352;
462 s_rc.size.height = 14;
463 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
466 s_rc.size.width = 50;
467 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
474 [o_fs_timeSlider release];
475 [o_fs_volumeSlider release];
481 [o_fullscreen release];
482 [o_streamTitle_txt release];
483 [o_streamPosition_txt release];
489 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
490 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
495 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
496 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
499 - (void)setStreamTitle:(NSString *)o_title
501 [o_streamTitle_txt setStringValue: o_title];
504 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
506 [o_streamPosition_txt setStringValue: o_time];
507 [o_fs_timeSlider setFloatValue: f_pos];
510 - (void)setSeekable:(BOOL)b_seekable
512 [o_bwd setEnabled: b_seekable];
513 [o_fwd setEnabled: b_seekable];
514 [o_fs_timeSlider setEnabled: b_seekable];
517 - (void)setVolumeLevel: (float)f_volumeLevel
519 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
522 - (IBAction)play:(id)sender
524 [[[VLCMain sharedInstance] getControls] play: sender];
527 - (IBAction)forward:(id)sender
529 [[[VLCMain sharedInstance] getControls] forward: sender];
532 - (IBAction)backward:(id)sender
534 [[[VLCMain sharedInstance] getControls] backward: sender];
537 - (IBAction)prev:(id)sender
539 [[[VLCMain sharedInstance] getControls] prev: sender];
542 - (IBAction)next:(id)sender
544 [[[VLCMain sharedInstance] getControls] next: sender];
547 - (IBAction)windowAction:(id)sender
549 [[[VLCMain sharedInstance] getControls] windowAction: sender];
552 - (IBAction)fsTimeSliderUpdate:(id)sender
554 [[VLCMain sharedInstance] timesliderUpdate: sender];
557 - (IBAction)fsVolumeSliderUpdate:(id)sender
559 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
562 #define addImage(image, _x, _y, mode, _width) \
563 img = [NSImage imageNamed:image]; \
564 image_rect.size = [img size]; \
565 image_rect.origin.x = 0; \
566 image_rect.origin.y = 0; \
567 frame.origin.x = _x; \
568 frame.origin.y = _y; \
569 frame.size = [img size]; \
570 if( _width ) frame.size.width = _width; \
571 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
573 - (void)drawRect:(NSRect)rect
575 NSRect frame = [self frame];
578 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
579 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
580 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
581 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
582 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
587 /*****************************************************************************
589 *****************************************************************************/
590 @implementation VLCFSTimeSlider
591 - (void)drawKnobInRect:(NSRect)knobRect
594 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
595 image_rect.size = [img size];
596 image_rect.origin.x = 0;
597 image_rect.origin.y = 0;
598 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
599 knobRect.size.width = image_rect.size.width;
600 knobRect.size.height = image_rect.size.height;
601 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
604 - (void)drawRect:(NSRect)rect
606 /* Draw default to make sure the slider behaves correctly */
607 [[NSGraphicsContext currentContext] saveGraphicsState];
608 NSRectClip(NSZeroRect);
609 [super drawRect:rect];
610 [[NSGraphicsContext currentContext] restoreGraphicsState];
612 NSRect knobRect = [[self cell] knobRectFlipped:NO];
613 knobRect.origin.y+=7.5;
614 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
615 [self drawKnobInRect: knobRect];
620 /*****************************************************************************
622 *****************************************************************************/
623 @implementation VLCFSVolumeSlider
624 - (void)drawKnobInRect:(NSRect) knobRect
627 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
628 image_rect.size = [img size];
629 image_rect.origin.x = 0;
630 image_rect.origin.y = 0;
631 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
632 knobRect.size.width = image_rect.size.width;
633 knobRect.size.height = image_rect.size.height;
634 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
637 - (void)drawRect:(NSRect)rect
639 /* Draw default to make sure the slider behaves correctly */
640 [[NSGraphicsContext currentContext] saveGraphicsState];
641 NSRectClip(NSZeroRect);
642 [super drawRect:rect];
643 [[NSGraphicsContext currentContext] restoreGraphicsState];
645 NSRect knobRect = [[self cell] knobRectFlipped:NO];
646 knobRect.origin.y+=6;
647 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
648 [self drawKnobInRect: knobRect];