* builder.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
- * $Id: builder.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
#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"
-Builder::Builder( intf_thread_t *pIntf, BuilderData &rData):
- SkinObject( pIntf ), m_rData( rData ), m_interpreter( pIntf ),
- m_pTheme( NULL )
+Builder::Builder( intf_thread_t *pIntf, const BuilderData &rData):
+ SkinObject( pIntf ), m_rData( rData ), m_pTheme( NULL )
{
}
CmdGeneric *Builder::parseAction( const string &rAction )
{
- return m_interpreter.parseAction( rAction, m_pTheme );
+ return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
}
// 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;
}
pBmp = m_pTheme->m_bitmaps[id].get(); \
if( pBmp == NULL ) \
{ \
- msg_Err( getIntf(), "Unknown Bitmap id: %s", id.c_str() ); \
+ msg_Err( getIntf(), "unknown bitmap id: %s", id.c_str() ); \
return; \
} \
}
void Builder::addTheme( const BuilderData::Theme &rData )
{
- m_pTheme->getWindowManager().setMagnetValue( rData.m_magnet );
- m_pTheme->getWindowManager().setAlphaValue( rData.m_alpha );
- m_pTheme->getWindowManager().setMoveAlphaValue( rData.m_moveAlpha );
+ 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::addBitmapFont( const BuilderData::BitmapFont &rData )
+{
+ GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 );
+ m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
+
+ GenericFont *pFont = new BitmapFont( getIntf(), *pBmp );
+ 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 )
{
- // XXX: font to fix
- GenericFont *pFont = new FT2Font( getIntf(), "FreeSans.ttf", 12 );
- pFont->init();
- GenericWindow *pWin =
- new GenericWindow( getIntf(), rData.m_xPos, rData.m_yPos,
- m_pTheme->getWindowManager(), *pFont,
+ TopWindow *pWin =
+ new TopWindow( getIntf(), rData.m_xPos, rData.m_yPos,
+ m_pTheme->getWindowManager(),
rData.m_dragDrop, rData.m_playOnDrop );
- m_pTheme->m_windows[uniqueId( 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->m_windows[rData.m_windowId].get();
if( pWin == NULL )
{
- msg_Err( getIntf(), "Unknown Window id: %s", rData.m_windowId.c_str() );
+ msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.c_str() );
return;
}
rData.m_height,
minWidth, maxWidth, minHeight,
maxHeight );
- m_pTheme->m_layouts[uniqueId( rData.m_id) ] = GenericLayoutPtr( pLayout );
+ m_pTheme->m_layouts[rData.m_id] = GenericLayoutPtr( pLayout );
// Attach the layout to its window
pWin->setActiveLayout( pLayout );
void Builder::addAnchor( const BuilderData::Anchor &rData )
{
- GenericWindow *pWin = m_pTheme->m_windows[rData.m_windowId].get();
+ TopWindow *pWin = m_pTheme->m_windows[rData.m_windowId].get();
if( pWin == NULL )
{
- msg_Err( getIntf(), "Unknown Window id: %s", rData.m_windowId.c_str() );
+ msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.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;
+ }
+ m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
+
Anchor *pAnc = new Anchor( getIntf(), rData.m_xPos, rData.m_yPos,
- rData.m_range, rData.m_priority, *pWin );
+ rData.m_range, rData.m_priority,
+ *pCurve, *pWin );
pWin->addAnchor( pAnc );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
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() ) );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
// XXX (we suppose all the images have the same size...)
pLayout->addControl( pButton, pos, rData.m_layer );
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pButton );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
}
// Get the state variable
- VarBool *pVar = m_interpreter.getVarBool( rData.m_state, m_pTheme );
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarBool *pVar = pInterpreter->getVarBool( rData.m_state, m_pTheme );
if( pVar == NULL )
{
// TODO: default state
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() ) );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
// XXX (we suppose all the images have the same size...)
pLayout->addControl( pCheckbox, pos, rData.m_layer );
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pCheckbox );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCheckbox );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ 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->m_windows[rData.m_windowId].get();
if( pWindow == NULL )
{
- msg_Err( getIntf(), "Unknown Window id: %s", rData.m_windowId.c_str() );
+ msg_Err( getIntf(), "unknown window id: %s", rData.m_windowId.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 );
+
CtrlImage *pImage = new CtrlImage( getIntf(), *pBmp,
- UString( getIntf(), rData.m_help.c_str() ) );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
pBmp->getHeight(), *pLayout );
// XXX: test to be changed! XXX
- if( rData.m_onclickId == "move" )
+ if( rData.m_actionId == "move" )
{
CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
- *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ) );
+ *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
+ NULL);
pLayout->addControl( pMove, pos, rData.m_layer );
}
- else if( rData.m_onclickId == "resize" )
+ else if( rData.m_actionId == "resize" )
{
CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
- UString( getIntf(), rData.m_help.c_str() ) );
+ UString( getIntf(), rData.m_help.c_str() ), NULL );
pLayout->addControl( pResize, pos, rData.m_layer );
}
else
pLayout->addControl( pImage, pos, rData.m_layer );
}
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pImage );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pImage );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ 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() ) );
+ UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible );
int height = pFont->getSize();
rData.m_yPos + height, *pLayout ),
rData.m_layer );
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pText );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
// Get the variable associated to the slider
- VarPercent *pVar = m_interpreter.getVarPercent( rData.m_value, m_pTheme );
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
if( pVar == NULL )
{
msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.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() ) );
+ UString( getIntf(), rData.m_help.c_str() ),
+ pVisible );
// XXX: resizing is not supported
// Compute the position of the control
pLayout->addControl( pRadial, pos, rData.m_layer );
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pRadial );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pRadial );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ msg_Err( getIntf(), "unknown layout id: %s", rData.m_layoutId.c_str() );
return;
}
- // XXX: memory leak!
Bezier *pCurve = getPoints( rData.m_points.c_str() );
if( pCurve == NULL )
{
rData.m_points.c_str() );
return;
}
+ m_pTheme->m_curves.push_back( BezierPtr( pCurve ) );
// Get the visibility variable
// XXX check when it is null
- VarBool *pVisible = m_interpreter.getVarBool( rData.m_visible, m_pTheme );
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
// Get the variable associated to the slider
- VarPercent *pVar = m_interpreter.getVarPercent( rData.m_value, m_pTheme );
+ VarPercent *pVar = pInterpreter->getVarPercent( rData.m_value, m_pTheme );
if( pVar == NULL )
{
msg_Err( getIntf(), "Unknown slider value: %s", rData.m_value.c_str() );
pLayout->addControl( pBackground, pos, rData.m_layer );
pLayout->addControl( pCursor, pos, rData.m_layer );
- string newId = uniqueId( rData.m_id );
- m_pTheme->m_controls[newId] = CtrlGenericPtr( pCursor );
- m_pTheme->m_controls[newId + "_bg"] = CtrlGenericPtr( pBackground );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
+ m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
}
GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
if( pLayout == NULL )
{
- msg_Err( getIntf(), "Unknown Layout id: %s", rData.m_layoutId.c_str() );
+ 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() );
}
// Get the list variable
- VarList *pVar = m_interpreter.getVarList( rData.m_var, m_pTheme );
+ Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+ VarList *pVar = pInterpreter->getVarList( 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
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() ) );
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
// Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
pLayout->addControl( pList, pos, rData.m_layer );
- m_pTheme->m_controls[uniqueId( rData.m_id) ] = CtrlGenericPtr( pList );
+ m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pList );
}
-const string Builder::generateId() const
+void Builder::addVideo( const BuilderData::Video &rData )
{
- static int i = 1;
-
- const string base = "_ReservedId_";
- char genId[base.size() + 4];
- snprintf( genId, base.size() + 4, "%s%i", base.c_str(), i );
- i++;
- return genId;
-}
+ GenericLayout *pLayout = m_pTheme->m_layouts[rData.m_layoutId].get();
+ 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 );
-const string Builder::uniqueId( const string &id )
-{
- string newId;
+ CtrlVideo *pVideo = new CtrlVideo( getIntf(),
+ UString( getIntf(), rData.m_help.c_str() ), pVisible );
- if( m_idSet.find( id ) != m_idSet.end() )
- {
- // The id was already used
- if( id != "none" )
- {
- msg_Warn( getIntf(), "Non unique id: %s", id.c_str() );
- }
- newId = generateId();
- }
- else
- {
- // OK, this is a new id
- newId = id;
- }
+ // 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 );
- // Add the id to the set
- m_idSet.insert( newId );
+ pLayout->addControl( pVideo, pos, rData.m_layer );
- return newId;
+ 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->m_fonts[fontId].get();
+ 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() )
+ {
+ m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
+ }
+ else
+ {
+ delete pFont;
+ pFont = NULL;
+ }
+ }
+ return pFont;
+}
+
+
Bezier *Builder::getPoints( const char *pTag ) const
{
- vector<double> xBez, yBez;
+ vector<float> xBez, yBez;
int x, y, n;
while( 1 )
{
- if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 2 )
+ if( sscanf( pTag, "(%d,%d)%n", &x, &y, &n ) < 1 )
{
return NULL;
}
+#if 0
if( x < 0 || y < 0 )
{
msg_Err( getIntf(),
"Slider points cannot have negative coordinates!" );
return NULL;
}
+#endif
xBez.push_back( x );
yBez.push_back( y );
pTag += n;