vout.m

来自「VLC媒体播放程序」· M 代码 · 共 1,859 行 · 第 1/4 页

M
1,859
字号
- (BOOL)isFullscreen{    return( p_vout->b_fullscreen );}- (BOOL)canBecomeKeyWindow{    return( YES );}- (void)keyDown:(NSEvent *)o_event{    unichar key = 0;    vlc_value_t val;    unsigned int i_pressed_modifiers = 0;    val.i_int = 0;        i_pressed_modifiers = [o_event modifierFlags];    if( i_pressed_modifiers & NSShiftKeyMask )        val.i_int |= KEY_MODIFIER_SHIFT;    if( i_pressed_modifiers & NSControlKeyMask )        val.i_int |= KEY_MODIFIER_CTRL;    if( i_pressed_modifiers & NSAlternateKeyMask )        val.i_int |= KEY_MODIFIER_ALT;    if( i_pressed_modifiers & NSCommandKeyMask )        val.i_int |= KEY_MODIFIER_COMMAND;    key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];    if( key )    {        /* Escape should always get you out of fullscreen */        if( key == (unichar) 0x1b )        {             if( [self isFullscreen] )             {                 [self toggleFullscreen];             }        }        else if ( key == ' ' )        {             playlist_t *p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,                                                     FIND_ANYWHERE );             if ( p_playlist != NULL )             {                 playlist_Pause( p_playlist );                 vlc_object_release( p_playlist);             }        }        else        {            val.i_int |= CocoaKeyToVLC( key );            var_Set( p_vout->p_vlc, "key-pressed", val );        }    }    else    {        [super keyDown: o_event];    }}- (void)updateTitle{    NSMutableString * o_title;    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );        if( p_playlist == NULL )    {        return;    }    vlc_mutex_lock( &p_playlist->object_lock );    o_title = [NSMutableString stringWithUTF8String:         p_playlist->pp_items[p_playlist->i_index]->psz_uri];     vlc_mutex_unlock( &p_playlist->object_lock );    vlc_object_release( p_playlist );    if( o_title != nil )    {        NSRange prefix_range = [o_title rangeOfString: @"file:"];        if( prefix_range.location != NSNotFound )        {            [o_title deleteCharactersInRange: prefix_range];        }        [self setTitleWithRepresentedFilename: o_title];    }    else    {        [self setTitle:            [NSString stringWithCString: VOUT_TITLE " (QuickTime)"]];    }}/* This is actually the same as VLCControls::stop. */- (BOOL)windowShouldClose:(id)sender{    playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    if( p_playlist == NULL )          {        return NO;    }    playlist_Stop( p_playlist );    vlc_object_release( p_playlist );    /* The window will be closed by the intf later. */    return NO;}@end/***************************************************************************** * VLCQTView implementation *****************************************************************************/@implementation VLCQTView- (void)drawRect:(NSRect)rect{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];        [[NSColor blackColor] set];    NSRectFill( rect );    [super drawRect: rect];    p_vout->i_changes |= VOUT_SIZE_CHANGE;}- (BOOL)acceptsFirstResponder{    return( YES );}- (BOOL)becomeFirstResponder{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];        [o_window setAcceptsMouseMovedEvents: YES];    return( YES );}- (BOOL)resignFirstResponder{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];        [o_window setAcceptsMouseMovedEvents: NO];    VLCHideMouse( p_vout, NO );    return( YES );}- (void)mouseDown:(NSEvent *)o_event{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {                case NSLeftMouseDown:        {            var_Get( p_vout, "mouse-button-down", &val );            val.i_int |= 1;            var_Set( p_vout, "mouse-button-down", val );        }        break;                default:            [super mouseDown: o_event];        break;    }}- (void)otherMouseDown:(NSEvent *)o_event{    /* This is not the the wheel button. you need to poll the     * mouseWheel event for that. other is a third, forth or fifth button */    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {        case NSOtherMouseDown:        {            var_Get( p_vout, "mouse-button-down", &val );            val.i_int |= 2;            var_Set( p_vout, "mouse-button-down", val );        }        break;                default:            [super mouseDown: o_event];        break;    }}- (void)rightMouseDown:(NSEvent *)o_event{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {        case NSRightMouseDown:        {            var_Get( p_vout, "mouse-button-down", &val );            val.i_int |= 4;            var_Set( p_vout, "mouse-button-down", val );        }        break;                default:            [super mouseDown: o_event];        break;    }}- (void)mouseUp:(NSEvent *)o_event{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {        case NSLeftMouseUp:        {            vlc_value_t b_val;            b_val.b_bool = VLC_TRUE;            var_Set( p_vout, "mouse-clicked", b_val );                        var_Get( p_vout, "mouse-button-down", &val );            val.i_int &= ~1;            var_Set( p_vout, "mouse-button-down", val );        }        break;                        default:            [super mouseUp: o_event];        break;    }}- (void)otherMouseUp:(NSEvent *)o_event{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {        case NSOtherMouseUp:        {            var_Get( p_vout, "mouse-button-down", &val );            val.i_int &= ~2;            var_Set( p_vout, "mouse-button-down", val );        }        break;                        default:            [super mouseUp: o_event];        break;    }}- (void)rightMouseUp:(NSEvent *)o_event{    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    vlc_value_t val;    switch( [o_event type] )    {        case NSRightMouseUp:        {            var_Get( p_vout, "mouse-button-down", &val );            val.i_int &= ~4;            var_Set( p_vout, "mouse-button-down", val );        }        break;                default:            [super mouseUp: o_event];        break;    }}- (void)mouseDragged:(NSEvent *)o_event{    [self mouseMoved:o_event];}- (void)otherMouseDragged:(NSEvent *)o_event{    [self mouseMoved:o_event];}- (void)rightMouseDragged:(NSEvent *)o_event{    [self mouseMoved:o_event];}- (void)mouseMoved:(NSEvent *)o_event{    NSPoint ml;    NSRect s_rect;    BOOL b_inside;    vout_thread_t * p_vout;    id o_window = [self window];    p_vout = (vout_thread_t *)[o_window getVout];    s_rect = [self bounds];    ml = [self convertPoint: [o_event locationInWindow] fromView: nil];    b_inside = [self mouse: ml inRect: s_rect];    if( b_inside )    {        vlc_value_t val;        int i_width, i_height, i_x, i_y;                vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,                                   (unsigned int)s_rect.size.height,                                   &i_x, &i_y, &i_width, &i_height );        val.i_int = ( ((int)ml.x) - i_x ) *                     p_vout->render.i_width / i_width;        var_Set( p_vout, "mouse-x", val );        val.i_int = ( ((int)ml.y) - i_y ) *                     p_vout->render.i_height / i_height;        var_Set( p_vout, "mouse-y", val );                    val.b_bool = VLC_TRUE;        var_Set( p_vout, "mouse-moved", val );        p_vout->p_sys->i_time_mouse_last_moved = mdate();        p_vout->p_sys->b_mouse_moved = YES;    }    [super mouseMoved: o_event];}@end/***************************************************************************** * VLCGLView implementation *****************************************************************************/@implementation VLCGLView- (id) initWithFrame: (NSRect) frame vout: (vout_thread_t*) _p_vout{    char * psz_effect;    p_vout = _p_vout;        NSOpenGLPixelFormatAttribute attribs[] =    {        NSOpenGLPFAAccelerated,        NSOpenGLPFANoRecovery,        NSOpenGLPFADoubleBuffer,        NSOpenGLPFAColorSize, 24,        NSOpenGLPFAAlphaSize, 8,        NSOpenGLPFADepthSize, 24,        NSOpenGLPFAWindow,        0    };    NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]        initWithAttributes: attribs];    if( !fmt )    {        msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );        return nil;    }    self = [super initWithFrame:frame pixelFormat: fmt];    currentContext = [self openGLContext];    [currentContext makeCurrentContext];    [currentContext update];    /* Black background */    glClearColor( 0.0, 0.0, 0.0, 0.0 );    /* Check if the user asked for useless visual effects */    psz_effect = config_GetPsz( p_vout, "macosx-opengl-effect" );    if( !strcmp( psz_effect, "none" ) )    {        i_effect = OPENGL_EFFECT_NONE;    }    else if( !strcmp( psz_effect, "cube" ) )    {        i_effect = OPENGL_EFFECT_CUBE;        glEnable( GL_DEPTH_TEST );    }    else if( !strcmp( psz_effect, "transparent-cube" ) )    {        i_effect = OPENGL_EFFECT_TRANSPARENT_CUBE;        glDisable( GL_DEPTH_TEST );        glEnable( GL_BLEND );        glBlendFunc( GL_SRC_ALPHA, GL_ONE );    }    else    {        msg_Warn( p_vout, "no valid opengl effect provided, using "                  "\"none\"" );        i_effect = OPENGL_EFFECT_NONE;    }    if( i_effect & ( OPENGL_EFFECT_CUBE |                OPENGL_EFFECT_TRANSPARENT_CUBE ) )    {        /* Set the perpective */        glMatrixMode( GL_PROJECTION );        glLoadIdentity();        glFrustum( -1.0, 1.0, -1.0, 1.0, 3.0, 20.0 );        glMatrixMode( GL_MODELVIEW );        glLoadIdentity();        glTranslatef( 0.0, 0.0, - 5.0 );    }    i_texture    = 0;    initDone     = 0;    isFullScreen = 0;    return self;}- (void) reshape{    if( !initDone )    {        return;    }        [currentContext makeCurrentContext];    NSRect bounds = [self bounds];    glViewport( 0, 0, (GLint) bounds.size.width,                (GLint) bounds.size.height );    /* Quad size is set in order to preserve the aspect ratio */    if( config_GetInt( p_vout, "macosx-stretch" ) )    {

⌨️ 快捷键说明

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