/*****************************************************************************
* builder.cpp
*****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
* $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
#include "builder.hpp"
#include "builder_data.hpp"
#include "interpreter.hpp"
-#include "../src/png_bitmap.hpp"
+#include "../src/file_bitmap.hpp"
#include "../src/os_factory.hpp"
#include "../src/generic_bitmap.hpp"
#include "../src/top_window.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/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):
- SkinObject( pIntf ), m_rData( rData ), m_pTheme( NULL )
+
+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 )
{
// Create everything from the data in the XML
ADD_OBJECTS( Theme );
ADD_OBJECTS( Bitmap );
+ ADD_OBJECTS( SubBitmap );
ADD_OBJECTS( BitmapFont );
ADD_OBJECTS( Font );
ADD_OBJECTS( Window );
ADD_OBJECTS( RadialSlider );
ADD_OBJECTS( Slider );
ADD_OBJECTS( List );
+ ADD_OBJECTS( Tree );
ADD_OBJECTS( Video );
return m_pTheme;
#define GET_BMP( pBmp, id ) \
if( id != "none" ) \
{ \
- pBmp = m_pTheme->m_bitmaps[id].get(); \
+ pBmp = m_pTheme->getBitmapById(id); \
if( pBmp == NULL ) \
{ \
msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
void Builder::addBitmap( const BuilderData::Bitmap &rData )
{
- GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_fileName,
- rData.m_alphaColor );
+ GenericBitmap *pBmp =
+ new FileBitmap( getIntf(), m_pImageHandler,
+ getFilePath( rData.m_fileName ), rData.m_alphaColor );
+ 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 );
+ 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(), "SubBitmap %s ignored", rData.m_id.c_str() );
+ return;
+ }
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
}
void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
{
- GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 );
+ 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 );
void Builder::addFont( const BuilderData::Font &rData )
{
- GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontFile,
+ // Try to load the font from the theme directory
+ GenericFont *pFont = new FT2Font( getIntf(),
+ getFilePath( rData.m_fontFile ),
rData.m_size );
if( pFont->init() )
{
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;
+ }
+ }
}
}
{
TopWindow *pWin =
new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
- m_pTheme->getWindowManager(),
- rData.m_dragDrop, rData.m_playOnDrop );
+ 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->m_windows[rData.m_windowId].get();
+ TopWindow *pWin = m_pTheme->getWindowById(rData.m_windowId);
if( pWin == NULL )
{
msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
// Attach the layout to its window
- pWin->setActiveLayout( pLayout );
+ m_pTheme->getWindowManager().addLayout( *pWin, *pLayout );
}
void Builder::addAnchor( const BuilderData::Anchor &rData )
{
- TopWindow *pWin = m_pTheme->m_windows[rData.m_windowId].get();
- if( pWin == NULL )
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
+ if( pLayout == NULL )
{
- msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
rData.m_range, rData.m_priority,
- *pCurve, *pWin );
- pWin->addAnchor( pAnc );
+ *pCurve, *pLayout );
+ pLayout->addAnchor( pAnc );
}
GenericBitmap *pBmpOver = pBmpUp;
GET_BMP( pBmpOver, rData.m_overId );
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
GenericBitmap *pBmpOver2 = pBmpUp2;
GET_BMP( pBmpOver2, rData.m_over2Id );
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
GenericBitmap *pBmp = NULL;
GET_BMP( pBmp, rData.m_bmpId );
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
- TopWindow *pWindow = m_pTheme->m_windows[rData.m_windowId].get();
+ TopWindow *pWindow = m_pTheme->getWindowById(rData.m_windowId);
if( pWindow == NULL )
{
msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
Interpreter *pInterpreter = Interpreter::instance( getIntf() );
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
- CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp,
+ CtrlImage::resize_t resizeMethod =
+ (rData.m_resize == "scale" ? CtrlImage::kScale : CtrlImage::kMosaic);
+ CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp, resizeMethod,
UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
NULL);
pLayout->addControl( pMove, pos, rData.m_layer );
}
- else if( rData.m_actionId == "resize" )
+ else if( rData.m_actionId == "resizeSE" )
{
CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
UString( getIntf(), rData.m_help.c_str() ), NULL );
void Builder::addText( const BuilderData::Text &rData )
{
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
int height = pFont->getSize();
- pLayout->addControl( pText, Position( rData.m_xPos, rData.m_yPos,
- rData.m_xPos + rData.m_width,
- rData.m_yPos + height, *pLayout ),
- rData.m_layer );
+ // Compute the position of the control
+ const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
+ rData.m_xPos, rData.m_yPos,
+ rData.m_width, height,
+ *pLayout );
+
+ pLayout->addControl( pText, pos, rData.m_layer );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
}
GenericBitmap *pSeq = NULL;
GET_BMP( pSeq, rData.m_sequence );
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
void Builder::addSlider( const BuilderData::Slider &rData )
{
- // Get the bitmaps of the slider
- GenericBitmap *pBmpUp = NULL;
- GET_BMP( pBmpUp, rData.m_upId );
+ // Add the background first, so that we will still have something almost
+ // functional if the cursor cannot be created properly (this happens for
+ // some winamp2 skins, where the images of the cursor are not always
+ // present)
- GenericBitmap *pBmpDown = pBmpUp;
- GET_BMP( pBmpDown, rData.m_downId );
-
- GenericBitmap *pBmpOver = pBmpUp;
- GET_BMP( pBmpOver, rData.m_overId );
+ // Get the bitmaps of the background
+ GenericBitmap *pBgImage = NULL;
+ if( rData.m_imageId != "none" )
+ {
+ GET_BMP( pBgImage, rData.m_imageId );
+ }
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
- // Create the cursor and background controls
- CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
- *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
- UString( getIntf(), rData.m_tooltip.c_str() ),
- UString( getIntf(), rData.m_help.c_str() ) );
-
- CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCursor,
- *pCurve, *pVar, rData.m_thickness, pVisible,
- UString( getIntf(), rData.m_help.c_str() ) );
+ // Create the background control
+ CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
+ *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
+ rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
+ pVisible, UString( getIntf(), rData.m_help.c_str() ) );
// Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
*pLayout );
pLayout->addControl( pBackground, pos, rData.m_layer );
+
+ m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
+
+ // Get the bitmaps of the cursor
+ GenericBitmap *pBmpUp = NULL;
+ GET_BMP( pBmpUp, rData.m_upId );
+
+ GenericBitmap *pBmpDown = pBmpUp;
+ GET_BMP( pBmpDown, rData.m_downId );
+
+ GenericBitmap *pBmpOver = pBmpUp;
+ GET_BMP( pBmpOver, rData.m_overId );
+
+ // Create the cursor control
+ CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
+ *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
+ UString( getIntf(), rData.m_tooltip.c_str() ),
+ UString( getIntf(), rData.m_help.c_str() ) );
+
pLayout->addControl( pCursor, pos, rData.m_layer );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
- m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
+
+ // Associate the cursor to the background
+ pBackground->associateCursor( *pCursor );
}
void Builder::addList( const BuilderData::List &rData )
{
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ // Get the background bitmap, if any
+ GenericBitmap *pBgBmp = NULL;
+ GET_BMP( pBgBmp, rData.m_bgImageId );
+
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
// Create the list control
- CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont,
+ CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
rData.m_bgColor2, rData.m_selColor,
UString( getIntf(), rData.m_help.c_str() ), pVisible );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
}
+void Builder::addTree( const BuilderData::Tree &rData )
+{
+ // Get the bitmaps, if any
+ GenericBitmap *pBgBmp = NULL;
+ GenericBitmap *pItemBmp = NULL;
+ GenericBitmap *pOpenBmp = NULL;
+ GenericBitmap *pClosedBmp = NULL;
+ GET_BMP( pBgBmp, rData.m_bgImageId );
+ GET_BMP( pItemBmp, rData.m_itemImageId );
+ GET_BMP( pOpenBmp, rData.m_openImageId );
+ GET_BMP( pClosedBmp, rData.m_closedImageId );
+
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
+ if( pLayout == NULL )
+ {
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
+ return;
+ }
+
+ GenericFont *pFont = getFont( rData.m_fontId );
+ if( pFont == NULL )
+ {
+ msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
+ return;
+ }
+
+ // Get the list variable
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarTree *pVar = pInterpreter->getVarTree( rData.m_var, m_pTheme );
+ if( pVar == NULL )
+ {
+ msg_Err( getIntf(), "No such list variable: %s", rData.m_var.c_str() );
+ return;
+ }
+
+ // Get the visibility variable
+ // XXX check when it is null
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
+ // Create the list control
+ CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
+ pItemBmp, pOpenBmp, pClosedBmp,
+ rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
+ rData.m_bgColor2, rData.m_selColor,
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
+
+ // Compute the position of the control
+ const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
+ rData.m_xPos, rData.m_yPos,
+ rData.m_width, rData.m_height,
+ *pLayout );
+
+ pLayout->addControl( pTree, pos, rData.m_layer );
+
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pTree );
+}
void Builder::addVideo( const BuilderData::Video &rData )
{
- GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId);
if( pLayout == NULL )
{
msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
Interpreter *pInterpreter = Interpreter::instance( getIntf() );
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
- CtrlVideo *pVideo = new CtrlVideo( getIntf(),
- UString( getIntf(), rData.m_help.c_str() ), pVisible );
+ CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
+ rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
+ pVisible );
// Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
GenericFont *Builder::getFont( const string &fontId )
{
- GenericFont *pFont = m_pTheme->m_fonts[fontId].get();
+ GenericFont *pFont = m_pTheme->getFontById(fontId);
if( !pFont && fontId == "defaultfont" )
{
-#ifdef WIN32_SKINS
- string defaultFont = (string)getIntf()->p_libvlc->psz_vlcpath +
- "\\skins2\\fonts\\FreeSans.ttf";
-#else
- string defaultFont = (string)DATA_PATH + "/skins2/fonts/FreeSans.ttf";
-#endif
- pFont = new FT2Font( getIntf(), defaultFont, 12 );
- if( pFont->init() )
+ // Get the resource path and try to load the default font
+ 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++ )
{
- m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
+ string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
+ pFont = new FT2Font( getIntf(), path, 12 );
+ if( pFont->init() )
+ {
+ // Font loaded successfully
+ m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
+ break;
+ }
+ else
+ {
+ delete pFont;
+ pFont = NULL;
+ }
}
- else
+ if( !pFont )
{
- delete pFont;
- pFont = NULL;
+ msg_Err( getIntf(), "Failed to open the default font" );
}
}
return pFont;
}
+string Builder::getFilePath( const string &rFileName ) const
+{
+ OSFactory *pFactory = OSFactory::instance( getIntf() );
+ return m_path + pFactory->getDirSeparator() + rFileName;
+}
+
+
+
Bezier *Builder::getPoints( const char *pTag ) const
{
vector<float> xBez, yBez;