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;
using System.IO;
using WpfImageGallery;
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;
bool SongsMode = false;
#endregion
List<ImageEntity> childImages = new List<ImageEntity>();
Random rndImg = new Random();
void DisplayResource()
{
int n = rndImg.Next(childImages.Count);
ImageEntity selectedIE = childImages[n];
img = new BitmapImage(new Uri(selectedIE.ImagePath));
Image1.Source = img;
speaker.SpeakAsync(selectedIE.Info);
}
public MainWindow()
{
// MessageBox.Show(Environment.CurrentDirectory);
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);
if (!SongsMode)
{
this.Dispatcher.Invoke(
DispatcherPriority.Normal,
(System.Windows.Forms.MethodInvoker)delegate()
{/////////////
try
{
string fileName = WorkingPath.Path+"\\"+DateTime.Now.Date.ToShortDateString() + "_" + DateTime.Now.TimeOfDay.TotalMilliseconds + ".jpg";
Save(fileName, Image1.Source as BitmapSource);
}
catch (Exception ) {//MessageBox.Show(ex.ToString()) ;
}
//////////////
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();
}
Random r = new Random();
private int outDeviceID = 0;
private Sanford.Multimedia.Midi.OutputDevice od = new Sanford.Multimedia.Midi.OutputDevice(0);
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;
int n = r.Next(30, 96);
od.Send(new Sanford.Multimedia.Midi.ChannelMessage(Sanford.Multimedia.Midi.ChannelCommand.NoteOn, 0, n,127));
}
}
private void Window_Closed_1(object sender, EventArgs e)
{
this.Dispatcher.InvokeShutdown();
}
private void Image1_TouchMove_1(object sender, TouchEventArgs e)
{
SongsMode = false;
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)
{
SongsMode = false;
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 Ball");
break;
case Key.C:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/C.png")));
Image1.Source = img;
speaker.SpeakAsync("C for Cat");
break;
case Key.D:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/D.png")));
Image1.Source = img;
speaker.SpeakAsync("D for Dog");
break;
case Key.E:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/E.png")));
Image1.Source = img;
speaker.SpeakAsync("E for Egg");
break;
case Key.F:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/F.png")));
Image1.Source = img;
speaker.SpeakAsync("F for Fan");
break;
case Key.G:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/G.png")));
Image1.Source = img;
speaker.SpeakAsync("G for Grapes");
break;
case Key.H:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/H.png")));
Image1.Source = img;
speaker.SpeakAsync("H for Horse");
break;
case Key.I:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/I.png")));
Image1.Source = img;
speaker.SpeakAsync("I for Icecream");
break;
case Key.J:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/J.png")));
Image1.Source = img;
speaker.SpeakAsync("J for Jug");
break;
case Key.K:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/K.png")));
Image1.Source = img;
speaker.SpeakAsync("K for Kite");
break;
case Key.L:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/L.png")));
Image1.Source = img;
speaker.SpeakAsync("L for Lion");
break;
case Key.M:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/M.png")));
Image1.Source = img;
speaker.SpeakAsync("M for Mango");
break;
case Key.N:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/N.png")));
Image1.Source = img;
speaker.SpeakAsync("N for Nest");
break;
case Key.O:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/O.png")));
Image1.Source = img;
speaker.SpeakAsync("O for Orange");
break;
case Key.P:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/P.png")));
Image1.Source = img;
speaker.SpeakAsync("P for Pot");
break;
case Key.Q:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Q.png")));
Image1.Source = img;
speaker.SpeakAsync("Q for Queen");
break;
case Key.R:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/R.png")));
Image1.Source = img;
speaker.SpeakAsync("R for Rat");
break;
case Key.S:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/S.png")));
Image1.Source = img;
speaker.SpeakAsync("S for Ship");
break;
case Key.T:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/T.png")));
Image1.Source = img;
speaker.SpeakAsync("T for Tiger");
break;
case Key.U:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/U.png")));
Image1.Source = img;
speaker.SpeakAsync("U for Umbrella");
break;
case Key.V:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/V.png")));
Image1.Source = img;
speaker.SpeakAsync("V for Violin");
break;
case Key.W:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/W.png")));
Image1.Source = img;
speaker.SpeakAsync("W for Watermelon");
break;
case Key.X:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/X.png")));
Image1.Source = img;
speaker.SpeakAsync("X for X-mas");
break;
case Key.Y:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Y.png")));
Image1.Source = img;
speaker.SpeakAsync("Y for Yarn");
break;
case Key.Z:
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Alphabets/Z.png")));
Image1.Source = img;
speaker.SpeakAsync("Z for Zebra");
break;
}
}
void StopAllSongs()
{
mediaTwinkle.Stop();
mediaAlphabet.Stop();
}
private void btnOther_Click(object sender, RoutedEventArgs e)
{
SongsMode = true;
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)
{
SongsMode = true;
img = new BitmapImage(new Uri(System.IO.Path.GetFullPath("Songs/Twinkle_Twinkle_Little_Star.gif")));
Image1.Source = img;
StopAllSongs();
mediaTwinkle.Play();
}
private void mediaTwinkle_MediaEnded_1(object sender, RoutedEventArgs e)
{
}
public void Save(string filePath,BitmapSource Image)
{
try
{
BitmapEncoder encoder = null;
var image = Image;
using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
if (filePath.EndsWith(".jpg"))
encoder = new JpegBitmapEncoder();
if (filePath.EndsWith(".jpeg"))
encoder = new JpegBitmapEncoder();
if (filePath.EndsWith(".jpg"))
encoder = new JpegBitmapEncoder();
if (filePath.EndsWith(".png"))
encoder = new PngBitmapEncoder();
if (filePath.EndsWith(".tif"))
encoder = new TiffBitmapEncoder();
if (filePath.EndsWith(".tiff"))
encoder = new TiffBitmapEncoder();
if (filePath.EndsWith(".bmp"))
encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
encoder.Save(fileStream);
}
}
catch (Exception ex)
{
MessageBox.Show("Can not save! Make sure you have permission to access the folder and that image is not opened elsewhere");
}
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
try
{
if(!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\Integrated Ideas"))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas");
}
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas\\Kidsoo"))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Integrated Ideas\\Kidsoo");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}