Browse Source

- Added support for ColorF & ColorI for both values and stock-color enums.

MelvMay-GG 12 years ago
parent
commit
0d5dddf
3 changed files with 135 additions and 43 deletions
  1. 30 42
      engine/source/graphics/color.cc
  2. 34 0
      engine/source/graphics/color.h
  3. 71 1
      engine/source/persistence/taml/taml.cc

+ 30 - 42
engine/source/graphics/color.cc

@@ -48,35 +48,6 @@ static typeColorIToNameHash    mColorIToName;
 
 //-----------------------------------------------------------------------------
 
-class StockColorItem
-{
-private:
-    StockColorItem() {}
-
-public:
-    StockColorItem( const char* pName, const U8 red, const U8 green, const U8 blue, const U8 alpha = 255 )
-    {
-        // Sanity!
-        AssertFatal( pName != NULL, "Stock color name cannot be NULL." );
-
-        // Set stock color.
-        // NOTE:-   We'll use the char pointer here.  We can yet use the string-table unfortunately.
-        mColorName = pName;
-        mColorI.set( red, green, blue, alpha );
-        mColorF = mColorI;
-    }
-
-    inline const char*      getColorName( void ) const { return mColorName; }
-    inline const ColorF&    getColorF( void ) const { return mColorF; }
-    inline const ColorI&    getColorI( void ) const { return mColorI; }
-
-    const char*         mColorName;
-    ColorF              mColorF;
-    ColorI              mColorI;
-};
-
-//-----------------------------------------------------------------------------
-
 StockColorItem StockColorTable[] =
 {
     StockColorItem( "InvisibleBlack", 0, 0, 0, 0 ),
@@ -368,6 +339,32 @@ StringTableEntry StockColor::name( const ColorI& color )
 
 //-----------------------------------------------------------------------------
 
+S32 StockColor::getCount( void )
+{
+    return sizeof(StockColorTable) / sizeof(StockColorItem);
+}
+
+//-----------------------------------------------------------------------------
+
+const StockColorItem* StockColor::getColorItem( const S32 index )
+{
+    // Fetch stock color count.
+    const S32 stockColorCount = StockColor::getCount();
+
+    // Is the stock color index in range?
+    if ( index < 0 || index >= stockColorCount )
+    {
+        // No, so warn.
+        Con::warnf("StockColor::getName() - Specified color index '%d' is out of range.  Range is 0 to %d.", index, stockColorCount-1 );
+        return NULL;
+    }
+
+    // Return color name.
+    return &(StockColorTable[index]);
+}
+
+//-----------------------------------------------------------------------------
+
 ColorF::ColorF( const char* pStockColorName )
 {
     // Set stock color.
@@ -582,7 +579,7 @@ ConsoleSetType( TypeColorI )
 ConsoleFunction( getStockColorCount, S32, 1, 1, "() - Gets a count of available stock colors.\n"
                                                 "@return A count of available stock colors." )
 {
-    return sizeof(StockColorTable) / sizeof(StockColorItem);
+    return StockColor::getCount();
 }
 
 //-----------------------------------------------------------------------------
@@ -594,19 +591,10 @@ ConsoleFunction( getStockColorName, const char*, 2, 2,  "(stockColorIndex) - Get
     // Fetch stock color index.
     const S32 stockColorIndex = dAtoi(argv[1]);
 
-    // Fetch stock color count.
-    const S32 stockColorCount = sizeof(StockColorTable) / sizeof(StockColorItem);
+    // Fetch the color item.
+    const StockColorItem* pColorItem = StockColor::getColorItem( stockColorIndex );
 
-    // Is the stock color index in range?
-    if ( stockColorIndex < 0 || stockColorIndex >= stockColorCount )
-    {
-        // No, so warn.
-        Con::warnf("getStockColorName() - Specified color index '%d' is out of range.  Range is 0 to %d.", stockColorIndex, stockColorCount-1 );
-        return StringTable->EmptyString;
-    }
-
-    // Return color name.
-    return StockColorTable[stockColorIndex].getColorName();
+    return pColorItem == NULL ? NULL : pColorItem->getColorName();
 }
 
 //-----------------------------------------------------------------------------

+ 34 - 0
engine/source/graphics/color.h

@@ -36,6 +36,7 @@
 DefineConsoleType( TypeColorI )
 DefineConsoleType( TypeColorF )
 
+
 //-----------------------------------------------------------------------------
 
 class ColorI;
@@ -176,6 +177,36 @@ class ColorI
    U16 get4444() const;
 };
 
+
+//-----------------------------------------------------------------------------
+
+class StockColorItem
+{
+private:
+    StockColorItem() {}
+
+public:
+    StockColorItem( const char* pName, const U8 red, const U8 green, const U8 blue, const U8 alpha = 255 )
+    {
+        // Sanity!
+        AssertFatal( pName != NULL, "Stock color name cannot be NULL." );
+
+        // Set stock color.
+        // NOTE:-   We'll use the char pointer here.  We can yet use the string-table unfortunately.
+        mColorName = pName;
+        mColorI.set( red, green, blue, alpha );
+        mColorF = mColorI;
+    }
+
+    inline const char*      getColorName( void ) const { return mColorName; }
+    inline const ColorF&    getColorF( void ) const { return mColorF; }
+    inline const ColorI&    getColorI( void ) const { return mColorI; }
+
+    const char*         mColorName;
+    ColorF              mColorF;
+    ColorI              mColorI;
+};
+
 //-----------------------------------------------------------------------------
 
 class StockColor
@@ -187,6 +218,9 @@ public:
     static StringTableEntry name( const ColorF& color );
     static StringTableEntry name( const ColorI& color );
 
+    static S32 getCount( void );
+    static const StockColorItem* getColorItem( const S32 index );
+
     static void create( void );
     static void destroy( void );
 };

+ 71 - 1
engine/source/persistence/taml/taml.cc

@@ -959,7 +959,7 @@ bool Taml::generateTamlSchema( const char* pFilename )
     pRectFElementA->SetAttribute( "base", "xs:string" );
     pRectFTypeElement->LinkEndChild( pRectFElementA );
     TiXmlElement* pRectFElementB = new TiXmlElement( "xs:pattern" );
-    pRectFElementB->SetAttribute( "value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b" );   
+    pRectFElementB->SetAttribute( "value", "(\\b[-]?(b[0-9]+)?\\.)?[0-9]+\\b" );   
     pRectFElementA->LinkEndChild( pRectFElementB );
 
     // AssetId.
@@ -976,6 +976,68 @@ bool Taml::generateTamlSchema( const char* pFilename )
     pAssetIdElementB->SetAttribute( "value", buffer );
     pAssetIdElementA->LinkEndChild( pAssetIdElementB );
 
+    // Color Enums.
+    TiXmlComment* pColorEnumsComment = new TiXmlComment( "Color Enums" );
+    pSchemaElement->LinkEndChild( pColorEnumsComment );
+    TiXmlElement* pColorEnumsTypeElement = new TiXmlElement( "xs:simpleType" );
+    pColorEnumsTypeElement->SetAttribute( "name", "Color_Enums" );
+    pSchemaElement->LinkEndChild( pColorEnumsTypeElement );
+    TiXmlElement* pColorEnumsRestrictionElement = new TiXmlElement( "xs:restriction" );
+    pColorEnumsRestrictionElement->SetAttribute( "base", "xs:string" );
+    pColorEnumsTypeElement->LinkEndChild( pColorEnumsRestrictionElement );
+    const S32 ColorEnumsCount = StockColor::getCount();
+    for( S32 index = 0; index < ColorEnumsCount; ++index )
+    {
+        // Add enumeration element.
+        TiXmlElement* pColorEnumsAttributeEnumerationElement = new TiXmlElement( "xs:enumeration" );
+        pColorEnumsAttributeEnumerationElement->SetAttribute( "value", StockColor::getColorItem(index)->getColorName() );
+        pColorEnumsRestrictionElement->LinkEndChild( pColorEnumsAttributeEnumerationElement );
+    }
+
+    // ColorF.
+    TiXmlComment* pColorFValuesComment = new TiXmlComment( "ColorF Values" );
+    pSchemaElement->LinkEndChild( pColorFValuesComment );
+    TiXmlElement* pColorFValuesTypeElement = new TiXmlElement( "xs:simpleType" );
+    pColorFValuesTypeElement->SetAttribute( "name", "ColorF_Values" );
+    pSchemaElement->LinkEndChild( pColorFValuesTypeElement );
+    TiXmlElement* pColorFValuesElementA = new TiXmlElement( "xs:restriction" );
+    pColorFValuesElementA->SetAttribute( "base", "xs:string" );
+    pColorFValuesTypeElement->LinkEndChild( pColorFValuesElementA );
+    TiXmlElement* pColorFValuesElementB = new TiXmlElement( "xs:pattern" );
+    pColorFValuesElementB->SetAttribute( "value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b" );
+    pColorFValuesElementA->LinkEndChild( pColorFValuesElementB );
+
+    TiXmlComment* pColorFComment = new TiXmlComment( "ColorF Console Type" );
+    pSchemaElement->LinkEndChild( pColorFComment );
+    TiXmlElement* pColorFTypeElement = new TiXmlElement( "xs:simpleType" );
+    pColorFTypeElement->SetAttribute( "name", "ColorF_ConsoleType" );
+    pSchemaElement->LinkEndChild( pColorFTypeElement );
+    TiXmlElement* pColorFUnionElement = new TiXmlElement( "xs:union" );
+    pColorFUnionElement->SetAttribute( "memberTypes", "ColorF_Values Color_Enums" );
+    pColorFTypeElement->LinkEndChild( pColorFUnionElement );
+
+    // ColorI.
+    TiXmlComment* pColorIValuesComment = new TiXmlComment( "ColorI Values" );
+    pSchemaElement->LinkEndChild( pColorIValuesComment );
+    TiXmlElement* pColorIValuesTypeElement = new TiXmlElement( "xs:simpleType" );
+    pColorIValuesTypeElement->SetAttribute( "name", "ColorI_Values" );
+    pSchemaElement->LinkEndChild( pColorIValuesTypeElement );
+    TiXmlElement* pColorIValuesElementA = new TiXmlElement( "xs:restriction" );
+    pColorIValuesElementA->SetAttribute( "base", "xs:string" );
+    pColorIValuesTypeElement->LinkEndChild( pColorIValuesElementA );
+    TiXmlElement* pColorIValuesElementB = new TiXmlElement( "xs:pattern" );
+    pColorIValuesElementB->SetAttribute( "value", "[-]?[0-9]* [-]?[0-9]* [-]?[0-9]* [-]?[0-9]*" );
+    pColorIValuesElementA->LinkEndChild( pColorIValuesElementB );
+
+    TiXmlComment* pColorIComment = new TiXmlComment( "ColorI Console Type" );
+    pSchemaElement->LinkEndChild( pColorIComment );
+    TiXmlElement* pColorITypeElement = new TiXmlElement( "xs:simpleType" );
+    pColorITypeElement->SetAttribute( "name", "ColorI_ConsoleType" );
+    pSchemaElement->LinkEndChild( pColorITypeElement );
+    TiXmlElement* pColorIUnionElement = new TiXmlElement( "xs:union" );
+    pColorIUnionElement->SetAttribute( "memberTypes", "ColorI_Values Color_Enums" );
+    pColorITypeElement->LinkEndChild( pColorIUnionElement );
+
     // *************************************************************
     // Generate engine type elements.
     // *************************************************************
@@ -1176,6 +1238,14 @@ bool Taml::generateTamlSchema( const char* pFilename )
                 {
                     pFieldTypeDescription = "RectF_ConsoleType";
                 }
+                else if( fieldType == TypeColorF )
+                {
+                    pFieldTypeDescription = "ColorF_ConsoleType";
+                }
+                else if( fieldType == TypeColorI )
+                {
+                    pFieldTypeDescription = "ColorI_ConsoleType";
+                }
                 else if(    fieldType == TypeAssetId ||
                             fieldType == TypeImageAssetPtr ||
                             fieldType == TypeAnimationAssetPtr ||