Exemple #1
0
        public override void Draw(PointF location)
        {
            if (IsTextVisible())
            {
                RectangleF drawRectangle = new RectangleF(location, AllocatedSize);
                Font       fnt           = new Font(tipFont, FontStyle.Bold);

                /*Graphics.DrawString(tipText.Substring(0,beg_bold), tipFont,
                 *                  BrushRegistry.GetBrush(Color),
                 *                  drawRectangle,
                 *                  GetInternalStringFormat());
                 * Graphics.DrawString(tipText.Substring(beg_bold,len_bold), fnt,
                 *                  BrushRegistry.GetBrush(Color),
                 *                  drawRectangle,
                 *                  GetInternalStringFormat());
                 * Graphics.DrawString(tipText.Substring(beg_bold+len_bold), tipFont,
                 *                  BrushRegistry.GetBrush(Color),
                 *                  drawRectangle,
                 *                  GetInternalStringFormat());*/
                if (this is CountTipText || is_doc)
                {
                    Graphics.DrawString(tipText, tipFont,
                                        BrushRegistry.GetBrush(Color),
                                        drawRectangle,
                                        GetInternalStringFormat());
                }
                else if (is_head)
                {
                    Graphics.DrawString(tipText, fnt,
                                        BrushRegistry.GetBrush(Color),
                                        drawRectangle,
                                        GetInternalStringFormatForHeader());
                }
                else if (param_name)
                {
                    drawRectangle.X += 10;
                    Graphics.DrawString(tipText, fnt,
                                        BrushRegistry.GetBrush(System.Drawing.Color.Brown),
                                        drawRectangle,
                                        GetInternalStringFormatForHeader());
                }
                else if (need_tab)
                {
                    if (param_desc)
                    {
                        drawRectangle.X += 20;
                    }
                    else
                    {
                        drawRectangle.X += 10;
                    }
                    Graphics.DrawString(tipText, tipFont,
                                        BrushRegistry.GetBrush(Color),
                                        drawRectangle,
                                        GetInternalStringFormat());
                }
                else
                {
                    SizeF szfull = Graphics.MeasureString(tipText, tipFont, new SizeF(drawRectangle.Width, drawRectangle.Height), GetInternalStringFormat());

                    SizeF sz1 = Graphics.MeasureString(tipText.Substring(0, beg_bold), tipFont, new SizeF(drawRectangle.Width, drawRectangle.Height), GetInternalStringFormat());
                    if (szfull.Height > sz1.Height + 3)
                    {
                        Graphics.DrawString(tipText, tipFont,
                                            BrushRegistry.GetBrush(Color),
                                            drawRectangle,
                                            GetInternalStringFormat());
                        return;
                    }
                    Graphics.DrawString(tipText.Substring(0, beg_bold), tipFont,
                                        BrushRegistry.GetBrush(Color),
                                        drawRectangle,
                                        GetInternalStringFormat());
                    SizeF sz2      = Graphics.MeasureString(tipText.Substring(beg_bold, len_bold), fnt, new SizeF(drawRectangle.Width, drawRectangle.Height), GetInternalStringFormat());
                    SizeF sz2_simp = Graphics.MeasureString(tipText.Substring(beg_bold, len_bold), tipFont, new SizeF(drawRectangle.Width, drawRectangle.Height), GetInternalStringFormat());
                    float x_coord  = drawRectangle.X;
                    float y_coord  = drawRectangle.Y;
                    if (sz1.Width + sz2.Width > drawRectangle.Width)
                    {
                        if (drawRectangle.Height > sz1.Height)
                        {
                            y_coord += sz1.Height;
                        }
                    }
                    else
                    {
                        x_coord += sz1.Width;
                    }
                    Graphics.DrawString(tipText.Substring(beg_bold, len_bold), fnt,
                                        BrushRegistry.GetBrush(Color),
                                        x_coord,
                                        y_coord,
                                        GetInternalStringFormat());
                    SizeF sz3 = Graphics.MeasureString(tipText.Substring(beg_bold + len_bold), tipFont, new SizeF(drawRectangle.Width, drawRectangle.Height), GetInternalStringFormat());
                    if (sz1.Width + sz2.Width + sz3.Width > drawRectangle.Width)
                    {
                        if (drawRectangle.Height > sz1.Height)
                        {
                            x_coord  = drawRectangle.X;
                            y_coord += sz2.Height;
                        }
                    }
                    else
                    {
                        x_coord += sz2.Width;
                    }
                    Graphics.DrawString(tipText.Substring(beg_bold + len_bold), tipFont,
                                        BrushRegistry.GetBrush(Color),
                                        x_coord,
                                        y_coord,
                                        GetInternalStringFormat());
                }
            }
        }
        public override void Paint(Graphics g, Rectangle rect)
        {
            var totalWidth = Size.Width;
            var leftWidth  = (int)(totalWidth / 2.0);
            var rightWidth = rect.Width - leftWidth;

            var fontHeight             = textArea.TextView.FontHeight;
            var lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers");
            var fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder;
            var drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color);

            for (var y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y)
            {
                var ypos = drawingPosition.Y + fontHeight * y - textArea.TextView.VisibleLineDrawingRemainder;
                var backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight);
                if (!rect.IntersectsWith(backgroundRectangle))
                {
                    continue;
                }
                g.FillRectangle(fillBrush, backgroundRectangle);
                var curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y);

                if (curLine >= textArea.Document.TotalNumberOfLines)
                {
                    continue;
                }
                if (!DiffLines.ContainsKey(curLine + 1))
                {
                    continue;
                }
                var diffLine = DiffLines[curLine + 1];
                if (diffLine.Style != DiffLineNum.DiffLineStyle.Context)
                {
                    var brush = default(Brush);
                    switch (diffLine.Style)
                    {
                    case DiffLineNum.DiffLineStyle.Plus:
                        brush = new SolidBrush(AppSettings.DiffAddedColor);
                        break;

                    case DiffLineNum.DiffLineStyle.Minus:
                        brush = new SolidBrush(AppSettings.DiffRemovedColor);
                        break;

                    case DiffLineNum.DiffLineStyle.Header:
                        brush = new SolidBrush(AppSettings.DiffSectionColor);
                        break;
                    }

                    Debug.Assert(brush != null, string.Format("brush != null, unknow diff line style {0}", diffLine.Style));
                    g.FillRectangle(brush, new Rectangle(0, backgroundRectangle.Top, leftWidth, backgroundRectangle.Height));

                    g.FillRectangle(brush, new Rectangle(leftWidth, backgroundRectangle.Top, rightWidth, backgroundRectangle.Height));
                }
                if (diffLine.LeftLineNum != DiffLineNum.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.LeftLineNum.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(TextHorizontalMargin, backgroundRectangle.Top));
                }

                if (diffLine.RightLineNum != DiffLineNum.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.RightLineNum.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(TextHorizontalMargin + totalWidth / 2, backgroundRectangle.Top));
                }
            }
        }
Exemple #3
0
        public override void Paint(Graphics g, Rectangle rect)
        {
            var numbersWidth = Width - TextHorizontalMargin;
            var leftWidth    = TextHorizontalMargin + (numbersWidth / 2);
            var rightWidth   = rect.Width - leftWidth;

            var fontHeight             = textArea.TextView.FontHeight;
            var lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers");
            var fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder;
            var drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color);

            for (var y = 0; y < ((DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight) + 1; ++y)
            {
                var       ypos = drawingPosition.Y + (fontHeight * y) - textArea.TextView.VisibleLineDrawingRemainder;
                Rectangle backgroundRectangle = new(drawingPosition.X, ypos, drawingPosition.Width, fontHeight);
                if (!rect.IntersectsWith(backgroundRectangle))
                {
                    continue;
                }

                g.FillRectangle(fillBrush, backgroundRectangle);
                var curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y);

                if (curLine >= textArea.Document.TotalNumberOfLines)
                {
                    continue;
                }

                if (!_diffLines.ContainsKey(curLine + 1))
                {
                    continue;
                }

                var diffLine = _diffLines[curLine + 1];
                if (diffLine.LineType != DiffLineType.Context)
                {
                    using Brush brush = diffLine.LineType switch
                          {
                              DiffLineType.Plus => new SolidBrush(AppColor.DiffAdded.GetThemeColor()),
                              DiffLineType.Minus => new SolidBrush(AppColor.DiffRemoved.GetThemeColor()),
                              DiffLineType.Header => new SolidBrush(AppColor.DiffSection.GetThemeColor()),
                              _ => default(Brush)
                          };

                    Debug.Assert(brush is not null, string.Format("brush is not null, unknow diff line style {0}", diffLine.LineType));
                    g.FillRectangle(brush, new Rectangle(0, backgroundRectangle.Top, leftWidth, backgroundRectangle.Height));
                    g.FillRectangle(brush, new Rectangle(leftWidth, backgroundRectangle.Top, rightWidth, backgroundRectangle.Height));
                }

                if (diffLine.LeftLineNumber != DiffLineInfo.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.LeftLineNumber.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(TextHorizontalMargin, backgroundRectangle.Top));
                }

                if (diffLine.RightLineNumber != DiffLineInfo.NotApplicableLineNum)
                {
                    g.DrawString(diffLine.RightLineNumber.ToString(),
                                 lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer),
                                 drawBrush,
                                 new Point(leftWidth, backgroundRectangle.Top));
                }
            }
        }