Click here to Skip to main content
15,886,026 members
Articles / Desktop Programming / Windows Forms

Storm - the world's best IDE framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (82 votes)
4 Feb 2010LGPL311 min read 274.5K   6.5K   340  
Create fast, flexible, and extensible IDE applications easily with Storm - it takes nearly no code at all!
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.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)



Comments and Discussions