QSWidgetLib.ImageViewer.OnSizeAllocated C# (CSharp) Method

OnSizeAllocated() protected method

protected OnSizeAllocated ( Gdk allocation ) : void
allocation Gdk
return void
        protected override void OnSizeAllocated(Gdk.Rectangle allocation)
        {
            base.OnSizeAllocated (allocation);
            logger.Debug("Allocate w={0}, h={1}", allocation.Width, allocation.Height) ;

            if (_pixbuf == null)
                return;
            double vratio = _VerticalFit ? (double)allocation.Height / _pixbuf.Height : 1;
            double hratio = _HorizontalFit ? (double)allocation.Width / _pixbuf.Width : 1;
            int Heigth, Width;
            if(vratio < hratio)
            {
                Heigth = allocation.Height;
                Width = Convert.ToInt32(_pixbuf.Width * vratio);
            }
            else
            {
                Heigth = Convert.ToInt32(_pixbuf.Height * hratio);
                Width = allocation.Width;
            }

            if(ResizedPixbuf == null || ResizedPixbuf.Width != Width || ResizedPixbuf.Height != Heigth)
                ResizedPixbuf = _pixbuf.ScaleSimple (Width,
                    Heigth,
                    InterpType.Nearest);
            int ReqHeigth = _VerticalFit ? 1 : Heigth;
            int ReqWidth = _HorizontalFit ? 1 : Width;

            if (ReqWidth != WidthRequest || ReqHeigth != HeightRequest)
                SetSizeRequest(ReqWidth, ReqHeigth);
        }