<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_style_manager.xml,v $
$Revision: 745 $

last change: $Date: 2008-09-15 14:44:27 +0400 (Пн, 15 сен 2008) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->

<composition name="rnmc_StyleManager">
<xml name="stylesXML"/>
<script><![CDATA[
	this.definedStyles = null;

	function loadStylesFromFile(srcFile){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		if(!this.definedStyles)
			this.definedStyles = new Array();
		
		stylesXML.src = srcFile;
		if (!stylesXML.XMLDocument || !stylesXML.XMLDocument.firstChild){
			// Если загружаемый файл не правильный - пишем в трэйсер и выходим
			trace("Файл " + srcFile + " не является правильным XML файлом.");
			return false;
		} else {
			stylesXML.XMLDocument.source = stylesXML.src;
			xmlNode = stylesXML.XMLDocument.firstChild.firstChild;
			while(xmlNode){
				if(xmlNode.nodeName == "style"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("name");
						if (xmlAttribute != null && xmlAttribute.specified
							&& !this.styleExists(xmlAttribute.value)){
							this.definedStyles.push(xmlAttribute.value);
							var newStyle = new Styles();
							newStyle.name = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("fontFamily");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.fontFamily = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("fontSize");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.fontSize = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("fontStyle");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.fontStyle = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("color");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.color = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("fontWeight");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.fontWeight = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("textAlign");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.textAlign = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("textDecoration");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.textDecoration = xmlAttribute.value;
							xmlAttribute =  xmlAttributeMap.getNamedItem("lineHeight");
							if (xmlAttribute != null && xmlAttribute.specified)
								newStyle.lineHeight = xmlAttribute.value;
							newStyle.parent = scene;
						};
					}
				};
				xmlNode = xmlNode.nextSibling;
			};
		}
		return true;
	};
	
	function styleExists(styleName){
		for(var i = 0; i < this.definedStyles.length; i++){
			if(this.definedStyles[i] == styleName)
				return true;
		}
		return false;
	};
	
	function addStyle(styleName, fontFamily, fontSize, fontColor, fontWeight, textAlign, lineHeight){
		if(!styleExists(styleName)){
			var newStyle = new Styles();
			newStyle.name = styleName;
			if (fontFamily != undefined && styleName != null)
				newStyle.fontFamily = fontFamily;
			if (fontSize != undefined && styleName != null)
				newStyle.fontFamily = fontSize;
			if (fontColor != undefined && styleName != null)
				newStyle.fontFamily = fontColor;
			if (fontWeight != undefined && styleName != null)
				newStyle.fontFamily = fontWeight;
			if (textAlign != undefined && styleName != null)
				newStyle.fontFamily = textAlign;
			if (lineHeight != undefined && styleName != null)
				newStyle.fontFamily = lineHeight;
			newStyle.parent = scene;
			this.definedStyles.push(styleName);
			return true;		
		} else {
			return false;
		}
	}	
]]></script>
</composition>

</rmml>