1 /*****************************************************************************
\r
2 * fspanel.m: MacOS X full screen panel
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2006-2007 the VideoLAN team
\r
7 * Authors: J
\8er
\99me Decoodt <djc at videolan dot org>
\r
8 * Felix K
\9fhne <fkuehne at videolan dot org>
\r
10 * This program is free software; you can redistribute it and/or modify
\r
11 * it under the terms of the GNU General Public License as published by
\r
12 * the Free Software Foundation; either version 2 of the License, or
\r
13 * (at your option) any later version.
\r
15 * This program is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
18 * GNU General Public License for more details.
\r
20 * You should have received a copy of the GNU General Public License
\r
21 * along with this program; if not, write to the Free Software
\r
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
\r
23 *****************************************************************************/
\r
25 /*****************************************************************************
\r
27 *****************************************************************************/
\r
29 #import "controls.h"
\r
33 #define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after a user's action */
\r
35 /*****************************************************************************
\r
37 *****************************************************************************/
\r
38 @implementation VLCFSPanel
\r
39 /* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */
\r
40 - (id)initWithContentRect:(NSRect)contentRect
\r
41 styleMask:(unsigned int)aStyle
\r
42 backing:(NSBackingStoreType)bufferingType
\r
45 id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag];
\r
47 [win setHasShadow: NO];
\r
48 [win setBackgroundColor:[NSColor clearColor]];
\r
50 /* let the window sit on top of everything else and start out completely transparent */
\r
51 [win setLevel:NSModalPanelWindowLevel];
\r
52 [win setAlphaValue:0.0];
\r
59 - (void)awakeFromNib
\r
61 [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]];
\r
62 BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame]));
\r
63 [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside];
\r
65 [self mouseEntered:NULL];
\r
67 [self mouseExited:NULL];
\r
69 /* get a notification if VLC isn't the active app anymore */
\r
70 [[NSNotificationCenter defaultCenter]
\r
72 selector: @selector(setNonActive:)
\r
73 name: NSApplicationDidResignActiveNotification
\r
76 /* get a notification if VLC is the active app again */
\r
77 [[NSNotificationCenter defaultCenter]
\r
79 selector: @selector(setActive:)
\r
80 name: NSApplicationDidBecomeActiveNotification
\r
84 /* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */
\r
85 - (BOOL)canBecomeKeyWindow
\r
90 - (BOOL)mouseDownCanMoveWindow
\r
98 /* dealloc isn't called on 10.5 in case that GC is enabled, so we need to provide the functionality here */
\r
99 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
100 [self setFadeTimer:nil];
\r
108 [[NSNotificationCenter defaultCenter] removeObserver: self];
\r
110 if( hideAgainTimer )
\r
111 [hideAgainTimer release];
\r
112 [self setFadeTimer:nil];
\r
118 /* centre the panel in the lower third of the screen */
\r
119 NSPoint theCoordinate;
\r
120 NSRect theScreensFrame;
\r
121 NSRect theWindowsFrame;
\r
123 if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )
\r
124 /* invalid preferences or none specified, using main screen */
\r
125 theScreensFrame = [[NSScreen mainScreen] frame];
\r
127 /* user-defined screen */
\r
128 theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] frame];
\r
130 theWindowsFrame = [self frame];
\r
132 theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x;
\r
133 theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y;
\r
134 [self setFrameTopLeftPoint: theCoordinate];
\r
139 [[self contentView] setPlay];
\r
144 [[self contentView] setPause];
\r
147 - (void)setStreamTitle:(NSString *)o_title
\r
149 [[self contentView] setStreamTitle: o_title];
\r
152 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
154 [[self contentView] setStreamPos:f_pos andTime: o_time];
\r
157 - (void)setSeekable:(BOOL) b_seekable
\r
159 [[self contentView] setSeekable: b_seekable];
\r
162 - (void)setVolumeLevel: (float)f_volumeLevel
\r
164 [[self contentView] setVolumeLevel: f_volumeLevel];
\r
167 - (void)setNonActive:(id)noData
\r
170 [self orderOut: self];
\r
172 /* here's fadeOut, just without visibly fading */
\r
174 [self setAlphaValue:0.0];
\r
175 [self setFadeTimer:nil];
\r
179 - (void)setActive:(id)noData
\r
181 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
188 /* This routine is called repeatedly to fade in the window */
\r
189 - (void)focus:(NSTimer *)timer
\r
191 /* we need to push ourselves to front if the vout window was closed since our last display */
\r
192 if( b_voutWasUpdated )
\r
194 [self orderFront: self];
\r
195 b_voutWasUpdated = NO;
\r
198 if( [self alphaValue] < 1.0 )
\r
199 [self setAlphaValue:[self alphaValue]+0.1];
\r
200 if( [self alphaValue] >= 1.0 )
\r
203 [self setAlphaValue: 1.0];
\r
204 [self setFadeTimer:nil];
\r
208 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]];
\r
213 /* This routine is called repeatedly to hide the window */
\r
214 - (void)unfocus:(NSTimer *)timer
\r
216 if( b_keptVisible )
\r
218 b_keptVisible = NO;
\r
220 [self setFadeTimer: NULL];
\r
224 if( [self alphaValue] > 0.0 )
\r
225 [self setAlphaValue:[self alphaValue]-0.1];
\r
226 if( [self alphaValue] <= 0.1 )
\r
229 [self setAlphaValue:0.0];
\r
230 [self setFadeTimer:nil];
\r
234 [self setFadeTimer:
\r
235 [NSTimer scheduledTimerWithTimeInterval:0.1
\r
237 selector:@selector(focus:)
\r
244 - (void)mouseExited:(NSEvent *)theEvent
\r
246 /* give up our focus, so the vout may show us again without letting the user clicking it */
\r
247 if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] )
\r
248 [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];
\r
253 /* in case that the user don't want us to appear, just return here */
\r
254 if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || b_nonActive )
\r
257 [self orderFront: nil];
\r
259 if( [self alphaValue] < 1.0 || b_displayed != YES )
\r
261 if (![self fadeTimer])
\r
262 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]];
\r
263 else if ([[[self fadeTimer] userInfo] shortValue]==0)
\r
271 if( NSPointInRect([NSEvent mouseLocation],[self frame]))
\r
274 if( ( [self alphaValue] > 0.0 ) )
\r
276 if (![self fadeTimer])
\r
277 [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]];
\r
278 else if ([[[self fadeTimer] userInfo] shortValue]==1)
\r
283 /* triggers a timer to autoHide us again after some seconds of no activity */
\r
286 /* this will tell the timer to start over again or to start at all */
\r
287 b_keptVisible = YES;
\r
289 /* get us a valid timer */
\r
290 if(! b_alreadyCounting )
\r
292 hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
\r
294 selector: @selector(keepVisible:)
\r
297 [hideAgainTimer fire];
\r
298 [hideAgainTimer retain];
\r
299 b_alreadyCounting = YES;
\r
303 - (void)keepVisible:(NSTimer *)timer
\r
305 /* if the user triggered an action, start over again */
\r
306 if( b_keptVisible )
\r
308 i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
\r
309 b_keptVisible = NO;
\r
312 /* count down until we hide ourselfes again and do so if necessary */
\r
313 i_timeToKeepVisibleInSec -= 1;
\r
314 if( i_timeToKeepVisibleInSec < 1 )
\r
317 [timer invalidate];
\r
319 b_alreadyCounting = NO;
\r
324 /* A getter and setter for our main timer that handles window fading */
\r
325 - (NSTimer *)fadeTimer
\r
330 - (void)setFadeTimer:(NSTimer *)timer
\r
333 [fadeTimer invalidate];
\r
334 [fadeTimer release];
\r
338 - (void)mouseDown:(NSEvent *)theEvent
\r
340 mouseClic = [theEvent locationInWindow];
\r
343 - (void)mouseDragged:(NSEvent *)theEvent
\r
345 NSPoint point = [NSEvent mouseLocation];
\r
346 point.x -= mouseClic.x;
\r
347 point.y -= mouseClic.y;
\r
348 [self setFrameOrigin:point];
\r
351 - (BOOL)isDisplayed
\r
353 return b_displayed;
\r
356 - (void)setVoutWasUpdated: (int)i_newdevice;
\r
358 b_voutWasUpdated = YES;
\r
359 if( i_newdevice != i_device )
\r
361 i_device = i_newdevice;
\r
367 /*****************************************************************************
\r
369 *****************************************************************************/
\r
370 @implementation VLCFSPanelView
\r
372 #define addButton( o_button, imageOff, imageOn, _x, _y, action ) \
\r
373 s_rc.origin.x = _x; \
\r
374 s_rc.origin.y = _y; \
\r
375 o_button = [[NSButton alloc] initWithFrame: s_rc]; \
\r
376 [o_button setButtonType: NSMomentaryChangeButton]; \
\r
377 [o_button setBezelStyle: NSRegularSquareBezelStyle]; \
\r
378 [o_button setBordered: NO]; \
\r
379 [o_button setFont:[NSFont systemFontOfSize:0]]; \
\r
380 [o_button setImage:[NSImage imageNamed:imageOff]]; \
\r
381 [o_button setAlternateImage:[NSImage imageNamed:imageOn]]; \
\r
382 [o_button sizeToFit]; \
\r
383 [o_button setTarget: self]; \
\r
384 [o_button setAction: @selector(action:)]; \
\r
385 [self addSubview:o_button];
\r
387 #define addTextfield( o_text, align, font, color, size ) \
\r
388 o_text = [[NSTextField alloc] initWithFrame: s_rc]; \
\r
389 [o_text setDrawsBackground: NO]; \
\r
390 [o_text setBordered: NO]; \
\r
391 [o_text setEditable: NO]; \
\r
392 [o_text setSelectable: NO]; \
\r
393 [o_text setStringValue: _NS("(no item is being played)")]; \
\r
394 [o_text setAlignment: align]; \
\r
395 [o_text setTextColor: [NSColor color]]; \
\r
396 [o_text setFont:[NSFont font:[NSFont smallSystemFontSize] - size]]; \
\r
397 [self addSubview:o_text];
\r
399 - (id)initWithFrame:(NSRect)frameRect
\r
401 id view = [super initWithFrame:frameRect];
\r
402 fillColor = [[NSColor clearColor] retain];
\r
403 NSRect s_rc = [self frame];
\r
404 addButton( o_prev, @"fs_skip_previous" , @"fs_skip_previous_highlight", 174, 15, prev );
\r
405 addButton( o_bwd, @"fs_rewind" , @"fs_rewind_highlight" , 211, 14, backward );
\r
406 addButton( o_play, @"fs_play" , @"fs_play_highlight" , 267, 10, play );
\r
407 addButton( o_fwd, @"fs_forward" , @"fs_forward_highlight" , 313, 14, forward );
\r
408 addButton( o_next, @"fs_skip_next" , @"fs_skip_next_highlight" , 365, 15, next );
\r
409 addButton( o_fullscreen, @"fs_exit_fullscreen", @"fs_exit_fullscreen_hightlight", 507, 13, windowAction );
\r
411 addButton( o_button, @"image (off state)", @"image (on state)", 38, 51, something );
\r
415 s_rc = [self frame];
\r
416 s_rc.origin.x = 15;
\r
417 s_rc.origin.y = 53;
\r
418 s_rc.size.width = 518;
\r
419 s_rc.size.height = 9;
\r
420 o_fs_timeSlider = [[VLCFSTimeSlider alloc] initWithFrame: s_rc];
\r
421 [o_fs_timeSlider setMinValue:0];
\r
422 [o_fs_timeSlider setMaxValue:10000];
\r
423 [o_fs_timeSlider setFloatValue: 0];
\r
424 [o_fs_timeSlider setContinuous: YES];
\r
425 [o_fs_timeSlider setTarget: self];
\r
426 [o_fs_timeSlider setAction: @selector(fsTimeSliderUpdate:)];
\r
427 [self addSubview: o_fs_timeSlider];
\r
429 /* volume slider */
\r
430 s_rc = [self frame];
\r
431 s_rc.origin.x = 26;
\r
432 s_rc.origin.y = 17.5;
\r
433 s_rc.size.width = 95;
\r
434 s_rc.size.height = 10;
\r
435 o_fs_volumeSlider = [[VLCFSVolumeSlider alloc] initWithFrame: s_rc];
\r
436 [o_fs_volumeSlider setMinValue:0];
\r
437 [o_fs_volumeSlider setMaxValue:32];
\r
438 [o_fs_volumeSlider setFloatValue: 0];
\r
439 [o_fs_volumeSlider setContinuous: YES];
\r
440 [o_fs_volumeSlider setTarget: self];
\r
441 [o_fs_volumeSlider setAction: @selector(fsVolumeSliderUpdate:)];
\r
442 [self addSubview: o_fs_volumeSlider];
\r
444 /* time counter and stream title output fields */
\r
445 s_rc = [self frame];
\r
446 s_rc.origin.x = 98;
\r
447 s_rc.origin.y = 64;
\r
448 s_rc.size.width = 352;
\r
449 s_rc.size.height = 14;
\r
450 addTextfield( o_streamTitle_txt, NSCenterTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
451 s_rc.origin.x = 486;
\r
452 s_rc.origin.y = 64;
\r
453 s_rc.size.width = 50;
\r
454 addTextfield( o_streamPosition_txt, NSRightTextAlignment, systemFontOfSize, whiteColor, 0 );
\r
461 [o_fs_timeSlider release];
\r
462 [o_fs_volumeSlider release];
\r
468 [o_fullscreen release];
\r
469 [o_streamTitle_txt release];
\r
470 [o_streamPosition_txt release];
\r
476 [o_play setImage:[NSImage imageNamed:@"fs_play"]];
\r
477 [o_play setAlternateImage: [NSImage imageNamed:@"fs_play_highlight"]];
\r
482 [o_play setImage: [NSImage imageNamed:@"fs_pause"]];
\r
483 [o_play setAlternateImage: [NSImage imageNamed:@"fs_pause_highlight"]];
\r
486 - (void)setStreamTitle:(NSString *)o_title
\r
488 [o_streamTitle_txt setStringValue: o_title];
\r
491 - (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time
\r
493 [o_streamPosition_txt setStringValue: o_time];
\r
494 [o_fs_timeSlider setFloatValue: f_pos];
\r
497 - (void)setSeekable:(BOOL)b_seekable
\r
499 [o_bwd setEnabled: b_seekable];
\r
500 [o_fwd setEnabled: b_seekable];
\r
501 [o_fs_timeSlider setEnabled: b_seekable];
\r
504 - (void)setVolumeLevel: (float)f_volumeLevel
\r
506 [o_fs_volumeSlider setFloatValue: f_volumeLevel];
\r
509 - (IBAction)play:(id)sender
\r
511 [[[VLCMain sharedInstance] getControls] play: sender];
\r
514 - (IBAction)forward:(id)sender
\r
516 [[[VLCMain sharedInstance] getControls] forward: sender];
\r
519 - (IBAction)backward:(id)sender
\r
521 [[[VLCMain sharedInstance] getControls] backward: sender];
\r
524 - (IBAction)prev:(id)sender
\r
526 [[[VLCMain sharedInstance] getControls] prev: sender];
\r
529 - (IBAction)next:(id)sender
\r
531 [[[VLCMain sharedInstance] getControls] next: sender];
\r
534 - (IBAction)windowAction:(id)sender
\r
536 [[[VLCMain sharedInstance] getControls] windowAction: sender];
\r
539 - (IBAction)fsTimeSliderUpdate:(id)sender
\r
541 [[VLCMain sharedInstance] timesliderUpdate: sender];
\r
544 - (IBAction)fsVolumeSliderUpdate:(id)sender
\r
546 [[[VLCMain sharedInstance] getControls] volumeSliderUpdated: sender];
\r
549 #define addImage(image, _x, _y, mode, _width) \
\r
550 img = [NSImage imageNamed:image]; \
\r
551 image_rect.size = [img size]; \
\r
552 image_rect.origin.x = 0; \
\r
553 image_rect.origin.y = 0; \
\r
554 frame.origin.x = _x; \
\r
555 frame.origin.y = _y; \
\r
556 frame.size = [img size]; \
\r
557 if( _width ) frame.size.width = _width; \
\r
558 [img drawInRect:frame fromRect:image_rect operation:mode fraction:1];
\r
560 - (void)drawRect:(NSRect)rect
\r
562 NSRect frame = [self frame];
\r
565 addImage( @"fs_background", 0, 0, NSCompositeCopy, 0 );
\r
566 addImage( @"fs_volume_slider_bar", 26, 22, NSCompositeSourceOver, 0 );
\r
567 addImage( @"fs_volume_mute", 16, 18, NSCompositeSourceOver, 0 );
\r
568 addImage( @"fs_volume_max", 124, 17, NSCompositeSourceOver, 0 );
\r
569 addImage( @"fs_time_slider", 15, 53, NSCompositeSourceOver, 0);
\r
574 /*****************************************************************************
\r
576 *****************************************************************************/
\r
577 @implementation VLCFSTimeSlider
\r
578 - (void)drawKnobInRect:(NSRect)knobRect
\r
581 NSImage *img = [NSImage imageNamed:@"fs_time_slider_knob_highlight"];
\r
582 image_rect.size = [img size];
\r
583 image_rect.origin.x = 0;
\r
584 image_rect.origin.y = 0;
\r
585 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
586 knobRect.size.width = image_rect.size.width;
\r
587 knobRect.size.height = image_rect.size.height;
\r
588 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
591 - (void)drawRect:(NSRect)rect
\r
593 /* Draw default to make sure the slider behaves correctly */
\r
594 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
595 NSRectClip(NSZeroRect);
\r
596 [super drawRect:rect];
\r
597 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
599 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
600 knobRect.origin.y+=7.5;
\r
601 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
602 [self drawKnobInRect: knobRect];
\r
607 /*****************************************************************************
\r
608 * VLCFSVolumeSlider
\r
609 *****************************************************************************/
\r
610 @implementation VLCFSVolumeSlider
\r
611 - (void)drawKnobInRect:(NSRect) knobRect
\r
614 NSImage *img = [NSImage imageNamed:@"fs_volume_slider_knob"];
\r
615 image_rect.size = [img size];
\r
616 image_rect.origin.x = 0;
\r
617 image_rect.origin.y = 0;
\r
618 knobRect.origin.x += (knobRect.size.width - image_rect.size.width) / 2;
\r
619 knobRect.size.width = image_rect.size.width;
\r
620 knobRect.size.height = image_rect.size.height;
\r
621 [img drawInRect:knobRect fromRect:image_rect operation:NSCompositeSourceOver fraction:1];
\r
624 - (void)drawRect:(NSRect)rect
\r
626 /* Draw default to make sure the slider behaves correctly */
\r
627 [[NSGraphicsContext currentContext] saveGraphicsState];
\r
628 NSRectClip(NSZeroRect);
\r
629 [super drawRect:rect];
\r
630 [[NSGraphicsContext currentContext] restoreGraphicsState];
\r
632 NSRect knobRect = [[self cell] knobRectFlipped:NO];
\r
633 knobRect.origin.y+=6;
\r
634 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
\r
635 [self drawKnobInRect: knobRect];
\r