Example #1
0
        private void DrawFillStyleItem(IFillStyle fillStyle, DrawItemEventArgs e)
        {
            Brush fillBrush = ToolCache.GetBrush(fillStyle);

            // Transform
            if (fillBrush is LinearGradientBrush)
            {
                float srcGradLen = ((LinearGradientBrush)fillBrush).Rectangle.Width;
                //float dstGradLen = previewRect.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle));
                float dstGradLen = (float)Math.Sqrt((previewRect.Width * previewRect.Width) + (previewRect.Height * previewRect.Height));
                float scale      = dstGradLen / srcGradLen;
                ((LinearGradientBrush)fillBrush).ResetTransform();
                ((LinearGradientBrush)fillBrush).TranslateTransform(previewRect.X, previewRect.Y);
                ((LinearGradientBrush)fillBrush).ScaleTransform(scale, scale);
                ((LinearGradientBrush)fillBrush).RotateTransform(fillStyle.GradientAngle);
            }
            else if (fillBrush is TextureBrush)
            {
                float scaleX = (float)previewRect.Width / ((TextureBrush)fillBrush).Image.Width;
                float scaleY = (float)previewRect.Height / ((TextureBrush)fillBrush).Image.Height;
                ((TextureBrush)fillBrush).ResetTransform();
                ((TextureBrush)fillBrush).TranslateTransform(previewRect.X, previewRect.Y);
                ((TextureBrush)fillBrush).ScaleTransform(scaleX, scaleY);
            }
            // Draw
            if (fillBrush != Brushes.Transparent)
            {
                e.Graphics.FillRectangle(fillBrush, previewRect);
            }
            e.Graphics.DrawRectangle(ItemBorderPen, previewRect);
            e.Graphics.DrawRectangle(Pens.Black, previewRect);
            e.Graphics.DrawString(fillStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
        }
Example #2
0
        private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IFillStyle fillStyle)
        {
            Brush fillBrush = ToolCache.GetBrush(fillStyle);

            // Transform
            if (fillBrush is LinearGradientBrush)
            {
                float srcGradLen = ((LinearGradientBrush)fillBrush).Rectangle.Width;
                float dstGradLen = previewBounds.Width / (float)Math.Cos(Geometry.DegreesToRadians(fillStyle.GradientAngle));
                float scale      = dstGradLen / srcGradLen;
                ((LinearGradientBrush)fillBrush).ResetTransform();
                ((LinearGradientBrush)fillBrush).ScaleTransform(scale, scale);
                ((LinearGradientBrush)fillBrush).RotateTransform(fillStyle.GradientAngle);
            }
            else if (fillBrush is TextureBrush)
            {
                if (fillStyle.ImageLayout == ImageLayoutMode.Stretch)
                {
                    float scaleX = (float)previewBounds.Width / ((TextureBrush)fillBrush).Image.Width;
                    float scaleY = (float)previewBounds.Height / ((TextureBrush)fillBrush).Image.Height;
                    ((TextureBrush)fillBrush).ScaleTransform(scaleX, scaleY);
                }
                else
                {
                    float scale = Geometry.CalcScaleFactor(((TextureBrush)fillBrush).Image.Width, ((TextureBrush)fillBrush).Image.Height, previewBounds.Width, previewBounds.Height);
                    ((TextureBrush)fillBrush).ScaleTransform(scale, scale);
                    ((TextureBrush)fillBrush).TranslateTransform((((TextureBrush)fillBrush).Image.Width * scale) / 2, (((TextureBrush)fillBrush).Image.Height * scale) / 2);
                }
            }
            // Draw
            if (fillBrush != Brushes.Transparent)
            {
                gfx.FillRectangle(fillBrush, previewBounds);
            }
        }
Example #3
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICharacterStyle charStyle) {
			Brush fontBrush = ToolCache.GetBrush(charStyle.ColorStyle);
			Font font = ToolCache.GetFont(charStyle);
			int height = Geometry.PointToPixel(charStyle.SizeInPoints, gfx.DpiY);
			float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
			gfx.ScaleTransform(scale, scale);
			RectangleF layoutRect = RectangleF.Empty;
			layoutRect.X = 0;
			layoutRect.Y = 0;
			layoutRect.Width = (float)previewBounds.Width / scale;
			layoutRect.Height = (float)previewBounds.Height / scale;
			gfx.DrawString(string.Format("{0} {1} pt", charStyle.FontName, charStyle.SizeInPoints), 
				font, fontBrush, layoutRect, formatter);
		}
Example #4
0
        private void DrawCapStyleItem(ICapStyle capStyle, DrawItemEventArgs e)
        {
            ILineStyle lineStyle = styleSet.LineStyles.Normal;
            Pen        capPen    = ToolCache.GetPen(lineStyle, capStyle, capStyle);
            Brush      capBrush  = null;

            PointF[] capPoints = null;

            int left  = previewRect.Left;
            int right = previewRect.Right;

            if (capPen.StartCap == LineCap.Custom)
            {
                if (capPen.CustomStartCap.BaseInset > 0)
                {
                    left  += (int)Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
                    right -= (int)Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
                }
            }
            int y = previewRect.Y + (previewRect.Height / 2);

            // Start Cap
            if (HasCustomLineCap(capStyle))
            {
                capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
                ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
                float angle = Geometry.RadiansToDegrees(Geometry.Angle(left, y, right, y));
                matrix.Reset();
                matrix.Translate(left, y);
                matrix.Rotate(angle + 90);
                matrix.TransformPoints(capPoints);
                e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
            }
            // End Cap
            if (HasCustomLineCap(capStyle))
            {
                capBrush = ToolCache.GetBrush(capStyle.ColorStyle, lineStyle);
                ToolCache.GetCapPoints(capStyle, styleSet.LineStyles.Normal, ref capPoints);
                float angle = Geometry.RadiansToDegrees(Geometry.Angle(right, y, left, y));
                matrix.Reset();
                matrix.Translate(right, y);
                matrix.Rotate(angle + 90);
                matrix.TransformPoints(capPoints);
                e.Graphics.FillPolygon(capBrush, capPoints, System.Drawing.Drawing2D.FillMode.Alternate);
            }
            // Draw
            e.Graphics.DrawLine(capPen, left, y, right, y);
            e.Graphics.DrawString(capStyle.Title, e.Font, TextBrush, labelLayoutRect, styleItemFormatter);
        }
Example #5
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);
                }
            }
        }
Example #6
0
        private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, IColorStyle colorStyle)
        {
            Brush brush = ToolCache.GetBrush(colorStyle);

            gfx.FillRectangle(brush, previewBounds);
        }