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

📄 interfacewindow.cpp

📁 video linux conference
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * InterfaceWindow.cpp: beos interface ***************************************************************************** * Copyright (C) 1999, 2000, 2001 VideoLAN * $Id: InterfaceWindow.cpp 10101 2005-03-02 16:47:31Z robux4 $ * * Authors: Jean-Marc Dressler <polux@via.ecp.fr> *          Samuel Hocevar <sam@zoy.org> *          Tony Castley <tony@castley.net> *          Richard Shepherd <richard@rshepherd.demon.co.uk> *          Stephan Aßmus <superstippi@gmx.de> * * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//* System headers */#include <kernel/OS.h>#include <InterfaceKit.h>#include <AppKit.h>#include <StorageKit.h>#include <SupportKit.h>#include <malloc.h>#include <scsi.h>#include <scsiprobe_driver.h>#include <fs_info.h>#include <string.h>/* VLC headers */#include <vlc/vlc.h>#include <vlc/aout.h>#include <vlc/intf.h>#include <vlc/input.h>/* BeOS interface headers */#include "MsgVals.h"#include "MediaControlView.h"#include "PlayListWindow.h"#include "PreferencesWindow.h"#include "MessagesWindow.h"#include "InterfaceWindow.h"#define INTERFACE_UPDATE_TIMEOUT  80000 // 2 frames if at 25 fps#define INTERFACE_LOCKING_TIMEOUT 5000// make_sure_frame_is_on_screenboolmake_sure_frame_is_on_screen( BRect& frame ){    BScreen screen( B_MAIN_SCREEN_ID );    if (frame.IsValid() && screen.IsValid()) {        if (!screen.Frame().Contains(frame)) {            // make sure frame fits in the screen            if (frame.Width() > screen.Frame().Width())                frame.right -= frame.Width() - screen.Frame().Width() + 10.0;            if (frame.Height() > screen.Frame().Height())                frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;            // frame is now at the most the size of the screen            if (frame.right > screen.Frame().right)                frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);            if (frame.bottom > screen.Frame().bottom)                frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));            if (frame.left < screen.Frame().left)                frame.OffsetBy((screen.Frame().left - frame.left), 0.0);            if (frame.top < screen.Frame().top)                frame.OffsetBy(0.0, (screen.Frame().top - frame.top));        }        return true;    }    return false;}// make_sure_frame_is_within_limitsvoidmake_sure_frame_is_within_limits( BRect& frame, float minWidth, float minHeight,                                  float maxWidth, float maxHeight ){    if ( frame.Width() < minWidth )        frame.right = frame.left + minWidth;    if ( frame.Height() < minHeight )        frame.bottom = frame.top + minHeight;    if ( frame.Width() > maxWidth )        frame.right = frame.left + maxWidth;    if ( frame.Height() > maxHeight )        frame.bottom = frame.top + maxHeight;}// get_volume_infoboolget_volume_info( BVolume& volume, BString& volumeName, bool& isCDROM, BString& deviceName ){    bool success = false;    isCDROM = false;    deviceName = "";    volumeName = "";    char name[B_FILE_NAME_LENGTH];    if ( volume.GetName( name ) >= B_OK )    // disk is currently mounted    {        volumeName = name;        dev_t dev = volume.Device();        fs_info info;        if ( fs_stat_dev( dev, &info ) == B_OK )        {            success = true;            deviceName = info.device_name;            if ( volume.IsReadOnly() )            {                int i_dev = open( info.device_name, O_RDONLY );                if ( i_dev >= 0 )                {                    device_geometry g;                    if ( ioctl( i_dev, B_GET_GEOMETRY, &g, sizeof( g ) ) >= 0 )                        isCDROM = ( g.device_type == B_CD );                    close( i_dev );                }            }        }     }     return success;}// collect_folder_contentsvoidcollect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry ){    while ( dir.GetNextEntry( &entry, true ) == B_OK )    {        if ( !entry.IsDirectory() )        {            BPath path;            // since the directory will give us the entries in reverse order,            // we put them each at the same index, effectively reversing the            // items while adding them            if ( entry.GetPath( &path ) == B_OK )            {                BString* string = new BString( path.Path() );                if ( !list.AddItem( string, 0 ) )                    delete string;    // at least don't leak            }        }        else        {            if ( !asked )            {                // ask user if we should parse sub-folders as well                BAlert* alert = new BAlert( "sub-folders?",                                            _("Open files from all sub-folders as well?"),                                            _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL,                                            B_IDEA_ALERT );                int32 buttonIndex = alert->Go();                deep = buttonIndex == 1;                asked = true;                // never delete BAlerts!!            }            if ( deep )            {                BDirectory subDir( &entry );                if ( subDir.InitCheck() == B_OK )                    collect_folder_contents( subDir, list,                                             deep, asked, entry );            }        }    }}/***************************************************************************** * InterfaceWindow *****************************************************************************/InterfaceWindow::InterfaceWindow( intf_thread_t * _p_intf, BRect frame,                                  const char * name )    : BWindow( frame, name, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,               B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS ),      /* Initializations */      p_intf( _p_intf ),      p_input( NULL ),      p_playlist( NULL ),      fFilePanel( NULL ),      fLastUpdateTime( system_time() ),      fSettings( new BMessage( 'sett' ) ){    char psz_tmp[1024];#define ADD_ELLIPSIS( a ) \    memset( psz_tmp, 0, 1024 ); \    snprintf( psz_tmp, 1024, "%s%s", a, B_UTF8_ELLIPSIS );    BScreen screen;    BRect screen_rect = screen.Frame();    BRect window_rect;    window_rect.Set( ( screen_rect.right - PREFS_WINDOW_WIDTH ) / 2,                     ( screen_rect.bottom - PREFS_WINDOW_HEIGHT ) / 2,                     ( screen_rect.right + PREFS_WINDOW_WIDTH ) / 2,                     ( screen_rect.bottom + PREFS_WINDOW_HEIGHT ) / 2 );    fPreferencesWindow = new PreferencesWindow( p_intf, window_rect, _("Preferences") );    window_rect.Set( screen_rect.right - 500,                     screen_rect.top + 50,                     screen_rect.right - 150,                     screen_rect.top + 250 );    fPlaylistWindow = new PlayListWindow( window_rect, _("Playlist"), this, p_intf );    window_rect.Set( screen_rect.right - 550,                     screen_rect.top + 300,                     screen_rect.right - 150,                     screen_rect.top + 500 );    fMessagesWindow = new MessagesWindow( p_intf, window_rect, _("Messages") );    // the media control view    p_mediaControl = new MediaControlView( p_intf, BRect( 0.0, 0.0, 250.0, 50.0 ) );    p_mediaControl->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );    float width, height;    p_mediaControl->GetPreferredSize( &width, &height );    // set up the main menu    fMenuBar = new BMenuBar( BRect(0.0, 0.0, width, 15.0), "main menu",                             B_FOLLOW_NONE, B_ITEMS_IN_ROW, false );    // make menu bar resize to correct height    float menuWidth, menuHeight;    fMenuBar->GetPreferredSize( &menuWidth, &menuHeight );    fMenuBar->ResizeTo( width, menuHeight );    // don't change! it's a workarround!    // take care of proper size for ourself    height += fMenuBar->Bounds().Height();    ResizeTo( width, height );    p_mediaControl->MoveTo( fMenuBar->Bounds().LeftBottom() + BPoint(0.0, 1.0) );    AddChild( fMenuBar );    // Add the file Menu    BMenu* fileMenu = new BMenu( _("File") );    fMenuBar->AddItem( fileMenu );    ADD_ELLIPSIS( _("Open File") );    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_FILE ), 'O') );    fileMenu->AddItem( new CDMenu( _("Open Disc") ) );    ADD_ELLIPSIS( _("Open Subtitles") );    fileMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( LOAD_SUBFILE ) ) );    fileMenu->AddSeparatorItem();    ADD_ELLIPSIS( _("About") );    BMenuItem* item = new BMenuItem( psz_tmp, new BMessage( B_ABOUT_REQUESTED ), 'A');    item->SetTarget( be_app );    fileMenu->AddItem( item );    fileMenu->AddItem( new BMenuItem( _("Quit"), new BMessage( B_QUIT_REQUESTED ), 'Q') );    fLanguageMenu = new LanguageMenu( p_intf, _("Language"), "audio-es" );    fSubtitlesMenu = new LanguageMenu( p_intf, _("Subtitles"), "spu-es" );    /* Add the Audio menu */    fAudioMenu = new BMenu( _("Audio") );    fMenuBar->AddItem ( fAudioMenu );    fAudioMenu->AddItem( fLanguageMenu );    fAudioMenu->AddItem( fSubtitlesMenu );    fPrevTitleMI = new BMenuItem( _("Prev Title"), new BMessage( PREV_TITLE ) );    fNextTitleMI = new BMenuItem( _("Next Title"), new BMessage( NEXT_TITLE ) );    fPrevChapterMI = new BMenuItem( _("Previous chapter"), new BMessage( PREV_CHAPTER ) );    fNextChapterMI = new BMenuItem( _("Next chapter"), new BMessage( NEXT_CHAPTER ) );    /* Add the Navigation menu */    fNavigationMenu = new BMenu( _("Navigation") );    fMenuBar->AddItem( fNavigationMenu );    fNavigationMenu->AddItem( fPrevTitleMI );    fNavigationMenu->AddItem( fNextTitleMI );    fNavigationMenu->AddItem( fTitleMenu = new TitleMenu( _("Go to Title"), p_intf ) );    fNavigationMenu->AddSeparatorItem();    fNavigationMenu->AddItem( fPrevChapterMI );    fNavigationMenu->AddItem( fNextChapterMI );    fNavigationMenu->AddItem( fChapterMenu = new ChapterMenu( _("Go to Chapter"), p_intf ) );    /* Add the Speed menu */    fSpeedMenu = new BMenu( _("Speed") );    fSpeedMenu->SetRadioMode( true );    fSpeedMenu->AddItem(        fHeighthMI = new BMenuItem( "1/8x", new BMessage( HEIGHTH_PLAY ) ) );    fSpeedMenu->AddItem(        fQuarterMI = new BMenuItem( "1/4x", new BMessage( QUARTER_PLAY ) ) );    fSpeedMenu->AddItem(        fHalfMI = new BMenuItem( "1/2x", new BMessage( HALF_PLAY ) ) );    fSpeedMenu->AddItem(        fNormalMI = new BMenuItem( "1x", new BMessage( NORMAL_PLAY ) ) );    fSpeedMenu->AddItem(        fTwiceMI = new BMenuItem( "2x", new BMessage( TWICE_PLAY ) ) );    fSpeedMenu->AddItem(        fFourMI = new BMenuItem( "4x", new BMessage( FOUR_PLAY ) ) );    fSpeedMenu->AddItem(        fHeightMI = new BMenuItem( "8x", new BMessage( HEIGHT_PLAY ) ) );    fMenuBar->AddItem( fSpeedMenu );    /* Add the Show menu */    fShowMenu = new BMenu( _("Window") );    ADD_ELLIPSIS( _("Playlist") );    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PLAYLIST ), 'P') );    ADD_ELLIPSIS( _("Messages") );    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_MESSAGES ), 'M' ) );    ADD_ELLIPSIS( _("Preferences") );    fShowMenu->AddItem( new BMenuItem( psz_tmp, new BMessage( OPEN_PREFERENCES ), 'S' ) );    fMenuBar->AddItem( fShowMenu );    // add the media control view after the menubar is complete    // because it will set the window size limits in AttachedToWindow()    // and the menubar needs to report the correct PreferredSize()    AddChild( p_mediaControl );    /* Prepare fow showing */    _SetMenusEnabled( false );    p_mediaControl->SetEnabled( false );    _RestoreSettings();    Show();}InterfaceWindow::~InterfaceWindow(){    if( p_input )    {        vlc_object_release( p_input );    }    if( p_playlist )    {        vlc_object_release( p_playlist );    }    if( fPlaylistWindow )    {        fPlaylistWindow->ReallyQuit();    }    if( fMessagesWindow )    {        fMessagesWindow->ReallyQuit();    }    if( fPreferencesWindow )    {        fPreferencesWindow->ReallyQuit();    }    delete fFilePanel;    delete fSettings;}/***************************************************************************** * InterfaceWindow::FrameResized *****************************************************************************/voidInterfaceWindow::FrameResized(float width, float height){    BRect r(Bounds());

⌨️ 快捷键说明

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