using System;
using GHI.Glide;
using GHI.Glide.UI;
using GHI.Glide.Display;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace MultiplesWindows
{
public partial class Program
{
Window wind1 = new Window();
Window wind2 = new Window();
Window wind3 = new Window();
Canvas canvas1 = new Canvas();
Camera camera1;
Bitmap currentBitmapData;
Bitmap currentBitmapData1;
//Image imgCamera;
int top = 30;
bool Wind2Visible = true;
int JoyCount = 0;
void ProgramStarted()
{
//wind2.AddChild(canvas1);
currentBitmapData = new Bitmap(camera.CurrentPictureResolution.Width, camera.CurrentPictureResolution.Height);
currentBitmapData1 = new Bitmap(camera.CurrentPictureResolution.Width, camera.CurrentPictureResolution.Height);
camera1 = new Camera(3);
GT.Timer timer = new GT.Timer(300); // Create a timer
wind1 = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Wind1));
wind2 = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Wind2));
wind3 = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.Wind3));
camera.BitmapStreamed += camera_BitmapStreamed;
camera1.BitmapStreamed += camera1_BitmapStreamed;
camera.PictureCaptured += camera_PictureCaptured;
joystick.JoystickPressed +=joystick_JoystickPressed;
//wind3.TapEvent += wind3_TapEvent;
GlideTouch.Initialize();
Button StartBtn = (Button)wind1.GetChildByName("StartBtn");
Button SkipBtn = (Button)wind2.GetChildByName("SkipBtn");
Button SendBtn = (Button)wind2.GetChildByName("SendBtn");
Button BackBtnWind2 = (Button)wind2.GetChildByName("BackBtnWind2");
Button BackBtnWind3 = (Button)wind3.GetChildByName("BackBtnWind3");
Button TakeAnotherBtn = (Button)wind3.GetChildByName("TakeAnotherBtn");
StartBtn.TapEvent += StartBtn_TapEvent;
SkipBtn.TapEvent += SkipBtn_TapEvent;
SendBtn.TapEvent +=SendBtn_TapEvent;
TakeAnotherBtn.TapEvent +=TakeAnotherBtn_TapEvent;
BackBtnWind3.TapEvent +=BackBtnWind3_TapEvent;
BackBtnWind2.TapEvent +=BackBtnWind2_TapEvent;
//btn3.TapEvent += btn3_TapEvent;
Glide.MainWindow = wind1;
Debug.Print("Program Started");
Mainboard.SetDebugLED(false);
Thread.Sleep(10000);
}
private void SendBtn_TapEvent(object sender)
{
Glide.MainWindow = wind3;
}
private void BackBtnWind3_TapEvent(object sender)
{
Glide.MainWindow = wind1;
}
private void TakeAnotherBtn_TapEvent(object sender)
{
streamOn();
}
private void BackBtnWind2_TapEvent(object sender)
{
Glide.MainWindow = wind1;
}
private void camera_BitmapStreamed(Camera sender, Bitmap bipmap)
{
displayTE35.SimpleGraphics.DisplayImage(bipmap, 0, 0);
Debug.Print("sta mostrando immagine");
}
private void camera1_BitmapStreamed(Camera sender, Bitmap e)
{
displayTE35.SimpleGraphics.DisplayImage(currentBitmapData1, 0, 0);
Debug.Print("sta mostrando immagine dalla cam2");
}
private void SkipBtn_TapEvent(object sender)
{
Debug.Print("Ho fatto skip event");
camera.StopStreaming();
streamOn();
}
private void joystick_JoystickPressed(Joystick sender, Joystick.ButtonState state)
{
camera.StopStreaming();
JoyCount += 1;
if (JoyCount == 1)
{
Debug.Print("tu hai premuto btn2");
camera.TakePicture();
}
if(JoyCount == 2)
{
Glide.MainWindow = wind2;
JoyCount = 0;
}
}
private void camera_PictureCaptured(Camera sender, GT.Picture picture)
{
displayTE35.SimpleGraphics.DisplayImage(picture, 0, 0);
}
private void StartBtn_TapEvent(object sender)
{
streamOn();
}
void streamOn()
{
Debug.Print("ciaooooo");
//Glide.MainWindow = null;
if (camera.CameraReady)
{
camera.StopStreaming();
camera.StartStreaming();
}
else
{
Debug.Print("camera not ready");
}
}
}
}