|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
namespace Storm.Docking.Visual.Drawing
{
/// <summary>
/// Since creating a new brush/pen everytime we need to
/// redraw a TextView is too inefficient, we keep them in
/// a stack here.
/// </summary>
public class BrushStack
{
#region Fields
private static Hashtable _brushes = new Hashtable();
private static Hashtable _pens = new Hashtable();
#endregion
#region Methods
#region Public
/// <summary>
/// Returns a Brush from the stack of brushes.
/// If the brush stack doesn't contain the specified
/// Brush, creates a Brush and adds it to the stack.
/// </summary>
/// <param name="color">Color of the returned Brush.</param>
/// <returns>Brush from the stack of brushes.</returns>
public static Brush GetBrush(Color color)
{
if (_brushes.Contains(color) == false)
{
Brush brush = new SolidBrush(color);
_brushes.Add(color, brush);
return brush;
}
return _brushes[color] as Brush;
}
/// <summary>
/// Returns a Pen from the stack of pens.
/// If the pen stack doesn't contain the specified
/// Pen, creates a Pen and adds it to the stack.
/// </summary>
/// <param name="color">Color of the returned Pen.</param>
/// <returns>Pen from the stack of pens.</returns>
public static Pen GetPen(Color color)
{
if (_pens.Contains(color) == false)
{
Pen pen = new Pen(color);
_pens.Add(color, pen);
return pen;
}
return _pens[color] as Pen;
}
#endregion
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.