/// <summary> /// Handle Mouse Move event. Here we detect whether we've exceeded the _selectionThreshold /// and if so capture the mouse and create the visual zoom rectangle on the container object. /// </summary> /// <param name="sender">Mouse</param> /// <param name="e">Mouse move information.</param> void OnMouseMove(object sender, MouseEventArgs e) { if (_watching) { Point pos = e.GetPosition(_container); if (new Vector(_start.X - pos.X, _start.Y - pos.Y).Length > _selectionThreshold) { _watching = false; Mouse.Capture(_target, CaptureMode.SubTree); _selectionRectVisual = new SelectionRectVisual(_start, _start, _zoom.Zoom); _container.Children.Add(_selectionRectVisual); } } if (_selectionRectVisual != null) { if (_selectionRectVisual.Zoom != _zoom.Zoom) { _selectionRectVisual.Zoom = _zoom.Zoom; } _selectionRectVisual.SecondPoint = e.GetPosition(_container); } }
/// <summary> /// Handle the mouse left button up event. Here we actually process the selected rectangle /// if any by first raising an event for client to receive then also zooming to that rectangle /// if ZoomSelection is true /// </summary> /// <param name="sender">Mouse</param> /// <param name="e">Mouse button information</param> void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { _watching = false; if (_selectionRectVisual != null) { Mouse.Capture(_target, CaptureMode.None); Point pos = e.GetPosition(_container); double f = Math.Min(Math.Abs(pos.X - _mouseDownPoint.X), Math.Abs(pos.Y - _mouseDownPoint.Y)); Rect r = GetSelectionRect(pos); _selectionRect = r; if (Selected != null) { Selected(this, EventArgs.Empty); } if (_zoomSelection && f > _zoomSizeThreshold) { _zoom.ZoomToRect(r); } _container.Children.Remove(_selectionRectVisual); _selectionRectVisual = null; } }