Exemple #1
0
        public object Clone()
        {
            CalcData obj = MemberwiseClone() as CalcData;

            obj.Matrix = Matrix.Clone();
            return(obj);
        }
Exemple #2
0
        /// <summary>
        /// 获取旋转角
        /// </summary>
        /// <param name="data"></param>
        /// <param name="point"></param>
        /// <param name="center"></param>
        /// <returns></returns>
        public static float GetRotateAngle(CalcData data, PointF point, PointF center)
        {
            double angle1 = Math.Atan2(data.MousePos.Y - center.Y, data.MousePos.X - center.X);
            double angle2 = Math.Atan2(point.Y - center.Y, point.X - center.X);
            float  angle  = (float)((angle2 - angle1) * 180 / Math.PI);

            return(data.RotateAngle + angle);
        }
Exemple #3
0
        /// <summary>
        /// 获取边框移动后的偏移量
        /// </summary>
        /// <param name="data"></param>
        /// <param name="point"></param>
        /// <param name="pos"></param>
        /// <param name="xOff"></param>
        /// <param name="yOff"></param>
        /// <param name="wOff"></param>
        /// <param name="hOff"></param>
        public static void GetFrameOffset(CalcData data, PointF point, int pos, out float xOff, out float yOff, out float wOff, out float hOff, float orthoTan)
        {
            PointF begin = GetInvertPos(data.Matrix, data.MousePos);
            PointF end   = GetInvertPos(data.Matrix, point);

            GetOffset(begin, end, pos, out xOff, out yOff, out wOff, out hOff, orthoTan);
            LimitOffset(data.Rect, ref xOff, ref yOff, ref wOff, ref hOff);
        }
Exemple #4
0
        /// <summary>
        /// 获取成组旋转的偏移
        /// </summary>
        /// <param name="data"></param>
        /// <param name="center"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        public static PointF GetRotateAtOffset(CalcData data, PointF center, float angle)
        {
            _funPath.Reset();
            _funPath.AddRectangle(data.Rect);
            _funPath.Transform(data.Matrix);
            PointF p1         = _funPath.PathPoints[0];
            PointF p2         = _funPath.PathPoints[2];
            PointF rectCenter = new PointF((p1.X + p2.X) / 2f, (p1.Y + p2.Y) / 2f);

            return(GetRotateOffset(rectCenter, center, angle));
        }
Exemple #5
0
        /// <summary>
        /// 根据控件形状获取其矩阵旋转角度,倾斜和实际大小。边框移动调用此函数
        /// </summary>
        /// <param name="data"></param>
        /// <param name="wOff"></param>
        /// <param name="hOff"></param>
        /// <param name="angle"></param>
        /// <param name="shear"></param>
        /// <param name="rect"></param>
        public static void GetBoundMoveData(CalcData data, float wOff, float hOff, out float angle, out float shear, out RectangleF rect)
        {
            _funMatrix.Reset();
            _funPath.Reset();

            PointF pf = PointF.Empty;

            CalcMatrix(data, ref _funMatrix, ref pf);
            _funPath.AddRectangle(data.Rect);
            _funPath.Transform(_funMatrix);

            //反转Flip
            PointF[] ps = _funPath.PathPoints;
            FlipRectPos(ps, data.IsFlipX, data.IsFlipY);

            RectangleF bound  = _funPath.GetBounds();
            float      newW   = bound.Width + wOff;
            float      scaleW = newW / bound.Width;
            float      newH   = bound.Height + hOff;
            float      scaleH = newH / bound.Height;

            for (int i = 0; i < ps.Length; i++)
            {
                ps[i].X = (ps[i].X - bound.X) * scaleW + bound.X;
                ps[i].Y = (ps[i].Y - bound.Y) * scaleH + bound.Y;
            }

            //计算旋转角度
            angle = (float)Math.Atan2(ps[1].Y - ps[0].Y, ps[1].X - ps[0].X);
            angle = (float)(angle * 180 / Math.PI);

            //获取反旋转后的数据
            _funPath.Reset();
            _funPath.AddLines(ps);
            bound = _funPath.GetBounds();
            PointF center = new PointF(bound.X + bound.Width * 0.5f, bound.Y + bound.Height * 0.5f);

            _funMatrix.Reset();
            _funMatrix.RotateAt(-angle, center);
            _funPath.Transform(_funMatrix);

            //计算倾斜
            ps = _funPath.PathPoints;
            float h      = ps[3].Y - ps[0].Y;
            float wShear = ps[3].X - ps[0].X;

            shear = wShear / h;

            //获取反倾斜后的数据
            rect = new RectangleF {
                X = ps[0].X + wShear / 2f, Y = ps[0].Y, Width = ps[1].X - ps[0].X, Height = h
            };
        }
Exemple #6
0
        /// <summary>
        /// 获取倾斜值
        /// </summary>
        /// <param name="data"></param>
        /// <param name="point"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static float GetShear(CalcData data, PointF point, int pos)
        {
            float x1     = GetRotatePos(data.MousePos, data.RotatePointPos, -data.RotateAngle).X;
            float x2     = GetRotatePos(point, data.RotatePointPos, -data.RotateAngle).X;
            float xShear = (x2 - x1) * 2 / data.Rect.Height;

            if (pos == 0)
            {
                xShear = -xShear;
            }
            if (data.IsFlipY)
            {
                xShear = -xShear;
            }

            return(data.Shear + xShear);
        }