Here's what I'm calling v2 internally. This is July 10th's checkin.

This commit is contained in:
shanselman 2008-07-10 20:47:38 +00:00
Родитель 9bf44790d3
Коммит 151825beb3
42 изменённых файлов: 3764 добавлений и 740 удалений

Просмотреть файл

@ -4,58 +4,6 @@
xmlns:BabySmash="clr-namespace:BabySmash" Startup="Application_Startup"
>
<Application.Resources>
<Style x:Key="BabySmashBaseStyle" TargetType="Shape">
<Setter Property="StrokeThickness" Value="5"/>
<Setter Property="Stroke" Value="Black"/>
</Style>
<Style x:Key="trapezoid" TargetType="Path"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Data" Value="F1 M 257.147,126.953L 543.657,126.953L 640.333,448.287L 160.333,448.287L 257.147,126.953 Z"/>
</Style>
<Style x:Key="star" TargetType="BabySmash:Star"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="NumberOfPoints" Value="5"/>
<Setter Property="Width" Value="400"/>
<Setter Property="Height" Value="400"/>
</Style>
<Style x:Key="square" TargetType="Rectangle"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Width" Value="380"/>
<Setter Property="Height" Value="380"/>
</Style>
<Style x:Key="heart" TargetType="Path"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Data" Value="F1 M 429,161.333C 506.333,88.6667 609,142.122 609,225.333C 609,308.544 429,462.667 429,462.667C 429,462.667 257,306.544 257,223.333C 257,140.123 356.138,88.4713 429,161.333 Z"/>
</Style>
<Style x:Key="path" TargetType="Path"
BasedOn="{StaticResource BabySmashBaseStyle}">
</Style>
<Style x:Key="circle" TargetType="Ellipse"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Width" Value="400"/>
<Setter Property="Height" Value="400"/>
</Style>
<Style x:Key="triangle" TargetType="Polygon"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Points" Value="200,50 400,400 0,400 200,50"/>
<Setter Property="Width" Value="400"/>
<Setter Property="Height" Value="400"/>
</Style>
<Style x:Key="rectangle" TargetType="Rectangle"
BasedOn="{StaticResource BabySmashBaseStyle}">
<Setter Property="Width" Value="380"/>
<Setter Property="Height" Value="160"/>
</Style>
</Application.Resources>
</Application>

Просмотреть файл

@ -1,93 +1,75 @@
using System.Windows;
using System;
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows;
using System.Windows.Forms;
using Application = System.Windows.Application;
using WinForms = System.Windows.Forms;
using System.Diagnostics;
namespace BabySmash
{
public partial class App : Application
{
private static readonly InterceptKeys.LowLevelKeyboardProc _proc = HookCallback;
private static IntPtr _hookID = IntPtr.Zero;
public partial class App : Application
{
private static IntPtr _hookID = IntPtr.Zero;
static InterceptKeys.LowLevelKeyboardProc _proc = HookCallback;
readonly MainWindow mainWindow = null;
public App()
{
try
private void Application_Startup(object sender, StartupEventArgs e)
{
Controller c = new Controller();
c.Launch();
}
public App()
{
ShutdownMode = ShutdownMode.OnExplicitShutdown;
try
{
_hookID = InterceptKeys.SetHook(_proc);
}
catch
{
if (_hookID != IntPtr.Zero)
InterceptKeys.UnhookWindowsHookEx(_hookID);
}
}
public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
bool Alt = (WinForms.Control.ModifierKeys & Keys.Alt) != 0;
bool Control = (WinForms.Control.ModifierKeys & Keys.Control) != 0;
//Prevent ALT-TAB and CTRL-ESC by eating TAB and ESC. Also kill Windows Keys.
int vkCode = Marshal.ReadInt32(lParam);
Keys key = (Keys)vkCode;
if (Alt && key == Keys.F4)
{
_hookID = InterceptKeys.SetHook(_proc);
ShutdownMode = ShutdownMode.OnLastWindowClose; //TODO: Should this be OnMainWindowClose?
mainWindow = new MainWindow();
MainWindow.WindowState = WindowState.Maximized; //Do it here, rather than in XAML otherwise multimon won't work.
mainWindow.Show();
Application.Current.Shutdown();
return (IntPtr)1; //handled
}
catch
{
if (_hookID != IntPtr.Zero)
InterceptKeys.UnhookWindowsHookEx(_hookID);
}
}
if (key == Keys.LWin ||key == Keys.RWin) return (IntPtr)1; //handled
if (Alt && key == Keys.Tab) return (IntPtr)1; //handled
if (Alt && key == Keys.Space) return (IntPtr)1; //handled
if (Control && key == Keys.Escape)return (IntPtr)1;
if (key == Keys.None) return (IntPtr)1; //handled
if (key <= Keys.Back) return (IntPtr)1; //handled
if (key == Keys.Menu ) return (IntPtr)1; //handled
if (key == Keys.Pause) return (IntPtr)1; //handled
if (key == Keys.Help) return (IntPtr)1; //handled
if (key == Keys.Sleep) return (IntPtr)1; //handled
if (key == Keys.Apps) return (IntPtr)1; //handled
if (key >= Keys.KanaMode && key <= Keys.HanjaMode) return (IntPtr)1; //handled
if (key >= Keys.IMEConvert && key <= Keys.IMEModeChange) return (IntPtr)1; //handled
if (key >= Keys.BrowserBack && key <= Keys.BrowserHome) return (IntPtr)1; //handled
if (key >= Keys.MediaNextTrack && key <= Keys.OemClear) return (IntPtr)1; //handled
private void Application_Startup(object sender, StartupEventArgs e)
{
////UNDONE: Make a Window instance for each screen, position them, show them, then maximize them.
////TODO: Now, how to respond to events on all screens at once?
//foreach (WinForms.Screen s in WinForms.Screen.AllScreens)
//{
// if (s.Primary == false)
// {
// Window1 w = new Window1();
// w.WindowStartupLocation = WindowStartupLocation.Manual; //key!
// Debug.Write("Found screen: " + s.DeviceName);
// w.Left = s.WorkingArea.Left;
// Debug.Write(" Left: " + s.WorkingArea.Left);
// w.Top = s.WorkingArea.Top;
// Debug.Write(" Top: " + s.WorkingArea.Top);
// w.Width = s.WorkingArea.Width;
// Debug.Write(" Width: " + s.WorkingArea.Width);
// w.Height = s.WorkingArea.Height;
// Debug.Write("Height: " + s.WorkingArea.Height);
// w.WindowStyle = WindowStyle.None;
// w.Topmost = true;
// w.Owner = mainWindow;
// w.Show();
// w.WindowState = WindowState.Maximized;
// }
// mainWindow.Focus();
//};
mainWindow.Focus();
}
Debug.WriteLine(vkCode.ToString() + " " + key);
public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
bool Alt = (System.Windows.Forms.Control.ModifierKeys & WinForms.Keys.Alt) != 0;
bool Control = (System.Windows.Forms.Control.ModifierKeys & WinForms.Keys.Control) != 0;
//Prevent ALT-TAB and CTRL-ESC by eating TAB and ESC. Also kill Windows Keys.
int vkCode = Marshal.ReadInt32(lParam);
if ((WinForms.Keys)vkCode == WinForms.Keys.LWin ||
(WinForms.Keys)vkCode == WinForms.Keys.RWin)
{
return (IntPtr)1; //handled
}
if (Alt && (WinForms.Keys)vkCode == WinForms.Keys.Tab)
{
return (IntPtr)1; //handled
}
if (Alt && (WinForms.Keys)vkCode == WinForms.Keys.Space)
{
return (IntPtr)1; //handled
}
if (Control && (WinForms.Keys)vkCode == WinForms.Keys.Escape)
{
return (IntPtr)1; //handled
}
}
return InterceptKeys.CallNextHookEx(_hookID, nCode, wParam, lParam);
}
}
}
}
return InterceptKeys.CallNextHookEx(_hookID, nCode, wParam, lParam);
}
}
}

Просмотреть файл

@ -1,29 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
namespace BabySmash
{
public class Winmm
{
public const UInt32 SND_ASYNC = 0x0001;
public const UInt32 SND_MEMORY = 0x0004;
public const UInt32 SND_LOOP = 0x0008;
public const UInt32 SND_MEMORY = 0x0004;
public const UInt32 SND_NOSTOP = 0x0010;
// this is the overload we want to play embedded resource...
[DllImport("Winmm.dll")]
public static extern bool PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
public static Dictionary<string, byte[]> cachedWavs = new Dictionary<string, byte[]>();
public static object cachedWavsLock = new object();
[DllImport("Winmm.dll")]
public static extern bool PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags);
public static void PlayWavResource(string wav)
{
byte[] b = GetWavResource(wav);
@ -35,20 +33,20 @@ namespace BabySmash
byte[] b = GetWavResource(wav);
PlaySound(b, IntPtr.Zero, SND_ASYNC | SND_MEMORY | SND_NOSTOP);
}
private static byte[] GetWavResource(string wav)
{
//TODO: Is this valid double-check caching?
byte[] b = null;
if(cachedWavs.ContainsKey(wav))
b = cachedWavs[wav];
if (cachedWavs.ContainsKey(wav))
b = cachedWavs[wav];
if (b == null)
{
lock (cachedWavsLock)
{
// get the namespace
string strNameSpace = Assembly.GetExecutingAssembly().GetName().Name.ToString();
string strNameSpace = Assembly.GetExecutingAssembly().GetName().Name;
// get the resource into a stream
using (Stream str = Assembly.GetExecutingAssembly().GetManifestResourceStream(strNameSpace + wav))
@ -57,14 +55,13 @@ namespace BabySmash
throw new ArgumentException(wav + " not found!");
// bring stream into a byte array
var bStr = new Byte[str.Length];
str.Read(bStr, 0, (int)str.Length);
str.Read(bStr, 0, (int) str.Length);
cachedWavs.Add(wav, bStr);
return bStr;
}
}
}
return b;
}
}
}
}

Просмотреть файл

@ -31,12 +31,12 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>http://www.hanselman.com/BabySmash/</InstallUrl>
<SupportUrl>http://www.babysmash.com</SupportUrl>
<SupportUrl>http://www.hanselman.com/forum/forum21-babysmash-end-user-support.aspx</SupportUrl>
<ProductName>BabySmash!</ProductName>
<PublisherName>Scott Hanselman</PublisherName>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>30</ApplicationRevision>
<ApplicationRevision>36</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
@ -89,20 +89,78 @@
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Page Include="Shapes\allShapes.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Shapes\CoolCircle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolHeart.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolHexagon.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolSquare.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolStar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolTrapezoid.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="Shapes\CoolCircle.xaml.cs">
<DependentUpon>CoolCircle.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolHeart.xaml.cs">
<DependentUpon>CoolHeart.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolHexagon.xaml.cs">
<DependentUpon>CoolHexagon.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolSquare.xaml.cs">
<DependentUpon>CoolSquare.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolStar.xaml.cs">
<DependentUpon>CoolStar.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolTrapezoid.xaml.cs">
<DependentUpon>CoolTrapezoid.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<Page Include="Shapes\CoolTriangle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolLetter.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Options.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Shapes\CoolRectangle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
@ -110,6 +168,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Audio.cs" />
<Compile Include="Controller.cs" />
<Compile Include="Shapes\AnimationBehaviors.cs" />
<Compile Include="Shapes\CoolTriangle.xaml.cs">
<DependentUpon>CoolTriangle.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\CoolLetter.xaml.cs">
<DependentUpon>CoolLetter.xaml</DependentUpon>
</Compile>
<Compile Include="KeyboardHook.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
@ -131,9 +197,12 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Settings.cs" />
<Compile Include="Shapes\Animation.cs" />
<Compile Include="Shapes\CoolRectangle.xaml.cs">
<DependentUpon>CoolRectangle.xaml</DependentUpon>
</Compile>
<Compile Include="Shapes\Figure.cs" />
<Compile Include="Shapes\FigureGenerator.cs" />
<Compile Include="Shapes\Star.cs" />
<Compile Include="Utils.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -190,6 +259,10 @@
<ItemGroup>
<EmbeddedResource Include="Resources\Sounds\smallbumblebee.wav" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Sounds\falling.wav" />
<EmbeddedResource Include="Resources\Sounds\rising.wav" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\Voices\Female\" />
<Folder Include="Resources\Voices\Male\" />

255
Controller.cs Normal file
Просмотреть файл

@ -0,0 +1,255 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Speech.Synthesis;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BabySmash.Properties;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using WinForms = System.Windows.Forms;
namespace BabySmash
{
public class Controller
{
private bool isDrawing = false;
private readonly SpeechSynthesizer objSpeech = new SpeechSynthesizer();
private readonly List<MainWindow> windows = new List<MainWindow>();
private int FiguresCount = 0;
public void Launch()
{
foreach (WinForms.Screen s in WinForms.Screen.AllScreens)
{
MainWindow m = new MainWindow(this)
{
WindowStartupLocation = WindowStartupLocation.Manual,
Left = s.WorkingArea.Left,
Top = s.WorkingArea.Top,
Width = s.WorkingArea.Width,
Height = s.WorkingArea.Height,
WindowStyle = WindowStyle.None,
Topmost = true
};
m.Show();
//TODO: Start - COMMENT IN for Debugging
//m.Width = 700;
//m.Height = 600;
//m.Left = 900;
//m.Top = 500;
//TODO: END - COMMENT IN for Debugging
//TODO: Start - COMMENT OUT for Debugging
m.WindowState = WindowState.Maximized;
//TODO: Start - COMMENT OUT for Debugging
windows.Add(m);
}
ShowOptionsDialog();
}
public void ProcessKey(FrameworkElement uie, KeyEventArgs e)
{
bool Alt = (Keyboard.Modifiers & ModifierKeys.Alt) != 0;
bool Control = (Keyboard.Modifiers & ModifierKeys.Control) != 0;
bool Shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;
if (uie.IsMouseCaptured)
uie.ReleaseMouseCapture();
//TODO: Might be able to remove this: http://www.ageektrapped.com/blog/using-commands-in-babysmash/
if (Alt && Control && Shift && e.Key == Key.O)
{
ShowOptionsDialog();
e.Handled = true;
return;
}
if (FiguresCount == Settings.Default.ClearAfter)
ClearAllFigures();
string s = e.Key.ToString();
if (s.Length == 2 && s[0] == 'D') s = s[1].ToString(); //HACK: WTF? Numbers start with a "D?" as in D1?
AddFigure(uie, s);
}
private void ClearAllFigures()
{
foreach (MainWindow m in this.windows)
{
m.mainCanvas.Children.Clear();
}
}
private void AddFigure(FrameworkElement uie, string s)
{
FigureTemplate template = FigureGenerator.GenerateFigureTemplate(s);
foreach (MainWindow m in this.windows)
{
UserControl f = FigureGenerator.NewUserControlFrom(template);
m.AddUserControl(f);
f.Width = 300;
f.Height = 300;
Canvas.SetLeft(f, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(m.ActualWidth - f.Width)));
Canvas.SetTop(f, Utils.RandomBetweenTwoNumbers(0, Convert.ToInt32(m.ActualHeight - f.Height)));
Storyboard storyboard = Animation.CreateDPAnimation(uie, f,
UIElement.OpacityProperty,
new Duration(TimeSpan.FromSeconds(Settings.Default.FadeAfter)));
if (Settings.Default.FadeAway) storyboard.Begin(uie);
IHasFace face = f as IHasFace;
if (face != null)
{
face.FaceVisible = Settings.Default.FacesOnShapes ? Visibility.Visible : Visibility.Hidden;
}
f.MouseLeftButtonDown += HandleMouseLeftButtonDown;
}
FiguresCount++;
PlaySound(template);
}
void HandleMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
UserControl f = sender as UserControl;
if (f != null && f.Opacity > 0.1) //can it be seen?
{
isDrawing = true; //HACK: This is a cheat to stop the mouse draw action.
Animation.ApplyRandomAnimationEffect(f, Duration.Automatic);
PlayLaughter(); //Might be better to re-speak the name, color, etc.
}
}
public void PlaySound(FigureTemplate template)
{
if (Settings.Default.Sounds == "Laughter")
{
PlayLaughter();
}
if (objSpeech != null && Settings.Default.Sounds == "Speech")
{
if (template.Letter != null && template.Letter.Length == 1 && Char.IsLetterOrDigit(template.Letter[0]))
{
SpeakString(template.Letter);
}
else
{
SpeakString(Utils.ColorToString(template.Color) + " " + template.Name);
}
}
}
private static void PlayLaughter()
{
Winmm.PlayWavResource(Utils.GetRandomSoundFile());
}
private void SpeakString(string s)
{
objSpeech.SpeakAsyncCancelAll();
objSpeech.Rate = -1;
objSpeech.Volume = 100;
objSpeech.SpeakAsync(s);
}
private void ShowOptionsDialog()
{
var o = new Options();
Mouse.Capture(null);
foreach (MainWindow m in this.windows)
{
m.Topmost = false;
}
o.Topmost = true;
o.Focus();
o.ShowDialog();
Debug.Write("test");
foreach (MainWindow m in this.windows)
{
m.Topmost = true;
}
}
public void MouseDown(MainWindow main, MouseButtonEventArgs e)
{
if (isDrawing || Settings.Default.MouseDraw) return;
// Create a new Ellipse object and add it to canvas.
Point ptCenter = e.GetPosition(main.mainCanvas);
MouseDraw(main, ptCenter);
isDrawing = true;
main.CaptureMouse();
Winmm.PlayWavResource(".Resources.Sounds." + "smallbumblebee.wav");
}
public void MouseWheel(MainWindow main, MouseWheelEventArgs e)
{
if (e.Delta > 0)
{
Winmm.PlayWavResource(".Resources.Sounds." + "rising.wav");
}
else
{
Winmm.PlayWavResource(".Resources.Sounds." + "falling.wav");
}
}
public void MouseUp(MainWindow main, MouseButtonEventArgs e)
{
isDrawing = false;
if (Settings.Default.MouseDraw) return;
main.ReleaseMouseCapture();
}
public void MouseMove(MainWindow main, MouseEventArgs e)
{
if (Settings.Default.MouseDraw && main.IsMouseCaptured == false)
main.CaptureMouse();
if (isDrawing || Settings.Default.MouseDraw)
{
MouseDraw(main, e.GetPosition(main));
}
//Cheesy, but hotkeys are ignored when the mouse is captured.
// However, if we don't capture and release, the shapes will draw forever.
if (Settings.Default.MouseDraw && main.IsMouseCaptured)
main.ReleaseMouseCapture();
}
private void MouseDraw(MainWindow main, Point p)
{
//sanity check
if (main.mainCanvas.Children.Count > 300) main.mainCanvas.Children.Clear();
//randomize at some point?
Shape shape = new Ellipse
{
Stroke = SystemColors.WindowTextBrush,
StrokeThickness = 3,
Fill = Utils.GetGradientBrush(Utils.GetRandomColor()),
Width = 50,
Height = 50
};
main.mainCanvas.Children.Add(shape);
Canvas.SetLeft(shape, p.X - 25);
Canvas.SetTop(shape, p.Y - 25);
if (Settings.Default.MouseDraw)
Winmm.PlayWavResourceYield(".Resources.Sounds." + "smallbumblebee.wav");
}
public void LostMouseCapture(MainWindow main, MouseEventArgs e)
{
if (Settings.Default.MouseDraw) return;
if (isDrawing) isDrawing = false;
}
}
}

Просмотреть файл

@ -1,12 +1,17 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BabySmash
{
class InterceptKeys
internal class InterceptKeys
{
#region Delegates
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
#endregion
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x0100;
@ -15,16 +20,13 @@ namespace BabySmash
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
GetModuleHandle(curModule.ModuleName), 0);
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,GetModuleHandle(curModule.ModuleName), 0);
}
}
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook,
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
@ -32,9 +34,9 @@ namespace BabySmash
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
IntPtr wParam, IntPtr lParam);
IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
}
}
}

Просмотреть файл

@ -3,28 +3,18 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BabySmash"
Title="Baby Smash by Scott Hanselman - http://www.hanselman.com/babysmash"
Height="386" Width="601" WindowStyle="None"
Closing="Window_Closing"
KeyUp="Window_KeyUp" Loaded="Window_Loaded"
MouseLeftButtonDown="Window_MouseButtonDown"
MouseRightButtonDown="Window_MouseButtonDown"
MouseDown="Window_MouseButtonDown"
MouseMove="Window_MouseMove"
MouseUp="Window_MouseUp"
LostMouseCapture="Window_LostMouseCapture">
<Window.Resources>
<local:FigureGenerator x:Key="figureGenerator"/>
</Window.Resources>
<Grid>
<TextBlock>
BabySmash by Scott Hanselman
<Hyperlink RequestNavigate="HelpUrlNavigated" NavigateUri="http://www.babysmash.com">http://www.babysmash.com</Hyperlink>
<LineBreak />Ctrl-Shift-Alt-O for options, ALT-F4 to exit</TextBlock>
<Canvas Name="mainCanvas"></Canvas>
<ItemsControl Name="figures" ItemsSource="{Binding Source={StaticResource figureGenerator},Path=Figures}">
Height="500" Width="500" WindowStyle="None" HorizontalAlignment="Center" VerticalAlignment="Center"
>
<Grid Name="mainGrid">
<TextBlock FontSize="10">
<Bold>BabySmash!</Bold> by Scott Hanselman <Italic>with many community contributions!</Italic> - http://www.babysmash.com
<LineBreak /><Bold>Ctrl-Shift-Alt-O</Bold> for options, <Bold>ALT-F4</Bold> to exit</TextBlock>
<Canvas Name="mainCanvas"/>
<!--<ItemsControl Name="figuresControl" ItemsSource="{Binding Path=Figures}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Path=Shape}" />
<ContentPresenter />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
@ -38,6 +28,6 @@
<Setter Property="Canvas.Top" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}},Path=ShapeTop}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</ItemsControl>-->
</Grid>
</Window>

Просмотреть файл

@ -1,196 +1,71 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Speech.Synthesis;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Speech.Synthesis;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BabySmash.Properties;
namespace BabySmash
{
public partial class MainWindow : Window
{
private SpeechSynthesizer objSpeech;
private readonly FigureGenerator figureGenerator;
public partial class MainWindow : Window
{
private readonly Controller controller;
public Controller Controller { get { return controller; } }
public MainWindow()
{
InitializeComponent();
figureGenerator = (FigureGenerator)Resources["figureGenerator"];
figureGenerator.ClearAfter = Properties.Settings.Default.ClearAfter;
ICollectionView collectionView = CollectionViewSource.GetDefaultView(figureGenerator.Figures);
collectionView.CollectionChanged += FiguresCollectionChanged;
}
public void AddUserControl(UserControl c)
{
this.mainCanvas.Children.Add(c);
}
private void FiguresCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
Figure f = (Figure)e.NewItems[0];
PlayLaughter();
if (f is LetterFigure)
SpeakString(f.Name);
else
SpeakString(f.Color + " " + f.Name);
}
}
public MainWindow(Controller c)
{
this.controller = c;
this.DataContext = controller;
InitializeComponent();
}
public double ShapeLeft
{
//TODO: Feels weird...we need to know the actualwidth of the canvas and of the figure....
// ideally: Utils.RandomBetweenTwoNumbers(0,
// Convert.ToInt32(canvas.ActualWidth - figure.ActualWidth)
// Perhaps this belongs elsewhere?
get { return Utils.RandomBetweenTwoNumbers(-100,
Convert.ToInt32(figures.ActualWidth) - 200); }
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
controller.MouseWheel(this, e);
}
public double ShapeTop
{
//TODO: Feels weird...we need to know the actualwidth of the canvas and of the figure....
// ideally: Utils.RandomBetweenTwoNumbers(0,
// Convert.ToInt32(canvas.ActualWidth - figure.ActualWidth)
// Perhaps this belongs elsewhere?
get { return Utils.RandomBetweenTwoNumbers(
-100,
Convert.ToInt32(figures.ActualHeight) - 300); }
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
controller.MouseUp(this, e);
}
private void Window_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
//HACK: Why did I find the Windows Forms modifier keys classes to be so much more accurate?
bool Alt = (Keyboard.Modifiers & ModifierKeys.Alt) != 0;
bool Control = (Keyboard.Modifiers & ModifierKeys.Control) != 0;
bool Shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
controller.MouseDown(this, e);
}
if (IsMouseCaptured)
Mouse.Capture(null);
//TODO: Might be able to remove this: http://www.ageektrapped.com/blog/using-commands-in-babysmash/
if (Alt && Control && Shift && e.Key == Key.O)
{
ShowOptionsDialog();
e.Handled = true;
return;
}
string s = e.Key.ToString();
if (s.Length == 2 && s[0] == 'D') s = s[1].ToString(); //HACK: WTF? Numbers start with a "D?" as in D1?
figureGenerator.Generate(this, s);
}
private void ShowOptionsDialog()
{
var o = new Options();
o.ShowDialog();
}
private static void PlayLaughter()
{
if (Properties.Settings.Default.Sounds == "Laughter")
{
Winmm.PlayWavResource(Utils.GetRandomSoundFile());
}
}
private void SpeakString(string s)
{
if (objSpeech == null || Properties.Settings.Default.Sounds != "Speech") return;
objSpeech.SpeakAsyncCancelAll();
objSpeech.Rate = -1;
objSpeech.Volume = 100;
objSpeech.SpeakAsync(s);
}
private void HelpUrlNavigated(object sender, RequestNavigateEventArgs e)
{
Process.Start(e.Uri.ToString());
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ShowOptionsDialog();
objSpeech = new SpeechSynthesizer();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
Application.Current.Shutdown();
}
private bool isDrawing = false;
Shape shape;
private void Window_MouseButtonDown(object sender, MouseButtonEventArgs e)
{
if (isDrawing || Properties.Settings.Default.MouseDraw) return;
// Create a new Ellipse object and add it to canvas.
Point ptCenter = e.GetPosition(mainCanvas);
MouseDraw(ptCenter);
isDrawing = true;
CaptureMouse();
Winmm.PlayWavResource(".Resources.Sounds." + "smallbumblebee.wav");
}
private void MouseDraw(Point p)
{
//Sanity check
if(mainCanvas.Children.Count > 500) mainCanvas.Children.Clear();
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
controller.MouseMove(this, e);
}
//randomize at some point?
shape = new Ellipse
{
Stroke = SystemColors.WindowTextBrush,
StrokeThickness = 3,
Fill = Utils.GetRandomColoredBrush(),
Width = 50,
Height = 50
};
mainCanvas.Children.Add(shape);
Canvas.SetLeft(shape, p.X-25);
Canvas.SetTop(shape, p.Y-25);
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
e.Handled = true;
controller.ProcessKey(this, e);
}
if(Properties.Settings.Default.MouseDraw)
Winmm.PlayWavResourceYield(".Resources.Sounds." + "smallbumblebee.wav");
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
if (Properties.Settings.Default.MouseDraw && IsMouseCaptured == false)
CaptureMouse();
if(isDrawing || Properties.Settings.Default.MouseDraw)
{
MouseDraw(e.GetPosition(mainCanvas));
}
//Cheesy, but hotkeys are ignored when the mouse is captured.
// However, if we don't capture and release, the shapes will draw forever.
if (Properties.Settings.Default.MouseDraw && IsMouseCaptured)
ReleaseMouseCapture();
}
private void Window_MouseUp(object sender, MouseButtonEventArgs e)
{
if (Properties.Settings.Default.MouseDraw) return;
isDrawing = false;
ReleaseMouseCapture();
}
private void Window_LostMouseCapture(object sender, MouseEventArgs e)
{
if (Properties.Settings.Default.MouseDraw) return;
if(isDrawing) isDrawing = false;
}
}
}
protected override void OnLostMouseCapture(MouseEventArgs e)
{
base.OnLostMouseCapture(e);
controller.LostMouseCapture(this, e);
}
}
}

Просмотреть файл

@ -4,7 +4,7 @@
xmlns:local="clr-namespace:BabySmash.Properties"
xmlns:l="clr-namespace:BabySmash"
Title="Baby Smash! - Options"
Height="227" Width="542"
Height="261" Width="542"
ShowInTaskbar="True"
Topmost="True"
WindowStartupLocation="CenterScreen"
@ -16,58 +16,70 @@
<Grid DataContext="{StaticResource settings}" Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="119" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="58" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="43" />
<RowDefinition Height="Auto" MinHeight="43" />
<RowDefinition Height="Auto" MinHeight="16" />
<RowDefinition Height="Auto" MinHeight="16" />
<RowDefinition Height="Auto" MinHeight="16" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" MinHeight="34" />
<RowDefinition Height="Auto" MinHeight="20" />
<RowDefinition Height="Auto" MinHeight="20" />
<RowDefinition Height="Auto" MinHeight="20" />
<RowDefinition Height="Auto" MinHeight="20" />
<RowDefinition Height="Auto" MinHeight="20" />
<RowDefinition Height="*" MinHeight="34" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="3" Grid.RowSpan="7" TextWrapping="Wrap" FontSize="18" TextAlignment="Center" Grid.ColumnSpan="1" >
<TextBlock Grid.Column="3" Grid.RowSpan="9" TextWrapping="Wrap" FontSize="18" TextAlignment="Center" Grid.ColumnSpan="1" >
<TextBlock.BitmapEffect>
<BitmapEffectGroup>
<OuterGlowBitmapEffect GlowColor="Yellow" GlowSize="15"/>
</BitmapEffectGroup>
</TextBlock.BitmapEffect>
<Bold>Welcome to BabySmash!</Bold><LineBreak/>We're adding new features weekly.
This week added cool effects for faster computers, as well as drawing with the mouse.
Clicking "Mouse Draw" lets your baby draw without clicking any buttons!<LineBreak/>
<Italic>There's more fun coming soon!</Italic>
This week added click animations and all new graphics!
<LineBreak/>Try turning <Bold>OFF</Bold> Clickless Mouse <LineBreak/>and show your baby<LineBreak/> how to click on shapes!<LineBreak/>
<Italic>There's even more fun soon!</Italic>
</TextBlock >
<Label Height="23" Margin="10,20,0,0" Grid.ColumnSpan="1">Clear after x Shape</Label>
<TextBox Text="{Binding Path=Default.ClearAfter}"
Height="23" Grid.Column="1" Margin="15,20,7,0"/>
<Label Height="23" Margin="10,20,0,0" Grid.Row="0" Grid.ColumnSpan="1">Clear after x Shapes</Label>
<TextBox Text="{Binding Path=Default.ClearAfter}" Grid.Row="0"
Height="23" Width="40" Grid.Column="1" Margin="15,20,0,0" HorizontalAlignment="Right"/>
<Label Height="23" Grid.Row="1" Margin="10">Sounds</Label>
<ComboBox
SelectedValue="{Binding Path=Default.Sounds}"
SelectedValuePath="Content"
Grid.Column="1" Grid.Row="1" Height="23" Margin="15,0,7,0">
SelectedValuePath="Content" Grid.Row="1" Height="23" Margin="70,10,7,0" Grid.ColumnSpan="2" VerticalAlignment="Top">
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Laughter</ComboBoxItem>
<ComboBoxItem>Speech</ComboBoxItem>
</ComboBox>
<CheckBox Grid.Row="2" Grid.Column="1" Margin="15,0,0,0"
<CheckBox Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="0" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.ForceUppercase,Mode=TwoWay}" >
Force Uppercase
Force Letters to UPPERCASE
</CheckBox>
<CheckBox Grid.Row="3" Grid.Column="1" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.FadeAway,Mode=TwoWay}" >
Fade Away
<CheckBox Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="0" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.FacesOnShapes,Mode=TwoWay}" >
Faces on Shapes
</CheckBox>
<CheckBox Grid.Row="4" Grid.Column="1" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.BitmapEffects,Mode=TwoWay}" >
Bitmap Effects
<CheckBox Grid.Row="4" Grid.ColumnSpan="2" Grid.Column="0" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.BitmapEffects,Mode=TwoWay}" IsEnabled="False">
Effects (DISABLED FOR NOW)
</CheckBox>
<CheckBox Grid.Row="5" Grid.Column="1" Margin="15,0,0,0"
<CheckBox Grid.Row="5" Grid.ColumnSpan="2" Grid.Column="0" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.MouseDraw,Mode=TwoWay}" >
Mouse Draw
Clickless Mouse Drawing
</CheckBox>
<StackPanel Orientation="Horizontal" Grid.Row="6" Grid.ColumnSpan="2" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal"
Grid.Row="6" Grid.ColumnSpan="2" HorizontalAlignment="Stretch">
<CheckBox x:Name="FadeChecked" Margin="15,0,0,0"
IsChecked="{Binding Path=Default.FadeAway,Mode=TwoWay}" >
Fade Shapes Away in</CheckBox>
<TextBox Margin="5,0,0,0"
Text="{Binding Path=Default.FadeAfter}"
IsEnabled="{Binding ElementName=FadeChecked,Path=IsChecked,Mode=TwoWay}"
Height="20" Width="25" />
<TextBlock>secs.</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="8" Grid.ColumnSpan="2" HorizontalAlignment="Right">
<Button Name="okButton" IsDefault="True" Margin="0,7,10,7" Padding="30,0,30,0" Click="OK_Click" >OK</Button>
<Button IsCancel="True" Margin="5,7,7,7" Padding="15,0,15,0" Click="Cancel_Click" Width="77">Cancel</Button>
</StackPanel>

Просмотреть файл

@ -1,4 +1,5 @@
using System.Windows;
using BabySmash.Properties;
namespace BabySmash
{
@ -11,16 +12,14 @@ namespace BabySmash
private void OK_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.Save();
Settings.Default.Save();
Close();
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.Reload();
Settings.Default.Reload();
Close();
}
}
}
}

Просмотреть файл

@ -5,6 +5,7 @@ using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BabySmash")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@ -17,6 +18,7 @@ using System.Windows;
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
@ -36,7 +38,7 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
)]
// Version information for an assembly consists of the following four values:
@ -49,5 +51,6 @@ using System.Windows;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

52
Properties/Settings.Designer.cs сгенерированный
Просмотреть файл

@ -35,18 +35,6 @@ namespace BabySmash.Properties {
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Laughter")]
public string Sounds {
get {
return ((string)(this["Sounds"]));
}
set {
this["Sounds"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
@ -73,7 +61,7 @@ namespace BabySmash.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("30")]
[global::System.Configuration.DefaultSettingValueAttribute("65")]
public int ClearAfter {
get {
return ((int)(this["ClearAfter"]));
@ -85,7 +73,7 @@ namespace BabySmash.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool MouseDraw {
get {
return ((bool)(this["MouseDraw"]));
@ -94,5 +82,41 @@ namespace BabySmash.Properties {
this["MouseDraw"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("20")]
public int FadeAfter {
get {
return ((int)(this["FadeAfter"]));
}
set {
this["FadeAfter"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool FacesOnShapes {
get {
return ((bool)(this["FacesOnShapes"]));
}
set {
this["FacesOnShapes"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Speech")]
public string Sounds {
get {
return ((string)(this["Sounds"]));
}
set {
this["Sounds"] = value;
}
}
}
}

Просмотреть файл

@ -5,9 +5,6 @@
<Setting Name="ForceUppercase" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Sounds" Type="System.String" Scope="User">
<Value Profile="(Default)">Laughter</Value>
</Setting>
<Setting Name="FadeAway" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
@ -15,10 +12,19 @@
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ClearAfter" Type="System.Int32" Scope="User">
<Value Profile="(Default)">30</Value>
<Value Profile="(Default)">65</Value>
</Setting>
<Setting Name="MouseDraw" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FadeAfter" Type="System.Int32" Scope="User">
<Value Profile="(Default)">20</Value>
</Setting>
<Setting Name="FacesOnShapes" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="Sounds" Type="System.String" Scope="User">
<Value Profile="(Default)">Speech</Value>
</Setting>
</Settings>
</SettingsFile>

Двоичные данные
Resources/Sounds/falling.wav Normal file

Двоичный файл не отображается.

Двоичные данные
Resources/Sounds/rising.wav Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -1,28 +1,23 @@
namespace BabySmash.Properties {
using System.ComponentModel;
using System.Configuration;
namespace BabySmash.Properties
{
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
internal sealed partial class Settings
{
private void SettingChangingEventHandler(object sender, SettingChangingEventArgs e)
{
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
private void SettingsSavingEventHandler(object sender, CancelEventArgs e)
{
// Add code to handle the SettingsSaving event here.
}
}
}
}

148
Shapes/Animation.cs Normal file
Просмотреть файл

@ -0,0 +1,148 @@
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media;
namespace BabySmash
{
class Animation
{
public static BitmapEffect GetRandomBitmapEffect()
{
int e = Utils.RandomBetweenTwoNumbers(0, 3);
switch (e)
{
case 0:
return new BevelBitmapEffect();
case 1:
return new DropShadowBitmapEffect();
case 2:
return new EmbossBitmapEffect();
case 3:
return new OuterGlowBitmapEffect();
}
return new BevelBitmapEffect();
}
public static void ApplyRandomAnimationEffect(FrameworkElement fe, Duration duration)
{
int e = Utils.RandomBetweenTwoNumbers(0, 3);
switch (e)
{
case 0:
ApplyJiggle(fe, duration);
break;
case 1:
ApplySnap(fe, duration);
break;
case 2:
ApplyThrob(fe, duration);
break;
case 3:
ApplyRotate(fe, duration);
break;
}
}
public static Storyboard CreateDPAnimation(FrameworkElement container, UIElement shape,
DependencyProperty dp, Duration duration)
{
var st = new Storyboard();
NameScope.SetNameScope(container, new NameScope());
container.RegisterName("shape", shape);
var d = new DoubleAnimation
{
From = 1.0,
To = 0.0,
Duration = duration,
AutoReverse = false
};
st.Children.Add(d);
Storyboard.SetTargetName(d, "shape");
Storyboard.SetTargetProperty(d, new PropertyPath(dp));
return st;
}
public static void ApplyJiggle(FrameworkElement fe, Duration duration)
{
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(10, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(-10, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(5, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(-5, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.Duration = duration;
da.AccelerationRatio = da.DecelerationRatio = 0.2;
fe.RenderTransformOrigin = new Point(0.5, 0.5);
fe.RenderTransform = new RotateTransform(0);
fe.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, da);
}
public static void ApplyThrob(FrameworkElement fe, Duration duration)
{
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1.1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0.9, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1.05, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0.95, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.Duration = duration;
da.AccelerationRatio = da.DecelerationRatio = 0.2;
fe.RenderTransformOrigin = new Point(0.5, 0.5);
fe.RenderTransform = new ScaleTransform(1, 1);
fe.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da);
fe.RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);
}
public static void ApplyRotate(FrameworkElement fe, Duration duration)
{
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(-5, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(90, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(180, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(270, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(360, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(365, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(360, KeyTime.Paced));
da.Duration = duration;
da.AccelerationRatio = da.DecelerationRatio = 0.2;
fe.RenderTransformOrigin = new Point(0.5, 0.5);
fe.RenderTransform = new RotateTransform(0);
fe.RenderTransform.BeginAnimation(RotateTransform.AngleProperty, da);
}
public static void ApplySnap(FrameworkElement fe, Duration duration)
{
DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.Paced));
da.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.Paced));
da.Duration = duration;
da.AccelerationRatio = da.DecelerationRatio = 0.2;
fe.RenderTransformOrigin = new Point(0.5, 0.5);
fe.RenderTransform = new ScaleTransform(1, 1);
fe.RenderTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);
}
}
}

1785
Shapes/AnimationBehaviors.cs Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

72
Shapes/CoolCircle.xaml Normal file
Просмотреть файл

@ -0,0 +1,72 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolCircle"
x:Name="UserControl"
d:DesignWidth="6.666" d:DesignHeight="10"
>
<UserControl.Resources>
<Storyboard x:Key="CircleEyesSB">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="CircleEye1" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="CircleEye2" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="CircleSpin">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Circle" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.9000000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<!--<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Circle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-50"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="5"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.9000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>-->
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource CircleEyesSB}"/>
<BeginStoryboard Storyboard="{StaticResource CircleSpin}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas
x:Name="Circle">
<Ellipse x:Name="Body" StrokeThickness="10" Stroke="#ff000000" Width="212.176" Height="212.176">
<Ellipse.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="123,198" Center="123,198" RadiusX="102" RadiusY="102">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-16,305" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffffff00"/>
<GradientStop Offset="1" Color="#ff98ff00"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Canvas x:Name="Face">
<Path Fill="#ff000000" Data="F1 M 124.545898,151.451172 C 124.529297,161.141602 116.688477,168.981445 107.000977,168.998047 L 107.000977,168.998047 C 97.310547,168.981445 89.469727,161.141602 89.453125,151.451172 L 89.453125,151.451172 C 89.453125,148.690430 87.213867,146.451172 84.453125,146.451172 L 84.453125,146.451172 C 81.692383,146.451172 79.453125,148.690430 79.453125,151.451172 L 79.453125,151.451172 C 79.457031,166.666992 91.785156,178.995117 107.000977,178.999023 L 107.000977,178.999023 C 122.214844,178.995117 134.543945,166.666992 134.546875,151.451172 L 134.546875,151.451172 C 134.546875,148.690430 132.308594,146.451172 129.545898,146.451172 L 129.545898,146.451172 C 126.785156,146.451172 124.545898,148.690430 124.545898,151.451172 L 124.545898,151.451172 Z"/>
<Path x:Name="CircleEye1" StrokeThickness="10" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeMiterLimit="1" Data="F1 M 58.970703,66.372070 C 64.513184,62.001953 71.509277,59.393555 79.114258,59.393555 C 86.719727,59.393555 93.715820,62.001953 99.258301,66.372070"/>
<Path x:Name="CircleEye2" StrokeThickness="10" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeMiterLimit="1" Data="F1 M 114.742188,66.372070 C 120.284180,62.001953 127.280273,59.393555 134.885742,59.393555 C 142.491211,59.393555 149.487305,62.001953 155.029297,66.372070"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

49
Shapes/CoolCircle.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolCircle.xaml
/// </summary>
[Serializable]
public partial class CoolCircle : IHasFace
{
public CoolCircle(Brush x)
: this()
{
this.Body.Fill = x;
}
public CoolCircle()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

55
Shapes/CoolHeart.xaml Normal file
Просмотреть файл

@ -0,0 +1,55 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolHeart"
x:Name="UserControl"
d:DesignWidth="6.666" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="HeartSB">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HeartEyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource HeartSB}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Heart">
<Path x:Name="Body" Stroke="#ff000000" StrokeMiterLimit="1" StrokeThickness="15" Stretch="Fill" Data="F1 M 229,161.333C 306.333,88.6667 409,142.122 409,225.333C 409,308.544 229,462.667 229,462.667C 229,462.667 057,306.544 057,223.333C 057,140.123 156.138,88.4713 229,161.333 Z" Canvas.Top="-38" RenderTransformOrigin="0.5,0.5" Canvas.Left="-37">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.65" ScaleY="0.65"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Path.RenderTransform>
<Path.Fill>
<RadialGradientBrush>
<GradientStop Color="#FFFF0000" Offset="0"/>
<GradientStop Color="#FF980000" Offset="1"/>
<GradientStop Color="#FFC50000" Offset="0.531"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Canvas x:Name="Face">
<Path Fill="#ff000000" Data="F1 M 124.545898,151.451172 C 124.529297,161.141602 116.688477,168.981445 107.000977,168.998047 L 107.000977,168.998047 C 97.310547,168.981445 89.469727,161.141602 89.453125,151.451172 L 89.453125,151.451172 C 89.453125,148.690430 87.213867,146.451172 84.453125,146.451172 L 84.453125,146.451172 C 81.692383,146.451172 79.453125,148.690430 79.453125,151.451172 L 79.453125,151.451172 C 79.457031,166.666992 91.785156,178.995117 107.000977,178.999023 L 107.000977,178.999023 C 122.214844,178.995117 134.543945,166.666992 134.546875,151.451172 L 134.546875,151.451172 C 134.546875,148.690430 132.308594,146.451172 129.545898,146.451172 L 129.545898,146.451172 C 126.785156,146.451172 124.545898,148.690430 124.545898,151.451172 L 124.545898,151.451172 Z" Canvas.Left="36.333" Canvas.Top="14"/>
<Canvas x:Name="HeartEyes">
<Path Fill="#ff000000" Data="F1 M 121.578613,114.592773 C 121.578613,120.943848 116.429199,126.092773 110.078613,126.092773 C 103.727051,126.092773 98.578613,120.943848 98.578613,114.592773 C 98.578613,108.241699 103.727051,103.092773 110.078613,103.092773 C 116.429199,103.092773 121.578613,108.241699 121.578613,114.592773 Z" Canvas.Left="1" Canvas.Top="-31.134" d:LayoutOverrides="Width, Height, GridBox"/>
<Path Fill="#ff000000" Data="F1 M 154.578613,114.592773 C 154.578613,120.943848 149.430176,126.092773 143.078613,126.092773 C 136.727051,126.092773 131.578613,120.943848 131.578613,114.592773 C 131.578613,108.241699 136.727051,103.092773 143.078613,103.092773 C 149.430176,103.092773 154.578613,108.241699 154.578613,114.592773 Z" Canvas.Left="31.333" Canvas.Top="-31.134" d:LayoutOverrides="Width, Height, GridBox"/>
</Canvas>
</Canvas>
</Canvas>
</Grid>
</UserControl>

49
Shapes/CoolHeart.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolHeart.xaml
/// </summary>
[Serializable]
public partial class CoolHeart : IHasFace
{
public CoolHeart(Brush x)
: this()
{
this.Body.Fill = x;
}
public CoolHeart()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

49
Shapes/CoolHexagon.xaml Normal file
Просмотреть файл

@ -0,0 +1,49 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolHexagon"
x:Name="UserControl"
d:DesignWidth="6.666" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="Eyes">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Eyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Eyes}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Hexagon">
<Path x:Name="Body" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 61.853516,199.267578 L 5.773438,102.133789 L 61.853516,5 L 174.013672,5 L 230.093750,102.133789 L 174.013672,199.267578 L 61.853516,199.267578 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="664.333008,431.5" Center="664.333008,431.5" RadiusX="104.916328" RadiusY="104.916328">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-546.399414,533.633789" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffffff00"/>
<GradientStop Offset="1" Color="#fff05923"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Canvas x:Name="Face">
<Canvas x:Name="Eyes">
<Path Fill="#ff000000" Data="F1 M 100.433594,88.735352 C 103.952148,88.735352 107.389648,89.074707 110.728516,89.693848 L 110.728516,58.061035 C 110.728516,55.126465 108.349609,52.747070 105.414063,52.747070 L 95.451172,52.747070 C 92.517578,52.747070 90.138672,55.126465 90.138672,58.061035 L 90.138672,89.693848 C 93.477539,89.074707 96.915039,88.735352 100.433594,88.735352 Z"/>
<Path Fill="#ff000000" Data="F1 M 135.433594,88.735352 C 138.952148,88.735352 142.389648,89.074707 145.728516,89.693848 L 145.728516,58.061035 C 145.728516,55.126465 143.349609,52.747070 140.414063,52.747070 L 130.451172,52.747070 C 127.517578,52.747070 125.138672,55.126465 125.138672,58.061035 L 125.138672,89.693848 C 128.477539,89.074707 131.915039,88.735352 135.433594,88.735352 Z"/>
</Canvas>
<Path Fill="#ff000000" Data="F1 M 117.933594,135.528809 C 112.938477,135.528809 93.465820,133.640625 88.424805,132.747559 L 96.684570,165.867188 C 97.222656,168.024414 100.017578,169.694336 102.953125,169.694336 L 132.916016,169.694336 C 135.849609,169.694336 138.644531,168.024414 139.182617,165.867188 L 147.442383,132.747559 C 142.402344,133.640625 122.929688,135.528809 117.933594,135.528809 Z"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolHexagon.xaml
/// </summary>
[Serializable]
public partial class CoolHexagon :IHasFace
{
public CoolHexagon(Brush x)
: this()
{
this.Body.Fill = x;
}
public CoolHexagon()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

26
Shapes/CoolLetter.xaml Normal file
Просмотреть файл

@ -0,0 +1,26 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolLetter"
x:Name="UserControl"
d:DesignWidth="6.666" d:DesignHeight="10">
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Letter" Height="400" Width="400">
<Path x:Name="letterPath" StrokeThickness="10" Stroke="#ff000000" >
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="123,198" Center="123,198" RadiusX="102" RadiusY="102">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-16,305" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffffff00"/>
<GradientStop Offset="1" Color="#ff98ff00"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
</Canvas>
</Grid>
</UserControl>

71
Shapes/CoolLetter.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
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 BabySmash.Properties;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolCircle.xaml
/// </summary>
[Serializable]
public partial class CoolLetter
{
public CoolLetter()
{
this.InitializeComponent();
}
public CoolLetter(Brush x, string letter) : this()
{
this.letterPath.Fill = x;
this.letterPath.Data = MakeCharacterGeometry(GetLetterCharacter(letter));
this.Height = 400;
}
private static Geometry MakeCharacterGeometry(string t)
{
var fText = new FormattedText(
t,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(
new FontFamily("Arial"),
FontStyles.Normal,
FontWeights.Heavy,
FontStretches.Normal),
300,
Brushes.Black
);
return fText.BuildGeometry(new Point(0, 0)).GetAsFrozen() as Geometry;
}
private static string GetLetterCharacter(string name)
{
string nameToDisplay;
if (Settings.Default.ForceUppercase)
{
nameToDisplay = name;
}
else
{
nameToDisplay = Utils.GetRandomBoolean() ? name : name.ToLowerInvariant();
}
return nameToDisplay;
}
}
}

49
Shapes/CoolRectangle.xaml Normal file
Просмотреть файл

@ -0,0 +1,49 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolRectangle"
x:Name="UserControl"
d:DesignWidth="6.667" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="Eyes">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Eyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Eyes}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Square">
<Rectangle x:Name="Body" StrokeThickness="10" Stroke="#ff000000" Width="407" Height="207">
<Rectangle.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="110.185547,455" Center="110.185547,455" RadiusX="98.5" RadiusY="98.5">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-6.685547,558.5" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffff00ff"/>
<GradientStop Offset="1" Color="#ff9d005c"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Canvas x:Name="Face">
<Canvas x:Name="Eyes">
<Path Fill="#ff000000" Data="F1 M 93.295410,58.927246 C 93.295410,55.992676 90.916504,53.613281 87.981445,53.613281 L 78.018066,53.613281 C 75.083496,53.613281 72.704590,55.992676 72.704590,58.927246 L 72.704590,91 L 93.295410,91 L 93.295410,58.927246 Z" Height="91" Canvas.Left="98" Canvas.Top="0" Width="93" />
<Path Fill="#ff000000" Data="F1 M 134.295410,58.927246 C 134.295410,55.992676 131.916504,53.613281 128.981445,53.613281 L 119.018066,53.613281 C 116.083496,53.613281 113.704590,55.992676 113.704590,58.927246 L 113.704590,91 L 134.295410,91 L 134.295410,58.927246 Z" Height="91" Canvas.Left="98" Canvas.Top="0" Width="134.295" />
</Canvas>
<Path Fill="#ff000000" Data="F1 M 122.779297,145.530762 C 122.779297,156.178223 114.147461,164.810059 103.5,164.810059 C 92.852539,164.810059 84.220703,156.178223 84.220703,145.530762 C 84.220703,134.883301 92.852539,145.530762 103.5,145.530762 C 114.147461,145.530762 122.779297,134.883301 122.779297,145.530762 Z" Height="164.81" Canvas.Left="98" Canvas.Top="0" Width="122.779" />
</Canvas>
</Canvas>
</Grid>
</UserControl>

Просмотреть файл

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolSquare.xaml
/// </summary>
[Serializable]
public partial class CoolRectangle :IHasFace
{
public CoolRectangle(Brush x)
: this()
{
this.Body.Fill = x;
}
public CoolRectangle()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

51
Shapes/CoolSquare.xaml Normal file
Просмотреть файл

@ -0,0 +1,51 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolSquare"
x:Name="UserControl"
d:DesignWidth="6.667" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="Eyes">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Eyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Eyes}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Square">
<Rectangle x:Name="Body" StrokeThickness="10" Stroke="#ff000000" Width="207" Height="207">
<Rectangle.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="110.185547,455" Center="110.185547,455" RadiusX="98.5" RadiusY="98.5">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-6.685547,558.5" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffff00ff"/>
<GradientStop Offset="1" Color="#ff9d005c"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Canvas x:Name="Face">
<Canvas x:Name="Eyes">
<Path Fill="#ff000000" Data="F1 M 93.295410,58.927246 C 93.295410,55.992676 90.916504,53.613281 87.981445,53.613281 L 78.018066,53.613281 C 75.083496,53.613281 72.704590,55.992676 72.704590,58.927246 L 72.704590,91 L 93.295410,91 L 93.295410,58.927246 Z"/>
<Path Fill="#ff000000" Data="F1 M 134.295410,58.927246 C 134.295410,55.992676 131.916504,53.613281 128.981445,53.613281 L 119.018066,53.613281 C 116.083496,53.613281 113.704590,55.992676 113.704590,58.927246 L 113.704590,91 L 134.295410,91 L 134.295410,58.927246 Z"/>
</Canvas>
<Path Fill="#ff000000" Data="F1 M 122.779297,145.530762 C 122.779297,156.178223 114.147461,164.810059 103.5,164.810059 C 92.852539,164.810059 84.220703,156.178223 84.220703,145.530762 C 84.220703,134.883301 92.852539,145.530762 103.5,145.530762 C 114.147461,145.530762 122.779297,134.883301 122.779297,145.530762 Z"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

50
Shapes/CoolSquare.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolSquare.xaml
/// </summary>
[Serializable]
public partial class CoolSquare : IHasFace
{
public CoolSquare(Brush x)
: this()
{
this.Body.Fill = x;
}
public CoolSquare()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

49
Shapes/CoolStar.xaml Normal file
Просмотреть файл

@ -0,0 +1,49 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolStar"
x:Name="UserControl"
d:DesignWidth="6.667" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="Eyes">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Eyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Eyes}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Star">
<Path x:Name="Body" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.456055 L 90.783691,83.825684 L 126.578613,11.297852 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="390.395508,448.130371" Center="390.395508,448.130371" RadiusX="113.034821" RadiusY="113.034821">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-263.816895,569.592773" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ff00"/>
<GradientStop Offset="1" Color="#ff006736"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Canvas x:Name="Face">
<Canvas x:Name="Eyes">
<Path Fill="#ff000000" Data="F1 M 121.578613,114.592773 C 121.578613,120.943848 116.429199,126.092773 110.078613,126.092773 C 103.727051,126.092773 98.578613,120.943848 98.578613,114.592773 C 98.578613,108.241699 103.727051,103.092773 110.078613,103.092773 C 116.429199,103.092773 121.578613,108.241699 121.578613,114.592773 Z"/>
<Path Fill="#ff000000" Data="F1 M 154.578613,114.592773 C 154.578613,120.943848 149.430176,126.092773 143.078613,126.092773 C 136.727051,126.092773 131.578613,120.943848 131.578613,114.592773 C 131.578613,108.241699 136.727051,103.092773 143.078613,103.092773 C 149.430176,103.092773 154.578613,108.241699 154.578613,114.592773 Z"/>
</Canvas>
<Path Fill="#ff000000" Data="F1 M 139.507324,154.020020 C 139.507324,161.159668 133.717773,166.948242 126.578125,166.948242 C 119.438477,166.948242 113.649902,161.159668 113.649902,154.020020 C 113.649902,146.879883 119.438477,154.020020 126.578125,154.020020 C 133.717773,154.020020 139.507324,146.879883 139.507324,154.020020 Z"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

49
Shapes/CoolStar.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolStar.xaml
/// </summary>
[Serializable]
public partial class CoolStar : IHasFace
{
public CoolStar(Brush x) : this()
{
Body.Fill = x;
}
public CoolStar()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

47
Shapes/CoolTrapezoid.xaml Normal file
Просмотреть файл

@ -0,0 +1,47 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolTrapezoid"
x:Name="UserControl"
d:DesignWidth="20" d:DesignHeight="20">
<UserControl.Resources>
<Storyboard x:Key="ParallelogramSB">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ParallelEyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource ParallelogramSB}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Parellelogram">
<Path x:Name="Body" StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 302.564941,159.833984 L 6.651855,159.833984 L 51.451172,5 L 257.766113,5 L 302.564941,159.833984 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="410.416016,182.5" Center="410.416016,182.5" RadiusX="118.077667" RadiusY="118.077667">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-255.808105,264.916992" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ffff"/>
<GradientStop Offset="1" Color="#ff0000ff"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Canvas x:Name="Face">
<Path Fill="#ff000000" Data="F1 M 172.153809,102.869141 C 172.137207,112.559570 164.296387,120.399414 154.608887,120.416016 L 154.608887,120.416016 C 144.918457,120.399414 137.077637,112.559570 137.061035,102.869141 L 137.061035,102.869141 C 137.061035,100.108398 134.821777,97.869141 132.061035,97.869141 L 132.061035,97.869141 C 129.300293,97.869141 127.061035,100.108398 127.061035,102.869141 L 127.061035,102.869141 C 127.064941,118.084961 139.393066,130.413086 154.608887,130.416992 L 154.608887,130.416992 C 169.822754,130.413086 182.151855,118.084961 182.154785,102.869141 L 182.154785,102.869141 C 182.154785,100.108398 179.916504,97.869141 177.153809,97.869141 L 177.153809,97.869141 C 174.393066,97.869141 172.153809,100.108398 172.153809,102.869141 L 172.153809,102.869141 Z" x:Name="mouth"/>
<Path Fill="#ff000000" Stretch="Fill" x:Name="ParallelEyes" Width="30" Height="34" Canvas.Left="139.608" Canvas.Top="34.417" Data="M23.5,0 C27.089844,0 30,2.9101563 30,6.5 L30,27.5 C30,31.089844 27.089844,34 23.5,34 19.910156,34 17,31.089844 17,27.5 L17,6.5 C17,2.9101563 19.910156,0 23.5,0 z M6.5,0 C10.089844,0 13,2.9101563 13,6.5 L13,27.5 C13,31.089844 10.089844,34 6.5,34 2.9101563,34 0,31.089844 0,27.5 L0,6.5 C0,2.9101563 2.9101563,0 6.5,0 z"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolTrapezoid.xaml
/// </summary>
[Serializable]
public partial class CoolTrapezoid : IHasFace
{
public CoolTrapezoid(Brush x)
: this()
{
Body.Fill = x;
}
public CoolTrapezoid()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

49
Shapes/CoolTriangle.xaml Normal file
Просмотреть файл

@ -0,0 +1,49 @@
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="BabySmash.CoolTriangle"
x:Name="UserControl"
d:DesignWidth="6.666" d:DesignHeight="10">
<UserControl.Resources>
<Storyboard x:Key="Eyes">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Eyes" Storyboard.TargetProperty="(UIElement.Opacity)" RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.1000000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:02.300000" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:10.300000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Eyes}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid x:Name="LayoutRoot">
<Canvas x:Name="Triangle">
<Path x:Name="Body" Stretch="Fill" Stroke="#ff000000" StrokeMiterLimit="1" StrokeThickness="10" HorizontalAlignment="Left" Width="247.666" Data="M-182.61185,-253.00014 L-301.61203,-82.000235 C-301.61203,-82.000235 -67,-81 -64,-82 -61,-83 -182.61185,-253.00014 -182.61185,-253.00014 z" Grid.RowSpan="2" Canvas.Left="-17" Canvas.Top="8">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="664.333008,431.5" Center="664.333008,431.5" RadiusX="104.916328" RadiusY="104.916328">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-546.399414,533.633789" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#FFFF00F9"/>
<GradientStop Offset="1" Color="#FFF0ECEA"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Canvas x:Name="Face">
<Canvas x:Name="Eyes">
<Path Fill="#ff000000" Data="F1 M10.294922,23.294434 C13.813476,23.294434 17.250976,23.633789 20.589844,24.25293 L20.589844,5.3139647 C20.589844,2.3793947 18.210937,-3.125E-07 15.275391,-3.125E-07 L5.3125001,-3.125E-07 C2.3789061,-3.125E-07 1.25E-07,2.3793947 1.25E-07,5.3139647 L1.25E-07,24.25293 C3.3388671,23.633789 6.7763671,23.294434 10.294922,23.294434 z" Width="20.59" Height="24.253" Canvas.Left="85.14" Canvas.Top="83.747"/>
<Path Fill="#ff000000" Data="F1 M10.294922,23.294434 C13.813476,23.294434 17.250976,23.633789 20.589844,24.25293 L20.589844,5.3139647 C20.589844,2.3793947 18.210937,-3.125E-07 15.275391,-3.125E-07 L5.3125001,-3.125E-07 C2.3789061,-3.125E-07 1.25E-07,2.3793947 1.25E-07,5.3139647 L1.25E-07,24.25293 C3.3388671,23.633789 6.7763671,23.294434 10.294922,23.294434 z" Width="20.59" Height="24.253" Canvas.Left="112.853" Canvas.Top="83.747"/>
</Canvas>
<Path Fill="#ff000000" Data="F1 M 122.779297,145.530762 C 122.779297,156.178223 114.147461,164.810059 103.5,164.810059 C 92.852539,164.810059 84.220703,156.178223 84.220703,145.530762 C 84.220703,134.883301 92.852539,145.530762 103.5,145.530762 C 114.147461,145.530762 122.779297,134.883301 122.779297,145.530762 Z" Canvas.Left="6" Canvas.Top="-1"/>
</Canvas>
</Canvas>
</Grid>
</UserControl>

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
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;
namespace BabySmash
{
/// <summary>
/// Interaction logic for CoolTriangle.xaml
/// </summary>
[Serializable]
public partial class CoolTriangle : IHasFace
{
public CoolTriangle(Brush x) : this()
{
Body.Fill = x;
}
public CoolTriangle()
{
this.InitializeComponent();
}
#region IHasFace Members
public Visibility FaceVisible
{
get
{
return Face.Visibility;
}
set
{
Face.Visibility = value;
}
}
#endregion
}
}

Просмотреть файл

@ -1,123 +1,14 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using Drawing = System.Drawing;
using System.Globalization;
using BabySmash.Properties;
namespace BabySmash
{
public abstract class Figure
{
private readonly string name;
private readonly string color;
protected Figure(Brush fill, string name, Shape s)
{
this.color = Utils.BrushToString(fill);
this.name = name;
this.Shape = s;
s.Fill = fill;
s.Style = Application.Current.Resources[Name] as Style;
}
public UIElement Shape { get; protected set; }
public string Name { get { return name; } }
public string Color { get { return color; } }
}
public class SquareFigure : Figure
{
public SquareFigure(Brush fill)
: base(fill, "square", new Rectangle()){}
}
public class RectangleFigure : Figure
{
public RectangleFigure(Brush fill)
: base(fill, "rectangle", new Rectangle()){}
}
public class CircleFigure : Figure
{
public CircleFigure(Brush fill)
: base(fill, "circle", new Ellipse()){}
}
public class TriangleFigure : Figure
{
public TriangleFigure(Brush fill)
: base(fill, "triangle", new Polygon()){}
}
public class StarFigure : Figure
{
public StarFigure(Brush fill)
: base(fill, "star", new Star()){}
}
public class TrapezoidFigure : Figure
{
public TrapezoidFigure(Brush fill)
: base(fill, "trapezoid", new Path())
{
}
}
public class HeartFigure : Figure
{
public HeartFigure(Brush fill)
: base(fill, "heart", new Path())
{}
}
public class LetterFigure : Figure
{
public LetterFigure(Brush fill, string name)
: base(fill, "BabySmashBaseStyle",
new Path()
{
Data = MakeCharacterGeometry(
GetLetterCharacter(name)),
Height = 400
}
)
{
}
private static string GetLetterCharacter(string name)
{
string nameToDisplay;
if (Properties.Settings.Default.ForceUppercase)
{
nameToDisplay = name;
}
else
{
nameToDisplay = Utils.GetRandomBoolean() ? name : name.ToLowerInvariant();
}
return nameToDisplay;
}
private static Geometry MakeCharacterGeometry(string t)
{
FormattedText fText = new FormattedText(
t,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(
new FontFamily("Arial"),
FontStyles.Normal,
FontWeights.Heavy,
FontStretches.Normal),
300,
Brushes.Black
);
return fText.BuildGeometry(new Point(0, 0)).GetAsFrozen() as Geometry;
}
}
}
public interface IHasFace
{
Visibility FaceVisible { get; set; }
}
}

Просмотреть файл

@ -1,112 +1,75 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Effects;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using BabySmash;
using System.Windows.Media.Effects;
using BrushControlFunc = System.Func<System.Windows.Media.Brush, System.Windows.Controls.UserControl>;
namespace BabySmash
{
public class FigureTemplate
{
public Brush Fill { get; set; }
public Color Color { get; set; }
public BrushControlFunc GeneratorFunc { get; set; }
public BitmapEffect Effect { get; set; }
public string Name { get; set; }
public string Letter { get; set; }
}
public class FigureGenerator
{
private int clearAfter;
private readonly ObservableCollection<Figure> figures = new ObservableCollection<Figure>();
private static readonly List<KeyValuePair<string, BrushControlFunc>> hashTableOfFigureGenerators = new List<KeyValuePair<string, BrushControlFunc>>
{
new KeyValuePair<string, BrushControlFunc>("Circle", x => new CoolCircle(x) ),
new KeyValuePair<string, BrushControlFunc>("Rectangle", x => new CoolRectangle(x) ),
new KeyValuePair<string, BrushControlFunc>("Hexagon", x => new CoolHexagon(x) ),
new KeyValuePair<string, BrushControlFunc>("Trapezoid", x => new CoolTrapezoid(x) ),
new KeyValuePair<string, BrushControlFunc>("Star", x => new CoolStar(x) ),
new KeyValuePair<string, BrushControlFunc>("Square", x => new CoolSquare(x) ),
new KeyValuePair<string, BrushControlFunc>("Triangle", x => new CoolTriangle(x) ),
new KeyValuePair<string, BrushControlFunc>("Heart", x => new CoolHeart(x) )
};
public int ClearAfter
public static UserControl NewUserControlFrom(FigureTemplate template)
{
get { return clearAfter; }
set { clearAfter = value; }
}
public ObservableCollection<Figure> Figures
{
get { return figures; }
}
public void Generate(FrameworkElement container)
{
Generate(container, "");
}
public void Generate(FrameworkElement container, string letter)
{
if (figures.Count == clearAfter)
figures.Clear();
Figure f = GenerateFigure(letter);
Storyboard s = CreateStoryboardAnimation(container, f.Shape, Shape.OpacityProperty);
UserControl retVal = null;
//We'll wait for Hardware Accelerated Shader Effects in SP1
if (Properties.Settings.Default.BitmapEffects)
f.Shape.BitmapEffect = GetRandomBitmapEffect();
figures.Add(f);
if (Properties.Settings.Default.FadeAway) s.Begin(container);
}
private BitmapEffect GetRandomBitmapEffect()
{
int e = Utils.RandomBetweenTwoNumbers(0, 3);
switch (e)
if (template.Letter.Length == 1 && Char.IsLetterOrDigit(template.Letter[0]))
{
case 0:
return new BevelBitmapEffect();
case 1:
return new DropShadowBitmapEffect();
case 2:
return new EmbossBitmapEffect();
case 3:
return new OuterGlowBitmapEffect();
retVal = new CoolLetter(template.Fill.Clone(), template.Letter);
}
else
{
retVal = template.GeneratorFunc(template.Fill.Clone());
}
return new BevelBitmapEffect();
}
private static Storyboard CreateStoryboardAnimation(FrameworkElement container, UIElement shape, DependencyProperty dp)
{
var st = new Storyboard();
NameScope.SetNameScope(container, new NameScope());
container.RegisterName("shape", shape);
var d = new DoubleAnimation();
d.From = 1.0;
d.To = 0.0;
d.Duration = new Duration(TimeSpan.FromSeconds(7));
d.AutoReverse = false;
st.Children.Add(d);
Storyboard.SetTargetName(d, "shape");
Storyboard.SetTargetProperty(d, new PropertyPath(dp));
return st;
//TODO: TOO SLOW! Waiting for ShaderEffects in 3.5SP1
//if (Settings.Default.BitmapEffects)
//{
// retVal.BitmapEffect = template.Effect.Clone();
//}
return retVal;
}
//TODO: Should this be in XAML? Would that make it better?
//TODO: Should I change the height, width and stroke to be relative to the screen size?
//TODO: Where can I get REALLY complex shapes like animal vectors or custom pics? Where do I store them?
private static readonly List<Func<Brush, Figure>> listOfPotentialFigures = new List<Func<Brush, Figure>>
public static FigureTemplate GenerateFigureTemplate(string letter)
{
x => new SquareFigure(x),
x => new CircleFigure(x),
x => new TriangleFigure(x),
x => new StarFigure(x),
x => new HeartFigure(x),
x => new TrapezoidFigure(x),
x => new RectangleFigure(x)
};
Color c = Utils.GetRandomColor();
private static Figure GenerateFigure(string letter)
{
var fill = Utils.GetRandomColoredBrush();
if (letter.Length == 1 && Char.IsLetterOrDigit(letter[0]))
return new LetterFigure(fill, letter);
var myFunc = listOfPotentialFigures[
Utils.RandomBetweenTwoNumbers(0, listOfPotentialFigures.Count - 1)];
return myFunc(fill);
var nameFunc = hashTableOfFigureGenerators[Utils.RandomBetweenTwoNumbers(0, hashTableOfFigureGenerators.Count - 1)];
return new FigureTemplate
{
Color = c,
Name = (letter.Length == 1 && Char.IsLetterOrDigit(letter[0])) ? letter : nameFunc.Key,
GeneratorFunc = nameFunc.Value,
Fill = Utils.GetGradientBrush(c),
Letter = letter,
Effect = Animation.GetRandomBitmapEffect()
};
}
}
}

Просмотреть файл

@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Windows.Shapes;
namespace BabySmash
{
public class Star : Shape
{
// Using a DependencyProperty as the backing store for NumberOfPoints.
public static readonly DependencyProperty NumberOfPointsProperty =
DependencyProperty.Register("NumberOfPoints", typeof(int), typeof(Shape), new UIPropertyMetadata(5));
public int NumberOfPoints
{
get { return (int)GetValue(NumberOfPointsProperty); }
set { SetValue(NumberOfPointsProperty, value); }
}
protected override Geometry DefiningGeometry
{
get { return CreateStarGeometry(NumberOfPoints); }
}
public Geometry CreateStarGeometry(int numberOfPoints)
{
const double outerRadius = 300;
const double innerRadius = 90;
Point[] points = new Point[numberOfPoints * 2 - 1];
for (int i = 0; i < numberOfPoints * 2 - 1; ++i)
{
double radius = ((i & 1) == 0) ? innerRadius : outerRadius;
double angle = Math.PI * (i + 1) / numberOfPoints;
points[i] = new Point(radius * Math.Sin(angle), -radius * Math.Cos(angle));
}
PolyLineSegment segment = new PolyLineSegment(points, true);
PathFigure starFigure = new PathFigure(new Point(0, -outerRadius), new PathSegment[] { segment }, true);
return new PathGeometry(new PathFigure[] { starFigure });
}
}
}

158
Shapes/allShapes.xaml Normal file
Просмотреть файл

@ -0,0 +1,158 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- BOF Parellelogram -->
<Canvas x:Name="Parellelogram" Grid.Row="1" HorizontalAlignment="Left" Height="20" Margin="-42,0,0,-95" VerticalAlignment="Bottom" Width="20">
<Path StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 302.564941,159.833984 L 6.651855,159.833984 L 51.451172,5 L 257.766113,5 L 302.564941,159.833984 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="410.416016,182.5" Center="410.416016,182.5" RadiusX="118.077667" RadiusY="118.077667">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-255.808105,264.916992" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ffff"/>
<GradientStop Offset="1" Color="#ff0000ff"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Path Fill="#ff000000" Data="F1 M 172.153809,102.869141 C 172.137207,112.559570 164.296387,120.399414 154.608887,120.416016 L 154.608887,120.416016 C 144.918457,120.399414 137.077637,112.559570 137.061035,102.869141 L 137.061035,102.869141 C 137.061035,100.108398 134.821777,97.869141 132.061035,97.869141 L 132.061035,97.869141 C 129.300293,97.869141 127.061035,100.108398 127.061035,102.869141 L 127.061035,102.869141 C 127.064941,118.084961 139.393066,130.413086 154.608887,130.416992 L 154.608887,130.416992 C 169.822754,130.413086 182.151855,118.084961 182.154785,102.869141 L 182.154785,102.869141 C 182.154785,100.108398 179.916504,97.869141 177.153809,97.869141 L 177.153809,97.869141 C 174.393066,97.869141 172.153809,100.108398 172.153809,102.869141 L 172.153809,102.869141 Z"/>
<Path Fill="#ff000000" Data="F1 M 152.607910,61.916992 C 152.607910,65.506836 149.697754,68.416992 146.107910,68.416992 L 146.107910,68.416992 C 142.518066,68.416992 139.607910,65.506836 139.607910,61.916992 L 139.607910,40.916992 C 139.607910,37.327148 142.518066,34.416992 146.107910,34.416992 L 146.107910,34.416992 C 149.697754,34.416992 152.607910,37.327148 152.607910,40.916992 L 152.607910,61.916992 Z"/>
<Path Fill="#ff000000" Data="F1 M 169.607910,61.916992 C 169.607910,65.506836 166.697754,68.416992 163.107910,68.416992 L 163.107910,68.416992 C 159.518066,68.416992 156.607910,65.506836 156.607910,61.916992 L 156.607910,40.916992 C 156.607910,37.327148 159.518066,34.416992 163.107910,34.416992 L 163.107910,34.416992 C 166.697754,34.416992 169.607910,37.327148 169.607910,40.916992 L 169.607910,61.916992 Z"/>
</Canvas>
<!-- EOF Parellelogram -->
<!-- BOF Hexagon -->
<Canvas x:Name="Hexagon" Height="10" HorizontalAlignment="Left" Width="6.666" Margin="-252.333,-139,0,0" VerticalAlignment="Top">
<Path StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 61.853516,199.267578 L 5.773438,102.133789 L 61.853516,5 L 174.013672,5 L 230.093750,102.133789 L 174.013672,199.267578 L 61.853516,199.267578 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="664.333008,431.5" Center="664.333008,431.5" RadiusX="104.916328" RadiusY="104.916328">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-546.399414,533.633789" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffffff00"/>
<GradientStop Offset="1" Color="#fff05923"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Path Fill="#ff000000" Data="F1 M 100.433594,88.735352 C 103.952148,88.735352 107.389648,89.074707 110.728516,89.693848 L 110.728516,58.061035 C 110.728516,55.126465 108.349609,52.747070 105.414063,52.747070 L 95.451172,52.747070 C 92.517578,52.747070 90.138672,55.126465 90.138672,58.061035 L 90.138672,89.693848 C 93.477539,89.074707 96.915039,88.735352 100.433594,88.735352 Z"/>
<Path Fill="#ff000000" Data="F1 M 135.433594,88.735352 C 138.952148,88.735352 142.389648,89.074707 145.728516,89.693848 L 145.728516,58.061035 C 145.728516,55.126465 143.349609,52.747070 140.414063,52.747070 L 130.451172,52.747070 C 127.517578,52.747070 125.138672,55.126465 125.138672,58.061035 L 125.138672,89.693848 C 128.477539,89.074707 131.915039,88.735352 135.433594,88.735352 Z"/>
<Path Fill="#ff000000" Data="F1 M 117.933594,135.528809 C 112.938477,135.528809 93.465820,133.640625 88.424805,132.747559 L 96.684570,165.867188 C 97.222656,168.024414 100.017578,169.694336 102.953125,169.694336 L 132.916016,169.694336 C 135.849609,169.694336 138.644531,168.024414 139.182617,165.867188 L 147.442383,132.747559 C 142.402344,133.640625 122.929688,135.528809 117.933594,135.528809 Z"/>
</Canvas>
<!-- EOF Hexagon -->
<!-- BOF Square -->
<Canvas Grid.Column="2" x:Name="Square" Width="6.667" Height="10" HorizontalAlignment="Right" Margin="0,-226,-156,0" VerticalAlignment="Top">
<Rectangle StrokeThickness="10" Stroke="#ff000000" Width="207" Height="207">
<Rectangle.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="110.185547,455" Center="110.185547,455" RadiusX="98.5" RadiusY="98.5">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-6.685547,558.5" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffff00ff"/>
<GradientStop Offset="1" Color="#ff9d005c"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Path Fill="#ff000000" Data="F1 M 93.295410,58.927246 C 93.295410,55.992676 90.916504,53.613281 87.981445,53.613281 L 78.018066,53.613281 C 75.083496,53.613281 72.704590,55.992676 72.704590,58.927246 L 72.704590,91 L 93.295410,91 L 93.295410,58.927246 Z"/>
<Path Fill="#ff000000" Data="F1 M 134.295410,58.927246 C 134.295410,55.992676 131.916504,53.613281 128.981445,53.613281 L 119.018066,53.613281 C 116.083496,53.613281 113.704590,55.992676 113.704590,58.927246 L 113.704590,91 L 134.295410,91 L 134.295410,58.927246 Z"/>
<Path Fill="#ff000000" Data="F1 M 122.779297,145.530762 C 122.779297,156.178223 114.147461,164.810059 103.5,164.810059 C 92.852539,164.810059 84.220703,156.178223 84.220703,145.530762 C 84.220703,134.883301 92.852539,145.530762 103.5,145.530762 C 114.147461,145.530762 122.779297,134.883301 122.779297,145.530762 Z"/>
</Canvas>
<!-- EOF Square -->
<!-- BOF Star -->
<Canvas Grid.Row="1" x:Name="Star" Width="6.667" Height="10" Grid.Column="2" HorizontalAlignment="Right" Margin="0,0,-338.667,-36" VerticalAlignment="Bottom">
<Path StrokeThickness="10" Stroke="#ff000000" StrokeMiterLimit="1" Data="F1 M 126.578613,11.297852 L 162.373535,83.825684 L 242.412598,95.456055 L 184.495605,151.911133 L 198.167480,231.626953 L 126.578613,193.990234 L 54.988770,231.626953 L 68.661621,151.911133 L 10.744629,95.456055 L 90.783691,83.825684 L 126.578613,11.297852 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="390.395508,448.130371" Center="390.395508,448.130371" RadiusX="113.034821" RadiusY="113.034821">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-263.816895,569.592773" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ff00ff00"/>
<GradientStop Offset="1" Color="#ff006736"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Path Fill="#ff000000" Data="F1 M 121.578613,114.592773 C 121.578613,120.943848 116.429199,126.092773 110.078613,126.092773 C 103.727051,126.092773 98.578613,120.943848 98.578613,114.592773 C 98.578613,108.241699 103.727051,103.092773 110.078613,103.092773 C 116.429199,103.092773 121.578613,108.241699 121.578613,114.592773 Z"/>
<Path Fill="#ff000000" Data="F1 M 154.578613,114.592773 C 154.578613,120.943848 149.430176,126.092773 143.078613,126.092773 C 136.727051,126.092773 131.578613,120.943848 131.578613,114.592773 C 131.578613,108.241699 136.727051,103.092773 143.078613,103.092773 C 149.430176,103.092773 154.578613,108.241699 154.578613,114.592773 Z"/>
<Path Fill="#ff000000" Data="F1 M 139.507324,154.020020 C 139.507324,161.159668 133.717773,166.948242 126.578125,166.948242 C 119.438477,166.948242 113.649902,161.159668 113.649902,154.020020 C 113.649902,146.879883 119.438477,154.020020 126.578125,154.020020 C 133.717773,154.020020 139.507324,146.879883 139.507324,154.020020 Z"/>
</Canvas>
<!-- EOF Star -->
<!-- BOF Circle -->
<Canvas Grid.Row="1" x:Name="Circle" Height="10" HorizontalAlignment="Left" Width="6.666" Margin="-310.333,0,0,-36" VerticalAlignment="Bottom">
<Ellipse StrokeThickness="10" Stroke="#ff000000" Width="212.176" Height="212.176">
<Ellipse.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="123,198" Center="123,198" RadiusX="102" RadiusY="102">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-16,305" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#ffff0000"/>
<GradientStop Offset="1" Color="#ff980000"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Path Fill="#ff000000" Data="F1 M 124.545898,151.451172 C 124.529297,161.141602 116.688477,168.981445 107.000977,168.998047 L 107.000977,168.998047 C 97.310547,168.981445 89.469727,161.141602 89.453125,151.451172 L 89.453125,151.451172 C 89.453125,148.690430 87.213867,146.451172 84.453125,146.451172 L 84.453125,146.451172 C 81.692383,146.451172 79.453125,148.690430 79.453125,151.451172 L 79.453125,151.451172 C 79.457031,166.666992 91.785156,178.995117 107.000977,178.999023 L 107.000977,178.999023 C 122.214844,178.995117 134.543945,166.666992 134.546875,151.451172 L 134.546875,151.451172 C 134.546875,148.690430 132.308594,146.451172 129.545898,146.451172 L 129.545898,146.451172 C 126.785156,146.451172 124.545898,148.690430 124.545898,151.451172 L 124.545898,151.451172 Z"/>
<Path StrokeThickness="10" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeMiterLimit="1" Data="F1 M 58.970703,66.372070 C 64.513184,62.001953 71.509277,59.393555 79.114258,59.393555 C 86.719727,59.393555 93.715820,62.001953 99.258301,66.372070"/>
<Path StrokeThickness="10" Stroke="#ff000000" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeMiterLimit="1" Data="F1 M 114.742188,66.372070 C 120.284180,62.001953 127.280273,59.393555 134.885742,59.393555 C 142.491211,59.393555 149.487305,62.001953 155.029297,66.372070"/>
</Canvas>
<Canvas x:Name="Triangle" Height="10" HorizontalAlignment="Left" Width="6.666" VerticalAlignment="Top">
<Path Stretch="Fill" Stroke="#ff000000" StrokeMiterLimit="1" StrokeThickness="10" HorizontalAlignment="Left" Width="247.666" Data="M-182.61185,-253.00014 L-301.61203,-82.000235 C-301.61203,-82.000235 -67,-81 -64,-82 -61,-83 -182.61185,-253.00014 -182.61185,-253.00014 z" Grid.RowSpan="2" Canvas.Left="-17" Canvas.Top="8">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="664.333008,431.5" Center="664.333008,431.5" RadiusX="104.916328" RadiusY="104.916328">
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1,0,-0,-1,-546.399414,533.633789" />
</RadialGradientBrush.Transform>
<GradientStop Offset="0" Color="#FFFF00F9"/>
<GradientStop Offset="1" Color="#FFF0ECEA"/>
</RadialGradientBrush>
</Path.Fill>
</Path>
<Path Fill="#ff000000" Data="F1 M10.294922,23.294434 C13.813476,23.294434 17.250976,23.633789 20.589844,24.25293 L20.589844,5.3139647 C20.589844,2.3793947 18.210937,-3.125E-07 15.275391,-3.125E-07 L5.3125001,-3.125E-07 C2.3789061,-3.125E-07 1.25E-07,2.3793947 1.25E-07,5.3139647 L1.25E-07,24.25293 C3.3388671,23.633789 6.7763671,23.294434 10.294922,23.294434 z" Canvas.Top="83.747" Canvas.Left="85.14" Width="20.59" Height="24.253"/>
<Path Fill="#ff000000" Data="F1 M10.294922,23.294434 C13.813476,23.294434 17.250976,23.633789 20.589844,24.25293 L20.589844,5.3139647 C20.589844,2.3793947 18.210937,-3.125E-07 15.275391,-3.125E-07 L5.3125001,-3.125E-07 C2.3789061,-3.125E-07 1.25E-07,2.3793947 1.25E-07,5.3139647 L1.25E-07,24.25293 C3.3388671,23.633789 6.7763671,23.294434 10.294922,23.294434 z" Width="20.59" Height="24.253" Canvas.Left="112.853" Canvas.Top="83.747"/>
<Path Fill="#ff000000" Data="F1 M 122.779297,145.530762 C 122.779297,156.178223 114.147461,164.810059 103.5,164.810059 C 92.852539,164.810059 84.220703,156.178223 84.220703,145.530762 C 84.220703,134.883301 92.852539,145.530762 103.5,145.530762 C 114.147461,145.530762 122.779297,134.883301 122.779297,145.530762 Z" Canvas.Left="6" Canvas.Top="-1"/>
</Canvas>
<Canvas x:Name="Heart" Height="10" HorizontalAlignment="Left" Width="6.666" Margin="-404.333,0,0,-234.134" VerticalAlignment="Bottom" Grid.Row="1">
<Path Stroke="#ff000000" StrokeMiterLimit="1" StrokeThickness="15" Stretch="Fill" Data="F1 M 229,161.333C 306.333,88.6667 409,142.122 409,225.333C 409,308.544 229,462.667 229,462.667C 229,462.667 057,306.544 057,223.333C 057,140.123 156.138,88.4713 229,161.333 Z" Canvas.Top="-38" RenderTransformOrigin="0.5,0.5" Canvas.Left="-37">
<Path.Fill>
<RadialGradientBrush>
<GradientStop Color="#FFFF0000" Offset="0"/>
<GradientStop Color="#FF980000" Offset="1"/>
<GradientStop Color="#FFC50000" Offset="0.531"/>
</RadialGradientBrush>
</Path.Fill>
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.65" ScaleY="0.65"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Path.RenderTransform>
</Path>
<Path Fill="#ff000000" Data="F1 M 124.545898,151.451172 C 124.529297,161.141602 116.688477,168.981445 107.000977,168.998047 L 107.000977,168.998047 C 97.310547,168.981445 89.469727,161.141602 89.453125,151.451172 L 89.453125,151.451172 C 89.453125,148.690430 87.213867,146.451172 84.453125,146.451172 L 84.453125,146.451172 C 81.692383,146.451172 79.453125,148.690430 79.453125,151.451172 L 79.453125,151.451172 C 79.457031,166.666992 91.785156,178.995117 107.000977,178.999023 L 107.000977,178.999023 C 122.214844,178.995117 134.543945,166.666992 134.546875,151.451172 L 134.546875,151.451172 C 134.546875,148.690430 132.308594,146.451172 129.545898,146.451172 L 129.545898,146.451172 C 126.785156,146.451172 124.545898,148.690430 124.545898,151.451172 L 124.545898,151.451172 Z" Canvas.Top="14" Canvas.Left="36.333"/>
<Path Fill="#ff000000" Data="F1 M 121.578613,114.592773 C 121.578613,120.943848 116.429199,126.092773 110.078613,126.092773 C 103.727051,126.092773 98.578613,120.943848 98.578613,114.592773 C 98.578613,108.241699 103.727051,103.092773 110.078613,103.092773 C 116.429199,103.092773 121.578613,108.241699 121.578613,114.592773 Z" Canvas.Top="-31.134" d:LayoutOverrides="Width, Height, GridBox" Canvas.Left="1"/>
<Path Fill="#ff000000" Data="F1 M 154.578613,114.592773 C 154.578613,120.943848 149.430176,126.092773 143.078613,126.092773 C 136.727051,126.092773 131.578613,120.943848 131.578613,114.592773 C 131.578613,108.241699 136.727051,103.092773 143.078613,103.092773 C 149.430176,103.092773 154.578613,108.241699 154.578613,114.592773 Z" Canvas.Left="31.333" Canvas.Top="-31.134" d:LayoutOverrides="Width, Height, GridBox"/>
</Canvas>
<!-- EOF Circle -->
</Grid>
</Page>

136
Utils.cs
Просмотреть файл

@ -1,67 +1,95 @@
using System;
using System.Windows.Media;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Markup;
using System.IO;
using System.Xml;
namespace BabySmash
{
class Utils
{
static Utils()
{
brushToString = new Dictionary<Brush, string> { { Brushes.Red, "Red" },
{ Brushes.Blue, "Blue" },
{ Brushes.Yellow, "Yellow" },
{ Brushes.Green, "Green" },
{ Brushes.Purple, "Purple" },
{ Brushes.Pink, "Pink" },
{ Brushes.Orange, "Orange" },
{ Brushes.Tan, "Tan" },
{ Brushes.Gray, "Gray" }
};
internal static class Utils
{
private static readonly Dictionary<Color, string> brushToString;
private static readonly Random lRandom = new Random();
private static readonly Color[] someColors;
someBrushes = new Brush[brushToString.Count];
brushToString.Keys.CopyTo(someBrushes, 0);
}
private static Brush[] someBrushes;
private static readonly string[] sounds = {
"giggle.wav",
"babylaugh.wav",
"babygigl2.wav",
"ccgiggle.wav",
"laughingmice.wav",
"scooby2.wav",
};
private static Dictionary<Brush, string> brushToString;
static Utils()
{
brushToString = new Dictionary<Color, string>
{
{Colors.Red, "Red"},
{Colors.Blue, "Blue"},
{Colors.Yellow, "Yellow"},
{Colors.Green, "Green"},
{Colors.Purple, "Purple"},
{Colors.Pink, "Pink"},
{Colors.Orange, "Orange"},
{Colors.Tan, "Tan"},
{Colors.Gray, "Gray"}
};
private static readonly string[] sounds = { "giggle.wav",
"babylaugh.wav",
"babygigl2.wav",
"ccgiggle.wav",
"laughingmice.wav",
"scooby2.wav",
};
someColors = new Color[brushToString.Count];
brushToString.Keys.CopyTo(someColors, 0);
}
public static Brush GetRandomColoredBrush()
{
Brush brush = someBrushes[lRandom.Next(0, someBrushes.Length)];
return brush;
}
public static Color GetRandomColor()
{
Color color = someColors[lRandom.Next(0, someColors.Length)];
return color;
}
public static string BrushToString(Brush b)
{
return brushToString[b];
}
public static Brush GetGradientBrush(Color color)
{
RadialGradientBrush myBrush = new RadialGradientBrush();
myBrush.GradientOrigin = new Point(0.75, 0.25);
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(-50), 0.0));
myBrush.GradientStops.Add(new GradientStop(color, 0.5));
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(50), 1.0));
return myBrush;
}
public static string GetRandomSoundFile()
{
string retVal = sounds[lRandom.Next(0, sounds.Length)];
return ".Resources.Sounds." + retVal;
}
public static bool GetRandomBoolean()
{
if (lRandom.Next(0, 2) == 0)
return false;
return true;
}
public static Color LightenOrDarken(this Color src, sbyte degree)
{
Color ret = new Color();
ret.A = src.A;
ret.R = (byte)Math.Max(Math.Min(src.R + degree, 255), 0);
ret.G = (byte)Math.Max(Math.Min(src.G + degree, 255), 0);
ret.B = (byte)Math.Max(Math.Min(src.B + degree, 255), 0);
return ret;
}
private static readonly Random lRandom = new Random();
public static int RandomBetweenTwoNumbers(int min, int max)
{
return lRandom.Next(min, max + 1);
}
}
}
public static string ColorToString(Color b)
{
return brushToString[b];
}
public static string GetRandomSoundFile()
{
string retVal = sounds[lRandom.Next(0, sounds.Length)];
return ".Resources.Sounds." + retVal;
}
public static bool GetRandomBoolean()
{
if (lRandom.Next(0, 2) == 0)
return false;
return true;
}
public static int RandomBetweenTwoNumbers(int min, int max)
{
return lRandom.Next(min, max + 1);
}
}
}

Просмотреть файл

@ -5,14 +5,30 @@
<section name="BabySmash.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<system.diagnostics>
<sources>
<source name="System.Windows.Data" switchName="SourceSwitch" >
<listeners>
<add name="default" />
</listeners>
</source>
</sources>
<switches>
<add name="SourceSwitch" value="All" />
</switches>
<sharedListeners>
<add name="default"
type="System.Diagnostics.DefaultTraceListener"
/>
</sharedListeners>
<trace autoflush="true" indentsize="4"></trace>
</system.diagnostics>
<userSettings>
<BabySmash.Properties.Settings>
<setting name="ForceUppercase" serializeAs="String">
<value>True</value>
</setting>
<setting name="Sounds" serializeAs="String">
<value>Laughter</value>
</setting>
<setting name="FadeAway" serializeAs="String">
<value>True</value>
</setting>
@ -20,11 +36,20 @@
<value>False</value>
</setting>
<setting name="ClearAfter" serializeAs="String">
<value>30</value>
<value>65</value>
</setting>
<setting name="MouseDraw" serializeAs="String">
<value>False</value>
</setting>
<setting name="FadeAfter" serializeAs="String">
<value>20</value>
</setting>
<setting name="FacesOnShapes" serializeAs="String">
<value>True</value>
</setting>
<setting name="Sounds" serializeAs="String">
<value>Speech</value>
</setting>
</BabySmash.Properties.Settings>
</userSettings>
</configuration>