]> git.sesse.net Git - vlc/commitdiff
skins2: provide more info to help skin developpers debug their skins
authorErwan Tulou <erwan10@videolan.org>
Thu, 4 Apr 2013 13:13:58 +0000 (15:13 +0200)
committerErwan Tulou <erwan10@videolan.org>
Thu, 4 Apr 2013 15:32:20 +0000 (17:32 +0200)
Many skins are buggy because the bitmap sizes or the resize policy
are inconsistent with button or checkbox constraints (fixed size)

This patch will help skin developers pinpoint which button or
checkbox is at fault. In addition, the resize policy will be
corrected (guessed from the lefttop parameter). This will enable
buggy and often unmaintained skins to work fine nevertheless.

modules/gui/skins2/parser/builder.cpp

index 288afb145dbafd602b16c8aacb7318ce0d972ac5..e5b54a08393e233417b7bedf4621367c996529ff 100644 (file)
@@ -142,6 +142,27 @@ Theme *Builder::build()
         } \
     }
 
+// macro to check bitmap size consistency for button and checkbox
+#define CHECK_BMP( pBmp, pBmpRef, id) \
+    if( pBmp != pBmpRef ) \
+    { \
+        int w_ref = pBmpRef->getWidth(); \
+        int h_ref = pBmpRef->getHeight() / pBmpRef->getNbFrames(); \
+        int w = pBmp->getWidth(); \
+        int h = pBmp->getHeight() / pBmp->getNbFrames(); \
+        if( w != w_ref || h != h_ref ) \
+            msg_Err( getIntf(), "pls, check bitmap sizes for id: %s", id.c_str() ); \
+    }
+
+// macro to check resize policy of button and checkbox
+#define CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio, id )\
+    if( (!xkeepratio && lefttop != rightbottom) || \
+        (!ykeepratio && lefttop != rightbottom) ) \
+    { \
+        msg_Err( getIntf(), "pls, check resize policy for id: %s", \
+                            id.c_str() ); \
+        rightbottom = lefttop; \
+    }
 
 // Macro to get the parent box of a control, given the panel ID
 #define GET_BOX( pRect, id, pLayout ) \
@@ -467,15 +488,27 @@ void Builder::addButton( const BuilderData::Button &rData )
         UString( getIntf(), rData.m_help.c_str() ), pVisible );
     m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pButton );
 
+    // width and height are set up from the 'up' bitmap size
+    int width = pBmpUp->getWidth();
+    int height = pBmpUp->getHeight() / pBmpUp->getNbFrames();
+    bool xkeepratio = rData.m_xKeepRatio;
+    bool ykeepratio = rData.m_yKeepRatio;
+    string lefttop( rData.m_leftTop );
+    string rightbottom( rData.m_rightBottom );
+
+    // various checks to help skin developers debug their skin
+    CHECK_BMP( pBmpDown, pBmpUp, rData.m_id );
+    CHECK_BMP( pBmpOver, pBmpUp, rData.m_id );
+    CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio,
+                         rData.m_id );
+
     // Compute the position of the control
     // XXX (we suppose all the images have the same size...)
     const GenericRect *pRect;
     GET_BOX( pRect, rData.m_panelId , pLayout);
-    const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
-                             rData.m_xPos, rData.m_yPos,
-                             pBmpUp->getWidth(),
-                             pBmpUp->getHeight() / pBmpUp->getNbFrames(),
-                             *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio );
+    const Position pos = makePosition( lefttop, rightbottom,
+                             rData.m_xPos, rData.m_yPos, width, height,
+                             *pRect, xkeepratio, ykeepratio );
 
     pLayout->addControl( pButton, pos, rData.m_layer );
 }
@@ -536,6 +569,24 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
     // XXX check when it is null
     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
 
+    // width and height are set up from the 'up1' bitmap size
+    int width = pBmpUp1->getWidth();
+    int height = pBmpUp1->getHeight() / pBmpUp1->getNbFrames();
+    bool xkeepratio = rData.m_xKeepRatio;
+    bool ykeepratio = rData.m_yKeepRatio;
+    string lefttop( rData.m_leftTop );
+    string rightbottom( rData.m_rightBottom );
+
+
+    // various checks to help skin developers debug their skin
+    CHECK_BMP( pBmpDown1, pBmpUp1, rData.m_id );
+    CHECK_BMP( pBmpOver1, pBmpUp1, rData.m_id );
+    CHECK_BMP( pBmpUp2, pBmpUp1, rData.m_id );
+    CHECK_BMP( pBmpDown2, pBmpUp1, rData.m_id );
+    CHECK_BMP( pBmpOver2, pBmpUp1, rData.m_id );
+    CHECK_RESIZE_POLICY( lefttop, rightbottom, xkeepratio, ykeepratio,
+                         rData.m_id );
+
     // Create the control
     CtrlCheckbox *pCheckbox = new CtrlCheckbox( getIntf(), *pBmpUp1,
         *pBmpOver1, *pBmpDown1, *pBmpUp2, *pBmpOver2, *pBmpDown2, *pCommand1,
@@ -548,11 +599,9 @@ void Builder::addCheckbox( const BuilderData::Checkbox &rData )
     // XXX (we suppose all the images have the same size...)
     const GenericRect *pRect;
     GET_BOX( pRect, rData.m_panelId , pLayout);
-    const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
-                            rData.m_xPos, rData.m_yPos,
-                            pBmpUp1->getWidth(),
-                            pBmpUp1->getHeight() / pBmpUp1->getNbFrames(),
-                            *pRect, rData.m_xKeepRatio, rData.m_yKeepRatio );
+    const Position pos = makePosition( lefttop, rightbottom,
+                             rData.m_xPos, rData.m_yPos, width, height,
+                             *pRect, xkeepratio, ykeepratio );
 
     pLayout->addControl( pCheckbox, pos, rData.m_layer );
 }