Пример #1
0
	void CLabelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
	{
		if( _tcscmp(pstrName, _T("align")) == 0 ) {
			if( _tcsstr(pstrValue, _T("left")) != NULL ) {
				m_uTextStyle &= ~(DT_CENTER | DT_RIGHT | DT_SINGLELINE);
				m_uTextStyle |= DT_LEFT;
			}
			if( _tcsstr(pstrValue, _T("center")) != NULL ) {
				m_uTextStyle &= ~(DT_LEFT | DT_RIGHT );
				m_uTextStyle |= DT_CENTER;
			}
			if( _tcsstr(pstrValue, _T("right")) != NULL ) {
				m_uTextStyle &= ~(DT_LEFT | DT_CENTER | DT_SINGLELINE);
				m_uTextStyle |= DT_RIGHT;
			}
		}
		else if( _tcscmp(pstrName, _T("valign")) == 0 ) {
			if( _tcsstr(pstrValue, _T("top")) != NULL ) {
				m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER);
				m_uTextStyle |= (DT_TOP | DT_SINGLELINE);
			}
			if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) {
				m_uTextStyle &= ~(DT_TOP | DT_BOTTOM );            
				m_uTextStyle |= (DT_VCENTER | DT_SINGLELINE);
			}
			if( _tcsstr(pstrValue, _T("bottom")) != NULL ) {
				m_uTextStyle &= ~(DT_TOP | DT_VCENTER);
				m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE);
			}
		}
		else if( _tcscmp(pstrName, _T("endellipsis")) == 0 ) {
			if( _tcscmp(pstrValue, _T("true")) == 0 ) m_uTextStyle |= DT_END_ELLIPSIS;
			else m_uTextStyle &= ~DT_END_ELLIPSIS;
		}    
		else if( _tcscmp(pstrName, _T("font")) == 0 ) SetFont(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("textcolor")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetTextColor(clrColor);
		}
		else if( _tcscmp(pstrName, _T("disabledtextcolor")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetDisabledTextColor(clrColor);
		}
		else if( _tcscmp(pstrName, _T("textpadding")) == 0 ) {
			RECT rcTextPadding = { 0 };
			LPTSTR pstr = NULL;
			rcTextPadding.left = _tcstol(pstrValue, &pstr, 10);  ASSERT(pstr);    
			rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10);    ASSERT(pstr);    
			rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10);  ASSERT(pstr);    
			rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);    
			SetTextPadding(rcTextPadding);
		}
		else if( _tcscmp(pstrName, _T("showhtml")) == 0 ) SetShowHtml(_tcscmp(pstrValue, _T("true")) == 0);

		else if( _tcscmp(pstrName, _T("enabledeffect")) == 0 ) SetEnabledEffect(_tcscmp(pstrValue, _T("true")) == 0);
		else if( _tcscmp(pstrName, _T("transshadow")) == 0 ) SetTransShadow(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("transtext")) == 0 ) SetTransText(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("transshadow1")) == 0 ) SetTransShadow1(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("transtext1")) == 0 ) SetTransText1(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("gradientangle")) == 0 ) SetGradientAngle(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("enabledstroke")) == 0 ) SetEnabledStroke(_tcscmp(pstrValue, _T("true")) == 0);
		else if( _tcscmp(pstrName, _T("enabledshadow")) == 0 ) SetEnabledShadow(_tcscmp(pstrValue, _T("true")) == 0);
		else if( _tcscmp(pstrName, _T("transstroke")) == 0 ) SetTransStroke(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("gradientlength")) == 0 ) SetGradientLength(_ttoi(pstrValue));
		else if( _tcscmp(pstrName, _T("shadowoffset")) == 0 ){
			LPTSTR pstr = NULL;
			int offsetx = _tcstol(pstrValue, &pstr, 10);	ASSERT(pstr);    
			int offsety = _tcstol(pstr + 1, &pstr, 10);		ASSERT(pstr);
			SetShadowOffset(offsetx,offsety);
		}
		else if( _tcscmp(pstrName, _T("textcolor1")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetTextColor1(clrColor);
		}
		else if( _tcscmp(pstrName, _T("textshadowcolora")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetTextShadowColorA(clrColor);
		}
		else if( _tcscmp(pstrName, _T("textshadowcolorb")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetTextShadowColorB(clrColor);
		}
		else if( _tcscmp(pstrName, _T("strokecolor")) == 0 ) {
			if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
			LPTSTR pstr = NULL;
			DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
			SetStrokeColor(clrColor);
		}
		else if( _tcscmp(pstrName, _T("autocalcwidth")) == 0 ) {
			SetAutoCalcWidth(_tcscmp(pstrValue, _T("true")) == 0);
		}
		else CControlUI::SetAttribute(pstrName, pstrValue);
	}
Пример #2
0
void UIStaticText::LoadFromYamlNode(const YamlNode * node, UIYamlLoader * loader)
{
    UIControl::LoadFromYamlNode(node, loader);

    const YamlNode * fontNode = node->Get("font");
    const YamlNode * textNode = node->Get("text");
    const YamlNode * multilineNode = node->Get("multiline");
    const YamlNode * multilineBySymbolNode = node->Get("multilineBySymbol");
    const YamlNode * fittingNode = node->Get("fitting");
    const YamlNode * textColorNode = node->Get("textcolor");
    const YamlNode * shadowColorNode = node->Get("shadowcolor");
    const YamlNode * shadowOffsetNode = node->Get("shadowoffset");
    const YamlNode * textAlignNode = node->Get("textalign");
    const YamlNode * textColorInheritTypeNode = node->Get("textcolorInheritType");
    const YamlNode * shadowColorInheritTypeNode = node->Get("shadowcolorInheritType");

    if (fontNode)
    {
        const String & fontName = fontNode->AsString();
        Font * font = loader->GetFontByName(fontName);
        SetFont(font);
    }

    bool multiline = loader->GetBoolFromYamlNode(multilineNode, false);
    bool multilineBySymbol = loader->GetBoolFromYamlNode(multilineBySymbolNode, false);
    SetMultiline(multiline, multilineBySymbol);

    if(fittingNode)
    {
        SetFittingOption(loader->GetFittingOptionFromYamlNode(fittingNode));
    }

    if(textColorNode)
    {
        SetTextColor(textColorNode->AsColor());
    }

    if(shadowColorNode)
    {
        SetShadowColor(shadowColorNode->AsColor());
    }

    if(shadowOffsetNode)
    {
        SetShadowOffset(shadowOffsetNode->AsVector2());
    }

    if (textAlignNode)
    {
        SetTextAlign(loader->GetAlignFromYamlNode(textAlignNode));
    }

    if (textNode)
    {
        SetText(LocalizedString(textNode->AsWString()));
    }

    if (textColorInheritTypeNode)
    {
        GetTextBackground()->SetColorInheritType((UIControlBackground::eColorInheritType)loader->GetColorInheritTypeFromNode(textColorInheritTypeNode));
    }

    if (shadowColorInheritTypeNode)
    {
        GetShadowBackground()->SetColorInheritType((UIControlBackground::eColorInheritType)loader->GetColorInheritTypeFromNode(shadowColorInheritTypeNode));
    }
}
Пример #3
0
void UIStaticText::LoadFromYamlNode(YamlNode * node, UIYamlLoader * loader)
{
	UIControl::LoadFromYamlNode(node, loader);
	
	YamlNode * fontNode = node->Get("font");
	YamlNode * textNode = node->Get("text");
	YamlNode * multilineNode = node->Get("multiline");
    YamlNode * multilineBySymbolNode = node->Get("multilineBySymbol");
    YamlNode * fittingNode = node->Get("fitting");
	YamlNode * textColorNode = node->Get("textcolor");
	YamlNode * shadowColorNode = node->Get("shadowcolor");
	YamlNode * shadowOffsetNode = node->Get("shadowoffset");

	if (fontNode)
	{
		const String & fontName = fontNode->AsString();
		Font * font = loader->GetFontByName(fontName);
		SetFont(font);
	}

	bool multiline = loader->GetBoolFromYamlNode(multilineNode, false);
    bool multilineBySymbol = loader->GetBoolFromYamlNode(multilineBySymbolNode, false);
	SetMultiline(multiline, multilineBySymbol);
	
    if(fittingNode)
    {
        int32 fittingArray[] = {TextBlock::FITTING_DISABLED, TextBlock::FITTING_ENLARGE, 
                                TextBlock::FITTING_REDUCE, TextBlock::FITTING_POINTS};
		String fittingValues[] = {"Disabled", "Enlarge", "Reduce", "Points"};

		const String & fittinOption = fittingNode->AsString();
        
        int32 fittingType = 0;
        for(int32 i = 0 ; i < 4; ++i)
        {
            size_t find = fittinOption.find(fittingValues[i]);
            if(find != fittinOption.npos)
            {
                fittingType |= fittingArray[i];
            }
        }

        SetFittingOption(fittingType);
    }
    
	if (textNode)
	{
		SetText(LocalizedString(textNode->AsWString()));
	}

	if(textColorNode)
	{
		Vector4 c = textColorNode->AsVector4();
		SetTextColor(Color(c.x, c.y, c.z, c.w));
	}

	if(shadowColorNode)
	{
		Vector4 c = shadowColorNode->AsVector4();
		SetShadowColor(Color(c.x, c.y, c.z, c.w));
	}

	if(shadowOffsetNode)
	{
		SetShadowOffset(shadowOffsetNode->AsVector2());
	}

	YamlNode * alignNode = node->Get("align");
	SetAlign(loader->GetAlignFromYamlNode(alignNode)); // NULL is also OK here.
}
Пример #4
0
void UITextField::LoadFromYamlNode(YamlNode * node, UIYamlLoader * loader)
{
	UIControl::LoadFromYamlNode(node, loader);

    YamlNode * textNode = node->Get("text");
	if (textNode)
    {
        SetText(textNode->AsWString());
    }

    YamlNode * fontNode = node->Get("font");
    if (fontNode)
    {
        Font * font = loader->GetFontByName(fontNode->AsString());
        if (font)
            SetFont(font);
    }

    if(staticText)
    {
        staticText->SetRect(Rect(0,0,GetRect().dx, GetRect().dy));
		
		YamlNode * textColorNode = node->Get("textcolor");
		YamlNode * shadowColorNode = node->Get("shadowcolor");
		YamlNode * shadowOffsetNode = node->Get("shadowoffset");
		YamlNode * textAlignNode = node->Get("textalign");
		
		if(textColorNode)
		{
			Vector4 c = textColorNode->AsVector4();
			SetTextColor(Color(c.x, c.y, c.z, c.w));
		}

		if(shadowColorNode)
		{
			Vector4 c = shadowColorNode->AsVector4();
			SetShadowColor(Color(c.x, c.y, c.z, c.w));
		}

		if(shadowOffsetNode)
		{
			SetShadowOffset(shadowOffsetNode->AsVector2());
		}

		if(textAlignNode)
		{
			SetTextAlign(loader->GetAlignFromYamlNode(textAlignNode));
		}
    }
    //InitAfterYaml();

#if 0
	YamlNode * orientNode = node->Get("orientation");
	if (orientNode)
	{
		if (orientNode->AsString() == "Vertical")
			orientation = ORIENTATION_VERTICAL;
		else if (orientNode->AsString() == "Horizontal")
			orientation = ORIENTATION_HORIZONTAL;
	}



		// TODO
	InitAfterYaml();
#endif
}