当前位置: 首页>>代码示例>>C#>>正文


C# Shape.GetControlPointPosition方法代码示例

本文整理汇总了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);
				}
			}
		}
开发者ID:stewmc,项目名称:vixen,代码行数:34,代码来源:DiameterShape.cs

示例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);
				}
			}
开发者ID:jestonitiro,项目名称:nshape,代码行数:17,代码来源:ShapeAggregation.cs

示例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;
			}
		}
开发者ID:stewmc,项目名称:vixen,代码行数:31,代码来源:RectangleShape.cs

示例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);
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:20,代码来源:Tool.cs

示例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;
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:73,代码来源:Tool.cs

示例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);
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:8,代码来源:Tool.cs

示例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;
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:17,代码来源:Tool.cs

示例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;
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:12,代码来源:TextShape.cs

示例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; }
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:45,代码来源:TextShape.cs

示例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);
        }
开发者ID:LudovicT,项目名称:NShape,代码行数:25,代码来源:DiagramBaseTest.cs


注:本文中的Shape.GetControlPointPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。