Esempio n. 1
0
        /// <summary>
        /// Frames the items in the current view</summary>
        /// <param name="items">Items to frame</param>
        public void Frame(IEnumerable<object> items)
        {
            if (ToggleFramingEnabled)
            {
                if (m_isUnframing)
                {
                    m_isUnframing = false;
                    m_transformAdapter.SetTransform(m_unframeMtrx.M11, m_unframeMtrx.M22, m_unframeMtrx.DX, m_unframeMtrx.DY);
                    return;
                }
                m_isUnframing = true;
                m_unframeMtrx = m_transformAdapter.Transform;
            }



            var bounds = GetBounds(items);

            // transform bounds from client space to graph space.
            Matrix3x2F invXform = Matrix3x2F.Invert(m_transformAdapter.Transform);
            var gBounds = Matrix3x2F.Transform(invXform, bounds);            
            var crect = AdaptedControl.ClientRectangle;
            crect.Inflate(-MarginSize.Width, -MarginSize.Height);
            if (crect.Width < 1 || crect.Height < 1) return;

            float sx = MathUtil.Clamp(crect.Width / gBounds.Width, m_transformAdapter.MinScale.X, m_transformAdapter.MaxScale.X);
            float sy = MathUtil.Clamp(crect.Height / gBounds.Height, m_transformAdapter.MinScale.Y, m_transformAdapter.MaxScale.Y);
            float scale = Math.Min(sx, sy);
            crect.X +=(int) (crect.Width - gBounds.Width * scale) / 2;
            crect.Y += (int)(crect.Height - gBounds.Height * scale) / 2;
            float tx = crect.X - gBounds.X * scale;
            float ty = crect.Y - gBounds.Y * scale;
            m_transformAdapter.SetTransform(scale, scale, tx, ty);            
        }
Esempio n. 2
0
 /// <summary>
 /// Transforms vector</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="v">Vector</param>
 /// <returns>Transformed vector</returns>
 public static PointF TransformVector(Matrix3x2F matrix, PointF v)
 {
     s_tempPtsF[0] = v;
     Matrix3x2F.TransformVector(matrix, s_tempPtsF[0]);
     return s_tempPtsF[0];
 }
Esempio n. 3
0
 /// <summary>
 /// Transforms point by inverse transform</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="p">Point</param>
 /// <returns>Inverse transformed point</returns>
 public static Point InverseTransform(Matrix3x2F matrix, Point p)
 {
     Matrix3x2F inverse = matrix;
     inverse.Invert();
     s_tempPtsF[0] = p;
     s_tempPtsF[0] = Matrix3x2F.TransformPoint(inverse, s_tempPtsF[0]);
     return new Point((int)s_tempPtsF[0].X, (int)s_tempPtsF[0].Y);
 }
Esempio n. 4
0
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix3x2F matrix, RectangleF r)
 {
     s_tempPtsF[0] = new PointF(r.Left, r.Top);
     s_tempPtsF[1] = new PointF(r.Right, r.Bottom);
     s_tempPtsF[0] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[0]);
     s_tempPtsF[1] = Matrix3x2F.TransformPoint(matrix, s_tempPtsF[1]);
     return MakeRectangle(s_tempPtsF[0], s_tempPtsF[1]);
 }
Esempio n. 5
0
 /// <summary>
 /// Changes the rotation of the coordinate system by prepending the specified rotation
 /// to the Transform property</summary>
 /// <param name="angle">Angle of rotation, in degrees</param>
 public void RotateTransform(float angle)
 {
     var trans = Matrix3x2F.CreateRotation(angle);
     var xform = Transform;
     Transform = (trans * xform);
 }
Esempio n. 6
0
 /// <summary>
 /// Changes the scale of the coordinate system by prepending the specified scale
 /// to the Transform property</summary>
 /// <param name="sx">Amount to scale by in the x-axis direction</param>
 /// <param name="sy">Amount to scale by in the y-axis direction</param>
 public void ScaleTransform(float sx, float sy)
 {
     var trans = Matrix3x2F.CreateScale(sx, sy);
     var xform = Transform;
     Transform = (trans * xform);
 }
Esempio n. 7
0
 /// <summary>
 /// Changes the origin of the coordinate system by prepending the specified translation
 /// to the Transform property</summary>
 /// <param name="dx">X translation</param>
 /// <param name="dy">Y translation</param>
 /// <remarks>Modeled after GDI version http://msdn.microsoft.com/en-us/library/6a1d65f4.aspx </remarks>
 public void TranslateTransform(float dx, float dy)
 {
     var trans = Matrix3x2F.CreateTranslation(dx, dy);
     var xform = Transform;
     Transform = (trans * xform);
 }
Esempio n. 8
0
 /// <summary>
 /// Transforms vector</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="v">Vector</param>
 /// <returns>Transformed vector</returns>
 public static PointF TransformVector(Matrix3x2F matrix, PointF v)
 {            
     return Matrix3x2F.TransformVector(matrix, v);
 }
Esempio n. 9
0
 /// <summary>
 /// Transforms point by inverse transform</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="p">Point</param>
 /// <returns>Inverse transformed point</returns>
 public static Point InverseTransform(Matrix3x2F matrix, Point p)
 {            
     Matrix3x2F inverse = Matrix3x2F.Invert(matrix);
     return Point.Truncate(Matrix3x2F.TransformPoint(inverse, p));                       
 }
Esempio n. 10
0
 /// <summary>
 /// Transforms rectangle</summary>
 /// <param name="matrix">Matrix representing transform</param>
 /// <param name="r">Rectangle</param>
 /// <returns>Transformed rectangle</returns>
 public static RectangleF Transform(Matrix3x2F matrix, RectangleF r)
 {
     return Matrix3x2F.Transform(matrix, r);          
 }
        private static void TraceMatrix(Matrix3x2F matrix)
        {
#if _D2DTRACE
            Trace.WriteLine(string.Format("  Matrix3x2: {0}, {1}", matrix.M11, matrix.M12));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M21, matrix.M22));
            Trace.WriteLine(string.Format("             {0}, {1}", matrix.M31, matrix.M32));
#endif
        }
 protected internal Matrix3x2F RandomMatrix3x2()
 {
     var which = Random.NextDouble();
     //return Matrix3x2F.Skew(90, 0); //check for bug 730701
     Matrix3x2F ret;
     if (which < 0.5)
     {
         ret = new Matrix3x2F(
             1.0f - (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             1.0f - (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble(),
             (float) Random.NextDouble()*(float) Random.NextDouble()
             );
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.8)
     {
         ret = Matrix3x2F.Identity;
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.85)
     {
         ret = Matrix3x2F.Translation(
             Random.Next(-20, 20),
             Random.Next(-20, 20));
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.90)
     {
         ret = Matrix3x2F.Skew(
             (float)(Random.NextDouble() * Random.NextDouble() * 89),
             (float)(Random.NextDouble() * Random.NextDouble() * 89),
             CoinFlip ? new Point2F(0, 0) : RandomPoint());
         TraceMatrix(ret);
         return ret;
     }
     if (which < 0.95)
     {
         ret = Matrix3x2F.Scale(
             1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
             1 + (float)((Random.NextDouble() - 0.5) * Random.NextDouble()),
             CoinFlip ? new Point2F(0, 0) : RandomPoint());
         TraceMatrix(ret);
         return ret;
     }
     ret = Matrix3x2F.Rotation(
         (float)((Random.NextDouble() - 0.5) * Random.NextDouble() * 720),
         CoinFlip ? new Point2F(0,0) : RandomPoint());
     TraceMatrix(ret);
     return ret;
 }