/// <summary>
        ///  Removes the surface associated with the given key.
        /// </summary>
        /// <param name="key">The key of the surface to remove.</param>
        /// <returns>The DirectDrawSurface being removed.</returns>
        internal DirectDrawSurface Remove(string key)
        {
            DirectDrawSurface ddSurface = null;

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            if (sprites.ContainsKey(key))
            {
                ddSurface = (DirectDrawSurface)sprites[key];
                sprites.Remove(key);
            }

            return(ddSurface);
        }
Exemple #2
0
        /// <summary>
        ///  Adds a new string to the text surface manager.  This creates
        ///  the associated text surface so that text can be rendered with
        ///  a fast Blt rather than with a DrawText call.  Note that caching
        ///  could be done in a much more efficient manner and some text
        ///  surfaces will have identical contents.
        /// </summary>
        /// <param name="key">The string to add.</param>
        internal void Add(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            // Set up the surface
            var rect      = new RECT();
            var ddSurface = new DirectDrawSurface(StandardFontRect.Right, StandardFontRect.Bottom)
            {
                TransparencyKey = DirectDrawSurface.MagentaColorKey
            };

            // Color in the back and add the text
            ddSurface.Surface.BltColorFill(ref rect, DirectDrawSurface.MagentaColorKey.low);
            ddSurface.Surface.SetForeColor(0);

            var text = key;

            if (text.Length > 16)
            {
                text  = text.Substring(0, 16);
                text += "...";
            }

            var dcHandle = new IntPtr(ddSurface.Surface.GetDC());

            var graphics = Graphics.FromHdc(dcHandle);

            var font = new Font("Verdana", 6.75f, FontStyle.Regular);

            graphics.DrawString(text, font, Brushes.Black, 1, 1);
            graphics.DrawString(text, font, Brushes.WhiteSmoke, 0, 0);

            font.Dispose();

            graphics.Dispose();

            ddSurface.Surface.ReleaseDC(dcHandle.ToInt32());

            sprites.Add(key, ddSurface);
        }