]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/parser/builder.cpp
* skins2/parser/builder*: All the controls now have a 'visible' attribute
[vlc] / modules / gui / skins2 / parser / builder.cpp
index e5963d86306938c5d10a167210c3da36e3a71efd..2e721a138fa5d15066f3a89a9cd8ac7b720e3020 100755 (executable)
@@ -116,10 +116,16 @@ void Builder::addTheme( const BuilderData::Theme &rData )
     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() );
+    }
 }
 
 
@@ -133,7 +139,7 @@ void Builder::addBitmap( const BuilderData::Bitmap &rData )
 
 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 );
     if( pFont->init() )
     {
@@ -234,9 +240,14 @@ void Builder::addButton( const BuilderData::Button &rData )
         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...)
@@ -302,12 +313,16 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
         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...)
@@ -341,9 +356,13 @@ void Builder::addImage( const BuilderData::Image &rData )
         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() ),
-                                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,
@@ -383,7 +402,7 @@ void Builder::addText( const BuilderData::Text &rData )
         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() );
@@ -396,8 +415,13 @@ void Builder::addText( const BuilderData::Text &rData )
     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();
 
@@ -432,12 +456,16 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
         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
@@ -526,7 +554,7 @@ void Builder::addList( const BuilderData::List &rData )
         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() );
@@ -542,11 +570,15 @@ void Builder::addList( const BuilderData::List &rData )
         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,
@@ -569,8 +601,13 @@ void Builder::addVideo( const BuilderData::Video &rData )
         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() ), 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,
@@ -653,6 +690,32 @@ const Position Builder::makePosition( const string &rLeftTop,
 }
 
 
+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<float> xBez, yBez;