Ejemplo n.º 1
0
bool SColorParser::ParseValue(const SStringW & strValue, COLORREF & value)
{
	int r = 255, g = 255, b = 255, a = 255;
    int nSeg=0;
    SStringW strValueL = strValue;
    strValueL.MakeLower();
    if(strValueL.Left(1)==L"#")
    {
        nSeg = swscanf(strValueL,L"#%02x%02x%02x%02x",&r,&g,&b,&a);
    }else if(strValueL.Left(4).CompareNoCase(L"rgba")==0)
    {
        nSeg = swscanf(strValueL,L"rgba(%d,%d,%d,%d)",&r,&g,&b,&a);                
    }else if(strValueL.Left(3).CompareNoCase(L"rgb")==0)
    {
        nSeg = swscanf(strValueL,L"rgb(%d,%d,%d)",&r,&g,&b);                
    }
    if(nSeg!=3 && nSeg != 4)
    {
        SASSERT_FMT(FALSE,TEXT("ParseColor Failed with [%s]"),S_CW2T(strValue));
        return false;
    }else
    {
        value = RGBA(r,g,b,a);
        return true;
    }
}
Ejemplo n.º 2
0
    bool SPropertyItemColor::ParseValue(const SStringT & strValue, COLORREF & value)
	{
		int r,g,b,a=255;
		int nSeg=0;
		SStringW strValueL = strValue;
		strValueL.MakeLower();
		if(strValueL.Left(1)==L"#")
		{
			nSeg = swscanf(strValueL,L"#%02x%02x%02x%02x",&r,&g,&b,&a);
		}else if(strValueL.Left(4).CompareNoCase(L"rgba")==0)
		{
			nSeg = swscanf(strValueL,L"rgba(%d,%d,%d,%d)",&r,&g,&b,&a);                
		}else if(strValueL.Left(3).CompareNoCase(L"rgb")==0)
		{
			nSeg = swscanf(strValueL,L"rgb(%d,%d,%d)",&r,&g,&b); 
		}
		if(nSeg!=3 && nSeg != 4)
		{
			//SASSERT_FMT(FALSE,TEXT("解析颜色值失败 [%s]"),S_CW2T(strValue));
			value = CR_INVALID;
			return false;
		}else
		{
			value = RGBA(r,g,b,a);
			return true;
		}
	}
Ejemplo n.º 3
0
	void SLayoutSize::parseString(const SStringW & strSize)
	{
		if(strSize.IsEmpty()) return;
		SStringW strUnit = strSize.Right(2);
		strUnit.MakeLower();
		unit = px;
		for(int i=0; i< ARRAYSIZE(s_pszUnit);i++)
		{
			if(strUnit.Compare(s_pszUnit[i]) == 0)
			{
				unit = (Unit)i;
				break;
			}
		}
		fSize = (float)_wtof(strSize);
	}