diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs index 3603165985..06c4b95184 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs @@ -7,6 +7,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; @@ -18,44 +19,47 @@ namespace ICSharpCode.TextEditor /// public class BrushRegistry { - static Hashtable brushes = new Hashtable(); - static Hashtable pens = new Hashtable(); - static Hashtable dotPens = new Hashtable(); + static Dictionary brushes = new Dictionary(); + static Dictionary pens = new Dictionary(); + static Dictionary dotPens = new Dictionary(); public static Brush GetBrush(Color color) { - if (!brushes.Contains(color)) { - Brush newBrush = new SolidBrush(color); - brushes.Add(color, newBrush); - return newBrush; + lock (brushes) { + Brush brush; + if (!brushes.TryGetValue(color, out brush)) { + brush = new SolidBrush(color); + brushes.Add(color, brush); + } + return brush; } - return brushes[color] as Brush; } public static Pen GetPen(Color color) { - if (!pens.Contains(color)) { - Pen newPen = new Pen(color); - pens.Add(color, newPen); - return newPen; + lock (pens) { + Pen pen; + if (!pens.TryGetValue(color, out pen)) { + pen = new Pen(color); + pens.Add(color, pen); + } + return pen; } - return pens[color] as Pen; } - public static Pen GetDotPen(Color bgColor, Color fgColor) + static readonly float[] dotPattern = { 1, 1, 1, 1 }; + + public static Pen GetDotPen(Color color) { - bool containsBgColor = dotPens.Contains(bgColor); - if (!containsBgColor || !((Hashtable)dotPens[bgColor]).Contains(fgColor)) { - if (!containsBgColor) { - dotPens[bgColor] = new Hashtable(); + lock (dotPens) { + Pen pen; + if (!dotPens.TryGetValue(color, out pen)) { + pen = new Pen(color); + pen.DashPattern = dotPattern; + dotPens.Add(color, pen); } - - HatchBrush hb = new HatchBrush(HatchStyle.Percent50, bgColor, fgColor); - Pen newPen = new Pen(hb); - ((Hashtable)dotPens[bgColor])[fgColor] = newPen; - return newPen; + return pen; } - return ((Hashtable)dotPens[bgColor])[fgColor] as Pen; } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs index 2935946250..1129b85abc 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs @@ -242,7 +242,7 @@ namespace ICSharpCode.TextEditor HighlightColor caretLineColor = textArea.Document.HighlightingStrategy.GetColorFor("CaretLine"); - g.DrawLine(BrushRegistry.GetDotPen(caretLineColor.Color, caretLineColor.BackgroundColor), + g.DrawLine(BrushRegistry.GetDotPen(caretLineColor.Color), currentPos.X, 0, currentPos.X, diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs index 7326b33f4e..2ebd32c096 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs @@ -56,9 +56,9 @@ namespace ICSharpCode.TextEditor // draw dotted separator line if (textArea.Document.TextEditorProperties.ShowLineNumbers) { g.FillRectangle(BrushRegistry.GetBrush(textArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), - new Rectangle(markerRectangle.X + 1, markerRectangle.Y, markerRectangle.Width - 1, markerRectangle.Height)); + markerRectangle); - g.DrawLine(BrushRegistry.GetDotPen(lineNumberPainterColor.Color, lineNumberPainterColor.BackgroundColor), + g.DrawLine(BrushRegistry.GetDotPen(lineNumberPainterColor.Color), base.drawingPosition.X, markerRectangle.Y, base.drawingPosition.X,