📄 fspanel.m
字号:
/***************************************************************************** * fspanel.m: MacOS X full screen panel ***************************************************************************** * Copyright (C) 2006-2008 the VideoLAN team * $Id$ * * Authors: Jérôme Decoodt <djc at videolan dot org> * Felix Paul Kühne <fkuehne at videolan dot org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#import "intf.h"#import "controls.h"#import "vout.h"#import "misc.h"#import "fspanel.h"@interface VLCFSPanel ()- (void)hideMouse;@end/***************************************************************************** * VLCFSPanel *****************************************************************************/@implementation VLCFSPanel/* We override this initializer so we can set the NSBorderlessWindowMask styleMask, and set a few other important settings */- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag{ id win = [super initWithContentRect:contentRect styleMask:NSTexturedBackgroundWindowMask backing:bufferingType defer:flag]; [win setOpaque:NO]; [win setHasShadow: NO]; [win setBackgroundColor:[NSColor clearColor]]; /* let the window sit on top of everything else and start out completely transparent */ [win setLevel:NSModalPanelWindowLevel]; i_device = 0; [win center]; hideAgainTimer = fadeTimer = nil; [self setNonActive:nil]; return win;}- (void)awakeFromNib{ [self setContentView:[[VLCFSPanelView alloc] initWithFrame: [self frame]]]; BOOL isInside = (NSPointInRect([NSEvent mouseLocation],[self frame])); [[self contentView] addTrackingRect:[[self contentView] bounds] owner:self userData:nil assumeInside:isInside]; if (isInside) [self mouseEntered:NULL]; if (!isInside) [self mouseExited:NULL]; /* get a notification if VLC isn't the active app anymore */ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(setNonActive:) name: NSApplicationDidResignActiveNotification object: NSApp]; /* get a notification if VLC is the active app again */ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(setActive:) name: NSApplicationDidBecomeActiveNotification object: NSApp];}/* Windows created with NSBorderlessWindowMask normally can't be key, but we want ours to be */- (BOOL)canBecomeKeyWindow{ return YES;}- (BOOL)mouseDownCanMoveWindow{ return YES;}-(void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver: self]; if( hideAgainTimer ) { [hideAgainTimer invalidate]; [hideAgainTimer release]; } [self setFadeTimer:nil]; [super dealloc];}-(void)center{ /* centre the panel in the lower third of the screen */ NSPoint theCoordinate; NSRect theScreensFrame; NSRect theWindowsFrame; NSScreen *screen; /* user-defined screen */ screen = [NSScreen screenWithDisplayID: (CGDirectDisplayID)i_device]; if (!screen) { /* invalid preferences or none specified, using main screen */ screen = [NSScreen mainScreen]; } theScreensFrame = [screen frame]; theWindowsFrame = [self frame]; theCoordinate.x = (theScreensFrame.size.width - theWindowsFrame.size.width) / 2 + theScreensFrame.origin.x; theCoordinate.y = (theScreensFrame.size.height / 3) - theWindowsFrame.size.height + theScreensFrame.origin.y; [self setFrameTopLeftPoint: theCoordinate];}- (void)setPlay{ [[self contentView] setPlay];}- (void)setPause{ [[self contentView] setPause];}- (void)setStreamTitle:(NSString *)o_title{ [[self contentView] setStreamTitle: o_title];}- (void)setStreamPos:(float) f_pos andTime:(NSString *)o_time{ [[self contentView] setStreamPos:f_pos andTime: o_time];}- (void)setSeekable:(BOOL) b_seekable{ [[self contentView] setSeekable: b_seekable];}- (void)setVolumeLevel: (float)f_volumeLevel{ [[self contentView] setVolumeLevel: f_volumeLevel];}- (void)setNonActive:(id)noData{ b_nonActive = YES; [self orderOut: self]; /* here's fadeOut, just without visibly fading */ b_displayed = NO; [self setAlphaValue:0.0]; [self setFadeTimer:nil]; b_fadeQueued = NO;}- (void)setActive:(id)noData{ if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] ) { b_nonActive = NO; [self fadeIn]; }}/* This routine is called repeatedly to fade in the window */- (void)focus:(NSTimer *)timer{ /* we need to push ourselves to front if the vout window was closed since our last display */ if( b_voutWasUpdated ) { [self orderFront: self]; b_voutWasUpdated = NO; } if( [self alphaValue] < 1.0 ) [self setAlphaValue:[self alphaValue]+0.1]; if( [self alphaValue] >= 1.0 ) { b_displayed = YES; [self setAlphaValue: 1.0]; [self setFadeTimer:nil]; if( b_fadeQueued ) { b_fadeQueued=NO; [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unfocus:) userInfo:NULL repeats:YES]]; } }}/* This routine is called repeatedly to hide the window */- (void)unfocus:(NSTimer *)timer{ if( b_keptVisible ) { b_keptVisible = NO; b_fadeQueued = NO; [self setFadeTimer: NULL]; [self fadeIn]; return; } if( [self alphaValue] > 0.0 ) [self setAlphaValue:[self alphaValue]-0.05]; if( [self alphaValue] <= 0.05 ) { b_displayed = NO; [self setAlphaValue:0.0]; [self setFadeTimer:nil]; if( b_fadeQueued ) { b_fadeQueued=NO; [self setFadeTimer: [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(focus:) userInfo:NULL repeats:YES]]; } }}- (void)mouseExited:(NSEvent *)theEvent{ /* give up our focus, so the vout may show us again without letting the user clicking it */ if( [[[[VLCMain sharedInstance] getControls] getVoutView] isFullscreen] ) [[[[[VLCMain sharedInstance] getControls] getVoutView] window] makeKeyWindow];}- (void)hideMouse{ [NSCursor setHiddenUntilMouseMoves: YES];}- (void)fadeIn{ /* in case that the user don't want us to appear, make sure we hide the mouse */ if( !config_GetInt( VLCIntf, "macosx-fspanel" ) ) { float time = (float)var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 1000.; [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(hideMouse) userInfo:nil repeats:NO]]; return; } if( b_nonActive ) return; [self orderFront: nil]; if( [self alphaValue] < 1.0 || b_displayed != YES ) { if (![self fadeTimer]) [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(focus:) userInfo:[NSNumber numberWithShort:1] repeats:YES]]; else if ([[[self fadeTimer] userInfo] shortValue]==0) b_fadeQueued=YES; } [self autoHide];}- (void)fadeOut{ if( NSPointInRect([NSEvent mouseLocation],[self frame])) return; if( ( [self alphaValue] > 0.0 ) ) { if (![self fadeTimer]) [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(unfocus:) userInfo:[NSNumber numberWithShort:0] repeats:YES]]; else if ([[[self fadeTimer] userInfo] shortValue]==1) b_fadeQueued=YES; }}/* triggers a timer to autoHide us again after some seconds of no activity */- (void)autoHide{ /* this will tell the timer to start over again or to start at all */ b_keptVisible = YES; /* get us a valid timer */ if(! b_alreadyCounting ) { i_timeToKeepVisibleInSec = var_CreateGetInteger( VLCIntf, "mouse-hide-timeout" ) / 500; if( hideAgainTimer ) { [hideAgainTimer invalidate]; [hideAgainTimer autorelease]; } /* released in -autoHide and -dealloc */ hideAgainTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(keepVisible:) userInfo: nil repeats: YES] retain]; b_alreadyCounting = YES; }}- (void)keepVisible:(NSTimer *)timer{ /* if the user triggered an action, start over again */ if( b_keptVisible ) b_keptVisible = NO; /* count down until we hide ourselfes again and do so if necessary */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -