Ejemplo n.º 1
0
        public TileBrushImplHelper(ITileBrush brush, Size targetSize)
        {
            _imageBrush  = brush as IImageBrush;
            _visualBrush = brush as IVisualBrush;
            if (_imageBrush != null)
            {
                if (_imageBrush.Source == null)
                {
                    return;
                }
                _imageSize = new Size(_imageBrush.Source.PixelWidth, _imageBrush.Source.PixelHeight);
                IsValid    = true;
            }
            else if (_visualBrush != null)
            {
                var control = _visualBrush.Visual as IControl;

                if (control != null)
                {
                    EnsureInitialized(control);

                    if (control.IsArrangeValid == false)
                    {
                        control.Measure(Size.Infinity);
                        control.Arrange(new Rect(control.DesiredSize));
                    }

                    _imageSize = control.Bounds.Size;
                    IsValid    = true;
                }
            }
            else
            {
                return;
            }

            _tileMode        = brush.TileMode;
            _sourceRect      = brush.SourceRect.ToPixels(_imageSize);
            DestinationRect  = brush.DestinationRect.ToPixels(targetSize);
            _scale           = brush.Stretch.CalculateScaling(DestinationRect.Size, _sourceRect.Size);
            _translate       = CalculateTranslate(brush, _sourceRect, DestinationRect, _scale);
            IntermediateSize = CalculateIntermediateSize(_tileMode, targetSize, DestinationRect.Size);
            _transform       = CalculateIntermediateTransform(
                _tileMode,
                _sourceRect,
                DestinationRect,
                _scale,
                _translate,
                out _drawRect);
        }
Ejemplo n.º 2
0
 public ImageBrushImpl(IImageBrush brush, Size destinationSize)
 {
     this.PlatformBrush = TileBrushes.CreateTileBrush(brush, destinationSize);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImmutableImageBrush"/> class.
 /// </summary>
 /// <param name="source">The brush from which this brush's properties should be copied.</param>
 public ImmutableImageBrush(IImageBrush source)
     : base(source)
 {
     Source = source.Source;
 }