Browse Source

Use Dictionary instead of Hashtable in BrushRegistry to prevent boxing of Color objects. Use Pen.DashPattern instead of Pen with HatchBrush for dotted pens.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3673 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
8b507a58ac
  1. 52
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs
  2. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs
  3. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs

52
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/BrushRegistry.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
@ -18,44 +19,47 @@ namespace ICSharpCode.TextEditor
/// </summary> /// </summary>
public class BrushRegistry public class BrushRegistry
{ {
static Hashtable brushes = new Hashtable(); static Dictionary<Color, Brush> brushes = new Dictionary<Color, Brush>();
static Hashtable pens = new Hashtable(); static Dictionary<Color, Pen> pens = new Dictionary<Color, Pen>();
static Hashtable dotPens = new Hashtable(); static Dictionary<Color, Pen> dotPens = new Dictionary<Color, Pen>();
public static Brush GetBrush(Color color) public static Brush GetBrush(Color color)
{ {
if (!brushes.Contains(color)) { lock (brushes) {
Brush newBrush = new SolidBrush(color); Brush brush;
brushes.Add(color, newBrush); if (!brushes.TryGetValue(color, out brush)) {
return newBrush; brush = new SolidBrush(color);
brushes.Add(color, brush);
}
return brush;
} }
return brushes[color] as Brush;
} }
public static Pen GetPen(Color color) public static Pen GetPen(Color color)
{ {
if (!pens.Contains(color)) { lock (pens) {
Pen newPen = new Pen(color); Pen pen;
pens.Add(color, newPen); if (!pens.TryGetValue(color, out pen)) {
return newPen; 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); lock (dotPens) {
if (!containsBgColor || !((Hashtable)dotPens[bgColor]).Contains(fgColor)) { Pen pen;
if (!containsBgColor) { if (!dotPens.TryGetValue(color, out pen)) {
dotPens[bgColor] = new Hashtable(); pen = new Pen(color);
pen.DashPattern = dotPattern;
dotPens.Add(color, pen);
} }
return pen;
HatchBrush hb = new HatchBrush(HatchStyle.Percent50, bgColor, fgColor);
Pen newPen = new Pen(hb);
((Hashtable)dotPens[bgColor])[fgColor] = newPen;
return newPen;
} }
return ((Hashtable)dotPens[bgColor])[fgColor] as Pen;
} }
} }
} }

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/Caret.cs

@ -242,7 +242,7 @@ namespace ICSharpCode.TextEditor
HighlightColor caretLineColor = textArea.Document.HighlightingStrategy.GetColorFor("CaretLine"); HighlightColor caretLineColor = textArea.Document.HighlightingStrategy.GetColorFor("CaretLine");
g.DrawLine(BrushRegistry.GetDotPen(caretLineColor.Color, caretLineColor.BackgroundColor), g.DrawLine(BrushRegistry.GetDotPen(caretLineColor.Color),
currentPos.X, currentPos.X,
0, 0,
currentPos.X, currentPos.X,

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/FoldMargin.cs

@ -56,9 +56,9 @@ namespace ICSharpCode.TextEditor
// draw dotted separator line // draw dotted separator line
if (textArea.Document.TextEditorProperties.ShowLineNumbers) { if (textArea.Document.TextEditorProperties.ShowLineNumbers) {
g.FillRectangle(BrushRegistry.GetBrush(textArea.Enabled ? lineNumberPainterColor.BackgroundColor : SystemColors.InactiveBorder), 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, base.drawingPosition.X,
markerRectangle.Y, markerRectangle.Y,
base.drawingPosition.X, base.drawingPosition.X,

Loading…
Cancel
Save