// Auxiliary functions. trans_affine_resizing() modifier sets up the resizing // matrix on the basis of the given width and height and the initial // width and height of the window. The implementation should simply // call this function every time when it catches the resizing event // passing in the new values of width and height of the window. // Nothing prevents you from "cheating" the scaling matrix if you // call this function from somewhere with wrong arguments. // trans_affine_resizing() accessor simply returns current resizing matrix // which can be used to apply additional scaling of any of your // stuff when the window is being resized. // width(), height(), initial_width(), and initial_height() must be // clear to understand with no comments :-) public void trans_affine_resizing(int width, int height) { if ((m_window_flags & (uint)WindowFlags.KeepAspectRatio) != 0) { double sx = (double)(width) / (double)(m_initial_width); double sy = (double)(height) / (double)(m_initial_height); if (sy < sx) { sx = sy; } m_resize_mtx = MatrixFactory <T> .NewScaling2D(M.New <T>(sx), M.New <T>(sx)); Viewport <T> vp = new Viewport <T>(); vp.PreserveAspectRatio(M.New <T>(0.5), M.New <T>(0.5), AspectRatio.Meet); vp.DeviceViewport(M.Zero <T>(), M.Zero <T>(), M.New <T>(width), M.New <T>(height)); vp.WorldViewport(M.Zero <T>(), M.Zero <T>(), M.New <T>(m_initial_width), M.New <T>(m_initial_height)); m_resize_mtx = vp.ToAffine(); } else { m_resize_mtx = MatrixFactory <T> .NewScaling2D( M.New <T>((double)(width) / (double)(m_initial_width)), M.New <T>((double)(height) / (double)(m_initial_height))); } }
//------------------------------------------------------------------- public IAffineTransformMatrix <T> ToAffineScaleOnly() { return(MatrixFactory <T> .NewScaling2D(m_kx, m_ky)); }