2005-07-07, 09:41 PM
just tested zooming out and it will also work if with a slightly change in the code
Code:
double leftpos = current.X; //only first time when zoom is 1
double toppos = current.Y; //only first time when zoom is 1
double leftoff = (-1 * current.X) - leftpos;
double topoff = (-1 * current.Y) - toppos;
double oldWidth = current.Width;
double oldHeight = current.Height;
current.Width = current.OriginalWidth * current.Zoom;
current.Height = current.OriginalHeight * current.Zoom;
if (oldWidth <= ScreenWidth)
{
current.X -= ((current.Width - oldWidth) / 2);
}
else
{
current.X = (-1 * leftoff * current.Zoom / oldZoom) - (((ScreenWidth * current.Zoom / oldZoom) - ScreenWidth) / 2);
if (current.X > 0)
{
current.X = current.X * -1;
}
else
{
current.X -= leftpos;
}
}
if (oldHeight <= ScreenHeight)
{
current.Y -= ((current.Height - oldHeight) / 2);
}
else
{
current.Y = (-1 * topoff * current.Zoom / oldZoom) - (((ScreenHeight * current.Zoom / oldZoom) - ScreenHeight) / 2);
if (current.Y > 0)
{
current.Y = current.Y * -1;
}
else
{
current.Y -= toppos;
}
}