protected override void CalculatePreTransform(Matrix cumulativeTransform)
{
if (_imagePosterior != null)
{
// when the posterior edge of the image can be determined,
// apply an offset in addition to user-applied translations
// this allows the image to appear initially at (and reset to)
// a position where the posterior ("chest wall") is aligned
// against an edge of the client rectangle.
// compute the posterior vector according to the adjusted parameters
var destPosteriorVector = GetCurrentPosteriorVector(_imagePosterior, SourceWidth, AdjustedSourceHeight, RotationXY, ScaleX, ScaleY, FlipX, FlipY);
// check if posterior direction is along client X axis
if (Math.Abs(destPosteriorVector.X) > Math.Abs(destPosteriorVector.Y))
{
// compute additional horizontal translation to align posterior edge of image with client bounds
cumulativeTransform.Translate(Math.Sign(destPosteriorVector.X)*((ClientRectangle.Width - Math.Abs(destPosteriorVector.X))/2f), 0);
}
else
{
// compute additional vertical translation to align posterior edge of image with client bounds
cumulativeTransform.Translate(0, Math.Sign(destPosteriorVector.Y)*((ClientRectangle.Height - Math.Abs(destPosteriorVector.Y))/2f));
}
}
base.CalculatePreTransform(cumulativeTransform);
}