Ejemplo n.º 1
0
		public static RadialGradientBrush GetBackgroundByName(string strName)
		{
			RadialGradientBrush result = new RadialGradientBrush();
			if (Application.Current.Resources.Contains(strName))
			{
				result = Application.Current.Resources[strName] as RadialGradientBrush;
			}

			//string uri = "/Designer;component/Resources/Brushes.xaml";
			//StreamResourceInfo StreamResourceInfoObj = Application.GetResourceStream(new Uri(uri, UriKind.RelativeOrAbsolute));

			//if (StreamResourceInfoObj != null && StreamResourceInfoObj.Stream != null)
			//{
			//    using (StreamReader StreamReaderObj = new StreamReader(StreamResourceInfoObj.Stream))
			//    {
			//        string resourcemerged = StreamReaderObj.ReadToEnd();

			//        if (string.IsNullOrEmpty(resourcemerged) == false)
			//        {
			//            ResourceDictionary loadresources = XamlReader.Load(resourcemerged) as ResourceDictionary;

			//            if (loadresources.Contains(strName))
			//                result = loadresources[strName] as RadialGradientBrush;
			//        }
			//    }
			//}

			return result;

		}
Ejemplo n.º 2
0
 public static System.Windows.Media.RadialGradientBrush GetGradientColorBrush(Color color)
 {
     System.Windows.Media.RadialGradientBrush brush = new System.Windows.Media.RadialGradientBrush();
     brush.GradientStops.Add(new GradientStop(color, 1.0));
     brush.GradientStops.Add(new GradientStop(Colors.White, 0.005));
     return(brush);
 }
Ejemplo n.º 3
0
        private void Initialize()
        {
            try
            {
                ColorConverter cc = new ColorConverter();
                _colourStart = new byte[3];
                _colourStop = new byte[3];
                _brushPosted = (Color)ColorConverter.ConvertFromString("#FF0DE251");
                _brushNotPosted = (Color)ColorConverter.ConvertFromString("#FFEA402F");

                _colourStart[0] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartR"));
                _colourStart[1] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartG"));
                _colourStart[2] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStartB"));

                _colourStop[0] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopR"));
                _colourStop[1] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopG"));
                _colourStop[2] = Convert.ToByte(System.Configuration.ConfigurationManager.AppSettings.Get("ColourStopB"));

                _brushNotTransparent = new RadialGradientBrush(
                    Color.FromRgb(_colourStart[0], _colourStart[1], _colourStart[2]),
                    Color.FromRgb(_colourStop[0], _colourStop[1], _colourStop[2]));

                OverrideSelectionEvent += UIPictureBox_OverrideSelectionEvent;
            }
            catch (Exception) { }
        }
Ejemplo n.º 4
0
		static ResizeChrome()
		{
			TransparentBrush = Brushes.Transparent;
			TransparentBrush.Freeze();
			var borderBrush = new LinearGradientBrush()
			{
				Opacity = 0.7,
				StartPoint = new Point(0, 0),
				EndPoint = new Point(1, 0.3),

			};
			borderBrush.GradientStops.Add(new GradientStop(Colors.SlateBlue, 0));
			borderBrush.GradientStops.Add(new GradientStop(Colors.LightBlue, 0.5));
			borderBrush.GradientStops.Add(new GradientStop(Colors.SlateBlue, 1));
			borderBrush.Freeze();
			BorderBrush = borderBrush;
			var thumbBrush = new RadialGradientBrush()
			{
				Center = new Point(0.3, 0.3),
				GradientOrigin = new Point(0.3, 0.3),
				RadiusX = 0.7,
				RadiusY = 0.7,
			};
			thumbBrush.GradientStops.Add(new GradientStop(Colors.White, 0));
			thumbBrush.GradientStops.Add(new GradientStop(Colors.DarkSlateBlue, 0.9));
			thumbBrush.Freeze();
			ThumbBrush = thumbBrush;
			TransparentPen = new Pen(TransparentBrush, 3.5);
			BorderPen = new Pen(BorderBrush, 2);
			BorderPen.DashStyle = DashStyles.Dash;
			ThumbGeometry = new EllipseGeometry();
			UpdateZoom(1);
		}
Ejemplo n.º 5
0
 public static Brush getBrushFromColorRadialGradient(Color color)
 {
     RadialGradientBrush b = new RadialGradientBrush();
     b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
     b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));
     return b;
 }
Ejemplo n.º 6
0
 private void OnReplaceBrush(object sender, RoutedEventArgs e)
 {
     var brush = new RadialGradientBrush();
     brush.GradientStops.Add(new GradientStop(Colors.Blue, 0));
     brush.GradientStops.Add(new GradientStop(Colors.White, 1));
     this.Resources["brush1"] = brush;
 }
Ejemplo n.º 7
0
        public override void SaveGradient()
        {
            double rate = DataManager.Instance.MainData.PixelWidth / _bokehData.Width;

            GradientStopCollection collection = new GradientStopCollection();
            collection.Add(new GradientStop() { Color = Colors.Transparent, Offset = _bokehData.Rate });
            collection.Add(new GradientStop() { Color = Color.FromArgb(128, 0, 0, 0), Offset = _bokehData.Rate });
            collection.Add(new GradientStop() { Color = Color.FromArgb(255, 0, 0, 0), Offset = 1 });

            RadialGradientBrush brush = new RadialGradientBrush()
            {
                GradientOrigin = _bokehData.StarPoint,
                Center = _bokehData.StarPoint,
                RadiusX = _bokehData.RadiusX,
                RadiusY = _bokehData.RadiusY,
                GradientStops = collection,
            };
            Rectangle rectangle = new Rectangle()
            {
                Width = DataManager.Instance.MainData.PixelWidth,
                Height = DataManager.Instance.MainData.PixelHeight,
                Fill = _bokehData.MaskBrush,
                OpacityMask = brush
            };
            Canvas saveCanvas = new Canvas()
            {
                Width = rectangle.Width,
                Height = rectangle.Height,
                Background = new ImageBrush() { ImageSource = DataManager.Instance.MainData },
            };
            saveCanvas.Children.Add(rectangle);

            WriteableBitmap bmp = new WriteableBitmap(saveCanvas, null);
            DataManager.Instance.SaveToFile(bmp);
        }
Ejemplo n.º 8
0
        public Feature AddFeature(String Id, GeoCoordinate GeoCoordinate, Double Width, Double Height, Color Color)
        {
            var radialBrush = new RadialGradientBrush();
            var ColorHigh = Color; ColorHigh.A = 0xFF;
            var ColorLow  = Color; ColorLow.A  = 0x00;

            radialBrush.GradientStops.Add(new GradientStop(ColorHigh, 0.0));
            radialBrush.GradientStops.Add(new GradientStop(ColorLow,  1.0));

            var XY = GeoCalculations.WorldCoordinates_2_Screen(GeoCoordinate.Latitude, GeoCoordinate.Longitude, ZoomLevel);

            var Feature              = new Feature(new EllipseGeometry() { RadiusX = Width/2, RadiusY = Height/2 });
            Feature.Id               = Id;
            Feature.Latitude         = GeoCoordinate.Latitude;
            Feature.Longitude        = GeoCoordinate.Longitude;
            Feature.Width            = Width;
            Feature.Height           = Height;
            Feature.Fill             = radialBrush;
            Feature.ToolTip          = Id;

            // The position on the map will be set within the PaintMap() method!
            this.Children.Add(Feature);

            return Feature;
        }
Ejemplo n.º 9
0
        public ParticleSystem(int maxCount, System.Windows.Media.Color color)
        {
            this.maxParticleCount = maxCount;

            this.particleList = new List<Particle>();

            this.particleModel = new GeometryModel3D();
            this.particleModel.Geometry = new MeshGeometry3D();

            Ellipse e = new Ellipse();
            e.Width = 32.0;
            e.Height = 32.0;
            RadialGradientBrush b = new RadialGradientBrush();
            b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0xFF, color.R, color.G, color.B), 0.25));
            b.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromArgb(0x00, color.R, color.G, color.B), 1.0));
            e.Fill = b;
            e.Measure(new System.Windows.Size(32, 32));
            e.Arrange(new Rect(0, 0, 32, 32));

            var brush = new VisualBrush(e);

            DiffuseMaterial material = new DiffuseMaterial(brush);

            this.particleModel.Material = material;

            this.rand = new Random(brush.GetHashCode());
        }
		private void OnMouseLeave(object sender, RoutedEventArgs e)
		{
			GradientStopCollection stopCollection = new GradientStopCollection();
			stopCollection.Add(new GradientStop(Colors.Blue, 0.05));
			stopCollection.Add(new GradientStop(Colors.LightBlue, 0.95));
			RadialGradientBrush brush = new RadialGradientBrush(stopCollection);
			circle.Fill = brush;		
		}
Ejemplo n.º 11
0
 /// <summary>
 ///     Set brush
 /// </summary>
 /// <param name="RadialGradientBrush">Radial gradient brush</param>
 /// <remarks>This method sets BrushOpacity.</remarks>
 public void SetBrush
 (
     SysMedia.RadialGradientBrush RadialGradientBrush
 )
 {
     NonStroking  = RadialGradientBrush;
     BrushOpacity = RadialGradientBrush.Opacity;
 }
 public ClickTheGradientCenter()
 {
     Title = "Click The Gradient Center";
     brush = new RadialGradientBrush(Colors.White, Colors.Red);
     brush.RadiusX = brush.RadiusY = 0.10;
     brush.SpreadMethod = GradientSpreadMethod.Repeat;
     Background = brush;
 }
Ejemplo n.º 13
0
        private void ConfigurarComponenteVisualArticulacao(Shape pForma, int pDiametroArticulacao,
            int pLarguraDesenho, Brush pCorDesenho, bool pPreencheComGradiente, bool pColorirGradienteMesmaCorDoPincel)
        {
            pForma.Height = pDiametroArticulacao;
            pForma.Width = pDiametroArticulacao;
            pForma.StrokeThickness = pLarguraDesenho;

            if (pPreencheComGradiente)
            {
                pForma.Stroke = Brushes.Black;

                RadialGradientBrush lGradiente = new RadialGradientBrush();
                lGradiente.GradientOrigin = new Point(0.5, 0.5);
                lGradiente.Center = new Point(0.5, 0.5);
                lGradiente.RadiusX = 0.5;
                lGradiente.RadiusY = 0.5;

                Color lCor1;
                Color lCor2;

                if (pColorirGradienteMesmaCorDoPincel)
                {
                    if (pCorDesenho == Brushes.Green)
                    {
                        lCor1 = Colors.Lime;
                        lCor2 = Colors.DarkGreen;
                    }
                    else if (pCorDesenho == Brushes.Blue)
                    {
                        lCor1 = Colors.RoyalBlue;
                        lCor2 = Colors.DarkBlue;
                    }
                    else
                    {
                        lCor1 = Colors.OrangeRed;
                        lCor2 = Colors.DarkRed;
                    }
                }
                else
                {
                    lCor1 = Colors.OrangeRed;
                    lCor2 = Colors.DarkRed;
                }

                //lCor1 = Colors.Lime;
                //lCor2 = Colors.DarkGreen;

                lGradiente.GradientStops.Add(new GradientStop(lCor1, 0.5));

                lGradiente.GradientStops.Add(new GradientStop(lCor2, 1));

                pForma.Fill = lGradiente;
            }
            else
            {
                pForma.Stroke = pCorDesenho;
            }
        }
Ejemplo n.º 14
0
 public static Brush GetGradientBrush(Color color)
 {
     RadialGradientBrush myBrush = new RadialGradientBrush();
      myBrush.GradientOrigin = new Point(0.75, 0.25);
      myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(50), 0.0));
      myBrush.GradientStops.Add(new GradientStop(color, 0.5));
      myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(-50), 1.0));
      return myBrush;
 }
        RadialGradientBrush BackGradient()
        {
            RadialGradientBrush rgb
                = new RadialGradientBrush()
                {
                    GradientOrigin = new Point(_rnd.NextDouble(), _rnd.NextDouble()),
                    Center = new Point(_rnd.NextDouble(), _rnd.NextDouble()),
                    RadiusX = _rnd.NextDouble(),
                    RadiusY = _rnd.NextDouble()
                };

            // Beginning of gradient offset
            rgb.GradientStops.Add(
                new GradientStop(new Color()
                {
                    R = (byte)_rnd.Next(255),
                    G = (byte)_rnd.Next(255),
                    B = (byte)_rnd.Next(255),
                    A = 255
                }, 0.0
                    )
                );

            // Scrambled middle gradients
            for (int i = 0; i < _rnd.Next(5); i++)
            {
                rgb.GradientStops.Add(
                    new GradientStop(
                        new Color()
                        {
                            R = (byte)_rnd.Next(255),
                            G = (byte)_rnd.Next(255),
                            B = (byte)_rnd.Next(255),
                            A = 255
                        }
                            , _rnd.NextDouble()
                            )
                        );
            }

            // Ending of gradient offset
            rgb.GradientStops.Add(
                new GradientStop(
                    new Color()
                    {
                        R = (byte)_rnd.Next(255),
                        G = (byte)_rnd.Next(255),
                        B = (byte)_rnd.Next(255),
                        A = 255
                    }, 1.0
                    )
                );

            rgb.Freeze();

            return rgb;
        }
Ejemplo n.º 16
0
 protected override void OnRender(DrawingContext dc)
 {
     RadialGradientBrush brush = new RadialGradientBrush(
         IsPressed ? SystemColors.ControlDarkColor : SystemColors.ControlLightLightColor,
         SystemColors.ControlColor);
     brush.GradientOrigin = IsPressed ? new Point(0.75, 0.75) : new Point(0.25, 0.25);
     dc.DrawRoundedRectangle(brush, new Pen(SystemColors.ControlDarkDarkBrush, 1),
         new Rect(new Point(0, 0), RenderSize), RenderSize.Height/2, RenderSize.Height/2);
 }
Ejemplo n.º 17
0
        public static System.Windows.Media.RadialGradientBrush GetGradientColorBrush(string colorName)
        {
            Color color = (Color)ColorConverter.ConvertFromString(colorName);

            System.Windows.Media.RadialGradientBrush brush = new System.Windows.Media.RadialGradientBrush();
            brush.GradientStops.Add(new GradientStop(color, 1.0));
            brush.GradientStops.Add(new GradientStop(Colors.White, 0.05));
            return(brush);
        }
Ejemplo n.º 18
0
		public BrushEditor()
		{
			GradientStopCollection stops = new GradientStopCollection();
			stops.Add(new GradientStop(Colors.Black, 0));
			stops.Add(new GradientStop(Colors.White, 1));

			linearGradientBrush = new LinearGradientBrush(stops);
			linearGradientBrush.EndPoint = new Point(1, 0);
			radialGradientBrush = new RadialGradientBrush(stops);
		}
        public Media.Brush GetRarityBrush(Card card)
        {
            Logger.ConditionalTrace("Start GetRarityBrush");
            Media.Brush returnValue = null;
            if ((card != null) && (card != Card.Unknown))
            {
                switch (card.Rarity)
                {
                case CardRarity.Common:
                    returnValue = new Media.RadialGradientBrush(
                        Media.Color.FromArgb(255, 115, 115, 115),
                        Media.Color.FromArgb(255, 200, 200, 200))
                    {
                        RadiusX = 0.6, RadiusY = 0.6
                    };
                    break;

                case CardRarity.Rare:
                    returnValue = new Media.RadialGradientBrush(
                        Media.Color.FromArgb(255, 72, 132, 226),
                        Media.Color.FromArgb(255, 135, 195, 224))
                    {
                        RadiusX = 0.6, RadiusY = 0.6
                    };
                    break;

                case CardRarity.Epic:
                    returnValue = new Media.RadialGradientBrush(
                        Media.Color.FromArgb(255, 138, 43, 226),
                        Media.Color.FromArgb(255, 204, 84, 199))
                    {
                        RadiusX = 0.6, RadiusY = 0.6
                    };
                    break;

                case CardRarity.Legendary:
                    returnValue = new Media.RadialGradientBrush(
                        Media.Color.FromArgb(255, 240, 154, 35),
                        Media.Color.FromArgb(255, 255, 255, 40))
                    {
                        RadiusX = 0.6, RadiusY = 0.6
                    };
                    break;

                default:
                    throw new NotImplementedException("Unknown card rarity");
                }
            }
            else
            {
                returnValue = new Media.SolidColorBrush(Media.Color.FromArgb(255, 255, 255, 255));
            }
            Logger.ConditionalTrace("End GetRarityBrush");
            return(returnValue);
        }
 public MainWindow()
 {
     Title = "Click the Gradient Center";
     brush = new RadialGradientBrush(Colors.White, Colors.Red);
     brush.RadiusX = brush.RadiusY = 0.10;
     brush.SpreadMethod = GradientSpreadMethod.Repeat;
     //BorderBrush = Brushes.SaddleBrown;
        // BorderThickness = new Thickness(25, 50, 75, 100);
     Background = brush;
     InitializeComponent();
 }
Ejemplo n.º 21
0
		public void CollectionCtorSingle ()
		{
			GradientStopCollection gsc = new GradientStopCollection ();
			gsc.Add (new GradientStop ());
			RadialGradientBrush rgb = new RadialGradientBrush (gsc);
			Assert.IsTrue (Object.ReferenceEquals (gsc, rgb.GradientStops), "Same GradientStops");

			GradientStop gs1 = rgb.GradientStops [0];
			Assert.AreEqual ("#00000000", gs1.Color.ToString (), "1.Color");
			Assert.AreEqual (0.0, gs1.Offset, "1.Offset");
		}
Ejemplo n.º 22
0
 /// <summary>
 /// PDF radial shading constructor for one unit bounding box
 /// </summary>
 /// <param name="Document">Parent PDF document object.</param>
 /// <param name="MediaBrush">System.Windows.Media brush</param>
 /// <remarks>Support for WPF media</remarks>
 public PdfRadialShading
 (
     PdfDocument Document,
     SysMedia.RadialGradientBrush MediaBrush
 ) : this(Document, 0.0, 0.0, 1.0, 1.0, new PdfShadingFunction(Document, MediaBrush))
 {
     SetGradientDirection(MediaBrush.Center.X, MediaBrush.Center.Y, 0.0,
                          MediaBrush.GradientOrigin.X, MediaBrush.GradientOrigin.Y, 0.5 * (MediaBrush.RadiusX + MediaBrush.RadiusY),
                          MediaBrush.MappingMode == SysMedia.BrushMappingMode.RelativeToBoundingBox ? MappingMode.Relative : MappingMode.Absolute);
     return;
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var start = new GradientStop { Offset = 0.9, Color = ((Color) value) };
            var stop = new GradientStop { Offset = 1, Color = Colors.Transparent };

            var result = new RadialGradientBrush
                         	{
                         		GradientStops = new GradientStopCollection {start, stop}
                         	};

            return result;
        }
Ejemplo n.º 24
0
		public void ColorsCtor ()
		{
			RadialGradientBrush rgb = new RadialGradientBrush (Colors.Black, Colors.White);

			GradientStop gs1 = rgb.GradientStops [0];
			Assert.AreEqual ("#FF000000", gs1.Color.ToString (), "1.Color");
			Assert.AreEqual (0.0, gs1.Offset, "1.Offset");

			GradientStop gs2 = rgb.GradientStops [1];
			Assert.AreEqual ("#FFFFFFFF", gs2.Color.ToString (), "2.Color");
			Assert.AreEqual (1.0, gs2.Offset, "2.Offset");
		}
Ejemplo n.º 25
0
        public BasicLED()
        {
            InitializeComponent();

            ellipseRGB = ellipse.Fill as RadialGradientBrush;
            ellipseRGB_GS1 = ellipseRGB.GradientStops[0];
            ellipseRGB_GS2 = ellipseRGB.GradientStops[1];

            lastIsActive = false;
            lastActiveColor = lastInactiveColor = ellipseRGB_GS2.Color;
            lastHighlightColor = ellipseRGB_GS1.Color;
            lastBorderWidth = ellipse.StrokeThickness;
        }
        internal override WpfBrush RealizeWpfBrush()
        {
            //if (this.dirty)
            //{
            //  if (this.brush == null)
            //    this.brush = new SolidBrush(this.color.ToGdiColor());
            //  else
            //  {
            //    this.brush.Color = this.color.ToGdiColor();
            //  }
            //  this.dirty = false;
            //}

            WpfRadialGradientBrush brush;

#if !SILVERLIGHT
            brush         = new WpfRadialGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor());
            brush.RadiusX = OuterRadius;
            brush.RadiusY = OuterRadius;
            //brush = new System.Drawing.Drawing2D.LinearGradientBrush(
            //  this.point1.ToPointF(), this.point2.ToPointF(),
            //  this.color1.ToGdiColor(), this.color2.ToGdiColor());
#else
            GradientStop gs1 = new GradientStop();
            gs1.Color  = _color1.ToWpfColor();
            gs1.Offset = 0;

            GradientStop gs2 = new GradientStop();
            gs2.Color  = _color2.ToWpfColor();
            gs2.Offset = 1;

            GradientStopCollection gsc = new GradientStopCollection();
            gsc.Add(gs1);
            gsc.Add(gs2);

            brush         = new WpfRadialGradientBrush(_color1.ToWpfColor(), _color2.ToWpfColor());
            brush.RadiusX = OuterRadius;
            brush.RadiusY = OuterRadius;
#endif
            if (!_matrix.IsIdentity)
            {
#if !SILVERLIGHT
                brush.Transform = new MatrixTransform(_matrix.ToWpfMatrix());
#else
                MatrixTransform transform = new MatrixTransform();
                transform.Matrix = _matrix.ToWpfMatrix();
                brush.Transform  = transform;
#endif
            }
            return(brush); //this.brush;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Handles the click event on the Koch Snowflake button
        /// </summary>
        /// <param name="sender">The object generating the event</param>
        /// <param name="e">RoutedEventArgs event arguments</param>
        private void BtnSnowflake_Click(object sender, RoutedEventArgs e)
        {
            // set up the canvas background brush and instantiate the window with it
            GradientStopCollection gradStop = new GradientStopCollection();
            gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF88ADD8"), 0.947));
            gradStop.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF235087"), 0.992));
            gradStop.Add(new GradientStop(Colors.White, 0));
            RadialGradientBrush brushBG = new RadialGradientBrush(gradStop);
            FractalWindow winFrac = new FractalWindow(brushBG);

            // setup the fractal we're going to draw and put it in the FractalWindow object
            LineBendingFractal fractal = new LineBendingFractal();
            winFrac.HostedFractal = fractal;
            winFrac.Show();
        }
Ejemplo n.º 28
0
        public override void Start()
        {
            base.Start();

            defaultColor = Model.Model.GetColor("Color", Colors.Red);
            radialGradientBrush = new RadialGradientBrush(defaultColor, Color.FromArgb(30, defaultColor.R, defaultColor.G, defaultColor.B));

            var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => Poi.PositionChanged += ev, ev => Poi.PositionChanged -= ev);
            posChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k => Calculate());

            var labelChanged = Observable.FromEventPattern<LabelChangedEventArgs>(ev => Poi.LabelChanged += ev, ev => Poi.LabelChanged -= ev);
            labelChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k => LabelChanged(k.EventArgs.Label));

            Calculate();
        }
Ejemplo n.º 29
0
        public CircleTheRainbow()
        {
            Title = "Circle the Rainbow";

            RadialGradientBrush brush = new RadialGradientBrush();
            Background = brush;

            brush.GradientStops.Add(new GradientStop(Colors.Red, 0));
            brush.GradientStops.Add(new GradientStop(Colors.Orange, .17));
            brush.GradientStops.Add(new GradientStop(Colors.Yellow, .33));
            brush.GradientStops.Add(new GradientStop(Colors.Green, .5));
            brush.GradientStops.Add(new GradientStop(Colors.Blue, .67));
            brush.GradientStops.Add(new GradientStop(Colors.Indigo, .84));
            brush.GradientStops.Add(new GradientStop(Colors.Violet, 1));
        }
Ejemplo n.º 30
0
        public SingleLed()
        {
            this.Resources.MergedDictionaries.Add(SharedDictionaryManager.SharedDictionary);

            blueOn = this.Resources["blueOn"] as RadialGradientBrush;
            blueOff = this.Resources["blueOff"] as RadialGradientBrush;
            greenOn = this.Resources["greenOn"] as RadialGradientBrush;
            greenOff = this.Resources["greenOff"] as RadialGradientBrush;
            orangeOn = this.Resources["orangeOn"] as RadialGradientBrush;
            orangeOff = this.Resources["orangeOff"] as RadialGradientBrush;
            redOn = this.Resources["redOn"] as RadialGradientBrush;
            redOff = this.Resources["redOff"] as RadialGradientBrush;

            this.InitializeComponent();
        }
Ejemplo n.º 31
0
        private void canvasDrawingArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Shape shapeToRender = null;

            // configure the correct shape to draw.
            switch (currentShape)
            {
                case SelectedShape.Circle:
                    shapeToRender = new Ellipse() { Height = 35, Width = 35 };
                    RadialGradientBrush brush = new RadialGradientBrush();
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF87E71B"), 0.589));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF2BA92B"), 0.013));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF34B71B"), 1));
                    shapeToRender.Fill = brush;
                    break;
                case SelectedShape.Rectangle:
                    shapeToRender = new Rectangle() { Fill = Brushes.Red, Height = 35, Width = 35, RadiusX = 10, RadiusY = 10 };
                    break;
                case SelectedShape.Line:
                    shapeToRender = new Line()
                    {
                        Stroke = Brushes.Blue,
                        StrokeThickness = 10,
                        X1 = 0,
                        X2 = 50,
                        Y1 = 0,
                        Y2 = 50,
                        StrokeStartLineCap = PenLineCap.Triangle,
                        StrokeEndLineCap = PenLineCap.Round
                    };
                    break;
                default:
                    return;
            }

            if (isFlipped)
            {
                RotateTransform rotate = new RotateTransform(-180);
                shapeToRender.RenderTransform = rotate;
            }

            // Set top / left to draw in the canvas.
            Canvas.SetLeft(shapeToRender, e.GetPosition(canvasDrawingArea).X);
            Canvas.SetTop(shapeToRender, e.GetPosition(canvasDrawingArea).Y);

            // Draw shape!
            canvasDrawingArea.Children.Add(shapeToRender);
        }
        private RadialGradientBrush getBrush(PuckColor pc)
        {
            var brush = new RadialGradientBrush { GradientOrigin = new Point(0.65, 0.25) };

            switch (pc)
            {
                case PuckColor.Blue:
                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("White")),
                        Offset = 0.0
                    });

                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("#FF4777CE")),
                        Offset = 0.5
                    });

                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("Blue")),
                        Offset = 1.0
                    });
                    break;
                case PuckColor.Red:
                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("White")),
                        Offset = 0.0
                    });

                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("#FFD85A5A")),
                        Offset = 0.5
                    });

                    brush.GradientStops.Add(new GradientStop
                    {
                        Color = ((Color)ColorConverter.ConvertFromString("Red")),
                        Offset = 1.0
                    });
                    break;
            }//switch

            return brush;
        }
Ejemplo n.º 33
0
 public PathCanvasGradient(double x0, double y0, double r0, double x1, double y1, double r1)
 {
     _brush = new RadialGradientBrush();
     _brush.GradientOrigin = new Point(x0, y0);
     _brush.Center = new Point(x1, y1);
     _brush.MappingMode = BrushMappingMode.Absolute;
     _brush.RadiusX = r1;
     _brush.RadiusY = r1;
     _brush.SpreadMethod = GradientSpreadMethod.Pad;
     _innerRadius = r0;
     _outerRadius = r1;
     double rMin = Math.Min(r0, r1);
     double rMax = Math.Max(r0, r1);
     OffsetMinimum = rMin/rMax;
     OffsetMultiplier = (rMax - rMin)/rMax;
 }
Ejemplo n.º 34
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/Talentos_Master;component/ButtonSeven.xaml", System.UriKind.Relative));
     this.animEnter          = ((System.Windows.Media.Animation.Storyboard)(this.FindName("animEnter")));
     this.animLeave          = ((System.Windows.Media.Animation.Storyboard)(this.FindName("animLeave")));
     this.LayoutRoot         = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.brushLight         = ((System.Windows.Media.RadialGradientBrush)(this.FindName("brushLight")));
     this.transitionColor    = ((System.Windows.Media.GradientStop)(this.FindName("transitionColor")));
     this.transitionSubColor = ((System.Windows.Media.GradientStop)(this.FindName("transitionSubColor")));
     this.imgItem            = ((System.Windows.Controls.Image)(this.FindName("imgItem")));
 }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            RadialGradientBrush brush = new RadialGradientBrush();
            brush.MappingMode = BrushMappingMode.Absolute;
            var mainColor = (((value as Path).Tag as PieDataPoint).DataItem as DetailedInfo).MainColor;
            var secondColor = (((value as Path).Tag as PieDataPoint).DataItem as DetailedInfo).SecondColor;

            brush.GradientStops.Add(new GradientStop { Color = Telerik.Windows.Controls.ColorEditor.ColorConverter.ColorFromString(mainColor), Offset = 0.4 });
            brush.GradientStops.Add(new GradientStop { Color = Telerik.Windows.Controls.ColorEditor.ColorConverter.ColorFromString(secondColor), Offset = 1});

            BindingOperations.SetBinding(brush, RadialGradientBrush.CenterProperty, new Binding("Data.Figures[0].StartPoint") { Source = value });
            BindingOperations.SetBinding(brush, RadialGradientBrush.GradientOriginProperty, new Binding("Data.Figures[0].StartPoint") { Source = value });
            BindingOperations.SetBinding(brush, RadialGradientBrush.RadiusXProperty, new Binding("Data") { Source = value, Converter = pathGeometryToRadiusConverter });
            BindingOperations.SetBinding(brush, RadialGradientBrush.RadiusYProperty, new Binding("Data") { Source = value, Converter = pathGeometryToRadiusConverter });
            return brush;
        }
        public static void DrawEllipse(Point p, Canvas canvas)
        {
            Ellipse ellipse = new Ellipse();
            ellipse.Uid = "Ellipse";
            ellipse.Height = 10;
            ellipse.Width = 10;
            RadialGradientBrush brush = new RadialGradientBrush();

            brush.GradientStops.Add(new GradientStop(Colors.Red, 0.250));
            brush.GradientStops.Add(new GradientStop(Colors.Red, 0.100));
            brush.GradientStops.Add(new GradientStop(Colors.Red, 8));
            ellipse.Fill = brush;
            Canvas.SetLeft(ellipse, p.X);
            Canvas.SetTop(ellipse, p.Y);

            canvas.Children.Add(ellipse);
        }
Ejemplo n.º 37
0
 public object Convert(
     object value,
     Type targetType,
     object parameter,
     CultureInfo culture)
 {
     Color c = (Color)value;
     RadialGradientBrush radBrush = new RadialGradientBrush();
     GradientStop g1 = new GradientStop();
     g1.Offset = 0.982;
     g1.Color = c;
     GradientStop g2 = new GradientStop();
     g2.Color = Color.FromArgb(0xFF, 0xAF, 0xB2, 0xB0);
     radBrush.GradientStops.Add(g1);
     radBrush.GradientStops.Add(g2);
     return radBrush;
 }
Ejemplo n.º 38
0
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/Hoan_Xich_Huong;component/MainPage.xaml", System.UriKind.Relative));
     this.LayoutRoot         = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.move_light         = ((System.Windows.Media.Animation.Storyboard)(this.FindName("move_light")));
     this.light_bottom       = ((System.Windows.Media.RadialGradientBrush)(this.FindName("light_bottom")));
     this.main_title         = ((System.Windows.Controls.TextBlock)(this.FindName("main_title")));
     this.title_shadow       = ((System.Windows.Media.Effects.DropShadowEffect)(this.FindName("title_shadow")));
     this.menu_mouse_enter_1 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_1")));
     this.menu_mouse_enter_2 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_2")));
     this.menu_mouse_enter_3 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_3")));
     this.menu_mouse_enter_4 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_4")));
     this.menu_mouse_enter_5 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_5")));
     this.menu_mouse_enter_6 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_6")));
     this.menu_mouse_enter_7 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_enter_7")));
     this.menu_mouse_leave_1 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_1")));
     this.menu_mouse_leave_2 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_2")));
     this.menu_mouse_leave_3 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_3")));
     this.menu_mouse_leave_4 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_4")));
     this.menu_mouse_leave_5 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_5")));
     this.menu_mouse_leave_6 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_6")));
     this.menu_mouse_leave_7 = ((System.Windows.Media.Animation.Storyboard)(this.FindName("menu_mouse_leave_7")));
     this.menu_bar           = ((System.Windows.Controls.Grid)(this.FindName("menu_bar")));
     this.trangchu           = ((System.Windows.Controls.Label)(this.FindName("trangchu")));
     this.solid1             = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid1")));
     this.clbhoanxichhuong   = ((System.Windows.Controls.Label)(this.FindName("clbhoanxichhuong")));
     this.solid2             = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid2")));
     this.hoidap             = ((System.Windows.Controls.Label)(this.FindName("hoidap")));
     this.solid3             = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid3")));
     this.tietnieu           = ((System.Windows.Controls.Label)(this.FindName("tietnieu")));
     this.solid4             = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid4")));
     this.video           = ((System.Windows.Controls.Label)(this.FindName("video")));
     this.solid5          = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid5")));
     this.tintuc          = ((System.Windows.Controls.Label)(this.FindName("tintuc")));
     this.solid6          = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid6")));
     this.lienhe          = ((System.Windows.Controls.Label)(this.FindName("lienhe")));
     this.solid7          = ((System.Windows.Media.SolidColorBrush)(this.FindName("solid7")));
     this.viewer          = ((System.Windows.Controls.Grid)(this.FindName("viewer")));
     this.Grid3           = ((System.Windows.Controls.Grid)(this.FindName("Grid3")));
     this.under_textblock = ((System.Windows.Controls.TextBlock)(this.FindName("under_textblock")));
 }
Ejemplo n.º 39
0
        public static Sm.RadialGradientBrush ToMediaBrush(this Wg.GradientRadial input)
        {
            Sm.RadialGradientBrush brush = new Sm.RadialGradientBrush();
            int i = 0;

            foreach (Wg.Color color in input.Colors)
            {
                brush.GradientStops.Add(new Sm.GradientStop(color.ToMediaColor(), input.Stops[i]));
                i++;
            }

            brush.SpreadMethod = Sm.GradientSpreadMethod.Pad;
            brush.MappingMode  = Sm.BrushMappingMode.RelativeToBoundingBox;

            brush.Center         = new Point(input.Center.X, input.Center.Y);
            brush.GradientOrigin = new Point(input.Focus.X, input.Focus.Y);
            brush.RadiusX        = input.RadiusX;
            brush.RadiusY        = input.RadiusY;

            return(brush);
        }
Ejemplo n.º 40
0
        public Microsoft.WindowsAPICodePack.DirectX.Direct2D1.Brush GetDirectXBrush(System.Windows.Media.Brush mediaBrush)
        {
            if (mediaBrush is System.Windows.Media.SolidColorBrush)
            {
                return(GetDirectXBrush(((System.Windows.Media.SolidColorBrush)mediaBrush).Color));
            }
            else if (mediaBrush is System.Windows.Media.RadialGradientBrush)
            {
                System.Windows.Media.RadialGradientBrush mediaRadialBrush = (mediaBrush as System.Windows.Media.RadialGradientBrush);
                RadialGradientBrushProperties            properties       = new RadialGradientBrushProperties(mediaRadialBrush.Center.AsDirectX2DPoint(), mediaRadialBrush.GradientOrigin.AsDirectX2DPoint(), (float)mediaRadialBrush.RadiusX, (float)mediaRadialBrush.RadiusY);
                List <Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop> stopCollection = new List <Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop>();
                foreach (var stop in mediaRadialBrush.GradientStops)
                {
                    stopCollection.Add(new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStop((float)stop.Offset, new ColorF((float)stop.Color.R, ((float)stop.Color.G / 255), ((float)stop.Color.B / 255), ((float)stop.Color.A / 255))));
                }
                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.GradientStopCollection stops = this.RenderTarget.CreateGradientStopCollection(stopCollection, Gamma.StandardRgb, ExtendMode.Wrap);

                Microsoft.WindowsAPICodePack.DirectX.Direct2D1.RadialGradientBrush radialBrush = this.RenderTarget.CreateRadialGradientBrush(properties, stops);
                return(radialBrush);
            }
            return(null);
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Returns a Windows brush from the NGraphics brush
        /// </summary>
        /// <param name="fromBrush"></param>
        /// <returns></returns>
        private System.Windows.Media.Brush GetBrush(NGraphics.Brush fromBrush)
        {
            var sb = fromBrush as SolidBrush;

            if (sb != null)
            {
                // Solid brush
                return(new SolidColorBrush(new System.Windows.Media.Color
                {
                    A = sb.Color.A,
                    R = sb.Color.R,
                    G = sb.Color.G,
                    B = sb.Color.B
                }));
            }

            var lb = fromBrush as NGraphics.LinearGradientBrush;

            if (lb != null)
            {
                // Linear gradient
                var gradStops = new GradientStopCollection();
                var n         = lb.Stops.Count;
                if (n >= 2)
                {
                    var locs  = new float[n];
                    var comps = new int[n];
                    for (var i = 0; i < n; i++)
                    {
                        var s = lb.Stops[i];
                        gradStops.Add(new System.Windows.Media.GradientStop
                        {
                            Color = new System.Windows.Media.Color
                            {
                                A = s.Color.A,
                                R = s.Color.R,
                                B = s.Color.B,
                                G = s.Color.G,
                            },
                            Offset = s.Offset,
                        });
                    }
                }

                var grad = new System.Windows.Media.LinearGradientBrush(gradStops, 90);
                return(grad);
            }

            var rb = fromBrush as NGraphics.RadialGradientBrush;

            if (rb != null)
            {
                // Radial gradient
                var grad = new System.Windows.Media.RadialGradientBrush();
                var n    = rb.Stops.Count;
                if (n >= 2)
                {
                    var locs  = new float[n];
                    var comps = new int[n];
                    for (var i = 0; i < n; i++)
                    {
                        var s = rb.Stops[i];
                        grad.GradientStops.Add(new System.Windows.Media.GradientStop
                        {
                            Color = new System.Windows.Media.Color
                            {
                                A = s.Color.A,
                                R = s.Color.R,
                                B = s.Color.B,
                                G = s.Color.G,
                            },
                            Offset = s.Offset,
                        });
                    }
                }
                return(grad);
            }

            return(null);
        }
        void genView(Canvas can)
        {
            can.Children.Clear();

            for (int x = 0; x < cx; x++)
            {
                for (int y = 0; y < cy; y++)
                {
                    int iCnum = getCnum(x, y);

                    Ellipse ell = new System.Windows.Shapes.
                                  Ellipse();
                    ell.Name   = "v_" + sIdx(x) + "_" + sIdx(y);
                    ell.Width  = rcW;
                    ell.Height = rcH;
                    ell.Margin = new System.Windows.
                                 Thickness(rcG + (x * (rcG + rcW)),
                                           rcG + (y * (rcG + rcH)), 0, 0);

                    if (iCnum > 0)
                    {
                        if (b3D)
                        {
                            RadialGradientBrush br = new System.Windows.Media.
                                                     RadialGradientBrush();
                            br.Center = new System.Windows.
                                        Point(0.4, 0.4);
                            br.GradientOrigin = new System.Windows.
                                                Point(0.4, 0.4);

                            GradientStop gs1 = new System.Windows.Media.
                                               GradientStop();
                            gs1.Offset = 0;
                            gs1.Color  = System.Windows.Media.
                                         Colors.White;
                            br.GradientStops.Add(gs1);

                            GradientStop gs2 = new System.Windows.Media.
                                               GradientStop();
                            gs2.Offset = 1;
                            gs2.Color  = getCvalDir(iCnum);
                            br.GradientStops.Add(gs2);

                            ell.Fill = br;
                        }
                        else
                        {
                            ell.Fill = new System.Windows.Media.
                                       SolidColorBrush(getCvalDir(iCnum));
                        }
                    }
                    else
                    {
                        ell.Fill = host.UI.view.Background;
                    }

                    addClk(ell);

                    can.Children.Add(ell);
                }
            }
        }
Ejemplo n.º 43
0
        public static D.Brush MediaBrushToDrawingBrush(M.Brush in_brush)
        {
            if (in_brush is M.SolidColorBrush)
            {
                D.SolidBrush brush = new D.SolidBrush(
                    ColorUtils.MediaColorToDrawingColor((in_brush as M.SolidColorBrush).Color)
                    );

                return(brush);
            }
            else if (in_brush is M.LinearGradientBrush)
            {
                M.LinearGradientBrush lgb = (in_brush as M.LinearGradientBrush);

                D.PointF starting_point = new D.PointF(
                    (float)lgb.StartPoint.X,
                    (float)lgb.StartPoint.Y
                    );

                D.PointF ending_point = new D.PointF(
                    (float)lgb.EndPoint.X,
                    (float)lgb.EndPoint.Y
                    );

                D.Drawing2D.LinearGradientBrush brush = new D.Drawing2D.LinearGradientBrush(
                    starting_point,
                    ending_point,
                    D.Color.Red,
                    D.Color.Red
                    );

                /*
                 * switch(lgb.SpreadMethod)
                 * {
                 *  case System.Windows.Media.GradientSpreadMethod.Pad:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Reflect:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Repeat:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                 *      break;
                 * }
                 */

                SortedDictionary <float, D.Color> brush_blend = new SortedDictionary <float, D.Color>();

                foreach (var grad_stop in lgb.GradientStops)
                {
                    if (!brush_blend.ContainsKey((float)grad_stop.Offset))
                    {
                        brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color));
                    }
                }

                List <D.Color> brush_colors    = new List <D.Color>();
                List <float>   brush_positions = new List <float>();

                foreach (var kvp in brush_blend)
                {
                    brush_colors.Add(kvp.Value);
                    brush_positions.Add(kvp.Key);
                }

                D.Drawing2D.ColorBlend color_blend = new D.Drawing2D.ColorBlend();
                color_blend.Colors        = brush_colors.ToArray();
                color_blend.Positions     = brush_positions.ToArray();
                brush.InterpolationColors = color_blend;

                return(brush);
            }
            else if (in_brush is M.RadialGradientBrush)
            {
                M.RadialGradientBrush rgb = (in_brush as M.RadialGradientBrush);

                D.RectangleF brush_region = new D.RectangleF(
                    0.0f,
                    0.0f,
                    2.0f * (float)rgb.RadiusX,
                    2.0f * (float)rgb.RadiusY
                    );

                D.PointF center_point = new D.PointF(
                    (float)rgb.Center.X,
                    (float)rgb.Center.Y
                    );

                D.Drawing2D.GraphicsPath g_path = new D.Drawing2D.GraphicsPath();
                g_path.AddEllipse(brush_region);

                D.Drawing2D.PathGradientBrush brush = new D.Drawing2D.PathGradientBrush(g_path);

                brush.CenterPoint = center_point;

                /*
                 * switch (rgb.SpreadMethod)
                 * {
                 *  case System.Windows.Media.GradientSpreadMethod.Pad:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Reflect:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipXY;
                 *      break;
                 *  case System.Windows.Media.GradientSpreadMethod.Repeat:
                 *      brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                 *      break;
                 * }
                 */

                SortedDictionary <float, D.Color> brush_blend = new SortedDictionary <float, D.Color>();

                foreach (var grad_stop in rgb.GradientStops)
                {
                    if (!brush_blend.ContainsKey((float)grad_stop.Offset))
                    {
                        brush_blend.Add((float)grad_stop.Offset, ColorUtils.MediaColorToDrawingColor(grad_stop.Color));
                    }
                }

                List <D.Color> brush_colors    = new List <D.Color>();
                List <float>   brush_positions = new List <float>();

                foreach (var kvp in brush_blend)
                {
                    brush_colors.Add(kvp.Value);
                    brush_positions.Add(kvp.Key);
                }

                D.Drawing2D.ColorBlend color_blend = new D.Drawing2D.ColorBlend();
                color_blend.Colors        = brush_colors.ToArray();
                color_blend.Positions     = brush_positions.ToArray();
                brush.InterpolationColors = color_blend;

                return(brush);
            }
            else
            {
                return(new D.SolidBrush(System.Drawing.Color.Red)); //Return error color
            }
        }
Ejemplo n.º 44
0
        public static M.Brush DrawingBrushToMediaBrush(D.Brush in_brush)
        {
            if (in_brush is D.SolidBrush)
            {
                M.SolidColorBrush brush = new M.SolidColorBrush(
                    ColorUtils.DrawingColorToMediaColor((in_brush as D.SolidBrush).Color)
                    );

                return(brush);
            }
            else if (in_brush is D.Drawing2D.LinearGradientBrush)
            {
                D.Drawing2D.LinearGradientBrush lgb = (in_brush as D.Drawing2D.LinearGradientBrush);

                System.Windows.Point starting_point = new System.Windows.Point(
                    lgb.Rectangle.X,
                    lgb.Rectangle.Y
                    );

                System.Windows.Point ending_point = new System.Windows.Point(
                    lgb.Rectangle.Right,
                    lgb.Rectangle.Bottom
                    );

                M.GradientStopCollection collection = new M.GradientStopCollection();

                try
                {
                    if (lgb.InterpolationColors != null && lgb.InterpolationColors.Colors.Length == lgb.InterpolationColors.Positions.Length)
                    {
                        for (int x = 0; x < lgb.InterpolationColors.Colors.Length; x++)
                        {
                            collection.Add(
                                new M.GradientStop(
                                    ColorUtils.DrawingColorToMediaColor(lgb.InterpolationColors.Colors[x]),
                                    lgb.InterpolationColors.Positions[x]
                                    )
                                );
                        }
                    }
                }
                catch (Exception exc)
                {
                    for (int x = 0; x < lgb.LinearColors.Length; x++)
                    {
                        collection.Add(
                            new M.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(lgb.LinearColors[x]),
                                x / (double)(lgb.LinearColors.Length - 1)
                                )
                            );
                    }
                }

                M.LinearGradientBrush brush = new M.LinearGradientBrush(
                    collection,
                    starting_point,
                    ending_point
                    );

                return(brush);
            }
            else if (in_brush is D.Drawing2D.PathGradientBrush)
            {
                D.Drawing2D.PathGradientBrush pgb = (in_brush as D.Drawing2D.PathGradientBrush);

                System.Windows.Point starting_point = new System.Windows.Point(
                    pgb.CenterPoint.X,
                    pgb.CenterPoint.Y
                    );

                M.GradientStopCollection collection = new M.GradientStopCollection();

                if (pgb.InterpolationColors != null && pgb.InterpolationColors.Colors.Length == pgb.InterpolationColors.Positions.Length)
                {
                    for (int x = 0; x < pgb.InterpolationColors.Colors.Length; x++)
                    {
                        collection.Add(
                            new M.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(pgb.InterpolationColors.Colors[x]),
                                pgb.InterpolationColors.Positions[x]
                                )
                            );
                    }
                }

                M.RadialGradientBrush brush = new M.RadialGradientBrush(
                    collection
                    );

                brush.Center = starting_point;

                return(brush);
            }
            else
            {
                return(new M.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0))); //Return error color
            }
        }