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

📄 builder.cpp

📁 VLC Player Source Code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * builder.cpp ***************************************************************************** * Copyright (C) 2003 the VideoLAN team * $Id$ * * Authors: Cyril Deguet     <asmax@via.ecp.fr> *          Olivier Teulière <ipkiss@via.ecp.fr> * * 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. *****************************************************************************/#include "builder.hpp"#include "builder_data.hpp"#include "interpreter.hpp"#include "skin_parser.hpp"#include "../src/file_bitmap.hpp"#include "../src/os_factory.hpp"#include "../src/generic_bitmap.hpp"#include "../src/top_window.hpp"#include "../src/anchor.hpp"#include "../src/bitmap_font.hpp"#include "../src/ft2_font.hpp"#include "../src/ini_file.hpp"#include "../src/generic_layout.hpp"#include "../src/popup.hpp"#include "../src/theme.hpp"#include "../src/window_manager.hpp"#include "../commands/cmd_generic.hpp"#include "../controls/ctrl_button.hpp"#include "../controls/ctrl_checkbox.hpp"#include "../controls/ctrl_image.hpp"#include "../controls/ctrl_list.hpp"#include "../controls/ctrl_move.hpp"#include "../controls/ctrl_resize.hpp"#include "../controls/ctrl_slider.hpp"#include "../controls/ctrl_radialslider.hpp"#include "../controls/ctrl_text.hpp"#include "../controls/ctrl_tree.hpp"#include "../controls/ctrl_video.hpp"#include "../utils/bezier.hpp"#include "../utils/position.hpp"#include "../utils/var_bool.hpp"#include "../utils/var_text.hpp"#include "vlc_image.h"Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData,                  const string &rPath ):    SkinObject( pIntf ), m_rData( rData ), m_path( rPath ), m_pTheme( NULL ){    m_pImageHandler = image_HandlerCreate( pIntf );}Builder::~Builder(){    if( m_pImageHandler ) image_HandlerDelete( m_pImageHandler );}CmdGeneric *Builder::parseAction( const string &rAction ){    return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );}// Useful macro#define ADD_OBJECTS( type ) \    list<BuilderData::type>::const_iterator it##type; \    for( it##type = m_rData.m_list##type.begin(); \         it##type != m_rData.m_list##type.end(); it##type++ ) \    { \        add##type( *it##type ); \    }Theme *Builder::build(){    m_pTheme = new Theme( getIntf() );    if( m_pTheme == NULL )    {        return NULL;    }    // Create everything from the data in the XML    ADD_OBJECTS( Theme );    ADD_OBJECTS( IniFile );    ADD_OBJECTS( Bitmap );    ADD_OBJECTS( SubBitmap );    ADD_OBJECTS( BitmapFont );    ADD_OBJECTS( Font );    ADD_OBJECTS( Window );    // XXX: PopupMenus are created after the windows, so that the Win32Factory    // (at least) can give a valid window handle to the OSPopup objects    ADD_OBJECTS( PopupMenu );    ADD_OBJECTS( Layout );    ADD_OBJECTS( Panel );    ADD_OBJECTS( Anchor );    ADD_OBJECTS( Button );    ADD_OBJECTS( Checkbox );    ADD_OBJECTS( Image );    ADD_OBJECTS( Text );    ADD_OBJECTS( RadialSlider );    ADD_OBJECTS( Slider );    ADD_OBJECTS( List );    ADD_OBJECTS( Tree );    ADD_OBJECTS( Video );    // MenuItems must be created after all the rest, so that the IDs of the    // other elements exist and can be parsed in the actions    ADD_OBJECTS( MenuItem );    ADD_OBJECTS( MenuSeparator );    return m_pTheme;}// Macro to get a bitmap by its ID in the builder#define GET_BMP( pBmp, id ) \    if( id != "none" ) \    { \        pBmp = m_pTheme->getBitmapById(id); \        if( pBmp == NULL ) \        { \            msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \            return; \        } \    }// Macro to get the parent box of a control, given the panel ID#define GET_BOX( pRect, id, pLayout ) \    if( id == "none" ) \        pRect = &pLayout->getRect(); \    else \    { \        const Position *pParent = \            m_pTheme->getPositionById( rData.m_panelId ); \        if( pParent == NULL ) \        { \            msg_Err( getIntf(), "parent panel could not be found: %s", \                     rData.m_panelId.c_str() ); \            return; \        } \        pRect = pParent; \    }void Builder::addTheme( const BuilderData::Theme &rData ){    WindowManager &rManager = m_pTheme->getWindowManager();    rManager.setMagnetValue( rData.m_magnet );    rManager.setAlphaValue( rData.m_alpha );    rManager.setMoveAlphaValue( rData.m_moveAlpha );    GenericFont *pFont = getFont( rData.m_tooltipfont );    if( pFont )    {        rManager.createTooltip( *pFont );    }    else    {        msg_Warn( getIntf(), "invalid tooltip font: %s",                  rData.m_tooltipfont.c_str() );    }}void Builder::addIniFile( const BuilderData::IniFile &rData ){    // Parse the INI file    IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );    iniFile.parseFile();}void Builder::addBitmap( const BuilderData::Bitmap &rData ){    GenericBitmap *pBmp =        new FileBitmap( getIntf(), m_pImageHandler,                        getFilePath( rData.m_fileName ), rData.m_alphaColor,                        rData.m_nbFrames, rData.m_fps );    if( !pBmp->getData() )    {        // Invalid bitmap        delete pBmp;        return;    }    m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );}void Builder::addSubBitmap( const BuilderData::SubBitmap &rData ){    if( m_pTheme->m_bitmaps.find( rData.m_id ) != m_pTheme->m_bitmaps.end() )    {        msg_Dbg( getIntf(), "bitmap %s already exists", rData.m_id.c_str() );        return;    }    // Get the parent bitmap    GenericBitmap *pParentBmp = NULL;    GET_BMP( pParentBmp, rData.m_parent );    // Copy a region of the parent bitmap to the new one    BitmapImpl *pBmp =        new BitmapImpl( getIntf(), rData.m_width, rData.m_height,                        rData.m_nbFrames, rData.m_fps );    bool res = pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0,                                 rData.m_width, rData.m_height );    if( !res )    {        // Invalid sub-bitmap        delete pBmp;        msg_Warn( getIntf(), "sub-bitmap %s ignored", rData.m_id.c_str() );        return;    }    m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );}void Builder::addBitmapFont( const BuilderData::BitmapFont &rData ){    if( m_pTheme->m_fonts.find( rData.m_id ) != m_pTheme->m_fonts.end() )    {        msg_Dbg( getIntf(), "font %s already exists", rData.m_id.c_str() );        return;    }    GenericBitmap *pBmp =        new FileBitmap( getIntf(), m_pImageHandler,                        getFilePath( rData.m_file ), 0 );    if( !pBmp->getData() )    {        // Invalid bitmap        delete pBmp;        return;    }    m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );    GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );    if( pFont->init() )    {        m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );    }    else    {        delete pFont;    }}void Builder::addFont( const BuilderData::Font &rData ){    // Try to load the font from the theme directory    GenericFont *pFont = new FT2Font( getIntf(),                                      getFilePath( rData.m_fontFile ),                                      rData.m_size );    if( pFont->init() )    {        m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );    }    else    {        delete pFont;        // Font not found; try in the resource path        OSFactory *pOSFactory = OSFactory::instance( getIntf() );        const list<string> &resPath = pOSFactory->getResourcePath();        const string &sep = pOSFactory->getDirSeparator();        list<string>::const_iterator it;        for( it = resPath.begin(); it != resPath.end(); it++ )        {            string path = (*it) + sep + "fonts" + sep + rData.m_fontFile;            pFont = new FT2Font( getIntf(), path, rData.m_size );            if( pFont->init() )            {                // Font loaded successfully                m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );                break;            }            else            {                delete pFont;            }        }    }}void Builder::addPopupMenu( const BuilderData::PopupMenu &rData ){    Popup *pPopup = new Popup( getIntf(), m_pTheme->getWindowManager() );    m_pTheme->m_popups[rData.m_id] = PopupPtr( pPopup );}void Builder::addMenuItem( const BuilderData::MenuItem &rData ){    Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );    if( pPopup == NULL )    {        msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );        return;    }    CmdGeneric *pCommand = parseAction( rData.m_action );    if( pCommand == NULL )    {        msg_Err( getIntf(), "invalid action: %s", rData.m_action.c_str() );        return;    }    pPopup->addItem( rData.m_label, *pCommand, rData.m_pos );}void Builder::addMenuSeparator( const BuilderData::MenuSeparator &rData ){    Popup *pPopup = m_pTheme->getPopupById( rData.m_popupId );    if( pPopup == NULL )    {        msg_Err( getIntf(), "unknown popup id: %s", rData.m_popupId.c_str() );        return;    }    pPopup->addSeparator( rData.m_pos );}void Builder::addWindow( const BuilderData::Window &rData ){    TopWindow *pWin =        new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,                       m_pTheme->getWindowManager(),                       rData.m_dragDrop, rData.m_playOnDrop,                       rData.m_visible );    m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );}void Builder::addLayout( const BuilderData::Layout &rData ){    TopWindow *pWin = m_pTheme->getWindowById( rData.m_windowId );    if( pWin == NULL )    {        msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );        return;    }    int minWidth = rData.m_minWidth != -1 ? rData.m_minWidth : rData.m_width;    int maxWidth = rData.m_maxWidth != -1 ? rData.m_maxWidth : rData.m_width;    int minHeight = rData.m_minHeight != -1 ? rData.m_minHeight :                    rData.m_height;    int maxHeight = rData.m_maxHeight != -1 ? rData.m_maxHeight :                    rData.m_height;    GenericLayout *pLayout = new GenericLayout( getIntf(), rData.m_width,                                                rData.m_height,                                                minWidth, maxWidth, minHeight,                                                maxHeight );    m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );    // Attach the layout to its window    m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );}void Builder::addAnchor( const BuilderData::Anchor &rData ){    GenericLayout *pLayout = m_pTheme->getLayoutById( rData.m_layoutId );    if( pLayout == NULL )    {        msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );        return;    }    Bezier *pCurve = getPoints( rData.m_points.c_str() );    if( pCurve == NULL )    {        msg_Err( getIntf(), "invalid format in tag points=\"%s\"",                 rData.m_points.c_str() );        return;    }

⌨️ 快捷键说明

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