///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
void FireEventForEachFileFound( const std::string& eventToFire, const std::string& directory, const std::string& searchPattern, bool recurseSubfolders )
{
    Strings files;
    EnumerateFiles( directory, searchPattern, files, recurseSubfolders );

    for (std::string& file : files)
    {
        std::string fileWithoutPath = ExtractFileNameFromPath( file );
        std::string fileName = RemoveFileExtension( fileWithoutPath );
        Strings fileNameTokens;
        Tokenize( fileWithoutPath, fileNameTokens, "." );
        std::string fileExtension = "." + fileNameTokens[1];
        std::string relativePath = ConvertBackSlashesToForwardSlashes( file );
        char fullPath[_MAX_PATH];
        _fullpath( fullPath, relativePath.c_str(), _MAX_PATH );
        std::string fullFilePath = ConvertBackSlashesToForwardSlashes( std::string( fullPath ) );

        ConsolePrintf( "File without path:  %s\n File Name: %s\n File Extension: %s\n File Relative: %s\n File Absolute: %s\n", fileWithoutPath.c_str(), fileName.c_str(), fileExtension.c_str(), relativePath.c_str(), fullFilePath.c_str() );

        NamedProperties props;
        props.Set( "FileName", fileWithoutPath );
        props.Set( "FileExtension", fileExtension );
        props.Set( "FileNameWithoutExtension", fileName );
        props.Set( "FileRelativePath", relativePath );
        props.Set( "FileAbsolutePath", fullFilePath );

        FireEvent( eventToFire, props );
    }
}
void BaseWidget::Update(double deltaSeconds) {
	
	//consider, not updating at all if hidden
	
	WidgetStateProperties& currentStateProperties = GetCurrentStateProperties();

	//calls this widget's update event
	std::string updateEventNameStr = "";
	currentStateProperties.GetProperty("updateEvent", updateEventNameStr);
	if (updateEventNameStr != "") {
		NamedProperties updateEventParams;
		updateEventParams.Set("widgetInstance", this);
		updateEventParams.Set("deltaSeconds", deltaSeconds);
		EventSystem::GetInstance().FireEvent(updateEventNameStr, updateEventParams);
	}

	ProcessInput(deltaSeconds);
	
	currentStateProperties.Update(deltaSeconds);

	//optimize: only update if it is rendering, or if it is dirty
	if (!m_isHidden) {
		UpdateRenderComponent(deltaSeconds);
		SetUICollider2DComponent();
	}
}
Exemple #3
0
UISystem::UISystem() 
{
	//Read all styles and widgets 

	s_rootWidget = new GroupWidget();

	std::vector<std::string> out_styles;
	FindAllFilesOfType("Data/Styles/", "*", out_styles);

	for (auto it = out_styles.begin(); it != out_styles.end(); ++it) {
		std::string filePath = *it;
		ReadStyleFile(filePath);
	}

	std::vector<std::string> out_widgets;
	FindAllFilesOfType("Data/Widgets/", "*", out_widgets);

	for (auto it = out_widgets.begin(); it != out_widgets.end(); ++it) {
		std::string filePath = *it;
		ReadWidgetFile(filePath);
	}

	WidgetStyle wid;
	NamedProperties defaultProps;
	NamedProperties allProps;

	KeyFrameAnimation<RGBA> animColor;
	animColor.AddAnimationFrameAtParameter(RGBA(50, 255, 50, 255), 0.f);
	//defaultProps.Set("color", animColor);

	KeyFrameAnimation<Vec2> offsetAnim;
	offsetAnim.AddAnimationFrameAtParameter(Vec2(100.f, 500.f), 0.f);
	allProps.Set("offset", offsetAnim);

	KeyFrameAnimation<RGBA> animColor2;
	animColor2.AddAnimationFrameAtParameter(RGBA(255, 0, 0, 255), 0.f);
	allProps.Set("color", animColor2);

	wid.AddProperty(UI_STATE_DEFAULT, defaultProps);
	wid.AddGeneralProperty(allProps);
	WidgetBase* widget = AddStyledWidgetExplicitly("Button", "Default", wid, s_rootWidget);

	std::string name;
	widget->GetPropertyForCurrentState("name", name);

	//ToggleWidgetVisibility(name);
	ToggleWidgetEnabled(name);


}
///-----------------------------------------------------------------------
///
///-----------------------------------------------------------------------
void ReportXMLDocumentUsage( XMLNode& xmlDocumentToReport, const ResourceStream& resourceStream, bool reportUsed )
{
	UNUSED( reportUsed );

	std::vector< XMLNode > unusedElements ;
	GetUnusedElements( xmlDocumentToReport, unusedElements );

	if ( !unusedElements.empty() )
	{
		std::string warningMessage = Stringf( "Unused elements in file: %s\n", resourceStream.GetJazzPath().c_str() );
		for ( std::vector< XMLNode >::iterator xmlNodeIter = unusedElements.begin(); xmlNodeIter != unusedElements.end(); ++xmlNodeIter )
		{
			XMLNode& unusedNode = (*xmlNodeIter);
			int stringSize = 0 ;
			char* nodeString = unusedNode.createXMLString( 1, &stringSize );
			if ( nodeString )
			{
				if ( stringSize > 2048 )
				{
					nodeString[ 2040 ] = '.' ;
					nodeString[ 2041 ] = '.' ;
					nodeString[ 2042 ] = '.' ;
					nodeString[ 2043 ] = 0 ;
				}
				delete nodeString ;
			}
		}

		NamedProperties warningProperties ;
		warningProperties.Set( "Warning", warningMessage );
//		FireEvent( "SystemWarningEvent", warningProperties );
	}

}
void BaseWidget::Render(OpenGLRenderer* renderer) {
	
	if (m_isHidden)
		return;
	
	WidgetStateProperties& currentStateProperties = GetCurrentStateProperties();

	std::string renderEventNameStr = "";
	currentStateProperties.GetProperty("renderEvent", renderEventNameStr);
	if (renderEventNameStr != "") {
		NamedProperties renderEventParams;
		renderEventParams.Set("widgetInstance", this);
		EventSystem::GetInstance().FireEvent(renderEventNameStr, renderEventParams);
	}

	float myEdgeSize;
	currentStateProperties.GetProperty("edgeSize", myEdgeSize);

	renderer->SetModelLineWidth((int)myEdgeSize);

	//basic render component
	m_edgeRenderComponent.Render2D(renderer);

	m_renderComponent.Render2D(renderer);

	//draw debug collider
	//renderer->DrawMeshQuad(m_UIColliderComponent.GetBox2DCollider(), Rgba::GREEN);
}
//-----------------------------------------------------------------------------------------------
void XMLDocumentParser::BuildFlagsFromString( const std::string& flagsAsString, NamedProperties& propertiesOut )
{
	std::vector<std::string> flagNames = SplitStringBySingleCharacterDelimiters( flagsAsString, "," );

	std::string actualString;
	bool truthValue;

	for( auto iter = flagNames.begin(); iter != flagNames.end(); ++iter )
	{
		actualString = *iter;

		truthValue = GetTruthValueFromFlag( actualString );
		propertiesOut.Set( actualString, truthValue );
	}
}
NamedProperties WidgetStyle::ExtractWidgetAttributesFromStateDefinition(const TiXmlNode* stateDefinition) {
	NamedProperties widgetAttributes;

	//const char* stateName = stateDefinition->ToElement()->Value();
	const char* onExit = stateDefinition->ToElement()->Attribute("OnExit");
	const char* onEnter = stateDefinition->ToElement()->Attribute("OnEnter");

	if (onEnter) {
		KeyFrameAnimation<std::vector<std::string>> enterSeq;
		enterSeq.AddAnimationFrameAtParameter(SplitString(onEnter, ","), 0.f);

		widgetAttributes.Set("enter event", enterSeq);
	}

	if (onExit) {
		KeyFrameAnimation<std::vector<std::string>> exitSeq;
		exitSeq.AddAnimationFrameAtParameter(SplitString(onExit, ","), 0.f);

		widgetAttributes.Set("exit event", exitSeq);
	}

	const TiXmlNode* bgcolor = stateDefinition->FirstChild("BackgroundColor");

	const TiXmlNode* borderSize = stateDefinition->FirstChild("BorderSize");
	const TiXmlNode* borderColor = stateDefinition->FirstChild("BorderColor");
	const TiXmlNode* size = stateDefinition->FirstChild("Size");
	const TiXmlNode* offset = stateDefinition->FirstChild("Offset");
	const TiXmlNode* opacity = stateDefinition->FirstChild("Opacity");
	const TiXmlNode* textColor = stateDefinition->FirstChild("TextColor");
	const TiXmlNode* fontSize = stateDefinition->FirstChild("FontSize");
	const TiXmlNode* textOpacity = stateDefinition->FirstChild("TextOpacity");
	const TiXmlNode* textContents = stateDefinition->FirstChild("TextContents");
	const TiXmlNode* innerColor = stateDefinition->FirstChild("InnerColor");



	if (bgcolor) {
		const TiXmlElement* bgColorElement = bgcolor->ToElement();
		const char* R = bgColorElement->Attribute("R");
		const char* G = bgColorElement->Attribute("G");
		const char* B = bgColorElement->Attribute("B");
		const char* A = bgColorElement->Attribute("A");

		bool isAnim = bgcolor->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<RGBA> colorSeq = SetupColorAnimation(bgColorElement);
			widgetAttributes.Set("color", colorSeq);
		}
		else {

			if (!A)
				A = "255";

			char Rc = (char)atoi(R);
			char Gc = (char)atoi(G);
			char Bc = (char)atoi(B);
			char Ac = (char)atoi(A);

			KeyFrameAnimation<RGBA> colorSeq;
			colorSeq.AddAnimationFrameAtParameter(RGBA(Rc, Gc, Bc, Ac), 0.f);
			widgetAttributes.Set("color", colorSeq);
		}
	}

	if (size) {

		const TiXmlElement* sizeElement = size->ToElement();
		bool isAnim = size->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<Vec2> sizeSeq = SetupVec2Animation(sizeElement);
			widgetAttributes.Set("size", sizeSeq);
		}
		else {
			const char* sizeX = sizeElement->Attribute("X");
			const char* sizeY = sizeElement->Attribute("Y");

			float X = (float)atof(sizeX);
			float Y = (float)atof(sizeY);

			KeyFrameAnimation<Vec2> sizeSeq;
			sizeSeq.AddAnimationFrameAtParameter(Vec2(X, Y), 0.f);

			widgetAttributes.Set("size", sizeSeq);
		}
	}

	if (offset) {
		const TiXmlElement* offsetElement = offset->ToElement();

		bool isAnim = offset->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<Vec2> offsetSeq = SetupVec2Animation(offsetElement);
			widgetAttributes.Set("offset", offsetSeq);
		}
		else {
			const char* offsetX = offsetElement->Attribute("X");
			const char* offsetY = offsetElement->Attribute("Y");

			float X = (float)atof(offsetX);
			float Y = (float)atof(offsetY);

			KeyFrameAnimation<Vec2> offsetSeq;
			offsetSeq.AddAnimationFrameAtParameter(Vec2(X, Y), 0.f);

			widgetAttributes.Set("offset", offsetSeq);
		}
	}

	if (opacity) {
		bool isAnim = opacity->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<float> opacitySeq = SetupFloatAnimation(opacity->ToElement());
			widgetAttributes.Set("opacity", opacitySeq);
		}
		else {
			KeyFrameAnimation <float> opacitySeq;
			float opacityVal = (float)atof(opacity->ToElement()->Attribute("value"));
			opacitySeq.AddAnimationFrameAtParameter(opacityVal, 0.f);

			widgetAttributes.Set("opacity", opacitySeq);
		}
	}

	if (borderSize) {

		bool isAnim = borderSize->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<float> borderSizeSeq = SetupFloatAnimation(borderSize->ToElement());
			widgetAttributes.Set("border size", borderSizeSeq);
		}
		else {
			KeyFrameAnimation <float> borderSizeSeq;
			float borderSizeVal = (float)atof(borderSize->ToElement()->Attribute("value"));
			borderSizeSeq.AddAnimationFrameAtParameter(borderSizeVal, 0.f);

			widgetAttributes.Set("border size", borderSizeSeq);
		}
	}

	if (borderColor) {

		bool isAnim = borderColor->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<RGBA> colorSeq = SetupColorAnimation(borderColor->ToElement());
			widgetAttributes.Set("border color", colorSeq);
		}
		else {
			KeyFrameAnimation <RGBA> borderColorSeq;

			const TiXmlElement* borderColorElement = borderColor->ToElement();
			const char* R = borderColorElement->Attribute("R");
			const char* G = borderColorElement->Attribute("G");
			const char* B = borderColorElement->Attribute("B");
			const char* A = borderColorElement->Attribute("A");

			unsigned char Rc = (unsigned char)atoi(R);
			unsigned char Gc = (unsigned char)atoi(G);
			unsigned char Bc = (unsigned char)atoi(B);
			unsigned char Ac = '0';

			if (!A)
				Ac = 255;
			else
				Ac = (char)atoi(A);

			borderColorSeq.AddAnimationFrameAtParameter(RGBA(Rc, Gc, Bc, Ac), 0.f);

			widgetAttributes.Set("border color", borderColorSeq);
		}
	}

	if (textColor) {

		bool isAnim = textColor->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<RGBA> colorSeq = SetupColorAnimation(textColor->ToElement());
			widgetAttributes.Set("text color", colorSeq);
		}
		else {
			KeyFrameAnimation <RGBA> textColorSeq;

			const TiXmlElement* bgColorElement = textColor->ToElement();
			const char* R = bgColorElement->Attribute("R");
			const char* G = bgColorElement->Attribute("G");
			const char* B = bgColorElement->Attribute("B");
			const char* A = bgColorElement->Attribute("A");

			unsigned char Rc = (unsigned char)atoi(R);
			unsigned char Gc = (unsigned char)atoi(G);
			unsigned char Bc = (unsigned char)atoi(B);
			unsigned char Ac = '0';

			if (!A)
				Ac = 255;
			else
				Ac = (char)atoi(A);

			textColorSeq.AddAnimationFrameAtParameter(RGBA(Rc, Gc, Bc, Ac), 0.f);

			widgetAttributes.Set("text color", textColorSeq);
		}
	}

	if (fontSize) {

		bool isAnim = fontSize->FirstChild("KeyFrame") != nullptr;
		const TiXmlElement* fontSizeElement = fontSize->ToElement();

		if (isAnim) {
			KeyFrameAnimation<float> fontSizeSeq = SetupFloatAnimation(fontSizeElement);
			widgetAttributes.Set("font size", fontSizeSeq);
		}
		else {
			KeyFrameAnimation <float> fontSizeSeq;
			float fontS = (float)atof(fontSizeElement->Attribute("value"));

			fontSizeSeq.AddAnimationFrameAtParameter(fontS, 0.f);
			widgetAttributes.Set("text scale", fontSizeSeq);
		}
	}

	if (textOpacity) {

		bool isAnim = textOpacity->FirstChild("KeyFrame") != nullptr;
		const TiXmlElement* textOpacityElement = textOpacity->ToElement();

		if (isAnim) {
			KeyFrameAnimation<float> textOpacitySeq = SetupFloatAnimation(textOpacityElement);
			widgetAttributes.Set("text opacity", textOpacitySeq);
		}
		else {
			KeyFrameAnimation <float> textOpacityAnim;
			float textOpacityVal = (float)atof(textOpacityElement->Attribute("value"));

			textOpacityAnim.AddAnimationFrameAtParameter(textOpacityVal, 0.f);
			widgetAttributes.Set("text opacity", textOpacityAnim);
		}
	}

	if (textContents) {
		KeyFrameAnimation <std::string> textcontentsAnim;

		const TiXmlElement* textContentsElement = textContents->ToElement();
		const std::string textContentsStr = textContentsElement->Attribute("value");

		textcontentsAnim.AddAnimationFrameAtParameter(textContentsStr, 0.f);
		widgetAttributes.Set("text", textcontentsAnim);
	}

	if (innerColor) {
		bool isAnim = innerColor->FirstChild("KeyFrame") != nullptr;

		if (isAnim) {
			KeyFrameAnimation<RGBA> innerColorSeq = SetupColorAnimation(innerColor->ToElement());
			widgetAttributes.Set("inner color", innerColorSeq);
		}
		else {
			KeyFrameAnimation <RGBA> innerColorSeq;

			const TiXmlElement* innerColorElement = innerColor->ToElement();
			const char* R = innerColorElement->Attribute("R");
			const char* G = innerColorElement->Attribute("G");
			const char* B = innerColorElement->Attribute("B");
			const char* A = innerColorElement->Attribute("A");

			unsigned char Rc = (unsigned char)atoi(R);
			unsigned char Gc = (unsigned char)atoi(G);
			unsigned char Bc = (unsigned char)atoi(B);
			unsigned char Ac = '0';

			if (!A)
				Ac = 255;
			else
				Ac = (char)atoi(A);

			innerColorSeq.AddAnimationFrameAtParameter(RGBA(Rc, Gc, Bc, Ac), 0.f);

			widgetAttributes.Set("inner color", innerColorSeq);
		}
	}

	return widgetAttributes;
}
Exemple #8
0
void DropdownWidget::Update(float deltaSecond, Vector2& mousePosition)
{
	m_currentStateProperty = m_forStates[m_currentState];
	Vector2 offset = GetOffSet();
	for (unsigned int i = 0; i < NUM_WIDGET_STATE_; i++)
	{
		m_forStates[i].fromWidget.Set("parentsOffset", offset);
		if (m_options.size()>0)
		{
			m_options[0]->m_forStates[i].fromWidget.Set("parentsOffset", offset);
		}
	}
	if (m_isExpend)
	{
		for (unsigned int i = 0; i < m_options.size(); i++)
		{
			NamedProperties properties;
			properties.Set("widget", this, "index", i);
			m_options[i]->Update(deltaSecond, mousePosition, &properties);
			if (i>=1)
			{
				m_options[i]->SetDragable(false);
			}
		}
	}
	else
	{
		NamedProperties properties;
		properties.Set("widget", this, "index", 0);
		m_options[0]->Update(deltaSecond, mousePosition, &properties);

	}
	
	
	if (!m_isExpend)
	{
		Vector2 currentOffset(0.0f, 0.0f);
		currentOffset = m_options[0]->GetOffSet();
		Vector2 mins;
		Vector2 maxs;
		m_options[0]->GetValueInCurrentState("mins", mins);
		m_options[0]->GetValueInCurrentState("maxs", maxs);
		AABB2D box(mins+ currentOffset, maxs+ currentOffset);
		if (box.IsPointInside(mousePosition))
		{
			m_isExpend = true;
		}
	}
	else
	{
		Vector2 currentOffset(0.0f, 0.0f);
		currentOffset = m_options[0]->GetOffSet();
		Vector2 mins;
		Vector2 maxs;
		m_options.back()->GetValueInCurrentState("mins", mins);
		m_options[0]->GetValueInCurrentState("maxs", maxs);
		AABB2D box(mins+ currentOffset, maxs+ currentOffset);
		if (!box.IsPointInside(mousePosition))
		{
			m_isExpend = false;
		}
		//for (unsigned int i = 0; i < m_options.size(); i++)
		//{
		//	m_options[i]->GetValueInCurrentState("mins", mins);
		//	m_options[i]->GetValueInCurrentState("maxs", maxs);
		//	box = AABB2D(mins, maxs);
		//	if (box.IsPointInside(mousePosition) && s_theInputSystem->WasMouseButtonJustReleased(VK_LBUTTON))
		//	{
		//		NamedProperties properties;
		//		properties.Set("widget", this, "index", i);
		//		m_options[i]->CallEvent(&properties);
		//		//SwitchOption(i);
		//	}
		//}
			
	}
}