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 @@ @@ -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 @@ -18,44 +19,47 @@ namespace ICSharpCode.TextEditor
/// </summary>
public class BrushRegistry
{
static Hashtable brushes = new Hashtable();
static Hashtable pens = new Hashtable();
static Hashtable dotPens = new Hashtable();
static Dictionary<Color, Brush> brushes = new Dictionary<Color, Brush>();
static Dictionary<Color, Pen> pens = new Dictionary<Color, Pen>();
static Dictionary<Color, Pen> dotPens = new Dictionary<Color, Pen>();
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;
}
}
}

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

@ -242,7 +242,7 @@ namespace ICSharpCode.TextEditor @@ -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,

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

@ -56,9 +56,9 @@ namespace ICSharpCode.TextEditor @@ -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,

Loading…
Cancel
Save