public void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = Shared.TEP.LineNumbersColor; int fontHeight = TextArea._FontHeight; Brush fillBrush = TextArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder; Brush drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color); for (int y = 0; y < (DrawingPosition.Height + TextArea.VisibleLineDrawingRemainder) / fontHeight + 1; ++y) { int ypos = DrawingPosition.Y + fontHeight * y - TextArea.VisibleLineDrawingRemainder; Rectangle backgroundRectangle = new Rectangle(DrawingPosition.X, ypos, DrawingPosition.Width, fontHeight); if (rect.IntersectsWith(backgroundRectangle)) { g.FillRectangle(fillBrush, backgroundRectangle); int curLine = TextArea.Document.GetFirstLogicalLine(TextArea.Document.GetVisibleLine(TextArea.FirstVisibleLine) + y); if (curLine < TextArea.Document.TotalNumberOfLines) { g.DrawString((curLine + 1).ToString(), FontRegistry.GetFont(lineNumberPainterColor.Bold, lineNumberPainterColor.Italic), drawBrush, backgroundRectangle, _numberStringFormat); } } } }
void DrawFoldMarker(Graphics g, RectangleF rectangle, bool isOpened, bool isSelected) { HighlightColor foldMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("FoldMarker"); HighlightColor foldLineColor = textArea.Document.HighlightingStrategy.GetColorFor("FoldLine"); HighlightColor selectedFoldLine = textArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine"); Rectangle intRect = new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height); g.FillRectangle(BrushRegistry.GetBrush(foldMarkerColor.BackgroundColor), intRect); g.DrawRectangle(BrushRegistry.GetPen(isSelected ? selectedFoldLine.Color : foldLineColor.Color), intRect); int space = (int)Math.Round(((double)rectangle.Height) / 8d) + 1; int mid = intRect.Height / 2 + intRect.Height % 2; // draw minus g.DrawLine(BrushRegistry.GetPen(foldMarkerColor.Color), rectangle.X + space, rectangle.Y + mid, rectangle.X + rectangle.Width - space, rectangle.Y + mid); // draw plus if (!isOpened) { g.DrawLine(BrushRegistry.GetPen(foldMarkerColor.Color), rectangle.X + mid, rectangle.Y + space, rectangle.X + mid, rectangle.Y + rectangle.Height - space); } }
public override void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); int fontHeight = textArea.TextView.FontHeight; Brush fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder; Brush drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color); for (int y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y) { int ypos = drawingPosition.Y + fontHeight * y - textArea.TextView.VisibleLineDrawingRemainder; Rectangle backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight); if (rect.IntersectsWith(backgroundRectangle)) { g.FillRectangle(fillBrush, backgroundRectangle); int curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y); if (curLine < textArea.Document.TotalNumberOfLines) { g.DrawString((curLine + 1).ToString(), lineNumberPainterColor.Font, drawBrush, backgroundRectangle, numberStringFormat); } } } }
public override void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); for (int y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / textArea.TextView.FontHeight + 1; ++y) { Rectangle markerRectangle = new Rectangle(DrawingPosition.X, DrawingPosition.Top + y * textArea.TextView.FontHeight - textArea.TextView.VisibleLineDrawingRemainder, DrawingPosition.Width, textArea.TextView.FontHeight); if (rect.IntersectsWith(markerRectangle)) { // draw dotted separator line if (textArea.Document.TextEditorProperties.ShowLineNumbers) { g.FillRectangle(BrushRegistry.GetBrush(textArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), markerRectangle); g.DrawLine(BrushRegistry.GetDotPen(lineNumberPainterColor.Color), drawingPosition.X, markerRectangle.Y, drawingPosition.X, markerRectangle.Bottom); } else { g.FillRectangle(BrushRegistry.GetBrush(textArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), markerRectangle); } int currentLine = textArea.Document.GetFirstLogicalLine(textArea.TextView.FirstPhysicalLine + y); if (currentLine < textArea.Document.TotalNumberOfLines) { PaintFoldMarker(g, currentLine, markerRectangle); } } } }
Brush GetBgColorBrush(int lineNumber) { if (DrawLineMarkerAtLine(lineNumber)) { HighlightColor caretLine = textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker"); return(BrushRegistry.GetBrush(caretLine.Color)); } HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("Default"); return(BrushRegistry.GetBrush(background.BackgroundColor)); }
private Brush GetBgColorBrush(int lineNumber) { if (this.DrawLineMarkerAtLine(lineNumber)) { HighlightColor colorFor = this.textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker"); return(BrushRegistry.GetBrush(colorFor.Color)); } HighlightColor highlightColor = this.textArea.Document.HighlightingStrategy.GetColorFor("Default"); return(BrushRegistry.GetBrush(highlightColor.BackgroundColor)); }
public static float DrawDocumentWord(Graphics g, string word, PointF position, Font font, Color foreColor) { if (word == null || word.Length == 0) { return(0f); } SizeF sizeF = g.MeasureString(word, font, 32768, DrawableLine.sf); g.DrawString(word, font, BrushRegistry.GetBrush(foreColor), position, DrawableLine.sf); return(sizeF.Width); }
float DrawEOLMarker(Graphics g, Color color, Brush backBrush, float x, float y) { float width = GetWidth(g, '\u00B6'); g.FillRectangle(backBrush, new RectangleF(x, y, width, fontHeight)); HighlightColor eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EOLMarkers"); g.DrawString("\u00B6", eolMarkerColor.Font, BrushRegistry.GetBrush(color), x, y, measureStringFormat); return(width); }
/// <summary> /// Get the marker brush (for solid block markers) at a given position. /// </summary> /// <param name="offset">The offset.</param> /// <param name="length">The length.</param> /// <param name="markers">All markers that have been found.</param> /// <returns>The Brush or null when no marker was found.</returns> Brush GetMarkerBrushAt(int offset, int length, out ArrayList markers) { markers = Document.MarkerStrategy.GetMarkers(offset, length); foreach (TextMarker marker in markers) { if (marker.TextMarkerType == TextMarkerType.SolidBlock) { return(BrushRegistry.GetBrush(marker.Color)); } } return(null); }
public static float DrawDocumentWord(Graphics g, string word, PointF position, Font font, Color foreColor) { if (string.IsNullOrEmpty(word)) { return(0f); } SizeF wordSize = g.MeasureString(word, font, 32768, sf); g.DrawString(word, font, BrushRegistry.GetBrush(foreColor), position, sf); return(wordSize.Width); }
private int PaintFoldingText(Graphics g, int lineNumber, int physicalXPos, Rectangle lineRectangle, string text, bool drawSelected) { HighlightColor colorFor = this.textArea.Document.HighlightingStrategy.GetColorFor("Selection"); Brush brush = (drawSelected ? BrushRegistry.GetBrush(colorFor.BackgroundColor) : this.GetBgColorBrush(lineNumber)); Brush brush1 = (this.textArea.Enabled ? brush : SystemBrushes.InactiveBorder); Font regularFont = this.textArea.TextEditorProperties.FontContainer.RegularFont; int num = this.MeasureStringWidth(g, text, regularFont) + 1; Rectangle rectangle = new Rectangle(physicalXPos, lineRectangle.Y, num, lineRectangle.Height - 1); g.FillRectangle(brush1, rectangle); this.physicalColumn += text.Length; this.DrawString(g, text, regularFont, (drawSelected ? colorFor.Color : Color.Gray), rectangle.X + 1, rectangle.Y); g.DrawRectangle(BrushRegistry.GetPen((drawSelected ? Color.DarkGray : Color.Gray)), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); return(physicalXPos + num + 1); }
public override void PaintCaret(Graphics g) { if (blink && visible) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; if (parentCaret.CaretMode == CaretMode.OverwriteMode) { g.FillRectangle(BrushRegistry.GetBrush((this.textArea.TextEditorProperties.DarkScheme) ? Color.FromArgb(160, 255, 255, 255) : Color.FromArgb(144, 0, 0, 0)), x + 1, y, width, height); } else { g.DrawRectangle((this.textArea.TextEditorProperties.DarkScheme) ? Pens.White : Pens.Black, x, y, width - 1, height); } } }
Brush GetBgColorBrush(int lineNumber) { if (DrawLineMarkerAtLine(lineNumber)) { HighlightColor caretLine = textArea.Document.HighlightingStrategy.GetColorFor("CaretMarker"); return(BrushRegistry.GetBrush(caretLine.Color)); } HighlightBackground background = (HighlightBackground)textArea.Document.HighlightingStrategy.GetColorFor("DefaultBackground"); Color bgColor = background.BackgroundColor; if (textArea.MotherTextAreaControl.TextEditorProperties.UseCustomLine == true) { bgColor = textArea.Document.CustomLineManager.GetCustomColor(lineNumber, bgColor); } return(BrushRegistry.GetBrush(bgColor)); }
public override void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); int fontHeight = textArea.TextView.FontHeight; Brush fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder; Brush drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color); for (int y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y) { int ypos = drawingPosition.Y + fontHeight * y - textArea.TextView.VisibleLineDrawingRemainder; Rectangle backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight); if (rect.IntersectsWith(backgroundRectangle)) { g.FillRectangle(fillBrush, backgroundRectangle); int curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y); if (curLine < textArea.Document.TotalNumberOfLines) { g.DrawString((curLine + 1).ToString(), lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer), drawBrush, backgroundRectangle, numberStringFormat); if (textArea.Document.LineSegmentCollection[curLine].State == LineState.Modified) { g.FillRectangle(BrushRegistry.GetBrush(Color.FromArgb(255, 238, 98)), backgroundRectangle.Width + backgroundRectangle.X - 4, backgroundRectangle.Y, 4, backgroundRectangle.Height); } else if (textArea.Document.LineSegmentCollection[curLine].State == LineState.Saved) { g.FillRectangle(BrushRegistry.GetBrush(Color.FromArgb(108, 226, 108)), backgroundRectangle.Width + backgroundRectangle.X - 4, backgroundRectangle.Y, 4, backgroundRectangle.Height); } } } } //g.FillRectangle(BrushRegistry.GetBrush(Color.Black), rect); }
///// void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin) { g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; float xPos = 0.0f; FontContainer fontContainer = _editor.TextEditorProperties.FontContainer; foreach (TextWord word in line.Words) { switch (word.Type) { case TextWordType.Space: case TextWordType.Tab: //TODO2 this blows up throw new NotImplementedException(); case TextWordType.Word: Font f = word.GetFont(fontContainer); // Check for run off side of page. // Note that MeasureString does not count the same way as DrawString but should be close enough. float reqWidth = _xSpace * word.Word.Length; if (xPos + reqWidth > margin.Width) { Advance(ref xPos, ref yPos, margin.Width, reqWidth, _ySpace); } // Print word one letter at a time to control spacing. for (int i = 0; i < word.Word.Length; i++) { // If bg is not "white" draw a colored rectangle first. if (word.SyntaxColor.BackgroundColor != _hcDef.BackgroundColor) { g.FillRectangle(BrushRegistry.GetBrush(word.SyntaxColor.BackgroundColor), xPos + margin.X + 2.0f, yPos, _xSpace, f.Height); // have to add 2.0 to start to make bg work?!? } g.DrawString(new string(word.Word[i], 1), f, BrushRegistry.GetBrush(word.SyntaxColor.Color), xPos + margin.X, yPos); xPos += _xSpace; } break; } } }
private void DrawFoldMarker(Graphics g, RectangleF rectangle, bool isOpened, bool isSelected) { HighlightColor colorFor = this.textArea.Document.HighlightingStrategy.GetColorFor("FoldMarker"); HighlightColor highlightColor = this.textArea.Document.HighlightingStrategy.GetColorFor("FoldLine"); HighlightColor colorFor1 = this.textArea.Document.HighlightingStrategy.GetColorFor("SelectedFoldLine"); Rectangle rectangle1 = new Rectangle((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height); g.FillRectangle(BrushRegistry.GetBrush(colorFor.BackgroundColor), rectangle1); g.DrawRectangle(BrushRegistry.GetPen((isSelected ? colorFor1.Color : highlightColor.Color)), rectangle1); int num = (int)Math.Round((double)rectangle.Height / 8) + 1; int height = rectangle1.Height / 2 + rectangle1.Height % 2; g.DrawLine(BrushRegistry.GetPen(colorFor.Color), rectangle.X + (float)num, rectangle.Y + (float)height, rectangle.X + rectangle.Width - (float)num, rectangle.Y + (float)height); if (!isOpened) { g.DrawLine(BrushRegistry.GetPen(colorFor.Color), rectangle.X + (float)height, rectangle.Y + (float)num, rectangle.X + (float)height, rectangle.Y + rectangle.Height - (float)num); } }
private void DrawMarkerDraw(Graphics g) { foreach (TextView.MarkerToDraw markerToDraw in this.markersToDraw) { TextMarker textMarker = markerToDraw.marker; RectangleF rectangleF = markerToDraw.drawingRect; float bottom = rectangleF.Bottom - 1f; switch (textMarker.TextMarkerType) { case TextMarkerType.SolidBlock: { g.FillRectangle(BrushRegistry.GetBrush(textMarker.Color), rectangleF); continue; } case TextMarkerType.Underlined: { g.DrawLine(BrushRegistry.GetPen(textMarker.Color), rectangleF.X, bottom, rectangleF.Right, bottom); continue; } case TextMarkerType.WaveLine: { int x = (int)rectangleF.X % 6; for (float i = (float)((int)rectangleF.X - x); i < rectangleF.Right; i += 6f) { g.DrawLine(BrushRegistry.GetPen(textMarker.Color), i, bottom + 3f - 4f, i + 3f, bottom + 1f - 4f); if (i + 3f < rectangleF.Right) { g.DrawLine(BrushRegistry.GetPen(textMarker.Color), i + 3f, bottom + 1f - 4f, i + 6f, bottom + 3f - 4f); } } continue; } default: { continue; } } } this.markersToDraw.Clear(); }
void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin) { float xPos = 0; float fontHeight = Font.GetHeight(g); bool gotNonWhitespace = false; curTabIndent = 0; FontContainer fontContainer = TextEditorProperties.FontContainer; foreach (TextWord word in line.Words) { switch (word.Type) { case TextWordType.Space: Advance(ref xPos, ref yPos, margin.Width, primaryTextArea.TextArea.TextView.SpaceWidth, fontHeight); if (!gotNonWhitespace) { curTabIndent = xPos; } break; case TextWordType.Tab: Advance(ref xPos, ref yPos, margin.Width, TabIndent * primaryTextArea.TextArea.TextView.WideSpaceWidth, fontHeight); if (!gotNonWhitespace) { curTabIndent = xPos; } break; case TextWordType.Word: if (!gotNonWhitespace) { gotNonWhitespace = true; // curTabIndent += TabIndent * primaryTextArea.TextArea.TextView.GetWidth(' '); } g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), xPos + margin.X, yPos); SizeF drawingSize = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, fontHeight * 100), printingStringFormat); Advance(ref xPos, ref yPos, margin.Width, drawingSize.Width, fontHeight); break; } } }
float DrawDocumentWord(Graphics g, string word, PointF position, Font font, Color foreColor, Brush backBrush) { if (word == null || word.Length == 0) { return(0f); } float wordWidth = g.MeasureString(word, font, 32768, measureStringFormat).Width; g.FillRectangle(backBrush, new RectangleF(position.X, position.Y, (float)Math.Ceiling(wordWidth), FontHeight)); g.DrawString(word, font, BrushRegistry.GetBrush(foreColor), position.X, position.Y, measureStringFormat); return(wordWidth); }
public override void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); int fontHeight = textArea.TextView.FontHeight; Brush fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder; Brush drawBrush = BrushRegistry.GetBrush(lineNumberPainterColor.Color); //行番号を右揃えにするためのフォーマット作成 int figure = textArea.Document.TotalNumberOfLines.ToString().Length + 1; //一つ多めにする string format = "{0, " + figure.ToString() + "}"; for (int y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y) { int ypos = drawingPosition.Y + fontHeight * y - textArea.TextView.VisibleLineDrawingRemainder; Rectangle backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight); if (rect.IntersectsWith(backgroundRectangle)) { g.FillRectangle(fillBrush, backgroundRectangle); int curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y); if (curLine < textArea.Document.TotalNumberOfLines) { g.DrawString(String.Format(format, curLine + 1), lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer), drawBrush, backgroundRectangle, numberStringFormat); //g.DrawString((curLine + 1).ToString(), // lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer), // drawBrush, // backgroundRectangle, // numberStringFormat); } } } }
public override void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = textArea.Document.HighlightingStrategy.GetColorFor("LineNumbers"); int fontHeight = textArea.TextView.FontHeight; Brush fillBrush = textArea.Enabled ? BrushRegistry.GetBrush(lineNumberPainterColor.BackgroundColor) : SystemBrushes.InactiveBorder; Font lineFont = lineNumberPainterColor.GetFont(TextEditorProperties.FontContainer); for (int y = 0; y < (DrawingPosition.Height + textArea.TextView.VisibleLineDrawingRemainder) / fontHeight + 1; ++y) { int ypos = drawingPosition.Y + fontHeight * y - textArea.TextView.VisibleLineDrawingRemainder; Rectangle backgroundRectangle = new Rectangle(drawingPosition.X, ypos, drawingPosition.Width, fontHeight); //if (rect.IntersectsWith(backgroundRectangle)) { g.FillRectangle(fillBrush, backgroundRectangle); int curLine = textArea.Document.GetFirstLogicalLine(textArea.Document.GetVisibleLine(textArea.TextView.FirstVisibleLine) + y); if (curLine < textArea.Document.TotalNumberOfLines) { Brush drawBrush = (curLine != textArea.Caret.Line) ? BrushRegistry.GetBrush(lineNumberPainterColor.Color) : drawBrush = BrushRegistry.GetBrush((textArea.Document.TextEditorProperties.DarkScheme) ? Color.Gold : Color.Blue); g.DrawString((curLine + 1).ToString(), lineFont, drawBrush, backgroundRectangle, numberStringFormat); } //} } if (!textArea.Document.TextEditorProperties.EnableFolding) { g.DrawLine(BrushRegistry.GetPen(lineNumberPainterColor.Color), rect.X + Size.Width - 3, rect.Y, rect.X + Size.Width - 3, rect.Bottom); } }
private void DrawLine(Graphics g, LineSegment line, float yPos, RectangleF margin) { float single = 0f; float height = this.Font.GetHeight(g); this.curTabIndent = 0f; FontContainer fontContainer = base.TextEditorProperties.FontContainer; foreach (TextWord word in line.Words) { switch (word.Type) { case TextWordType.Word: { g.DrawString(word.Word, word.GetFont(fontContainer), BrushRegistry.GetBrush(word.Color), single + margin.X, yPos); SizeF sizeF = g.MeasureString(word.Word, word.GetFont(fontContainer), new SizeF(margin.Width, height * 100f), this.printingStringFormat); this.Advance(ref single, ref yPos, margin.Width, sizeF.Width, height); continue; } case TextWordType.Space: { this.Advance(ref single, ref yPos, margin.Width, (float)this.primaryTextArea.TextArea.TextView.SpaceWidth, height); continue; } case TextWordType.Tab: { this.Advance(ref single, ref yPos, margin.Width, (float)(base.TabIndent * this.primaryTextArea.TextArea.TextView.WideSpaceWidth), height); continue; } default: { continue; } } } }
public void Paint(Graphics g, Rectangle rect) { if (rect.Width <= 0 || rect.Height <= 0) { return; } HighlightColor lineNumberPainterColor = Shared.TEP.LineNumbersColor; for (int y = 0; y < (DrawingPosition.Height + TextArea.VisibleLineDrawingRemainder) / TextArea._FontHeight + 1; ++y) { Rectangle markerRectangle = new Rectangle(DrawingPosition.X, DrawingPosition.Top + y * TextArea._FontHeight - TextArea.VisibleLineDrawingRemainder, DrawingPosition.Width, TextArea._FontHeight); if (rect.IntersectsWith(markerRectangle)) { // draw dotted separator line if (Shared.TEP.ShowLineNumbers) { g.FillRectangle(BrushRegistry.GetBrush(TextArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), markerRectangle); g.DrawLine(BrushRegistry.GetDotPen(lineNumberPainterColor.Color), DrawingPosition.X, markerRectangle.Y, DrawingPosition.X, markerRectangle.Bottom); } else { g.FillRectangle(BrushRegistry.GetBrush(TextArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), markerRectangle); } int currentLine = TextArea.Document.GetFirstLogicalLine(TextArea.FirstPhysicalLine + y); if (currentLine < TextArea.Document.TotalNumberOfLines) { PaintFoldMarker(g, currentLine, markerRectangle); } } } }
void DrawMarker(Graphics g, TextMarker marker, RectangleF drawingRect) { float drawYPos = drawingRect.Bottom - 1; switch (marker.TextMarkerType) { case TextMarkerType.Underlined: g.DrawLine(BrushRegistry.GetPen(marker.Color), drawingRect.X, drawYPos, drawingRect.Right, drawYPos); break; case TextMarkerType.WaveLine: int reminder = ((int)drawingRect.X) % 6; for (float i = drawingRect.X - reminder; i < drawingRect.Right + reminder; i += 6) { g.DrawLine(BrushRegistry.GetPen(marker.Color), i, drawYPos + 3 - 4, i + 3, drawYPos + 1 - 4); g.DrawLine(BrushRegistry.GetPen(marker.Color), i + 3, drawYPos + 1 - 4, i + 6, drawYPos + 3 - 4); } break; case TextMarkerType.SolidBlock: g.FillRectangle(BrushRegistry.GetBrush(marker.Color), drawingRect); break; } }
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e) { //横定規はエディタのデフォルト値を使用する HighlightColor color = textArea.Document.HighlightingStrategy.GetColorFor("Default"); int x = 0; if (textArea.TextEditorProperties.IsIconBarVisible) { x = textArea.IconBarMargin.DrawingPosition.Width; if (x != 0) { //アイコン表示領域が存在するときはその部分を描画する e.Graphics.FillRectangle(BrushRegistry.GetBrush(SystemColors.Control), new Rectangle(0, 0, x, Height)); e.Graphics.DrawLine(SystemPens.ControlDark, x - 1, 0, x - 1, Height); } } e.Graphics.FillRectangle(BrushRegistry.GetBrush(color.BackgroundColor), new Rectangle(x, 0, Width, Height)); }
float PaintLinePart(Graphics g, int lineNumber, int startColumn, int endColumn, Rectangle lineRectangle, float physicalXPos) { bool drawLineMarker = DrawLineMarkerAtLine(lineNumber); Brush bgColorBrush = GetBgColorBrush(lineNumber); Brush backgroundBrush = textArea.Enabled ? bgColorBrush : SystemBrushes.InactiveBorder; HighlightColor selectionColor = textArea.Document.HighlightingStrategy.GetColorFor("Selection"); ColumnRange selectionRange = textArea.SelectionManager.GetSelectionAtLine(lineNumber); HighlightColor tabMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("TabMarkers"); HighlightColor spaceMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("SpaceMarkers"); float spaceWidth = GetWidth(g, ' '); LineSegment currentLine = textArea.Document.GetLineSegment(lineNumber); int logicalColumn = startColumn; Brush selectionBackgroundBrush = BrushRegistry.GetBrush(selectionColor.BackgroundColor); Brush unselectedBackgroundBrush = backgroundBrush; if (currentLine.Words != null) { int startword = 0; // search the first word after startColumn and update physicalColumn if a word is Tab int wordOffset = 0; for (; startword < currentLine.Words.Count; ++startword) { if (wordOffset >= startColumn) { break; } TextWord currentWord = ((TextWord)currentLine.Words[startword]); if (currentWord.Type == TextWordType.Tab) { ++wordOffset; } else if (currentWord.Type == TextWordType.Space) { ++wordOffset; } else { wordOffset += currentWord.Length; } } for (int i = startword; i < currentLine.Words.Count; ++i) { // if already all words before endColumn are drawen: break if (logicalColumn >= endColumn) { break; } ArrayList markers = Document.MarkerStrategy.GetMarkers(currentLine.Offset + wordOffset); foreach (TextMarker marker in markers) { if (marker.TextMarkerType == TextMarkerType.SolidBlock) { // if (unselectedBackgroundBrush != null) { // unselectedBackgroundBrush.Dispose(); // } unselectedBackgroundBrush = BrushRegistry.GetBrush(marker.Color); break; } } // Clear old marker arrary // TODO: cut the word if startColumn or endColimn is in the word; // needed for foldings wich can start or end in the middle of a word TextWord currentWord = ((TextWord)currentLine.Words[i]); switch (currentWord.Type) { case TextWordType.Space: RectangleF spaceRectangle = new RectangleF(physicalXPos, lineRectangle.Y, (float)Math.Ceiling(spaceWidth), lineRectangle.Height); Brush spaceBackgroundBrush; if (ColumnRange.WholeColumn.Equals(selectionRange) || logicalColumn >= selectionRange.StartColumn && logicalColumn < selectionRange.EndColumn) { spaceBackgroundBrush = selectionBackgroundBrush; } else { Brush markerBrush = GetMarkerBrushAt(currentLine.Offset + logicalColumn, 1); if (!drawLineMarker && markerBrush != null) { spaceBackgroundBrush = markerBrush; } else if (!drawLineMarker && currentWord.SyntaxColor != null && currentWord.SyntaxColor.HasBackground) { spaceBackgroundBrush = BrushRegistry.GetBrush(currentWord.SyntaxColor.BackgroundColor); } else { spaceBackgroundBrush = unselectedBackgroundBrush; } } g.FillRectangle(spaceBackgroundBrush, spaceRectangle); if (TextEditorProperties.ShowSpaces) { DrawSpaceMarker(g, spaceMarkerColor.Color, physicalXPos, lineRectangle.Y); } foreach (TextMarker marker in markers) { DrawMarker(g, marker, spaceRectangle); } physicalXPos += spaceWidth; ++logicalColumn; ++physicalColumn; break; case TextWordType.Tab: int oldPhysicalColumn = physicalColumn; physicalColumn += TextEditorProperties.TabIndent; physicalColumn = (physicalColumn / TextEditorProperties.TabIndent) * TextEditorProperties.TabIndent; float tabWidth = (physicalColumn - oldPhysicalColumn) * spaceWidth; RectangleF tabRectangle = new RectangleF(physicalXPos, lineRectangle.Y, (float)Math.Ceiling(tabWidth), lineRectangle.Height); if (ColumnRange.WholeColumn.Equals(selectionRange) || logicalColumn >= selectionRange.StartColumn && logicalColumn <= selectionRange.EndColumn - 1) { spaceBackgroundBrush = selectionBackgroundBrush; } else { Brush markerBrush = GetMarkerBrushAt(currentLine.Offset + logicalColumn, 1); if (!drawLineMarker && markerBrush != null) { spaceBackgroundBrush = markerBrush; } else if (!drawLineMarker && currentWord.SyntaxColor != null && currentWord.SyntaxColor.HasBackground) { spaceBackgroundBrush = BrushRegistry.GetBrush(currentWord.SyntaxColor.BackgroundColor); } else { spaceBackgroundBrush = unselectedBackgroundBrush; } } g.FillRectangle(spaceBackgroundBrush, tabRectangle); if (TextEditorProperties.ShowTabs) { DrawTabMarker(g, tabMarkerColor.Color, physicalXPos, lineRectangle.Y); } foreach (TextMarker marker in markers) { DrawMarker(g, marker, tabRectangle); } physicalXPos += tabWidth; ++logicalColumn; break; case TextWordType.Word: string word = currentWord.Word; float lastPos = physicalXPos; Brush bgMarkerBrush = GetMarkerBrushAt(currentLine.Offset + logicalColumn, word.Length); Brush wordBackgroundBrush; if (!drawLineMarker && bgMarkerBrush != null) { wordBackgroundBrush = bgMarkerBrush; } else if (!drawLineMarker && currentWord.SyntaxColor.HasBackground) { wordBackgroundBrush = BrushRegistry.GetBrush(currentWord.SyntaxColor.BackgroundColor); } else { wordBackgroundBrush = unselectedBackgroundBrush; } if (ColumnRange.WholeColumn.Equals(selectionRange) || selectionRange.EndColumn - 1 >= word.Length + logicalColumn && selectionRange.StartColumn <= logicalColumn) { physicalXPos += DrawDocumentWord(g, word, new PointF(physicalXPos, lineRectangle.Y), currentWord.Font, selectionColor.HasForgeground ? selectionColor.Color : currentWord.Color, selectionBackgroundBrush); } else { if (ColumnRange.NoColumn.Equals(selectionRange) /* || selectionRange.StartColumn > logicalColumn + word.Length || selectionRange.EndColumn - 1 <= logicalColumn */) { physicalXPos += DrawDocumentWord(g, word, new PointF(physicalXPos, lineRectangle.Y), currentWord.Font, currentWord.Color, wordBackgroundBrush); } else { int offset1 = Math.Min(word.Length, Math.Max(0, selectionRange.StartColumn - logicalColumn)); int offset2 = Math.Max(offset1, Math.Min(word.Length, selectionRange.EndColumn - logicalColumn)); physicalXPos += DrawDocumentWord(g, word.Substring(0, offset1), new PointF(physicalXPos, lineRectangle.Y), currentWord.Font, currentWord.Color, wordBackgroundBrush); physicalXPos += DrawDocumentWord(g, word.Substring(offset1, offset2 - offset1), new PointF(physicalXPos, lineRectangle.Y), currentWord.Font, selectionColor.HasForgeground ? selectionColor.Color : currentWord.Color, selectionBackgroundBrush); physicalXPos += DrawDocumentWord(g, word.Substring(offset2), new PointF(physicalXPos, lineRectangle.Y), currentWord.Font, currentWord.Color, wordBackgroundBrush); } } // if (markerBrush != null) { // markerBrush.Dispose(); // } foreach (TextMarker marker in markers) { if (marker.TextMarkerType != TextMarkerType.SolidBlock) { DrawMarker(g, marker, new RectangleF(lastPos, lineRectangle.Y, (physicalXPos - lastPos), lineRectangle.Height)); } } // draw bracket highlight if (highlight != null) { if (highlight.OpenBrace.Y == lineNumber && highlight.OpenBrace.X == logicalColumn || highlight.CloseBrace.Y == lineNumber && highlight.CloseBrace.X == logicalColumn) { DrawBracketHighlight(g, new Rectangle((int)lastPos, lineRectangle.Y, (int)(physicalXPos - lastPos) - 1, lineRectangle.Height - 1)); } } physicalColumn += word.Length; logicalColumn += word.Length; break; } markers.Clear(); } } // if (bgColorBrush != null) { // bgColorBrush.Dispose(); // bgColorBrush = null; // } // // if (selectionBackgroundBrush != null) { // selectionBackgroundBrush.Dispose(); // selectionBackgroundBrush = null; // } // // if (unselectedBackgroundBrush != null) { // unselectedBackgroundBrush.Dispose(); // unselectedBackgroundBrush = null; // } return(physicalXPos); }
void PaintDocumentLine(Graphics g, int lineNumber, Rectangle lineRectangle) { Debug.Assert(lineNumber >= 0); Brush bgColorBrush = GetBgColorBrush(lineNumber); Brush backgroundBrush = textArea.Enabled ? bgColorBrush : SystemBrushes.InactiveBorder; if (lineNumber >= textArea.Document.TotalNumberOfLines) { g.FillRectangle(backgroundBrush, lineRectangle); if (TextEditorProperties.ShowInvalidLines) { DrawInvalidLineMarker(g, lineRectangle.Left, lineRectangle.Top); } if (TextEditorProperties.ShowVerticalRuler) { DrawVerticalRuler(g, lineRectangle); } // bgColorBrush.Dispose(); return; } float physicalXPos = lineRectangle.X; // there can't be a folding wich starts in an above line and ends here, because the line is a new one, // there must be a return before this line. int column = 0; physicalColumn = 0; if (TextEditorProperties.EnableFolding) { while (true) { ArrayList starts = textArea.Document.FoldingManager.GetFoldedFoldingsWithStartAfterColumn(lineNumber, column - 1); if (starts == null || starts.Count <= 0) { if (lineNumber < textArea.Document.TotalNumberOfLines) { physicalXPos = PaintLinePart(g, lineNumber, column, textArea.Document.GetLineSegment(lineNumber).Length, lineRectangle, physicalXPos); } break; } // search the first starting folding FoldMarker firstFolding = (FoldMarker)starts[0]; foreach (FoldMarker fm in starts) { if (fm.StartColumn < firstFolding.StartColumn) { firstFolding = fm; } } starts.Clear(); physicalXPos = PaintLinePart(g, lineNumber, column, firstFolding.StartColumn, lineRectangle, physicalXPos); column = firstFolding.EndColumn; lineNumber = firstFolding.EndLine; ColumnRange selectionRange2 = textArea.SelectionManager.GetSelectionAtLine(lineNumber); bool drawSelected = ColumnRange.WholeColumn.Equals(selectionRange2) || firstFolding.StartColumn >= selectionRange2.StartColumn && firstFolding.EndColumn <= selectionRange2.EndColumn; physicalXPos = PaintFoldingText(g, lineNumber, physicalXPos, lineRectangle, firstFolding.FoldText, drawSelected); } } else { physicalXPos = PaintLinePart(g, lineNumber, 0, textArea.Document.GetLineSegment(lineNumber).Length, lineRectangle, physicalXPos); } if (lineNumber < textArea.Document.TotalNumberOfLines) { // Paint things after end of line ColumnRange selectionRange = textArea.SelectionManager.GetSelectionAtLine(lineNumber); LineSegment currentLine = textArea.Document.GetLineSegment(lineNumber); HighlightColor selectionColor = textArea.Document.HighlightingStrategy.GetColorFor("Selection"); float spaceWidth = GetWidth(g, ' '); bool selectionBeyondEOL = selectionRange.EndColumn > currentLine.Length || ColumnRange.WholeColumn.Equals(selectionRange); if (TextEditorProperties.ShowEOLMarker) { HighlightColor eolMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("EOLMarkers"); physicalXPos += DrawEOLMarker(g, eolMarkerColor.Color, selectionBeyondEOL ? bgColorBrush : backgroundBrush, physicalXPos, lineRectangle.Y); } else { if (selectionBeyondEOL) { g.FillRectangle(BrushRegistry.GetBrush(selectionColor.BackgroundColor), new RectangleF(physicalXPos, lineRectangle.Y, spaceWidth, lineRectangle.Height)); physicalXPos += spaceWidth; } } Brush fillBrush = selectionBeyondEOL && TextEditorProperties.AllowCaretBeyondEOL ? bgColorBrush : backgroundBrush; g.FillRectangle(fillBrush, new RectangleF(physicalXPos, lineRectangle.Y, lineRectangle.Width - physicalXPos + lineRectangle.X, lineRectangle.Height)); } if (TextEditorProperties.ShowVerticalRuler) { DrawVerticalRuler(g, lineRectangle); } // bgColorBrush.Dispose(); }
void DrawTabMarker(Graphics g, Color color, float x, float y) { HighlightColor tabMarkerColor = textArea.Document.HighlightingStrategy.GetColorFor("TabMarkers"); g.DrawString("\u00BB", tabMarkerColor.Font, BrushRegistry.GetBrush(color), x, y, measureStringFormat); }
void DrawInvalidLineMarker(Graphics g, float x, float y) { HighlightColor invalidLinesColor = textArea.Document.HighlightingStrategy.GetColorFor("InvalidLines"); g.DrawString("~", invalidLinesColor.Font, BrushRegistry.GetBrush(invalidLinesColor.Color), x, y, measureStringFormat); }
void DrawBracketHighlight(Graphics g, Rectangle rect) { g.FillRectangle(BrushRegistry.GetBrush(Color.FromArgb(50, 0, 0, 255)), rect); g.DrawRectangle(Pens.Blue, rect); }