コード例 #1
0
        public static void ScaleGraphicsObject(PointF touchLocation, 
		                                       PointF prevTouchLocation, 
		                                       LayerInfo layerItem, 
		                                       CanvasControlPoint controlPoint, 
		                                       bool aspectRatioLocked,
		                                       ContentPackItem.ItemSize itemSize = ContentPackItem.ItemSize.Small)
        {
            RectangleF boundingBox = layerItem.GetBoundingBox ();

            bool scaleUpOnly = boundingBox.Width < 10f || boundingBox.Height < 10f;

            float sx = 0;
            float sy = 0;

            PointF fixedPoint = PointF.Empty;

            switch (controlPoint) {

            case CanvasControlPoint.TopLeft:

                // Fixed point is bottom-right
                fixedPoint = new PointF (boundingBox.Right, boundingBox.Bottom);
                sx = boundingBox.Width / (boundingBox.Width + (touchLocation.X - prevTouchLocation.X));
                sy = aspectRatioLocked ?
                    sx :
                        boundingBox.Height / (boundingBox.Height + (touchLocation.Y - prevTouchLocation.Y));

                break;

            case CanvasControlPoint.TopRight:

                // Fixed point is bottom-left
                fixedPoint = new PointF (boundingBox.Left, boundingBox.Bottom);

                sx = boundingBox.Width / (boundingBox.Width - (touchLocation.X - prevTouchLocation.X));
                sy = aspectRatioLocked ?
                    sx :
                        boundingBox.Height / (boundingBox.Height + (touchLocation.Y - prevTouchLocation.Y));

                break;

            case CanvasControlPoint.BottomRight:

                // Fixed point is top-left
                fixedPoint = boundingBox.Location;

                sx = boundingBox.Width / (boundingBox.Width - (touchLocation.X - prevTouchLocation.X));
                sy = aspectRatioLocked ?
                    sx :
                        boundingBox.Height / (boundingBox.Height - (touchLocation.Y - prevTouchLocation.Y));

                break;

            case CanvasControlPoint.BottomLeft:

                // Fixed point is top-right
                fixedPoint = new PointF (boundingBox.Right, boundingBox.Top);

                sx = boundingBox.Width / (boundingBox.Width + (touchLocation.X - prevTouchLocation.X));
                sy = aspectRatioLocked ?
                    sx :
                        boundingBox.Height / (boundingBox.Height - (touchLocation.Y - prevTouchLocation.Y));

                break;

            }//end switch

            if (scaleUpOnly &&
                sx < 1) {
                sx = 1;
            }//end if

            if (scaleUpOnly &&
                sy < 1) {
                sy = 1;
            }//end if

            foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) {

                if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) {

                    for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) {

                        PointF point = eachDrawingInfo.PathPoints [i];
                        point.X = sx * (point.X + (-fixedPoint.X)) + fixedPoint.X;
                        point.Y = sy * (point.Y + (-fixedPoint.Y)) + fixedPoint.Y;

                        eachDrawingInfo.PathPoints [i] = point;

                    }//end for

                } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Comix ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Stamp ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Callout) {

                    RectangleF imgFrame = eachDrawingInfo.ImageFrame;
                    imgFrame.Width *= sx;
                    imgFrame.Height *= sy;

                    switch (controlPoint) {

                    case CanvasControlPoint.BottomLeft:

                        imgFrame.X += touchLocation.X - prevTouchLocation.X;

                        break;

                    case CanvasControlPoint.BottomRight:

                        //NOTE: Location is ok, when the only item in the layer is the image.

                        break;

                    case CanvasControlPoint.TopLeft:

                        imgFrame.X += touchLocation.X - prevTouchLocation.X;
                        imgFrame.Y += touchLocation.Y - prevTouchLocation.Y;

                        break;

                    case CanvasControlPoint.TopRight:

                        imgFrame.Y += touchLocation.Y - prevTouchLocation.Y;

                        break;

                    }//end switch

                    eachDrawingInfo.ImageFrame = imgFrame;
                    eachDrawingInfo.RotatedImageBox = eachDrawingInfo.ImageFrame.Rotate (eachDrawingInfo.RotationAngle);

                    if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout)
                    {
                        eachDrawingInfo.CalloutTextRect = GetCalloutTextRect (eachDrawingInfo.ImageFrame, itemSize);
                    }//end if

                }//end if else

            }//end foreach
        }
コード例 #2
0
        public static void RotateGraphicsObject(PointF touchLocation, LayerInfo layerItem, ref double prevRadAngle)
        {
            RectangleF boundingRect = layerItem.GetBoundingBox ();
            //			PointF center = new PointF (boundingRect.GetMidX (), boundingRect.GetMidY ());
            PointF center = boundingRect.GetCenterOfRect();

            double deltaX = touchLocation.X - center.X;
            double deltaY = touchLocation.Y - center.Y;

            double radAngle = Math.Atan2 (deltaY, deltaX);
            double angleDiff = radAngle - prevRadAngle;

            float angleCos = (float)Math.Cos (angleDiff);
            float angleSin = (float)Math.Sin (angleDiff);

            foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) {

                if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) {

                    for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) {

                        PointF point = eachDrawingInfo.PathPoints [i];

                        // Translate point
                        float tx = point.X - center.X;
                        float ty = point.Y - center.Y;

                        // Rotate it
                        float rx = (tx * angleCos) - (ty * angleSin);
                        float ry = (ty * angleCos) + (tx * angleSin);

                        // Translate back
                        rx += center.X;
                        ry += center.Y;

                        point.X = rx;
                        point.Y = ry;

                        eachDrawingInfo.PathPoints [i] = point;

                    }//end for

                } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Comix ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Stamp ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Callout) {

                    double degAngle = radAngle * RadToDeg;
                    RectangleF imgFrame = eachDrawingInfo.ImageFrame;
                    eachDrawingInfo.RotatedImageBox = imgFrame.Rotate (degAngle);

                }//end if else if

                eachDrawingInfo.RotationAngle = radAngle * RadToDeg;

            }//end foreach

            prevRadAngle = radAngle;
        }
コード例 #3
0
        public static void RotateGraphicsObjectByAngle(double degAngle, LayerInfo layerItem)
        {
            RectangleF boundingBox = layerItem.GetBoundingBox ();
            //			PointF center = new PointF (boundingBox.GetMidX (), boundingBox.GetMidY ());
            PointF center = boundingBox.GetCenterOfRect();

            double radAngle = degAngle * DegToRad;
            float angleCos = (float)Math.Cos (radAngle);
            float angleSin = (float)Math.Sin (radAngle);

            foreach (DrawingInfo eachDrawingInfo in layerItem.DrawingItems.Values) {

                if (eachDrawingInfo.DrawingType == DrawingLayerType.Drawing) {

                    for (int i = 0; i < eachDrawingInfo.PathPoints.Count; i++) {

                        PointF point = eachDrawingInfo.PathPoints [i];

                        // Translate point
                        float tx = point.X - center.X;
                        float ty = point.Y - center.Y;

                        // Rotate it
                        float rx = (tx * angleCos) - (ty * angleSin);
                        float ry = (ty * angleCos) + (tx * angleSin);

                        // Translate back
                        rx += center.X;
                        ry += center.Y;

                        point.X = rx;
                        point.Y = ry;

                        eachDrawingInfo.PathPoints [i] = point;

                    }//end for

                } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Image ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Comix ||
                    eachDrawingInfo.DrawingType == DrawingLayerType.Stamp) {

                    RectangleF imgFrame = eachDrawingInfo.ImageFrame;
                    eachDrawingInfo.RotatedImageBox = imgFrame.Rotate (degAngle);
                    eachDrawingInfo.RotationAngle = degAngle;

                } else if (eachDrawingInfo.DrawingType == DrawingLayerType.Callout) {

                    RectangleF imgFrame = eachDrawingInfo.ImageFrame;
                    eachDrawingInfo.RotatedImageBox = imgFrame.Rotate (degAngle);
                    eachDrawingInfo.RotationAngle = degAngle;

                }//end if else if

            }//end foreach
        }
コード例 #4
0
        public static AnimationTypesTransitionEffectType CreateTransitionEffect(LayerInfo guideLayer, TransitionInfo transitionItem)
        {
            AnimationTypesTransitionEffectType toReturn = AnimationTypesTransitionEffectType.None;

            RectangleF layerBox = guideLayer.GetBoundingBox ();
            RectangleF trBox = new RectangleF (transitionItem.EndLocation, transitionItem.EndSize);

            // Check for Move transition
            if (layerBox.Location != transitionItem.EndLocation) {
                toReturn = AnimationTypesTransitionEffectType.Move;
            }//end if

            // Check for Rotation transition
            double guideRotationAngle = guideLayer.DrawingItems.Select (s => s.Value.RotationAngle).Max ();
            if (guideRotationAngle != transitionItem.RotationAngle)
            {
                if (toReturn == AnimationTypesTransitionEffectType.None)
                {
                    toReturn = AnimationTypesTransitionEffectType.Rotate;
                } else
                {
                    toReturn |= AnimationTypesTransitionEffectType.Rotate;
                }//end if else

            }//end if

            // Check for Scale transition
            if (layerBox.Size != transitionItem.EndSize)
            {
                if (toReturn == AnimationTypesTransitionEffectType.None)
                {
                    toReturn = AnimationTypesTransitionEffectType.Scale;
                } else
                {
                    toReturn |= AnimationTypesTransitionEffectType.Scale;
                }//end if else

            }//end if

            return toReturn;
        }