/// <summary> /// Centres the given node in the view. /// </summary> /// <param name="node">The node which will be centred.</param> internal void CenterNode(NodeViewData node) { _maintainNodePosition = node; // we use the existing maintain position stuff for that RectangleF bbox = node.IsFSM ? node.GetTotalBoundingBox() : node.BoundingBox; float width = bbox.Width <= 0.0f ? node.MinWidth : bbox.Width; float height = bbox.Height <= 0.0f ? node.MinHeight : bbox.Height; // Scale the whole graph to the suitable size in the view. float viewWidth = ClientSize.Width - 30; float viewHeight = ClientSize.Height - 30; bool isWidthScale = false; if (viewWidth > 0 && viewHeight > 0) { SizeF totalSize = node.GetTotalSize(_nodeLayoutManager.Padding.Width, int.MaxValue); float scale = 1.0f; if (totalSize.Width / totalSize.Height < viewWidth / viewHeight) { scale = viewHeight / totalSize.Height; isWidthScale = false; } else { scale = viewWidth / totalSize.Width; isWidthScale = true; } const float MinScale = 0.1f; const float MaxScale = 2.0f; if (scale < MinScale) { _nodeLayoutManager.Scale = MinScale; } else if (scale > MaxScale) { _nodeLayoutManager.Scale = MaxScale; } else { _nodeLayoutManager.Scale = scale; } } if (node.IsFSM) { if (isWidthScale) _graphOrigin = new PointF(0.0f, ClientSize.Height * 0.5f - height * 0.5f * _nodeLayoutManager.Scale); else _graphOrigin = new PointF(ClientSize.Width * 0.5f - width * 0.5f * _nodeLayoutManager.Scale, 0.0f); } else { _graphOrigin = new PointF(20.0f, ClientSize.Height * 0.5f - height * 0.5f); } Invalidate(); }
/// <summary> /// Centres the given node in the view. /// </summary> /// <param name="node">The node which will be centred.</param> internal void CenterNode(NodeViewData node) { _maintainNodePosition = node; // we use the existing maintain position stuff for that RectangleF bbox = node.BoundingBox; // if the node was not yet shown there is no bounding box so we simply use the min height for that float height = bbox.Height <= 0.0f ? node.MinHeight : bbox.Height; _graphOrigin = new PointF(20.0f, ClientSize.Height * 0.5f - height * 0.5f); // Scale the whole graph to the suitable size in the view. float viewWidth = ClientSize.Width - 30; float viewHeight = ClientSize.Height - 30; if (viewWidth > 0 && viewHeight > 0) { SizeF totalSize = node.GetTotalSize(_nodeLayoutManager.Padding.Width, int.MaxValue); float scale = 1.0f; if (totalSize.Width / totalSize.Height < viewWidth / viewHeight) scale = viewHeight / totalSize.Height; else scale = viewWidth / totalSize.Width; const float MinScale = 0.1f; const float MaxScale = 2.0f; if (scale < MinScale) _nodeLayoutManager.Scale = MinScale; else if (scale > MaxScale) _nodeLayoutManager.Scale = MaxScale; else _nodeLayoutManager.Scale = scale; } Invalidate(); }