Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TileBrushCalculator"/> class.
        /// </summary>
        /// <param name="tileMode">The brush's tile mode.</param>
        /// <param name="stretch">The brush's stretch.</param>
        /// <param name="alignmentX">The brush's horizontal alignment.</param>
        /// <param name="alignmentY">The brush's vertical alignment.</param>
        /// <param name="sourceRect">The brush's source rect</param>
        /// <param name="destinationRect">The brush's destination rect.</param>
        /// <param name="contentSize">The size of the content of the tile brush.</param>
        /// <param name="targetSize">The size of the control to which the brush is being rendered.</param>
        public TileBrushCalculator(
            TileMode tileMode,
            Stretch stretch,
            AlignmentX alignmentX,
            AlignmentY alignmentY,
            RelativeRect sourceRect,
            RelativeRect destinationRect,
            Size contentSize,
            Size targetSize)
        {
            _imageSize = contentSize;

            SourceRect      = sourceRect.ToPixels(_imageSize);
            DestinationRect = destinationRect.ToPixels(targetSize);

            var scale     = stretch.CalculateScaling(DestinationRect.Size, SourceRect.Size);
            var translate = CalculateTranslate(alignmentX, alignmentY, SourceRect, DestinationRect, scale);

            IntermediateSize      = tileMode == TileMode.None ? targetSize : DestinationRect.Size;
            IntermediateTransform = CalculateIntermediateTransform(
                tileMode,
                SourceRect,
                DestinationRect,
                scale,
                translate,
                out _drawRect);
        }