ARCed.UI.VS2005AutoHideStrip.DrawTab C# (CSharp) Method

DrawTab() private method

private DrawTab ( Graphics g, TabVS2005 tab ) : void
g System.Drawing.Graphics
tab TabVS2005
return void
        private void DrawTab(Graphics g, TabVS2005 tab)
        {
            Rectangle rectTabOrigin = this.GetTabRectangle(tab);
            if (rectTabOrigin.IsEmpty)
                return;

            DockState dockState = tab.Content.DockHandler.DockState;
            IDockContent content = tab.Content;

            GraphicsPath path = this.GetTabOutline(tab, false, true);

            Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor;
            Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor;
            LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode;
            g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path);
            g.DrawPath(PenTabBorder, path);

            // Set no rotate for drawing icon and text
            Matrix matrixRotate = g.Transform;
            g.Transform = MatrixIdentity;

            // Draw the icon
            Rectangle rectImage = rectTabOrigin;
            rectImage.X += ImageGapLeft;
            rectImage.Y += ImageGapTop;
            int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom;
            int imageWidth = ImageWidth;
            if (imageHeight > ImageHeight)
                imageWidth = ImageWidth * (imageHeight / ImageHeight);
            rectImage.Height = imageHeight;
            rectImage.Width = imageWidth;
            rectImage = this.GetTransformedRectangle(dockState, rectImage);

            if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
            {
                // The DockState is DockLeftAutoHide or DockRightAutoHide, so rotate the _srcTexture 90 degrees to the right.
                Rectangle rectTransform = this.RtlTransform(rectImage, dockState);
                Point[] rotationPoints =
                {
                    new Point(rectTransform.X + rectTransform.Width, rectTransform.Y),
                    new Point(rectTransform.X + rectTransform.Width, rectTransform.Y + rectTransform.Height),
                    new Point(rectTransform.X, rectTransform.Y)
                };

                using (var rotatedIcon = new Icon(((Form)content).Icon, 16, 16))
                {
                    g.DrawImage(rotatedIcon.ToBitmap(), rotationPoints);
                }
            }
            else
            {
                // Draw the icon normally without any rotation.
                g.DrawIcon(((Form)content).Icon, this.RtlTransform(rectImage, dockState));
            }

            // Draw the text
            Rectangle rectText = rectTabOrigin;
            rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
            rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
            rectText = this.RtlTransform(this.GetTransformedRectangle(dockState, rectText), dockState);

            Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor;

            if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
                g.DrawString(content.DockHandler.TabText, this.TextFont, new SolidBrush(textColor), rectText, this.StringFormatTabVertical);
            else
                g.DrawString(content.DockHandler.TabText, this.TextFont, new SolidBrush(textColor), rectText, this.StringFormatTabHorizontal);

            // Set rotate back
            g.Transform = matrixRotate;
        }