bool ImageBox::SetProperty(UIProperty::Enum prop, const char* val)
{
	switch (prop)
	{
	case UIProperty::TEXTUREATLAS:
	{
									 mTextureAtlasFile = val;
									 return true;
	}
		break;

	case UIProperty::REGION:
	{
		mStrRegion = val;
		if (mTextureAtlasFile.empty()){
			mTextureAtlasFile = "data/textures/gameui.xml";
		}
		SetTextureAtlasRegion(mTextureAtlasFile.c_str(), val);
		return true;
	}
		break;

	case UIProperty::REGIONS:
	{
		mStrRegions = val;
		if (mTextureAtlasFile.empty()){
			mTextureAtlasFile = "data/textures/gameui.xml";
		}
		mAnimation = true;
		auto useNumberData = Split(val, ":");
		if (useNumberData.size() >= 2)
		{
			auto fromtoData = Split(useNumberData[1], ",");
			fromtoData[0] = StripBoth(fromtoData[0].c_str());
			fromtoData[1] = StripBoth(fromtoData[1].c_str());
			unsigned from = StringConverter::ParseUnsignedInt(fromtoData[0].c_str());
			unsigned to = StringConverter::ParseUnsignedInt(fromtoData[1].c_str());
			assert(to > from);
			std::vector<std::string> data;
			char buf[256];
			for (unsigned i = from; i <= to; i++)
			{
				sprintf_s(buf, "%s%u", useNumberData[0].c_str(), i);
				data.push_back(buf);
			}
			SetTextureAtlasRegions(mTextureAtlasFile.c_str(), data);
		}
		else
		{
			auto data = Split(val, ",");
			for (auto& str : data)
			{
				str = StripBoth(str.c_str());
			}
			SetTextureAtlasRegions(mTextureAtlasFile.c_str(), data);
		}
		if (!mAtlasRegions.empty())
		{
			Vec2 texcoords[4];
			mAtlasRegions[mCurFrame]->GetQuadUV(texcoords);
			mUIObject->SetTexCoord(texcoords, 4);
		}
								
		return true;

	}
		break;

	case UIProperty::FPS:
	{
							mSecPerFrame = 1.0f / StringConverter::ParseReal(val);
							return true;
	}
		break;

	case UIProperty::TEXTURE_FILE:
	{
									 SetTexture(val);
									 return true;
	}

	case UIProperty::KEEP_IMAGE_RATIO:
	{
										 SetKeepImageRatio(StringConverter::ParseBool(val, true));
										 return true;
	}
	case UIProperty::FRAME_IMAGE:
	{
		mStrFrameImage = val;
									if (!mFrameImage)
									{
										mFrameImage = CreateChildImageBox();
									}
									mFrameImage->SetTextureAtlasRegion(mTextureAtlasFile.c_str(), val);
									if (strlen(val) == 0)
									{
										mFrameImage->SetVisible(false);
									}
									else
									{
										mFrameImage->SetVisible(true);
									}
									return true;
	}

	case UIProperty::IMAGE_COLOR_OVERLAY:
	{
		mColorOveraySet = true;
											Color color = Color(val);
											if (mUIObject)
											{
												mUIObject->GetMaterial()->SetDiffuseColor(color.GetVec4());
											}
											return true;

	}

	case UIProperty::IMAGE_FIXED_SIZE:
	{
										 mImageFixedSize = StringConverter::ParseBool(val);										 
										 if (mTexture || mAtlasRegion)
										 {
											 DrawAsFixedSize();
										 }
										 
										 return true;

	}

	case UIProperty::IMAGE_ROTATE:
	{
		SetUVRot(mImageRot);		
		return true;

	}

	case UIProperty::IMAGE_LINEAR_SAMPLER:
	{
		mLinearSampler = StringConverter::ParseBool(val);
		if (mUIObject){
			mUIObject->EnableLinearSampler(mLinearSampler);
		}
		return true;
	}

	}

	return __super::SetProperty(prop, val);
}
Example #2
0
void TextField::SetUseBorder(bool use)
{
    if (use && mBorders.empty())
    {
        auto T = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        T->SetHwndId(GetHwndId());
        mBorders.push_back(T);
        T->SetRender3D(mRender3D, GetRenderTargetSize());
        T->SetManualParent(mSelfPtr.lock());
        T->ChangeSizeY(1);
        T->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");


        auto L = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        L->SetHwndId(GetHwndId());
        mBorders.push_back(L);
        L->SetRender3D(mRender3D, GetRenderTargetSize());
        L->SetManualParent(mSelfPtr.lock());
        L->ChangeSizeX(1);
        L->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto R = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        R->SetHwndId(GetHwndId());
        mBorders.push_back(R);
        R->SetRender3D(mRender3D, GetRenderTargetSize());
        R->SetManualParent(mSelfPtr.lock());
        R->SetAlign(ALIGNH::RIGHT, ALIGNV::TOP);
        R->ChangeSizeX(1);
        R->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");


        auto B = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        B->SetHwndId(GetHwndId());
        mBorders.push_back(B);
        B->SetRender3D(mRender3D, GetRenderTargetSize());
        B->SetManualParent(mSelfPtr.lock());
        B->SetAlign(ALIGNH::LEFT, ALIGNV::BOTTOM);
        B->ChangeSizeY(1);
        B->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto LT = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        LT->SetHwndId(GetHwndId());
        mBorders.push_back(LT);
        LT->SetRender3D(mRender3D, GetRenderTargetSize());
        LT->SetManualParent(mSelfPtr.lock());
        LT->ChangeSize(Vec2I(1, 1));
        LT->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto RT = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        RT->SetHwndId(GetHwndId());
        mBorders.push_back(RT);
        RT->SetRender3D(mRender3D, GetRenderTargetSize());
        RT->SetManualParent(mSelfPtr.lock());
        RT->ChangeSize(Vec2I(1, 1));
        RT->SetAlign(ALIGNH::RIGHT, ALIGNV::TOP);
        RT->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto LB = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        LB->SetHwndId(GetHwndId());
        mBorders.push_back(LB);
        LB->SetRender3D(mRender3D, GetRenderTargetSize());
        LB->SetManualParent(mSelfPtr.lock());
        LB->ChangeSize(Vec2I(1, 1));
        LB->SetAlign(ALIGNH::LEFT, ALIGNV::BOTTOM);
        LB->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        auto RB = std::static_pointer_cast<ImageBox>(UIManager::GetInstance().CreateComponent(ComponentType::ImageBox));
        RB->SetHwndId(GetHwndId());
        mBorders.push_back(RB);
        RB->SetRender3D(mRender3D, GetRenderTargetSize());
        RB->SetManualParent(mSelfPtr.lock());
        RB->ChangeSize(Vec2I(1, 1));
        RB->SetAlign(ALIGNH::RIGHT, ALIGNV::BOTTOM);
        RB->SetTextureAtlasRegion("EssentialEngineData/textures/ui.xml", "ThinBorder");

        RefreshBorder();
        RefreshScissorRects();
        UIManager::GetInstance().DirtyRenderList(GetHwndId());
    }
    else if (!use && !mBorders.empty())
    {
        mBorders.clear();
        UIManager::GetInstance().DirtyRenderList(GetHwndId());
    }
}