Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            var g = pevent.Graphics;

            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            g.Clear(Parent.BackColor);

            //Hover
            Color c = SkinManager.GetFlatButtonHoverBackgroundColor();

            using (Brush b = new SolidBrush(/*Color.FromArgb((int)(_hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())*/ c))
                g.FillRectangle(b, ClientRectangle);

            //Ripple
            if (_animationManager.IsAnimating())
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                for (var i = 0; i < _animationManager.GetAnimationCount(); i++)
                {
                    var animationValue  = _animationManager.GetProgress(i);
                    var animationSource = _animationManager.GetSource(i);

                    using (Brush rippleBrush = new SolidBrush(Color.FromArgb((int)(101 - (animationValue * 100)), Color.Black)))
                    {
                        var rippleSize = (int)(animationValue * Width * 2);
                        g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize));
                    }
                }
                g.SmoothingMode = SmoothingMode.None;
            }

            //Icon
            var iconRect = new Rectangle(8, 6, 24, 24);

            if (string.IsNullOrEmpty(Text))
            {
                // Center Icon
                iconRect.X += 2;
            }

            if (Icon != null)
            {
                g.DrawImage(Icon, iconRect);
            }

            //Text
            var textRect = ClientRectangle;

            if (Icon != null)
            {
                //
                // Resize and move Text container
                //

                // First 8: left padding
                // 24: icon width
                // Second 4: space between Icon and Text
                // Third 8: right padding
                textRect.Width -= 8 + 24 + 4 + 8;

                // First 8: left padding
                // 24: icon width
                // Second 4: space between Icon and Text
                textRect.X += 8 + 24 + 4;
            }

            using (SolidBrush sb = new SolidBrush(SkinManager.FontColor))
                using (StringFormat sf = new StringFormat {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                })
                {
                    g.DrawString(Text.ToUpper(), SkinManager.PINGFANG_MEDIUM_10, sb, textRect, sf);
                }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            var g = pevent.Graphics;

            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            g.Clear(Parent.BackColor);

            //Hover
            Color c = SkinManager.GetFlatButtonHoverBackgroundColor();

            using (Brush b = new SolidBrush(/*Color.FromArgb((int)(_hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())*/ c))
                g.FillRectangle(b, ClientRectangle);

            //Ripple
            if (_animationManager.IsAnimating())
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                for (var i = 0; i < _animationManager.GetAnimationCount(); i++)
                {
                    var animationValue  = _animationManager.GetProgress(i);
                    var animationSource = _animationManager.GetSource(i);

                    using (Brush rippleBrush = new SolidBrush(Color.FromArgb((int)(101 - (animationValue * 100)), Color.Black)))
                    {
                        var rippleSize = (int)(animationValue * Width * 2);
                        g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize));
                    }
                }
                g.SmoothingMode = SmoothingMode.None;
            }

            //Icon
            var iconRect = new Rectangle(1, 1, 20, 20);

            if (string.IsNullOrEmpty(Text))
            {
                // Center Icon
                iconRect.X += 2;
            }

            if (Icon != null)
            {
                g.DrawImage(Icon, iconRect);
            }

            //Text
            var textRect = ClientRectangle;

            using (var formButtonsPen = new Pen(SkinManager.ACTION_BAR_TEXT_SECONDARY, 2))
            {
                switch (BtnType)
                {
                case ButtonType.Max:
                    int x = _maxButtonBounds.X;
                    int y = _maxButtonBounds.Y;
                    g.DrawRectangle(
                        formButtonsPen,
                        /*_maxButtonBounds.X + */ (int)(this.Width * 0.33),
                        /*_maxButtonBounds.Y + */ (int)(this.Height * 0.36),
                        (int)(this.Width * 0.39),
                        (int)(this.Height * 0.31)
                        );
                    break;

                case ButtonType.Close:
                    g.DrawLine(
                        formButtonsPen,
                        /*_xButtonBounds.X + */ (int)(this.Width * 0.33),
                        /*_xButtonBounds.Y + */ (int)(this.Height * 0.33),
                        /*_xButtonBounds.X + */ (int)(this.Width * 0.66),
                        /*_xButtonBounds.Y + */ (int)(this.Height * 0.66)
                        );

                    g.DrawLine(
                        formButtonsPen,
                        /*_xButtonBounds.X + */ (int)(this.Width * 0.66),
                        /*_xButtonBounds.Y + */ (int)(this.Height * 0.33),
                        /*_xButtonBounds.X + */ (int)(this.Width * 0.33),
                        /*_xButtonBounds.Y + */ (int)(this.Height * 0.66));
                    break;

                case ButtonType.Min:
                    int xMin = _minButtonBounds.X;
                    int yMin = _minButtonBounds.Y;
                    g.DrawLine(
                        formButtonsPen, 4, 11, 18, 11);
                    break;
                }
            }
            using (SolidBrush sb = new SolidBrush(SkinManager.FontColor))
                using (StringFormat sf = new StringFormat {
                    Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                })
                {
                    g.DrawString(Text.ToUpper(), SkinManager.PINGFANG_MEDIUM_10, sb, textRect, sf);
                }
        }