public void OnMouseDown(MouseEventArgs e) { // get the world point of the mouse hit Coordinates worldPoint = drawingSurface.Transform.GetWorldPoint(e.Location); // do a hit test // calculate hit tolerance in world units double tolerance = MapSettings.PixelHitTolerance / drawingSurface.Transform.Scale; // check for only selectable objects HitTestResult hitResult = drawingSurface.HitTest(worldPoint, tolerance, HitTestFilters.SelectableOnly); if (hitResult.Hit) { // we had a hit // NOTE: we could add dragging support here // check if the selected object has changed object selected = drawingSurface.SelectedObject = (ISelectable)hitResult.Target; // check if the selected object is IInteract if (selected is IMouseInteract) { ((IMouseInteract)selected).OnMouseDown(new MouseEvent(worldPoint, e.Clicks, e.Button)); } } else { // there was no hit // deselect the old object if one was selected drawingSurface.SelectedObject = null; // do a screen drag if this is a left mouse click if (e.Button == MouseButtons.Left) { dragHelper = new DragScreenHelper(drawingSurface, worldPoint); } } }
public void OnMouseDown(MouseEventArgs e) { // get the world point of the mouse hit Coordinates worldPoint = drawingSurface.Transform.GetWorldPoint(e.Location); if (e.Button != MouseButtons.Left) { return; } // check if the control key is down if ((Control.ModifierKeys & Keys.Control) != Keys.None) { // user wants to do a drag dragHelper = new DragScreenHelper(drawingSurface, worldPoint); } else if ((Control.ModifierKeys & Keys.Shift) != Keys.None) { // do a hit test to get a snap point // calculate hit tolerance in world units double tolerance = MapSettings.PixelHitTolerance / drawingSurface.Transform.Scale; // check for only selectable objects HitTestResult hitResult = drawingSurface.HitTest(worldPoint, tolerance, HitTestFilters.HasSnap); if (hitResult.Hit) { // we have a snap point if (inRuler) { endPoint = hitResult.SnapPoint; } else { endPoint = startPoint = hitResult.SnapPoint; } } else { // no snap point if (inRuler) { endPoint = worldPoint; } else { endPoint = startPoint = worldPoint; } } inRuler = true; } else { if (inRuler) { endPoint = worldPoint; } else { endPoint = startPoint = worldPoint; } inRuler = true; } }