// Code to create and display objects goes here. public Window1() { InitializeComponent(); InitializeCommands(); // Now add some graphical items in the main drawing area, whose name is "Paper" gp = this.FindName("Paper") as GraphPaperAlt; // Track mouse activity in this window MouseLeftButtonDown += MyMouseButtonDown; MouseLeftButtonUp += MyMouseButtonUp; MouseMove += MyMouseMove; #region Triangles, segments, dots // A triangle, whose top point will be dragged by the slider. myTriangle = new Polygon(); myTriangle.Points.Add(new Point(0, 10)); myTriangle.Points.Add(new Point(10, 0)); myTriangle.Points.Add(new Point(0, -10)); myTriangle.Points.Add(new Point(-10, 0)); myTriangle.Stroke = Brushes.Black; myTriangle.StrokeThickness = 1; // 1 mm thick line myTriangle.Fill = Brushes.LightSeaGreen; gp.Children.Add(myTriangle); // A draggable Dot, which is the basepoint of an arrow. Dot dd = new Dot(new Point(-40, 60)); dd.MakeDraggable(gp); gp.Children.Add(dd); Circle cc = new Circle(20, 20, 20); // This circle wasn't included in the first testbed! gp.Children.Add(cc); Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END); gp.Children.Add(ee); // a dot and a segment that's attached to it; the dot is animated Dot p1 = new Dot(new Point(20, 20)); gp.Children.Add(p1); Point p2 = new Point(50, 50); Segment mySegment = new Segment(p1, p2); gp.Children.Add(mySegment); PointAnimation animaPoint1 = new PointAnimation( new Point(-20, -20), new Point(-40, 20), new Duration(new TimeSpan(0, 0, 5))); animaPoint1.AutoReverse = true; animaPoint1.RepeatBehavior = RepeatBehavior.Forever; p1.BeginAnimation(Dot.PositionProperty, animaPoint1); #endregion #region Images // And a photo from a file; note that because our Y-coordinate increases "up", // but WPF Y-coordinates increase "down", the photo shows up inverted. // We'll add a second photo, right-side-up, afterwards, and a third that's // created on-the-fly instead of read from a file. myImage1 = new GImage("foo.jpg"); myImage1.Width = GraphPaper.wpf(200); myImage1.Position = new Point(10, 40); gp.Children.Add(myImage1); // Create source // Now add a second image, based on first building an array of color values // Create source array byte[, ,] stripes = createStripeImageArray(); myImage2 = new GImage(stripes); // Establish the width and height for this image on the GraphPaper myImage2.Width = GraphPaper.wpf(128); myImage2.Height = GraphPaper.wpf(128); myImage2.Position = new Point(-40, 20); gp.Children.Add(myImage2); #endregion #region Mesh, Quiver, and Text labels myMesh = this.createSampleMesh(); gp.Children.Add(myMesh); Text myText = new Text("THIS IS TEXT", false); // the second arg says that y increases down myText.Position = new Point(20, 50); gp.Children.Add(myText); Text myText2 = new Text("THIS IS UPSIDE DOWN TEXT, because we didn't set the yUp flag to false"); myText2.Position = new Point(-20, -50); gp.Children.Add(myText2); myQuiver = makeQuiver(); foreach (Shape q in myQuiver) { gp.Children.Add(q); } #endregion ready = true; // Now we're ready to have sliders and buttons influence the display. }
// Code to create and display objects goes here. public Window1() { InitializeComponent(); InitializeCommands(); // Now add some graphical items in the main drawing area, whose name is "Paper" gp = this.FindName("Paper") as GraphPaper; // Track mouse activity in this window MouseLeftButtonDown += MyMouseButtonDown; MouseLeftButtonUp += MyMouseButtonUp; MouseMove += MyMouseMove; #region Triangles, segments, dots // A triangle, whose top point can be moved using the slider. myTriangle = new Polygon(); myTriangle.Points.Add(new Point(0, 10)); myTriangle.Points.Add(new Point(10, 0)); myTriangle.Points.Add(new Point(-10, 0)); myTriangle.Stroke = Brushes.Black; myTriangle.StrokeThickness = 1; // 1 mm thick line myTriangle.Fill = Brushes.LightSeaGreen; gp.Children.Add(myTriangle); // A draggable Dot, which is the basepoint of an arrow. Dot dd = new Dot(new Point(-40, 60)); dd.MakeDraggable(gp); gp.Children.Add(dd); Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END); gp.Children.Add(ee); // a dot and a segment that's attached to it; the dot is animated Dot p1 = new Dot(new Point(20, 20)); gp.Children.Add(p1); Point p2 = new Point(50, 50); Segment mySegment = new Segment(p1, p2); gp.Children.Add(mySegment); PointAnimation animaPoint1 = new PointAnimation( new Point(-20, -20), new Point(-40, 20), new Duration(new TimeSpan(0, 0, 5))); animaPoint1.AutoReverse = true; animaPoint1.RepeatBehavior = RepeatBehavior.Forever; p1.BeginAnimation(Dot.PositionProperty, animaPoint1); #endregion #region Images // And a photo from a file, then another that's // created on-the-fly instead of read from a file. myImage1 = new GImage("./foo.jpg"); myImage1.Width = GraphPaper.wpf(200); myImage1.Position = new Point(10, 40); Point pq = new Point(10, 40); gp.Children.Add(myImage1); // Now add a second image, based on first building an array of color values // Create source array byte[, ,] stripes = createStripeImageArray(); myImage2 = new GImage(stripes); // Establish the width and height for this image on the GraphPaper myImage2.Width = GraphPaper.wpf(128); myImage2.Height = GraphPaper.wpf(128); myImage2.Position = new Point(-40, 20); gp.Children.Add(myImage2); #endregion #region Mesh, Quiver, and Text labels myMesh = this.createSampleMesh(); gp.Children.Add(myMesh); Text myText = new Text("THIS IS TEXT"); myText.Position = new Point(20, 50); gp.Children.Add(myText); myQuiver = makeQuiver(); foreach (Shape q in myQuiver) { gp.Children.Add(q); } #endregion ready = true; // Now we're ready to have sliders and buttons influence the display. }