Ejemplo n.º 1
0
void NodeButton::SetDisabledSelectedNode(INode* val, bool updateSize /*= false*/)
{
	RETURN_IF_EQUAL(mDisabledSelectedNode, val);
	DeleteChild(mDisabledSelectedNode);
	mDisabledSelectedNode = val;
	if (mDisabledSelectedNode!=nullptr)
	{
		InitNode(mDisabledSelectedNode);
		mDisabledSelectedNode->SetName(MEDUSA_PREFIX(DisabledSelected));

		AddChild(mDisabledSelectedNode);
		mDisabledSelectedNode->SetVisible(false);
	}

	if (mButtonState == ButtonState::DisabledSelected)
	{
		OnUpdateNode();
		if (updateSize&&mDisabledSelectedNode!=nullptr)
		{
			SetSize(mDisabledSelectedNode->Size());
		}
	}

	
}
Ejemplo n.º 2
0
IShape* NodeFactory::CreateTriangle(float width, float height, const Color4F& color)
{
	ShapeTriangleMesh* mesh = MeshFactory::Instance().CreateShapeTriangleMesh(width, height, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
}
Ejemplo n.º 3
0
IShape* NodeFactory::CreateCircle(float radius, float precision, const Color4F& color)
{
	ShapeGeneralMesh* mesh = MeshFactory::Instance().CreateShapeCircleMesh(radius, precision, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_TrianglesFan));
	material->SetDrawMode(GraphicsDrawMode::TriangleFan);
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);
	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
	
}
Ejemplo n.º 4
0
LinesShape* NodeFactory::CreateLine(const Point3F& from, const Point3F& to, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateLineMesh(from, to, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_Lines));
	material->SetDrawMode(GraphicsDrawMode::Lines);
	LinesShape* sprite = new LinesShape();
	sprite->Initialize();

	sprite->SetSize(Math::Abs(to.X - from.X), Math::Abs(to.Y - from.Y));
	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;
}
Ejemplo n.º 5
0
IShape* NodeFactory::CreateTriangle(const Point3F& p1, const Point3F& p2, const Point3F& p3, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateShapeTriangleMesh(p1, p2, p3, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	return sprite;

}
Ejemplo n.º 6
0
IShape* NodeFactory::CreateRect(const Size2F& rectSize, const Color4F& color)
{

	ShapeQuadMesh* mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color);
	RETURN_NULL_IF_NULL(mesh);
	IMaterial* material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape));
	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	sprite->SetSize(rectSize);
	return sprite;
}
Ejemplo n.º 7
0
IShape* NodeFactory::CreateRectBorder(const Size2F& rectSize, const Color4F& color)
{
	auto mesh = MeshFactory::Instance().CreateShapeQuadMesh(rectSize, color);
	RETURN_NULL_IF_NULL(mesh);
	auto material = MaterialFactory::Instance().CreateShape(MEDUSA_PREFIX(Shape_WireFrame));
	material->SetDrawMode(GraphicsDrawMode::LineStrip);

	IShape* sprite = new IShape();
	sprite->Initialize();
	sprite->SetSizeToContent(SizeToContent::Mesh);

	sprite->SetMesh(mesh);
	sprite->SetMaterial(material);
	sprite->SetSize(rectSize);
	return sprite;
}
Ejemplo n.º 8
0
void ScrollPanel::OnUpdateScrollBar()
{


	{
		bool isShowHorizontal = false;
		switch (mHorizontalScrollBarVisibility)
		{
			case ScrollBarVisibility::Disabled:
				if (mHorizontalScrollBar != nullptr)
				{
					DeleteChild(mHorizontalScrollBar);
					mHorizontalScrollBar = nullptr;
				}
				break;
			case ScrollBarVisibility::VisibleIfNeed:
			case ScrollBarVisibility::Auto:
				isShowHorizontal = mScrollModel->NeedHorizontalScrollBar();
				if (!isShowHorizontal&&mHorizontalScrollBar != nullptr&&mHorizontalScrollBar->IsVisible())
				{
					mHorizontalScrollBar->StopAllActions();
					mHorizontalScrollBar->SetVisible(false);
				}
				break;
			case ScrollBarVisibility::AlwaysVisible:
				isShowHorizontal = true;
				break;
			default:
				break;
		}

		if (isShowHorizontal)
		{
			float offset = mScrollModel->HorizontalScrollBarOffset();
			float scrollBarWidth = mScrollModel->HorizontalScrollBarWidth();

			if (mHorizontalScrollBar == nullptr)
			{
				mHorizontalScrollBar = (INode*)NodeFactory::Instance().CreateRect( Rect2F(0, 0, 1, mHorizontalScrollBarHeight), mScrollBarColor);
				mHorizontalScrollBar->SetName(MEDUSA_PREFIX(HorizontalScrollBar));
				mHorizontalScrollBar->SetPosition(Point3F::Zero);
				mHorizontalScrollBar->EnableManaged();

				AddChild(mHorizontalScrollBar);
			}


			mHorizontalScrollBar->SetSize(1, mHorizontalScrollBarHeight);
			mHorizontalScrollBar->SetScaleX(scrollBarWidth);
			mHorizontalScrollBar->SetPositionX(offset);
			mHorizontalScrollBar->SetPositionY(0.f);

			if (mVerticalScrollBarVisibility == ScrollBarVisibility::Auto)
			{
				IScrollMathModel::ScrollState state = mScrollModel->State();

				switch (state)
				{
					case IScrollMathModel::ScrollState::None:
						mHorizontalScrollBar->SetOpacity(0.f);
						break;
					case IScrollMathModel::ScrollState::Begin:
						break;
					case IScrollMathModel::ScrollState::StaticScroll:
					case IScrollMathModel::ScrollState::Scrolling:
					case IScrollMathModel::ScrollState::Spring:
						if (Math::IsZero(mHorizontalScrollBar->Opacity()))
						{
							mHorizontalScrollBar->StopAllActions();
							mHorizontalScrollBar->RunAction(new FadeBySpeedAction(mScrollBarOpacityFadeSpeed));
						}
						break;
					case IScrollMathModel::ScrollState::End:
						mHorizontalScrollBar->StopAllActions();
						mHorizontalScrollBar->RunAction(new FadeBySpeedAction(-mScrollBarOpacityFadeSpeed));
						break;
					default:
						break;
				}
			}
		}
	}

	{
		//vertical
		bool isShowVertical = false;
		switch (mVerticalScrollBarVisibility)
		{
			case ScrollBarVisibility::Disabled:
				if (mVerticalScrollBar != nullptr)
				{
					DeleteChild(mVerticalScrollBar);
					mVerticalScrollBar = nullptr;
				}
				break;
			case ScrollBarVisibility::VisibleIfNeed:
			case ScrollBarVisibility::Auto:
				isShowVertical = mScrollModel->NeedVerticalScrollBar();
				if (!isShowVertical&&mVerticalScrollBar != nullptr&&mVerticalScrollBar->IsVisible())
				{
					mVerticalScrollBar->StopAllActions();
					mVerticalScrollBar->SetVisible(false);
				}
				break;
			case ScrollBarVisibility::AlwaysVisible:
				isShowVertical = true;
				break;
			default:
				break;
		}

		if (isShowVertical)
		{
			float offset = mScrollModel->VerticalScrollBarOffset();
			float scrollBarHeight = mScrollModel->VerticalScrollBarHeight();

			if (mVerticalScrollBar == nullptr)
			{
				mVerticalScrollBar = (INode*)NodeFactory::Instance().CreateRect(Rect2F(0, 0, mVerticalScrollBarWidth, 1), mScrollBarColor);
				mVerticalScrollBar->SetName(MEDUSA_PREFIX(VerticalScrollBar));
				mVerticalScrollBar->SetPosition(Point3F::Zero);
				mVerticalScrollBar->SetPositionX(mSize.Width - mVerticalScrollBarWidth);
				mVerticalScrollBar->EnableManaged();

				AddChild(mVerticalScrollBar);
			}


			mVerticalScrollBar->SetSize(mVerticalScrollBarWidth, 1);
			mVerticalScrollBar->SetScaleY(scrollBarHeight);
			mVerticalScrollBar->SetPositionX(mSize.Width - mVerticalScrollBarWidth);
			mVerticalScrollBar->SetPositionY(offset);

			if (mVerticalScrollBarVisibility == ScrollBarVisibility::Auto)
			{
				IScrollMathModel::ScrollState state = mScrollModel->State();

				switch (state)
				{
					case IScrollMathModel::ScrollState::None:
						mVerticalScrollBar->SetOpacity(0.f);
						break;
					case IScrollMathModel::ScrollState::Begin:
						break;
					case IScrollMathModel::ScrollState::StaticScroll:
					case IScrollMathModel::ScrollState::Scrolling:
					case IScrollMathModel::ScrollState::Spring:
						if (Math::IsZero(mVerticalScrollBar->Opacity()))
						{
							mVerticalScrollBar->StopAllActions();
							mVerticalScrollBar->RunAction(new FadeBySpeedAction(mScrollBarOpacityFadeSpeed));
						}
						break;
					case IScrollMathModel::ScrollState::End:
						mVerticalScrollBar->StopAllActions();
						mVerticalScrollBar->RunAction(new FadeBySpeedAction(-mScrollBarOpacityFadeSpeed));
						break;
					default:
						break;
				}
			}

		}

	}


}
Ejemplo n.º 9
0
NodeButton::NodeButton(StringRef name,
							 INode* normalNode,
							 INode* selectedNode/*=nullptr*/,
							 INode* disabledNode/*=nullptr*/,
							 INode* disabledSelectedNode/*=nullptr*/)
							 :IButton(name),
							 mNormalNode(normalNode),
							 mSelectedNode(selectedNode),
							 mDisabledNode(disabledNode),
							 mDisabledSelectedNode(disabledSelectedNode)
{
	bool hasSize = false;
	if (mNormalNode!=nullptr)
	{
		InitNode(mNormalNode);
		mNormalNode->SetName(MEDUSA_PREFIX(Normal));
		
		AddChild(mNormalNode);
		mNormalNode->SetVisible(false);
		SetSize(mNormalNode->Size());	//default to normal size
		hasSize = true;
	}
	if (mSelectedNode != nullptr)
	{
		InitNode(mSelectedNode);
		mSelectedNode->SetName(MEDUSA_PREFIX(Selected));

		AddChild(mSelectedNode);
		mSelectedNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mSelectedNode->Size());
			hasSize = true;
		}
	}
	if (mDisabledNode != nullptr)
	{
		InitNode(mDisabledNode);
		mDisabledNode->SetName(MEDUSA_PREFIX(Disabled));

		AddChild(mDisabledNode);
		mDisabledNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mDisabledNode->Size());
			hasSize = true;
		}
	}
	if (mDisabledSelectedNode != nullptr)
	{
		InitNode(mDisabledSelectedNode);
		mDisabledSelectedNode->SetName(MEDUSA_PREFIX(DisabledSelected));

		AddChild(mDisabledSelectedNode);
		mDisabledSelectedNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mDisabledSelectedNode->Size());
			//hasSize = true;
		}
	}
}