Exemple #1
0
            public void Paint(BidiGraphics g, Rectangle bounds)
            {
                using (g.Container(bounds.X, bounds.Y))
                {
                    g.Graphics.CompositingMode    = CompositingMode.SourceOver;
                    g.Graphics.CompositingQuality = CompositingQuality.HighQuality;


                    using (Font boldFont = new Font(_font, FontStyle.Bold))
                    {
                        Rectangle providerNameRect = new Rectangle(_providerNameLeft, 4, _providerNameWidth, _providerNameHeight);

                        if (_image != null)
                        {
                            g.DrawImage(false, _image, (int)(providerNameRect.Left - _image.Width - IMAGE_PADDING_RIGHT), (int)(providerNameRect.Top - 1));
                        }

                        g.DrawText(_providerName, boldFont, providerNameRect, Color.White, _textFormatFlags);
                    }

                    g.DrawText(_blogName, _font, new Rectangle(PADDING_LEFT, 23, _blogNameWidth, _providerNameHeight), Color.White, _textFormatFlags);
                }

                // This is down here because DrawIcon has a bug (at least with .NET 1.1) where it
                // doesn't respect any translation transforms that have been applied to the Graphics
                // object in GDI+.
                if (_image == null && _icon != null)
                {
                    g.DrawIcon(false, _icon, new Rectangle(bounds.Left + _imageLeft, bounds.Top + 3, IconWidth, IconHeight));
                }
            }
            protected override void OnDrawItem(DrawItemEventArgs e)
            {
                if (e.Index != -1)
                {
                    ParentCategoryComboItem comboItem = Items[e.Index] as ParentCategoryComboItem;

                    e.DrawBackground();

                    // don't indent for main display of category
                    string text = comboItem != null?comboItem.ToString() : "";

                    if (e.Bounds.Width < Width)
                    {
                        text = text.Trim();
                    }

                    Color textColor = ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                                          ? SystemColors.HighlightText
                                          : comboItem.TextColor;

                    BidiGraphics bg = new BidiGraphics(e.Graphics, e.Bounds);
                    bg.DrawText(text, e.Font, e.Bounds, textColor, TextFormatFlags.NoPrefix);

                    e.DrawFocusRectangle();
                }
            }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            int textX = 0;

            if (ShowIcon)
            {
                g.DrawImage(false, _tipIcon, new Point(0, (Height / 2) - (_tipIcon.Height / 2)));
                textX = _tipIcon.Width + 2;
            }

            if (TipText != null)
            {
                TextFormatFlags flags = TextFormatFlags.WordBreak | TextFormatFlags.EndEllipsis;

                // setup text rect
                Rectangle textRectangle = new Rectangle(textX, 0, Width - textX - 3, Height);

                // draw string
                g.DrawText(TipText, Font, textRectangle, Color.FromArgb(GraphicsHelper.Opacity(TextOpacityPct), ForeColor), flags);
            }
        }
Exemple #4
0
        private void DrawTabContents(BidiGraphics g, Color textColor)
        {
            Rectangle logicalClientRect = ClientRectangle;

            if (!Selected)
            {
                logicalClientRect.Height -= 2;
            }

            // Make up for the top "border" being just off the top of the control
            logicalClientRect.Y      -= 1;
            logicalClientRect.Height += 1;

            if (clipLeftBorder)
            {
                logicalClientRect.X     -= 1;
                logicalClientRect.Width += 1;
            }

            if (clipRightBorder)
            {
                logicalClientRect.Width += 1;
            }

            g.DrawText(Text, Font, logicalClientRect, textColor, Color.Transparent, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);

//            if (Focused)
//            {
//                Rectangle rect = logicalClientRect;
//                rect.Inflate(-2, -2);
//                g.DrawFocusRectangle(rect);
//            }
        }
Exemple #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, _controlRectangle);

            Color backgroundColor = ColorizedResources.Instance.SidebarGradientBottomColor;

            using (Brush brush = new SolidBrush(backgroundColor))
                g.FillRectangle(brush, _controlRectangle);

            if (!(_image == null && (Text == null || Text == string.Empty)))
            {
                // draw the border
                using (Pen pen = new Pen(ColorizedResources.Instance.BorderLightColor))
                {
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Top, _controlRectangle.Width, _controlRectangle.Top);
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Bottom, _controlRectangle.Width, _controlRectangle.Bottom);
                }

                // draw the image
                if (_image != null)
                {
                    g.DrawImage(true, _image, new Rectangle(_imageRectangle.Left, _imageRectangle.Top, _image.Width, _image.Height));
                }

                // draw the text
                g.DrawText(Text, ApplicationManager.ApplicationStyle.NormalApplicationFont,
                           new Rectangle(_textRectangle.X, _textRectangle.Y, _textRectangle.Width, _textRectangle.Height),
                           ApplicationManager.ApplicationStyle.PrimaryWorkspaceCommandBarTextColor,
                           _stringFormat);
            }
        }
Exemple #6
0
        protected override void OnPaint(PaintEventArgs args)
        {
            base.OnPaint(args);

            BidiGraphics g = new BidiGraphics(args.Graphics, ClientRectangle);

            g.DrawText(Text, Font, ClientRectangle, SystemColors.ControlText, TextFormatFlags);
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            g.DrawText(Res.Get(StringId.MapSeeInBirdseye), Font,
                       new Rectangle(ScaleX(TEXT_INSET), 0, Width - ScaleX(TEXT_INSET + 5), Height), Color.Black, TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak);
        }
Exemple #8
0
        public static void DrawErrorMockPlayer(Bitmap img, BidiGraphics bidiGraphics, string message)
        {
            int LEFT_PADDING          = 30;
            int RIGHT_PADDING         = 10;
            int ERROR_IMAGE_WIDTH     = 32;
            int ERROR_IMAGE_HEIGHT    = 32;
            int IMAGE_TO_TEXT_PADDING = 7;
            int PLACEHOLDER_HEIGHT    = img.Height;
            int PLACEHOLDER_WIDTH     = img.Width;
            int VERTICAL_OFFSET       = 30;
            int LINE_BREAK_PADDING    = 4;


            Size titleSize = bidiGraphics.MeasureText(Res.Get(StringId.VideoError),
                                                      Res.GetFont(FontSize.XXLarge, FontStyle.Bold),
                                                      new Size(PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING, PLACEHOLDER_HEIGHT - VERTICAL_OFFSET),
                                                      TextFormatFlags.WordBreak);

            bidiGraphics.DrawText(Res.Get(StringId.VideoError),
                                  Res.GetFont(FontSize.XXLarge,
                                              FontStyle.Bold),
                                  new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING,
                                                VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2),
                                                PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING,
                                                PLACEHOLDER_HEIGHT - VERTICAL_OFFSET),
                                  Color.White,
                                  TextFormatFlags.WordBreak);


            bidiGraphics.DrawText(message,
                                  Res.GetFont(FontSize.XLarge,
                                              FontStyle.Regular),
                                  new Rectangle(LEFT_PADDING + ERROR_IMAGE_WIDTH + IMAGE_TO_TEXT_PADDING,
                                                VERTICAL_OFFSET + (ERROR_IMAGE_HEIGHT / 2) - (titleSize.Height / 2) + titleSize.Height + LINE_BREAK_PADDING,
                                                PLACEHOLDER_WIDTH - LEFT_PADDING - ERROR_IMAGE_WIDTH - IMAGE_TO_TEXT_PADDING - RIGHT_PADDING,
                                                PLACEHOLDER_HEIGHT - (VERTICAL_OFFSET + titleSize.Height + LINE_BREAK_PADDING)),
                                  Color.White,
                                  TextFormatFlags.WordBreak);

            bidiGraphics.DrawImage(false,
                                   ResourceHelper.LoadAssemblyResourceBitmap("Video.Images.Error.gif"),
                                   LEFT_PADDING,
                                   VERTICAL_OFFSET);
        }
Exemple #9
0
        /// <summary>
        /// Draw the image and the text overlay
        /// </summary>
        public override void Draw(BidiGraphics g, Font font, Rectangle thumbnailRect)
        {
            // draw the image
            base.Draw(g, font, thumbnailRect);

            // calculate the rectangle for the text then draw it
            Rectangle textRect = new Rectangle(thumbnailRect.X + (int)(thumbnailRect.Width * 0.1F), thumbnailRect.Y, (int)(thumbnailRect.Width * 0.8F), thumbnailRect.Height);

            g.DrawText(_textOverlay, font, textRect, Color.Gray, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak);
        }
Exemple #10
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            //	Paint.
            g.DrawText(Text, Font, ClientRectangle, Color.FromArgb(GraphicsHelper.Opacity(Enabled ? 100.0 : 50.0), ForeColor), stringFormat);

            Size size = new Size(ClientSize.Width, ClientSize.Height);

            measuredTextSize = g.MeasureText(Text, Font, size, stringFormat);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Center;
            Rectangle rectangle = ClientRectangle;

            // draw text
            g.DrawText(HeaderText, _font, rectangle, ColorizedResources.Instance.SidebarHeaderTextColor, TextFormatFlags.VerticalCenter);
        }
Exemple #12
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            using (Brush b = new SolidBrush(ColorizedResources.Instance.BorderDarkColor))
                g.FillRectangle(b, ClientRectangle);

            TextFormatFlags tf    = TextFormatFlags.VerticalCenter;
            int             width = g.MeasureText(Text, Font).Width;

            g.DrawText(Text, Font, new Rectangle(20, -1, width, ClientSize.Height), _uiTheme.TextColor, tf);
        }
Exemple #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, summaryTextRect);

            //paint the background over the last text paint
            using (Brush backBrush = new SolidBrush(BackColor))
            {
                g.FillRectangle(backBrush, summaryTextRect);
            }

            Color textColor = Color.DarkGray;
            Size  sizeTextSize;

            if (linkToSizeText != null)
            {
                sizeTextSize = g.MeasureText(linkToSizeText, Font, summaryTextRect.Size, imageFileSizeFormat);
            }
            else
            {
                sizeTextSize = Size.Empty;
            }

            Size summaryTextSize = g.MeasureText(linkToSummaryText, Font, new Size(summaryTextRect.Size.Width - sizeTextSize.Width - ScaleX(summarySizeSpacing), sizeTextSize.Height), imageFileSummaryFormat);

            Rectangle summaryTextLayoutRect     = new Rectangle(new Point(summaryTextRect.X, summaryTextRect.Y), summaryTextSize);
            Rectangle sizeTextLayoutRect        = new Rectangle(new Point(summaryTextLayoutRect.Right + summarySizeSpacing, summaryTextRect.Y), sizeTextSize);
            Rectangle imageViewerTextLayoutRect = new Rectangle(summaryTextRect.X, sizeTextLayoutRect.Bottom + ScaleY(3), ClientRectangle.Width, (int)Math.Ceiling(Font.GetHeight(e.Graphics)));

            g.DrawText(linkToSummaryText, this.Font, summaryTextLayoutRect, textColor, imageFileSummaryFormat);
            g.DrawText(linkToSizeText, this.Font, sizeTextLayoutRect, textColor, imageFileSummaryFormat);
            if (linkToImageViewer != "")
            {
                g.DrawText(linkToImageViewer, this.Font, imageViewerTextLayoutRect, textColor, imageFileSummaryFormat);
            }
        }
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //	Call the base class's method so that registered delegates receive the event.
            base.OnPaint(e);

            if (!string.IsNullOrEmpty(text))
            {
                BidiGraphics bidiGraphics = new BidiGraphics(e.Graphics, VirtualSize);
                bidiGraphics.DrawText(text,
                                      ApplicationManager.ApplicationStyle.NormalApplicationFont,
                                      textLayoutRectangle,
                                      Color.Black,
                                      textFormatFlags | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.NoPadding);
            }
        }
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs args)
        {
            if (!TabEntry.Hidden)
            {
                //	Call the base class's method so that registered delegates receive the event.
                base.OnPaint(args);

                BidiGraphics g = new BidiGraphics(args.Graphics, VirtualClientRectangle);

                //	Draw the tab.
                DrawTab(g);

                //	Draw the tab bitmap.
                if (!bitmapRectangle.IsEmpty)
                {
                    g.DrawImage(false, TabEntry.TabPageControl.TabBitmap, bitmapRectangle);
                }

                //	Draw tab text.
                if (!textLayoutRectangle.IsEmpty)
                {
                    //	Select the text color to use.
                    Color textColor;
                    if (tabEntry.IsSelected)
                    {
                        textColor = TabEntry.TabPageControl.ApplicationStyle.ActiveTabTextColor;
                    }
                    else
                    {
                        textColor = TabEntry.TabPageControl.ApplicationStyle.InactiveTabTextColor;
                    }

                    Rectangle tempRect = textLayoutRectangle;
                    //	Draw the tab text.
                    g.DrawText(TabEntry.TabPageControl.TabText,
                               TabEntry.TabPageControl.ApplicationStyle.NormalApplicationFont,
                               tempRect,
                               textColor,
                               textFormatFlags);
                }
            }

            if (Focused)
            {
                ControlPaint.DrawFocusRectangle(args.Graphics, VirtualClientRectangle, Parent.ForeColor, Parent.BackColor);
            }
        }
Exemple #16
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientSize, false);

            ColorizedResources colRes = ColorizedResources.Instance;

            // draw the outer border
            using (Pen p = new Pen(colRes.BorderDarkColor, 1))
                g.DrawRectangle(p, new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1));

            // draw the caption
            using (Font f = Res.GetFont(FontSize.Large, FontStyle.Bold))
                g.DrawText(Text, f, new Rectangle(19, 8, ClientSize.Width - 1, ClientSize.Height - 1), SystemColors.WindowText, TextFormatFlags.NoPrefix);

            GdiTextHelper.DrawString(this, labelPublishingTo.Font, _progressMessage, labelPublishingTo.Bounds, false, GdiTextDrawMode.EndEllipsis);
        }
Exemple #17
0
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            // draw image
            const int HEADER_X_INSET = 0;
            const int HEADER_Y_INSET = 0;

            g.DrawImage(false, _headerImage, HEADER_X_INSET, HEADER_Y_INSET);

            // draw text centered vertically
            const int TEXT_X_INSET = 5;
            Size      textSize     = g.MeasureText(_label, Font);
            int       textY        = (Height / 2) - (textSize.Height / 2);
            Color     textColor    = !SystemInformation.HighContrast ? Color.FromArgb(0, 77, 131) : SystemColors.WindowText;
            Rectangle textRect     = new Rectangle(new Point(HEADER_X_INSET + _headerImage.Width + TEXT_X_INSET, textY), textSize);

            g.DrawText(_label, Font, textRect, textColor);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.ResetClip();
            BidiGraphics g = new BidiGraphics(e.Graphics, Bounds, false);

            using (Brush brush = new SolidBrush(SystemColors.ActiveCaption))
            {
                g.FillRectangle(brush, new Rectangle(0, 0, Width - 1, SystemInformation.ToolWindowCaptionHeight));
            }

            using (Pen borderPen = new Pen(Color.FromArgb(127, 157, 185)))
            {
                g.DrawRectangle(borderPen, new Rectangle(0, 0, Width - 1, Height - 1));
                g.DrawLine(borderPen, 0, SystemInformation.ToolWindowCaptionHeight, Width - 1, SystemInformation.ToolWindowCaptionHeight);
            }

            using (Font boldFont = new Font(Font, FontStyle.Bold))
                g.DrawText(Text, boldFont, new Rectangle(4, 2, Width - 2, SystemInformation.ToolWindowCaptionHeight - 1), SystemColors.ActiveCaptionText);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            if (m_pressed)
            {
                SystemButtonHelper.DrawSystemButtonFacePushed(g, false, ClientRectangle, false);
            }
            else if (m_hover)
            {
                SystemButtonHelper.DrawSystemButtonFace(g, false, false, ClientRectangle, false);
            }

            Rectangle colorRect         = new Rectangle(PADDING, PADDING, COLOR_SIZE, COLOR_SIZE);
            Rectangle dropDownArrowRect = new Rectangle(Width - PADDING - m_dropDownArrow.Width,
                                                        PADDING,
                                                        m_dropDownArrow.Width,
                                                        colorRect.Height);
            Rectangle textRect = new Rectangle(PADDING + GUTTER_SIZE + colorRect.Width,
                                               PADDING,
                                               Width - (PADDING + GUTTER_SIZE + colorRect.Width) - (PADDING + GUTTER_SIZE + dropDownArrowRect.Width),
                                               colorRect.Height);

            using (Brush b = new SolidBrush(EffectiveColor))
                g.FillRectangle(b, colorRect);
            using (Pen p = new Pen(SystemColors.Highlight, 1))
                g.DrawRectangle(p, colorRect);

            g.DrawText(Text, Font, textRect, SystemColors.ControlText, ShowKeyboardCues ? TextFormatFlags.Default : TextFormatFlags.NoPrefix);

            g.DrawImage(false,
                        m_dropDownArrow,
                        RectangleHelper.Center(m_dropDownArrow.Size, dropDownArrowRect, false),
                        0,
                        0,
                        m_dropDownArrow.Width,
                        m_dropDownArrow.Height,
                        GraphicsUnit.Pixel);
        }
        // replace standard painting behavior
        protected override void OnDrawItem(DrawItemEventArgs evt)
        {
            BidiGraphics g = new BidiGraphics(evt.Graphics, ClientRectangle);

            // determine the text color based on whether we have categories
            bool  hasCategories = _categoryContext.SelectedCategories.Length > 0;
            Color textColor     = hasCategories ? SystemColors.ControlText : SystemColors.GrayText; //Color.FromArgb(200, SystemColors.ControlText) ;

            // margins
            const int HORIZONTAL_MARGIN = 1;

            // draw the icon (if we have one)
            const int ICON_MARGIN = 4;
            int       textMargin  = 0;

            if (_icon != null)
            {
                g.DrawImage(true, _icon, new Rectangle(ScaleX(ICON_MARGIN), ScaleY(2), ScaleX(_icon.Width), ScaleY(_icon.Height)));
                textMargin += ScaleX(ICON_MARGIN + _icon.Width);
            }

            // draw the text
            int       leftMargin  = textMargin;
            int       rightMargin = ScaleX(HORIZONTAL_MARGIN);
            Rectangle textRegion  = new Rectangle(new Point(leftMargin, -1), new Size(Width - leftMargin - rightMargin, Height));

            TextFormatFlags tempFormat    = DisplayFormat;
            Rectangle       tempRectangle = textRegion;

            g.DrawText(
                _categoryContext.Text,
                Font, tempRectangle, textColor, tempFormat);

            // draw focus rectangle (only if necessary)
            evt.DrawFocusRectangle();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);
            // get post-source we are rendering
            ListBoxEntryItem item = Items[e.Index] as ListBoxEntryItem;

            // determine image and text to use
            Bitmap postSourceImage = item.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // center the image within the list box
            int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2));
            int imageTop  = e.Bounds.Top + ScaleY(LARGE_TOP_INSET);

            g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

            // calculate standard text drawing metrics
            float leftMargin = ScaleX(ELEMENT_PADDING);
            float topMargin  = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING);
            float fontHeight = e.Font.GetHeight();

            // caption
            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                (int)leftMargin,
                (int)topMargin,
                e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)),
                (int)fontHeight * TITLE_LINES);

            // draw caption
            g.DrawText(item.Name, e.Font, layoutRectangle, textColor, TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak);

            // draw focus rectangle if necessary
            e.DrawFocusRectangle();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }
            Rectangle area = e.Bounds;

            e.Graphics.ResetClip();

            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            Image  borderImage = null;
            string borderText  = "";
            object item        = Items[e.Index];

            if (item != null)
            {
                borderText = item.ToString();
            }
            if (item is IComboImageItem)
            {
                IComboImageItem comboItem = (IComboImageItem)item;
                borderImage = comboItem.Image;
            }

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor = SystemColors.Window;
            Color textColor = SystemColors.ControlText;

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                                                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);
            if (selected && Focused && dropDownShowing)
            {
                //draw the focus highlight rectangle
                Rectangle focusRect = new Rectangle(area.X, area.Y, area.Width - 1, area.Height - 1);
                using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(50, SystemColors.Highlight)))
                    g.FillRectangle(solidBrush, focusRect);
                using (Pen focusPen = new Pen(SystemColors.Highlight, 1))
                    g.DrawRectangle(focusPen, focusRect);
            }

            // draw border icon
            if (borderImage != null)
            {
                Rectangle imageRect =
                    new Rectangle(area.Left + HORIZONTAL_INSET, area.Top + TOP_INSET, borderImage.Width,
                                  borderImage.Height);
                g.DrawImage(false, borderImage, imageRect);
                //g.DrawRectangle(Pens.Blue, e.Bounds);
            }
            // calculate standard text drawing metrics
            int leftMargin = HORIZONTAL_INSET + MAX_IMAGE_WIDTH + HORIZONTAL_INSET;

            // draw title line
            // post title
            int       titleWidth     = e.Bounds.Width - leftMargin - 1;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height - 1);

            //g.DrawRectangle(Pens.Red,titleRectangle);
            g.DrawText(
                borderText,
                e.Font, titleRectangle,
                textColor, ellipsesStringFormat);
            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
Exemple #23
0
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //	Call the base class's method so that registered delegates receive the event.
            base.OnPaint(e);

            BidiGraphics g = new BidiGraphics(e.Graphics, ClientRectangle);

            //	Determine the draw state of the button.
            DrawState drawState;

            if (!Enabled)
            {
                drawState = DrawState.Disabled;
            }
            else if (Latched)
            {
                drawState = DrawState.Latched;
            }
            else if (Pushed && MouseInside)
            {
                drawState = DrawState.Pushed;
            }
            else if (MouseInside)
            {
                drawState = DrawState.Selected;
            }
            else
            {
                drawState = DrawState.Enabled;
            }

            //	Draw the button face, as needed, and select the button bitmap to draw below.
            Bitmap buttonBitmap = null;

            switch (drawState)
            {
            case DrawState.Disabled:
                buttonBitmap = BitmapDisabled;
                break;

            case DrawState.Enabled:
                if (Focused)
                {
                    if (ButtonStyle == ButtonStyle.Standard)
                    {
                        DrawStandardButtonFace(e.Graphics);
                    }
                    else if (ButtonStyle == ButtonStyle.Flat)
                    {
                        DrawFlatButtonFace(e.Graphics);
                    }
                }

                buttonBitmap = BitmapEnabled;
                break;

            case DrawState.Selected:
                if (ButtonStyle == ButtonStyle.Standard)
                {
                    DrawStandardButtonFace(e.Graphics);
                }
                else if (ButtonStyle == ButtonStyle.Flat)
                {
                    DrawFlatButtonFace(e.Graphics);
                }
                buttonBitmap = BitmapSelected;
                break;

            case DrawState.Latched:
            case DrawState.Pushed:
                if (ButtonStyle == ButtonStyle.Standard)
                {
                    DrawStandardButtonFacePushed(e.Graphics);
                    buttonBitmap = BitmapSelected;
                }
                else if (ButtonStyle == ButtonStyle.Flat)
                {
                    DrawFlatButtonFacePushed(e.Graphics);
                    buttonBitmap = BitmapSelected;
                }
                else if (ButtonStyle == ButtonStyle.Bitmap)
                {
                    buttonBitmap = BitmapPushed;
                }
                break;
            }

            //	Draw the button bitmap, if there is one.
            if (buttonBitmap != null)
            {
                //	Set the rectangle into which we'll draw the bitmap.
                Rectangle drawBitmapRectangle = bitmapRectangle;
                //				if (ButtonStyle != ButtonStyle.Bitmap && drawState == DrawState.Pushed)
                //					drawBitmapRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET));

                //	Draw the bitmap.
                var destRect = new Rectangle(drawBitmapRectangle.X, drawBitmapRectangle.Y, ScaleX(buttonBitmap.Width), ScaleY(buttonBitmap.Height));
                g.DrawImage(AllowMirroring, buttonBitmap, destRect);
            }

            //	If focus is being shown, and we're focused, draw the focus rectangle.
            if (ShowFocusCues && Focused)
            {
                Rectangle rectangle = ClientRectangle;
                if (ButtonStyle == ButtonStyle.Flat)
                {
                    //offset the focus a bit to ensure it draws directly over the flat border
                    rectangle = new Rectangle(rectangle.Location, new Size(ScaleX(rectangle.Width - 1), ScaleY(rectangle.Height - 1)));

                    //clear the background of the rectangle so it contrasts well with the flat selection
                    using (Pen p = new Pen(BackColor))
                        g.DrawRectangle(p, rectangle);
                }

                ControlPaint.DrawFocusRectangle(e.Graphics, rectangle);
            }

            //	Draw the button text, if there is some.
            if (ButtonStyle != ButtonStyle.Bitmap && buttonText != null)
            {
                //	Set the rectangle into which we'll draw the text.
                Rectangle drawTextRectangle = textRectangle;
                drawTextRectangle.Offset(HORIZONTAL_TEXT_PAD, VERTICAL_TEXT_PAD);
                if (drawState == DrawState.Pushed)
                {
                    drawTextRectangle.Offset(ScaleX(PUSHED_OFFSET), ScaleY(PUSHED_OFFSET));
                }

                TextFormatFlags textFormat;
                if (ShowKeyboardCues)
                {
                    textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis;
                }
                else
                {
                    textFormat = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding | TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.EndEllipsis | TextFormatFlags.HidePrefix;
                }

                //	Set the text color.
                Color textColor = ForeColor;
                if (!Enabled)
                {
                    textColor = Color.FromArgb(GraphicsHelper.Opacity(50), textColor);
                }

                //	Draw the text.
                g.DrawText(buttonText,
                           Font,
                           drawTextRectangle,
                           textColor,
                           textFormat);
            }
        }
Exemple #24
0
        /// <summary>
        /// Draws a menu item.
        /// </summary>
        /// <param name="drawItemState">A DrawItemEventArgs that contains the event data.</param>
        /// <param name="rect">A DrawItemEventArgs that contains the client rectangle.</param>
        private void DrawMenuItem(DrawItemState drawItemState, Rectangle rect)
        {
            //	Create graphics context on the offscreen bitmap and set the bounds for painting.
            Graphics graphics = Graphics.FromImage(offscreenBitmap);

            graphics.CompositingMode    = CompositingMode.SourceOver;
            graphics.CompositingQuality = CompositingQuality.HighQuality;
            BidiGraphics g = new BidiGraphics(graphics, new Rectangle(Point.Empty, offscreenBitmap.Size));

            try
            {
                Rectangle bounds = new Rectangle(0, 0, offscreenBitmap.Width, offscreenBitmap.Height);

                //	Fill the menu item with the system-defined menu color.
                g.FillRectangle(SystemBrushes.Menu, bounds);

                //	Fill the bitmap area with the system-defind control color.
                Rectangle bitmapAreaRectangle = new Rectangle(bounds.X,
                                                              bounds.Y,
                                                              STANDARD_BITMAP_AREA_WIDTH,
                                                              bounds.Height);

                //	Fill the background.

                /*
                 * using (SolidBrush solidBrush = new SolidBrush(ApplicationManager.ApplicationStyle.MenuBitmapAreaColor))
                 *  graphics.FillRectangle(solidBrush, bitmapAreaRectangle);
                 */
                Color backgroundColor = SystemColors.Menu;
                //	If the item is selected, draw the selection rectangle.
                if ((drawItemState & DrawItemState.Selected) != 0)
                {
                    DrawHotlight(g, SystemColors.Highlight, bounds, true);
                    backgroundColor = offscreenBitmap.GetPixel(2, 2);
                }

                //	Obtain the bitmap to draw.  If there is one, draw it centered in the bitmap area.
                Bitmap bitmap = MenuBitmap(drawItemState);
                if (bitmap != null)
                {
                    g.DrawImage(false, bitmap, new Point(
                                    bounds.X + Utility.CenterMinZero(bitmap.Width, bitmapAreaRectangle.Width),
                                    bounds.Y + Utility.CenterMinZero(bitmap.Height, bitmapAreaRectangle.Height)));
                }

                //	Obtain the menu text.  If it's not "-", then this is a menu item.  Otherwise, it's
                //	a separator menu item.
                if (MenuText() != "-")
                {
                    //	Calculate the text area rectangle.  This area excludes an area at the right
                    //	edge of the menu item where the system draws the cascade indicator.  It would
                    //	have been better if MenuItem let us draw the indicator (we did say "OwnerDraw"
                    //	afterall), but this is just how it works.
                    Rectangle textAreaRectangle = new Rectangle(bounds.X + STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING,
                                                                bounds.Y,
                                                                bounds.Width - (STANDARD_BITMAP_AREA_WIDTH + STANDARD_TEXT_PADDING + STANDARD_RIGHT_EDGE_PAD),
                                                                bounds.Height);

                    //	Select the brush to draw the menu text with.
                    Color color;
                    if ((drawItemState & DrawItemState.Disabled) == 0)
                    {
                        color = SystemColors.MenuText;
                    }
                    else
                    {
                        color = SystemColors.GrayText;
                    }

                    //	Determine the size of the shortcut, if it is being shown.
                    if (!(MenuType == MenuType.Context))
                    {
                        string shortcut;
                        Size   shortcutSize;
                        if (ShowShortcut && Shortcut != Shortcut.None)
                        {
                            shortcut     = FormatShortcutString(Shortcut);
                            shortcutSize = MeasureShortcutMenuItemText(graphics, shortcut);
                        }
                        else
                        {
                            shortcut     = null;
                            shortcutSize = MeasureShortcutMenuItemText(graphics, FormatShortcutString(Shortcut.CtrlIns));
                        }

                        //	Draw the shortcut.
                        if (shortcut != null)
                        {
                            Rectangle       shortcutTextRect = textAreaRectangle;
                            TextFormatFlags textFormatTemp   = shortcutStringFormat;
                            //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, shortcut, ref stringFormatTemp, ref shortcutTextRect);
                            //	Draw the shortcut text.
                            g.DrawText(shortcut,
                                       menuFont,
                                       shortcutTextRect,
                                       color,
                                       backgroundColor,
                                       textFormatTemp);
                        }

                        //	Reduce the width of the text area rectangle to account for the shortcut and
                        //	the padding before it.
                        textAreaRectangle.Width -= shortcutSize.Width + STANDARD_TEXT_PADDING;
                    }

                    //	Determine which StringFormat to use when drawing the menu item text.
                    TextFormatFlags textFormat;
                    if ((drawItemState & DrawItemState.NoAccelerator) != 0)
                    {
                        textFormat = menuItemTextNoHotKeyStringFormat;
                    }
                    else
                    {
                        textFormat = menuItemTextHotKeyStringFormat;
                    }

                    //DisplayHelper.FixupGdiPlusLineCentering(graphics, menuFont, MenuText(), ref stringFormat, ref textAreaRectangle);
                    //	Draw the text.
                    g.DrawText(MenuText(),
                               menuFont,
                               textAreaRectangle,
                               color,
                               backgroundColor,
                               textFormat);
                }
                else
                {
                    //	Calculate the separator line rectangle.  This area excludes an area at the right
                    //	edge of the menu item where the system draws the cascade indicator.  It would
                    //	have been better if MenuItem let us draw the indicator (we did say "OwnerDraw"
                    //	after all), but this is just how it works.
                    Rectangle separatorLineRectangle = new Rectangle(bounds.X + STANDARD_SEPARATOR_PADDING,
                                                                     bounds.Y + Utility.CenterMinZero(1, bounds.Height),
                                                                     bounds.Width - STANDARD_SEPARATOR_PADDING,
                                                                     1);

                    //	Fill the separator line rectangle.
                    g.FillRectangle(SystemBrushes.ControlDark, separatorLineRectangle);
                }
            }
            finally
            {
                //	We're finished with the double buffered painting.  Dispose of the graphics context
                //	and draw the offscreen image.  Cache the offscreen bitmap, though.
                graphics.Dispose();
            }
        }
Exemple #25
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get post we are rendering
            PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // draw top-line if necessary
            //if ( !selected )
            {
                using (Pen pen = new Pen(_theme.topLineColor))
                    g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1));
            }

            // draw post icon
            g.DrawImage(false, _blogPostImage, new Rectangle(
                            e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET),
                            ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height)));

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET);
            int topMargin  = e.Bounds.Top + ScaleY(TITLE_INSET);
            // draw title line

            // post date
            string    dateText      = postInfo.PrettyDateDisplay;
            Size      dateSize      = g.MeasureText(dateText, e.Font);
            Rectangle dateRectangle = new Rectangle(
                e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height);

            g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix);

            // post title
            int       titleWidth     = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING);
            string    titleString    = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title);
            int       fontHeight     = g.MeasureText(titleString, e.Font).Height;
            Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

            g.DrawText(
                titleString,
                e.Font,
                titleRectangle, textColor, ellipsesStringFormat);

            // draw post preview

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                topMargin + fontHeight + ScaleY(PREVIEW_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                fontHeight * PREVIEW_LINES);

            // draw post preview
            string postPreview = postInfo.PlainTextContents;

            if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty))
            {
                postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview);
            }

            g.DrawText(
                postPreview,
                e.Font, layoutRectangle, textColor, ellipsesStringFormat);

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
 public static void DrawStatusMockPlayer(Bitmap img, BidiGraphics bidiGraphics, string message)
 {
     bidiGraphics.DrawText(message, Res.GetFont(FontSize.XXLarge, FontStyle.Regular), new Rectangle(10, img.Height / 2, img.Width - 20, img.Height / 2), Color.White, TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak);
 }
        private Size Render(BidiGraphics g, int width, int height)
        {
            int maxWidth = 0;
            // Start at the top left after padding
            Point origin = new Point(HORIZONTAL_PADDING, VERTICAL_PADDING);

            // Draw the green arrow
            Image arrow;

            if (IsHovered)
            {
                arrow = ResourceHelper.LoadAssemblyResourceBitmap("Images.arrow_hover.png");
            }
            else
            {
                arrow = ResourceHelper.LoadAssemblyResourceBitmap("Images.arrow.png");
            }
            if (g != null)
            {
                g.DrawImage(true, arrow, origin.X, origin.Y + 3);
            }
            origin.Offset(arrow.Width + HORIZONTAL_PADDING, 0);

            TextFormatFlags textFormatFlags = TextFormatFlags.NoPadding | TextFormatFlags.WordBreak;

            // Draw the Heading
            Size headingMaxSize = new Size(width - origin.X - HORIZONTAL_PADDING - 1, height - origin.Y - VERTICAL_PADDING);

            if (g == null)
            {
                headingSize = TextRenderer.MeasureText(Heading, Res.GetFont(FontSize.XLarge, FontStyle.Regular),
                                                       headingMaxSize, textFormatFlags);
            }
            else
            {
                g.DrawText(Heading, Res.GetFont(FontSize.XLarge, FontStyle.Regular), new Rectangle(new Point(origin.X - 1, origin.Y), headingMaxSize), ChoiceDialog.BlueText, textFormatFlags);
            }
            origin.Offset(0, headingSize.Height + INSIDE_VERTICAL_PADDING);
            maxWidth = headingSize.Width;

            // Draw the subheading
            if (!string.IsNullOrEmpty(SubHeading))
            {
                if (g == null)
                {
                    subHeadingSize = TextRenderer.MeasureText(SubHeading, Res.DefaultFont,
                                                              new Size(width - origin.X - HORIZONTAL_PADDING, height - origin.Y), textFormatFlags | TextFormatFlags.NoPrefix);
                }
                else
                {
                    g.DrawText(SubHeading, Res.DefaultFont, new Rectangle(origin.X, origin.Y, width - origin.X - HORIZONTAL_PADDING, height - origin.Y), ChoiceDialog.BlueText, textFormatFlags | TextFormatFlags.NoPrefix);
                }
                maxWidth = Math.Max(subHeadingSize.Width, maxWidth);
                origin.Offset(0, subHeadingSize.Height + INSIDE_VERTICAL_PADDING);
            }

            // Draw the image
            if (OptionImage != null)
            {
                if (g != null)
                {
                    g.DrawImage(false, OptionImage, origin);
                }
                origin.Offset(0, OptionImage.Height);
                maxWidth = Math.Max(OptionImage.Width, maxWidth);
            }

            origin.Offset(maxWidth + HORIZONTAL_PADDING, VERTICAL_PADDING);
            return(new Size(origin));
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get item text and image
            string     itemText  = Items[e.Index].ToString();
            IComboItem comboItem = (IComboItem)Items[e.Index];
            Image      itemImage = comboItem.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected && Focused)
            {
                textColor = SystemColors.ControlText;
                backColor = Color.FromArgb(50, SystemColors.Highlight);
            }
            else
            {
                backColor = SystemColors.Window;
                textColor = SystemColors.ControlText;
            }
            Rectangle area = e.Bounds;

            //overlap issue in RTL builds in the selected box area ONLY
            if (area.X == 21)
            {
                area = ClientRectangle;
            }
            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            // draw background (always paint white over it first)
            g.FillRectangle(Brushes.White, area);
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);

            // draw icon
            g.DrawImage(AllowMirroring, itemImage, area.Left + IMAGE_INSET, area.Top + area.Height / 2 - itemImage.Height / 2);

            // text format and drawing metrics
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                                                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;
            int leftMargin = IMAGE_INSET + itemImage.Width + TEXT_INSET;

            // draw title line
            // post title
            int       titleWidth     = area.Right - leftMargin;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height);

            g.DrawText(
                itemText,
                e.Font, titleRectangle, textColor, ellipsesStringFormat);

            // separator line if necessary
            if (!selected && DroppedDown)
            {
                using (Pen pen = new Pen(SystemColors.ControlLight))
                    g.DrawLine(pen, area.Left, area.Bottom - 1, area.Right, area.Bottom - 1);
            }

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
Exemple #29
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            BidiGraphics g = new BidiGraphics(e.Graphics, VirtualClientRectangle);

            Rectangle tabRectangle = VirtualClientRectangle;

            if (selected)
            {
                ColorizedResources.Instance.ViewSwitchingTabSelected.DrawBorder(e.Graphics, tabRectangle);
            }
            else
            {
                ColorizedResources.Instance.ViewSwitchingTabUnselected.DrawBorder(e.Graphics, tabRectangle);
            }

            if (ColorizedResources.UseSystemColors)
            {
                if (BorderColor.HasValue)
                {
                    using (Pen pen = new Pen(BorderColor.Value))
                    {
                        if (!selected)
                        {
                            g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Right,
                                       tabRectangle.Top);
                        }
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Left,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Right - 1, tabRectangle.Top, tabRectangle.Right - 1,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Bottom - 1,
                                   tabRectangle.Right, tabRectangle.Bottom - 1);
                    }
                }
            }

            /*
             * if (!selected && !SystemInformation.HighContrast)
             * {
             *
             *  using (Pen p = new Pen(borderColor, 1.0f))
             *      g.DrawLine(p, 0, 0, VirtualWidth, 0);
             *  using (Pen p = new Pen(Color.FromArgb(192, borderColor), 1.0f))
             *      g.DrawLine(p, 0, 1, VirtualWidth - 1, 1);
             *  using (Pen p = new Pen(Color.FromArgb(128, borderColor), 1.0f))
             *      g.DrawLine(p, 0, 2, VirtualWidth - 2, 2);
             *  using (Pen p = new Pen(Color.FromArgb(64, borderColor), 1.0f))
             *      g.DrawLine(p, 0, 3, VirtualWidth - 2, 3);
             * }
             * */

            Rectangle textBounds = tabRectangle;

            if (!selected)
            {
                textBounds.Y += (int)DisplayHelper.ScaleX(3);
            }
            else
            {
                textBounds.Y += (int)DisplayHelper.ScaleX(3);
            }

            Color textColor = ColorizedResources.Instance.MainMenuTextColor;

            if (selected)
            {
                textColor = Parent.ForeColor;
            }

            g.DrawText(Text, selected ? ctx.Font : ctx.Font, textBounds, SystemInformation.HighContrast ? SystemColors.ControlText : textColor,
                       TextFormatFlags.Top | TextFormatFlags.HorizontalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping);
        }
Exemple #30
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
            {
                return;
            }

            // get post-source we are rendering
            IPostEditorPostSource postSource = (Items[e.Index] as PostSourceItem).PostSource;

            // determine image and text to use
            Image postSourceImage;

            if (e.Index == _draftsIndex)
            {
                postSourceImage = _showLargeIcons ? _draftsImageLarge : _draftsImage;
            }
            else if (e.Index == _recentPostsIndex)
            {
                postSourceImage = _showLargeIcons ? _recentPostsImageLarge : _recentPostsImage;
            }
            else
            {
                postSourceImage = _showLargeIcons ? _weblogImageLarge : _weblogImage;
            }


            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;

            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            if (_showLargeIcons)
            {
                // center the image within the list box
                int imageLeft = e.Bounds.Left + ((e.Bounds.Width / 2) - (ScaleX(postSourceImage.Width) / 2));
                int imageTop  = e.Bounds.Top + ScaleY(LARGE_TOP_INSET);
                g.DrawImage(false, postSourceImage, new Rectangle(imageLeft, imageTop, ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.HorizontalCenter;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING);
                int topMargin  = imageTop + ScaleY(postSourceImage.Height) + ScaleY(ELEMENT_PADDING);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - (2 * ScaleX(ELEMENT_PADDING)),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);
            }
            else
            {
                // draw post icon
                g.DrawImage(false, postSourceImage,
                            new Rectangle(e.Bounds.Left + ScaleX(ELEMENT_PADDING), e.Bounds.Top + ScaleY(SMALL_TOP_INSET),
                                          ScaleX(postSourceImage.Width), ScaleY(postSourceImage.Height)));

                // setup string format
                TextFormatFlags stringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

                // calculate standard text drawing metrics
                int leftMargin = ScaleX(ELEMENT_PADDING) + ScaleX(postSourceImage.Width) + ScaleX(ELEMENT_PADDING);
                int topMargin  = e.Bounds.Top + ScaleY(SMALL_TOP_INSET);
                int fontHeight = g.MeasureText(postSource.Name, e.Font).Height;

                // caption
                // calculate layout rectangle
                Rectangle layoutRectangle = new Rectangle(
                    leftMargin,
                    topMargin,
                    e.Bounds.Width - leftMargin - ScaleX(ELEMENT_PADDING),
                    fontHeight * TITLE_LINES);

                // draw caption
                g.DrawText(postSource.Name, e.Font, layoutRectangle, textColor, stringFormat);
            }

            // draw focus rectange if necessary
            e.DrawFocusRectangle();
        }