private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { double height = MainImage.Height; double width = MainImage.Width; Point mouse = e.GetPosition(MainImage); actheight = MainImage.ActualHeight; actwidth = MainImage.ActualWidth; mouse.X = (mouse.X / actwidth) * 1067; mouse.Y = (mouse.Y / actheight) * 657; Console.WriteLine("height: " + height + " width: " + width + " actual height: " + actheight + " actual width: " + actwidth); double wbmp = wbmap.Width; double hbmp = wbmap.Height; Console.WriteLine("bitmap height: " + hbmp + "bitmap width: " + wbmp); Console.WriteLine("x: " + mouse.X + " y: " + mouse.Y); // double wdiff = 1067 - actwidth; // double hdiff = 657 - actheight; Console.WriteLine("x: " + mouse.X + " y: " + mouse.Y); if (!polygonFinished && polygonStarted) { Vertex v = new Vertex(wbmap.DrawBresenhamCircle((int)mouse.X, (int)mouse.Y, 6), mouse); if (!IsDrawing) { vm.Start = mouse; IsDrawing = true; } else { if (vm.Polygon.IsStartPoint(mouse)) { polygonFinished = true; IsDrawing = false; wbmap.WritePixels(new Int32Rect(0, 0, wbmap.PixelWidth, wbmap.PixelHeight), vm.BitmapArraySource, wbmap.BackBufferStride, 0); line = wbmap.DrawBresenhamLine((int)vm.NewLine.X, (int)vm.NewLine.Y, (int)vm.Polygon.Lines[0].Vertices[0].GetX(), (int)vm.Polygon.Lines[0].Vertices[0].GetY(), Colors.Black); } vm.Polygon.AddLine(new Line(Vertex.GetVertexFromMiddlePoint(line[0], 6), Vertex.GetVertexFromMiddlePoint(line[1], 6))); } vm.NewLine = mouse; wbmap.CopyPixels(vm.BitmapArraySource, wbmap.BackBufferStride, 0); } else { if (vm.IsPointInPolygonVertices(mouse)) { vm.DraggedVertex = vm.Polygon.GetVertexFromPoint(mouse); vm.Adjacent = vm.Polygon.GetAdjacentLines(mouse); VertexDrag = true; } else if (vm.IsPointInPolygonLines(mouse)) { PolygonDrag = true; vm.Waypoint = mouse; } } }
public void DrawPolygon(WriteableBitmap wbm, Polygon polygon, Color color) { foreach (Edge e in polygon.Edges) { wbm.DrawBresenhamLine((int)e.Vertices[0].GetX(), (int)e.Vertices[0].GetY(), (int)e.Vertices[1].GetX(), (int)e.Vertices[1].GetY(), color); wbm.DrawBresenhamCircle((int)e.Vertices[0].GetX(), (int)e.Vertices[0].GetY(), 6); } }
public void DrawPolygon(WriteableBitmap wbm, Polygon polygon) { polygon.RecalculatePolygon(); foreach (var label in LineLabels) { label.UpdateLabel(); } foreach (Line l in polygon.Lines) { wbm.DrawBresenhamLine((int)l.Vertices[0].GetX(), (int)l.Vertices[0].GetY(), (int)l.Vertices[1].GetX(), (int)l.Vertices[1].GetY(), Colors.Black); wbm.DrawBresenhamCircle((int)l.Vertices[0].GetX(), (int)l.Vertices[0].GetY(), 6); } }