⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fspanel.m

📁 uclinux 下的vlc播放器源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 * fspanel.m: MacOS X full screen panel
 *****************************************************************************
 * Copyright (C) 2006-2007 the VideoLAN team
 * $Id: fspanel.m 17038 2006-10-12 18:24:34Z fkuehne $
 *
 * Authors: Jérôme Decoodt <djc at videolan dot org>
 *          Felix 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 "fspanel.h"

#define KEEP_VISIBLE_AFTER_ACTION 4 /* time in half-sec until this panel will hide again after an user's action */

/*****************************************************************************
 * 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:NSFloatingWindowLevel];
    [win setAlphaValue:0.0];
    i_device = 0;

    [win center];
    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 release];
    [self setFadeTimer:nil];
    [super dealloc];
}

-(void)center
{
    /* centre the panel in the lower third of the screen */
    NSPoint theCoordinate;
    NSRect theScreensFrame;
    NSRect theWindowsFrame;

    if( i_device < 0 || i_device >= (signed int)[[NSScreen screens] count] )
        /* invalid preferences or none specified, using main screen */
        theScreensFrame = [[NSScreen mainScreen] frame];
    else
        /* user-defined screen */
        theScreensFrame = [[[NSScreen screens] objectAtIndex: i_device] 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.1];
    if( [self alphaValue] <= 0.1 )
    {
        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)fadeIn
{
    /* in case that the user don't want us to appear, just return here */
    if(! config_GetInt( VLCIntf, "macosx-fspanel" ) || 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.1 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 )
    {
        hideAgainTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5
                                                          target: self 
                                                        selector: @selector(keepVisible:)
                                                        userInfo: nil 
                                                         repeats: YES];
        [hideAgainTimer fire];
        [hideAgainTimer retain];
        b_alreadyCounting = YES;
    }
}

- (void)keepVisible:(NSTimer *)timer
{
    /* if the user triggered an action, start over again */
    if( b_keptVisible )
    {
        i_timeToKeepVisibleInSec = KEEP_VISIBLE_AFTER_ACTION;
        b_keptVisible = NO;
    }
    
    /* count down until we hide ourselfes again and do so if necessary */
    i_timeToKeepVisibleInSec -= 1;
    if( i_timeToKeepVisibleInSec < 1 )
    {
        [self fadeOut];
        [timer invalidate];
        [timer release];
        b_alreadyCounting = NO;
        timer = NULL;
    }
}

/* A getter and setter for our main timer that handles window fading */
- (NSTimer *)fadeTimer

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -