<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by alex (mmlab) -->
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<composition   _name="CDraggableComposition" userEvents="onDragStart, onDragEnd">
		<script>
			this.dragLastX = 0;
			this.dragLastY = 0;
			this.drag=false;
			this.acceptMoveBy = null;
			this.sticks = 0;
			this.useOnlyClientArea = false;

			function	addHotspot(obj)
			{
				obj.onPress = this.onHSPress;
				//trace("### obj.name = " + obj.name + ":" + obj.onPress);
				obj.onRelease = this.onHSRelease;
				obj.onReleaseOutside = this.onHSRelease;
			}

			function onHSPress()
			{
				stick(true);
				fireEvent("onDragStart");
			}

			function onHSRelease()
			{
				stick(false);
				fireEvent("onDragEnd");
			}

			function stick(val)
			{
				if( val)
				{
					if( typeof(this.beginDrag) == "function")
						this.beginDrag();
					this.sticks++;
					if( this.sticks==1)
					{
						dragLastX = scene.xMouse;
						dragLastY = scene.yMouse;
						drag = true;
					}
				}
				else
				{
					if( typeof(this.endDrag) == "function")
						this.endDrag();
					this.sticks--;
					if( this.sticks==0)
					{
						drag = false;
					}
				}
			}
		</script>

		<script event="onMouseMove"><![CDATA[
			if( !drag) 	exit();

			var	nx = scene.xMouse;
			var	ny = scene.yMouse;
			if( nx > 32000)	nx = nx - 65535;
			if( ny > 32000)	ny = ny - 65535;
			var	dx = nx - dragLastX;
			var	dy = ny - dragLastY;
			if( this.acceptMoveBy!=null)
			{
				var	obj = this.acceptMoveBy(dx, dy);
				dx = obj.x;
				dy = obj.y;
			}
			if( this.useOnlyClientArea)
			{
				if( _x+dx+this.width > Player.window.clientWidth)
						dx = Player.window.clientWidth - this.width - _x;
				if( _x+dx < 0)	dx = -_x;
				if( _y+dy+this.height+scene.y > Player.window.clientHeight)
					dy = Player.window.clientHeight - this.height - scene.y - _y;
				if( _y+dy < 0)	dy = -y;
			}
			dragLastX += dx;
			dragLastY += dy;
			_x += dx;
			_y += dy;
		]]></script>
	</composition>
</rmml>
