public static GradientBrush Convert(System.Windows.Media.Color color)
        {
            var scrgb = color.ToScRGBColor();

            var xyz = KnownColorSpaces.scRGB.ToXYZColor(scrgb);

            var lab = KnownColorSpaces.Lab.FromXYZColor(xyz) as LabColor;

            var l_base = lab.L;

            var gradientStops = new GradientStopCollection();

            var _lab = new LabColor(0xff, l_base * 1.07, lab.a, lab.b);
            var _c = _lab.ToWindowsMediaColor();

            gradientStops.Add(new GradientStop(_c, 0.5));


            _lab = new LabColor(0xff, l_base * .93, lab.a, lab.b);
            _c = _lab.ToWindowsMediaColor();

            gradientStops.Add(new GradientStop(_c, 1));


            var result = new LinearGradientBrush(gradientStops, 90);

            result.Freeze();

            return result;
        }
示例#2
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);
		}
示例#3
0
        protected static LinearGradientBrush CreateFrozenBrush(GradientStopCollection stops, Point start, Point end)
        {
            var brush = new LinearGradientBrush(stops, start, end);

            brush.Freeze();

            return brush;
        }
示例#4
0
 static ColorManager()
 {
     var brush = new LinearGradientBrush();
     brush.GradientStops.Add(new GradientStop(Colors.Red, 0));
     brush.GradientStops.Add(new GradientStop(Colors.Green, .5));
     brush.GradientStops.Add(new GradientStop(Colors.Blue, 1));
     brush.Freeze();
     RgbBrush = brush;
 }
示例#5
0
        public void AssocColor(string seriesId, Color b)
        {
            Color bTransparent = b;
            bTransparent.A = 0;

            GradientStopCollection gs = new GradientStopCollection();
            gs.Add(new GradientStop(bTransparent, 0));
            gs.Add(new GradientStop(b, 0.1));
            LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0,0), new Point(ActualWidth, 0));
            g.MappingMode = BrushMappingMode.Absolute;
            g.Freeze();
            brushes[seriesId] = g;
        }
示例#6
0
        static Tooltip()
        {
            timer = new DispatcherTimer(TimeSpan.FromMilliseconds(1500), DispatcherPriority.Normal,
                delegate { timer.Stop(); ttip.IsOpen = false; },
                Application.Current.Dispatcher);

            var fillBrush = new LinearGradientBrush(Color.FromRgb(223, 20, 20), Color.FromRgb(255, 116, 116), 90);
            fillBrush.Freeze();

            ttip.BorderBrush = Brushes.Black;
            ttip.BorderThickness = new Thickness(1);
            ttip.Background = fillBrush;
            ttip.Placement = PlacementMode.MousePoint;
            ttip.Padding = new Thickness(20, 8, 20, 8);
        }
		public override void End()
		{
			Color newColor = Colors.Transparent;
			if (this.TurnNumber % 2 == 0)
				newColor = Colors.DarkGray;
				//expTurns.BorderBrush = Brushes.DarkGray;
			else
				newColor = Colors.DimGray;
				//expTurns.BorderBrush = Brushes.DimGray;

			lEdge.Stroke = new SolidColorBrush(newColor);
			LinearGradientBrush lgb = new LinearGradientBrush(new GradientStopCollection() { 
				new GradientStop(newColor, 0.0), 
				new GradientStop(newColor, 0.25), 
				new GradientStop(Colors.Transparent, 1.25) });
			lgb.Freeze();
			lTop.Stroke = lBottom.Stroke = lgb;
		}
示例#8
0
        // *** Private static methods ***
        private static void CreateBrushes()
        {
            // Get the colors for the shadow
            Color shadowColor = Color.FromArgb(128, 0, 0, 0);
            Color transparentColor = Color.FromArgb(16, 0, 0, 0);
            // Create a GradientStopCollection from these
            GradientStopCollection gradient = new GradientStopCollection(2);
            gradient.Add(new GradientStop(shadowColor, 0.5));
            gradient.Add(new GradientStop(transparentColor, 1.0));
            gradient.Freeze();
            // Create the background brush
            backgroundBrush = new SolidColorBrush(shadowColor);
            backgroundBrush.Freeze();
            // Create the LinearGradientBrushes
            rightBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(1.0, 0.0)); rightBrush.Freeze();
            bottomBrush = new LinearGradientBrush(gradient, new Point(0.0, 0.0), new Point(0.0, 1.0)); bottomBrush.Freeze();
            // Create the RadialGradientBrushes
            bottomRightBrush = new RadialGradientBrush(gradient);
            bottomRightBrush.GradientOrigin = new Point(0.0, 0.0);
            bottomRightBrush.Center = new Point(0.0, 0.0);
            bottomRightBrush.RadiusX = 1.0;
            bottomRightBrush.RadiusY = 1.0;
            bottomRightBrush.Freeze();

            topRightBrush = new RadialGradientBrush(gradient);
            topRightBrush.GradientOrigin = new Point(0.0, 1.0);
            topRightBrush.Center = new Point(0.0, 1.0);
            topRightBrush.RadiusX = 1.0;
            topRightBrush.RadiusY = 1.0;
            topRightBrush.Freeze();

            bottomLeftBrush = new RadialGradientBrush(gradient);
            bottomLeftBrush.GradientOrigin = new Point(1.0, 0.0);
            bottomLeftBrush.Center = new Point(1.0, 0.0);
            bottomLeftBrush.RadiusX = 1.0;
            bottomLeftBrush.RadiusY = 1.0;
            bottomLeftBrush.Freeze();
        }
示例#9
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            var minHeight = barContainer.ActualHeight * 0.1;
            bar.Height = (bar.Height-minHeight) * 0.9 + ((barContainer.ActualHeight-minHeight) * targetValue) * 0.1 + minHeight;

            if (confidence != targetConfidence)
            {
                confidence = confidence * 0.9 + targetConfidence * 0.1;

                if (Math.Abs(confidence - targetConfidence) < 0.0001)
                    confidence = targetConfidence;

                Color bTransparent = Colors.CadetBlue;
                bTransparent.A = 0;

                GradientStopCollection gs = new GradientStopCollection();
                gs.Add(new GradientStop(bTransparent, 0));
                gs.Add(new GradientStop(Colors.CadetBlue, 1));
                LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0, 0), new Point(0, bar.Height*(1-confidence)));
                g.MappingMode = BrushMappingMode.Absolute;
                g.Freeze();
                bar.Fill = g;
            }
        }
示例#10
0
        public DonationControl()
        {
            SetCols(2);
            SetRows(5);

            Width = 250;
            VerticalAlignment = VerticalAlignment.Top;
            HorizontalAlignment = HorizontalAlignment.Left;
            Margin = new Thickness(5);
            DataContext = this;
            ColumnDefinitions[0].Width = GridLength.Auto;

            LinearGradientBrush backgroundStroke = new LinearGradientBrush
            {
                EndPoint = new Point(0.5, 1),
                StartPoint = new Point(0.5, 0),
                RelativeTransform = new RotateTransform(115, 0.5, 0.5),
                GradientStops = new GradientStopCollection
                {
                    new GradientStop(Color.FromArgb(0xff, 0x61, 0x61, 0x61), 0),
                    new GradientStop(Color.FromArgb(0xff, 0xF2, 0xF2, 0xF2), 0.504),
                    new GradientStop(Color.FromArgb(0xff, 0xAE, 0xB1, 0xB1), 1)
                }
            };
            backgroundStroke.Freeze();

            LinearGradientBrush backgroundFill = new LinearGradientBrush
            {
                MappingMode = BrushMappingMode.RelativeToBoundingBox,
                StartPoint = new Point(0.5, 1.0),
                EndPoint = new Point(0.5, -0.4),
                GradientStops = new GradientStopCollection
                {
                    new GradientStop(Color.FromArgb(0xBB, 0x44, 0x71, 0xc1), 0),
                    new GradientStop(Color.FromArgb(0xBB, 0x28, 0x36, 0x65), 1)
                }
            };
            backgroundFill.Freeze();

            Rectangle backround = AddUiElement(new Rectangle {Stroke = backgroundStroke, Fill = backgroundFill, StrokeThickness = 5}, 0, 0, 9, 2);

            UiTextBlock title = AddUiElement(UiTextBlockFactory.Create("Пожертвования"), 0, 0, 0, 2);
            title.FontSize = 18;
            title.HorizontalAlignment = HorizontalAlignment.Center;
            title.Margin = new Thickness(0, 4, 0, 0);

            AddUiElement(UiTextBoxFactory.Create("Яндекс: "), 1, 0);
            AddUiElement(UiTextBoxFactory.Create("410013254932482"), 1, 1);
            AddUiElement(UiTextBoxFactory.Create("WMR: "), 2, 0);
            AddUiElement(UiTextBoxFactory.Create("R255847965836"), 2, 1);
            AddUiElement(UiTextBoxFactory.Create("WMZ: "), 3, 0);
            AddUiElement(UiTextBoxFactory.Create("Z321220468886 "), 3, 1);
            AddUiElement(UiTextBoxFactory.Create("WME: "), 4, 0);
            AddUiElement(UiTextBoxFactory.Create("E223137827385"), 4, 1).Margin = new Thickness(0,0,0,5);

            foreach (FrameworkElement child in Children)
            {
                if (!ReferenceEquals(child, backround))
                {
                    child.Margin = GetColumn(child) == 0
                        ? new Thickness(child.Margin.Left + 8, child.Margin.Top, child.Margin.Right, child.Margin.Bottom)
                        : new Thickness(child.Margin.Left, child.Margin.Top, child.Margin.Right + 8, child.Margin.Bottom);
                }

                TextBlock textBlock = child as TextBlock;
                if (textBlock != null)
                {
                    textBlock.Foreground = Brushes.WhiteSmoke;
                    textBlock.FontWeight = FontWeight.FromOpenTypeWeight(500);
                    continue;
                }

                TextBox textBox = child as TextBox;
                if (textBox != null)
                {
                    textBox.Foreground = Brushes.WhiteSmoke;
                    textBox.FontWeight = FontWeight.FromOpenTypeWeight(500);
                    textBox.Background = Brushes.Transparent;
                    textBox.BorderThickness = new Thickness(0);
                    textBox.IsReadOnly = true;
                }
            }
        }
示例#11
0
        private void RenderTheme(DrawingContext dc)
        {
            Size size = RenderSize;
            bool horizontal = Orientation == Orientation.Horizontal;
            bool isClickable = IsClickable && IsEnabled;
            bool isHovered = isClickable && IsHovered;
            bool isPressed = isClickable && IsPressed;
            ListSortDirection? sortDirection = SortDirection;
            bool isSorted = sortDirection != null;
            bool isSelected = IsSelected;

            EnsureCache((int)RoyaleFreezables.NumFreezables);

            if (horizontal)
            {
                // When horizontal, rotate the rendering by -90 degrees
                Matrix m1 = new Matrix();
                m1.RotateAt(-90.0, 0.0, 0.0);
                Matrix m2 = new Matrix();
                m2.Translate(0.0, size.Height);

                MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2);
                horizontalRotate.Freeze();
                dc.PushTransform(horizontalRotate);

                double temp = size.Width;
                size.Width = size.Height;
                size.Height = temp;
            }

            // Draw the background
            RoyaleFreezables backgroundType = isPressed ? RoyaleFreezables.PressedBackground : isHovered ? RoyaleFreezables.HoveredBackground : RoyaleFreezables.NormalBackground;
            LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType);
            if (background == null)
            {
                background = new LinearGradientBrush();
                background.StartPoint = new Point();
                background.EndPoint = new Point(0.0, 1.0);

                if (isPressed)
                {
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB9, 0xB9, 0xC8), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 0.1));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEC, 0xEC, 0xF3), 1.0));
                }
                else if (isHovered || isSelected)
                {
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFE, 0xFE, 0xFE), 0.85));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0));
                }
                else
                {
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.0));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF9, 0xFA, 0xFD), 0.85));
                    background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xBE, 0xCE), 1.0));
                }

                background.Freeze();
                CacheFreezable(background, (int)backgroundType);
            }

            dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height));

            if (isHovered && !isPressed && (size.Width >= 6.0) && (size.Height >= 4.0))
            {
                // When hovered, there is a colored tab at the bottom
                TranslateTransform positionTransform = new TranslateTransform(0.0, size.Height - 3.0);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                PathGeometry tabGeometry = new PathGeometry();
                PathFigure tabFigure = new PathFigure();

                tabFigure.StartPoint = new Point(0.5, 0.5);

                LineSegment line = new LineSegment(new Point(size.Width - 0.5, 0.5), true);
                line.Freeze();
                tabFigure.Segments.Add(line);

                ArcSegment arc = new ArcSegment(new Point(size.Width - 2.5, 2.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true);
                arc.Freeze();
                tabFigure.Segments.Add(arc);

                line = new LineSegment(new Point(2.5, 2.5), true);
                line.Freeze();
                tabFigure.Segments.Add(line);

                arc = new ArcSegment(new Point(0.5, 0.5), new Size(2.0, 2.0), 90.0, false, SweepDirection.Clockwise, true);
                arc.Freeze();
                tabFigure.Segments.Add(arc);

                tabFigure.IsClosed = true;
                tabFigure.Freeze();

                tabGeometry.Figures.Add(tabFigure);
                tabGeometry.Freeze();

                Pen tabStroke = (Pen)GetCachedFreezable((int)RoyaleFreezables.TabStroke);
                if (tabStroke == null)
                {
                    SolidColorBrush tabStrokeBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xF8, 0xA9, 0x00));
                    tabStrokeBrush.Freeze();

                    tabStroke = new Pen(tabStrokeBrush, 1.0);
                    tabStroke.Freeze();

                    CacheFreezable(tabStroke, (int)RoyaleFreezables.TabStroke);
                }

                LinearGradientBrush tabFill = (LinearGradientBrush)GetCachedFreezable((int)RoyaleFreezables.TabFill);
                if (tabFill == null)
                {
                    tabFill = new LinearGradientBrush();
                    tabFill.StartPoint = new Point();
                    tabFill.EndPoint = new Point(1.0, 0.0);

                    tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xE0, 0xA6), 0.0));
                    tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.1));
                    tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF6, 0xC4, 0x56), 0.9));
                    tabFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDF, 0x97, 0x00), 1.0));

                    tabFill.Freeze();
                    CacheFreezable(tabFill, (int)RoyaleFreezables.TabFill);
                }

                dc.DrawGeometry(tabFill, tabStroke, tabGeometry);

                dc.Pop(); // Translate Transform
            }

            if (isPressed && (size.Width >= 2.0) && (size.Height >= 2.0))
            {
                // When pressed, there is a border on the left and bottom
                SolidColorBrush border = (SolidColorBrush)GetCachedFreezable((int)RoyaleFreezables.PressedBorder);
                if (border == null)
                {
                    border = new SolidColorBrush(Color.FromArgb(0xFF, 0x80, 0x80, 0x99));
                    border.Freeze();
                    CacheFreezable(border, (int)RoyaleFreezables.PressedBorder);
                }

                dc.DrawRectangle(border, null, new Rect(0.0, 0.0, 1.0, size.Height));
                dc.DrawRectangle(border, null, new Rect(0.0, Max0(size.Height - 1.0), size.Width, 1.0));
            }

            if (!isPressed && !isHovered && (size.Width >= 4.0))
            {
                if (SeparatorVisibility == Visibility.Visible)
                {
                    Brush sideBrush;
                    if (SeparatorBrush != null)
                    {
                        sideBrush = SeparatorBrush;
                    }
                    else
                    {
                        // When not pressed or hovered, draw the resize gripper
                        LinearGradientBrush gripper = (LinearGradientBrush)GetCachedFreezable((int)(horizontal ? RoyaleFreezables.HorizontalGripper : RoyaleFreezables.VerticalGripper));
                        if (gripper == null)
                        {
                            gripper = new LinearGradientBrush();
                            gripper.StartPoint = new Point();
                            gripper.EndPoint = new Point(1.0, 0.0);

                            Color highlight = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
                            Color shadow = Color.FromArgb(0xFF, 0xC7, 0xC5, 0xB2);

                            if (horizontal)
                            {
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.0));
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.25));
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.75));
                                gripper.GradientStops.Add(new GradientStop(shadow, 1.0));
                            }
                            else
                            {
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.0));
                                gripper.GradientStops.Add(new GradientStop(shadow, 0.25));
                                gripper.GradientStops.Add(new GradientStop(highlight, 0.75));
                                gripper.GradientStops.Add(new GradientStop(highlight, 1.0));
                            }

                            gripper.Freeze();
                            CacheFreezable(gripper, (int)(horizontal ? RoyaleFreezables.HorizontalGripper : RoyaleFreezables.VerticalGripper));
                        }

                        sideBrush = gripper;
                    }

                    dc.DrawRectangle(sideBrush, null, new Rect(horizontal ? 0.0 : Max0(size.Width - 2.0), 4.0, 2.0, Max0(size.Height - 8.0)));
                }
            }

            if (isSorted && (size.Width > 14.0) && (size.Height > 10.0))
            {
                // When sorted, draw an arrow on the right
                TranslateTransform positionTransform = new TranslateTransform(size.Width - 15.0, (size.Height - 5.0) * 0.5);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                bool ascending = (sortDirection == ListSortDirection.Ascending);
                PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)RoyaleFreezables.ArrowUpGeometry : (int)RoyaleFreezables.ArrowDownGeometry);
                if (arrowGeometry == null)
                {
                    arrowGeometry = new PathGeometry();
                    PathFigure arrowFigure = new PathFigure();

                    if (ascending)
                    {
                        arrowFigure.StartPoint = new Point(0.0, 5.0);

                        LineSegment line = new LineSegment(new Point(5.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(10.0, 5.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }
                    else
                    {
                        arrowFigure.StartPoint = new Point(0.0, 0.0);

                        LineSegment line = new LineSegment(new Point(10.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(5.0, 5.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }

                    arrowFigure.IsClosed = true;
                    arrowFigure.Freeze();

                    arrowGeometry.Figures.Add(arrowFigure);
                    arrowGeometry.Freeze();

                    CacheFreezable(arrowGeometry, ascending ? (int)RoyaleFreezables.ArrowUpGeometry : (int)RoyaleFreezables.ArrowDownGeometry);
                }

                SolidColorBrush arrowFill = (SolidColorBrush)GetCachedFreezable((int)RoyaleFreezables.ArrowFill);
                if (arrowFill == null)
                {
                    arrowFill = new SolidColorBrush(Color.FromArgb(0xFF, 0xAC, 0xA8, 0x99));
                    arrowFill.Freeze();
                    CacheFreezable(arrowFill, (int)RoyaleFreezables.ArrowFill);
                }

                dc.DrawGeometry(arrowFill, null, arrowGeometry);

                dc.Pop(); // Position Transform
            }

            if (horizontal)
            {
                dc.Pop(); // Horizontal Rotate
            }
        }
示例#12
0
        private void RenderAeroNormalColor(DrawingContext dc)
        {
            Size size = RenderSize;
            bool horizontal = Orientation == Orientation.Horizontal;
            bool isClickable = IsClickable && IsEnabled;
            bool isHovered = isClickable && IsHovered;
            bool isPressed = isClickable && IsPressed;
            ListSortDirection? sortDirection = SortDirection;
            bool isSorted = sortDirection != null;
            bool isSelected = IsSelected;
            bool hasBevel = (!isHovered && !isPressed && !isSorted && !isSelected);

            EnsureCache((int)AeroFreezables.NumFreezables);

            if (horizontal)
            {
                // When horizontal, rotate the rendering by -90 degrees
                Matrix m1 = new Matrix();
                m1.RotateAt(-90.0, 0.0, 0.0);
                Matrix m2 = new Matrix();
                m2.Translate(0.0, size.Height);

                MatrixTransform horizontalRotate = new MatrixTransform(m1 * m2);
                horizontalRotate.Freeze();
                dc.PushTransform(horizontalRotate);

                double temp = size.Width;
                size.Width = size.Height;
                size.Height = temp;
            }

            if (hasBevel)
            {
                // This is a highlight that can be drawn by just filling the background with the color.
                // It will be seen through the gab between the border and the background.
                LinearGradientBrush bevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.NormalBevel);
                if (bevel == null)
                {
                    bevel = new LinearGradientBrush();
                    bevel.StartPoint = new Point();
                    bevel.EndPoint = new Point(0.0, 1.0);
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFC, 0xFC, 0xFD), 0.4));
                    bevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFB, 0xFC, 0xFC), 1.0));
                    bevel.Freeze();

                    CacheFreezable(bevel, (int)AeroFreezables.NormalBevel);
                }

                dc.DrawRectangle(bevel, null, new Rect(0.0, 0.0, size.Width, size.Height));
            }

            // Fill the background
            AeroFreezables backgroundType = AeroFreezables.NormalBackground;
            if (isPressed)
            {
                backgroundType = AeroFreezables.PressedBackground;
            }
            else if (isHovered)
            {
                backgroundType = AeroFreezables.HoveredBackground;
            }
            else if (isSorted || isSelected)
            {
                backgroundType = AeroFreezables.SortedBackground;
            }

            LinearGradientBrush background = (LinearGradientBrush)GetCachedFreezable((int)backgroundType);
            if (background == null)
            {
                background = new LinearGradientBrush();
                background.StartPoint = new Point();
                background.EndPoint = new Point(0.0, 1.0);

                switch (backgroundType)
                {
                    case AeroFreezables.NormalBackground:
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF7, 0xF8, 0xFA), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF1, 0xF2, 0xF4), 1.0));
                        break;

                    case AeroFreezables.PressedBackground:
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBC, 0xE4, 0xF9), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8D, 0xD6, 0xF7), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x8A, 0xD1, 0xF5), 1.0));
                        break;

                    case AeroFreezables.HoveredBackground:
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE3, 0xF7, 0xFF), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xBD, 0xED, 0xFF), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xB7, 0xE7, 0xFB), 1.0));
                        break;

                    case AeroFreezables.SortedBackground:
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.0));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF9, 0xFC), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE1, 0xF1, 0xF9), 0.4));
                        background.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xD8, 0xEC, 0xF6), 1.0));
                        break;
                }

                background.Freeze();

                CacheFreezable(background, (int)backgroundType);
            }

            dc.DrawRectangle(background, null, new Rect(0.0, 0.0, size.Width, size.Height));

            if (size.Width >= 2.0)
            {
                // Draw the borders on the sides
                AeroFreezables sideType = AeroFreezables.NormalSides;
                if (isPressed)
                {
                    sideType = AeroFreezables.PressedSides;
                }
                else if (isHovered)
                {
                    sideType = AeroFreezables.HoveredSides;
                }
                else if (isSorted || isSelected)
                {
                    sideType = AeroFreezables.SortedSides;
                }

                if (SeparatorVisibility == Visibility.Visible)
                {
                    Brush sideBrush;
                    if (SeparatorBrush != null)
                    {
                        sideBrush = SeparatorBrush;
                    }
                    else
                    {
                        sideBrush = (Brush)GetCachedFreezable((int)sideType);
                        if (sideBrush == null)
                        {
                            LinearGradientBrush lgBrush = null;
                            if (sideType != AeroFreezables.SortedSides)
                            {
                                lgBrush = new LinearGradientBrush();
                                lgBrush.StartPoint = new Point();
                                lgBrush.EndPoint = new Point(0.0, 1.0);
                                sideBrush = lgBrush;
                            }

                            switch (sideType)
                            {
                                case AeroFreezables.NormalSides:
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2), 0.0));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xEF, 0xEF, 0xEF), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xE7, 0xE8, 0xEA), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xDE, 0xDF, 0xE1), 1.0));
                                    break;

                                case AeroFreezables.PressedSides:
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.0));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x7A, 0x9E, 0xB1), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x50, 0x91, 0xAF), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x4D, 0x8D, 0xAD), 1.0));
                                    break;

                                case AeroFreezables.HoveredSides:
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.0));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x88, 0xCB, 0xEB), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 0.4));
                                    lgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x69, 0xBB, 0xE3), 1.0));
                                    break;

                                case AeroFreezables.SortedSides:
                                    sideBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                                    break;
                            }

                            sideBrush.Freeze();

                            CacheFreezable(sideBrush, (int)sideType);
                        }
                    }

                    dc.DrawRectangle(sideBrush, null, new Rect(0.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                    dc.DrawRectangle(sideBrush, null, new Rect(size.Width - 1.0, 0.0, 1.0, Max0(size.Height - 0.95)));
                }
            }

            if (isPressed && (size.Width >= 4.0) && (size.Height >= 4.0))
            {
                // When pressed, there are added borders on the left and top
                LinearGradientBrush topBrush = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedTop);
                if (topBrush == null)
                {
                    topBrush = new LinearGradientBrush();
                    topBrush.StartPoint = new Point();
                    topBrush.EndPoint = new Point(0.0, 1.0);
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.0));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x86, 0xA3, 0xB2), 0.1));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 0.9));
                    topBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xAA, 0xCE, 0xE1), 1.0));
                    topBrush.Freeze();

                    CacheFreezable(topBrush, (int)AeroFreezables.PressedTop);
                }

                dc.DrawRectangle(topBrush, null, new Rect(0.0, 0.0, size.Width, 2.0));

                LinearGradientBrush pressedBevel = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.PressedBevel);
                if (pressedBevel == null)
                {
                    pressedBevel = new LinearGradientBrush();
                    pressedBevel.StartPoint = new Point();
                    pressedBevel.EndPoint = new Point(0.0, 1.0);
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.0));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xA2, 0xCB, 0xE0), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x72, 0xBC, 0xDF), 0.4));
                    pressedBevel.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x6E, 0xB8, 0xDC), 1.0));
                    pressedBevel.Freeze();

                    CacheFreezable(pressedBevel, (int)AeroFreezables.PressedBevel);
                }

                dc.DrawRectangle(pressedBevel, null, new Rect(1.0, 0.0, 1.0, size.Height - 0.95));
                dc.DrawRectangle(pressedBevel, null, new Rect(size.Width - 2.0, 0.0, 1.0, size.Height - 0.95));
            }

            if (size.Height >= 2.0)
            {
                // Draw the bottom border
                AeroFreezables bottomType = AeroFreezables.NormalBottom;
                if (isPressed)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isHovered)
                {
                    bottomType = AeroFreezables.PressedOrHoveredBottom;
                }
                else if (isSorted || isSelected)
                {
                    bottomType = AeroFreezables.SortedBottom;
                }

                SolidColorBrush bottomBrush = (SolidColorBrush)GetCachedFreezable((int)bottomType);
                if (bottomBrush == null)
                {
                    switch (bottomType)
                    {
                        case AeroFreezables.NormalBottom:
                            bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xD5, 0xD5, 0xD5));
                            break;

                        case AeroFreezables.PressedOrHoveredBottom:
                            bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xC9, 0xE3));
                            break;

                        case AeroFreezables.SortedBottom:
                            bottomBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x96, 0xD9, 0xF9));
                            break;
                    }

                    bottomBrush.Freeze();

                    CacheFreezable(bottomBrush, (int)bottomType);
                }

                dc.DrawRectangle(bottomBrush, null, new Rect(0.0, size.Height - 1.0, size.Width, 1.0));
            }

            if (isSorted && (size.Width > 14.0) && (size.Height > 10.0))
            {
                // Draw the sort arrow
                TranslateTransform positionTransform = new TranslateTransform((size.Width - 8.0) * 0.5, 1.0);
                positionTransform.Freeze();
                dc.PushTransform(positionTransform);

                bool ascending = (sortDirection == ListSortDirection.Ascending);
                PathGeometry arrowGeometry = (PathGeometry)GetCachedFreezable(ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                if (arrowGeometry == null)
                {
                    arrowGeometry = new PathGeometry();
                    PathFigure arrowFigure = new PathFigure();

                    if (ascending)
                    {
                        arrowFigure.StartPoint = new Point(0.0, 4.0);

                        LineSegment line = new LineSegment(new Point(4.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(8.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }
                    else
                    {
                        arrowFigure.StartPoint = new Point(0.0, 0.0);

                        LineSegment line = new LineSegment(new Point(8.0, 0.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);

                        line = new LineSegment(new Point(4.0, 4.0), false);
                        line.Freeze();
                        arrowFigure.Segments.Add(line);
                    }

                    arrowFigure.IsClosed = true;
                    arrowFigure.Freeze();

                    arrowGeometry.Figures.Add(arrowFigure);
                    arrowGeometry.Freeze();

                    CacheFreezable(arrowGeometry, ascending ? (int)AeroFreezables.ArrowUpGeometry : (int)AeroFreezables.ArrowDownGeometry);
                }

                // Draw two arrows, one inset in the other. This is to achieve a double gradient over both the border and the fill.
                LinearGradientBrush arrowBorder = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowBorder);
                if (arrowBorder == null)
                {
                    arrowBorder = new LinearGradientBrush();
                    arrowBorder.StartPoint = new Point();
                    arrowBorder.EndPoint = new Point(1.0, 1.0);
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.0));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x3C, 0x5E, 0x72), 0.1));
                    arrowBorder.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xC3, 0xE4, 0xF5), 1.0));
                    arrowBorder.Freeze();
                    CacheFreezable(arrowBorder, (int)AeroFreezables.ArrowBorder);
                }

                dc.DrawGeometry(arrowBorder, null, arrowGeometry);

                LinearGradientBrush arrowFill = (LinearGradientBrush)GetCachedFreezable((int)AeroFreezables.ArrowFill);
                if (arrowFill == null)
                {
                    arrowFill = new LinearGradientBrush();
                    arrowFill.StartPoint = new Point();
                    arrowFill.EndPoint = new Point(1.0, 1.0);
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.0));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0x61, 0x96, 0xB6), 0.1));
                    arrowFill.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0xCA, 0xE6, 0xF5), 1.0));
                    arrowFill.Freeze();
                    CacheFreezable(arrowFill, (int)AeroFreezables.ArrowFill);
                }

                // Inset the fill arrow inside the border arrow
                ScaleTransform arrowScale = (ScaleTransform)GetCachedFreezable((int)AeroFreezables.ArrowFillScale);
                if (arrowScale == null)
                {
                    arrowScale = new ScaleTransform(0.75, 0.75, 3.5, 4.0);
                    arrowScale.Freeze();
                    CacheFreezable(arrowScale, (int)AeroFreezables.ArrowFillScale);
                }

                dc.PushTransform(arrowScale);

                dc.DrawGeometry(arrowFill, null, arrowGeometry);

                dc.Pop(); // Scale Transform
                dc.Pop(); // Position Transform
            }

            if (horizontal)
            {
                dc.Pop(); // Horizontal Rotate
            }
        }
示例#13
0
 Brush GetRandomBrush()
 {
     byte[] b = new byte[4];
     randy.NextBytes(b);
     Color c1 = Color.FromRgb(b[0], b[1], b[2]);
     randy.NextBytes(b);
     Color c2 = Color.FromRgb(b[0], b[1], b[2]);
     Brush brush = new LinearGradientBrush(c1, c2, 90);
     brush.Freeze();
     return brush;
 }
示例#14
0
        public GameSettingsControl()
        {
            SetCols(2);
            SetRows(9);

            Width = 250;
            VerticalAlignment = VerticalAlignment.Top;
            HorizontalAlignment = HorizontalAlignment.Left;
            Margin = new Thickness(5);
            DataContext = this;

            _info = InteractionService.LocalizatorEnvironment.Provide();
            InteractionService.LocalizatorEnvironment.InfoProvided += OnLocalizatorEnvironmentProvided;

            LinearGradientBrush backgroundStroke = new LinearGradientBrush
            {
                EndPoint = new Point(0.5, 1),
                StartPoint = new Point(0.5, 0),
                RelativeTransform = new RotateTransform(115, 0.5, 0.5),
                GradientStops = new GradientStopCollection
                {
                    new GradientStop(Color.FromArgb(0xff, 0x61, 0x61, 0x61), 0),
                    new GradientStop(Color.FromArgb(0xff, 0xF2, 0xF2, 0xF2), 0.504),
                    new GradientStop(Color.FromArgb(0xff, 0xAE, 0xB1, 0xB1), 1)
                }
            };
            backgroundStroke.Freeze();

            LinearGradientBrush backgroundFill = new LinearGradientBrush
            {
                MappingMode = BrushMappingMode.RelativeToBoundingBox,
                StartPoint = new Point(0.5, 1.0),
                EndPoint = new Point(0.5, -0.4),
                GradientStops = new GradientStopCollection
                {
                    new GradientStop(Color.FromArgb(0xBB, 0x44, 0x71, 0xc1), 0),
                    new GradientStop(Color.FromArgb(0xBB, 0x28, 0x36, 0x65), 1)
                }
            };
            backgroundFill.Freeze();

            Rectangle backround = AddUiElement(new Rectangle {Stroke = backgroundStroke, Fill = backgroundFill, StrokeThickness = 5}, 0, 0, 9, 2);

            InverseBoolConverter inverseBoolConverter = new InverseBoolConverter();
            Thickness rowMargin = new Thickness(0, 8, 0, 3);

            const string screenGroup = "Отображение:";
            AddUiElement(UiTextBlockFactory.Create(screenGroup), 0, 0, 0, 2).Margin = rowMargin;
            AddUiElement(UiRadioButtonFactory.Create(screenGroup, "Экран", true), 1, 0).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsFullScreen") {Mode = BindingMode.TwoWay});
            AddUiElement(UiRadioButtonFactory.Create(screenGroup, "Окно", false), 1, 1).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsFullScreen") {Mode = BindingMode.TwoWay, Converter = inverseBoolConverter});

            const string resolutionGroup = "Разрешение:";
            AddUiElement(UiTextBlockFactory.Create(resolutionGroup), 2, 0, 0, 2).Margin = rowMargin;
            AddUiElement(UiRadioButtonFactory.Create(resolutionGroup, "1920x1080", true), 3, 0).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsFullHd") {Mode = BindingMode.TwoWay});
            AddUiElement(UiRadioButtonFactory.Create(resolutionGroup, "1280x720", false), 3, 1).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsFullHd") {Mode = BindingMode.TwoWay, Converter = inverseBoolConverter});

            const string voiceGroup = "Озвучка:";
            AddUiElement(UiTextBlockFactory.Create(voiceGroup), 4, 0, 0, 2).Margin = rowMargin;
            AddUiElement(UiRadioButtonFactory.Create(voiceGroup, "Японская", true), 5, 0).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsNihonVoice") {Mode = BindingMode.TwoWay});
            AddUiElement(UiRadioButtonFactory.Create(voiceGroup, "Английская", false), 5, 1).SetBinding(ToggleButton.IsCheckedProperty, new Binding("IsNihonVoice") {Mode = BindingMode.TwoWay, Converter = inverseBoolConverter});

            UiCheckBox switchButtons = AddUiElement(UiCheckBoxFactory.Create("Поменять кнопки X/O", null), 6, 0, 0, 2);
            switchButtons.Margin = rowMargin;
            switchButtons.IsThreeState = true;
            switchButtons.SetBinding(ToggleButton.IsCheckedProperty, new Binding("SwitchButtons") {Mode = BindingMode.TwoWay});

            AddUiElement(UiTextBlockFactory.Create("MSAA:"), 7, 0).Margin = rowMargin;
            UiComboBox antiAliasing = AddUiElement(UiComboBoxFactory.Create(), 8, 0);
            antiAliasing.ItemStringFormat = "x{0}";
            antiAliasing.ItemsSource = new[] {2, 4, 8, 16};
            antiAliasing.SelectedIndex = 3;
            antiAliasing.SetBinding(Selector.SelectedItemProperty, new Binding("AntiAliasing") {Mode = BindingMode.TwoWay});
            antiAliasing.Margin = new Thickness(0, 0, 0, 8);

            AddUiElement(UiTextBlockFactory.Create("Тени:"), 7, 1).Margin = rowMargin;
            UiComboBox shadows = AddUiElement(UiComboBoxFactory.Create(), 8, 1);
            shadows.ItemStringFormat = "{0}x{0}";
            shadows.ItemsSource = new[] {512, 1024, 2048, 4096, 8192};
            shadows.SelectedIndex = 1;
            shadows.SetBinding(Selector.SelectedItemProperty, new Binding("ShadowResolution") {Mode = BindingMode.TwoWay});
            shadows.Margin = new Thickness(0, 0, 0, 8);

            foreach (FrameworkElement child in Children)
            {
                if (!ReferenceEquals(child, backround))
                    child.Margin = new Thickness(child.Margin.Left + 8, child.Margin.Top, child.Margin.Right + 8, child.Margin.Bottom);

                TextBlock textblock = child as TextBlock;
                if (textblock != null)
                {
                    textblock.Foreground = Brushes.WhiteSmoke;
                    textblock.FontWeight = FontWeight.FromOpenTypeWeight(500);
                    continue;
                }

                Control control = child as Control;
                if (control != null && !(control is ComboBox))
                    control.Foreground = Brushes.WhiteSmoke;
            }
        }
示例#15
0
        // Creates an array of brushes needed to render this 
        private static Brush[] CreateBrushes(Color c, CornerRadius cornerRadius)
        {
            Brush[] brushes = new Brush[9];

            // Create center brush
            brushes[Center] = new SolidColorBrush(c);
            brushes[Center].Freeze();



            // Sides
            GradientStopCollection sideStops = CreateStops(c, 0);
            LinearGradientBrush top = new LinearGradientBrush(sideStops, new Point(0, 1), new Point(0, 0));
            top.Freeze();
            brushes[Top] = top;

            LinearGradientBrush left = new LinearGradientBrush(sideStops, new Point(1, 0), new Point(0, 0));
            left.Freeze();
            brushes[Left] = left;

            LinearGradientBrush right = new LinearGradientBrush(sideStops, new Point(0, 0), new Point(1, 0));
            right.Freeze();
            brushes[Right] = right;

            LinearGradientBrush bottom = new LinearGradientBrush(sideStops, new Point(0, 0), new Point(0, 1));
            bottom.Freeze();
            brushes[Bottom] = bottom;

            // Corners

            // Use side stops if the corner radius is 0
            GradientStopCollection topLeftStops;
            if (cornerRadius.TopLeft == 0)
                topLeftStops = sideStops;
            else
                topLeftStops = CreateStops(c, cornerRadius.TopLeft);

            RadialGradientBrush topLeft = new RadialGradientBrush(topLeftStops);
            topLeft.RadiusX = 1;
            topLeft.RadiusY = 1;
            topLeft.Center = new Point(1, 1);
            topLeft.GradientOrigin = new Point(1, 1);
            topLeft.Freeze();
            brushes[TopLeft] = topLeft;

            // Reuse previous stops if corner radius is the same as side or top left
            GradientStopCollection topRightStops;
            if (cornerRadius.TopRight == 0)
                topRightStops = sideStops;
            else if (cornerRadius.TopRight == cornerRadius.TopLeft)
                topRightStops = topLeftStops;
            else
                topRightStops = CreateStops(c, cornerRadius.TopRight);

            RadialGradientBrush topRight = new RadialGradientBrush(topRightStops);
            topRight.RadiusX = 1;
            topRight.RadiusY = 1;
            topRight.Center = new Point(0, 1);
            topRight.GradientOrigin = new Point(0, 1);
            topRight.Freeze();
            brushes[TopRight] = topRight;

            // Reuse previous stops if corner radius is the same as any of the previous radii
            GradientStopCollection bottomLeftStops;
            if (cornerRadius.BottomLeft == 0)
                bottomLeftStops = sideStops;
            else if (cornerRadius.BottomLeft == cornerRadius.TopLeft)
                bottomLeftStops = topLeftStops;
            else if (cornerRadius.BottomLeft == cornerRadius.TopRight)
                bottomLeftStops = topRightStops;
            else
                bottomLeftStops = CreateStops(c, cornerRadius.BottomLeft);

            RadialGradientBrush bottomLeft = new RadialGradientBrush(bottomLeftStops);
            bottomLeft.RadiusX = 1;
            bottomLeft.RadiusY = 1;
            bottomLeft.Center = new Point(1, 0);
            bottomLeft.GradientOrigin = new Point(1, 0);
            bottomLeft.Freeze();
            brushes[BottomLeft] = bottomLeft;

            // Reuse previous stops if corner radius is the same as any of the previous radii
            GradientStopCollection bottomRightStops;
            if (cornerRadius.BottomRight == 0)
                bottomRightStops = sideStops;
            else if (cornerRadius.BottomRight == cornerRadius.TopLeft)
                bottomRightStops = topLeftStops;
            else if (cornerRadius.BottomRight == cornerRadius.TopRight)
                bottomRightStops = topRightStops;
            else if (cornerRadius.BottomRight == cornerRadius.BottomLeft)
                bottomRightStops = bottomLeftStops;
            else
                bottomRightStops = CreateStops(c, cornerRadius.BottomRight);

            RadialGradientBrush bottomRight = new RadialGradientBrush(bottomRightStops);
            bottomRight.RadiusX = 1;
            bottomRight.RadiusY = 1;
            bottomRight.Center = new Point(0, 0);
            bottomRight.GradientOrigin = new Point(0, 0);
            bottomRight.Freeze();
            brushes[BottomRight] = bottomRight;

            return brushes;
        }
示例#16
0
文件: Theme.cs 项目: se7ensoft/dnSpy
 public override IEnumerable<Tuple<object, object>> GetResourceKeyValues(MyHighlightingColor hlColor)
 {
     var br = new LinearGradientBrush() {
         StartPoint = StartPoint,
         EndPoint = EndPoint,
     };
     if (MappingMode != null)
         br.MappingMode = MappingMode.Value;
     for (int i = 0; i < GradientOffsets.Length; i++)
         br.GradientStops.Add(new GradientStop(((SolidColorBrush)hlColor.GetHighlightingBrush(i).GetBrush(null)).Color, GradientOffsets[i]));
     br.Freeze();
     yield return new Tuple<object, object>(ResourceKey, br);
 }
示例#17
0
        /// <summary>
        /// スペクトルの背景色を設定します。
        /// </summary>
        private void SetBackground()
        {
            var backgroundBrush = new LinearGradientBrush()
            {
                StartPoint = new Point(0.5, 0),
                EndPoint = new Point(0.5, 1),
            };

            var spectrumColors = ColorUtils.GetSpectrumColors(SpectrumColorCount);
            for (var i = 0; i < SpectrumColorCount; ++i)
            {
                var offset = i * 1.0 / SpectrumColorCount;
                var gradientStop = new GradientStop(spectrumColors[i], offset);

                backgroundBrush.GradientStops.Add(gradientStop);
            }

            backgroundBrush.Freeze();
            Background = backgroundBrush;
        }
示例#18
0
        /// <summary>
        /// Custom StrokeEraser Drawing
        /// </summary>
        /// <returns></returns>
        private static Drawing CreateStrokeEraserDrawing()
        {
            DrawingGroup drawingGroup = new DrawingGroup();
            DrawingContext dc = null;

            try
            {
                dc = drawingGroup.Open();
                LinearGradientBrush brush1 = new LinearGradientBrush(
                                                    Color.FromRgb(240, 242, 255),   // Start Color
                                                    Color.FromRgb(180, 207, 248),   // End Color
                                                    45f                             // Angle
                                                    );
                brush1.Freeze();

                SolidColorBrush brush2 = new SolidColorBrush(Color.FromRgb(180, 207, 248));
                brush2.Freeze();

                Pen pen1 = new Pen(Brushes.Gray, 0.7);
                pen1.Freeze();

                PathGeometry pathGeometry = new PathGeometry();

                PathFigure path = new PathFigure();
                path.StartPoint = new Point(5, 5);

                LineSegment segment = new LineSegment(new Point(16, 5), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(26, 15), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(15, 15), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(5, 5), true);
                segment.Freeze();
                path.Segments.Add(segment);

                path.IsClosed = true;
                path.Freeze();

                pathGeometry.Figures.Add(path);

                path = new PathFigure();
                path.StartPoint = new Point(5, 5);

                segment = new LineSegment(new Point(5, 10), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(15, 19), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(15, 15), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(5, 5), true);
                segment.Freeze();
                path.Segments.Add(segment);
                path.IsClosed = true;
                path.Freeze();

                pathGeometry.Figures.Add(path);
                pathGeometry.Freeze();

                PathGeometry pathGeometry1 = new PathGeometry();
                path = new PathFigure();
                path.StartPoint = new Point(15, 15);

                segment = new LineSegment(new Point(15, 19), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(26, 19), true);
                segment.Freeze();
                path.Segments.Add(segment);

                segment = new LineSegment(new Point(26, 15), true);
                segment.Freeze();
                path.Segments.Add(segment);
                segment.Freeze();
                segment = new LineSegment(new Point(15, 15), true);

                path.Segments.Add(segment);
                path.IsClosed = true;
                path.Freeze();

                pathGeometry1.Figures.Add(path);
                pathGeometry1.Freeze();

                dc.DrawGeometry(brush1, pen1, pathGeometry);
                dc.DrawGeometry(brush2, pen1, pathGeometry1);
                dc.DrawLine(pen1, new Point(5, 5), new Point(5, 0));
                dc.DrawLine(pen1, new Point(5, 5), new Point(0, 5));
                dc.DrawLine(pen1, new Point(5, 5), new Point(2, 2));
                dc.DrawLine(pen1, new Point(5, 5), new Point(8, 2));
                dc.DrawLine(pen1, new Point(5, 5), new Point(2, 8));
            }
            finally
            {
                if ( dc != null )
                {
                    dc.Close();
                }
            }

            return drawingGroup;
        }
示例#19
0
        public void AssocColor(int seriesId, Color b)
        {
            Color bTransparent = b;
            bTransparent.A = 0;

            GradientStopCollection gs = new GradientStopCollection();
            gs.Add(new GradientStop(bTransparent, 0));
            gs.Add(new GradientStop(b, 0.2));
            LinearGradientBrush g = new LinearGradientBrush(gs, new Point(0, 0), Orientation == System.Windows.Controls.Orientation.Horizontal ? new Point(ActualWidth, 0) : new Point(0, ActualHeight));
            g.MappingMode = BrushMappingMode.Absolute;
            g.Freeze();
            brushes[seriesId] = g;
        }
        /// <summary>
        /// 新しいインスタンスを生成します。
        /// </summary>
        public LineGraph()
        {
            this.SizeChanged += OnSizeChanged;

            _xAxisMoveAreaBrush = new LinearGradientBrush();
            _xAxisMoveAreaBrush.StartPoint = new Point(0, 0.5);
            _xAxisMoveAreaBrush.EndPoint = new Point(1, 0.5);
            _xAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 0.0));
            _xAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0x60, 0xDD, 0xA0, 0xDD), 0.5));
            _xAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1.0));
            _xAxisMoveAreaBrush.Freeze();

            _yAxisMoveAreaBrush = new LinearGradientBrush();
            _yAxisMoveAreaBrush.StartPoint = new Point(0.5, 0);
            _yAxisMoveAreaBrush.EndPoint = new Point(0.5, 1);
            _yAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 0.0));
            _yAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0x60, 0xDD, 0xA0, 0xDD), 0.5));
            _yAxisMoveAreaBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1.0));
            _yAxisMoveAreaBrush.Freeze();
        }
示例#21
0
 private static LinearGradientBrush GenerateHeatGradient()
 {
     var brush = new LinearGradientBrush();
     /*for (double i = 0; i < 1; i += 0.01)
     {
         brush.GradientStops.Add(new GradientStop(HSL2RGB(i, 0.5, 0.5), i));
         Debug.Print("Colour[{0}] {1}", i, HSL2RGB(i, 0.5, 0.5));
     }*/
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 1d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 5, 0), 0.99d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 10, 0), 0.98d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 15, 0), 0.97d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 25, 0), 0.96d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 30, 0), 0.95d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 35, 0), 0.94d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 45, 0), 0.93d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 50, 0), 0.92d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 60, 0), 0.91d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 65, 0), 0.90d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 70, 0), 0.89d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 75, 0), 0.88d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 80, 0), 0.87d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 90, 0), 0.86d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 95, 0), 0.85d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 100, 0), 0.84d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 105, 0), 0.83d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 120, 0), 0.82d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 135, 0), 0.81d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 145, 0), 0.80d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 160, 0), 0.79d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 180, 0), 0.78d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 200, 0), 0.77d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 225, 0), 0.76d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 245, 0), 0.75d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 255, 0), 0.74d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(240, 255, 0), 0.73d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(230, 255, 0), 0.72d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(220, 255, 0), 0.71d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(205, 255, 0), 0.70d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(195, 255, 0), 0.69d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(180, 255, 0), 0.68d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(175, 255, 0), 0.67d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(165, 255, 0), 0.66d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(155, 255, 0), 0.65d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(140, 255, 0), 0.64d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(130, 255, 0), 0.63d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(115, 255, 0), 0.62d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(105, 255, 0), 0.61d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(90, 255, 0), 0.60d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(80, 255, 0), 0.59d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(70, 255, 0), 0.58d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(55, 255, 0), 0.57d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(35, 255, 0), 0.56d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(20, 255, 0), 0.55d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(10, 255, 0), 0.54d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.53d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 10), 0.52d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 25), 0.51d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 45), 0.50d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 60), 0.49d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 70), 0.48d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 85), 0.47d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 100), 0.46d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 110), 0.45d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 125), 0.44d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 135), 0.43d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 150), 0.42d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 165), 0.41d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 175), 0.40d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 190), 0.39d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 200), 0.38d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 210), 0.37d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 220), 0.36d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 235), 0.35d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 240), 0.34d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 250), 0.33d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 255), 0.32d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 230, 255), 0.31d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 220, 255), 0.30d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 205, 255), 0.29d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 190, 255), 0.28d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 180, 255), 0.27d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 170, 255), 0.26d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 150, 255), 0.25d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 130, 255), 0.24d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 105, 255), 0.23d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 95, 255), 0.22d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 80, 255), 0.21d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 70, 255), 0.20d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 55, 255), 0.19d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 45, 255), 0.18d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 30, 255), 0.17d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 20, 255), 0.16d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 0.15d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 240), 0.14d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 230), 0.13d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 220), 0.12d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 200), 0.11d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 180), 0.10d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 160), 0.09d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 150), 0.08d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 140), 0.07d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 120), 0.06d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 100), 0.05d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 80), 0.04d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 60), 0.03d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 40), 0.02d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 20), 0.01d));
     brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 0), 0.0d));
     brush.Freeze();
     return brush;
 }
示例#22
0
		private LinearGradientBrush GetIcon() {
			LinearGradientBrush rez = new LinearGradientBrush();
			if (_frame.Count == 0)
				return rez;
			rez.EndPoint = new System.Windows.Point(1, .5);
			rez.StartPoint = new System.Windows.Point(0, .5);
			rez.GradientStops.Add(new GradientStop(_frame[0].BegColor, 0));
			for (int i = 0; i < _frame.Count; i++) {
				if (i > 0 && _frame[i].EndColor == _frame[i].BegColor)
					rez.GradientStops.Add(new GradientStop(_frame[i].BegColor, ((double)i) / _frame.Count));
				rez.GradientStops.Add(new GradientStop(_frame[i].EndColor, ((double)i + 1) / _frame.Count));
			}
			rez.Freeze();
			return rez;
		}
示例#23
0
        public static LinearGradientBrush GradientBrush(Color color, double luminance = 0.94, double saturation = 1.2)
        {
            // 彩度を上げる
            int[] numbers = {color.R, color.G, color.B};
            double n1 = numbers.Max();
            double n2 = numbers.Min();
            double n3 = n1 / (n1 - n2);
            double r = (color.R - n1) * saturation + n1;
            double g = (color.G - n1) * saturation + n1;
            double b = (color.B - n1) * saturation + n1;
            r = Math.Max(r, 0);
            g = Math.Max(g, 0);
            b = Math.Max(b, 0);

            // 明るさを下げる
            double l1 = 0.298912 * color.R + 0.586611 * color.G + 0.114478 * color.B;
            double l2 = 0.298912 * r + 0.586611 * g + 0.114478 * b;
            double f = (l2 / l1) * luminance;
            r *= f;
            g *= f;
            b *= f;
            r = Math.Min(r, 255);
            g = Math.Min(g, 255);
            b = Math.Min(b, 255);

            var color2 = Color.FromRgb((byte)r, (byte)g, (byte)b);

            var brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0, 0.5);
            brush.EndPoint = new Point(0, 1);
            brush.GradientStops.Add(new GradientStop(color, 0.0));
            brush.GradientStops.Add(new GradientStop(color2, 1.0));
            brush.Freeze();

            return brush;
        }
示例#24
0
 public override IEnumerable<Tuple<object, object>> GetResourceKeyValues(ThemeColor hlColor)
 {
     var br = new LinearGradientBrush() {
         StartPoint = StartPoint,
         EndPoint = EndPoint,
     };
     for (int i = 0; i < GradientOffsets.Length; i++) {
         var gs = new GradientStop(((SolidColorBrush)hlColor.GetBrushByIndex(i)).Color, GradientOffsets[i]);
         gs.Freeze();
         br.GradientStops.Add(gs);
     }
     br.Freeze();
     yield return new Tuple<object, object>(ResourceKey, br);
 }
示例#25
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="adornedElement">The adorned InkCanvas</param>
        internal InkCanvasSelectionAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            Debug.Assert(adornedElement is InkCanvasInnerCanvas, 
                "InkCanvasSelectionAdorner only should be used by InkCanvas internally");

            // Initialize the internal data.
            _adornerBorderPen = new Pen(Brushes.Black, 1.0);
            DoubleCollection dashes = new DoubleCollection( );
            dashes.Add(4.5);
            dashes.Add(4.5);
            _adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25);
            _adornerBorderPen.DashCap = PenLineCap.Flat;
            _adornerBorderPen.Freeze();

            _adornerPenBrush = new Pen(new SolidColorBrush(Color.FromRgb(132, 146, 222)), 1);
            _adornerPenBrush.Freeze();

            _adornerFillBrush = new LinearGradientBrush(  Color.FromRgb(240, 242, 255), //start color
                                            Color.FromRgb(180, 207, 248),               //end color
                                            45f                                         //angle
                                            );
            _adornerFillBrush.Freeze();

            // Create a hatch pen
            DrawingGroup hatchDG = new DrawingGroup( );
            DrawingContext dc = null;

            try
            {
                dc = hatchDG.Open( );

                dc.DrawRectangle(
                    Brushes.Transparent,
                    null,
                    new Rect(0.0, 0.0, 1f, 1f));

                Pen squareCapPen = new Pen(Brushes.Black, LineThickness);
                squareCapPen.StartLineCap = PenLineCap.Square;
                squareCapPen.EndLineCap = PenLineCap.Square;

                dc.DrawLine(squareCapPen,
                    new Point(1f, 0f), new Point(0f, 1f));
            }
            finally
            {
                if ( dc != null )
                {
                    dc.Close( );
                }
            }
            hatchDG.Freeze();

            DrawingBrush tileBrush = new DrawingBrush(hatchDG);
            tileBrush.TileMode = TileMode.Tile;
            tileBrush.Viewport = new Rect(0, 0, HatchBorderMargin, HatchBorderMargin);
            tileBrush.ViewportUnits = BrushMappingMode.Absolute;
            tileBrush.Freeze();

            _hatchPen = new Pen(tileBrush, HatchBorderMargin);
            _hatchPen.Freeze();

            _elementsBounds = new List<Rect>();
            _strokesBounds = Rect.Empty;
        }
 private static Brush[] CreateBrushes(System.Windows.Media.Color c, System.Windows.CornerRadius cornerRadius)
 {
     GradientStopCollection stops2;
     GradientStopCollection stops3;
     GradientStopCollection stops4;
     GradientStopCollection stops5;
     Brush[] brushArray = new Brush[9];
     brushArray[4] = new SolidColorBrush(c);
     brushArray[4].Freeze();
     GradientStopCollection gradientStopCollection = CreateStops(c, 0.0);
     LinearGradientBrush brush = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 1.0), new Point(0.0, 0.0));
     brush.Freeze();
     brushArray[1] = brush;
     LinearGradientBrush brush2 = new LinearGradientBrush(gradientStopCollection, new Point(1.0, 0.0), new Point(0.0, 0.0));
     brush2.Freeze();
     brushArray[3] = brush2;
     LinearGradientBrush brush3 = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 0.0), new Point(1.0, 0.0));
     brush3.Freeze();
     brushArray[5] = brush3;
     LinearGradientBrush brush4 = new LinearGradientBrush(gradientStopCollection, new Point(0.0, 0.0), new Point(0.0, 1.0));
     brush4.Freeze();
     brushArray[7] = brush4;
     if (cornerRadius.TopLeft == 0.0)
     {
         stops2 = gradientStopCollection;
     }
     else
     {
         stops2 = CreateStops(c, cornerRadius.TopLeft);
     }
     RadialGradientBrush brush5 = new RadialGradientBrush(stops2)
     {
         RadiusX = 1.0,
         RadiusY = 1.0,
         Center = new Point(1.0, 1.0),
         GradientOrigin = new Point(1.0, 1.0)
     };
     brush5.Freeze();
     brushArray[0] = brush5;
     if (cornerRadius.TopRight == 0.0)
     {
         stops3 = gradientStopCollection;
     }
     else if (cornerRadius.TopRight == cornerRadius.TopLeft)
     {
         stops3 = stops2;
     }
     else
     {
         stops3 = CreateStops(c, cornerRadius.TopRight);
     }
     RadialGradientBrush brush6 = new RadialGradientBrush(stops3)
     {
         RadiusX = 1.0,
         RadiusY = 1.0,
         Center = new Point(0.0, 1.0),
         GradientOrigin = new Point(0.0, 1.0)
     };
     brush6.Freeze();
     brushArray[2] = brush6;
     if (cornerRadius.BottomLeft == 0.0)
     {
         stops4 = gradientStopCollection;
     }
     else if (cornerRadius.BottomLeft == cornerRadius.TopLeft)
     {
         stops4 = stops2;
     }
     else if (cornerRadius.BottomLeft == cornerRadius.TopRight)
     {
         stops4 = stops3;
     }
     else
     {
         stops4 = CreateStops(c, cornerRadius.BottomLeft);
     }
     RadialGradientBrush brush7 = new RadialGradientBrush(stops4)
     {
         RadiusX = 1.0,
         RadiusY = 1.0,
         Center = new Point(1.0, 0.0),
         GradientOrigin = new Point(1.0, 0.0)
     };
     brush7.Freeze();
     brushArray[6] = brush7;
     if (cornerRadius.BottomRight == 0.0)
     {
         stops5 = gradientStopCollection;
     }
     else if (cornerRadius.BottomRight == cornerRadius.TopLeft)
     {
         stops5 = stops2;
     }
     else if (cornerRadius.BottomRight == cornerRadius.TopRight)
     {
         stops5 = stops3;
     }
     else if (cornerRadius.BottomRight == cornerRadius.BottomLeft)
     {
         stops5 = stops4;
     }
     else
     {
         stops5 = CreateStops(c, cornerRadius.BottomRight);
     }
     RadialGradientBrush brush8 = new RadialGradientBrush(stops5)
     {
         RadiusX = 1.0,
         RadiusY = 1.0,
         Center = new Point(0.0, 0.0),
         GradientOrigin = new Point(0.0, 0.0)
     };
     brush8.Freeze();
     brushArray[8] = brush8;
     return brushArray;
 }
示例#27
0
 private RenderTargetBitmap DrawHeatKey(int width, int height)
 {
     var heatKeyBitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
     ClearRenderTargetBitmap(heatKeyBitmap, Brushes.Black);
     var brush = new LinearGradientBrush();
     brush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 255, 255, 255), 0.0));
     brush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 255, 255), 1));
     brush.Freeze();
     var visual = new DrawingVisual();
     using (var context = visual.RenderOpen())
     {
         context.DrawRectangle(brush, null, new Rect(0, 0, heatKeyBitmap.PixelWidth, heatKeyBitmap.PixelHeight));
     }
     heatKeyBitmap.Render(visual);
     return heatKeyBitmap;
 }
        /// <summary>
        /// Create the a brush based off the enum given and the minimum and maximum value.
        /// The brush will be created, then frozen and returned.
        /// Spectrum of the color is 0.0 to 1.0.
        /// 
        /// I added black to the begining of some some, ranging from 0.0-0.01 to 0.0 - 0.1 
        /// to display black for bad velocity with a velocity of 0.  
        /// </summary>
        /// <param name="brushEnum">Brush chosen.</param>
        /// <param name="alphaValue">The transparency of the display.</param>
        /// <returns>Brush for the given enum.</returns>
        public static Brush GetBrush(ColormapBrush.ColormapBrushEnum brushEnum, byte alphaValue = 255)
        {
            // Determine which brush is being selected
            // Then create the brush and return
            switch (brushEnum)
            {
                case ColormapBrush.ColormapBrushEnum.Spring:
                    LinearGradientBrush springBrush = new LinearGradientBrush();
                    springBrush.StartPoint = new Point(0, 0.5);                                                         // Creates a horizontal linear gradient instead of it looking diagonal
                    springBrush.EndPoint = new Point(1, 0.5);
                    springBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                 // Add Black for bad Velocity (0 Velocity)
                    springBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 0, 255), 0.1));      // R = 255     G = 255*0 = 0        B = 255-G = 255
                    springBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 255, 0), 1.0));      // R = 255     G = 255*1 = 255      B = 255-G = 0
                    springBrush.Freeze();
                    return springBrush;

                case ColormapBrush.ColormapBrushEnum.Summer:
                    LinearGradientBrush summerBrush = new LinearGradientBrush();
                    summerBrush.StartPoint = new Point(0, 0.5);                                                         // Creates a horizontal linear gradient instead of it looking diagonal
                    summerBrush.EndPoint = new Point(1, 0.5);
                    summerBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                 // Add Black for bad Velocity (0 Velocity)
                    summerBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 0, 128, 102), 0.01));     // R = 255*0 = 0        G = 255 * 0.5 * (1 + 0) = 127.5     B = 255*0.4 = 102
                    summerBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 255, 102), 1.0));    // R = 255*1 = 255      G = 255 * 0.5 * (1 + 1) = 255       B = 255*0.4 = 102
                    summerBrush.Freeze();
                    return summerBrush;

                case ColormapBrush.ColormapBrushEnum.Autumn:
                    LinearGradientBrush autumnBrush = new LinearGradientBrush();
                    autumnBrush.StartPoint = new Point(0, 0.5);                                                         // Creates a horizontal linear gradient instead of it looking diagonal
                    autumnBrush.EndPoint = new Point(1, 0.5);
                    autumnBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                 // Add Black for bad Velocity (0 Velocity)
                    autumnBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 0, 0), 0.1));        // R = 255     G = 255*0 = 0      B = 0
                    autumnBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 255, 0), 1.0));      // R = 255     G = 255*1 = 255    B = 0
                    autumnBrush.Freeze();
                    return autumnBrush;

                case ColormapBrush.ColormapBrushEnum.Winter:
                    LinearGradientBrush winterBrush = new LinearGradientBrush();
                    winterBrush.StartPoint = new Point(0, 0.5);                                                         // Creates a horizontal linear gradient instead of it looking diagonal
                    winterBrush.EndPoint = new Point(1, 0.5);
                    winterBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                 // Add Black for bad Velocity (0 Velocity)
                    winterBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 0, 0, 255), 0.01));       // R = 0        G = 255*0 = 0       B = 255 * (1.0 - (0.5 * 0)) = 255
                    winterBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 0, 255, 128), 1.0));      // R = 0        G = 255*1 = 255     B = 255 * (1.0 - (0.5 * 1)) = 128
                    winterBrush.Freeze();
                    return winterBrush;

                case ColormapBrush.ColormapBrushEnum.Gray:
                    LinearGradientBrush grayBrush = new LinearGradientBrush();
                    grayBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 0, 0, 0), 0.0));            // R = 255*0 = 0        G = 255*0 = 0       B = 255*0 = 0
                    grayBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 255, 255), 1.0));      // R = 255*1 = 255      G = 255*1 = 255     B = 255*1 = 255
                    grayBrush.Freeze();
                    return grayBrush;

                case ColormapBrush.ColormapBrushEnum.Hot:
                    LinearGradientBrush hotBrush = new LinearGradientBrush();
                    hotBrush.StartPoint = new Point(0, 0.5);                                                            // Creates a horizontal linear gradient instead of it looking diagonal
                    hotBrush.EndPoint = new Point(1, 0.5);
                    hotBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));
                    hotBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.25));
                    hotBrush.GradientStops.Add(new GradientStop(Colors.Orange, 0.50));
                    hotBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.75));
                    hotBrush.GradientStops.Add(new GradientStop(Colors.White, 1.0));
                    hotBrush.Freeze();
                    return hotBrush;

                case ColormapBrush.ColormapBrushEnum.Cool:
                    LinearGradientBrush coolBrush = new LinearGradientBrush();
                    coolBrush.StartPoint = new Point(0, 0.5);                                                           // Creates a horizontal linear gradient instead of it looking diagonal
                    coolBrush.EndPoint = new Point(1, 0.5);
                    coolBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                   // Add Black for bad Velocity (0 Velocity)
                    coolBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 0, 255, 255), 0.1));        // R = 255*0 = 0        G = 255 * (1.0 - 0) = 255       B = 255
                    coolBrush.GradientStops.Add(new GradientStop(Color.FromArgb(alphaValue, 255, 0, 255), 1.0));        // R = 255*1 = 255      G = 255 * (1.0 - 1) = 0         B = 255
                    coolBrush.Freeze();
                    return coolBrush;

                case ColormapBrush.ColormapBrushEnum.Jet:
                    LinearGradientBrush jetBrush = new LinearGradientBrush();
                    jetBrush.StartPoint = new Point(0, 0.5);                                                            // Creates a horizontal linear gradient instead of it looking diagonal
                    jetBrush.EndPoint = new Point(1, 0.5);
                    jetBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0));                                    // Add Black for bad Velocity (0 Velocity)
                    jetBrush.GradientStops.Add(new GradientStop(Colors.DarkBlue, 0.01));
                    jetBrush.GradientStops.Add(new GradientStop(Colors.Blue, 0.125));
                    jetBrush.GradientStops.Add(new GradientStop(Colors.Cyan, 0.375));
                    jetBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.625));
                    jetBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.875));
                    jetBrush.GradientStops.Add(new GradientStop(Colors.DarkRed, 1.0));
                    jetBrush.Freeze();
                    return jetBrush;

                default:
                    SolidColorBrush defaultBrush = new SolidColorBrush(Colors.YellowGreen);
                    defaultBrush.Freeze();
                    return defaultBrush;
            }
        }