Exemplo n.º 1
0
        /// <summary>Creates a vertical gradient brush.</summary>
        /// <param name="baseColour">The base colour.</param>
        /// <returns>The <see cref="LinearGradientBrush"/>.</returns>
        public static LinearGradientBrush VerticalGradientBrush(this Color baseColour)
        {
            var colors = new GradientStopCollection(new[]
            {
                new GradientStop(baseColour.Lighten(0.5d), 0.0d),
                new GradientStop(baseColour.Lighten(0.25d), 0.4d),
                new GradientStop(baseColour, 0.6d),
                new GradientStop(baseColour.Fade(0.25d), 1.0d)
            });

            return(new LinearGradientBrush(colors, 90.0d));
        }
Exemplo n.º 2
0
        private void alphaPanel_Paint(object sender, PaintEventArgs e)
        {
            var alphaBrush = new LinearGradientBrush(new Rectangle(0, 0, alphaPanel.Width, alphaPanel.Height), Color.White, Color.Black, LinearGradientMode.Horizontal);

            Graphics g = e.Graphics;

            if (!alphaPanel.Enabled)
            {
                for (int i = 0; i < alphaBrush.LinearColors.Length; i++)
                {
                    alphaBrush.LinearColors[i] = alphaBrush.LinearColors[i].Darken(190);
                }
            }

            //Draw bar
            g.FillRectangle(alphaBrush, alphaPanel.ClientRectangle);

            //Draw indicator
            byte      col = (byte)(255 - Alpha);
            Color     p   = Color.FromArgb(255, col, col, col);
            int       x   = (int)(col / 255.0f * (alphaPanel.Width - 1));
            Rectangle r   = new Rectangle(x, -1, 4, alphaPanel.Height + 1);

            using (Pen pen = new Pen(p))
                g.DrawRectangle(pen, r);

            p.Lighten(64);

            r.X     += 1;
            r.Width -= 2;

            using (Pen pen = new Pen(p))
                g.DrawRectangle(pen, r);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks whether the specified color is within the range of another by the specified amount.
        /// </summary>
        /// <param name="color">
        /// The color to compare.
        /// </param>
        /// <param name="comparer">
        /// The color to compare with.
        /// </param>
        /// <param name="amount">
        /// The range either side of the <paramref name="comparer"/>.
        /// </param>
        /// <param name="ignoreTransparency">
        /// Indicates whether to ignore transparency.
        /// </param>
        /// <returns>
        /// Returns true if is in range; else false.
        /// </returns>
        public static bool IsInRange(this Color color, Color comparer, float amount, bool ignoreTransparency)
        {
            var isInRange = false;

            var colorToCompare = ignoreTransparency ? Color.FromArgb(255, color.R, color.G, color.B) : color;

            for (var i = 0; i < amount; i++)
            {
                if (colorToCompare == comparer)
                {
                    isInRange = true;
                    break;
                }

                var darken  = comparer.Darken(i);
                var lighten = comparer.Lighten(i);

                if (colorToCompare == darken)
                {
                    isInRange = true;
                    break;
                }

                if (colorToCompare == lighten)
                {
                    isInRange = true;
                    break;
                }
            }

            return(isInRange);
        }
        public void Draw(Matrix4 mvp)
        {
            GL.Disable(EnableCap.DepthTest);

            for (int i = 0; i < PathGroups.Count; i++)
            {
                foreach (var path in PathGroups[i].PathPoints)
                {
                    var translate = new Vector3(path.Translate.X, path.Translate.Z, path.Translate.Y);

                    if (path.IsSelected)
                    {
                        Render2D.DrawFilledCircle(translate, Color.LightGreen, 30, 40, true);
                    }
                    else if (path.IsHovered)
                    {
                        Render2D.DrawFilledCircle(translate, LineColor.Lighten(40), 40, 40, true);
                    }
                    else
                    {
                        Render2D.DrawFilledCircle(translate, LineColor.Darken(20), 30, 40, true);
                    }

                    GL.LineWidth(2f);

                    GL.Enable(EnableCap.DepthTest);
                }
            }
        }
Exemplo n.º 5
0
 public BaseLaserWeapon(StrategyGame game, Color laserColor, float laserWidth, int fireTicks, int refireTicks, float range, float damage, Ship shooter, PointF offset)
     : base(game, fireTicks, refireTicks, range, damage, shooter, offset)
 {
     WeaponSound     = ESounds.plasmamini1;
     LaserPen        = new Pen(laserColor, laserWidth);
     LaserPenBoosted = new Pen(laserColor.Lighten(0.2f), laserWidth * 1.5f);
 }
Exemplo n.º 6
0
        public void UpdateBackColor(Color?colorNullable)
        {
            Color color = colorNullable ?? ObjectSlotsConfig.VacantSlotColor;

            panelPicture.BackColor      = color;
            pictureBoxPicture.BackColor = color.Lighten(0.7);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Ball"/> class.
        /// </summary>
        public Ball()
        {
            // Required to initialize variables
            InitializeComponent();

            SetValue(LightColorProperty, Color.Lighten(1.5f));
            SetValue(DarkColorProperty, Color.Lighten(0.5f));
        }
Exemplo n.º 8
0
        /// <summary> Initializes a new instance of the <see cref="Truck"/> class. </summary>
        public Truck()
        {
            InitializeComponent();

            // Calculate the initial light and dark color shades.
            SetValue(LightColorProperty, Color.Lighten(1.5f));
            SetValue(DarkColorProperty, Color.Lighten(0.5f));
        }
Exemplo n.º 9
0
        public static void ChangeSecondaryColor(Color color)
        {
            theme.SecondaryLight = new ColorPair(color.Lighten(), theme.SecondaryLight.ForegroundColor);
            theme.SecondaryMid   = new ColorPair(color, theme.SecondaryMid.ForegroundColor);
            theme.SecondaryDark  = new ColorPair(color.Darken(), theme.SecondaryDark.ForegroundColor);

            paletteHelper.SetTheme(theme);
        }
        public static void ChangeSecondaryColor(this PaletteHelper paletteHelper, Color color)
        {
            ITheme theme = paletteHelper.GetTheme();

            theme.SecondaryLight = new ColorPair(color.Lighten());
            theme.SecondaryMid   = new ColorPair(color);
            theme.SecondaryDark  = new ColorPair(color.Darken());

            paletteHelper.SetTheme(theme);
        }
Exemplo n.º 11
0
        public static void ChangePrimaryColor(this PaletteHelper paletteHelper, Color color)
        {
            ITheme theme = paletteHelper.GetTheme();

            theme.PrimaryLight = new ColorPair(color.Lighten(), theme.PrimaryLight.ForegroundColor);
            theme.PrimaryMid   = new ColorPair(color, theme.PrimaryMid.ForegroundColor);
            theme.PrimaryDark  = new ColorPair(color.Darken(), theme.PrimaryDark.ForegroundColor);

            paletteHelper.SetTheme(theme);
        }
 public static void SetAccentColor(this ITheme theme, Color accentColor)
 {
     if (theme == null)
     {
         throw new ArgumentNullException(nameof(theme));
     }
     theme.SecondaryLight = accentColor.Lighten();
     theme.SecondaryMid   = accentColor;
     theme.SecondaryDark  = accentColor.Darken();
 }
 public static void SetPrimaryColor(this ITheme theme, Color primaryColor)
 {
     if (theme == null)
     {
         throw new ArgumentNullException(nameof(theme));
     }
     theme.PrimaryLight = primaryColor.Lighten();
     theme.PrimaryMid   = primaryColor;
     theme.PrimaryDark  = primaryColor.Darken();
 }
Exemplo n.º 14
0
        private void colorSquare_Paint(object sender, PaintEventArgs e)
        {
            var g = e.Graphics;

            Rectangle r = colorSquare.ClientRectangle;
            float     p = r.Height / 6.0f / r.Height;

            _mainBrush = new PathGradientBrush(new PointF[] {
                new PointF(r.Width, 0),
                new PointF(r.Width, r.Height),
                new PointF(0, r.Height),
                new PointF(0, 0),
                new PointF(r.Width, 0)
            });

            _boxColors[0]             = _boxColors[4] = new HSVPixel(_hsv.H, 100, 100).ToRGBA();
            _mainBrush.SurroundColors = _boxColors;
            _mainBrush.CenterColor    = new HSVPixel(_hsv.H, 50, 50).ToRGBA();
            _mainBrush.CenterPoint    = new PointF(r.Width / 2, r.Height / 2);

            if (!huePanel.Enabled)
            {
                for (int i = 0; i < _mainBrush.SurroundColors.Length; i++)
                {
                    _mainBrush.SurroundColors[i] = _mainBrush.SurroundColors[i].Darken(190);
                }
            }

            g.FillRectangle(_mainBrush, r);


            //Draw indicator
            int x = (int)(_hsv.V / 100.0f * colorSquare.Width);
            int y = (int)((100 - _hsv.S) / 100.0f * colorSquare.Height);

            Rectangle c = new Rectangle(x - 3, y - 3, 6, 6);

            Color pixel = _color.Inverse();

            pixel.WhiteAlpha();

            using (Pen pen = new Pen(pixel))
                g.DrawEllipse(pen, c);

            c.X      -= 1;
            c.Y      -= 1;
            c.Width  += 2;
            c.Height += 2;

            pixel = pixel.Lighten(64);

            using (Pen pen = new Pen(pixel))
                g.DrawEllipse(pen, c);
        }
        public static IExtendedTheme GetExtendedTheme(this ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary == null)
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }

            if (resourceDictionary[CurrentThemeKey] is IExtendedTheme theme)
            {
                return(theme);
            }

            Color secondaryMid           = GetColor(resourceDictionary, "SecondaryHueMidBrush", "SecondaryHueMidBrush");
            Color secondaryMidForeground = GetColor(resourceDictionary, "SecondaryHueMidForegroundBrush", "SecondaryHueMidForegroundBrush");

            if (!TryGetColor(resourceDictionary, "SecondaryHueLightBrush", out Color secondaryLight))
            {
                secondaryLight = secondaryMid.Lighten();
            }

            if (!TryGetColor(resourceDictionary, "SecondaryHueLightForegroundBrush", out Color secondaryLightForeground))
            {
                secondaryLightForeground = secondaryLight.ContrastingForegroundColor();
            }

            if (!TryGetColor(resourceDictionary, "SecondaryHueDarkBrush", out Color secondaryDark))
            {
                secondaryDark = secondaryMid.Darken();
            }

            if (!TryGetColor(resourceDictionary, "SecondaryHueDarkForegroundBrush", out Color secondaryDarkForeground))
            {
                secondaryDarkForeground = secondaryDark.ContrastingForegroundColor();
            }

            ExtendedTheme newTheme = new ExtendedTheme
            {
                PrimaryLight = new ColorPair(GetColor(resourceDictionary, "PrimaryHueLightBrush"), GetColor(resourceDictionary, "PrimaryHueLightForegroundBrush")),
                PrimaryMid   = new ColorPair(GetColor(resourceDictionary, "PrimaryHueMidBrush"), GetColor(resourceDictionary, "PrimaryHueMidForegroundBrush")),
                PrimaryDark  = new ColorPair(GetColor(resourceDictionary, "PrimaryHueDarkBrush"), GetColor(resourceDictionary, "PrimaryHueDarkForegroundBrush")),

                SecondaryLight = new ColorPair(secondaryLight, secondaryLightForeground),
                SecondaryMid   = new ColorPair(secondaryMid, secondaryMidForeground),
                SecondaryDark  = new ColorPair(secondaryDark, secondaryDarkForeground),

                ValidationError = GetColor(resourceDictionary, "ValidationErrorBrush")
            };

            GetColorProperties(newTheme.GetType(), false, true)
            .ForEach(property => property.SetValue(newTheme, GetColor(resourceDictionary, GetKey(property))));

            return(newTheme);
        }
Exemplo n.º 16
0
 private RadialMenuButton CreateColorRadialMenuButton(Color sourceColor)
 {
     return(new RadialMenuButton
     {
         InnerNormalColor = sourceColor,
         InnerHoverColor = sourceColor.Lighten(),
         InnerReleasedColor = sourceColor,
         InnerTappedColor = sourceColor,
         OuterNormalColor = _buttonColors["OuterNormalColor"],
         OuterHoverColor = _buttonColors["OuterHoverColor"],
         OuterDisabledColor = _buttonColors["OuterDisabledColor"]
     });
 }
Exemplo n.º 17
0
 public static ColorStrategy Get(Theme theme, Style style,
                                 Color background, Color foreground)
 {
     var fgHsl = (theme == Theme.LightBgDarkFg)
                     ? foreground.Darken()
                     : foreground.Lighten();
     if (background.A != 255) /* Not interfering with any transparent color */
         return set[style](background, fgHsl, theme);
     var bgHsl = (theme == Theme.LightBgDarkFg)
                     ? background.Lighten()
                     : background.Darken();
     return set[style]((Color) bgHsl, fgHsl, theme);
 }
Exemplo n.º 18
0
            public static void SetPaintFromSurface(IMyTextSurface surface, double secondaryColorShade = 0.2f)
            {
                paint.Font            = surface.Font;
                paint.PrimaryColor    = surface.ScriptForegroundColor;
                paint.BackgroundColor = surface.ScriptBackgroundColor;
                Vector3 hsv = surface.ScriptForegroundColor.ColorToHSV();

                paint.SecondaryColor  = (hsv.Z < 0.5f) ? Color.Lighten(paint.PrimaryColor, secondaryColorShade) : Color.Darken(paint.PrimaryColor, secondaryColorShade);
                paint.Offset          = new Vector2(0, (surface.TextureSize.Y - surface.SurfaceSize.Y) / 2.0f);
                paint.AvailableWidth  = surface.SurfaceSize.X;
                paint.AvailableHeight = surface.SurfaceSize.Y;
                paint.Center          = surface.SurfaceSize / 2.0f;
            }
Exemplo n.º 19
0
        private RadialMenuButton CreateColorRadialMenuButtonWithSubMenu(Color sourceColor, double subMenuButtonCount)
        {
            var colorButton = CreateColorRadialMenuButton(sourceColor);

            colorButton.Submenu = new RadialMenu();

            for (var i = 0; i < subMenuButtonCount; i++)
            {
                var lightenFactor = (float)i / 10;
                colorButton.Submenu.AddButton(CreateColorRadialMenuButton(sourceColor.Lighten(lightenFactor)));
            }

            return(colorButton);
        }
Exemplo n.º 20
0
 protected override void RenderBase(Graphics graphics, LevelOfDetail lod)
 {
     if (lod == LevelOfDetail.High)
     {
         RenderIcon(graphics);
         RenderText(graphics);
     }
     else if (lod == LevelOfDetail.Medium)
     {
         var brush = new SolidBrush(FontColor.Lighten());
         graphics.FillRectangle(brush, Bounds.Shrink(PaddingH, PaddingV));
         brush.Dispose();
     }
 }
Exemplo n.º 21
0
        private void DrawHeader(Bitmap headerBitmap, Color headerBorderColor, Color headerBackgroundColor, Rectangle headerRectangle)
        {
            Graphics innerGraphics = Graphics.FromImage(headerBitmap);

            if (HeaderFlatStyle)
            {
                innerGraphics.FillPath(new SolidBrush(headerBackgroundColor), ExtendedForms.RoundedRect(headerRectangle, BorderRadius));
            }
            else
            {
                LinearGradientBrush brush = new LinearGradientBrush(headerRectangle, headerBackgroundColor.Lighten(HeaderGradientLightenValue), headerBackgroundColor, LinearGradientMode.Vertical);
                innerGraphics.FillPath(brush, ExtendedForms.RoundedRect(headerRectangle, BorderRadius));
            }
            innerGraphics.DrawPath(new Pen(headerBorderColor, BorderThickness), ExtendedForms.RoundedRect(headerRectangle, BorderRadius));

            DrawString(innerGraphics, headerRectangle);

            if (ShowBottomBorder)
            {
                innerGraphics.DrawLine(
                    new Pen(headerBackgroundColor.Lighten(30)),
                    headerRectangle.X,
                    headerRectangle.Y + 1,
                    headerRectangle.Right,
                    headerRectangle.Y + 1);
                innerGraphics.DrawLine(
                    new Pen(headerBackgroundColor.Darken(30)),
                    headerRectangle.X,
                    headerRectangle.Bottom - 1,
                    headerRectangle.Right,
                    headerRectangle.Bottom - 1);
            }

            Graphics g = Graphics.FromHwnd(this.Handle);

            g.DrawImage(headerBitmap, headerRectangle.Location);
        }
Exemplo n.º 22
0
 private void SetSecondaryForegroundToSingleColor(Color color, string swatch)
 {
     try
     {
         ITheme theme = GetTheme();
         theme.PrimaryLight = new ColorPair(color.Lighten(), theme.PrimaryLight.ForegroundColor);
         theme.PrimaryMid   = new ColorPair(color, theme.PrimaryMid.ForegroundColor);
         theme.PrimaryDark  = new ColorPair(color.Darken(), theme.PrimaryDark.ForegroundColor);
         theme.TextFieldBoxHoverBackground = Color.FromRgb(247, 68, 1);
         SetTheme(theme, swatch);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 23
0
        public void Draw(Matrix4 mvp)
        {
            GL.Disable(EnableCap.DepthTest);
            for (int i = 0; i < PathGroups.Count; i++)
            {
                foreach (var path in PathGroups[i].PathPoints)
                {
                    var translate = new Vector3(path.Translate.X, path.Translate.Z, path.Translate.Y);

                    if (path.IsSelected)
                    {
                        Render2D.DrawFilledCircle(translate, Color.LightGreen, 30, 40, true);
                    }
                    else if (path.IsHovered)
                    {
                        Render2D.DrawFilledCircle(translate, LineColor.Lighten(40), 40, 40, true);
                    }
                    else
                    {
                        Render2D.DrawFilledCircle(translate, LineColor.Darken(20), 30, 40, true);
                    }

                    GL.LineWidth(2f);
                    foreach (var nextPt in path.NextPoints)
                    {
                        var nextTranslate = PathGroups[nextPt.PathID].PathPoints[nextPt.PtID].Translate;

                        GL.Color3(LineColor);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(translate);
                        GL.Vertex3(nextTranslate.X, nextTranslate.Z, nextTranslate.Y);
                        GL.End();
                    }
                    foreach (var prevPt in path.PrevPoints)
                    {
                        var prevTranslate = PathGroups[prevPt.PathID].PathPoints[prevPt.PtID].Translate;

                        GL.Color3(LineColor);
                        GL.Begin(PrimitiveType.Lines);
                        GL.Vertex3(translate);
                        GL.Vertex3(prevTranslate.X, prevTranslate.Z, prevTranslate.Y);
                        GL.End();
                    }
                }
            }
            GL.Enable(EnableCap.DepthTest);
        }
Exemplo n.º 24
0
            public static void SetCurrentSurfaceAndFrame(IMyTextSurface surface, MySpriteDrawFrame frame)
            {
                _surface = surface;
                _frame   = frame;
                _offset  = (_surface.TextureSize - _surface.SurfaceSize) / 2.0f;

                Width         = _surface.SurfaceSize.X;
                Height        = _surface.SurfaceSize.Y;
                Center        = new Vector2(Width, Height) / 2.0f + _offset;
                AvailableSize = new Vector2(Width, Height);

                Vector3 hsv = surface.ScriptForegroundColor.ColorToHSV();

                PrimaryColor    = _surface.ScriptForegroundColor;
                BackgroundColor = _surface.ScriptBackgroundColor;
                SecondaryColor  = (hsv.Z < 0.5f) ? Color.Lighten(PrimaryColor, 0.3f) : Color.Darken(PrimaryColor, 0.3f);
            }
Exemplo n.º 25
0
        public void RefreshStyles(Color?color = null)
        {
            DebugWrite($"Color: {color}");

            if (color != null)
            {
                // since every brush will be based on one color,
                // we will do so with theme in mind.

                switch (RequestedTheme)
                {
                case ElementTheme.Default:
                case ElementTheme.Light:
                {
                    HamburgerBackground        = color?.ToSolidColorBrush();
                    HamburgerForeground        = Colors.White.ToSolidColorBrush();
                    NavAreaBackground          = Colors.DimGray.ToSolidColorBrush();
                    NavButtonBackground        = Colors.Transparent.ToSolidColorBrush();
                    NavButtonForeground        = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedBackground = color?.Lighten(ColorUtils.Accents.Plus20).ToSolidColorBrush();
                    NavButtonPressedBackground = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonHoverBackground   = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus60).ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    SecondarySeparator         = PaneBorderBrush = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                }
                break;

                case ElementTheme.Dark:
                {
                    HamburgerBackground        = color?.ToSolidColorBrush();
                    HamburgerForeground        = Colors.White.ToSolidColorBrush();
                    NavAreaBackground          = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus80).ToSolidColorBrush();
                    NavButtonBackground        = Colors.Transparent.ToSolidColorBrush();
                    NavButtonForeground        = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedBackground = color?.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonPressedBackground = Colors.Gainsboro.Lighten(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonHoverBackground   = Colors.Gainsboro.Lighten(ColorUtils.Accents.Plus60).ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    SecondarySeparator         = PaneBorderBrush = Colors.Gainsboro.ToSolidColorBrush();
                }
                break;
                }
            }
        }
Exemplo n.º 26
0
        public static ColorStrategy Get(Theme theme, Style style,
                                        Color background, Color foreground)
        {
            var fgHsl = (theme == Theme.LightBgDarkFg)
                            ? foreground.Darken()
                            : foreground.Lighten();

            if (background.A != 255) /* Not interfering with any transparent color */
            {
                return(set[style](background, fgHsl, theme));
            }
            var bgHsl = (theme == Theme.LightBgDarkFg)
                            ? background.Lighten()
                            : background.Darken();

            return(set[style]((Color)bgHsl, fgHsl, theme));
        }
Exemplo n.º 27
0
        public static Image ChangeColor(Image image, double change)
        {
            if (image == null)
            {
                return(null);
            }
            Bitmap originalBitmap    = new Bitmap(image);
            Bitmap transparentBitmap = new Bitmap(image.Width, image.Height);

            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    Color oldColor = originalBitmap.GetPixel(x, y);
                    Color newColor = change > 0 ? oldColor.Lighten(change) : oldColor.Darken(-change);
                    transparentBitmap.SetPixel(x, y, newColor);
                }
            }
            return(transparentBitmap);
        }
Exemplo n.º 28
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics  g = e.Graphics;
            Color     toolStripButtonHoverColor         = ToolStripButtonHoverColor.SetAlpha(ToolStripButtonBackgroundAlpha);
            Color     toolStripButtonBorderHoverColor   = ToolStripButtonBorderHoverColor.SetAlpha(ToolStripButtonBorderAlpha);
            Color     toolStripButtonPressedColor       = ToolStripButtonPressedColor.SetAlpha(ToolStripButtonBackgroundAlpha);
            Color     toolStripButtonBorderPressedColor = ToolStripButtonBorderPressedColor.SetAlpha(ToolStripButtonBorderAlpha);
            Rectangle rect = new Rectangle(1, 1, e.Item.Bounds.Width - 2, e.Item.Bounds.Height - 3);

            if (!ToolStripDrawBorder)
            {
                rect = new Rectangle(0, 1, e.Item.Bounds.Width - 1, e.Item.Bounds.Height - 3);
            }

            if (e.Item.Selected)
            {
                using (Brush brush = new SolidBrush(toolStripButtonHoverColor)) {
                    g.FillRectangle(brush, rect);
                }
                g.DrawRectangle(new Pen(toolStripButtonBorderHoverColor), rect);

                Rectangle innerRect = rect;
                innerRect.Inflate(-1, -1);

                g.DrawRectangle(new Pen(toolStripButtonHoverColor.Lighten(100)), innerRect);
            }

            if (e.Item.Pressed)
            {
                using (Brush brush = new SolidBrush(toolStripButtonPressedColor)) {
                    g.FillRectangle(brush, rect);
                }
                g.DrawRectangle(new Pen(toolStripButtonBorderPressedColor), rect);

                Rectangle innerRect = rect;
                innerRect.Inflate(-1, -1);

                g.DrawRectangle(new Pen(toolStripButtonPressedColor.Lighten(100)), innerRect);
            }
        }
Exemplo n.º 29
0
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            Graphics g = e.Graphics;
            Color    toolStripTopGradienColor    = ToolStripTopGradienColor.SetAlpha(ToolStripBackgroundAlpha);
            Color    toolStripBottomGradienColor = ToolStripBottomGradienColor.SetAlpha(ToolStripBackgroundAlpha);

            using (Brush brush = new LinearGradientBrush(e.AffectedBounds, toolStripTopGradienColor, toolStripBottomGradienColor, ToolStripGradientAngle)) {
                g.FillRectangle(brush, e.AffectedBounds);

                if (ToolStripDrawBorder)
                {
                    if (ToolStripDrawTopShadow)
                    {
                        int borderOffset = 1;
                        if (!ToolStripDrawTopBorderPart)
                        {
                            borderOffset = 0;
                        }

                        g.DrawLine(
                            new Pen(toolStripTopGradienColor.Lighten(25)),
                            e.AffectedBounds.X + 1,
                            e.AffectedBounds.Top + borderOffset,
                            e.AffectedBounds.Right - 1,
                            e.AffectedBounds.Top + borderOffset);
                    }

                    if (ToolStripDrawBottomShadow)
                    {
                        g.DrawLine(
                            new Pen(toolStripBottomGradienColor.Darken(20)),
                            e.AffectedBounds.X + 1,
                            e.AffectedBounds.Bottom - 2,
                            e.AffectedBounds.Right - 1,
                            e.AffectedBounds.Bottom - 2);
                    }
                }
            }
        }
        public static ITheme GetTheme(this ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary == null)
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }
            if (resourceDictionary[CurrentThemeKey] is ITheme theme)
            {
                return(theme);
            }

            Color secondaryMid           = GetColor("SecondaryHueMidBrush", "SecondaryAccentBrush");
            Color secondaryMidForeground = GetColor("SecondaryHueMidForegroundBrush", "SecondaryAccentForegroundBrush");

            if (!TryGetColor("SecondaryHueLightBrush", out Color secondaryLight))
            {
                secondaryLight = secondaryMid.Lighten();
            }
            if (!TryGetColor("SecondaryHueLightForegroundBrush", out Color secondaryLightForeground))
            {
                secondaryLightForeground = secondaryLight.ContrastingForegroundColor();
            }

            if (!TryGetColor("SecondaryHueDarkBrush", out Color secondaryDark))
            {
                secondaryDark = secondaryMid.Darken();
            }
            if (!TryGetColor("SecondaryHueDarkForegroundBrush", out Color secondaryDarkForeground))
            {
                secondaryDarkForeground = secondaryDark.ContrastingForegroundColor();
            }

            //Attempt to simply look up the appropriate resources
            return(new Theme
            {
                PrimaryLight = new ColorPair(GetColor("PrimaryHueLightBrush"), GetColor("PrimaryHueLightForegroundBrush")),
                PrimaryMid = new ColorPair(GetColor("PrimaryHueMidBrush"), GetColor("PrimaryHueMidForegroundBrush")),
                PrimaryDark = new ColorPair(GetColor("PrimaryHueDarkBrush"), GetColor("PrimaryHueDarkForegroundBrush")),

                SecondaryLight = new ColorPair(secondaryLight, secondaryLightForeground),
                SecondaryMid = new ColorPair(secondaryMid, secondaryMidForeground),
                SecondaryDark = new ColorPair(secondaryDark, secondaryDarkForeground),

                ValidationError = GetColor("ValidationErrorBrush"),
                Background = GetColor("MaterialDesignBackground"),
                Paper = GetColor("MaterialDesignPaper"),
                CardBackground = GetColor("MaterialDesignCardBackground"),
                ToolBarBackground = GetColor("MaterialDesignToolBarBackground"),
                Body = GetColor("MaterialDesignBody"),
                BodyLight = GetColor("MaterialDesignBodyLight"),
                ColumnHeader = GetColor("MaterialDesignColumnHeader"),
                CheckBoxOff = GetColor("MaterialDesignCheckBoxOff"),
                CheckBoxDisabled = GetColor("MaterialDesignCheckBoxDisabled"),
                TextBoxBorder = GetColor("MaterialDesignTextBoxBorder"),
                Divider = GetColor("MaterialDesignDivider"),
                Selection = GetColor("MaterialDesignSelection"),
                FlatButtonClick = GetColor("MaterialDesignFlatButtonClick"),
                FlatButtonRipple = GetColor("MaterialDesignFlatButtonRipple"),
                ToolTipBackground = GetColor("MaterialDesignToolTipBackground"),
                ChipBackground = GetColor("MaterialDesignChipBackground"),
                SnackbarBackground = GetColor("MaterialDesignSnackbarBackground"),
                SnackbarMouseOver = GetColor("MaterialDesignSnackbarMouseOver"),
                SnackbarRipple = GetColor("MaterialDesignSnackbarRipple"),
                TextFieldBoxBackground = GetColor("MaterialDesignTextFieldBoxBackground"),
                TextFieldBoxHoverBackground = GetColor("MaterialDesignTextFieldBoxHoverBackground"),
                TextFieldBoxDisabledBackground = GetColor("MaterialDesignTextFieldBoxDisabledBackground"),
                TextAreaBorder = GetColor("MaterialDesignTextAreaBorder"),
                TextAreaInactiveBorder = GetColor("MaterialDesignTextAreaInactiveBorder")
            });

            Color GetColor(params string[] keys)
            {
                foreach (string key in keys)
                {
                    if (TryGetColor(key, out Color color))
                    {
                        return(color);
                    }
                }
                throw new InvalidOperationException($"Could not locate required resource with key(s) '{string.Join(", ", keys)}'");
            }

            bool TryGetColor(string key, out Color color)
            {
                if (resourceDictionary[key] is SolidColorBrush brush)
                {
                    color = brush.Color;
                    return(true);
                }
                color = default;
                return(false);
            }
        }
Exemplo n.º 31
0
 public static ColorStrategy Get(Theme TheTheme, Style TheStyle,
                                 Color Background, Color Foreground)
 {
     var FgHsl = (TheTheme == Theme.LightBgDarkFg)
                     ? Foreground.Darken()
                     : Foreground.Lighten();
     if (Background.A != 255) /* Not interfering with any transparent color */
         return _Set[TheStyle](Background, FgHsl, TheTheme);
     var BgHsl = (TheTheme == Theme.LightBgDarkFg)
                     ? Background.Lighten()
                     : Background.Darken();
     return _Set[TheStyle]((Color) BgHsl, FgHsl, TheTheme);
 }
Exemplo n.º 32
0
        public void RefreshStyles(Color?color = null)
        {
            if (color == null)
            {
                // manually setting the brushes is a way of ignoring the themes
                // in this block we will unset, then re-set the values

                var hamburgerBackground        = HamburgerBackground;
                var hamburgerForeground        = HamburgerForeground;
                var navAreaBackground          = NavAreaBackground;
                var navButtonBackground        = NavButtonBackground;
                var navButtonForeground        = NavButtonForeground;
                var navButtonCheckedBackground = NavButtonCheckedBackground;
                var navButtonPressedBackground = NavButtonPressedBackground;
                var navButtonHoverBackground   = NavButtonHoverBackground;
                var navButtonCheckedForeground = NavButtonCheckedForeground;
                var secondarySeparator         = SecondarySeparator;
                var paneBorderBush             = PaneBorderBrush;

                HamburgerBackground        = null;
                HamburgerForeground        = null;
                NavAreaBackground          = null;
                NavButtonBackground        = null;
                NavButtonForeground        = null;
                NavButtonCheckedBackground = null;
                NavButtonPressedBackground = null;
                NavButtonHoverBackground   = null;
                NavButtonCheckedForeground = null;
                SecondarySeparator         = null;
                PaneBorderBrush            = null;

                HamburgerBackground        = hamburgerBackground;
                HamburgerForeground        = hamburgerForeground;
                NavAreaBackground          = navAreaBackground;
                NavButtonBackground        = navButtonBackground;
                NavButtonForeground        = navButtonForeground;
                NavButtonCheckedBackground = navButtonCheckedBackground;
                NavButtonPressedBackground = navButtonPressedBackground;
                NavButtonHoverBackground   = navButtonHoverBackground;
                NavButtonCheckedForeground = navButtonCheckedForeground;
                SecondarySeparator         = secondarySeparator;
                PaneBorderBrush            = PaneBorderBrush;
            }
            else
            {
                // since every brush will be based on one color,
                // we will do so with theme in mind.

                switch (RequestedTheme)
                {
                case ElementTheme.Light:
                    HamburgerBackground        = color?.ToSolidColorBrush();
                    HamburgerForeground        = Colors.White.ToSolidColorBrush();
                    NavAreaBackground          = Colors.DimGray.ToSolidColorBrush();
                    NavButtonBackground        = Colors.Transparent.ToSolidColorBrush();
                    NavButtonForeground        = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedBackground = color?.Lighten(ColorUtils.Accents.Plus20).ToSolidColorBrush();
                    NavButtonPressedBackground = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonHoverBackground   = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus60).ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    SecondarySeparator         = PaneBorderBrush = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    break;

                case ElementTheme.Default:
                case ElementTheme.Dark:
                    HamburgerBackground        = color?.ToSolidColorBrush();
                    HamburgerForeground        = Colors.White.ToSolidColorBrush();
                    NavAreaBackground          = Colors.Gainsboro.Darken(ColorUtils.Accents.Plus80).ToSolidColorBrush();
                    NavButtonBackground        = Colors.Transparent.ToSolidColorBrush();
                    NavButtonForeground        = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    NavButtonCheckedBackground = color?.Darken(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonPressedBackground = Colors.Gainsboro.Lighten(ColorUtils.Accents.Plus40).ToSolidColorBrush();
                    NavButtonHoverBackground   = Colors.Gainsboro.Lighten(ColorUtils.Accents.Plus60).ToSolidColorBrush();
                    NavButtonCheckedForeground = Colors.White.ToSolidColorBrush();
                    SecondarySeparator         = PaneBorderBrush = Colors.Gainsboro.ToSolidColorBrush();
                    break;
                }
            }
        }