]> git.sesse.net Git - vlc/commitdiff
* skins2/src/theme.cpp: allow specifying lists of IDs for bitmaps and fonts,
authorOlivier Teulière <ipkiss@videolan.org>
Sun, 27 Nov 2005 14:42:02 +0000 (14:42 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Sun, 27 Nov 2005 14:42:02 +0000 (14:42 +0000)
   in controls. The first valid one will be used. This is particularly useful
   for winamp skin, where you cannot know in advance the size of some images,
   so you can define 2 bitmaps, but only one control.

modules/gui/skins2/src/theme.cpp

index bcfef87db483d02c716867b4706c5c024985f3e2..1b824906e7d74b58ff3feb6111af4fca1ac99f50 100644 (file)
@@ -126,14 +126,42 @@ void Theme::saveConfig()
     } \
     return (*it).second.get();
 
+// This macro takes an ID of the form "id1;id2;id3", and returns the object
+// corresponding to the first valid ID. If no ID is valid, it returns NULL.
+// XXX: should we use a template method instead?
+#define FIND_FIRST_OBJECT( mapDataPtr, mapName ) \
+    string rightPart = id; \
+    string::size_type pos; \
+    do \
+    { \
+        pos = rightPart.find( ";" ); \
+        string leftPart = rightPart.substr( 0, pos ); \
+        map<string, mapDataPtr>::const_iterator it = mapName.find( leftPart ); \
+        if( it != mapName.end() ) \
+        { \
+            return (*it).second.get(); \
+            break; \
+        } \
+ \
+        if( pos != string::npos ) \
+        { \
+            rightPart = rightPart.substr( pos, rightPart.size() ); \
+            rightPart = \
+                rightPart.substr( rightPart.find_first_not_of( " \t;" ), \
+                                  rightPart.size() ); \
+        } \
+    } \
+    while( pos != string::npos ); \
+    return NULL;
+
 GenericBitmap *Theme::getBitmapById( const string &id )
 {
-    FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
+    FIND_FIRST_OBJECT( GenericBitmapPtr, m_bitmaps );
 }
 
 GenericFont *Theme::getFontById( const string &id )
 {
-    FIND_OBJECT( GenericFontPtr, m_fonts );
+    FIND_FIRST_OBJECT( GenericFontPtr, m_fonts );
 }
 
 TopWindow *Theme::getWindowById( const string &id )