/// <summary> /// Sets the transformation needed to draw the model on the canvas when /// the diagram needs to fit the screen. /// </summary> /// <param name="screenBounds">the bounding box of the draw area</param> /// <param name="modelBounds">the bounding box of the model</param> /// <param name="reset">if true, model center will be set to the modelBounds center and the scale will be re-calculated</param> protected internal virtual void SetupTransformToFit(Rect screenBounds, Rect modelBounds, bool reset) { var scale = rendererModel.GetScale(); if (screenBounds == null) { return; } SetDrawCenter(screenBounds.X + screenBounds.Width / 2, screenBounds.Y + screenBounds.Height / 2); var drawWidth = screenBounds.Width; var drawHeight = screenBounds.Height; var diagramWidth = modelBounds.Width * scale; var diagramHeight = modelBounds.Height * scale; SetZoomToFit(drawWidth, drawHeight, diagramWidth, diagramHeight); // this controls whether editing a molecule causes it to re-center // with each change or not if (reset || rendererModel.GetFitToScreen()) { SetModelCenter(modelBounds.X + modelBounds.Width / 2, modelBounds.Y + modelBounds.Height / 2); } Setup(); }