private void SetSizeInternal(float width, float height, RectangleF internalRectangle) { if (StencilItem != null && StencilItem.Redraw) { SetPath(StencilItem.Draw(width, height), internalRectangle); } else { float scaleX = Convert.ToSingle(width / Rectangle.Width); float scaleY = Convert.ToSingle(height / Rectangle.Height); ScalePath(scaleX, scaleY, 0, 0, internalRectangle); } }
private void SetSizeInternal(float width, float height) { if (StencilItem != null && StencilItem.Redraw) { SetPath(StencilItem.Draw(width, height), StencilItem.InternalRectangle(width, height)); } else { float scaleX = Convert.ToSingle(width / Rectangle.Width); float scaleY = Convert.ToSingle(height / Rectangle.Height); //Scale rectangle RectangleF original = InternalRectangle; RectangleF rect = new RectangleF(original.X * scaleX, original.Y * scaleY, original.Width * scaleX, original.Height * scaleY); ScalePath(scaleX, scaleY, 0, 0, rect); } }
//Scale a shape using ratios private void ScaleShape(float sx, float sy, float dx, float dy, bool maintainAspect) { //Check min and max sizes if (!KeepAspect || Width >= Height) { if (MaximumSize.Width < (Bounds.Width * sx)) { sx = Convert.ToSingle(MaximumSize.Width / Bounds.Width); } if (MinimumSize.Width > (Bounds.Width * sx)) { sx = Convert.ToSingle(MinimumSize.Width / Bounds.Width); } } if (!KeepAspect || Height >= Width) { if (MaximumSize.Height < (Bounds.Height * sy)) { sy = Convert.ToSingle(MaximumSize.Height / Bounds.Height); } if (MinimumSize.Height > (Bounds.Height * sy)) { sy = Convert.ToSingle(MinimumSize.Height / Bounds.Height); } } if (maintainAspect) { if (sx < sy) { sy = sx; } else { sx = sy; } } //Get the new size float width = Width * sx; float height = Height * sy; if (StencilItem != null && StencilItem.Redraw) { SetPath(StencilItem.Draw(width, height), StencilItem.InternalRectangle(width, height)); SetRectangle(new PointF(Location.X + dx, Location.Y + dy)); } else { if (StencilItem == null) { RectangleF original = InternalRectangle; RectangleF rect = new RectangleF(original.X * sx, original.Y * sy, original.Width * sx, original.Height * sy); ScalePath(sx, sy, dx, dy, rect); } else { ScalePath(sx, sy, dx, dy, StencilItem.InternalRectangle(width, height)); } } //Offset the ports before the new rectangle is updated ScalePorts(sx, sy, dx, dy); CreateHandles(); }