本文整理汇总了C#中Shape.GetBoundingRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.GetBoundingRectangle方法的具体用法?C# Shape.GetBoundingRectangle怎么用?C# Shape.GetBoundingRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shape
的用法示例。
在下文中一共展示了Shape.GetBoundingRectangle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShapeInfoDialog
/// <summary>
/// Displays a dialog showing various information on the given shape:
/// Template, shape type, shape library and the shape's control points including their capabilities and connected shapes.
/// </summary>
public ShapeInfoDialog(Project project, Shape shape)
{
if (project == null) throw new ArgumentNullException("project");
if (shape == null) throw new ArgumentNullException("shape");
InitializeComponent();
this.project = project;
Rectangle shapeBounds = shape.GetBoundingRectangle(false);
this.shape = shape;
this.shapeClone = shape.Clone();
this.shapeClone.Fit(0, 0, shapeBounds.Width, shapeBounds.Height);
this.diagram.Size = shapeBounds.Size;
this.diagram.Shapes.Add(shapeClone);
diagramSetController.Project = project;
display.DrawDiagramSheet = false;
display.Diagram = diagram;
display.ShowGrid = false;
display.GripSize = 5;
display.HighQualityRendering = true;
display.RenderingQualityHighQuality = RenderingQuality.MaximumQuality;
display.CurrentTool = tool;
UpdateShapeInfo();
}
示例2: 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);
}
}
}
示例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: CheckOwnerboundsUpdateNeeded
private void CheckOwnerboundsUpdateNeeded(Shape shape)
{
if (!ownerBoundsUpdateNeeded) {
Rectangle shapeBounds = shape.GetBoundingRectangle(true);
if (shapeBounds.Left < 0 || owner.Width < shapeBounds.Right
|| shapeBounds.Top < 0 || owner.Height < shapeBounds.Bottom)
ownerBoundsUpdateNeeded = true;
}
}
示例5: FindNearestSnapPoint
/// <summary>
/// Finds the nearest SnapPoint in range of the given shape.
/// </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="shapeOffsetX">Declares the distance, the shape is moved on X axis before finding snap point.</param>
/// <param name="shapeOffsetY">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 the calculated snap point.</returns>
protected float FindNearestSnapPoint(IDiagramPresenter diagramPresenter, Shape shape, int shapeOffsetX, int shapeOffsetY,
out int snapDeltaX, out int snapDeltaY) {
if (diagramPresenter == null) throw new ArgumentNullException("diagramPresenter");
if (shape == null) throw new ArgumentNullException("shape");
snapDeltaX = snapDeltaY = 0;
int snapDistance = diagramPresenter.SnapDistance;
float lowestDistance = float.MaxValue;
Rectangle shapeBounds = shape.GetBoundingRectangle(true);
shapeBounds.Offset(shapeOffsetX, shapeOffsetY);
int boundsCenterX = (int)Math.Round(shapeBounds.X + shapeBounds.Width / 2f);
int boundsCenterY = (int)Math.Round(shapeBounds.Y + shapeBounds.Width / 2f);
int dx, dy;
float currDistance;
// Calculate snap distance of center point
currDistance = FindNearestSnapPoint(diagramPresenter, boundsCenterX, boundsCenterY, out dx, out dy);
if (currDistance < lowestDistance && currDistance >= 0 && currDistance <= snapDistance) {
lowestDistance = currDistance;
snapDeltaX = dx;
snapDeltaY = dy;
}
// Calculate snap distance of bounding rectangle
currDistance = FindNearestSnapPoint(diagramPresenter, shapeBounds.Left, shapeBounds.Top, out dx, out dy);
if (currDistance < lowestDistance && currDistance >= 0 && currDistance <= snapDistance) {
lowestDistance = currDistance;
snapDeltaX = dx;
snapDeltaY = dy;
}
currDistance = FindNearestSnapPoint(diagramPresenter, shapeBounds.Right, shapeBounds.Top, out dx, out dy);
if (currDistance < lowestDistance && currDistance >= 0 && currDistance <= snapDistance) {
lowestDistance = currDistance;
snapDeltaX = dx;
snapDeltaY = dy;
}
currDistance = FindNearestSnapPoint(diagramPresenter, shapeBounds.Left, shapeBounds.Bottom, out dx, out dy);
if (currDistance < lowestDistance && currDistance >= 0 && currDistance <= snapDistance) {
lowestDistance = currDistance;
snapDeltaX = dx;
snapDeltaY = dy;
}
currDistance = FindNearestSnapPoint(diagramPresenter, shapeBounds.Right, shapeBounds.Bottom, out dx, out dy);
if (currDistance < lowestDistance && currDistance >= 0 && currDistance <= snapDistance) {
lowestDistance = currDistance;
snapDeltaX = dx;
snapDeltaY = dy;
}
return lowestDistance;
}
示例6: CopyFrom
/// <override></override>
public override void CopyFrom(Shape source)
{
base.CopyFrom(source);
if (source is IPlanarShape) {
IPlanarShape src = (IPlanarShape) source;
// Copy regular properties
this.angle = src.Angle;
// Copy templated properties
this.fillStyle = (Template != null && src.FillStyle == ((IPlanarShape) Template.Shape).FillStyle)
? null
: src.FillStyle;
}
if (source is ICaptionedShape) {
// Copy as many captions as possible. Leave the rest untouched.
int ownCaptionCnt = CaptionCount;
int srcCaptionCnt = ((ICaptionedShape) source).CaptionCount;
int cnt = Math.Min(ownCaptionCnt, srcCaptionCnt);
for (int i = 0; i < cnt; ++i) {
this.SetCaptionText(i, ((ICaptionedShape) source).GetCaptionText(i));
this.SetCaptionCharacterStyle(i, ((ICaptionedShape) source).GetCaptionCharacterStyle(i));
this.SetCaptionParagraphStyle(i, ((ICaptionedShape) source).GetCaptionParagraphStyle(i));
}
}
if (source is ImageBasedShape) {
w = ((ImageBasedShape) source).w;
h = ((ImageBasedShape) source).h;
if (((ImageBasedShape) source).image != null)
image = (Image) ((ImageBasedShape) source).image.Clone();
}
else {
Rectangle r = source.GetBoundingRectangle(true);
Fit(r.X, r.Y, r.Width, r.Height);
}
}