public void InitSample() { for (int i = 0; i < 4; i++) { var p = Polygon.GetSampleSquare(); p.Move(new Point(i * 50, i * 50)); polygons.Add(p); } }
private void Canvas_MouseDown(object sender, MouseEventArgs e) { //handle add sample if (mouseState == MouseState.PutingSample) { var polygon = Polygon.GetSampleSquare(); polygon.Move(e.Location); polygons.Add(polygon); OnStructureChanged?.Invoke(this, polygon); Update(); mouseState = MouseState.Normal; return; } if (currentStructure == null) { return; } //handle add if (mouseState == MouseState.Drawing) { if (!(currentStructure is Polygon)) { return; } var polygon = currentStructure as Polygon; var result = polygon.AddVertex(e.Location); OnStructureChanged?.Invoke(this, polygon); if (result == Polygon.AddVertexResult.Closed) { mouseState = MouseState.Normal; } Update(); return; } //handle dragging previousMousePosition = e.Location; if (currentStructure.HitTest(e.Location)) { if (mouseState == MouseState.Normal) { mouseState = MouseState.Dragging; } } }