public override void CanvasTool_MouseDown(object sender, MouseEventArgs e) { if (_canvas == null || CurrentLayer() == null || !CurrentLayer().IsLine) { return; } if (WorkStopped()) { return; } OECPVertex vtx = new OECPVertex(e.Location.X, e.Location.Y); if (IsWaiting()) { if (e.Button != MouseButtons.Left) { return; } SetBusy(); var st = _canvas.C2I(vtx); _ptCollection.Add(st); _canvas.VertexLayer().AddElement(st); _canvas.RepaintCanvas(); return; } if (IsWorking()) { SetWaiting(); _canvas.FreezeRightClickMenu(true); if (e.Button == MouseButtons.Left) { var edPt = _canvas.C2I(vtx); _ptCollection.Add(edPt); _canvas.VertexLayer().AddElements(_ptCollection); var line = new OECPLine(_ptCollection[0], _ptCollection[1]); CurrentLayer().AddElement(line); _ptCollection.Clear(); _canvas.RepaintCanvas(); } if (e.Button == MouseButtons.Right) { var vtxLayer = _canvas.VertexLayer(); if (vtxLayer == null) { return; } vtx = _ptCollection[0]; vtxLayer.DeleteVertex(vtx); _ptCollection.Clear(); _canvas.RepaintCanvas(); } } }
bool VertexAtBoundary(OECPVertex vtx, RectangleF square) { var leftLine = new OECPLine(new OECPVertex(square.Left, square.Top), new OECPVertex(square.Left, square.Bottom), true); var rightLine = new OECPLine(new OECPVertex(square.Right, square.Top), new OECPVertex(square.Right, square.Bottom), true); var topLine = new OECPLine(new OECPVertex(square.Left, square.Top), new OECPVertex(square.Right, square.Top), true); var botLine = new OECPLine(new OECPVertex(square.Left, square.Bottom), new OECPVertex(square.Right, square.Bottom), true); bool onLeft = leftLine.VertexOnLine(vtx); if (onLeft) { _projVtx = leftLine.GetProjectVertex(vtx); return(true); } bool onRight = rightLine.VertexOnLine(vtx); if (onRight) { _projVtx = rightLine.GetProjectVertex(vtx); return(true); } bool onTop = topLine.VertexOnLine(vtx); if (onTop) { _projVtx = topLine.GetProjectVertex(vtx); return(true); } bool onBot = botLine.VertexOnLine(vtx); if (onBot) { _projVtx = botLine.GetProjectVertex(vtx); return(true); } return(false); }