ZForge.Controls.ExplorerBar.Expando.OnPaintTitleBarBackground C# (CSharp) Method

OnPaintTitleBarBackground() protected method

Paints the title bar background
protected OnPaintTitleBarBackground ( Graphics g ) : void
g System.Drawing.Graphics The Graphics used to paint the titlebar
return void
        protected void OnPaintTitleBarBackground(Graphics g)
        {
            // fix: draw grayscale titlebar when disabled
            //      Brad Jones ([email protected])
            //      20/08/2004
            //      v1.21

            int y = 0;

            // work out where the top of the titleBar actually is
            if (this.HeaderHeight > this.TitleBarHeight)
            {
                y = this.HeaderHeight - this.TitleBarHeight;
            }

            if (this.CustomHeaderSettings.TitleGradient && !this.AnyCustomTitleGradientsEmpty)
            {
                // gradient titlebar
                Color start = this.CustomHeaderSettings.NormalGradientStartColor;
                if (this.SpecialGroup)
                {
                    start = this.CustomHeaderSettings.SpecialGradientStartColor;
                }

                Color end = this.CustomHeaderSettings.NormalGradientEndColor;
                if (this.SpecialGroup)
                {
                    end = this.CustomHeaderSettings.SpecialGradientEndColor;
                }

                if (!this.Enabled)
                {
                    // simulate saturation of 0

                    start = Color.FromArgb((int) (start.GetBrightness() * 255),
                        (int) (start.GetBrightness() * 255),
                        (int) (start.GetBrightness() * 255));
                    end = Color.FromArgb((int) (end.GetBrightness() * 255),
                        (int) (end.GetBrightness() * 255),
                        (int) (end.GetBrightness() * 255));
                }

                using (LinearGradientBrush brush = new LinearGradientBrush(this.TitleBarRectangle, start, end, LinearGradientMode.Horizontal))
                {
                    // work out where the gradient starts
                    if (this.CustomHeaderSettings.GradientOffset > 0f && this.CustomHeaderSettings.GradientOffset < 1f)
                    {
                        ColorBlend colorBlend = new ColorBlend() ;
                        colorBlend.Colors = new Color [] {brush.LinearColors[0], brush.LinearColors[0], brush.LinearColors[1]} ;
                        colorBlend.Positions = new float [] {0f, this.CustomHeaderSettings.GradientOffset, 1f} ;
                        brush.InterpolationColors = colorBlend ;
                    }

                    // check if we need round corners
                    if (this.CustomHeaderSettings.TitleRadius > 0)
                    {
                        GraphicsPath path = new GraphicsPath();

                        // top
                        path.AddLine(this.TitleBarRectangle.Left + this.CustomHeaderSettings.TitleRadius,
                            this.TitleBarRectangle.Top,
                            this.TitleBarRectangle.Right - (this.CustomHeaderSettings.TitleRadius * 2) - 1,
                            this.TitleBarRectangle.Top);

                        // right corner
                        path.AddArc(this.TitleBarRectangle.Right - (this.CustomHeaderSettings.TitleRadius * 2) - 1,
                            this.TitleBarRectangle.Top,
                            this.CustomHeaderSettings.TitleRadius * 2,
                            this.CustomHeaderSettings.TitleRadius * 2,
                            270,
                            90);

                        // right
                        path.AddLine(this.TitleBarRectangle.Right,
                            this.TitleBarRectangle.Top + this.CustomHeaderSettings.TitleRadius,
                            this.TitleBarRectangle.Right,
                            this.TitleBarRectangle.Bottom);

                        // bottom
                        path.AddLine(this.TitleBarRectangle.Right,
                            this.TitleBarRectangle.Bottom,
                            this.TitleBarRectangle.Left - 1,
                            this.TitleBarRectangle.Bottom);

                        // left corner
                        path.AddArc(this.TitleBarRectangle.Left,
                            this.TitleBarRectangle.Top,
                            this.CustomHeaderSettings.TitleRadius * 2,
                            this.CustomHeaderSettings.TitleRadius * 2,
                            180,
                            90);

                        g.SmoothingMode = SmoothingMode.AntiAlias;

                        g.FillPath(brush, path);

                        g.SmoothingMode = SmoothingMode.Default;
                    }
                    else
                    {
                        g.FillRectangle(brush, this.TitleBarRectangle);
                    }
                }
            }
            else if (this.TitleBackImage != null)
            {
                // check if the system header background images have different
                // RightToLeft values compared to what we do.  if they are different,
                // then we had better mirror them
                if ((this.RightToLeft == RightToLeft.Yes && !this.SystemSettings.Header.RightToLeft) ||
                    (this.RightToLeft == RightToLeft.No && this.SystemSettings.Header.RightToLeft))
                {
                    if (this.SystemSettings.Header.NormalBackImage != null)
                    {
                        this.SystemSettings.Header.NormalBackImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    }

                    if (this.SystemSettings.Header.SpecialBackImage != null)
                    {
                        this.SystemSettings.Header.SpecialBackImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    }

                    this.SystemSettings.Header.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
                }

                if (this.Enabled)
                {
                    if (this.SystemSettings.OfficialTheme)
                    {
                        // left edge
                        g.DrawImage(this.TitleBackImage,
                            new Rectangle(0, y, 5, this.TitleBarHeight),
                            new Rectangle(0, 0, 5, this.TitleBackImage.Height),
                            GraphicsUnit.Pixel);

                        // right edge
                        g.DrawImage(this.TitleBackImage,
                            new Rectangle(this.Width-5, y, 5, this.TitleBarHeight),
                            new Rectangle(this.TitleBackImage.Width-5, 0, 5, this.TitleBackImage.Height),
                            GraphicsUnit.Pixel);

                        // middle
                        g.DrawImage(this.TitleBackImage,
                            new Rectangle(5, y, this.Width-10, this.TitleBarHeight),
                            new Rectangle(5, 0, this.TitleBackImage.Width-10, this.TitleBackImage.Height),
                            GraphicsUnit.Pixel);
                    }
                    else
                    {
                        g.DrawImage(this.TitleBackImage, 0, y, this.Width, this.TitleBarHeight);
                    }
                }
                else
                {
                    if (this.SystemSettings.OfficialTheme)
                    {
                        using (Image image = new Bitmap(this.Width, this.TitleBarHeight))
                        {
                            using (Graphics g2 = Graphics.FromImage(image))
                            {
                                // left edge
                                g2.DrawImage(this.TitleBackImage,
                                    new Rectangle(0, y, 5, this.TitleBarHeight),
                                    new Rectangle(0, 0, 5, this.TitleBackImage.Height),
                                    GraphicsUnit.Pixel);

                                // right edge
                                g2.DrawImage(this.TitleBackImage,
                                    new Rectangle(this.Width-5, y, 5, this.TitleBarHeight),
                                    new Rectangle(this.TitleBackImage.Width-5, 0, 5, this.TitleBackImage.Height),
                                    GraphicsUnit.Pixel);

                                // middle
                                g2.DrawImage(this.TitleBackImage,
                                    new Rectangle(5, y, this.Width-10, this.TitleBarHeight),
                                    new Rectangle(5, 0, this.TitleBackImage.Width-10, this.TitleBackImage.Height),
                                    GraphicsUnit.Pixel);
                            }

                            ControlPaint.DrawImageDisabled(g, image, 0, y, this.TitleBackColor);
                        }
                    }
                    else
                    {
                        // first stretch the background image for ControlPaint.
                        using (Image image = new Bitmap(this.TitleBackImage, this.Width, this.TitleBarHeight))
                        {
                            ControlPaint.DrawImageDisabled(g, image, 0, y, this.TitleBackColor);
                        }
                    }
                }
            }
            else
            {
                // single color titlebar
                using (SolidBrush brush = new SolidBrush(this.TitleBackColor))
                {
                    g.FillRectangle(brush, 0, y, this.Width, this.TitleBarHeight);
                }
            }
        }