using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace Kidsoo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#region variables
BitmapImage img;
BackgroundWorker workerClear;
BackgroundWorker workerNewColor;
Brush currentBrush;
Random rnd = new Random();
System.Speech.Synthesis.SpeechSynthesizer speaker;
#endregion
public MainWindow()
{
InitializeComponent();
speaker = new System.Speech.Synthesis.SpeechSynthesizer();
speaker.Rate = -8;
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("main.bmp")));
Image1.Source = img;
Image1.Width = System.Windows.SystemParameters.PrimaryScreenWidth - 100;
Image1.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
currentBrush = new SolidColorBrush(Color.FromRgb(255,0,0));
////////////////////Worker Clear will be used to clear the screen////////////////////////////////////
workerClear = new BackgroundWorker();
workerClear.DoWork += workerClear_DoWork;
workerClear.WorkerReportsProgress = true;
workerClear.ProgressChanged += workerClear_ProgressChanged;
workerClear.RunWorkerAsync();
////////////////////////////////// This will be used for changing the Color///////////////////////
workerNewColor = new BackgroundWorker();
workerNewColor.DoWork += workerNewColor_DoWork;
workerNewColor.WorkerReportsProgress = true;
workerNewColor.ProgressChanged += workerNewColor_ProgressChanged;
workerNewColor.RunWorkerAsync();
//// Why do we have ProgressChanged? There is no progress bar here.
// ProgressChange pumps a message to parent thread when invoked. This is a good way to
// let your parent thread know about any background thread to avoid application hang
}
void workerNewColor_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
void workerNewColor_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
System.Threading.Thread.Sleep(5000);
byte r = (byte)rnd.Next(0, 255);
byte g = (byte)rnd.Next(0, 255);
byte b = (byte)rnd.Next(0, 255);
this.Dispatcher.Invoke(
DispatcherPriority.Normal,
(System.Windows.Forms.MethodInvoker)delegate()
{
currentBrush = new SolidColorBrush(Color.FromRgb(r, g, b));
}
);
workerNewColor.ReportProgress(10);
System.Threading.Thread.Sleep(1000);
//throw new NotImplementedException();
}
//throw new NotImplementedException();
}
void workerClear_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//throw new NotImplementedException();
}
void workerClear_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
System.Threading.Thread.Sleep(40000);
this.Dispatcher.Invoke(
DispatcherPriority.Normal,
(System.Windows.Forms.MethodInvoker)delegate()
{
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("main.bmp")));
Image1.Source = img;
}
);
workerClear.ReportProgress(2);
System.Threading.Thread.Sleep(1000);
}
//throw new NotImplementedException();
}
private void Image1_MouseMove_1(object sender, MouseEventArgs e)
{
if (e.LeftButton.Equals(MouseButtonState.Pressed))
{
//MessageBox.Show(img.Height + "-->" + System.Windows.SystemParameters.PrimaryScreenWidth);
// Point current = e.GetPosition(Image1);
Point current = new Point(Math.Floor(e.GetPosition(Image1).X * img.Width / (System.Windows.SystemParameters.PrimaryScreenWidth - 100)), Math.Floor(e.GetPosition(Image1).Y * img.Height / System.Windows.SystemParameters.PrimaryScreenHeight));
img = Logic.DrawPoint(img, current, currentBrush, new Pen(currentBrush, 2), 3);
Image1.Source = img;
}
}
private void Window_Closed_1(object sender, EventArgs e)
{
this.Dispatcher.InvokeShutdown();
}
private void Image1_TouchMove_1(object sender, TouchEventArgs e)
{
Point current = new Point(Math.Floor(e.TouchDevice.GetTouchPoint(Image1).Position.X * img.Width / (System.Windows.SystemParameters.PrimaryScreenWidth - 100)), Math.Floor(e.TouchDevice.GetTouchPoint(Image1).Position.Y * img.Height / System.Windows.SystemParameters.PrimaryScreenHeight));
img = Logic.DrawPoint(img, current, currentBrush, new Pen(currentBrush, 2), 3);
Image1.Source = img;
}
private void Window_KeyDown_1(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.A:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/A.png")));
Image1.Source = img;
System.Threading.Thread.Sleep(400);
speaker.SpeakAsync("A for Apple");
break;
case Key.B:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/B.png")));
Image1.Source = img;
speaker.SpeakAsync("B for Banana");
break;
}
}
void StopAllSongs()
{
mediaTwinkle.Stop();
mediaAlphabet.Stop();
}
private void btnOther_Click(object sender, RoutedEventArgs e)
{
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Songs/alphabet.jpg")));
Image1.Source = img;
StopAllSongs();
mediaAlphabet.Play();
}
private void btnTwinkle_Click(object sender, RoutedEventArgs e)
{
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Songs/Twinkle_Twinkle_Little_Star.gif")));
Image1.Source = img;
StopAllSongs();
mediaTwinkle.Play();
}
}
}