public MainWindow() { InitializeComponent(); this.WindowState = WindowState.Maximized; this.Title = "Logo"; this.Loaded += (o, e) => { this.Top = 0; this.Left = 0; this.Width = 800; this.Height = 800; try { //there are a lot of quotes in XAML //and the C# string requires quotes to be doubled var strxaml = @" <Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" Name=""HwndTest"" Margin=""5,5,5,5""> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition Height=""25""></RowDefinition> </Grid.RowDefinitions> <DockPanel Grid.Row=""0""> <UserControl Name=""MyUserControl""></UserControl> </DockPanel> <DockPanel Grid.Row=""1""> <TextBox Name=""tbxStatus"" HorizontalAlignment=""Left"" Height=""23"" Margin=""10,2,0,0"" IsReadOnly=""True"" TextWrapping=""Wrap"" VerticalAlignment=""Top"" Width=""120""/> <TextBox Name=""tbxCmdList"" HorizontalAlignment=""Left"" Height=""23"" Margin=""10,2,0,0"" TextWrapping=""Wrap"" VerticalAlignment=""Top"" Width=""320""/> <Slider Name=""sldPenWidth"" HorizontalAlignment=""Left"" Margin=""12,2,0,0"" VerticalAlignment=""Top"" Width=""100"" ToolTip=""Change the pen width"" /> <Slider Name=""sldDelay"" HorizontalAlignment=""Left"" Margin=""12,2,0,0"" VerticalAlignment=""Top"" ToolTip=""Change the delay"" Width=""100""/> <Button Name=""btnQuit"" Content=""_Quit"" HorizontalAlignment=""Left"" Margin=""10,2,0,0"" VerticalAlignment=""Top"" Width=""55""/> </DockPanel> </Grid> "; var strReader = new System.IO.StringReader(strxaml); var xamlreader = XmlReader.Create(strReader); var grid = (Grid)(System.Windows.Markup.XamlReader.Load(xamlreader)); var btnQuit = (Button)grid.FindName("btnQuit"); btnQuit.Click += (ob, eb) => { App.Current.Shutdown(); }; _tbxCmdList = (TextBox)grid.FindName("tbxCmdList"); _tbxStatus = (TextBox)grid.FindName("tbxStatus"); var userCtrl = (UserControl)grid.FindName("MyUserControl"); var bgd = NativeMethods.CreateSolidBrush(new IntPtr(0xffffff)); _logoControl = new LogoControl(bgd, this); userCtrl.Content = _logoControl; userCtrl.Focusable = true; userCtrl.IsTabStop = true; this.Content = grid; var sldPenWidth = (Slider)grid.FindName("sldPenWidth"); sldPenWidth.Minimum = 0; sldPenWidth.Maximum = 400; sldPenWidth.ValueChanged += (os, es) => { _logoControl._Turtle.SetPenWidth((int)sldPenWidth.Value); }; var sldDelay = (Slider)grid.FindName("sldDelay"); sldDelay.Minimum = 0; sldDelay.Maximum = 100000; sldDelay.ValueChanged += (os, es) => { _logoControl._Delay = (int)sldDelay.Value; }; this.TextInput += (ot, et) => { _logoControl.GotTextInput(et); }; userCtrl.KeyUp += (ok, ek) => { _logoControl.OnKey(ek); }; this.SizeChanged += (os, es) => { _logoControl.OnSizeChanged(); }; btnQuit.ToolTip = @"Logo Program by Calvin Hsia Logo Drawing Program by Calvin Hsia based on Seymour Papert's Logo f = Move Forward the Stepsize (*) r = turn Right l = turn Left p = Pen Up (off the paper) or down h = Hide turtle e = Erase and start over (prerecorded programs survive) + = Increase the turtle's step size for Forward - = Decrease the step size a = Increase the angle for left/right . = Repeat current command indefinitely q = Quit out of program c = Change Color (*) InputValue d = Delay (*) n = Number for User Parameter. Used for 'x' s = Store (*) cmd. Inputvalue indicates which storage cell (1-9) x = Execute stored program (*) User parameter times [0-9] = input integer into Input value (defaults to 1) [any char] while executing will stop turtle * = command will use the Input value for parameter "; } catch (Exception ex) { this.Content = ex.ToString(); } }; }
public Turtle(LogoControl logoControl) { _logoControl = logoControl; _colorTurtle = NativeMethods.CreatePen(0, 0, (IntPtr)0x8f00); InitVals(); }