void _viewer_MouseUp(object sender, MouseEventArgs e) { LeadPoint pixels = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y)); LeadRect imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight); if (imageBounds.Contains(pixels)) { if (e.Button == MouseButtons.Left) { _movingPntIdx = -1; } } }
void _viewer_MouseDown(object sender, MouseEventArgs e) { LeadPoint pixels = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y)); LeadRect imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight); if (imageBounds.Contains(pixels)) { if (e.Button == MouseButtons.Left) { double xFactor = 1; double yFactor = 1; int xOffset = 0; int yOffset = 0; Point pnt = new Point((int)Math.Ceiling(((pixels.X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((pixels.Y - yOffset) * 1.0 / yFactor + 0.5))); _movingPntIdx = -1; if (!_drawing) { Rectangle[] hyberAreas = new Rectangle[_unWarpPoints.Count]; for (int idx = 0; idx < hyberAreas.Length; idx++) { hyberAreas[idx] = CreateRectFromPoint(_unWarpPoints[idx], 20); if (hyberAreas[idx].Contains(pnt)) { _movingPntIdx = idx; break; } } } if (_movingPntIdx == -1) { if (_unWarpPoints.Count < 4) { if (pnt.Equals(_lastPoint)) { return; } _firstPointSelected = true; _unWarpPoints.Add(pnt); _currentMousePoint = pnt; UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); _lastPoint = pnt; } if (_unWarpPoints.Count == 4) { for (int ii = 1; ii <= 2; ii++) { pnt.X = (_unWarpPoints[1].X - _unWarpPoints[0].X) * ii / 3 + _unWarpPoints[0].X; pnt.Y = (_unWarpPoints[1].Y - _unWarpPoints[0].Y) * ii / 3 + _unWarpPoints[0].Y; _currentMousePoint = pnt; _unWarpPoints.Add(pnt); Invalidate(); UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); } for (int ii = 1; ii <= 2; ii++) { pnt.X = (_unWarpPoints[2].X - _unWarpPoints[3].X) * ii / 3 + _unWarpPoints[3].X; pnt.Y = (_unWarpPoints[2].Y - _unWarpPoints[3].Y) * ii / 3 + _unWarpPoints[3].Y; _unWarpPoints.Add(pnt); Invalidate(); UpdateDialogPoints(_unWarpPoints.Count - 1, pnt); } _drawing = false; _viewer.Invalidate(); _btnApply.Enabled = true; } } } } }