コード例 #1
0
ファイル: DrawingContext.cs プロジェクト: alimbada/Perspex
        private IDisposable SetBrush(Brush brush, Size destinationSize)
        {
            _context.Save();

            var       solid = brush as SolidColorBrush;
            var       linearGradientBrush = brush as LinearGradientBrush;
            var       radialGradientBrush = brush as RadialGradientBrush;
            var       imageBrush          = brush as ImageBrush;
            var       visualBrush         = brush as VisualBrush;
            BrushImpl impl = null;

            if (solid != null)
            {
                impl = new SolidColorBrushImpl(solid, opacityOverride);
            }
            else if (linearGradientBrush != null)
            {
                impl = new LinearGradientBrushImpl(linearGradientBrush, destinationSize);
            }
            else if (radialGradientBrush != null)
            {
                impl = new RadialGradientBrushImpl(radialGradientBrush, destinationSize);
            }
            else if (imageBrush != null)
            {
                impl = new ImageBrushImpl(imageBrush, destinationSize);
            }
            else if (visualBrush != null)
            {
                impl = new VisualBrushImpl(visualBrush, destinationSize);
            }
            else
            {
                impl = new SolidColorBrushImpl(null, opacityOverride);
            }

            _context.SetSource(impl.PlatformBrush);
            return(Disposable.Create(() =>
            {
                impl.Dispose();
                _context.Restore();
            }));
        }
コード例 #2
0
ファイル: DrawingContext.cs プロジェクト: KvanTTT/Perspex
        private IDisposable SetBrush(Brush brush, Size destinationSize)
        {
			_context.Save ();

            var solid = brush as SolidColorBrush;
            var linearGradientBrush = brush as LinearGradientBrush;
            var radialGradientBrush = brush as RadialGradientBrush;
            var imageBrush = brush as ImageBrush;
            var visualBrush = brush as VisualBrush;
			BrushImpl impl = null;

			if (solid != null) 
			{
				impl = new SolidColorBrushImpl(solid, opacityOverride);
			} 
			else if (linearGradientBrush != null) 
			{
				impl = new LinearGradientBrushImpl(linearGradientBrush, destinationSize);
			}
            else if (radialGradientBrush != null)
            {
                impl = new RadialGradientBrushImpl(radialGradientBrush, destinationSize);
            }
            else if (imageBrush != null) 
			{
				impl = new ImageBrushImpl(imageBrush, destinationSize);
			} 
			else if (visualBrush != null) 
			{
				impl = new VisualBrushImpl(visualBrush, destinationSize);
			} 
			else 
			{
				impl = new SolidColorBrushImpl(null, opacityOverride);
			}

			_context.SetSource(impl.PlatformBrush);
			return Disposable.Create(() => 
			{
			    impl.Dispose();
				_context.Restore();
			});
        }