#include "../src/png_bitmap.hpp"
#include "../src/os_factory.hpp"
#include "../src/generic_bitmap.hpp"
-#include "../src/generic_window.hpp"
+#include "../src/top_window.hpp"
#include "../src/anchor.hpp"
+#include "../src/bitmap_font.hpp"
#include "../src/ft2_font.hpp"
#include "../src/theme.hpp"
#include "../controls/ctrl_button.hpp"
#include "../controls/ctrl_slider.hpp"
#include "../controls/ctrl_radialslider.hpp"
#include "../controls/ctrl_text.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):
+
+Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData ):
SkinObject( pIntf ), m_rData( rData ), 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( BitmapFont );
ADD_OBJECTS( Font );
ADD_OBJECTS( Window );
ADD_OBJECTS( Layout );
ADD_OBJECTS( RadialSlider );
ADD_OBJECTS( Slider );
ADD_OBJECTS( List );
+ 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() ); \
rManager.setMagnetValue( rData.m_magnet );
rManager.setAlphaValue( rData.m_alpha );
rManager.setMoveAlphaValue( rData.m_moveAlpha );
- // XXX: font to fix
- GenericFont *pFont = new FT2Font( getIntf(), "FreeSans.ttf", 12 );
- pFont->init();
- rManager.createTooltip( *pFont );
+ 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::addBitmap( const BuilderData::Bitmap &rData )
{
- GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_fileName,
- rData.m_alphaColor );
+ GenericBitmap *pBmp =
+ new PngBitmap( getIntf(), m_pImageHandler,
+ rData.m_fileName, rData.m_alphaColor );
+ m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
+}
+
+
+void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
+{
+ GenericBitmap *pBmp =
+ new PngBitmap( getIntf(), m_pImageHandler, rData.m_file, 0 );
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 )
{
- GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontName,
+ GenericFont *pFont = new FT2Font( getIntf(), rData.m_fontFile,
rData.m_size );
- pFont->init();
- m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
+ if( pFont->init() )
+ {
+ m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
+ }
+ else
+ {
+ delete pFont;
+ }
}
void Builder::addWindow( const BuilderData::Window &rData )
{
- GenericWindow *pWin =
- new GenericWindow( getIntf(), rData.m_xPos, rData.m_yPos,
+ TopWindow *pWin =
+ new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
m_pTheme->getWindowManager(),
rData.m_dragDrop, rData.m_playOnDrop );
- m_pTheme->m_windows[rData.m_id] = GenericWindowPtr( pWin );
+ m_pTheme->m_windows[rData.m_id] = TopWindowPtr( pWin );
}
void Builder::addLayout( const BuilderData::Layout &rData )
{
- GenericWindow *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 )
{
- GenericWindow *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() );
return;
}
+ // Get the visibility variable
+ // XXX check when it is null
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
CtrlButton *pButton = new CtrlButton( getIntf(), *pBmpUp, *pBmpOver,
*pBmpDown, *pCommand, UString( getIntf(), rData.m_tooltip.c_str() ),
- UString( getIntf(), rData.m_help.c_str() ), NULL );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
// XXX (we suppose all the images have the same size...)
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() );
return;
}
+ // Get the visibility variable
+ // XXX check when it is null
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
// Create the control
CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
*pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
*pCommand2, UString( getIntf(), rData.m_tooltip1.c_str() ),
UString( getIntf(), rData.m_tooltip2.c_str() ), *pVar,
- UString( getIntf(), rData.m_help.c_str() ), NULL );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
// XXX (we suppose all the images have the same size...)
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;
}
- GenericWindow *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() );
return;
}
- CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp,
- UString( getIntf(), rData.m_help.c_str() ),
- NULL);
+ // Get the visibility variable
+ // XXX check when it is null
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
+ 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
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
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() );
return;
}
- GenericFont *pFont = m_pTheme->m_fonts[rData.m_fontId].get();
+ GenericFont *pFont = getFont( rData.m_fontId );
if( pFont == NULL )
{
msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.c_str() );
pVar->set( msg );
m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
+ // Get the visibility variable
+ // XXX check when it is null
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
- UString( getIntf(), rData.m_help.c_str() ), rData.m_color, NULL );
+ UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible );
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() );
return;
}
+ // Get the visibility variable
+ // XXX check when it is null
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
+
// Create the control
CtrlRadialSlider *pRadial =
new CtrlRadialSlider( getIntf(), *pSeq, rData.m_nbImages, *pVar,
rData.m_minAngle, rData.m_maxAngle,
UString( getIntf(), rData.m_help.c_str() ),
- NULL );
+ pVisible );
// XXX: resizing is not supported
// Compute the position of the control
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() );
void Builder::addList( const BuilderData::List &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() );
return;
}
- GenericFont *pFont = m_pTheme->m_fonts[rData.m_fontId].get();
+ GenericFont *pFont = getFont( rData.m_fontId );
if( pFont == NULL )
{
msg_Err( getIntf(), "Unknown font id: %s", rData.m_fontId.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
CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont,
rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
rData.m_bgColor2, rData.m_selColor,
- UString( getIntf(), rData.m_help.c_str() ), NULL );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
}
+void Builder::addVideo( const BuilderData::Video &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;
+ }
+
+ // Get the visibility variable
+ // XXX check when it is null
+ 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 );
+
+ // 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( pVideo, pos, rData.m_layer );
+
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pVideo );
+}
+
+
const Position Builder::makePosition( const string &rLeftTop,
const string &rRightBottom,
int xPos, int yPos, int width,
}
+GenericFont *Builder::getFont( const string &fontId )
+{
+ GenericFont *pFont = m_pTheme->getFontById(fontId);
+ if( !pFont && fontId == "defaultfont" )
+ {
+ // 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++ )
+ {
+ 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;
+ }
+ }
+ if( !pFont )
+ {
+ msg_Err( getIntf(), "Failed to open the default font" );
+ }
+ }
+ return pFont;
+}
+
+
Bezier *Builder::getPoints( const char *pTag ) const
{
vector<float> xBez, yBez;