<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_stdQtEmulation.xml $
$Revision: 823 $

last change: $Date: 2008-11-06 17:21:34 +0300 (Чт, 06 ноя 2008) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->
<composition name="rnmc_stdQTEmulation" class="rnmc_stdMediaObject">
	<button name="rotateLeftArea"
		depth="-1" enabled="false" useHandCursor="false">
		<script event="onRollOver">
			parent.rolloverArea("ROTATE_LEFT");
		</script>
		<script event="onRollOut">
			parent.rolloutArea("ROTATE_LEFT");
		</script>
		<script event="onPress">
			parent.pressArea("ROTATE_LEFT");
		</script>
		<script event="onRelease">
			parent.releaseArea("ROTATE_LEFT");
		</script>
		<script event="onReleaseOutside">
			parent.releaseOutsideArea("ROTATE_LEFT");
		</script>
		<script event="onMouseMove">
			parent.mouseMoveInZone();
		</script>
	</button>

	<button name="rotateRightArea"
		depth="-1" enabled="false" useHandCursor="false">
		<script event="onRollOver">
			parent.rolloverArea("ROTATE_RIGHT");
		</script>
		<script event="onRollOut">
			parent.rolloutArea("ROTATE_RIGHT");
		</script>
		<script event="onPress">
			parent.pressArea("ROTATE_RIGHT");
		</script>
		<script event="onRelease">
			parent.releaseArea("ROTATE_RIGHT");
		</script>
		<script event="onReleaseOutside">
			parent.releaseOutsideArea("ROTATE_RIGHT");
		</script>
		<script event="onMouseMove">
			parent.mouseMoveInZone();
		</script>
	</button>
	
	<script><![CDATA[
		this.type = "rnmc_stdQTEmulation"
		this.areaPercent = 30;

		this.rotateDelay = 0;
		this.rotateDelta = 0;

		this.currentSlide = 0;
		this.currentAngle = 0;

		this.slidesArray = null;

		this.rotateStep = 10;
		this.playing = OBJECT_PLAYING_FALSE;

	// Картинка с текущем кадром
		this.currentImage = 0;

	// Ширина и высота объекта
		this.slideWidth  = 0;
		this.slideHeight = 0;

	// Объекты, показывающиеся на левой и правой зонах поворота
		this.leftArrow = 0;
		this.rightArrow = 0;

		this.yDelta = 10;

		this.direction = "all"; // "forward", "back"

	//	для каждого объекта необходимо определить
	//	какие эффекты к нему применимы
		this.fadeEffectEnabled = true;
		this.moveEffectEnabled = true;
		this.scaleEffectEnabled = false;

		function initFromNode(srcNode){
			var xmlNode = null;
			var xmlAttributeMap = null;
			var xmlAttribute = null;

			var srcBase = null;
			if (srcNode.ownerDocument.source){
				var tmp =
					new String(srcNode.ownerDocument.source).replace("/\/.g", "\\").split("\\")
				tmp.pop();
				srcBase = tmp.join("\\");
			}

			if (!this.slidesSrcArray)
				this.slidesSrcArray = new Array();

			xmlAttributeMap = srcNode.attributes;
			if (xmlAttributeMap){
				xmlAttribute = xmlAttributeMap.getNamedItem("id");
				if (xmlAttribute != null && xmlAttribute.specified)
					this.id = xmlAttribute.value;
				xmlAttribute = xmlAttributeMap.getNamedItem("visible");
				if (xmlAttribute != null && xmlAttribute.specified){
					if(xmlAttribute.value.toLowerCase() == "true")
						this.visibility = OBJECT_VISIBILITY_TRUE;
					else if(xmlAttribute.value.toLowerCase() == "false")
						this.visibility = OBJECT_VISIBILITY_FALSE;
				}
				xmlAttribute = xmlAttributeMap.getNamedItem("enabled");
				if (xmlAttribute != null && xmlAttribute.specified && xmlAttribute.value == "false")
					this.disabled = true;
				xmlAttribute = xmlAttributeMap.getNamedItem("playing");
				if (xmlAttribute != null && xmlAttribute.specified){
					if(xmlAttribute.value.toLowerCase() == "true"){
						this.playing = OBJECT_PLAYING_TRUE;
					} else if(xmlAttribute.value.toLowerCase() == "false"){
						this.playing = OBJECT_PLAYING_FALSE;
					}
				}
			}

			xmlNode = srcNode.firstChild;
			while(xmlNode){
				if(xmlNode.nodeName == "param"){

					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("src");
						if (xmlAttribute != null && xmlAttribute.specified){
							this.objectSrc =
								scene.Utils.makePathSrc(srcBase, xmlAttribute.value);				
							var theXML = new XML();
							theXML.src = this.objectSrc;
							if (theXML.XMLDocument && theXML.XMLDocument.firstChild){
								theXML.XMLDocument.source = this.objectSrc;
								this.initFromNode(theXML.XMLDocument.firstChild);
							}
						}
					}

					parseParamNode(xmlNode);

					if (xmlNode.firstChild){
						var tmpNode = xmlNode.firstChild.findElement("group", "id", "right");
						if (tmpNode)
							this.rightArrow = scene.Utils.initStdMediaGroupFromNode(tmpNode, this);
						tmpNode = xmlNode.firstChild.findElement("group", "id", "left");
						if (tmpNode)
							this.leftArrow = scene.Utils.initStdMediaGroupFromNode(tmpNode, this);
					}

					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("direction");
						if (xmlAttribute != null && xmlAttribute.specified){
							if(xmlAttribute.value.toLowerCase() == "forward")
								this.direction = "forward";
							else if(xmlAttribute.value.toLowerCase() == "back")
								this.direction = "back";
						}
					}
				} else if(xmlNode.nodeName == "rollovermenu"){
					this.parseRolloverMenuNode(xmlNode);
				}  else if(xmlNode.nodeName == "actions"){
					this.parseActionsNode(xmlNode);
				} else if(xmlNode.nodeName == "control"){
					this.parseControlNode(xmlNode);
				} else if(xmlNode.nodeName == "title"){
					this.parseTitleNode(xmlNode);
				} else if(xmlNode.nodeName == "hint"){
					this.parseHintNode(xmlNode);
				} else if(xmlNode.nodeName == "attach"){
					this.parseAttachNode(xmlNode);
				} else if(xmlNode.nodeName == "effects"){
					this.parseEffectsNode(xmlNode);
				} else if(xmlNode.nodeName == "drag"){
					this.parseDraggingNode(xmlNode);
				} else if(xmlNode.nodeName == "scrollmenu"){
					this.parseScrollMenuNode(xmlNode);
				} else if(xmlNode.nodeName == "objectives"){
					this.parseObjectivesNode(xmlNode);
				} else if(xmlNode.nodeName == "slides"){
					var slideNode = xmlNode.firstChild;
					while(slideNode){
						if(slideNode.nodeName == "slide"){
							xmlAttributeMap = slideNode.attributes;
							if (xmlAttributeMap){
								var begin = null, end = null;
								xmlAttribute = xmlAttributeMap.getNamedItem("begin");
								if (xmlAttribute != null && xmlAttribute.specified)
									begin = parseInt(xmlAttribute.value);
								xmlAttribute = xmlAttributeMap.getNamedItem("end");
								if (xmlAttribute != null && xmlAttribute.specified)
									end = parseInt(xmlAttribute.value);
								xmlAttribute = xmlAttributeMap.getNamedItem("src");
								if (xmlAttribute != null && xmlAttribute.specified){
									if (begin != null && end != null){
										var delta = end > begin ? 1 : -1;
										while (begin != end + delta){
											var tmp
												= scene.Utils.sprintf(xmlAttribute.value, begin);
											tmp = scene.Utils.makePathSrc(srcBase, tmp);
											this.slidesSrcArray.push(tmp);
											begin += delta;
										}
									} else {
										this.slidesSrcArray.push(
											scene.Utils.makePathSrc(srcBase, xmlAttribute.value));
									}
								}
							}
						}
						slideNode = slideNode.nextSibling;
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
			return true;
		}

		function loadObject(){
			var slideWidth = 0;
			var slideHeight = 0;

			this.mediaSize = new Object();
			this.mediaSize.width = 0;
			this.mediaSize.height = 0;
			this.slidesArray = new Array();

			this.objectContent = new Composition();
			this.objectContent.parent = this;
			this.objectContent.duration   = 360;
			this.objectContent.currentPos = 0;

			this.currentImage = new Image();
			if(this.slidesSrcArray.length > 0)
				this.currentImage.src = this.slidesSrcArray[0];
			this.currentImage.parent = this.objectContent;

			this.slideWidth  = this.currentImage.width;
			this.slideHeight = this.currentImage.height;
			if (this.objectWidth > 0){
				this.slideWidth = this.objectWidth;
				this.currentImage.width = this.slideWidth;
			}
			if (this.objectHeight > 0){
				this.slideHeight = this.objectHeight;
				this.currentImage.height = this.objectHeight;
			}

			for(var i = 0; i < this.slidesSrcArray.length; i++){
				var newSlide = new Object();
				this.slidesArray.push(newSlide);
			}

		//
			var areaWidth = parseInt(this.slideWidth*this.areaPercent/100);
			var areaHeight = this.slideHeight;

			rotateLeftArea.hitArea =
				"[" + this.objectX + "," + this.objectY + "," + areaWidth + "," + areaHeight + "]";
			if (this.direction != "forward"){
				rotateLeftArea.enabled = true;
				if(this.actionsList && this.actionsList[EVENT_ON_PRESS])
					rotateLeftArea.useHandCursor = true;
			}

			rotateRightArea.hitArea =
				"[" + (this.objectX +(this.slideWidth - areaWidth)) + ","
					+ this.objectY + "," + areaWidth + "," + areaHeight + "]";
			if (this.direction != "back"){
				rotateRightArea.enabled = true;
				if(this.actionsList && this.actionsList[EVENT_ON_PRESS])
					rotateRightArea.useHandCursor = true;
			}

			if(this.slidesArray.length > 0){
				var currentAngle = 0;
				var slideDelta = (360/this.slidesArray.length);
				this.rotateStep = slideDelta;
				for(var i = 0; i < this.slidesArray.length; i++){
					this.slidesArray[i].minAngle = currentAngle;
					currentAngle += slideDelta;
					if(currentAngle > 360)
						currentAngle = 360;
					this.slidesArray[i].maxAngle = currentAngle;
				}
			}
		}

		function unloadObject(){
			this.effectsTarget = null;
			this.pauseObject();
			if (this.currentImage){
				this.currentImage.parent = null;
				this.currentImage = null;
			}

			if (this.objectContent){
				this.objectContent.parent = null;
				this.objectContent = null;
			}
		}

		function showObject(){
			this.x = 0;
			this.y = 0;
			this.loadObject();

			if(this.objectContent){
				this.objectContent.getMediaSize = function() {
					return currentImage.getMediaSize();
				}

				var objectPosition = this.getPosition();
				this.setPosition(objectPosition[0], objectPosition[1], objectPosition[2], objectPosition[3], this.objectDepth);
				this.objectContent.visible = false;

				this.objectContent.opacity = this.objectOpacity;
				this.objectContent.visible = false;

				if (this.leftArrow){
					this.leftArrow.objectDepth = - 1;
					if (this.leftArrow.childObjects){
						for (var i = 0; i < this.leftArrow.childObjects.length; ++i)
							this.leftArrow.childObjects[i].objectHitArea = "[0,0,0,0]";
					}
				}
				if (this.rightArrow){
					this.rightArrow.objectDepth = - 1;
					if (this.rightArrow.childObjects){
						for (var i = 0; i < this.rightArrow.childObjects.length; ++i)
							this.rightArrow.childObjects[i].objectHitArea = "[0,0,0,0]";
					}
				}
			}

		//	перебор присоединённых эффектов для показа
			this.effectsTarget = this.objectContent;
			var showEffectsCount = this.startEffects(EVENT_ON_SHOW);
			if(showEffectsCount == 0){
				this.objectContent.visible = true;
			}

		//	создание объекта подпись
			this.createTitleObject();

		//	если определена панель управления
			if(this.controlDefined && !this.attachedControl){
				this.attachedControl = scene.ControlManager.getControl(this.controlStyle, this);
				if(this.attachedControl){
					this.attachedControl.visible = false;
					this.attachedControl.x = this.controlX;
					this.attachedControl.y = this.controlY;

					this.attachedControl.depth = this.controlDepth;
					this.attachedControl.setDispatcher(this, this.buttonDispatcher);

					if (this.attachedControl.id == "playcontrol")
						this.playControl = this.attachedControl;
					else
						this.playControl = this.attachedControl.getChildControl("playcontrol");

					if(this.playControl){
						this.playControl.attachToObject(this.objectContent);
						this.playControl.setDispatcher(this, this.buttonDispatcher);
						this.playControl.showObject();
					}
					if(this.zoomObject){
						this.attachedControl.hideChildControl("zoomout");
						this.attachedControl.showChildControl("zoomin");
					}
				//	кнопки, относящиеся к подписи
					if(this.titleObject){
						if(this.titleVisible){
							this.attachedControl.hideChildControl("showtitle");
							this.attachedControl.showChildControl("hidetitle");
						} else {
							this.attachedControl.hideChildControl("hidetitle");
							this.attachedControl.showChildControl("showtitle");
						}
					} else {
						this.attachedControl.hideChildControl("hidetitle");
						this.attachedControl.hideChildControl("showtitle");
					}
					this.attachedControl.showChildControl("save");
					this.attachedControl.showChildControl("copy");
					this.attachedControl.showObject();
				}
			}

		// если определён хинт
			if(this.hintDefined && this.hintEvent == HINT_EVENT_ONROLLOVER)
				this.objectContent.onRollOver = this.onRollOverHandlerAlias;
			if(this.hintDefined && this.hintEvent == HINT_EVENT_ONPRESS)
				this.objectContent.onRollOver = this.onPressHandlerAlias;

			if (this.playing == OBJECT_PLAYING_TRUE)
				this.playObject();

			rnmc_stdMediaObject_showObject()
		}

		function hideObject(){
			rnmc_stdMediaObject_hideObject();
		}

		function buttonDispatcher(btnId){
			switch(btnId){
			case "play":
				this.playObject();
				break;
			case "pause":
				this.pauseObject();
				break;
			case "stop":
				this.stopObject();
				break;
			default:
				rnmc_stdMediaObject_buttonDispatcher(btnId);
				break;
			}
		}
		
		function saveAs(){
			if (this.currentImage)
				this.currentImage.saveAs();
		}

		function saveToClipboard(){
			if (this.currentImage)
				this.currentImage.copyToClipboard();
		}

		function playObject(){
			if (this.direction == "back")
				this.rotateDelta = -this.rotateStep;
			else
				this.rotateDelta = this.rotateStep;
			this.objectPlaying = true;
			this.rotateSequencer.playing = true;
			this.objectContent.playing = true;
			if(this.playControl)
				this.playControl.synchronizeControl();
			if (this.rolloverMenuObject)
				this.rolloverMenuObject.synchronizeControl();
			this.applyActions(EVENT_ON_PLAY);
		}

		function pauseObject(){
			this.objectPlaying = false;
			this.rotateSequencer.playing = false;
			this.rotateDelta = 0;
			this.objectContent.playing = false;
			if(this.playControl)
				this.playControl.synchronizeControl();
			if (this.rolloverMenuObject)
				this.rolloverMenuObject.synchronizeControl();
			this.applyActions(EVENT_ON_PAUSE);
		}

		function stopObject(){
			this.pauseObject();
			this.currentAngle = 0;
			this.updateScreen();
			if(this.playControl)
				this.playControl.synchronizeControl();
			if (this.rolloverMenuObject)
				this.rolloverMenuObject.synchronizeControl();
		}

		function rolloverArea(zoneId){
			switch(zoneId){
			case "ROTATE_RIGHT":
				if (this.rightArrow) {
					this.rightArrow.objectX = this._xmouse;
					this.rightArrow.objectY = this._ymouse - this.rightArrow.height;
					this.rightArrow.showObject();
				}
				this.onRollOverHandler();
				break;
			case "ROTATE_LEFT":
				if (this.leftArrow){
					this.leftArrow.objectX = this._xmouse;
					this.leftArrow.objectY = this._ymouse - this.leftArrow.height;
					this.leftArrow.showObject();
				}
				this.onRollOverHandler();
				break;
			}
		}

		function rolloutArea(zoneId){
			switch(zoneId){
				case "ROTATE_RIGHT":
					if (this.rightArrow)
						this.rightArrow.hideObject();
					this.onRollOutHandler();
					break;
				case "ROTATE_LEFT":
					if (this.leftArrow)
						this.leftArrow.hideObject();
					this.onRollOutHandler();
					break;
			}
		}

		function pressArea(zoneId){
			if(this.objectPlaying)
				pauseObject();

			this.captured = true;
			switch(zoneId){
				case "ROTATE_RIGHT":
					this.rotateDelta = this.rotateStep;
					this.onPressHandlerAlias();
					break;
				case "ROTATE_LEFT":
					this.rotateDelta = -this.rotateStep;
					this.onPressHandlerAlias();
					break;
			}

			rotateSequencer.playing = true;
		}

		function releaseArea(zoneId){
			this.captured = false;
			rotateSequencer.playing = false;

			switch(zoneId){
				case "ROTATE_RIGHT":
					this.rotateDelta = 0;
					zoneId = "";
					this.onReleaseHandler();
					break;
				case "ROTATE_LEFT":
					this.rotateDelta = 0;
					zoneId = "";
					this.onReleaseHandler();
					break;
			}
		}

		function releaseOutsideArea(zoneId){
			this.captured = false;
			rotateSequencer.playing = false;

			switch(zoneId){
				case "ROTATE_RIGHT":
					this.rotateDelta = 0;
					zoneId = "";
					break;
				case "ROTATE_LEFT":
					this.rotateDelta = 0;
					zoneId = "";
					break;
			}
		}

		function onPressHandler() {
			rnmc_stdMediaObject_onPressHandler();
		}

		function updateScreen(){
			var lastSlide = this.currentSlide;
			if(this.currentAngle >= 360){
				this.currentAngle -= 360;
				this.currentSlide = 0;
			} else if(this.currentAngle < 0){
				this.currentAngle += 360;
				this.currentSlide = this.slidesArray.length - 1;
			} else if(this.currentAngle >= this.slidesArray[this.currentSlide].maxAngle){
				if(this.currentSlide == this.slidesArray.length - 1){
					this.currentSlide = 0;
				} else {
					this.currentSlide++;
				}
			} else if(this.currentAngle < this.slidesArray[this.currentSlide].minAngle){
				if(this.currentSlide == 0){
					this.currentSlide = this.slidesArray.length - 1;
				} else {
					this.currentSlide--;
				}
			} 

			if(lastSlide != this.currentSlide){
				this.currentImage.src = this.slidesSrcArray[this.currentSlide];
				this.currentImage.width = this.slideWidth;
				this.currentImage.height = this.objectHeight;
			}
		}

		function rotateUpdate(){
			if (this.objectContent){
				this.currentAngle += this.rotateDelta;
				this.objectContent.currentPos = this.currentAngle;
				this.updateScreen();
				if(!this.objectContent.playing && this.playControl)
					this.playControl.synchronizeControl();
				if (!this.objectContent.playing && this.rolloverMenuObject)
					this.rolloverMenuObject.synchronizeControl();
			}
		}

		function mouseMoveHandler(){
			var oldX = this.objectContent.x;
			var oldY = this.objectContent.y;
			rnmc_stdMediaObject_mouseMoveHandler();

			oldX -= this.objectContent.x;
			oldY -= this.objectContent.y;

			this.rotateLeftArea.x -= oldX;
			this.rotateLeftArea.y -= oldY;

			this.rotateRightArea.x -= oldX;
			this.rotateRightArea.y -= oldY;
		}

		function mouseMoveInZone(){
			if (this.rightArrow){
				this.rightArrow.x = this._xmouse;
				this.rightArrow.y = this._ymouse - this.rightArrow.height;
			}

			if (this.leftArrow){
				this.leftArrow.x = this._xmouse;
				this.leftArrow.y = this._ymouse - this.leftArrow.height;
			}
		}
    
    function enableObject(){
      this.enabled = true;
    }
   	
    function disableObject(){
      this.enabled = false;
    }
	]]></script>
	<sequencer name="rotateSequencer" playing="false" loop="true">
		<script>
			this.rotateDelay; // ms
		</script>
		<script>
			rotateUpdate();
		</script>
	</sequencer>
</composition>
</rmml>