Beispiel #1
0
        protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
        {
            var g = e.Graphics;

            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            var itemRect = GetItemRect(e.Item);
            var textRect = new Rectangle(24, itemRect.Y, itemRect.Width - (24 + 16), itemRect.Height);

            g.DrawString(
                e.Text,
                MaterialSkinManager.ROBOTO_MEDIUM_10,
                e.Item.Enabled ? MaterialSkinManager.GetPrimaryTextBrush() : MaterialSkinManager.GetDisabledOrHintBrush(),
                textRect,
                new StringFormat {
                LineAlignment = StringAlignment.Center
            });
        }
Beispiel #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(MaterialSkinManager.GetApplicationBackgroundColor());
            e.Graphics.FillRectangle(MaterialSkinManager.GetDisabledOrHintBrush(), 0, 0, Width, Height);
            int doneProgress = (int)(Width * ((double)Value / Maximum));

            if (OnRight)
            {
                e.Graphics.FillRectangle(MaterialSkinManager.ColorScheme.PrimaryBrush, Width - doneProgress, 0, Width, Height);
            }
            else
            {
                e.Graphics.FillRectangle(MaterialSkinManager.ColorScheme.PrimaryBrush, 0, 0, doneProgress, Height);
            }
            if (animationManager.IsAnimating())
            {
                for (int i = 0; i < animationManager.GetAnimationCount(); i++)
                {
                    double animationValue     = animationManager.GetProgress(i);
                    bool   animationDirection = (bool)animationManager.GetData(i)[0];
                    int    animationData      = (int)animationManager.GetData(i)[1];
                    if (animationDirection)
                    {
                        int oldProgress = (int)(((float)(animationData - _value) / Maximum) * Width);
                        if (OnRight)
                        {
                            if (DecreaseHighlight)
                            {
                                e.Graphics.FillRectangle(MaterialSkinManager.Theme == MaterialSkinManager.Themes.DARK ? MaterialSkinManager.ColorScheme.DarkPrimaryBrush : MaterialSkinManager.ColorScheme.LightPrimaryBrush, Width - doneProgress - oldProgress, 0, oldProgress, Height);
                            }
                            e.Graphics.FillRectangle(MaterialSkinManager.ColorScheme.PrimaryBrush, (float)(Width - doneProgress - oldProgress + (oldProgress * animationValue)), 0, (float)(oldProgress - oldProgress * animationValue), Height);
                        }
                        else
                        {
                            if (DecreaseHighlight)
                            {
                                e.Graphics.FillRectangle(MaterialSkinManager.Theme == MaterialSkinManager.Themes.DARK ? MaterialSkinManager.ColorScheme.DarkPrimaryBrush : MaterialSkinManager.ColorScheme.LightPrimaryBrush, doneProgress, 0, oldProgress, Height);
                            }
                            e.Graphics.FillRectangle(MaterialSkinManager.ColorScheme.PrimaryBrush, doneProgress, 0, (float)(oldProgress - oldProgress * animationValue), Height);
                        }
                    }
                    else
                    {
                        int oldProgress = (int)(((float)(_value - animationData) / Maximum) * Width);
                        if (OnRight)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(MaterialSkinManager.GetApplicationBackgroundColor()), Width - doneProgress, 0, (float)(oldProgress - oldProgress * animationValue), Height);
                            e.Graphics.FillRectangle(MaterialSkinManager.GetDisabledOrHintBrush(), Width - doneProgress, 0, (float)(oldProgress - oldProgress * animationValue), Height);
                        }
                        else
                        {
                            e.Graphics.FillRectangle(new SolidBrush(MaterialSkinManager.GetApplicationBackgroundColor()), doneProgress - oldProgress + (float)(oldProgress * animationValue), 0, (float)(oldProgress - oldProgress * animationValue), Height);
                            e.Graphics.FillRectangle(MaterialSkinManager.GetDisabledOrHintBrush(), doneProgress - oldProgress + (float)(oldProgress * animationValue), 0, (float)(oldProgress - oldProgress * animationValue), Height);
                        }
                    }
                }
            }
            if (!DesignMode && Controls.Count > 0)
            {
                this.DrawChildShadow(e.Graphics);
            }
        }
Beispiel #3
0
        protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
        {
            var       g          = e.Graphics;
            const int ARROW_SIZE = 4;

            var arrowMiddle = new Point(e.ArrowRectangle.X + e.ArrowRectangle.Width / 2, e.ArrowRectangle.Y + e.ArrowRectangle.Height / 2);
            var arrowBrush  = e.Item.Enabled ? MaterialSkinManager.GetPrimaryTextBrush() : MaterialSkinManager.GetDisabledOrHintBrush();

            using (var arrowPath = new GraphicsPath())
            {
                arrowPath.AddLines(
                    new[] {
                    new Point(arrowMiddle.X - ARROW_SIZE, arrowMiddle.Y - ARROW_SIZE),
                    new Point(arrowMiddle.X, arrowMiddle.Y),
                    new Point(arrowMiddle.X - ARROW_SIZE, arrowMiddle.Y + ARROW_SIZE)
                });
                arrowPath.CloseFigure();

                g.FillPath(arrowBrush, arrowPath);
            }
        }
Beispiel #4
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            var g = pevent.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            var RADIOBUTTON_CENTER = boxOffset + RADIOBUTTON_SIZE_HALF;

            var animationProgress = animationManager.GetProgress();

            int   colorAlpha        = Enabled ? (int)(animationProgress * 255.0) : MaterialSkinManager.GetCheckBoxOffDisabledColor().A;
            int   backgroundAlpha   = Enabled ? (int)(MaterialSkinManager.GetCheckboxOffColor().A *(1.0 - animationProgress)) : MaterialSkinManager.GetCheckBoxOffDisabledColor().A;
            float animationSize     = (float)(animationProgress * 8f);
            float animationSizeHalf = animationSize / 2;

            animationSize = (float)(animationProgress * 9f);

            var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? MaterialSkinManager.ColorScheme.AccentColor : MaterialSkinManager.GetCheckBoxOffDisabledColor()));
            var pen   = new Pen(brush.Color);

            // draw ripple animation
            if (Ripple && rippleAnimationManager.IsAnimating())
            {
                for (int i = 0; i < rippleAnimationManager.GetAnimationCount(); i++)
                {
                    var animationValue  = rippleAnimationManager.GetProgress(i);
                    var animationSource = new Point(RADIOBUTTON_CENTER, RADIOBUTTON_CENTER);
                    var rippleBrush     = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color));
                    var rippleHeight    = (Height % 2 == 0) ? Height - 3 : Height - 2;
                    var rippleSize      = (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight;
                    using (var path = DrawHelper.CreateRoundRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2))
                    {
                        g.FillPath(rippleBrush, path);
                    }

                    rippleBrush.Dispose();
                }
            }

            // draw radiobutton circle
            Color uncheckedColor = DrawHelper.BlendColor(Parent.BackColor, Enabled ? MaterialSkinManager.GetCheckboxOffColor() : MaterialSkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha);

            using (var path = DrawHelper.CreateRoundRect(boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE, 9f))
            {
                g.FillPath(new SolidBrush(uncheckedColor), path);

                if (Enabled)
                {
                    g.FillPath(brush, path);
                }
            }

            g.FillEllipse(
                new SolidBrush(Parent.BackColor),
                RADIOBUTTON_OUTER_CIRCLE_WIDTH + boxOffset,
                RADIOBUTTON_OUTER_CIRCLE_WIDTH + boxOffset,
                RADIOBUTTON_INNER_CIRCLE_SIZE,
                RADIOBUTTON_INNER_CIRCLE_SIZE);

            if (Checked)
            {
                using (var path = DrawHelper.CreateRoundRect(RADIOBUTTON_CENTER - animationSizeHalf, RADIOBUTTON_CENTER - animationSizeHalf, animationSize, animationSize, 4f))
                {
                    g.FillPath(brush, path);
                }
            }
            SizeF stringSize = g.MeasureString(Text, MaterialSkinManager.ROBOTO_MEDIUM_10);

            g.DrawString(Text, MaterialSkinManager.ROBOTO_MEDIUM_10, Enabled ? MaterialSkinManager.GetPrimaryTextBrush() : MaterialSkinManager.GetDisabledOrHintBrush(), boxOffset + 22, Height / 2 - stringSize.Height / 2);

            brush.Dispose();
            pen.Dispose();
            if (!DesignMode && Controls.Count > 0)
            {
                this.DrawChildShadow(g);
            }
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            var g = pevent.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;


            var CHECKBOX_CENTER = boxOffset + CHECKBOX_SIZE_HALF - 1;

            double animationProgress = animationManager.GetProgress();

            int colorAlpha      = Enabled ? (int)(animationProgress * 255.0) : MaterialSkinManager.GetCheckBoxOffDisabledColor().A;
            int backgroundAlpha = Enabled ? (int)(MaterialSkinManager.GetCheckboxOffColor().A *(1.0 - animationProgress)) : MaterialSkinManager.GetCheckBoxOffDisabledColor().A;

            var brush  = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? MaterialSkinManager.ColorScheme.AccentColor : MaterialSkinManager.GetCheckBoxOffDisabledColor()));
            var brush3 = new SolidBrush(Enabled ? MaterialSkinManager.ColorScheme.AccentColor : MaterialSkinManager.GetCheckBoxOffDisabledColor());
            var pen    = new Pen(brush.Color);

            // draw ripple animation
            if (Ripple && rippleAnimationManager.IsAnimating())
            {
                for (int i = 0; i < rippleAnimationManager.GetAnimationCount(); i++)
                {
                    var animationValue  = rippleAnimationManager.GetProgress(i);
                    var animationSource = new Point(CHECKBOX_CENTER, CHECKBOX_CENTER);
                    var rippleBrush     = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color));
                    var rippleHeight    = (Height % 2 == 0) ? Height - 3 : Height - 2;
                    var rippleSize      = (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight;
                    using (var path = DrawHelper.CreateRoundRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2))
                    {
                        g.FillPath(rippleBrush, path);
                    }

                    rippleBrush.Dispose();
                }
            }

            brush3.Dispose();

            var checkMarkLineFill = new Rectangle(boxOffset, boxOffset, (int)(17.0 * animationProgress), 17);

            using (var checkmarkPath = DrawHelper.CreateRoundRect(boxOffset, boxOffset, 17, 17, 1f))
            {
                SolidBrush brush2 = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, Enabled ? MaterialSkinManager.GetCheckboxOffColor() : MaterialSkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha));
                Pen        pen2   = new Pen(brush2.Color);
                g.FillPath(brush2, checkmarkPath);
                g.DrawPath(pen2, checkmarkPath);

                g.FillRectangle(new SolidBrush(Parent.BackColor), boxOffset + 2, boxOffset + 2, CHECKBOX_INNER_BOX_SIZE - 1, CHECKBOX_INNER_BOX_SIZE - 1);
                g.DrawRectangle(new Pen(Parent.BackColor), boxOffset + 2, boxOffset + 2, CHECKBOX_INNER_BOX_SIZE - 1, CHECKBOX_INNER_BOX_SIZE - 1);

                brush2.Dispose();
                pen2.Dispose();

                if (Enabled)
                {
                    g.FillPath(brush, checkmarkPath);
                    g.DrawPath(pen, checkmarkPath);
                }
                else if (Checked)
                {
                    g.SmoothingMode = SmoothingMode.None;
                    g.FillRectangle(brush, boxOffset + 2, boxOffset + 2, CHECKBOX_INNER_BOX_SIZE, CHECKBOX_INNER_BOX_SIZE);
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                }

                g.DrawImageUnscaledAndClipped(DrawCheckMarkBitmap(), checkMarkLineFill);
            }

            // draw checkbox text
            SizeF stringSize = g.MeasureString(Text, MaterialSkinManager.ROBOTO_MEDIUM_10);

            g.DrawString(
                Text,
                MaterialSkinManager.ROBOTO_MEDIUM_10,
                Enabled ? MaterialSkinManager.GetPrimaryTextBrush() : MaterialSkinManager.GetDisabledOrHintBrush(),
                boxOffset + TEXT_OFFSET, Height / 2 - stringSize.Height / 2);

            // dispose used paint objects
            pen.Dispose();
            brush.Dispose();
            if (!DesignMode && Controls.Count > 0)
            {
                this.DrawChildShadow(g);
            }
        }