<?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">
	<!--
Photo camera
-->
	<include src="dragcomp.xml" />
	<composition _name="CCamEye" _class="CDraggableComposition" _depth="-110" _x="265" _y="265" enabled="true">
		<image _name="imFilm" _visible="true">
			<script>
				this.autoUpdateMode = true;
				function setAutoUpdatePhotolist(aval)
				{
					this.autoUpdateMode = aval;
				}
				function saveAs(fileName, atxt, akeepsize)
				{
					this.dll.call("", "saveAs", fileName);
					if( autoUpdateMode)
						scene.photoList.addPhoto(fileName, atxt, akeepsize);
				}
			</script>
			<plugin name="dll" src="rmeq:dlls\chem3drnd.dll" uid="mmlabSnapshotPlugin"/>
		</image>
		<script><![CDATA[
			this.cellsize = 40;
			this.onShot = null;
			this.images = new Array();
			//this.lastxmouse = 0;
			//this.lastymouse = 0;
			for(j=0; j<9; j++)
			{
				i = new Image();
				i.src = "rmeq:environment\\photo\\cameye.png";
				i._name = "cambit"+j;
				i.parent = this;
				i.enabled = true;
				this.images[this.images.length] = i;
				var cx = this.cellsize*(j%3);
				var cy = this.cellsize*Math.floor(j/3);
				i.crop(cx, cy,this.cellsize,this.cellsize);
			}
		]]></script>
		<script><![CDATA[
			function	resize(nw, nh)
			{
				//trace("resized["+nw+","+ nh+"]");
				this.images[1]._x = this.cellsize;	this.images[1]._y = 0;	this.images[1]._width = nw - 2*this.cellsize;
				this.images[2]._x = nw - this.cellsize;	this.images[2]._y = 0;

				this.images[3]._x = 0;	this.images[3]._y = this.cellsize;	this.images[3]._height = nh - 2*this.cellsize;
				this.images[4]._x = this.cellsize;	this.images[4]._y = this.cellsize;	this.images[4]._height = nh - 2*this.cellsize;	this.images[4]._width = nw - 2*this.cellsize;
				this.images[5]._x = nw - this.cellsize;	this.images[5]._y = this.cellsize;	this.images[5]._height = nh - 2*this.cellsize;

				this.images[6]._x = 0;	this.images[6]._y = nh - this.cellsize;
				this.images[7]._x = this.cellsize;	this.images[7]._y = nh - this.cellsize;		this.images[7]._width = nw - 2*this.cellsize;
				this.images[8]._x = nw - this.cellsize;	this.images[8]._y = nh - this.cellsize;
			}
			function showFrame()
			{
				var xpos = scene._xmouse - this._width/2;
				if (xpos < 0)
					xpos = 0;
				this._x = xpos;
				this._y = scene._ymouse - this._height + 2;
				/*this.lastxmouse = scene._xmouse;
				this.lastymouse = scene._ymouse;*/
				this._visible = true;
				this.enabled = true;
trace("#FF0000 this.sticks="+this.sticks);
				this.stick(true);
			}
			function hideFrame()
			{
				this._visible = false;
				this.enabled = false;
			}

			function cancelShot()
			{
				trace("#FF0090-----------------------------------------");
				trace("#FF0090-----------------------------------------");
				trace("#FF0090-----------------------------------------");
				trace("#FF0090-----------------------------------------");
				if( this.sticks == 1)
				{
					this.stick(false);
					this.hideFrame();
					this.imFilm.hide();
				}
			}

			this.acceptMoveBy = function(dx, dy)
			{
				var obj = new Object;
				obj.x = dx;
				obj.y = dy;
				if( this._x + this._width + dx > 800)
					obj.x = 800 - (this._x + this._width);
				if( this._x + dx < 0)
					obj.x = -this._x;
				if( this._y + this._height + dy > 600)
					obj.y = 600 - (this._y + this._height);
				if( this._y + dy < 0)
					obj.y = -this._y;
				return obj;
			}
	]]></script>
	<!--<script event="onMouseMove">
		this._x += (scene._xmouse - this.lastxmouse);
		this._y += (scene._ymouse - this.lastymouse);
		this.lastxmouse = scene._xmouse;
		this.lastymouse = scene._ymouse;
	</script>-->
	<script event="onPress"><![CDATA[
			this.stick(false);
			this.hideFrame();
			var realX = this._x + scene.x;
			var realY = this._y + scene.y;
			this.imFilm.makeSnapshot(scene, new Rectangle(realX,realY,realX+this._width,realY+this._height));
			var tmp_path = scene.labReportWindow.imgPhoto.tempDir + Player.module.identifier.replace( /:/g, '_') + '\\image';
			tmp_path += (scene.photoList.list.nextId+1) + ".png";
			this.imFilm.saveAs(tmp_path);
			this.imFilm.hide();

			/*
			var mod = new Module;
			mod.create("mod.pref", "modalais");
			var modid = mod.identifier;
			mod.saveMedia(this.imFilm, "\\im1.png");
			mod.close();
			*/
			/*if (scene.loadReport())
				scene.labReportWin.savePhoto( this.imFilm);*/

			if( this.onShot!=null)
				this.onShot();
			parent.onShotDone();
	]]></script>
	</composition>

	<composition _name="CPhotoCamera" userEvents="evShotDone">
		<composition _class="CCamEye" _name="cameye" _visible="false"/>
		<script >
			cameye.onShot = function(){
				sePhotoShot.rewindAndPlay();
			};
		</script>
		<!--<audio _name="sePhotoFlash" src="rmsnd:SE\se_photoflash.mp3"  _loop="true" />-->
		<audio _name="sePhotoShot" src="rmsnd:SE\se_photoshot.mp3"/>
		<animation _name="hotspot" src="rmeq:environment\photo\cam.fln" _y="444" _playing="false" _loop="true">
			<script event="onPress">
			//parent.cameye.resize(240,180);
			if (scene._class.name == "CMolConstBaseScene")
			{
				parent.cameye.imFilm.makeSnapshot(scene, new Rectangle(123,157,978,665));
				var tmp_path = scene.labReportWindow.imgPhoto.tempDir + Player.module.identifier.replace( /:/g, '_') + '\\image';
				tmp_path += (scene.photoList.list.nextId+1) + ".png";
				parent.cameye.imFilm.saveAs(tmp_path);
				parent.cameye.imFilm.hide();
				parent.cameye.onShot();
				parent.shot_seq.rewindAndPlay();
			}
			else
			{
				parent.cameye.showFrame();
				parent.alertseq.stop();
			}
		</script>
		</animation>
		<script>
		function alertPhotoCamera(wait)
		{
			hotspot._playing = true;
			//sePhotoFlash._playing = true;
			this.alertseq.rewindAndPlay();
			if( wait)	return this.target+".evShotDone";
		}

		function onShotDone()
		{
			hotspot._playing = false;
			//sePhotoFlash._playing = false;
			this.hotspot.currentFrame = 0;
			fireEvent("evShotDone");
		}

		function resize(w, h)
		{
			this.cameye.resize(w, h);
		}

		function cancelShot()
		{
			this.cameye.cancelShot();
		}

		resize(240,180);
	</script>
		<sequencer _name="alertseq">
			<script>
				4000;
			</script>
			<script>
				onShotDone();
			</script>
		</sequencer>
	<sequencer name="shot_seq">
		<script>
			this.hotspot.rewindAndPlay();
			1000;
		</script>
		<script>
			this.hotspot.stop();
			this.hotspot.rewind();
		</script>
	</sequencer>

	</composition>
</rmml>
