private void Fit(D2dAdaptableControl control, RectangleF gBounds) { if (m_currentGraphBounds.IsEmpty) { return; } var targetXform = control.As <ITransformAdapter>(); var crect = control.ClientRectangle; crect.Inflate(-12, -12); // 8 pixels margin. if (crect.Width < 1 || crect.Height < 1) { return; } float sx = MathUtil.Clamp(crect.Width / gBounds.Width, targetXform.MinScale.X, targetXform.MaxScale.X); float sy = MathUtil.Clamp(crect.Height / gBounds.Height, targetXform.MinScale.Y, targetXform.MaxScale.Y); float scale = Math.Min(sx, sy); crect.X += (int)(crect.Width - gBounds.Width * scale) / 2; crect.Y += (int)(crect.Height - gBounds.Height * scale) / 2; float tx = crect.X - gBounds.X * scale; float ty = crect.Y - gBounds.Y * scale; targetXform.SetTransform(scale, scale, tx, ty); control.Invalidate(); }
private void UpdateControl(D2dAdaptableControl source, D2dAdaptableControl target, Point cpt) { target.Context = source.Context; if (target.Context == null) { return; } // transform current mouse point to graph space. var srcXform = source.As <ITransformAdapter>(); Matrix3x2F mtrx = Matrix3x2F.Invert(srcXform.Transform); var gpt = Matrix3x2F.TransformPoint(mtrx, cpt); var targetXform = target.As <ITransformAdapter>(); var csz = target.ClientSize; PointF translation = new PointF(csz.Width / 2 - gpt.X * targetXform.Scale.X, csz.Height / 2 - gpt.Y * targetXform.Scale.Y); targetXform.Translation = translation; var edgeEditor = source.As <D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin> >(); m_activeEdgeEditor = (edgeEditor != null && edgeEditor.IsDraggingEdge) ? edgeEditor : null; target.Invalidate(); }