Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public override void Render(DrawingContext context)
        {
            var source = Source;
            var mem    = new MemoryStream();

            Source.Save(mem);

            if (source != null && mem.Length > 0 && Bounds.Width > 0 && Bounds.Height > 0)
            {
                Rect viewPort   = new Rect(Bounds.Size);
                Size sourceSize = source.Size;

                Vector scale      = Stretch.CalculateScaling(Bounds.Size, sourceSize, StretchDirection);
                Size   scaledSize = sourceSize * scale;
                Rect   destRect   = viewPort
                                    .CenterRect(new Rect(scaledSize))
                                    .Intersect(viewPort);
                Rect sourceRect = new Rect(sourceSize)
                                  .CenterRect(new Rect(destRect.Size / scale));

                var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);
                context.Custom(new BlurImageRender(mem, destRect, sourceRect, BlurLevel, BlurLevel, null));
                // Dispatcher.UIThread.InvokeAsync(InvalidateVisual, DispatcherPriority.Background);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Calculates a scaled size based on a <see cref="Stretch"/> value.
 /// </summary>
 /// <param name="stretch">The stretch mode.</param>
 /// <param name="destinationSize">The size of the destination viewport.</param>
 /// <param name="sourceSize">The size of the source.</param>
 /// <param name="stretchDirection">The stretch direction.</param>
 /// <returns>The size of the stretched source.</returns>
 public static Size CalculateSize(
     this Stretch stretch,
     Size destinationSize,
     Size sourceSize,
     StretchDirection stretchDirection = StretchDirection.Both)
 {
     return(sourceSize * stretch.CalculateScaling(destinationSize, sourceSize, stretchDirection));
 }
Exemplo n.º 4
0
 public override void Render(DrawingContext context)
 {
     if (!_isDisposed)
     {
         // TODO: Better to calculate this stuff when resizing only
         Size   bSize      = Bounds.Size;
         Vector scale      = _stretch.CalculateScaling(bSize, _screenSize);
         Size   scaledSize = _screenSize * scale;
         var    viewPort   = new Rect(bSize);
         Rect   destRect   = viewPort.CenterRect(new Rect(scaledSize)).Intersect(viewPort);
         Rect   sourceRect = new Rect(_screenSize).CenterRect(new Rect(destRect.Size / scale));
         context.DrawImage(_screen, sourceRect, destRect);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Renders the control.
        /// </summary>
        /// <param name="context">The drawing context.</param>
        public override void Render(DrawingContext context)
        {
            var source = Source;

            if (source != null)
            {
                Rect   viewPort   = new Rect(Bounds.Size);
                Size   sourceSize = source.Size;
                Vector scale      = Stretch.CalculateScaling(Bounds.Size, sourceSize, StretchDirection);
                Size   scaledSize = sourceSize * scale;
                Rect   destRect   = viewPort
                                    .CenterRect(new Rect(scaledSize))
                                    .Intersect(viewPort);
                Rect sourceRect = new Rect(sourceSize)
                                  .CenterRect(new Rect(destRect.Size / scale));

                var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);

                context.DrawImage(source, sourceRect, destRect, interpolationMode);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Calculates a scaled size based on a <see cref="Stretch"/> value.
 /// </summary>
 /// <param name="stretch">The stretch mode.</param>
 /// <param name="destinationSize">The size of the destination viewport.</param>
 /// <param name="sourceSize">The size of the source.</param>
 /// <returns>The size of the stretched source.</returns>
 public static Size CalculateSize(this Stretch stretch, Size destinationSize, Size sourceSize)
 {
     return(sourceSize * stretch.CalculateScaling(destinationSize, sourceSize));
 }