Bubbles3/Controls/BblImageSurface.cs
/// <summary>
/// calculate the transformations needed so that the viewport coincides with the
/// provided ivp.
/// </summary>
/// <param name="ivp">the view to restore</param>
/// <param name="widthSignificant">if true the width of the ivp will come into account for the restoration of the view</param>
/// <param name="centered">if true the origin of the restoration will be the center of the ivp, not the tl corner</param>
calculate the transformations needed so that the viewport coincides with the
provided ivp.
calculate the transformations needed so that the viewport coincides with the provided ivp .
protected void IvpToTransform(ImageViewingParams ivp, bool widthSignificant, bool centered, out Matrix3x2 rotateM, out Matrix3x2 scaleM, out Matrix3x2 translateM)
        {
            rotateM = Matrix3x2.Rotation((float)(ivp.rotation * deg2rad), ImgCenter);
            float clientRatio = (float)ClientSize.Width / (float)ClientSize.Height;
            float ivpRatio = ivp.rect.Width / ivp.rect.Height;
            float zf = 0;
            if ((!widthSignificant || ivpRatio < clientRatio) && ivp.rect.Height != 0)
            {
                float scaley = (float)ClientSize.Height / (float)ImgSize.Height;
                float oldscaley = ivp.rect.Height;
                float zfy = scaley / oldscaley;
                zf = zfy;
            }
            else if (widthSignificant && ivpRatio > clientRatio && ivp.rect.Width != 0)
            {
                float scalex = (float)ClientSize.Width / (float)ImgSize.Width;
                float oldscalex = ivp.rect.Width;
                float zfx = scalex / oldscalex;
                zf = zfx;
            }
            else
            {
                if (P.keepZoom) zf = _lastzf;
                else zf = 1;
            }
            scaleM = Matrix3x2.Scaling(zf, zf, Vector2.Zero);
            float xtrans = (ivp.l * ImgSize.Width) * zf;
            float ytrans = (ivp.t * ImgSize.Height) * zf;
            if (centered)
            {
                Matrix3x2 translation = Matrix3x2.Translation(-xtrans, -ytrans);
                Matrix3x2 prod = scaleM * translation;
                prod.Invert();
                Vector2 br = Matrix3x2.TransformPoint(prod, new Vector2(ClientSize.Width, ClientSize.Height));
                float w = (br.X - ivp.r * ImgSize.Width);
                float h = (br.Y - ivp.b * ImgSize.Height);
                xtrans = (ivp.l * ImgSize.Width - w / 2) * zf;
                ytrans = (ivp.t * ImgSize.Height - h / 2) * zf;
            }
            translateM = Matrix3x2.Translation(-xtrans, -ytrans);
        }
protected void IvpToTransform ( ImageViewingParams ivp , bool widthSignificant , bool centered , out Matrix3x2 rotateM , out Matrix3x2 scaleM , out Matrix3x2 translateM ) { rotateM = Matrix3x2 . Rotation ( ( float ) ( ivp . rotation * deg2rad ) , ImgCenter ) ; float clientRatio = ( float ) ClientSize . Width / ( float ) ClientSize . Height ; float ivpRatio = ivp . rect . Width / ivp . rect . Height ; float zf = 0 ; if ( ( ! widthSignificant || ivpRatio < clientRatio ) && ivp . rect . Height != 0 ) { float scaley = ( float ) ClientSize . Height / ( float ) ImgSize . Height ; float oldscaley = ivp . rect . Height ; float zfy = scaley / oldscaley ; zf = zfy ; } else if ( widthSignificant && ivpRatio > clientRatio && ivp . rect . Width != 0 ) { float scalex = ( float ) ClientSize . Width / ( float ) ImgSize . Width ; float oldscalex = ivp . rect . Width ; float zfx = scalex / oldscalex ; zf = zfx ; } else { if ( P . keepZoom ) zf = _lastzf ; else zf = 1 ; } scaleM = Matrix3x2 . Scaling ( zf , zf , Vector2 . Zero ) ; float xtrans = ( ivp . l * ImgSize . Width ) * zf ; float ytrans = ( ivp . t * ImgSize . Height ) * zf ; if ( centered ) { Matrix3x2 translation = Matrix3x2 . Translation ( - xtrans , - ytrans ) ; Matrix3x2 prod = scaleM * translation ; prod . Invert ( ) ; Vector2 br = Matrix3x2 . TransformPoint ( prod , new Vector2 ( ClientSize . Width , ClientSize . Height ) ) ; float w = ( br . X - ivp . r * ImgSize . Width ) ; float h = ( br . Y - ivp . b * ImgSize . Height ) ; xtrans = ( ivp . l * ImgSize . Width - w / 2 ) * zf ; ytrans = ( ivp . t * ImgSize . Height - h / 2 ) * zf ; } translateM = Matrix3x2 . Translation ( - xtrans , - ytrans ) ; }
calculate the transformations needed so that the viewport coincides with the
provided ivp.
calculate the transformations needed so that the viewport coincides with the provided ivp .
//System.Windows.Forms.MessageBox.Show(string.Format("unidim ivp : {0}", ivp.ToString()));
ivp
ImageViewingParams
the view to restore
the view to restore
widthSignificant
bool
if true the width of the ivp will come into account for the restoration of the view
if true the width of the ivp will come into account for the restoration of the view
centered
bool
if true the origin of the restoration will be the center of the ivp, not the tl corner
if true the origin of the restoration will be the center of the ivp not the tl corner
Matrix3x2
out