/// <summary>
 /// Initialize a transformer.
 /// </summary>
 /// <param name="transformerRect"> The initial rectangle. </param>
 public Transformer(TransformerRect transformerRect)
 {
     this.LeftTop     = transformerRect.LeftTop;
     this.RightTop    = transformerRect.RightTop;
     this.RightBottom = transformerRect.RightBottom;
     this.LeftBottom  = transformerRect.LeftBottom;
 }
        /// <summary>
        /// Initialize a transformer.
        /// </summary>
        /// <param name="pointA"> The frist point of transformer. </param>
        /// <param name="pointB"> The second point of transformer. </param>
        /// <param name="isCenter"> Scaling around the center. </param>
        /// <param name="isRatio"> Maintain a ratio when scaling. </param>
        public Transformer(Vector2 pointA, Vector2 pointB, bool isCenter, bool isRatio)
        {
            TransformerRect rect = new TransformerRect(pointA, pointB, isCenter, isRatio);

            this.LeftTop     = rect.LeftTop;
            this.RightTop    = rect.RightTop;
            this.RightBottom = rect.RightBottom;
            this.LeftBottom  = rect.LeftBottom;
        }
        /// <summary>
        /// Initialize a transformer.
        /// </summary>
        /// <param name="pointA"> The frist point of transformer. </param>
        /// <param name="pointB"> The second point of transformer. </param>
        public Transformer(Vector2 pointA, Vector2 pointB)
        {
            TransformerRect rect = new TransformerRect(pointA, pointB);

            this.LeftTop     = rect.LeftTop;
            this.RightTop    = rect.RightTop;
            this.RightBottom = rect.RightBottom;
            this.LeftBottom  = rect.LeftBottom;
        }
        /// <summary>
        /// Draw a marquee-tool.
        /// </summary>
        /// <param name="drawingSession"> The drawing-session. </param>
        /// <param name="resourceCreator"> The resource-creator. </param>
        /// <param name="toolType"> The marquee-tool type. </param>
        /// <param name="marqueeTool"> The marquee-tool. </param>
        /// <param name="matrix"> The matrix. </param>
        public static void DrawMarqueeTool(this CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, MarqueeToolType toolType, MarqueeTool marqueeTool, Matrix3x2 matrix)
        {
            if (marqueeTool.IsStarted)
            {
                switch (toolType)
                {
                case MarqueeToolType.Rectangular:
                {
                    TransformerRect transformerRect = marqueeTool.TransformerRect;
                    CanvasGeometry  canvasGeometry  = transformerRect.ToRectangle(resourceCreator, matrix);
                    drawingSession.DrawThickGeometry(canvasGeometry);
                }
                break;

                case MarqueeToolType.Elliptical:
                {
                    TransformerRect transformerRect = marqueeTool.TransformerRect;
                    CanvasGeometry  canvasGeometry  = transformerRect.ToEllipse(resourceCreator, matrix);
                    drawingSession.DrawThickGeometry(canvasGeometry);
                }
                break;

                case MarqueeToolType.Polygonal:
                {
                    Vector2[]      points                  = marqueeTool.Points.ToArray();
                    CanvasGeometry canvasGeometry          = CanvasGeometry.CreatePolygon(resourceCreator, points);
                    CanvasGeometry canvasGeometryTransform = canvasGeometry.Transform(matrix);
                    drawingSession.DrawThickGeometry(canvasGeometryTransform);

                    Vector2 firstPoint = Vector2.Transform(marqueeTool.Points.First(), matrix);
                    Vector2 lastPoint  = Vector2.Transform(marqueeTool.Points.Last(), matrix);
                    drawingSession.DrawNode5(firstPoint);
                    drawingSession.DrawNode5(lastPoint);
                }
                break;

                case MarqueeToolType.FreeHand:
                {
                    Vector2[]      points                  = marqueeTool.Points.ToArray();
                    CanvasGeometry canvasGeometry          = CanvasGeometry.CreatePolygon(resourceCreator, points);
                    CanvasGeometry canvasGeometryTransform = canvasGeometry.Transform(matrix);
                    drawingSession.DrawThickGeometry(canvasGeometryTransform);
                }
                break;
                }
            }
        }
Example #5
0
 /// <summary>
 /// The vector was contained in a rectangle.
 /// </summary>
 /// <param name="transformerRect"> The destination rectangle. </param>
 /// <returns> Return **true** if the vector was contained in rectangle. </returns>
 public bool Contained(TransformerRect transformerRect) => this.Contained(transformerRect.Left, transformerRect.Top, transformerRect.Right, transformerRect.Bottom);
        private static void DrawMarqueeToolEllipse(this CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, TransformerRect transformerRect, Rect sourceRectangle, MarqueeCompositeMode compositeMode = MarqueeCompositeMode.New)
        {
            switch (compositeMode)
            {
            case MarqueeCompositeMode.New:
            {
                drawingSession.Clear(Windows.UI.Colors.Transparent);

                Vector2 centerPoint = transformerRect.Center;
                float   width       = transformerRect.Width / 2;
                float   height      = transformerRect.Height / 2;

                drawingSession.FillEllipse(centerPoint, width, height, Windows.UI.Colors.DodgerBlue);
            }
            break;

            case MarqueeCompositeMode.Add:
            {
                Vector2 centerPoint = transformerRect.Center;
                float   width       = transformerRect.Width / 2;
                float   height      = transformerRect.Height / 2;

                drawingSession.FillEllipse(centerPoint, width, height, Windows.UI.Colors.DodgerBlue);
            }
            break;

            case MarqueeCompositeMode.Subtract:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolEllipse(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.DestinationOut;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;

            case MarqueeCompositeMode.Intersect:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolEllipse(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.DestinationIn;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;

            case MarqueeCompositeMode.Xor:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolEllipse(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.Xor;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;
            }
        }
        private static CanvasCommandList GetMarqueeToolEllipse(CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, TransformerRect transformerRect)
        {
            CanvasCommandList canvasCommandList = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession ds = canvasCommandList.CreateDrawingSession())
            {
                Vector2 centerPoint = transformerRect.Center;
                float   width       = transformerRect.Width / 2;
                float   height      = transformerRect.Height / 2;

                drawingSession.FillEllipse(centerPoint, width, height, Windows.UI.Colors.DodgerBlue);
            }
            return(canvasCommandList);
        }
        private static void DrawMarqueeToolRectangular(this CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, TransformerRect transformerRect, Rect sourceRectangle, MarqueeCompositeMode compositeMode = MarqueeCompositeMode.New)
        {
            switch (compositeMode)
            {
            case MarqueeCompositeMode.New:
            {
                drawingSession.Clear(Windows.UI.Colors.Transparent);
                Rect rect = transformerRect.ToRect();
                drawingSession.FillRectangle(rect, Windows.UI.Colors.DodgerBlue);
            }
            break;

            case MarqueeCompositeMode.Add:
            {
                Rect rect = transformerRect.ToRect();
                drawingSession.FillRectangle(rect, Windows.UI.Colors.DodgerBlue);
            }
            break;

            case MarqueeCompositeMode.Subtract:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolRectangular(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.DestinationOut;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;

            case MarqueeCompositeMode.Intersect:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolRectangular(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.DestinationIn;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;

            case MarqueeCompositeMode.Xor:
            {
                CanvasCommandList canvasCommandList = CanvasDrawingSessionExtensions.GetMarqueeToolRectangular(drawingSession, resourceCreator, transformerRect);
                CanvasComposite   canvasComposite   = CanvasComposite.Xor;
                drawingSession.DrawImage(canvasCommandList, 0, 0, sourceRectangle, 1, CanvasImageInterpolation.Linear, canvasComposite);
            }
            break;
            }
        }
        private static CanvasCommandList GetMarqueeToolRectangular(CanvasDrawingSession drawingSession, ICanvasResourceCreator resourceCreator, TransformerRect transformerRect)
        {
            CanvasCommandList canvasCommandList = new CanvasCommandList(resourceCreator);

            using (CanvasDrawingSession ds = canvasCommandList.CreateDrawingSession())
            {
                Rect rect = transformerRect.ToRect();
                ds.FillRectangle(rect, Windows.UI.Colors.DodgerBlue);
            }
            return(canvasCommandList);
        }
 /// <summary>
 /// Check node which in the rect.
 /// </summary>
 /// <param name="boxRect"> The destination rectangle. </param>
 public void BoxChoose(TransformerRect boxRect) => this.RectChoose(boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Bottom);