<?xml version="1.0" encoding="UTF-8"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<composition _name="CDragDrop" >
		<image  name="dragImage" depth="-1000" enabled="false"/>
		<script>
			this.dragObject = null;
			this.dragOffstX = 0;
			this.dragOffstY = 0;
		</script>
		<script><![CDATA[
			function startDrag( anObject)
			{
				if (anObject == null)
					return;
				this.dragImage.visible = true;
				this.dragObject = anObject;
				var tmpX = anObject.x;
				var tmpY = anObject.y;

				var bounds = { xMin: 0, yMin: 0, xMax: anObject.width, yMax: anObject.height};

				if (typeof( anObject.getBounds) == 'function')
					bounds = anObject.getBounds();

				var pnt = anObject.globalToLocal(
					(Player.window.clientWidth - bounds.xMin) / 2,
					(Player.window.clientHeight - bounds.yMin) / 2);

				anObject.x = pnt.x;
				anObject.xy = pnt.y;
				this.dragImage.makeSnapshot( this.dragObject);
				anObject.x = tmpX;
				anObject.y = tmpY;
				this.dragOffstX = Math.round( this.dragImage.width / 2);
				this.dragOffstY = Math.round( this.dragImage.height / 2);
				this.sqDrag.rewindAndPlay();
			}
			function onDrag()
			{
				if ( Mouse.x < 0 || Mouse.x > Player.window.clientWidth
					|| Mouse.y < 0 || Mouse.y > Player.window.clientHeight)
					this.stopDrag();

				this.dragImage.x = this.xMouse - this.dragOffstX + 2;
				this.dragImage.y = this.yMouse - this.dragOffstY + 2;
			}
			function stopDrag()
			{
				this.sqDrag.stop();
				this.dragImage.visible = false;
				this.dragImage.x += this.dragImage.width;
				if (Mouse.target != null && this.dragObject != null)
				{
					var target = Mouse.target;
					while (target != null)
					{
						if (typeof( target.onDrop) == 'function')
						{
							var p = this.localToGlobal( this.xMouse, this.yMouse);
							var dropPoint = target.globalToLocal( p.x, p.y);
							if (target.onDrop( this.dragObject, dropPoint.x, dropPoint.y))
								break;
						}
						target = target.parent;
					}
				}
				this.dragObject = null;
			}
		]]></script>
		<sequencer name="sqDrag" loop="true">
			<script>
				if (this.dragObject != null)
					this.onDrag();
				"onMouseMove";
			</script>
		</sequencer>
		<script event="onMouseUp">
			if (this.dragObject != null)
				this.stopDrag();
		</script>
	</composition>
</rmml>