BiomePainter.BitmapSelector.BitmapSelector.Zoom C# (CSharp) Méthode

Zoom() public méthode

public Zoom ( int magnififcation, int offsetX, int offsetY, bool redraw = true ) : void
magnififcation int
offsetX int
offsetY int
redraw bool
Résultat void
        public void Zoom(int magnififcation, int offsetX, int offsetY, bool redraw = true)
        {
            Magnification = magnififcation;
            OffsetX = offsetX;
            OffsetY = offsetY;

            int scaledWidth = (int)Math.Round(((double)Width) / ((double)Magnification));
            int scaledHeight = (int)Math.Round(((double)Height) / ((double)Magnification));

            int scrollWidth = Magnification <= 1 ? 0 : (int)Math.Round(((double)scrollVertical.Width) / ((double)Magnification)); ;
            int scrollHeight = Magnification <= 1 ? 0 : (int)Math.Round(((double)scrollHorizontal.Height) / ((double)Magnification));

            //prevent scrolling past the end of the image
            if (OffsetX < 0)
                OffsetX = 0;
            if (Width - OffsetX < scaledWidth - scrollWidth)
                OffsetX = Width - scaledWidth + scrollWidth;
            if (OffsetY < 0)
                OffsetY = 0;
            if (Height - OffsetY < scaledHeight - scrollHeight)
                OffsetY = Height - scaledHeight + scrollHeight;

            if (Magnification <= 1)
            {
                scrollHorizontal.Visible = false;
                scrollVertical.Visible = false;
            }
            else
            {
                scrollHorizontal.Visible = true;
                scrollHorizontal.Value = OffsetX;
                scrollHorizontal.Maximum = Width - scaledWidth + scrollWidth + scrollHorizontal.LargeChange - 1;
                scrollVertical.Visible = true;
                scrollVertical.Value = OffsetY;
                scrollVertical.Maximum = Height - scaledHeight + scrollHeight + scrollVertical.LargeChange - 1;
            }

            if(redraw)
                Redraw();
            OnZoom(new ZoomEventArgs(Magnification, OffsetX, OffsetY));
        }