﻿using UnityEngine;
using System.Collections;


public class ScreenTransfer : MonoBehaviour {
	/// <summary>
	/// Image Flow script
	/// </summary>
	ImageFlow ImgF;

	/// <summary>
	/// main camera object in the game that is running on the Uniquitous server
	/// </summary>
	GameObject Cam;

	int screenWidth, screenHeight;


	void Start(){
		screenWidth = Screen.width;
		screenHeight = Screen.height;
			
			if (screenWidth % 2 != 0)
				screenWidth -= 1;
			
			if (screenHeight % 2 != 0)
				screenHeight -= 1;
		
	}


	void Update(){
		if(Cam==null){
		    Cam = GameObject.Find("Main Camera");
		    ImgF = Cam.GetComponent<ImageFlow>(); 
		}
		
		
	}

	/// <summary>
	/// Raises the GU event.
	/// </summary>
	void OnGUI()
	{
	  if(uLink.Network.isServer){
 

        if(ImgF.IsSending())
		{
		 if(GUI.Button(new Rect(Screen.width * 0.5f - 15.0f, 1.0f, 80.0f, 30.0f), "StopImage")) //stop game image transmission
			ImgF.StopSending();
		}
		else if(GUI.Button(new Rect(Screen.width * 0.5f - 15.0f, 1.0f, 80.0f, 30.0f), "StartImage")) //start game image transmission before GUI elements rendered
		    ImgF.StartSending(false);
		
		else if(GUI.Button(new Rect(Screen.width * 0.5f - 15.0f + 85.0f, 1.0f, 80.0f, 30.0f), "..withGUI")) //start game image transmisson after GUI elements rendered
			ImgF.StartSending(true);
		}
	
	}
	/// <summary>
	/// Signature of the RPC method for receiving images.
	/// </summary>
		[RPC]
	   void ReceiveImages(byte[] bytes){


		}
}
