本文整理汇总了C#中IDiagramPresenter.UnselectAll方法的典型用法代码示例。如果您正苦于以下问题:C# IDiagramPresenter.UnselectAll方法的具体用法?C# IDiagramPresenter.UnselectAll怎么用?C# IDiagramPresenter.UnselectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDiagramPresenter
的用法示例。
在下文中一共展示了IDiagramPresenter.UnselectAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformSelection
// (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;
//.........这里部分代码省略.........
示例2: ProcessMouseClick
private bool ProcessMouseClick(IDiagramPresenter diagramPresenter, MouseState mouseState) {
Debug.Print("ProcessMouseClick");
bool result = false;
switch (CurrentAction) {
case Action.None:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
if (diagramPresenter.SelectedShapes.Count > 0)
diagramPresenter.UnselectAll();
ShapeAtCursorInfo targetShapeInfo = FindShapeAtCursor(diagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Glue, diagramPresenter.ZoomedGripSize, false);
if (IsExtendLineFeasible(CurrentAction, targetShapeInfo.Shape, targetShapeInfo.ControlPointId)) {
if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Layout, targetShapeInfo.Shape)) {
ExtendLine(diagramPresenter, mouseState, targetShapeInfo);
result = true;
}
} else {
// If no other ToolAction is in Progress (e.g. drawing a line or moving a point),
// a normal MouseClick starts a new line in Point-By-Point mode
if (diagramPresenter.Project.SecurityManager.IsGranted(Permission.Insert, Template.Shape)) {
CreateLine(diagramPresenter, mouseState);
result = true;
}
}
} else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
Cancel();
result = true;
}
break;
case Action.CreateLine:
case Action.ExtendLine:
if (mouseState.IsButtonDown(MouseButtonsDg.Left)) {
Invalidate(ActionDiagramPresenter);
bool doFinishLine = false;
// If the line has reached the MaxVertexCount limit, create it
if (PreviewLinearShape.VertexCount >= PreviewLinearShape.MaxVertexCount)
doFinishLine = true;
else {
// Check if it has to be connected to a shape or connection point
ShapeAtCursorInfo shapeAtCursorInfo = base.FindShapeAtCursor(ActionDiagramPresenter, mouseState.X, mouseState.Y, ControlPointCapabilities.Connect, diagramPresenter.ZoomedGripSize, false);
if (!shapeAtCursorInfo.IsEmpty && !shapeAtCursorInfo.IsCursorAtGluePoint)
doFinishLine = true;
else AddNewPoint(ActionDiagramPresenter, mouseState);
}
// Create line if necessary
if (doFinishLine) {
if (CurrentAction == Action.CreateLine)
FinishLine(ActionDiagramPresenter, mouseState, false);
else FinishExtendLine(ActionDiagramPresenter, mouseState, false);
while (IsToolActionPending)
EndToolAction();
OnToolExecuted(ExecutedEventArgs);
}
} else if (mouseState.IsButtonDown(MouseButtonsDg.Right)) {
#if DEBUG_DIAGNOSTICS
Assert(PreviewShape != null);
#endif
// When creating a line, the new line has to have more than the minimum number of
// vertices because the last vertex (sticking to the mouse cursor) will not be created.
if (CurrentAction == Action.CreateLine) {
if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount)
Cancel();
else FinishLine(ActionDiagramPresenter, mouseState, true);
} else {
// When extending a line, the new line has to have more than the minimum number of
// vertices and more than the original line because the last vertex will not be created.
if (PreviewLinearShape.VertexCount <= PreviewLinearShape.MinVertexCount
|| PreviewLinearShape.VertexCount - 1 == modifiedLinearShape.VertexCount)
Cancel();
else FinishExtendLine(ActionDiagramPresenter, mouseState, true);
}
while (IsToolActionPending)
EndToolAction();
OnToolExecuted(ExecutedEventArgs);
}
result = true;
break;
default: throw new NShapeUnsupportedValueException(CurrentAction);
}
Invalidate(diagramPresenter);
return result;
}