// Select shapes inside the selection frame private bool PerformFrameSelection(IDiagramPresenter diagramPresenter, MouseState mouseState) { bool multiSelect = mouseState.IsKeyPressed(KeysDg.Control) || mouseState.IsKeyPressed(KeysDg.Shift); diagramPresenter.SelectShapes(frameRect, multiSelect); return true; }
private bool IsEditCaptionFeasible(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { if (shapeAtCursorInfo.IsEmpty || mouseState.IsEmpty) return false; if (!diagramPresenter.Project.SecurityManager.IsGranted(Permission.ModifyData, shapeAtCursorInfo.Shape)) return false; if (!shapeAtCursorInfo.IsCursorAtCaption) return false; if (mouseState.IsKeyPressed(KeysDg.Control) || mouseState.IsKeyPressed(KeysDg.Shift)) return false; return true; }
// (Un)Select shape unter the mouse pointer private bool PerformSelection(IDiagramPresenter diagramPresenter, MouseState mouseState, ShapeAtCursorInfo shapeAtCursorInfo) { bool result = false; bool multiSelect = mouseState.IsKeyPressed(KeysDg.Control) || mouseState.IsKeyPressed(KeysDg.Shift); // When selecting shapes conteolpoints should be ignored as the user does not see them // until a shape is selected const ControlPointCapabilities capabilities = ControlPointCapabilities.None; const int range = 0; // Determine the shape that has to be selected: Shape shapeToSelect = null; if (!selectedShapeAtCursorInfo.IsEmpty) { // When in multiSelection mode, unselect the selected shape under the cursor if (multiSelect) shapeToSelect = selectedShapeAtCursorInfo.Shape; else { // First, check if the selected shape under the cursor has children that can be selected shapeToSelect = selectedShapeAtCursorInfo.Shape.Children.FindShape(mouseState.X, mouseState.Y, capabilities, range, null); // Second, check if the selected shape under the cursor has siblings that can be selected if (shapeToSelect == null && selectedShapeAtCursorInfo.Shape.Parent != null) { shapeToSelect = selectedShapeAtCursorInfo.Shape.Parent.Children.FindShape(mouseState.X, mouseState.Y, capabilities, range, selectedShapeAtCursorInfo.Shape); // Discard found shape if it is the selected shape at cursor if (shapeToSelect == selectedShapeAtCursorInfo.Shape) shapeToSelect = null; if (shapeToSelect == null) { foreach ( Shape shape in selectedShapeAtCursorInfo.Shape.Parent.Children.FindShapes(mouseState.X, mouseState.Y, capabilities, range)) { if (shape == selectedShapeAtCursorInfo.Shape) continue; // Ignore layer visibility for child shapes shapeToSelect = shape; break; } } } } } // If there was a shape to select related to the selected shape under the cursor // (a child or a sibling of the selected shape or a shape below it), // try to select the first non-selected shape under the cursor if (shapeToSelect == null && shapeAtCursorInfo.Shape != null && shapeAtCursorInfo.Shape.ContainsPoint(mouseState.X, mouseState.Y)) shapeToSelect = shapeAtCursorInfo.Shape; // If a new shape to select was found, perform selection if (shapeToSelect != null) { // (check if multiselection mode is enabled (Shift + Click or Ctrl + Click)) if (multiSelect) { // if multiSelect is enabled, add/remove to/from selected selectedShapes... if (diagramPresenter.SelectedShapes.Contains(shapeToSelect)) { // if object is selected -> remove from selection diagramPresenter.UnselectShape(shapeToSelect); RemovePreviewOf(shapeToSelect); result = true; } else { // If object is not selected -> add to selection diagramPresenter.SelectShape(shapeToSelect, true); result = true; } } else { // ... otherwise deselect all selectedShapes but the clicked object ClearPreviews(); // check if the clicked shape is a child of an already selected shape Shape childShape = null; if (diagramPresenter.SelectedShapes.Count == 1 && diagramPresenter.SelectedShapes.TopMost.Children != null && diagramPresenter.SelectedShapes.TopMost.Children.Count > 0) { childShape = diagramPresenter.SelectedShapes.TopMost.Children.FindShape(mouseState.X, mouseState.Y, ControlPointCapabilities.None, 0, null); } diagramPresenter.SelectShape(childShape ?? shapeToSelect, false); result = true; } // validate if the desired shape or its parent was selected if (shapeToSelect.Parent != null) { if (!diagramPresenter.SelectedShapes.Contains(shapeToSelect)) if (diagramPresenter.SelectedShapes.Contains(shapeToSelect.Parent)) shapeToSelect = shapeToSelect.Parent; } } else if (selectedShapeAtCursorInfo.IsEmpty) { // if there was no other shape to select and none of the selected shapes is under the cursor, // clear selection if (!multiSelect) { if (diagramPresenter.SelectedShapes.Count > 0) { diagramPresenter.UnselectAll(); ClearPreviews(); result = true; } } } return result; }
private int AlignAngle(int angle, MouseState mouseState) { int result = angle; if (mouseState.IsKeyPressed(KeysDg.Control) && mouseState.IsKeyPressed(KeysDg.Shift)) { // rotate by tenths of degrees // do nothing } else if (mouseState.IsKeyPressed(KeysDg.Control)) { // rotate by full degrees result -= (result % 10); } else if (mouseState.IsKeyPressed(KeysDg.Shift)) { // rotate by 5 degrees result -= (result % 50); } else { // default: // rotate by 15 degrees result -= (result % 150); } return result; }