/// <summary> /// Called when the mouse pressed on the zoom/pan selection canvas. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param> protected virtual void OnSelectionCanvasMouseDown(object sender, MouseButtonEventArgs e) { Mouse.Capture(_selection_canvas); _selection_start_point = e.GetPosition(_selection_canvas); _current_mouse_position = _selection_start_point; _last_mouse_position = _current_mouse_position; if (e.ClickCount == 2) { _zoom_rect = new System.Drawing.RectangleF(); _is_scaled = false; ZoomRectChanged?.Invoke(this, new EventArgs()); } else if (Keyboard.IsKeyDown(Key.LeftCtrl)) { _selection_rectangle.Width = 0; _selection_rectangle.Height = 0; _is_selection_mouse_down_zoom = true; _is_selection_mouse_down_pan = false; _selection_rectangle.Visibility = Visibility.Visible; } else { _is_selection_mouse_down_pan = true; } }
/// <summary> /// Called when the mouse released from the zoom/pan selection canvas. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The event arguments.</param> protected virtual void OnSelectionCanvasPointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { _selection_canvas.ReleasePointerCapture(e.Pointer); if (_is_selection_mouse_down_pan) { _is_selection_mouse_down_pan = false; } else if (_is_selection_mouse_down_zoom) { _is_selection_mouse_down_zoom = false; _zoom_rect = new System.Drawing.RectangleF((float)Canvas.GetLeft(_selection_rectangle), (float)Canvas.GetTop(_selection_rectangle), (float)_selection_rectangle.Width, (float)_selection_rectangle.Height); _selection_rectangle.Visibility = Visibility.Collapsed; _is_scaled = true; ZoomRectChanged?.Invoke(this, new EventArgs()); } }
/// <summary> /// Called when the mouse released from the zoom/pan selection canvas. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param> protected virtual void OnSelectionCanvasMouseUp(object sender, MouseButtonEventArgs e) { _selection_canvas.ReleaseMouseCapture(); if (_is_selection_mouse_down_pan) { _is_selection_mouse_down_pan = false; } else if (_is_selection_mouse_down_zoom) { _is_selection_mouse_down_zoom = false; _zoom_rect = new System.Drawing.RectangleF((float)Canvas.GetLeft(_selection_rectangle), (float)Canvas.GetTop(_selection_rectangle), (float)_selection_rectangle.Width, (float)_selection_rectangle.Height); _selection_rectangle.Visibility = Visibility.Hidden; _is_scaled = true; ZoomRectChanged?.Invoke(this, new EventArgs()); } }
/// <summary> /// Handles the On Selection Canvas Double Tapped event. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The event arguments.</param> protected virtual void OnSelectionCanvasDoubleTapped(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e) { _zoom_rect = new System.Drawing.RectangleF(); _is_scaled = false; ZoomRectChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// Called when the mouse moves over the zoom/pan selection canvas. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The event arguments.</param> protected virtual void OnSelectionCanvasPointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { _current_mouse_position = e.GetCurrentPoint(_selection_canvas).Position; if (_is_selection_mouse_down_zoom && IsCtrlDown()) { Canvas.SetLeft(_selection_rectangle, _selection_start_point.X); Canvas.SetTop(_selection_rectangle, _selection_start_point.Y); Point _selection_current_point = _current_mouse_position; if (_selection_current_point.X - _selection_start_point.X > 1) { _selection_rectangle.Width = _selection_current_point.X - _selection_start_point.X; } if (_selection_current_point.Y - _selection_start_point.Y > 1) { _selection_rectangle.Height = _selection_current_point.Y - _selection_start_point.Y; } if (_selection_current_point.X < _selection_start_point.X) { Canvas.SetLeft(_selection_rectangle, _selection_current_point.X); _selection_rectangle.Width = _selection_start_point.X - _selection_current_point.X; } if (_selection_current_point.Y < _selection_start_point.Y) { Canvas.SetTop(_selection_rectangle, _selection_current_point.Y); _selection_rectangle.Height = _selection_start_point.Y - _selection_current_point.Y; } } else if (_is_selection_mouse_down_pan && _is_scaled) { Point _selection_current_point = _current_mouse_position; double delta_x = _current_mouse_position.X - _last_mouse_position.X; double delta_y = _current_mouse_position.Y - _last_mouse_position.Y; double x = _zoom_rect.Left - delta_x; double y = _zoom_rect.Top - delta_y; if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x + _zoom_rect.Width > _size.Width) { x = x - (x + _zoom_rect.Width - _size.Width); } if (y + _zoom_rect.Height > _size.Height) { y = y - (y + _zoom_rect.Height - _size.Height); } _zoom_rect = new System.Drawing.RectangleF((float)x, (float)y, _zoom_rect.Width, _zoom_rect.Height); ZoomRectChanged?.Invoke(this, new EventArgs()); } _last_mouse_position = _current_mouse_position; }
/// <summary> /// Called when the mouse moves over the zoom/pan selection canvas. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param> protected virtual void OnSelectionCanvasMouseMove(object sender, MouseEventArgs e) { _current_mouse_position = e.GetPosition(_selection_canvas); if (_is_selection_mouse_down_zoom && Keyboard.IsKeyDown(Key.LeftCtrl)) { Canvas.SetLeft(_selection_rectangle, _selection_start_point.X); Canvas.SetTop(_selection_rectangle, _selection_start_point.Y); Point _selection_current_point = e.GetPosition(_selection_canvas); if (_selection_current_point.X - _selection_start_point.X > 1) { _selection_rectangle.Width = _selection_current_point.X - _selection_start_point.X; } if (_selection_current_point.Y - _selection_start_point.Y > 1) { _selection_rectangle.Height = _selection_current_point.Y - _selection_start_point.Y; } if (_selection_current_point.X < _selection_start_point.X) { Canvas.SetLeft(_selection_rectangle, _selection_current_point.X); _selection_rectangle.Width = _selection_start_point.X - _selection_current_point.X; } if (_selection_current_point.Y < _selection_start_point.Y) { Canvas.SetTop(_selection_rectangle, _selection_current_point.Y); _selection_rectangle.Height = _selection_start_point.Y - _selection_current_point.Y; } } else if (_is_selection_mouse_down_pan && _is_scaled) { Point _selection_current_point = e.GetPosition(_selection_canvas); double delta_x = _current_mouse_position.X - _last_mouse_position.X; double delta_y = _current_mouse_position.Y - _last_mouse_position.Y; double x = _zoom_rect.Left - delta_x; double y = _zoom_rect.Top - delta_y; if (x < 0) { x = 0; } if (y < 0) { y = 0; } if (x + _zoom_rect.Width > _size.Width) { x = x - (x + _zoom_rect.Width - _size.Width); } if (y + _zoom_rect.Height > _size.Height) { y = y - (y + _zoom_rect.Height - _size.Height); } _zoom_rect = new System.Drawing.RectangleF((float)x, (float)y, _zoom_rect.Width, _zoom_rect.Height); ZoomRectChanged?.Invoke(this, new EventArgs()); } _last_mouse_position = _current_mouse_position; OnApplyToolTip(_last_mouse_position); }