예제 #1
0
        //private static readonly Point ImageIndent = new Point(2, 2);
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroTileItem item = (MetroTileItem)renderingInfo.Control;
            if (item.Frames.Count == 0)
            {
                using (HatchBrush brush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red))
                    renderingInfo.PaintEventArgs.Graphics.FillRectangle(brush, item.Bounds);
                return;
            }
            
            Matrix currentTransform = null;
            float zoom = 0.95f;
            System.Drawing.Drawing2D.Matrix mx = null;

            if (renderingInfo.ItemPaintArgs.DragInProgress)
            {
                currentTransform = renderingInfo.PaintEventArgs.Graphics.Transform;
                
                mx = new System.Drawing.Drawing2D.Matrix(zoom, 0, 0, zoom, 0, 0);
                float offsetX = (item.WidthInternal * (1.0f / zoom) - item.WidthInternal) / 2;
                float offsetY = (item.HeightInternal * (1.0f / zoom) - item.HeightInternal) / 2;
                mx.Translate(offsetX, offsetY);
                renderingInfo.PaintEventArgs.Graphics.Transform = mx;
            }

            if (item.CurrentFrameOffset != 0 && item.LastFrame != item.CurrentFrame)
            {
                Graphics g = renderingInfo.PaintEventArgs.Graphics;
                if (currentTransform == null)
                    currentTransform = g.Transform;
                g.TranslateTransform(0, -(item.HeightInternal - item.CurrentFrameOffset - InflatePixels * 2), MatrixOrder.Append);
                // Draw last frame first then offset the current frame
                RenderFrame(renderingInfo, item.LastFrame);
                if (mx != null)
                    g.Transform = mx;
                else
                    g.Transform = currentTransform;
                g.TranslateTransform(0, item.CurrentFrameOffset, MatrixOrder.Append);

                RenderFrame(renderingInfo, item.CurrentFrame);
            }
            else
                RenderFrame(renderingInfo, item.CurrentFrame);

            if (currentTransform != null)
            {
                renderingInfo.PaintEventArgs.Graphics.Transform = currentTransform;
                currentTransform.Dispose();
            }
        }
예제 #2
0
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroStatusBar bar = (MetroStatusBar)renderingInfo.Control;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            MetroStatusBarColorTable ct = renderingInfo.ColorTable.MetroStatusBar;
            Rectangle bounds = bar.ClientRectangle;

            if (ct.BackgroundStyle != null)
            {
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
                ElementStyleDisplay.PaintBackground(di);
            }

            if (ct.TopBorders != null && ct.TopBorders.Length > 0)
            {
                for (int i = 0; i < ct.TopBorders.Length; i++)
                {
                    using (Pen pen = new Pen(ct.TopBorders[i]))
                        g.DrawLine(pen, bounds.X, bounds.Y + i, bounds.Right, bounds.Y + i);
                }
            }

            if (ct.BottomBorders != null && ct.BottomBorders.Length > 0)
            {
                for (int i = 0; i < ct.BottomBorders.Length; i++)
                {
                    using (Pen pen = new Pen(ct.BottomBorders[i]))
                        g.DrawLine(pen, bounds.X, bounds.Bottom - i - 1, bounds.Right, bounds.Bottom - i - 1);
                }
            }

            if (bar.ResizeHandleVisible)
            {
                Form form = bar.FindForm();
                if (form != null && form.WindowState == FormWindowState.Normal)
                    DevComponents.DotNetBar.Rendering.ResizeHandlePainter.DrawResizeHandle(
                        g, bounds, ct.ResizeMarkerLightColor, ct.ResizeMarkerColor, (bar.RightToLeft == RightToLeft.Yes));
            }

#if TRIAL
            Rectangle tr = bounds;
            tr.Inflate(-2, -2);
            using(Font font=new Font(bar.Font.FontFamily, 8f, FontStyle.Regular))
                TextDrawing.DrawString(g, "DotNetBar Trial", font, Color.FromArgb(80, Color.Black), tr, eTextFormat.Bottom | eTextFormat.HorizontalCenter);
#endif
        }
예제 #3
0
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroToolbar bar = (MetroToolbar)renderingInfo.Control;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            MetroToolbarColorTable ct = renderingInfo.ColorTable.MetroToolbar;
            Rectangle bounds = bar.ClientRectangle;

            if (ct.BackgroundStyle != null)
            {
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
                ElementStyleDisplay.PaintBackground(di);
            }

#if TRIAL
            if (bar.Expanded)
            {
                Rectangle tr = bounds;
                tr.Inflate(-2, -2);
                using (Font font = new Font(bar.Font.FontFamily, 8f, FontStyle.Regular))
                    TextDrawing.DrawString(g, "DotNetBar Trial", font, Color.FromArgb(32, Color.Black), tr, eTextFormat.Bottom | eTextFormat.Right);
            }
#endif

        }
예제 #4
0
        private void RenderFrame(MetroRendererInfo renderingInfo, int frameIndex)
        {
            MetroTileItem item = (MetroTileItem)renderingInfo.Control;
            MetroTileFrame frame = item.Frames[frameIndex];
            MetroTileColorTable colorTable = renderingInfo.ColorTable.MetroTile;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            Rectangle bounds = item.Bounds;
            Region clip = null;
            if (!item.DragStartPoint.IsEmpty) // When dragging tile moves with the mouse
            {
                bounds.Location = renderingInfo.ItemPaintArgs.ContainerControl.PointToClient(Control.MousePosition);
                bounds.Location.Offset(-item.DragStartPoint.X, -item.DragStartPoint.Y);
                clip = g.Clip;
                g.SetClip(bounds, CombineMode.Replace);
            }
            Control control = item.ContainerControl as Control;
            bounds.Inflate(-InflatePixels, -InflatePixels);
            if (item.IsLeftMouseButtonDown)
                bounds.Inflate(-InflatePixelsMouseDown, -InflatePixelsMouseDown);
            else if (item.IsMouseOver)
                bounds.Inflate(InflatePixels, InflatePixels);

            //if (renderingInfo.ItemPaintArgs.DragInProgress)
            //    bounds.Inflate(DragEffectInflatePixels, DragEffectInflatePixels);

            eDesignInsertPosition insertMarker = item.DesignInsertMarker;
            if (insertMarker == eDesignInsertPosition.After)
            {
                if (item.IsDesignMarkHorizontal)
                    bounds.Offset(-DragInsertOffsetPixels, 0);
                else
                    bounds.Offset(0, -DragInsertOffsetPixels);
                g.ResetClip();
            }
            else if (insertMarker == eDesignInsertPosition.Before)
            {
                if (item.IsDesignMarkHorizontal)
                    bounds.Offset(DragInsertOffsetPixels, 0);
                else
                    bounds.Offset(0, DragInsertOffsetPixels);
                g.ResetClip();
            }

            bool dispose = false;
            bool enabled = item.GetEnabled(renderingInfo.ItemPaintArgs.ContainerControl);
            ElementStyle style = ElementStyleDisplay.GetElementStyle(frame.EffectiveStyle, out dispose);

            if (bounds.Width > 2048) bounds.Width = 2048;
            if (bounds.Height > 1600) bounds.Height = 1600;

            if (enabled)
            {
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(style, g,  bounds);
                ElementStyleDisplay.Paint(di);
            }
            else
            {
                using (SolidBrush brush = new SolidBrush(item.DisabledBackColor.IsEmpty ? renderingInfo.ColorTable.MetroPartColors.CanvasColorLighterShade : item.DisabledBackColor))
                    g.FillRectangle(brush, bounds);
            }

            Rectangle textRect = bounds;
            textRect.X += style.PaddingLeft;
            textRect.Y += style.PaddingTop;
            textRect.Width -= style.PaddingHorizontal;
            textRect.Height -= style.PaddingVertical;
            if(item.IsMouseOver)
                textRect.Inflate(-InflatePixels, -InflatePixels);
            if (item.SubItems.Count > 0 && frameIndex < item.SubItems.Count)
            {
                BaseItem child = item.SubItems[frameIndex];
                if (child.Displayed)
                {
                    child.TopInternal = bounds.Y + style.PaddingTop + ((bounds.Height - style.PaddingTop - frame.TitleTextBounds.Height) - child.HeightInternal) / 2;
                    child.LeftInternal = bounds.X + style.PaddingLeft;
                    child.WidthInternal = item.TileSize.Width - style.PaddingHorizontal;
                    child.Paint(renderingInfo.ItemPaintArgs);
                }
            }

            Image image = frame.Image;
            ContentAlignment imageTextAlign = frame.ImageTextAlignment;
            Color textColor = enabled ? style.TextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
            Color symbolColor = textColor;
            if (!frame.SymbolColor.IsEmpty) symbolColor = frame.SymbolColor;
            if (image != null || !string.IsNullOrEmpty(frame.Symbol))
            {
                Font symFont = null;
                Rectangle imageRect = Rectangle.Empty;
                if (string.IsNullOrEmpty(frame.Symbol))
                    imageRect = new Rectangle(0, 0, image.Width, image.Height);
                else
                {
                    symFont = Symbols.GetFontAwesome(frame.SymbolSize);
                    Size imageSize = TextDrawing.MeasureString(g, frame.Symbol, symFont);
                    int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
                        symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
                    imageSize.Height -= descent;
                    imageRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);
                }

                imageRect.Offset(bounds.Location);

                if (imageTextAlign == ContentAlignment.TopLeft)
                {
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                }
                else if (imageTextAlign == ContentAlignment.TopCenter)
                {
                    imageRect.X += (item.TileSize.Width - imageRect.Width) / 2;
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Y += (imageRect.Height + frame.ImageIndent.Y);
                    textRect.Height -= (imageRect.Height);
                }
                else if (imageTextAlign == ContentAlignment.TopRight)
                {
                    imageRect.X += (item.TileSize.Width - imageRect.Width - frame.ImageIndent.X);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.BottomCenter)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width) / 2, item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Height -= (imageRect.Height);
                }
                else if (imageTextAlign == ContentAlignment.BottomLeft)
                {
                    imageRect.Offset(0, item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.BottomRight)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), item.TileSize.Height - imageRect.Height);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.MiddleCenter)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width) / 2, (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.Height = Math.Max(0, textRect.Bottom - imageRect.Bottom);
                    textRect.Y = imageRect.Bottom + 1;
                }
                else if (imageTextAlign == ContentAlignment.MiddleLeft)
                {
                    imageRect.Offset(0, (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);
                    textRect.X += (imageRect.Width + frame.ImageIndent.X);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else if (imageTextAlign == ContentAlignment.MiddleRight)
                {
                    imageRect.Offset((item.TileSize.Width - imageRect.Width - frame.ImageIndent.X), (item.TileSize.Height - imageRect.Height) / 2);
                    imageRect.Offset(0, frame.ImageIndent.Y);
                    textRect.Width -= (imageRect.Width + frame.ImageIndent.X);
                }
                else
                    imageRect.Offset(frame.ImageIndent.X, frame.ImageIndent.Y);

                if (string.IsNullOrEmpty(frame.Symbol))
                    g.DrawImage(image, imageRect);
                else
                    TextDrawing.DrawStringLegacy(g, frame.Symbol, symFont, symbolColor, new Rectangle(imageRect.X, imageRect.Y, 0, 0), eTextFormat.Default);
            }

            if (textRect.Width > 0 && textRect.Height > 0 && frame.Text != null)
            {
                Font font = renderingInfo.DefaultFont;
                if (style.Font != null)
                    font = style.Font;
                bool rightToLeft = renderingInfo.RightToLeft;
                if (frame.TextMarkupBody == null)
                {
                    eTextFormat textFormat = eTextFormat.Default | eTextFormat.WordBreak | eTextFormat.NoClipping;
                    if (style.TextLineAlignment == eStyleTextAlignment.Center)
                        textFormat |= eTextFormat.VerticalCenter;
                    else if (style.TextLineAlignment == eStyleTextAlignment.Far)
                        textFormat |= eTextFormat.Bottom;
                    if (style.TextAlignment == eStyleTextAlignment.Center)
                        textFormat |= eTextFormat.HorizontalCenter;
                    else if (style.TextAlignment == eStyleTextAlignment.Far)
                        textFormat |= eTextFormat.Right;
                    TextDrawing.DrawString(g, frame.Text, font, textColor, textRect, textFormat);
                }
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
                    d.HotKeyPrefixVisible = false;
                    d.ContextObject = item;
                    frame.TextMarkupBody.Bounds = textRect;
                    frame.TextMarkupBody.Render(d);
                }
            }

            if (frame.TitleText != null)
            {
                Color titleTextColor = enabled ? frame.TitleTextColor : renderingInfo.ColorTable.MetroPartColors.CanvasColorLightShade;
                if (titleTextColor.IsEmpty)
                    titleTextColor = style.TextColor;
                Font font = item.GetTitleTextFont(frame, style, control);
                Rectangle titleTextRect = frame.TitleTextBounds;
                titleTextRect.Offset(bounds.Location);
                if (item.IsMouseOver)
                    titleTextRect.Offset(InflatePixels, InflatePixels);
                TextDrawing.DrawString(g, frame.TitleText, font, titleTextColor, titleTextRect, eTextFormat.Default | eTextFormat.SingleLine);
            }

            if (item.Checked)
            {
                Rectangle markBounds = new Rectangle(bounds.Right - CheckMarkSize.Width, bounds.Y, CheckMarkSize.Width, CheckMarkSize.Height);
                using (GraphicsPath markPath = new GraphicsPath())
                {
                    markPath.AddLine(markBounds.X, markBounds.Y, markBounds.Right - 1, markBounds.Y);
                    markPath.AddLine(markBounds.Right - 1, markBounds.Y, markBounds.Right - 1, markBounds.Bottom - 1);
                    markPath.CloseFigure();
                    using (SolidBrush brush = new SolidBrush(colorTable.CheckBackground))
                        g.FillPath(brush, markPath);
                }
                using (SolidBrush brush = new SolidBrush(colorTable.CheckForeground))
                {
                    Rectangle checkCircleBounds = new Rectangle();
                    checkCircleBounds.Size = new Size(11, 11);
                    checkCircleBounds.X = markBounds.Right - checkCircleBounds.Size.Width - 3;
                    checkCircleBounds.Y = markBounds.Y + 2;
                    using (Pen pen = new Pen(colorTable.CheckForeground, 2))
                    {
                        g.DrawEllipse(pen, checkCircleBounds);
                        g.DrawLine(pen, checkCircleBounds.X + 3, checkCircleBounds.Y + 5, checkCircleBounds.X + 6, checkCircleBounds.Y + 8);
                        g.DrawLine(pen, checkCircleBounds.X + 6, checkCircleBounds.Y + 8, checkCircleBounds.X + 9, checkCircleBounds.Y + 3);
                    }
                }
            }

            if (dispose) style.Dispose();

            if (clip != null) 
            {
                g.Clip = clip;
                clip.Dispose();
            }
        }
예제 #5
0
 /// <summary>
 /// Renders the 
 /// </summary>
 /// <param name="renderingInfo"></param>
 public abstract void Render(MetroRendererInfo renderingInfo);
예제 #6
0
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroTabItem tab = (MetroTabItem)renderingInfo.Control;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            MetroTabItemColorTable cti = renderingInfo.ColorTable.MetroTab.MetroTabItem;
            MetroTabItemStateColorTable color = cti.Default;
            if (!tab.Enabled)
                color = cti.Disabled;
            else if (tab.Checked)
                color = cti.Selected;
            else if (tab.IsMouseDown && cti.Pressed != null)
                color = cti.Pressed;
            else if (tab.IsMouseOver && cti.MouseOver != null)
                color = cti.MouseOver;

            Rectangle bounds = tab.Bounds;
            Rectangle textBounds = tab.TextRenderBounds;
            Rectangle imageBounds = tab.ImageRenderBounds;
            CompositeImage image = tab.GetImage();

            if (color.Background != null)
            {
                Font font = renderingInfo.DefaultFont;
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(color.Background, g, bounds);
                ElementStyleDisplay.Paint(di);

                if (image != null && tab.ButtonStyle != eButtonStyle.TextOnlyAlways)
                {
                    if (imageBounds.IsEmpty)
                        imageBounds = GetImageRectangle(tab, image);
                    if (textBounds.IsEmpty)
                        textBounds = GetTextRectangle(tab, image, imageBounds);

                }
                else if (textBounds.IsEmpty)
                    textBounds = bounds;

                if (tab.TextMarkupBody == null)
                {
                    di.Bounds = textBounds;
                    
                    ElementStyleDisplay.PaintText(di, tab.Text, font);
                }
                else
                {
                    eTextFormat stringFormat = eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter;
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, color.Background.TextColor, renderingInfo.RightToLeft);
                    d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
                    d.ContextObject = tab;
                    Rectangle mr = new Rectangle(textBounds.X, textBounds.Y + (textBounds.Height - tab.TextMarkupBody.Bounds.Height) / 2 + 1, tab.TextMarkupBody.Bounds.Width, tab.TextMarkupBody.Bounds.Height);
                    if ((stringFormat & eTextFormat.HorizontalCenter) != 0)
                        mr.Offset((textBounds.Width - mr.Width) / 2, 0);
                    if (tab._FixedSizeCenterText) mr.Y--;
                    tab.TextMarkupBody.Bounds = mr;
                    tab.TextMarkupBody.Render(d);
                }
                tab.TextRenderBounds = textBounds;
                tab.ImageRenderBounds = imageBounds;
            }

            if (image != null)
            {
                if (!tab.IsMouseOver && tab.HotTrackingStyle == eHotTrackingStyle.Color)
                {
                    // Draw gray-scale image for this hover style...
                    float[][] array = new float[5][];
                    array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
                    array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
                    array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
                    array[3] = new float[5] { 0, 0, 0, 1, 0 };
                    array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
                    ColorMatrix grayMatrix = new ColorMatrix(array);
                    ImageAttributes att = new ImageAttributes();
                    att.SetColorMatrix(grayMatrix);
                    image.DrawImage(g, imageBounds, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, att);
                }
                else
                {
                    image.DrawImage(g, imageBounds);
                }
            }

            //g.FillRectangle(Brushes.Red, bounds);
        }
예제 #7
0
        private void SetQatAndCaptionItemBounds(MetroTabStrip strip,MetroRendererInfo renderingInfo)
        {
            if (!strip.CaptionVisible)
                return;
            bool rightToLeft = (strip.RightToLeft == System.Windows.Forms.RightToLeft.Yes);
            
            System.Windows.Forms.Form form = strip.FindForm();
            bool isMaximized = false;
            if (form != null) isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;

            // Get right most X position of the Quick Access Toolbar
            int right = 0, sysLeft = 0;
            Size qatSize = Size.Empty;
            for (int i = strip.QuickToolbarItems.Count - 1; i >= 0; i--)
            {
                BaseItem item = strip.QuickToolbarItems[i];
                if (!item.Visible || !item.Displayed)
                    continue;
                if (item is QatCustomizeItem) qatSize = item.DisplayRectangle.Size;
                if (item.ItemAlignment == eItemAlignment.Near && item.Visible && i > 0)
                {
                    if (rightToLeft)
                        right = item.DisplayRectangle.X;
                    else
                        right = item.DisplayRectangle.Right;
                    break;
                }
                else if (item.ItemAlignment == eItemAlignment.Far && item.Visible)
                {
                    if (rightToLeft)
                        sysLeft = item.DisplayRectangle.Right;
                    else
                        sysLeft = item.DisplayRectangle.X;
                }
            }
            
            if (strip.CaptionContainerItem is CaptionItemContainer && ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems != null)
            {
                if (rightToLeft)
                    right = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.X;
                else
                    right = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.Right;
                qatSize = ((CaptionItemContainer)strip.CaptionContainerItem).MoreItems.DisplayRectangle.Size;
            }

            Rectangle r = new Rectangle(right, 2, strip.CaptionContainerItem.WidthInternal - right - (strip.CaptionContainerItem.WidthInternal-sysLeft), strip.GetTotalCaptionHeight());
            strip.CaptionBounds = r;

            if (sysLeft > 0)
            {
                if (rightToLeft)
                    strip.SystemCaptionItemBounds = new Rectangle(r.X, r.Y, sysLeft, r.Height);
                else
                    strip.SystemCaptionItemBounds = new Rectangle(sysLeft, r.Y, strip.CaptionContainerItem.WidthInternal - sysLeft, r.Height);
            }

            if (right == 0 || r.Height <= 0 || r.Width <= 0)
                return;

            BaseItem startButton = strip.GetApplicationButton();
            if (startButton != null)
            {
                int startIndex = strip.QuickToolbarItems.IndexOf(startButton);
                if (strip.QuickToolbarItems.Count - 1 > startIndex)
                {
                    BaseItem firstItem = strip.QuickToolbarItems[startIndex + 1];
                    if (rightToLeft)
                    {
                        r.Width -= r.Right - firstItem.DisplayRectangle.Right;
                    }
                    else
                    {
                        r.Width -= firstItem.DisplayRectangle.X - r.X;
                        r.X = firstItem.DisplayRectangle.X;
                    }
                }
            }

            r.Height = ((CaptionItemContainer)strip.CaptionContainerItem).MaxItemHeight + 6;
            r.X = 0;
            r.Width = right;
            strip.QuickToolbarBounds = r;
        }
예제 #8
0
        public override void Render(MetroRendererInfo renderingInfo)
        {
            MetroTabStrip strip = (MetroTabStrip)renderingInfo.Control;
            Graphics g = renderingInfo.PaintEventArgs.Graphics;
            MetroTabStripColorTable ct = renderingInfo.ColorTable.MetroTab.TabStrip;
            Rectangle bounds = strip.ClientRectangle;

            if (ct.BackgroundStyle != null)
            {
                ElementStyleDisplayInfo di = new ElementStyleDisplayInfo(ct.BackgroundStyle, g, bounds);
                ElementStyleDisplay.PaintBackground(di);
            }

            if (strip.CaptionVisible)
            {
                if (strip.CaptionBounds.IsEmpty || strip.SystemCaptionItemBounds.IsEmpty || strip.QuickToolbarBounds.IsEmpty)
                    SetQatAndCaptionItemBounds(strip, renderingInfo);
                Color captionTextColor = renderingInfo.ColorTable.MetroTab.ActiveCaptionText;
                eTextFormat textFormat = renderingInfo.ColorTable.MetroTab.CaptionTextFormat;
                System.Windows.Forms.Form form = strip.FindForm();
                bool isFormActive = true;
                if (form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
                    form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
                {
                    captionTextColor = renderingInfo.ColorTable.MetroTab.InactiveCaptionText;
                    isFormActive = false;
                }

                Font font = SystemFonts.DefaultFont; // System.Windows.Forms.SystemInformation.MenuFont;
                bool disposeFont = true;
                if (strip.CaptionFont != null)
                {
                    font.Dispose();
                    font = strip.CaptionFont;
                    disposeFont = false;
                }
                string text = strip.TitleText;
                if (string.IsNullOrEmpty(text) && form != null) text = form.Text;
                bool isTitleTextMarkup = strip.TitleTextMarkupBody != null;
                Rectangle captionRect = strip.CaptionBounds;
                const int CAPTION_TEXT_PADDING = 12;
                captionRect.X += CAPTION_TEXT_PADDING;
                captionRect.Width -= CAPTION_TEXT_PADDING;

                if (!isTitleTextMarkup)
                    TextDrawing.DrawString(g, text, font, captionTextColor, captionRect, textFormat);
                else
                {
                    TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, captionTextColor, strip.RightToLeft == System.Windows.Forms.RightToLeft.Yes, captionRect, false);
                    d.AllowMultiLine = false;
                    d.IgnoreFormattingColors = !isFormActive;
                    TextMarkup.BodyElement body = strip.TitleTextMarkupBody;
                    if (strip.TitleTextMarkupLastArrangeBounds != captionRect)
                    {
                        body.Measure(captionRect.Size, d);
                        body.Arrange(captionRect, d);
                        strip.TitleTextMarkupLastArrangeBounds = captionRect;
                        Rectangle mr = body.Bounds;
                        if (mr.Width < captionRect.Width)
                            mr.Offset((captionRect.Width - mr.Width) / 2, 0);
                        if (mr.Height < captionRect.Height)
                            mr.Offset(0, (captionRect.Height - mr.Height) / 2);
                        body.Bounds = mr;
                    }
                    Region oldClip = g.Clip;
                    g.SetClip(captionRect, CombineMode.Intersect);
                    body.Render(d);
                    g.Clip = oldClip;
                    if (oldClip != null) oldClip.Dispose();
                }

                if (disposeFont) font.Dispose();
            }

            //g.FillRectangle(Brushes.Yellow, strip.QuickToolbarBounds);
            //g.FillRectangle(Brushes.Green, strip.CaptionBounds);
            //g.FillRectangle(Brushes.Indigo, strip.SystemCaptionItemBounds);
            
        }