/// <summary> /// Initializes a new instance of Arrow with a Point as start point and a /// Dot as end-point, and arrowheads where specified by the /// endtypes parameter. /// </summary> /// <param name="sp">The starting point</param> /// <param name="ep">The ending point</param> /// <param name="endtypes">endtype constant saying which end(s) should have arrowhead(s)</param> public Arrow(Point sp, Dot ep, endtype endtypes) { constructionHelper4(sp, ep, endtypes); }
// 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(-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. }
/// <summary> /// Initializes a new instance of Arrow with a Dot as start point and a /// Point as end-point, and arrowheads where specified by the /// endtypes parameter. /// </summary> /// <param name="sp">The starting point</param> /// <param name="ep">The ending point</param> /// <param name="endtypes">endtype constant saying which end(s) should have arrowhead(s)</param> public Arrow(Dot sp, Point ep, endtype endtypes) { constructionHelper3(sp, ep, endtypes); }
/// <summary> /// Initializes a new instance of Arrow with a Point as start point and a /// Dot as end-point. /// </summary> /// <param name="sp">The starting point</param> /// <param name="ep">The ending point</param> public Arrow(Point sp, Dot ep) { constructionHelper4(sp, ep, endtype.START); }
/// <summary> /// Build an arrow using a Dot (manipulable) as starting point, and a Point as ending point /// /// </summary> /// <param name="sp">The start of the arrow</param> /// <param name="ep">The end of the arrow</param> public Arrow(Dot sp, Point ep) { constructionHelper3(sp, ep, endtype.END); }
/// <summary> /// Initializes a new instance of Arrow with specified Dots as start /// and end-points, and arrowheads where specified by the /// endtypes parameter. /// </summary> /// <param name="sp">The starting point</param> /// <param name="ep">The ending point</param> /// <param name="endtypes">endtype constant saying which end(s) should have arrowhead(s)</param> public Arrow(Dot sp, Dot ep, endtype endtypes) { constructionHelper2(sp, ep, endtypes); }
/// <summary> /// Build an arrow using Dots (manipulable) as starting and ending points /// /// </summary> /// <param name="sp">The start of the arrow</param> /// <param name="ep">The end of the arrow</param> public Arrow(Dot sp, Dot ep) { constructionHelper2(sp, ep, endtype.END); }
public void MyMouseButtonDown(object sender, RoutedEventArgs e) { if (sender != this) { return; } if (ready) { System.Windows.Input.MouseButtonEventArgs ee = (System.Windows.Input.MouseButtonEventArgs)e; Debug.Print("MouseDown at " + ee.GetPosition(this)); Point clickPoint = ee.GetPosition(gp); if (lastKey == Key.LeftShift || lastKey == Key.RightShift) { Dot dot = NearestDot(clickPoint); if (dot != null) { if (startingVertex != null) { startingVertex.Stroke = Brushes.Transparent; } startingVertex = dot; startingVertex.Stroke = Brushes.Red; lastKey = Key.None; } } else if (lastKey == Key.LeftCtrl || lastKey == Key.RightCtrl) { Dot dot = NearestDot(clickPoint); if (dot != null) { int idx = myDots.IndexOf(dot); if (!myTriangle.Contains(idx)) { myTriangle.Add(idx); dot.Stroke = Brushes.Blue; if (myTriangle.Count == 3) { myTriangle.Sort(); Polygon polygon; if (myTriangles.TryGetValue(new Tuple <int, int, int>(myTriangle[0], myTriangle[1], myTriangle[2]), out polygon)) { gp.Children.Remove(polygon); myTriangles.Remove(new Tuple <int, int, int>(myTriangle[0], myTriangle[1], myTriangle[2])); } else { polygon = new Polygon(); foreach (int i in myTriangle) { polygon.Points.Add(myDots[i].Position); } polygon.Stroke = Brushes.Black; polygon.StrokeThickness = 0.25; gp.Children.Add(polygon); myTriangles.Add(new Tuple <int, int, int>(myTriangle[0], myTriangle[1], myTriangle[2]), polygon); } foreach (int i in myTriangle) { myDots[i].Stroke = Brushes.Transparent; } myTriangle = new List <int>(); } lastKey = Key.None; } } } else { if (startingVertex == null) { AddDot(new Dot(clickPoint)); } else { Dot dot = NearestDot(clickPoint); if (!dot.IsMouseOver) { dot = new Dot(clickPoint); AddDot(dot); } if (dot != startingVertex) { AddEdge(dot); } startingVertex.Stroke = Brushes.Transparent; startingVertex = null; } } } e.Handled = true; }
protected void AddDot(Dot dot) { myDots.Add(dot); myDots[myDots.Count - 1].Stroke = Brushes.Transparent; gp.Children.Add(myDots[myDots.Count - 1]); }