Example #1
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IParagraphStyle paragraphStyle) {
			StringFormat stringFormat = ToolCache.GetStringFormat(paragraphStyle);
			Rectangle r = Rectangle.Empty;
			r.X = previewBounds.X + paragraphStyle.Padding.Left;
			r.Y = previewBounds.Y + paragraphStyle.Padding.Top;
			r.Width = (previewBounds.Width * 10) - (paragraphStyle.Padding.Left + paragraphStyle.Padding.Right);
			r.Height = (previewBounds.Height * 10) - (paragraphStyle.Padding.Top + paragraphStyle.Padding.Bottom);

			// Transform
			float scale = Geometry.CalcScaleFactor(r.Width, r.Height, previewBounds.Width, previewBounds.Height);
			gfx.ScaleTransform(scale, scale);

			// Draw
			gfx.DrawString(previewText, Control.DefaultFont, Brushes.Black, r, stringFormat);
		}
Example #2
0
        /// <override></override>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (maxItemTextWidth < 0)
            {
                UpdateMaxItemWidth(e.Graphics);
            }
            const int txtMargin = 4;

            itemBounds.X      = e.Bounds.X + 3;
            itemBounds.Y      = e.Bounds.Y + 1;
            itemBounds.Width  = (e.Bounds.Right - 3) - (e.Bounds.X + 3);
            itemBounds.Height = (e.Bounds.Bottom - 1) - (e.Bounds.Y + 1);

            previewRect.X      = itemBounds.X + margin;
            previewRect.Y      = itemBounds.Y + margin;
            previewRect.Width  = itemBounds.Width - Math.Max(maxItemTextWidth, itemBounds.Width / 4) - (2 * margin) - (2 * txtMargin);
            previewRect.Height = (itemBounds.Bottom - margin) - (itemBounds.Y + margin);

            labelLayoutRect.X      = previewRect.Right + txtMargin;
            labelLayoutRect.Y      = previewRect.Y;
            labelLayoutRect.Width  = maxItemTextWidth;
            labelLayoutRect.Height = previewRect.Height;

            // Draw Item Background and Border
            e.Graphics.FillRectangle(ItemBackgroundBrush, itemBounds);
            if (itemBorderColor != Color.Transparent)
            {
                e.Graphics.DrawRectangle(ItemBorderPen, itemBounds);
            }

            // Draw Selection and/or Focus markers
            if ((e.State & DrawItemState.Selected) != 0)
            {
                e.Graphics.FillRectangle(ItemSelectedBrush, itemBounds);
            }
            if ((e.State & DrawItemState.Focus) != 0)
            {
                if (itemFocusedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemFocusedBrush, itemBounds);
                }
                if (FocusBorderColor != Color.Transparent)
                {
                    e.Graphics.DrawRectangle(FocusBorderPen, itemBounds);
                }
            }
            else if (HighlightItems && (e.State & DrawItemState.HotLight) != 0)
            {
                if (ItemHighlightedColor != Color.Transparent)
                {
                    e.Graphics.FillRectangle(ItemHighlightedBrush, itemBounds);
                }
            }

            e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            if (Items.Count > 0 && e.Index >= 0)
            {
                if (Items[e.Index] is IStyle)
                {
                    switch (StyleCategory)
                    {
                    case StyleCategory.CapStyle:
                        DrawCapStyleItem((CapStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.ColorStyle:
                        ColorStyle colorStyle = (ColorStyle)Items[e.Index];
                        Brush      colorBrush = ToolCache.GetBrush(colorStyle);
                        e.Graphics.FillRectangle(colorBrush, previewRect);
                        e.Graphics.DrawRectangle(ItemBorderPen, previewRect);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(colorStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.FillStyle:
                        DrawFillStyleItem((FillStyle)Items[e.Index], e);
                        break;

                    case StyleCategory.CharacterStyle:
                        CharacterStyle charStyle = (CharacterStyle)Items[e.Index];
                        Font           font      = ToolCache.GetFont(charStyle);
                        Brush          fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
                        e.Graphics.DrawString(string.Format("{0} {1} pt", font.FontFamily.Name, font.SizeInPoints), font, fontBrush, previewRect, styleItemFormatter);
                        e.Graphics.DrawString(charStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.LineStyle:
                        LineStyle lineStyle = (LineStyle)Items[e.Index];
                        Pen       linePen   = ToolCache.GetPen(lineStyle, null, null);
                        e.Graphics.DrawLine(linePen, previewRect.X, previewRect.Y + (previewRect.Height / 2), previewRect.Right, previewRect.Y + (previewRect.Height / 2));
                        e.Graphics.DrawString(lineStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    case StyleCategory.ParagraphStyle:
                        ParagraphStyle paragraphStyle = (ParagraphStyle)Items[e.Index];
                        StringFormat   stringFormat   = ToolCache.GetStringFormat(paragraphStyle);
                        Rectangle      r = Rectangle.Empty;
                        r.X      = previewRect.Left + paragraphStyle.Padding.Left;
                        r.Y      = previewRect.Top + paragraphStyle.Padding.Top;
                        r.Width  = previewRect.Width - (paragraphStyle.Padding.Left + paragraphStyle.Padding.Right);
                        r.Height = previewRect.Height - (paragraphStyle.Padding.Top + paragraphStyle.Padding.Bottom);
                        e.Graphics.DrawString(previewText, e.Font, TextBrush, r, stringFormat);
                        e.Graphics.DrawRectangle(Pens.Black, previewRect);
                        e.Graphics.DrawString(paragraphStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
                        break;

                    default:
                        throw new NShapeException(string.Format("Unexpected enum value '{0}'.", styleCategory));
                    }
                }
                else
                {
                    e.Graphics.DrawString(Items[e.Index].ToString().Trim(), e.Font, TextBrush, e.Bounds, specialItemFormatter);
                }
            }
        }