Пример #1
0
		public async Task EllipseRadialGradient ()
		{
			var canvas = Platforms.Current.CreateImageCanvas (new Size (100));

			var rect = new Rect (0, 10, 100, 80);
			var brush = new RadialGradientBrush (
				new Point (0.5, 0.5),
				new Size (0.5, 0.125),
				Colors.Green,
				Colors.LightGray);				

			canvas.DrawEllipse (rect, brush: brush);

			await SaveImage (canvas, "Brush.EllipseRadialGradient.png");
		}
Пример #2
0
		public GradientWrapMode GetGradientWrap(RadialGradientBrush widget)
		{
			return ((swm.RadialGradientBrush)widget.ControlObject).SpreadMethod.ToEto();
		}
Пример #3
0
		public void SetTransform(RadialGradientBrush widget, IMatrix transform)
		{
			((swm.RadialGradientBrush)widget.ControlObject).Transform = transform.ToWpfTransform();
		}
Пример #4
0
		public IMatrix GetTransform(RadialGradientBrush widget)
		{
			return ((swm.RadialGradientBrush)widget.ControlObject).Transform.ToEtoMatrix();
		}
Пример #5
0
		public void SetGradientWrap(RadialGradientBrush widget, GradientWrapMode gradientWrap)
		{
			var brush = (RadialBrushData)widget.ControlObject;
			brush.WrapMode = gradientWrap;
			brush.Reset();
		}
Пример #6
0
 public string ToImageString(RadialGradientBrush brush)
 {
     return(ToRadialGradientString(brush));
 }
Пример #7
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            // Create an array of gradient stops to put in the gradient stop
            // collection that will be used in the gradient brush.
            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromARGB(Colors.Gold, 1)),
                new GradientStop(0.85f, Color.FromARGB(Colors.Orange, 1)),
                new GradientStop(1, Color.FromARGB(Colors.OrangeRed, 1))
            };

            using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                // The center of the gradient is in the center of the box.
                // The gradient origin offset was set to zero(0, 0) or center in this case.
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(
                        new PointF(330, 330),
                        new PointF(140, 140),
                        140,
                        140),
                        BrushProperties.Default,
                        gradiendStops);
            }

            this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
Пример #8
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(0x9ACD32, 1));

            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromARGB(Colors.Yellow, 1)),
                new GradientStop(1, Color.FromARGB(Colors.ForestGreen, 1))
            };

            using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                this._linearGradientBrush = renderTarget.CreateLinearGradientBrush(
                    new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)),
                    BrushProperties.Default,
                    collection);
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75),
                    BrushProperties.Default,
                    collection);
            }

            using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg"))
            {
                this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap,
                    new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear),
                    BrushProperties.Default);
            }

            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
Пример #9
0
        private static Brush CreateBrush(string solidBrushColor, XElement xComplexBrush)
        {
            if (solidBrushColor != null)
            {
                return(new SolidColorBrush((Color)ColorConverter.ConvertFromString(solidBrushColor)));
            }
            else if (xComplexBrush != null)
            {
                var nfi = new NumberFormatInfo();
                nfi.NumberDecimalSeparator = ".";

                GradientBrush gBrush = null;
                if (String.CompareOrdinal(xComplexBrush.Name.LocalName, "LinearGradientBrush") == 0)
                {
                    var lBrush = new LinearGradientBrush();
                    if (xComplexBrush.Attribute("StartPoint") != null)
                    {
                        var props = xComplexBrush.Attribute("StartPoint").Value.Split(',', ' ');
                        lBrush.StartPoint = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));
                    }
                    if (xComplexBrush.Attribute("EndPoint") != null)
                    {
                        var props = xComplexBrush.Attribute("EndPoint").Value.Split(',', ' ');
                        lBrush.EndPoint = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));
                    }
                    gBrush = lBrush;
                }
                else if (String.CompareOrdinal(xComplexBrush.Name.LocalName, "RadialGradientBrush") == 0)
                {
                    var rBrush = new RadialGradientBrush();
                    if (xComplexBrush.Attribute("Center") != null)
                    {
                        var props = xComplexBrush.Attribute("Center").Value.Split(',', ' ');
                        rBrush.Center = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));
                    }
                    if (xComplexBrush.Attribute("GradientOrigin") != null)
                    {
                        var props = xComplexBrush.Attribute("GradientOrigin").Value.Split(',', ' ');
                        rBrush.GradientOrigin = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi));
                    }
                    if (xComplexBrush.Attribute("RadiusX") != null)
                    {
                        rBrush.RadiusX = Double.Parse(xComplexBrush.Attribute("RadiusX").Value, nfi);
                    }
                    if (xComplexBrush.Attribute("RadiusY") != null)
                    {
                        rBrush.RadiusY = Double.Parse(xComplexBrush.Attribute("RadiusY").Value, nfi);
                    }
                    gBrush = rBrush;
                }
                else
                {
                    throw new Exception("Unknwon complex brush type: " + xComplexBrush.Name.LocalName);
                }
                if (gBrush != null)
                {
                    var xStops = from s in xComplexBrush.Elements("GradientStop")
                                 select new
                    {
                        Offset = (string)s.Attributes("Offset").FirstOrDefault(),
                        Color  = (string)s.Attributes("Color").FirstOrDefault()
                    };

                    foreach (var s in xStops)
                    {
                        var stop = new GradientStop();
                        if (s.Offset != null)
                        {
                            stop.Offset = Double.Parse(s.Offset, nfi);
                        }
                        if (s.Color != null)
                        {
                            stop.Color = (Color)ColorConverter.ConvertFromString(s.Color);
                        }
                        gBrush.GradientStops.Add(stop);
                    }
                    return(gBrush);
                }
            }
            return(null);
        }
Пример #10
0
        /// <summary>
        /// 将点加入到动画故事版
        /// </summary>
        /// <param name="runPoint">运动的点</param>
        /// <param name="toEll">达到城市的圆</param>
        /// <param name="sb">故事版</param>
        /// <param name="particlePath">运动轨迹</param>
        /// <param name="l">运动轨迹的直线距离</param>
        /// <param name="from">来自</param>
        /// <param name="toItem">去</param>
        private void AddPointToStoryboard(Grid runPoint, Ellipse toEll, Storyboard sb, Path particlePath, double l, ProvincialCapital from, MapToItem toItem)
        {
            double pointTime    = l / m_Speed;   //点运动所需的时间
            double particleTime = pointTime / 2; //轨迹呈现所需时间(跑的比点快两倍)

            #region 运动的点
            TransformGroup  tfg = new TransformGroup();
            MatrixTransform mtf = new MatrixTransform();
            tfg.Children.Add(mtf);
            TranslateTransform ttf = new TranslateTransform(-runPoint.Width / 2, -runPoint.Height / 2);//纠正最上角沿path运动到中心沿path运动
            tfg.Children.Add(ttf);
            runPoint.RenderTransform = tfg;

            MatrixAnimationUsingPath maup = new MatrixAnimationUsingPath();
            maup.PathGeometry          = particlePath.Data.GetFlattenedPathGeometry();
            maup.Duration              = new Duration(TimeSpan.FromSeconds(pointTime));
            maup.RepeatBehavior        = RepeatBehavior.Forever;
            maup.AutoReverse           = false;
            maup.IsOffsetCumulative    = false;
            maup.DoesRotateWithTangent = true;
            Storyboard.SetTarget(maup, runPoint);
            Storyboard.SetTargetProperty(maup, new PropertyPath("(Grid.RenderTransform).Children[0].(MatrixTransform.Matrix)"));
            sb.Children.Add(maup);
            #endregion

            #region 达到城市的圆
            //轨迹到达圆时 圆呈现
            DoubleAnimation ellda = new DoubleAnimation();
            ellda.From         = 0.2;//此处值设置0-1会有不同的呈现效果
            ellda.To           = 1;
            ellda.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            ellda.BeginTime    = TimeSpan.FromSeconds(particleTime);//推迟动画开始时间 等轨迹连接到圆时 开始播放圆的呈现动画
            ellda.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTarget(ellda, toEll);
            Storyboard.SetTargetProperty(ellda, new PropertyPath(Ellipse.OpacityProperty));
            sb.Children.Add(ellda);
            //圆呈放射状
            RadialGradientBrush rgBrush = new RadialGradientBrush();
            GradientStop        gStop0  = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            //此为控制点 color的a值设为0 off值走0-1 透明部分向外放射 初始设为255是为了初始化效果 开始不呈放射状 等跑动的点运动到城市的圆后 color的a值才设为0开始呈现放射动画
            GradientStop gStopT = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            GradientStop gStop1 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 1);
            rgBrush.GradientStops.Add(gStop0);
            rgBrush.GradientStops.Add(gStopT);
            rgBrush.GradientStops.Add(gStop1);
            toEll.OpacityMask = rgBrush;
            //跑动的点达到城市的圆时 控制点由不透明变为透明 color的a值设为0 动画时间为0
            ColorAnimation ca = new ColorAnimation();
            ca.To           = Color.FromArgb(0, 0, 0, 0);
            ca.Duration     = new Duration(TimeSpan.FromSeconds(0));
            ca.BeginTime    = TimeSpan.FromSeconds(pointTime);
            ca.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTarget(ca, toEll);
            Storyboard.SetTargetProperty(ca, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Color)"));
            sb.Children.Add(ca);
            //点达到城市的圆时 呈现放射状动画 控制点的off值走0-1 透明部分向外放射
            DoubleAnimation eda = new DoubleAnimation();
            eda.To             = 1;
            eda.Duration       = new Duration(TimeSpan.FromSeconds(2));
            eda.RepeatBehavior = RepeatBehavior.Forever;
            eda.BeginTime      = TimeSpan.FromSeconds(particleTime);
            Storyboard.SetTarget(eda, toEll);
            Storyboard.SetTargetProperty(eda, new PropertyPath("(Ellipse.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)"));
            sb.Children.Add(eda);
            #endregion

            #region 运动轨迹
            //找到渐变的起点和终点
            Point startPoint = GetProvincialCapitalPoint(from);
            Point endPoint   = GetProvincialCapitalPoint(toItem.To);
            Point start      = new Point(0, 0);
            Point end        = new Point(1, 1);
            if (startPoint.X > endPoint.X)
            {
                start.X = 1;
                end.X   = 0;
            }
            if (startPoint.Y > endPoint.Y)
            {
                start.Y = 1;
                end.Y   = 0;
            }
            LinearGradientBrush lgBrush = new LinearGradientBrush();
            lgBrush.StartPoint = start;
            lgBrush.EndPoint   = end;
            GradientStop lgStop0 = new GradientStop(Color.FromArgb(255, 0, 0, 0), 0);
            GradientStop lgStop1 = new GradientStop(Color.FromArgb(0, 0, 0, 0), 0);
            lgBrush.GradientStops.Add(lgStop0);
            lgBrush.GradientStops.Add(lgStop1);
            particlePath.OpacityMask = lgBrush;
            //运动轨迹呈现
            DoubleAnimation pda0 = new DoubleAnimation();
            pda0.To           = 1;
            pda0.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            pda0.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTarget(pda0, particlePath);
            Storyboard.SetTargetProperty(pda0, new PropertyPath("(Path.OpacityMask).(GradientBrush.GradientStops)[0].(GradientStop.Offset)"));
            sb.Children.Add(pda0);
            DoubleAnimation pda1 = new DoubleAnimation();
            //pda1.From = 0.5; //此处解开注释 值设为0-1 会有不同的轨迹呈现效果
            pda1.To           = 1;
            pda1.Duration     = new Duration(TimeSpan.FromSeconds(particleTime));
            pda1.FillBehavior = FillBehavior.HoldEnd;
            Storyboard.SetTarget(pda1, particlePath);
            Storyboard.SetTargetProperty(pda1, new PropertyPath("(Path.OpacityMask).(GradientBrush.GradientStops)[1].(GradientStop.Offset)"));
            sb.Children.Add(pda1);
            #endregion
        }
Пример #11
0
            public static void VCell(Vec location)
            {
                Vec   index     = chunkpos + location;
                Color cellcolor = BColors.BCList[Globe.GetChunk(index).BiomeID];

                Point cellcenter = new Point(Globe.GetChunk(index).BiomeCenter[0], Globe.GetChunk(index).BiomeCenter[1]);

                Biomes[(int)location[0] + 1, (int)location[1] + 1] = Globe.GetChunk(index).BiomeID;

                RadialGradientBrush cellbrush = new RadialGradientBrush()
                {
                    GradientOrigin = new Point(0.5, 0.5),
                    Center         = new Point(0.5, 0.5),
                    RadiusX        = 0.5,
                    RadiusY        = 0.5
                };

                cellbrush.GradientStops.Add(new GradientStop(cellcolor, 0.0));
                cellbrush.GradientStops.Add(new GradientStop(Color.Multiply(cellcolor, (float)0.75), 1.0));

                cellbrush.Freeze();

                Polygon cell = new Polygon()
                {
                    Fill = cellbrush
                };

                Cells[(int)location[0] + 1, (int)location[1] + 1] = cell;

                // voronoi from triangulation algorithm

                Vec[] t = new Vec[4];
                Vec   p;
                Vec   q;

                q = new Vec()
                {
                    -1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    0, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    0, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                Cells[(int)location[0] + 1, (int)location[1] + 1] = cell;
                MainWindow.App.map.Children.Add(cell);

                Bases.Draw(index, location);
            }
Пример #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Theme" /> class.
        /// </summary>
        /// <param name="themeName">Name of the theme</param>
        public Theme(string themeName)
        {
            this.Name = themeName;

            string filePath = Path.Combine("Themes", themeName + ".cattheme");

            XmlDocument configFile = new XmlDocument();

            configFile.Load(filePath);
            if (configFile.DocumentElement.Name == "CATTheme")
            {
                XmlNode catThemeNode = configFile.DocumentElement;
                if (catThemeNode.ChildNodes.Count > 0)
                {
                    foreach (XmlNode n in catThemeNode.ChildNodes)
                    {
                        switch (n.Name)
                        {
                        case "ButtonBorderThickness":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonBorderThickness = valueInt;
                            }
                        }

                        break;

                        case "ButtonPadding":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonPadding = valueInt;
                            }
                        }

                        break;

                        case "ButtonCornerRadius":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonCornerRadius = valueInt;
                            }
                        }

                        break;

                        case "ButtonBorderThickness2":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonBorderThickness2 = valueInt;
                            }
                        }

                        break;

                        case "ButtonPadding2":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonPadding2 = valueInt;
                            }
                        }

                        break;

                        case "ButtonCornerRadius2":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ButtonCornerRadius2 = valueInt;
                            }
                        }

                        break;

                        case "ToggleButtonBorderThickness":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ToggleButtonBorderThickness = valueInt;
                            }
                        }

                        break;

                        case "ToggleButtonPadding":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ToggleButtonPadding = valueInt;
                            }
                        }

                        break;

                        case "ToggleButtonCornerRadius":
                        {
                            string valueString = string.Empty;
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            uint valueInt;
                            if (uint.TryParse(valueString, out valueInt))
                            {
                                this.ToggleButtonCornerRadius = valueInt;
                            }
                        }

                        break;

                        default:
                        {
                            string valueString = "White";
                            if (n.Attributes["Value"] != null)
                            {
                                valueString = n.Attributes["Value"].InnerText.Trim();
                            }

                            string brushType = string.Empty;
                            if (n.Attributes["Type"] != null)
                            {
                                brushType = n.Attributes["Type"].InnerText.Trim();
                            }

                            string valueString2 = "White";
                            if (n.Attributes["Value2"] != null)
                            {
                                valueString2 = n.Attributes["Value2"].InnerText.Trim();
                            }

                            string gradientAngleString = "0";
                            if (n.Attributes["Angle"] != null)
                            {
                                gradientAngleString = n.Attributes["Angle"].InnerText.Trim();
                            }

                            string gradientStartString = "0,0";
                            if (n.Attributes["GradientStart"] != null)
                            {
                                gradientStartString = n.Attributes["GradientStart"].InnerText.Trim();
                            }

                            string gradientEndString = "0,0";
                            if (n.Attributes["GradientEnd"] != null)
                            {
                                gradientEndString = n.Attributes["GradientEnd"].InnerText.Trim();
                            }

                            double gradientAngle = 0;
                            Point  gradientStart = new Point(0, 0);
                            Point  gradientEnd   = new Point(0, 0);
                            double.TryParse(gradientAngleString, out gradientAngle);
                            try
                            {
                                gradientStart = Point.Parse(gradientStartString);
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                gradientEnd = Point.Parse(gradientEndString);
                            }
                            catch (Exception)
                            {
                            }

                            Color brushColor;
                            try
                            {
                                brushColor = (Color)ColorConverter.ConvertFromString(valueString);
                            }
                            catch (Exception)
                            {
                                brushColor = Colors.Black;
                            }

                            Color brushColor2;
                            try
                            {
                                brushColor2 = (Color)ColorConverter.ConvertFromString(valueString2);
                            }
                            catch (Exception)
                            {
                                brushColor2 = brushColor;
                            }

                            Brush brush;
                            if (brushType == "LinearGradient")
                            {
                                if (gradientStart == gradientEnd)
                                {
                                    brush = new LinearGradientBrush(brushColor, brushColor2, gradientAngle);
                                }
                                else
                                {
                                    brush = new LinearGradientBrush(brushColor, brushColor2, gradientStart, gradientEnd);
                                }
                            }
                            else if (brushType == "RadialGradient")
                            {
                                brush = new RadialGradientBrush(brushColor, brushColor2);
                            }
                            else
                            {
                                // Default to brushType == "Solid"
                                brush = new SolidColorBrush(brushColor);
                            }

                            switch (n.Name)
                            {
                            case "Foreground1":
                                this.Foreground1 = brush;
                                break;

                            case "Foreground2":
                                this.Foreground2 = brush;
                                break;

                            case "Foreground3":
                                this.Foreground3 = brush;
                                break;

                            case "Foreground4":
                                this.Foreground4 = brush;
                                break;

                            case "Background1":
                                this.Background1 = brush;
                                break;

                            case "Background2":
                                this.Background2 = brush;
                                break;

                            case "Background3":
                                this.Background3 = brush;
                                break;

                            case "Background4":
                                this.Background4 = brush;
                                break;

                            case "ButtonForeground":
                                this.ButtonForeground = brush;
                                break;

                            case "ButtonForegroundDisabled":
                                this.ButtonForegroundDisabled = brush;
                                break;

                            case "ButtonForegroundPressed":
                                this.ButtonForegroundPressed = brush;
                                break;

                            case "ButtonForegroundMouseOver":
                                this.ButtonForegroundMouseOver = brush;
                                break;

                            case "ButtonBackground":
                                this.ButtonBackground = brush;
                                break;

                            case "ButtonBackgroundDisabled":
                                this.ButtonBackgroundDisabled = brush;
                                break;

                            case "ButtonBackgroundPressed":
                                this.ButtonBackgroundPressed = brush;
                                break;

                            case "ButtonBackgroundMouseOver":
                                this.ButtonBackgroundMouseOver = brush;
                                break;

                            case "ButtonForeground2":
                                this.ButtonForeground2 = brush;
                                break;

                            case "ButtonForegroundDisabled2":
                                this.ButtonForegroundDisabled2 = brush;
                                break;

                            case "ButtonForegroundPressed2":
                                this.ButtonForegroundPressed2 = brush;
                                break;

                            case "ButtonForegroundMouseOver2":
                                this.ButtonForegroundMouseOver2 = brush;
                                break;

                            case "ButtonBackground2":
                                this.ButtonBackground2 = brush;
                                break;

                            case "ButtonBackgroundDisabled2":
                                this.ButtonBackgroundDisabled2 = brush;
                                break;

                            case "ButtonBackgroundPressed2":
                                this.ButtonBackgroundPressed2 = brush;
                                break;

                            case "ButtonBackgroundMouseOver2":
                                this.ButtonBackgroundMouseOver2 = brush;
                                break;

                            case "ToggleButtonForeground":
                                this.ToggleButtonForeground = brush;
                                break;

                            case "ToggleButtonForegroundDisabled":
                                this.ToggleButtonForegroundDisabled = brush;
                                break;

                            case "ToggleButtonForegroundPressed":
                                this.ToggleButtonForegroundPressed = brush;
                                break;

                            case "ToggleButtonForegroundMouseOver":
                                this.ToggleButtonForegroundMouseOver = brush;
                                break;

                            case "ToggleButtonForegroundChecked":
                                this.ToggleButtonForegroundChecked = brush;
                                break;

                            case "ToggleButtonBackground":
                                this.ToggleButtonBackground = brush;
                                break;

                            case "ToggleButtonBackgroundDisabled":
                                this.ToggleButtonBackgroundDisabled = brush;
                                break;

                            case "ToggleButtonBackgroundPressed":
                                this.ToggleButtonBackgroundPressed = brush;
                                break;

                            case "ToggleButtonBackgroundMouseOver":
                                this.ToggleButtonBackgroundMouseOver = brush;
                                break;

                            case "ToggleButtonBackgroundChecked":
                                this.ToggleButtonBackgroundChecked = brush;
                                break;

                            case "ComboBoxForeground":
                                this.ComboBoxForeground = brush;
                                break;

                            case "ComboBoxForegroundDisabled":
                                this.ComboBoxForegroundDisabled = brush;
                                break;

                            case "ComboBoxForegroundMouseOver":
                                this.ComboBoxForegroundMouseOver = brush;
                                break;

                            case "ComboBoxForegroundPressed":
                                this.ComboBoxForegroundPressed = brush;
                                break;

                            case "ComboBoxBackground":
                                this.ComboBoxBackground = brush;
                                break;

                            case "ComboBoxBackgroundDisabled":
                                this.ComboBoxBackgroundDisabled = brush;
                                break;

                            case "ComboBoxBackgroundMouseOver":
                                this.ComboBoxBackgroundMouseOver = brush;
                                break;

                            case "ComboBoxBackgroundPressed":
                                this.ComboBoxBackgroundPressed = brush;
                                break;

                            case "TextBoxForeground":
                                this.TextBoxForeground = brush;
                                break;

                            case "TextBoxBackground":
                                this.TextBoxBackground = brush;
                                break;

                            case "ComboBoxItemForeground":
                                this.ComboBoxItemForeground = brush;
                                break;

                            case "ComboBoxItemBackground":
                                this.ComboBoxItemBackground = brush;
                                break;

                            case "TabControlForeground":
                                this.TabControlForeground = brush;
                                break;

                            case "TabControlBackground":
                                this.TabControlBackground = brush;
                                break;

                            case "TabControlBorderColor":
                                this.TabControlBorderColor = brush;
                                break;

                            case "TabItemForeground":
                                this.TabItemForeground = brush;
                                break;

                            case "TabItemBackground":
                                this.TabItemBackground = brush;
                                break;

                            case "TabItemBorderColor":
                                this.TabItemBorderColor = brush;
                                break;

                            case "TabItemForegroundDeselected":
                                this.TabItemForegroundDeselected = brush;
                                break;

                            case "TabItemBackgroundDeselected":
                                this.TabItemBackgroundDeselected = brush;
                                break;

                            case "TabItemBorderColorDeselected":
                                this.TabItemBorderColorDeselected = brush;
                                break;

                            default:
                                break;
                            }
                        }

                        break;
                        }
                    }
                }
            }
        }
Пример #13
0
        private static readonly MainWindow MainWindow = (MainWindow)Application.Current.MainWindow; //  Cсылка на главное окно

        public static void ShowNewAchieveWindow(string name, string achieve)                        //  Показываем окно новой ачивки
        {
            var window = new Windows.NewAchieve();

            switch (achieve) //  В зависимости от названия ачивки вибираем сообщение, картинку и кисть
            {
            case "A10matchespalyed":
                window.AchieveName.Content = "\"10 games played\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10MatchesPlayed.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A100MatchesPalyed":
                window.AchieveName.Content = "\"100 games played\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100MatchesPlayed.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A1000MatchesPalyed":
                window.AchieveName.Content = "\"1000 games played\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000MatchesPlayed.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A10MatchesWon":
                window.AchieveName.Content = "\"10 matches won\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10MatchesWon.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A100MatchesWon":
                window.AchieveName.Content = "\"100 matches won\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100MatchesWon.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A1000MatchesWon":
                window.AchieveName.Content = "\"1000 matches won\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000MatchesWon.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A1000Throws":
                window.AchieveName.Content = "\"1000 throws made\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000Throws.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A10000Throws":
                window.AchieveName.Content = "\"10000 throws made\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10000Throws.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A100000Throws":
                window.AchieveName.Content = "\"100000 throws made\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100000Throws.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A10000Points":
                window.AchieveName.Content = "\"10000 points collected\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10000Points.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A100000Points":
                window.AchieveName.Content = "\"100000 points collected\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100000Points.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A1000000Points":
                window.AchieveName.Content = "\"1000000 points collected\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000000Points.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A180x10":
                window.AchieveName.Content = "\"10x180 hand committed\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x10.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A180x100":
                window.AchieveName.Content = "\"100x180 hand committed\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x100.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A180x1000":
                window.AchieveName.Content = "\"1000x180 hand committed\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x1000.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "AFirst180":
                window.AchieveName.Content = "\"It's your first 180 !\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/First180.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "A3Bull":
                window.AchieveName.Content = "\"3-eyed bull\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/3Bull.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;

            case "AmrZ":
                window.AchieveName.Content = "\"Absolute zero\"";
                window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/mr.Z.png", UriKind.Relative));
                window.AchieveLight.Fill   = Brush(achieve);
                break;
            }

            window.PlayerName.Content = name;
            window.Owner = MainWindow;
            MainWindow.FadeIn();
            window.ShowDialog();
            MainWindow.FadeOut();

            Brush Brush(string achieveName) //  Выбираем кисть
            {
                var brush = new LinearGradientBrush();

                switch (achieveName)
                {
                case "A10matchespalyed":
                case "A10MatchesWon":
                case "A1000Throws":
                case "A10000Points":
                case "A180x10":
                    brush.StartPoint = new Point(0.5, 1);
                    brush.EndPoint   = new Point(0.5, 0);
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00420F"), 0));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF2DC700"), 1));
                    brush.RelativeTransform = new RotateTransform(225);
                    break;

                case "A100MatchesPalyed":
                case "A100MatchesWon":
                case "A10000Throws":
                case "A100000Points":
                case "A180x100":
                    brush.StartPoint = new Point(0.5, 1);
                    brush.EndPoint   = new Point(0.5, 0);
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF050078"), 0));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00B1D8"), 1));
                    brush.RelativeTransform = new RotateTransform(225);
                    break;

                case "A1000MatchesPalyed":
                case "A1000MatchesWon":
                case "A100000Throws":
                case "A1000000Points":
                case "A180x1000":
                    brush.StartPoint = new Point(0.5, 1);
                    brush.EndPoint   = new Point(0.5, 0);
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF610000"), 0));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF81009E"), 1));
                    brush.RelativeTransform = new RotateTransform(225);
                    break;

                case "AFirst180":
                    brush.StartPoint = new Point(0.5, 0);
                    brush.EndPoint   = new Point(0.5, 1);
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFFF4600"), 0));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF34CF07"), 1));
                    brush.RelativeTransform = new RotateTransform(250);
                    break;

                case "AmrZ":
                    brush.StartPoint = new Point(0.5, 0);
                    brush.EndPoint   = new Point(0.5, 1);
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF5B5B5B"), 0));
                    brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFF7F7F7"), 1));
                    brush.RelativeTransform = new RotateTransform(225);
                    break;

                case "A3Bull":
                    var gradientBrush = new RadialGradientBrush();
                    gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFC70900"), 0));
                    gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00420F"), 0.577));
                    gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF360146"), 1));
                    return(gradientBrush);
                }

                return(brush);
            }
        }
Пример #14
0
        private void SetColors()
        {
            //Rect1
            Rect1.Fill = new SolidColorBrush(System.Windows.Media.Colors.White);
            Rect1.StrokeDashArray.Add(2);
            Rect1.Stroke          = new SolidColorBrush(System.Windows.Media.Colors.Red);
            Rect1.StrokeThickness = 2;

            //Rect2
            //Create new gradient to add to the fill of the rectangle
            LinearGradientBrush Rect2Gradient = new LinearGradientBrush();

            //Create Gradient start and endpoints
            Rect2Gradient.StartPoint = new Point(0, 0);
            Rect2Gradient.EndPoint   = new Point(1, 1);

            //Create and add gradient stops
            GradientStop lightYellow = new GradientStop(Colors.LightYellow, 0.00);

            Rect2Gradient.GradientStops.Add(lightYellow);

            GradientStop whitish = new GradientStop(Colors.WhiteSmoke, 0.33);

            Rect2Gradient.GradientStops.Add(whitish);

            GradientStop lightBlue = new GradientStop(Colors.LightSkyBlue, 0.66);

            Rect2Gradient.GradientStops.Add(lightBlue);

            Rect2.Fill = Rect2Gradient;

            //Rect3
            //Create new gradient to add to the fill of the rectangle
            LinearGradientBrush Rect3Gradient = new LinearGradientBrush();

            //Create gradient start and endpoints
            Rect3Gradient.StartPoint = new Point(0, 0.5);
            Rect3Gradient.EndPoint   = new Point(1, 0.5);

            //Create and add gradient stops
            GradientStop Pink = new GradientStop(Colors.LightPink, 0.0);

            Rect3Gradient.GradientStops.Add(Pink);

            GradientStop Lightblue = new GradientStop(Colors.LightBlue, 0.7);

            Rect3Gradient.GradientStops.Add(Lightblue);

            Rect3.Fill = Rect3Gradient;

            //Rect4
            //Create new Radialgradient to add to he fill of the rectangle
            RadialGradientBrush Rect4Gradient = new RadialGradientBrush();

            Rect4Gradient.GradientOrigin = new Point(0.5, 0.5);
            Rect4Gradient.Center         = new Point(0.5, 0.5);


            //Create and add Gradient stops
            GradientStop Blue = new GradientStop(Colors.DarkBlue, 0.0);

            Rect4Gradient.GradientStops.Add(Blue);

            GradientStop White = new GradientStop(Colors.WhiteSmoke, 0.25);

            Rect4Gradient.GradientStops.Add(White);

            GradientStop Blue2 = new GradientStop(Colors.DarkBlue, 0.5);

            Rect4Gradient.GradientStops.Add(Blue2);

            GradientStop White2 = new GradientStop(Colors.WhiteSmoke, 0.75);

            Rect4Gradient.GradientStops.Add(White2);

            GradientStop Blue3 = new GradientStop(Colors.DarkBlue, 1.0);

            Rect4Gradient.GradientStops.Add(Blue3);

            Rect4.Fill = Rect4Gradient;

            //Rect5 In XAML

            //Rect6
            //Current Directory in the URI is a variable with the current Directory
            ImageBrush imgBrush = new ImageBrush();

            imgBrush.ImageSource = new BitmapImage(new Uri(RootDirectory + "Images/oog.png"));
            Rect6.Fill           = imgBrush;
        }
Пример #15
0
		public void SetGradientWrap(RadialGradientBrush widget, GradientWrapMode gradientWrap)
		{
			((swm.RadialGradientBrush)widget.ControlObject).SpreadMethod = gradientWrap.ToWpf ();
		}
Пример #16
0
		public IMatrix GetTransform(RadialGradientBrush widget)
		{
			var brush = (RadialBrushData)widget.ControlObject;
			return brush.Transform;
		}
Пример #17
0
		public void SetTransform(RadialGradientBrush widget, IMatrix transform)
		{
			var brush = (RadialBrushData)widget.ControlObject;
			brush.Transform = transform;
		}
Пример #18
0
		public async Task TriWithRadGrad ()
		{
			var canvas = Platform.CreateImageCanvas (new Size (100), transparency: true);
			var size = new Size (100);
			var b = new RadialGradientBrush (
				new Point (0.5, 1), new Size(1),
				Colors.Yellow, Colors.Blue);
			var p = new Path ();
			p.MoveTo (0, 0, false);
			p.LineTo (size.Width, 0,false);
			p.LineTo (size.Width / 2, size.Height,false);
			p.Close ();
			p.Brush = b;
			p.Draw (canvas);
      await SaveImage(canvas, "ImageCanvas.TriWithRadGrad");
		}
Пример #19
0
		public GradientWrapMode GetGradientWrap(RadialGradientBrush widget)
		{
			var brush = (RadialBrushData)widget.ControlObject;
			return brush.WrapMode;
		}
Пример #20
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties props = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops = 
                { 
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
Пример #21
0
        Visual CreateFillRadialGradientBrush3()
        {
            DrawingContext dc;
            DrawingVisual  dv = PrepareDrawingVisual(out dc);

            Rect   rect = new Rect(5, 5, BoxWidth - 10, BoxHeight - 10);
            double rx   = 20;
            double ry   = 20;
            RadialGradientBrush brush;

#if true
            BeginBox(dc, 1, BoxOptions.Tile, "2 colors, repeat");
            brush              = new RadialGradientBrush(Colors.DarkBlue, Colors.Orange);
            brush.RadiusX      = 0.1;
            brush.RadiusY      = 0.15;
            brush.SpreadMethod = GradientSpreadMethod.Repeat;
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

#if true
            BeginBox(dc, 2, BoxOptions.Tile, "2 colors, reflect");
            brush              = new RadialGradientBrush(Colors.DarkBlue, Colors.Orange);
            brush.RadiusX      = 0.1;
            brush.RadiusY      = 0.15;
            brush.SpreadMethod = GradientSpreadMethod.Reflect;
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

#if true
            BeginBox(dc, 3, BoxOptions.Tile, "3 colors, repeat");
            brush = new RadialGradientBrush();
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.5));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 1));
            brush.RadiusX      = 0.1;
            brush.RadiusY      = 0.15;
            brush.SpreadMethod = GradientSpreadMethod.Repeat;
            brush.Opacity      = 0.8;
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

#if true
            BeginBox(dc, 4, BoxOptions.Tile, "3 colors, reflect");
            brush = new RadialGradientBrush(Colors.DarkBlue, Colors.Orange);
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.5));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 1));
            brush.RadiusX      = 0.1;
            brush.RadiusY      = 0.15;
            brush.SpreadMethod = GradientSpreadMethod.Reflect;
            brush.Opacity      = 0.6;
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

#if true
            BeginBox(dc, 5, BoxOptions.Tile, "5 colors, repeat");
            brush = new RadialGradientBrush();
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 128, 0), 0.25));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.5));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 128), 0.75));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 1));
            brush.RadiusX      = 0.2;
            brush.RadiusY      = 0.1;
            brush.SpreadMethod = GradientSpreadMethod.Repeat;
            //brush.Opacity = 0.6;
            brush.RelativeTransform = new SkewTransform(20, 40);
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

#if true
            BeginBox(dc, 6, BoxOptions.Tile, "5 colors, reflect");
            brush = new RadialGradientBrush(Colors.DarkBlue, Colors.Orange);
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 128, 0), 0.25));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.5));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 128), 0.75));
            brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 1));
            brush.RadiusX      = 0.2;
            brush.RadiusY      = 0.1;
            brush.SpreadMethod = GradientSpreadMethod.Reflect;
            //brush.Opacity = 0.6;
            brush.RelativeTransform = new RotateTransform(30);
            dc.DrawRoundedRectangle(brush, null, rect, rx, ry);
            EndBox(dc);
#endif

            //BeginBox(dc, 5, BoxOptions.Tile);
            //EndBox(dc);

            //BeginBox(dc, 6, BoxOptions.Tile);
            //EndBox(dc);

            //BeginBox(dc, 7, BoxOptions.Tile);
            //EndBox(dc);

            //BeginBox(dc, 8, BoxOptions.Tile);
            //EndBox(dc);

            dc.Close();
            return(dv);
        }