Code Coverage Statistics for Source File
c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Gui\BrushRegistry.cs
|
Sequence Point Coverage
N/A
0 of 0
|
Branch Coverage
N/A
0 of 0
|
Lines
61
|
Highlight:
Uncovered Code
Covered Code
| L | V | Source |
|---|---|---|
1 |
// <file> |
|
2 |
// <copyright see="prj:///doc/copyright.txt"/> |
|
3 |
// <license see="prj:///doc/license.txt"/> |
|
4 |
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> |
|
5 |
// <version>$Revision: 1965 $</version> |
|
6 |
// </file> |
|
7 |
||
8 |
using System; |
|
9 |
using System.Collections; |
|
10 |
using System.Drawing; |
|
11 |
using System.Drawing.Drawing2D; |
|
12 |
||
13 |
namespace ICSharpCode.TextEditor |
|
14 |
{ |
|
15 |
/// <summary> |
|
16 |
/// Contains brushes/pens for the text editor to speed up drawing. Re-Creation of brushes and pens |
|
17 |
/// seems too costly. |
|
18 |
/// </summary> |
|
19 |
public class BrushRegistry |
|
20 |
{ |
|
21 |
static Hashtable brushes = new Hashtable(); |
|
22 |
static Hashtable pens = new Hashtable(); |
|
23 |
static Hashtable dotPens = new Hashtable(); |
|
24 |
||
25 |
public static Brush GetBrush(Color color) |
|
26 |
{ |
|
27 |
if (!brushes.Contains(color)) { |
|
28 |
Brush newBrush = new SolidBrush(color); |
|
29 |
brushes.Add(color, newBrush); |
|
30 |
return newBrush; |
|
31 |
} |
|
32 |
return brushes[color] as Brush; |
|
33 |
} |
|
34 |
||
35 |
public static Pen GetPen(Color color) |
|
36 |
{ |
|
37 |
if (!pens.Contains(color)) { |
|
38 |
Pen newPen = new Pen(color); |
|
39 |
pens.Add(color, newPen); |
|
40 |
return newPen; |
|
41 |
} |
|
42 |
return pens[color] as Pen; |
|
43 |
} |
|
44 |
||
45 |
public static Pen GetDotPen(Color bgColor, Color fgColor) |
|
46 |
{ |
|
47 |
bool containsBgColor = dotPens.Contains(bgColor); |
|
48 |
if (!containsBgColor || !((Hashtable)dotPens[bgColor]).Contains(fgColor)) { |
|
49 |
if (!containsBgColor) { |
|
50 |
dotPens[bgColor] = new Hashtable(); |
|
51 |
} |
|
52 |
||
53 |
HatchBrush hb = new HatchBrush(HatchStyle.Percent50, bgColor, fgColor); |
|
54 |
Pen newPen = new Pen(hb); |
|
55 |
((Hashtable)dotPens[bgColor])[fgColor] = newPen; |
|
56 |
return newPen; |
|
57 |
} |
|
58 |
return ((Hashtable)dotPens[bgColor])[fgColor] as Pen; |
|
59 |
} |
|
60 |
} |
|
61 |
} |