示例#1
0
        private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ICapStyle capStyle)
        {
            Pen   capPen = ToolCache.GetPen(design.LineStyles.Normal, null, capStyle);
            float scale  = 1;

            if (capStyle.CapSize + 2 >= previewBounds.Height)
            {
                scale = Geometry.CalcScaleFactor(capStyle.CapSize + 2, capStyle.CapSize + 2, previewBounds.Width - 2, previewBounds.Height - 2);
                gfx.ScaleTransform(scale, scale);
            }
            int startX, endX, y;

            startX = previewBounds.Left;
            if (capPen.StartCap == LineCap.Custom)
            {
                startX += (int)Math.Round(capStyle.CapSize - capPen.CustomStartCap.BaseInset);
            }
            startX = (int)Math.Round(startX / scale);
            endX   = previewBounds.Right;
            if (capPen.EndCap == LineCap.Custom)
            {
                endX -= (int)Math.Round(capStyle.CapSize - capPen.CustomEndCap.BaseInset);
            }
            endX = (int)Math.Round(endX / scale);
            y    = (int)Math.Round((previewBounds.Y + ((float)previewBounds.Height / 2)) / scale);
            gfx.DrawLine(capPen, startX, y, endX, y);
        }
示例#2
0
        /// <override></override>
        protected override float CalcCapAngle(ControlPointId pointId)
        {
            float          result = float.NaN;
            ControlPointId otherPointId;
            float          capInset;
            int            step, endIdx;

            // Get required infos
            Pen pen = ToolCache.GetPen(LineStyle, StartCapStyleInternal, EndCapStyleInternal);

            if (IsFirstVertex(pointId))
            {
                otherPointId = GetNextVertexId(ControlPointId.FirstVertex);
                capInset     = pen.CustomStartCap.BaseInset;
                step         = 1;
                endIdx       = VertexCount - 1;
            }
            else if (IsLastVertex(pointId))
            {
                otherPointId = GetPreviousVertexId(ControlPointId.LastVertex);
                capInset     = pen.CustomEndCap.BaseInset;
                step         = -1;
                endIdx       = 0;
            }
            else
            {
                throw new NotSupportedException();
            }
            int capPtIdx   = GetControlPointIndex(pointId);
            int otherPtIdx = GetControlPointIndex(otherPointId);

            // Calculate cap angle
            if (Geometry.DistancePointPoint(vertices[capPtIdx], vertices[otherPtIdx]) < capInset)
            {
                // if the second point of the line is inside the cap, calculate the intersection point of the
                // cap shape with the line (as GDI+ does automatically)
                int i = capPtIdx;
                endIdx = endIdx - step;
                while (i != endIdx)
                {
                    int    j = i + step;
                    PointF p = Geometry.IntersectCircleWithLine(vertices[capPtIdx].X, vertices[capPtIdx].Y, capInset, vertices[i].X, vertices[i].Y, vertices[j].X, vertices[j].Y, true);
                    if (Geometry.IsValid(p) && Geometry.LineContainsPoint(vertices[i].X, vertices[i].Y, vertices[j].X, vertices[j].Y, false, p.X, p.Y))
                    {
                        result = Geometry.RadiansToDegrees(Geometry.Angle(vertices[capPtIdx].X, vertices[capPtIdx].Y, p.X, p.Y));
                    }
                    i = i + step;
                }
            }
            if (float.IsNaN(result))
            {
                result = Geometry.RadiansToDegrees(Geometry.Angle(vertices[capPtIdx].X, vertices[capPtIdx].Y, vertices[otherPtIdx].X, vertices[otherPtIdx].Y));
            }
            Debug.Assert(!float.IsNaN(result));
            return(result);
        }
示例#3
0
		private void DrawStyleItem(Graphics gfx, Rectangle previewBounds, ILineStyle lineStyle) {
			Pen linePen = ToolCache.GetPen(lineStyle, null, null);
			int height = lineStyle.LineWidth + 2;
			bool scalePen = (height > previewBounds.Height);
			if (scalePen) {
				float scale = Geometry.CalcScaleFactor(height, height, previewBounds.Width, previewBounds.Height);
				linePen.ScaleTransform(scale, scale);
			}
			gfx.DrawLine(linePen, previewBounds.X, previewBounds.Y + (previewBounds.Height / 2), previewBounds.Right, previewBounds.Y + (previewBounds.Height / 2));
			if (scalePen) linePen.ResetTransform();
		}
示例#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);
        }
示例#5
0
        /// <override></override>
        public override void DrawThumbnail(Image image, int margin, Color transparentColor)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            using (Graphics g = Graphics.FromImage(image)) {
                GdiHelpers.ApplyGraphicsSettings(g, RenderingQuality.MaximumQuality);
                g.Clear(transparentColor);

                int startCapSize = 0;
                if (StartCapStyleInternal != null && StartCapStyleInternal.CapShape != CapShape.None)
                {
                    startCapSize = StartCapStyleInternal.CapSize;
                }
                int endCapSize = 0;
                if (EndCapStyleInternal != null && EndCapStyleInternal.CapShape != CapShape.None)
                {
                    endCapSize = EndCapStyleInternal.CapSize;
                }

                int height, width;
                height = width = (int)Math.Max(startCapSize, endCapSize) * 4;
                if (height == 0 || width == 0)
                {
                    width  = image.Width;
                    height = image.Height;
                }
                g.ScaleTransform((float)image.Width / width, (float)image.Height / height);

                Point[] points = new Point[4] {
                    new Point(margin, height / 4),
                    new Point(width / 2, height / 4),
                    new Point(width / 2, height - (height / 4)),
                    new Point(width - margin, height - (height / 4))
                };

                Pen pen = ToolCache.GetPen(LineStyle, StartCapStyleInternal, EndCapStyleInternal);
                g.DrawLines(pen, points);
            }
        }
示例#6
0
        /// <override></override>
        public override void Draw(Graphics graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }
            UpdateDrawCache();
            int lastIdx = shapePoints.Length - 1;

            if (lastIdx > 0)
            {
                // draw Caps interior
                DrawStartCapBackground(graphics, shapePoints[0].X, shapePoints[0].Y);
                DrawEndCapBackground(graphics, shapePoints[lastIdx].X, shapePoints[lastIdx].Y);

                // draw Line
                Pen pen = ToolCache.GetPen(LineStyle, StartCapStyleInternal, EndCapStyleInternal);
                graphics.DrawLines(pen, shapePoints);

                // ToDo: If the line is connected to another line, draw a connection indicator (ein Bommel oder so)
                // ToDo: Add a property for enabling/disabling this feature
            }
            base.Draw(graphics);
        }
示例#7
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);
                }
            }
        }
示例#8
0
        public override void Draw(Graphics graphics)
        {
            Pen pen = ToolCache.GetPen(LineStyle, null, null);

            DrawOutline(graphics, pen);
        }