本文整理汇总了C#中Shape.GetControlPointPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.GetControlPointPosition方法的具体用法?C# Shape.GetControlPointPosition怎么用?C# Shape.GetControlPointPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shape
的用法示例。
在下文中一共展示了Shape.GetControlPointPosition方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFrom
/// <override></override>
public override void CopyFrom(Shape source)
{
base.CopyFrom(source);
// Copy size if the source is a DiameterShape
if (source is DiameterShapeBase)
internalDiameter = ((DiameterShapeBase) source).DiameterInternal;
else {
// If not, try to calculate the size a good as possible
Rectangle srcBounds = Geometry.InvalidRectangle;
if (source is PathBasedPlanarShape) {
PathBasedPlanarShape src = (PathBasedPlanarShape) source;
// Calculate the bounds of the (unrotated) resize handles because with
// GetBoundingRectangle(), we receive the bounds including the children's bounds
List<Point> pointBuffer = new List<Point>();
int centerX = src.X;
int centerY = src.Y;
float angleDeg = Geometry.TenthsOfDegreeToDegrees(-src.Angle);
foreach (ControlPointId id in source.GetControlPointIds(ControlPointCapabilities.Resize))
pointBuffer.Add(Geometry.RotatePoint(centerX, centerY, angleDeg, source.GetControlPointPosition(id)));
Geometry.CalcBoundingRectangle(pointBuffer, out srcBounds);
}
else {
// Generic approach: try to fit into the bounding rectangle
srcBounds = source.GetBoundingRectangle(true);
}
//
// Calculate new size
if (Geometry.IsValid(srcBounds)) {
float scale = Geometry.CalcScaleFactor(DiameterInternal, DiameterInternal, srcBounds.Width, srcBounds.Height);
DiameterInternal = (int) Math.Round(DiameterInternal*scale);
}
}
}
示例2: PointPositions
public PointPositions(Shape shape, Shape owner)
: this() {
if (shape == null) throw new ArgumentNullException("shape");
if (owner == null) throw new ArgumentNullException("owner");
// First, store position of reference point
RelativePosition relativePos = RelativePosition.Empty;
relativePos = owner.CalculateRelativePosition(shape.X, shape.Y);
Debug.Assert(relativePos != RelativePosition.Empty);
items.Add(ControlPointId.Reference, relativePos);
// Then, store all resize control point positions as relative position
foreach (ControlPointId ptId in shape.GetControlPointIds(ControlPointCapabilities.Resize)) {
Point p = shape.GetControlPointPosition(ptId);
relativePos = owner.CalculateRelativePosition(p.X, p.Y);
Debug.Assert(relativePos != RelativePosition.Empty);
items.Add(ptId, relativePos);
}
}
示例3: CopyFrom
/// <override></override>
public override void CopyFrom(Shape source)
{
base.CopyFrom(source);
if (source is RectangleBase) {
size.Width = ((RectangleBase) source).Width;
size.Height = ((RectangleBase) source).Height;
}
else {
// If not, try to calculate the size a good as possible
Rectangle srcBounds = Geometry.InvalidRectangle;
if (source is PathBasedPlanarShape) {
PathBasedPlanarShape src = (PathBasedPlanarShape) source;
// Calculate the bounds of the (unrotated) resize handles because with
// GetBoundingRectangle(), we receive the bounds including the children's bounds
List<Point> pointBuffer = new List<Point>();
int centerX = src.X;
int centerY = src.Y;
float angleDeg = Geometry.TenthsOfDegreeToDegrees(-src.Angle);
foreach (ControlPointId id in source.GetControlPointIds(ControlPointCapabilities.Resize))
pointBuffer.Add(Geometry.RotatePoint(centerX, centerY, angleDeg, source.GetControlPointPosition(id)));
Geometry.CalcBoundingRectangle(pointBuffer, out srcBounds);
}
else {
// Generic approach: try to fit into the bounding rectangle
srcBounds = source.GetBoundingRectangle(true);
}
if (Geometry.IsValid(srcBounds))
size = srcBounds.Size;
}
}
示例4: FindNearestSnapPoint
/// <summary>
/// Finds the nearest SnapPoint in range of the given shape's control point.
/// </summary>
/// <param name="diagramPresenter">The <see cref="T:Dataweb.NShape.Controllers.IDiagramPresenter" /></param>
/// <param name="shape">The shape for which the nearest snap point is searched.</param>
/// <param name="controlPointId">The control point of the shape.</param>
/// <param name="pointOffsetX">Declares the distance, the shape is moved on X axis before finding snap point.</param>
/// <param name="pointOffsetY">Declares the distance, the shape is moved on X axis before finding snap point.</param>
/// <param name="snapDeltaX">Horizontal distance between ptX and the nearest snap point.</param>
/// <param name="snapDeltaY">Vertical distance between ptY and the nearest snap point.</param>
/// <returns>Distance to nearest snap point.</returns>
protected float FindNearestSnapPoint(IDiagramPresenter diagramPresenter, Shape shape, ControlPointId controlPointId,
int pointOffsetX, int pointOffsetY, out int snapDeltaX, out int snapDeltaY) {
if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter");
if (shape == null) throw new ArgumentNullException("shape");
snapDeltaX = snapDeltaY = 0;
Point p = shape.GetControlPointPosition(controlPointId);
return FindNearestSnapPoint(diagramPresenter, p.X + pointOffsetX, p.Y + pointOffsetY, out snapDeltaX, out snapDeltaY);
}
示例5: FindNearestControlPoint
/// <summary>
/// Finds the nearest ControlPoint in range of the given shape's ControlPoint.
/// If there is no ControlPoint in range, the snap distance to the nearest grid line will be calculated.
/// </summary>
/// <param name="diagramPresenter">The <see cref="T:Dataweb.NShape.Controllers.IDiagramPresenter" /></param>
/// <param name="shape">The given shape.</param>
/// <param name="controlPointId">the given shape's ControlPoint</param>
/// <param name="targetPointCapabilities">Capabilities of the control point to find.</param>
/// <param name="pointOffsetX">Declares the distance, the shape is moved on X axis before finding snap point.</param>
/// <param name="pointOffsetY">Declares the distance, the shape is moved on X axis before finding snap point.</param>
/// <param name="snapDeltaX">Horizontal distance between ptX and the nearest snap point.</param>
/// <param name="snapDeltaY">Vertical distance between ptY and the nearest snap point.</param>
/// <param name="resultPointId">The Id of the returned shape's nearest ControlPoint.</param>
/// <returns>The shape owning the found <see cref="T:Dataweb.NShape.Advanced.ControlPointId" />.</returns>
protected Shape FindNearestControlPoint(IDiagramPresenter diagramPresenter, Shape shape, ControlPointId controlPointId,
ControlPointCapabilities targetPointCapabilities, int pointOffsetX, int pointOffsetY,
out int snapDeltaX, out int snapDeltaY, out ControlPointId resultPointId) {
if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter");
if (shape == null) throw new ArgumentNullException("shape");
Shape result = null;
snapDeltaX = snapDeltaY = 0;
resultPointId = ControlPointId.None;
if (diagramPresenter.Diagram != null) {
// calculate new position of the ControlPoint
Point ctrlPtPos = shape.GetControlPointPosition(controlPointId);
ctrlPtPos.Offset(pointOffsetX, pointOffsetY);
int snapDistance = diagramPresenter.SnapDistance;
int resultZOrder = int.MinValue;
IEnumerable<Shape> foundShapes = FindVisibleShapes(diagramPresenter, ctrlPtPos.X, ctrlPtPos.Y, ControlPointCapabilities.Connect, snapDistance);
foreach (Shape foundShape in foundShapes) {
if (foundShape == shape) continue;
//
// Find the nearest control point
float distance, lowestDistance = float.MaxValue;
ControlPointId foundPtId = foundShape.FindNearestControlPoint(
ctrlPtPos.X, ctrlPtPos.Y, snapDistance, targetPointCapabilities);
//
// Skip shapes without matching control points or below the last matching shape
if (foundPtId == ControlPointId.None) continue;
if (foundShape.ZOrder < resultZOrder) continue;
//
// If a valid control point was found, check wether it matches the criteria
if (foundPtId != ControlPointId.Reference) {
// If the shape itself is hit, do not calculate the snap distance because snapping
// to "real" control point has a higher priority.
// Set TargetPointId and result shape in order to skip snapping to gridlines
Point targetPtPos = foundShape.GetControlPointPosition(foundPtId);
distance = Geometry.DistancePointPoint(ctrlPtPos.X, ctrlPtPos.Y, targetPtPos.X, targetPtPos.Y);
if (distance <= snapDistance && distance < lowestDistance) {
lowestDistance = distance;
snapDeltaX = targetPtPos.X - ctrlPtPos.X;
snapDeltaY = targetPtPos.Y - ctrlPtPos.Y;
} else continue;
}
resultZOrder = foundShape.ZOrder;
resultPointId = foundPtId;
result = foundShape;
}
// calcualte distance to nearest grid point if there is no suitable control point in range
if (resultPointId == ControlPointId.None)
FindNearestSnapPoint(diagramPresenter, ctrlPtPos.X, ctrlPtPos.Y, out snapDeltaX, out snapDeltaY);
else if (result != null && resultPointId == ControlPointId.Reference) {
// ToDo: Calculate snap distance if the current mouse position outside the shape's outline
if (result.ContainsPoint(ctrlPtPos.X, ctrlPtPos.Y)) {
}
}
}
return result;
}
示例6: IsGripHit
/// <summary>
/// Indicates wether a grip was hit
/// </summary>
protected bool IsGripHit(IDiagramPresenter diagramPresenter, Shape shape, ControlPointId controlPointId, int x, int y) {
if (shape == null) throw new ArgumentNullException("shape");
Point p = shape.GetControlPointPosition(controlPointId);
return IsGripHit(diagramPresenter, p.X, p.Y, x, y);
}
示例7: CanConnectTo
/// <summary>
/// Indicates wether the given shape can connect to the given targetShape with the specified glue point.
/// </summary>
protected bool CanConnectTo(IDiagramPresenter diagramPresenter, Shape shape, ControlPointId unmovedGluePoint, ControlPointId movedControlPoint, bool onlyUnselected) {
if (shape is ILinearShape && ((ILinearShape)shape).VertexCount == 2) {
Point posA = shape.GetControlPointPosition(unmovedGluePoint);
Point posB = shape.GetControlPointPosition(movedControlPoint);
ShapeAtCursorInfo shapeInfoA = FindShapeAtCursor(diagramPresenter, posA.X, posA.Y, ControlPointCapabilities.All, diagramPresenter.ZoomedGripSize, onlyUnselected);
ShapeAtCursorInfo shapeInfoB = FindShapeAtCursor(diagramPresenter, posB.X, posB.Y, ControlPointCapabilities.All, diagramPresenter.ZoomedGripSize, onlyUnselected);
if (!shapeInfoA.IsEmpty
&& shapeInfoA.Shape == shapeInfoB.Shape
&& (shapeInfoA.ControlPointId == ControlPointId.Reference
|| shapeInfoB.ControlPointId == ControlPointId.Reference))
return false;
}
return true;
}
示例8: CalcGluePoint
/// <override></override>
protected override Point CalcGluePoint(ControlPointId gluePointId, Shape shape) {
InvalidateDrawCache();
// Get current position of the GluePoint and the new position of the GluePoint
Point result = Geometry.InvalidPoint;
ControlPointId pointId = IsConnected(gluePointId, shape);
if (pointId == ControlPointId.Reference)
result = shape.CalculateAbsolutePosition(calcInfo.RelativePosition);
else result = shape.GetControlPointPosition(pointId);
Debug.Assert(Geometry.IsValid(result));
return result;
}
示例9: FollowConnectionPointWithGluePoint
/// <override></override>
public override void FollowConnectionPointWithGluePoint(ControlPointId gluePointId, Shape connectedShape, ControlPointId movedPointId) {
if (connectedShape == null) throw new ArgumentNullException("connectedShape");
try {
followingConnectedShape = true;
Point currGluePtPos = gluePointPos;
Point newGluePtPos = Geometry.InvalidPoint;
// If the connection is a point-to-shape connection, the shape calculates the new glue point position
// with the help of the connected shape.
if (movedPointId == ControlPointId.Reference)
newGluePtPos = CalcGluePoint(gluePointId, connectedShape);
else newGluePtPos = connectedShape.GetControlPointPosition(movedPointId);
// Ensure that the glue point is moved to a valid coordinate
if (!Geometry.IsValid(newGluePtPos)) {
//System.Diagnostics.Debug.Fail("Invalid glue point position");
newGluePtPos = currGluePtPos;
}
// Calculate new target outline intersection point along with old and new anchor point position
int shapeAngle;
if (connectedShape is ILinearShape) {
Point normalVector = ((ILinearShape)connectedShape).CalcNormalVector(newGluePtPos);
shapeAngle = Geometry.RadiansToTenthsOfDegree(Geometry.Angle(newGluePtPos.X, newGluePtPos.Y, normalVector.X, normalVector.Y)) - 900;
} else if (connectedShape is IPlanarShape) {
shapeAngle = ((IPlanarShape)connectedShape).Angle;
} else shapeAngle = 0; // There is no way to get an angle from a generic shape
// Move the glue point to the new position
int dx, dy;
dx = newGluePtPos.X - currGluePtPos.X;
dy = newGluePtPos.Y - currGluePtPos.Y;
// Calculate new position of the GlueLabel (calculation method depends on the desired behavior)
Point newCenter = Point.Round(Geometry.CalcPoint(newGluePtPos.X, newGluePtPos.Y, calcInfo.Alpha + Geometry.TenthsOfDegreeToDegrees(shapeAngle), calcInfo.Distance));
// Move GlueLabel and update GluePointPos
MoveTo(newCenter.X, newCenter.Y);
this.gluePointPos = newGluePtPos;
// Rotate shape if MaintainOrientation is set to false
if (!maintainOrientation) {
int newAngle = this.calcInfo.LabelAngle + shapeAngle;
if (Angle != newAngle) Angle = newAngle;
}
} finally { followingConnectedShape = false; }
}
示例10: MoveShapeControlPoint
private void MoveShapeControlPoint(Shape shape, ControlPointId pointId, int deltaX, int deltaY, ResizeModifiers modifiers)
{
Point origPointPos = shape.GetControlPointPosition(pointId);
Point p = origPointPos, ptPos = origPointPos;
// Move point to new position
if (shape.MoveControlPointBy(pointId, deltaX, deltaY, modifiers)) {
p.Offset(deltaX, deltaY);
ptPos = shape.GetControlPointPosition(pointId);
Assert.IsTrue(Math.Abs(p.X - ptPos.X) <= 1);
Assert.IsTrue(Math.Abs(p.Y - ptPos.Y) <= 1);
if (shape.MoveControlPointBy(pointId, -deltaX, -deltaY, modifiers)) {
p.Offset(-deltaX,-deltaY);
ptPos = shape.GetControlPointPosition(pointId);
Assert.IsTrue(Math.Abs(p.X - ptPos.X) <= 1);
Assert.IsTrue(Math.Abs(p.Y - ptPos.Y) <= 1);
}
}
// Move point back to original position
if (shape.MoveControlPointTo(pointId, origPointPos.X, origPointPos.Y, modifiers))
Assert.AreEqual(origPointPos, shape.GetControlPointPosition(pointId));
//ptPos = shape.GetControlPointPosition(pointId);
//Assert.IsTrue(Math.Abs(origPointPos.X - ptPos.X) <= 1);
//Assert.IsTrue(Math.Abs(origPointPos.Y - ptPos.Y) <= 1);
}