ZoomViaMouse
(
MouseEventArgs e,
Double dGraphZoomFactor
)
{
Debug.Assert(e != null);
Debug.Assert(dGraphZoomFactor > 0);
AssertValid();
// Do nothing if the drawing isn't in a stable state or a drag is in
// progress.
if ( this.IsLayingOutGraph || DragMightBeInProgress() )
{
return;
}
Double dGraphZoom = this.GraphZoom;
Double dNewGraphZoom = dGraphZoom * dGraphZoomFactor;
dNewGraphZoom = Math.Min(dNewGraphZoom, MaximumGraphZoom);
dNewGraphZoom = Math.Max(dNewGraphZoom, MinimumGraphZoom);
if (dNewGraphZoom == dGraphZoom)
{
return;
}
// Set the center of the zoom to the mouse position. Note that the
// mouse position is affected by the ScaleTransform used for this
// control's layout transform and needs to be adjusted for this.
Point oMousePosition = e.GetPosition(this);
ScaleTransform oScaleTransformForRender = this.ScaleTransformForRender;
oScaleTransformForRender.CenterX = oMousePosition.X;
oScaleTransformForRender.CenterY = oMousePosition.Y;
// Zoom the graph.
SetGraphZoom(dNewGraphZoom, false);
// That caused the point under the mouse to shift. Adjust the
// translation to shift the point back.
Point oNewMousePosition = e.GetPosition(this);
TranslateTransform oTranslateTransformForRender =
this.TranslateTransformForRender;
oTranslateTransformForRender.X +=
(oNewMousePosition.X - oMousePosition.X) * dNewGraphZoom;
oTranslateTransformForRender.Y +=
(oNewMousePosition.Y - oMousePosition.Y) * dNewGraphZoom;
LimitTranslation();
}