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 /*****************************************************************************
36 *****************************************************************************/
37 @implementation VLCFSPanel
38 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
39 - (id)initWithContentRect:(NSRect)contentRect
40 styleMask:(unsigned int)aStyle
41 backing:(NSBackingStoreType)bufferingType
44 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
46 [win setHasShadow: NO];
47 [win setBackgroundColor:[NSColor clearColor]];
49 /* let the window sit on top of everything else and start out completely transparent */
50 [win setLevel:NSModalPanelWindowLevel];
53 hideAgainTimer = fadeTimer = nil;
54 [self setNonActive:nil];
60 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
61 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
62 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
64 [self mouseEntered:NULL];
66 [self mouseExited:NULL];
68 /* get a notification if VLC isn't the active app anymore */
69 [[NSNotificationCenter defaultCenter]
71 selector: @selector(setNonActive:)
72 name: NSApplicationDidResignActiveNotification
75 /* get a notification if VLC is the active app again */
76 [[NSNotificationCenter defaultCenter]
78 selector: @selector(setActive:)
79 name: NSApplicationDidBecomeActiveNotification
83 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
84 - (BOOL)canBecomeKeyWindow
89 - (BOOL)mouseDownCanMoveWindow
96 [[NSNotificationCenter defaultCenter] removeObserver: self];
100 [hideAgainTimer invalidate];
101 [hideAgainTimer release];
103 [self setFadeTimer:nil];
109 /* centre the panel in the lower third of the screen */
110 NSPoint theCoordinate;
111 NSRect theScreensFrame;
112 NSRect theWindowsFrame;
115 /* user-defined screen */
116 screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device];
120 /* invalid preferences or none specified, using main screen */
121 screen = [NSScreen mainScreen];
124 theScreensFrame = [screen frame];
126 theWindowsFrame = [self frame];
128 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
129 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
130 [self setFrameTopLeftPoint: theCoordinate];
135 [[self contentView] setPlay];
140 [[self contentView] setPause];
143 - (void)setStreamTitle:(NSString *)o_title
145 [[self contentView] setStreamTitle: o_title];
148 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
150 [[self contentView] setStreamPos:f_pos andTime: o_time];
153 - (void)setSeekable:(BOOL) b_seekable
155 [[self contentView] setSeekable: b_seekable];
158 - (void)setVolumeLevel: (float)f_volumeLevel
160 [[self contentView] setVolumeLevel: f_volumeLevel];
163 - (void)setNonActive:(id)noData
166 [self orderOut: self];
168 /* here's fadeOut, just without visibly fading */
170 [self setAlphaValue:0.0];
171 [self setFadeTimer:nil];
175 - (void)setActive:(id)noData
177 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
184 /* This routine is called repeatedly to fade in the window */
185 - (void)focus:(NSTimer *)timer
187 /* we need to push ourselves to front if the vout window was closed since our last display */
188 if( b_voutWasUpdated )
190 [self orderFront: self];
191 b_voutWasUpdated = NO;
194 if( [self alphaValue] < 1.0 )
195 [self setAlphaValue:[self alphaValue]+0.1];
196 if( [self alphaValue] >= 1.0 )
199 [self setAlphaValue: 1.0];
200 [self setFadeTimer:nil];
204 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
209 /* This routine is called repeatedly to hide the window */
210 - (void)unfocus:(NSTimer *)timer
216 [self setFadeTimer: NULL];
220 if( [self alphaValue] > 0.0 )
221 [self setAlphaValue:[self alphaValue]-0.05];
222 if( [self alphaValue] <= 0.05 )
225 [self setAlphaValue:0.0];
226 [self setFadeTimer:nil];
231 [NSTimer scheduledTimerWithTimeInterval:0.1
233 selector:@selector(focus:)
240 - (void)mouseExited:(NSEvent *)theEvent
242 /* give up our focus, so the vout may show us again without letting the user clicking it */
243 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
244 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
249 /* in case that the user don't want us to appear, just return here */
250 if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
253 [self orderFront: nil];
255 if( [self alphaValue] < 1.0 || b_displayed != YES )
257 if (![self fadeTimer])
258 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
259 else if ([[[self fadeTimer] userInfo] shortValue]==0)
267 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
270 if( ( [self alphaValue] > 0.0 ) )
272 if (![self fadeTimer])
273 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
274 else if ([[[self fadeTimer] userInfo] shortValue]==1)
279 /* triggers a timer to autoHide us again after some seconds of no activity */
282 /* this will tell the timer to start over again or to start at all */
285 /* get us a valid timer */
286 if(! b_alreadyCounting )
288 i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500;
291 [hideAgainTimer invalidate];
292 [hideAgainTimer autorelease];
294 /* released in -autoHide and -dealloc */
295 hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
297 selector: @selector(keepVisible:)
299 repeats: YES] retain];
300 b_alreadyCounting = YES;
304 - (void)keepVisible:(NSTimer *)timer
306 /* if the user triggered an action, start over again */
310 /* count down until we hide ourselfes again and do so if necessary */
311 if( --i_timeToKeepVisibleInSec < 1 )
313 [NSCursor setHiddenUntilMouseMoves: YES];
315 [hideAgainTimer invalidate]; /* released in -autoHide and -dealloc */
316 b_alreadyCounting = NO;
320 /* A getter and setter for our main timer that handles window fading */
321 - (NSTimer *)fadeTimer
326 - (void)setFadeTimer:(NSTimer *)timer
329 [fadeTimer invalidate];
330 [fadeTimer autorelease];
334 - (void)mouseDown:(NSEvent *)theEvent
336 mouseClic = [theEvent locationInWindow];
339 - (void)mouseDragged:(NSEvent *)theEvent
341 NSPoint point = [NSEvent mouseLocation];
342 point.x -= mouseClic.x;
343 point.y -= mouseClic.y;
344 [self setFrameOrigin:point];
352 - (void)setVoutWasUpdated: (int)i_newdevice;
354 b_voutWasUpdated = YES;
355 if( i_newdevice != i_device )
357 i_device = i_newdevice;
363 /*****************************************************************************
365 *****************************************************************************/
366 @implementation VLCFSPanelView
368 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
369 s_rc.origin.x = _x; \
370 s_rc.origin.y = _y; \
371 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
372 [o_button setButtonType: NSMomentaryChangeButton]; \
373 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
374 [o_button setBordered: NO]; \
375 [o_button setFont:[NSFont systemFontOfSize:0]]; \
376 [o_button setImage:[NSImage imageNamed:imageOff]]; \
377 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
378 [o_button sizeToFit]; \
379 [o_button setTarget: self]; \
380 [o_button setAction: @selector(action:)]; \
381 [self addSubview:o_button];
383 #define addTextfield( o_text, align, font, color, size ) \
384 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
385 [o_text setDrawsBackground: NO]; \
386 [o_text setBordered: NO]; \
387 [o_text setEditable: NO]; \
388 [o_text setSelectable: NO]; \
389 [o_text setStringValue: _NS("(no item is being played)")]; \
390 [o_text setAlignment: align]; \
391 [o_text setTextColor: [NSColor color]]; \
392 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
393 [self addSubview:o_text];
395 - (id)initWithFrame:(NSRect)frameRect
397 id view = [super initWithFrame:frameRect];
398 fillColor = [[NSColor clearColor] retain];
399 NSRect s_rc = [self frame];
400 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
401 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
402 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
403 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
404 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
405 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
407 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
414 s_rc.size.width = 518;
415 s_rc.size.height = 9;
416 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
417 [o_fs_timeSlider setMinValue:0];
418 [o_fs_timeSlider setMaxValue:10000];
419 [o_fs_timeSlider setFloatValue: 0];
420 [o_fs_timeSlider setContinuous: YES];
421 [o_fs_timeSlider setTarget: self];
422 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
423 [self addSubview: o_fs_timeSlider];
428 s_rc.origin.y = 17.5;
429 s_rc.size.width = 95;
430 s_rc.size.height = 10;
431 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
432 [o_fs_volumeSlider setMinValue:0];
433 [o_fs_volumeSlider setMaxValue:32];
434 [o_fs_volumeSlider setFloatValue: 0];
435 [o_fs_volumeSlider setContinuous: YES];
436 [o_fs_volumeSlider setTarget: self];
437 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
438 [self addSubview: o_fs_volumeSlider];
440 /* time counter and stream title output fields */
444 s_rc.size.width = 352;
445 s_rc.size.height = 14;
446 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
449 s_rc.size.width = 50;
450 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
457 [o_fs_timeSlider release];
458 [o_fs_volumeSlider release];
464 [o_fullscreen release];
465 [o_streamTitle_txt release];
466 [o_streamPosition_txt release];
472 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
473 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
478 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
479 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
482 - (void)setStreamTitle:(NSString *)o_title
484 [o_streamTitle_txt setStringValue: o_title];
487 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
489 [o_streamPosition_txt setStringValue: o_time];
490 [o_fs_timeSlider setFloatValue: f_pos];
493 - (void)setSeekable:(BOOL)b_seekable
495 [o_bwd setEnabled: b_seekable];
496 [o_fwd setEnabled: b_seekable];
497 [o_fs_timeSlider setEnabled: b_seekable];
500 - (void)setVolumeLevel: (float)f_volumeLevel
502 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
505 - (IBAction)play:(id)sender
507 [[[VLCMain sharedInstance] getControls] play: sender];
510 - (IBAction)forward:(id)sender
512 [[[VLCMain sharedInstance] getControls] forward: sender];
515 - (IBAction)backward:(id)sender
517 [[[VLCMain sharedInstance] getControls] backward: sender];
520 - (IBAction)prev:(id)sender
522 [[[VLCMain sharedInstance] getControls] prev: sender];
525 - (IBAction)next:(id)sender
527 [[[VLCMain sharedInstance] getControls] next: sender];
530 - (IBAction)windowAction:(id)sender
532 [[[VLCMain sharedInstance] getControls] windowAction: sender];
535 - (IBAction)fsTimeSliderUpdate:(id)sender
537 [[VLCMain sharedInstance] timesliderUpdate: sender];
540 - (IBAction)fsVolumeSliderUpdate:(id)sender
542 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
545 #define addImage(image, _x, _y, mode, _width) \
546 img = [NSImage imageNamed:image]; \
547 image_rect.size = [img size]; \
548 image_rect.origin.x = 0; \
549 image_rect.origin.y = 0; \
550 frame.origin.x = _x; \
551 frame.origin.y = _y; \
552 frame.size = [img size]; \
553 if( _width ) frame.size.width = _width; \
554 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
556 - (void)drawRect:(NSRect)rect
558 NSRect frame = [self frame];
561 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
562 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
563 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
564 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
565 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
570 /*****************************************************************************
572 *****************************************************************************/
573 @implementation VLCFSTimeSlider
574 - (void)drawKnobInRect:(NSRect)knobRect
577 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
578 image_rect.size = [img size];
579 image_rect.origin.x = 0;
580 image_rect.origin.y = 0;
581 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
582 knobRect.size.width = image_rect.size.width;
583 knobRect.size.height = image_rect.size.height;
584 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
587 - (void)drawRect:(NSRect)rect
589 /* Draw default to make sure the slider behaves correctly */
590 [[NSGraphicsContext currentContext] saveGraphicsState];
591 NSRectClip(NSZeroRect);
592 [super drawRect:rect];
593 [[NSGraphicsContext currentContext] restoreGraphicsState];
595 NSRect knobRect = [[self cell] knobRectFlipped:NO];
596 knobRect.origin.y+=7.5;
597 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
598 [self drawKnobInRect: knobRect];
603 /*****************************************************************************
605 *****************************************************************************/
606 @implementation VLCFSVolumeSlider
607 - (void)drawKnobInRect:(NSRect) knobRect
610 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
611 image_rect.size = [img size];
612 image_rect.origin.x = 0;
613 image_rect.origin.y = 0;
614 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
615 knobRect.size.width = image_rect.size.width;
616 knobRect.size.height = image_rect.size.height;
617 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
620 - (void)drawRect:(NSRect)rect
622 /* Draw default to make sure the slider behaves correctly */
623 [[NSGraphicsContext currentContext] saveGraphicsState];
624 NSRectClip(NSZeroRect);
625 [super drawRect:rect];
626 [[NSGraphicsContext currentContext] restoreGraphicsState];
628 NSRect knobRect = [[self cell] knobRectFlipped:NO];
629 knobRect.origin.y+=6;
630 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
631 [self drawKnobInRect: knobRect];