/// <summary>
        /// Draw the overlay(s)
        /// </summary>
        public void Draw()
        {
            EnsureInitiliased();

            Begin();

            foreach (var overlay in Overlays)
            {
                foreach (var element in overlay.Elements)
                {
                    var textElement  = element as TextElement;
                    var imageElement = element as ImageElement;

                    if (textElement != null)
                    {
                        DXFont font = GetFontForTextElement(textElement);
                        if (font != null && !String.IsNullOrEmpty(textElement.Text))
                        {
                            _spriteEngine.DrawString(textElement.Location.X, textElement.Location.Y, textElement.Text, textElement.Color.R, textElement.Color.G, textElement.Color.B, textElement.Color.A, font);
                        }
                    }
                    else if (imageElement != null)
                    {
                    }
                }
            }

            End();
        }
        DXFont GetFontForTextElement(TextElement element)
        {
            DXFont result = null;

            string fontKey = String.Format("{0}{1}{2}", element.Font.Name, element.Font.Size, element.Font.Style, element.AntiAliased);

            if (!_fontCache.TryGetValue(fontKey, out result))
            {
                result = ToDispose(new DXFont(_device, _deviceContext));
                result.Initialize(element.Font.Name, element.Font.Size, element.Font.Style, element.AntiAliased);
                _fontCache[fontKey] = result;
            }
            return(result);
        }
        /// <summary>
        /// Draw the overlay(s)
        /// </summary>
        public void Draw()
        {
            EnsureInitiliased();

            Begin();

            foreach (var overlay in Overlays)
            {
                if (overlay.Hidden)
                {
                    continue;
                }

                foreach (var element in overlay.Elements)
                {
                    if (element.Hidden)
                    {
                        continue;
                    }

                    var textElement  = element as TextElement;
                    var imageElement = element as ImageElement;

                    if (textElement != null)
                    {
                        DXFont font = GetFontForTextElement(textElement);
                        if (font != null && !String.IsNullOrEmpty(textElement.Text))
                        {
                            _spriteEngine.DrawString(textElement.Location.X, textElement.Location.Y, textElement.Text, textElement.Color, font);
                        }
                    }
                    else if (imageElement != null)
                    {
                        DXImage image = GetImageForImageElement(imageElement);
                        if (image != null)
                        {
                            _spriteEngine.DrawImage(imageElement.Location.X, imageElement.Location.Y, imageElement.Scale, imageElement.Angle, imageElement.Tint, image);
                        }
                    }
                }
            }

            End();
        }
Exemplo n.º 4
0
        public void DrawString(int X, int Y, string text, int R, int G, int B, int A, DXFont F)
        {
            Color4 blendFactor = new Color4(1.0f);
            Color4 backupBlendFactor;
            int backupMask;
            var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask);
            _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);

            BeginBatch(F.GetFontSheetSRV());


            int length = text.Length;

            int posX = X;
            int posY = Y;

            Color4 color;
            Vector4 Vec = new Vector4(R > 0 ? (float)(R / 255.0f) : 0.0f, G > 0 ? (float)(G / 255.0f) : 0.0f, B > 0 ? (float)(B / 255.0f) : 0.0f, A > 0 ? (float)(A / 255.0f) : 0.0f);
            color = new Color4(Vec);

            for (int i = 0; i < length; ++i)
            {
                char character = text[i];

                if (character == ' ')
                    posX += F.GetSpaceWidth();
                else if (character == '\n')
                {
                    posX = X;
                    posY += F.GetCharHeight();
                }
                else
                {
                    Rectangle charRect = F.GetCharRect(character);

                    int width = charRect.Right - charRect.Left;
                    int height = charRect.Bottom - charRect.Top;

                    Draw(new Rectangle(posX, posY, posX + width, posY + height), charRect, color);

                    posX += width + 1;
                }
            }

            EndBatch();
            _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask);
        }
Exemplo n.º 5
0
        DXFont GetFontForTextElement(TextElement element)
        {
            DXFont result = null;

            string fontKey = String.Format("{0}{1}{2}", element.Font.Name, element.Font.Size, element.Font.Style, element.AntiAliased);

            if (!_fontCache.TryGetValue(fontKey, out result))
            {
                result = new DXFont(_device, _deviceContext);
                result.Initialize(element.Font.Name, element.Font.Size, element.Font.Style, element.AntiAliased);
                _fontCache[fontKey] = result;
            }
            return result;
        }
Exemplo n.º 6
0
        public void DrawString(int X, int Y, string text, System.Drawing.Color color, DXFont F)
        {
            Color4 blendFactor = new Color4(1.0f);
            Color4 backupBlendFactor;
            int backupMask;
            using (var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask))
            {
                _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);

                BeginBatch(F.GetFontSheetSRV());


                int length = text.Length;

                int posX = X;
                int posY = Y;

                Color4 color4 = ToColor4(color);

                for (int i = 0; i < length; ++i)
                {
                    char character = text[i];

                    if (character == ' ')
                        posX += F.GetSpaceWidth();
                    else if (character == '\n')
                    {
                        posX = X;
                        posY += F.GetCharHeight();
                    }
                    else
                    {
                        Rectangle charRect = F.GetCharRect(character);

                        int width = charRect.Right - charRect.Left;
                        int height = charRect.Bottom - charRect.Top;

                        Draw(new Rectangle(posX, posY, width, height), charRect, color4);

                        posX += width + 1;
                    }
                }

                EndBatch();
                _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask);
            }
        }
Exemplo n.º 7
0
        public void DrawString(int X, int Y, string text, System.Drawing.Color color, DXFont F)
        {
            Color4 blendFactor = new Color4(1.0f);

            SharpDX.Mathematics.Interop.RawColor4 backupBlendFactor;
            int backupMask;

            using (var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask))
            {
                _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);

                BeginBatch(F.GetFontSheetSRV());


                int length = text.Length;

                int posX = X;
                int posY = Y;

                Color4 color4 = ToColor4(color);

                for (int i = 0; i < length; ++i)
                {
                    char character = text[i];

                    if (character == ' ')
                    {
                        posX += F.GetSpaceWidth();
                    }
                    else if (character == '\n')
                    {
                        posX  = X;
                        posY += F.GetCharHeight();
                    }
                    else
                    {
                        Rectangle charRect = F.GetCharRect(character);

                        int width  = charRect.Right - charRect.Left;
                        int height = charRect.Bottom - charRect.Top;

                        Draw(new Rectangle(posX, posY, width, height), charRect, color4);

                        posX += width + 1;
                    }
                }

                EndBatch();
                _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask);
            }
        }
Exemplo n.º 8
0
        public void DrawString(int X, int Y, string text, int R, int G, int B, int A, DXFont F)
        {
            Color4 blendFactor = new Color4(1.0f);
            Color4 backupBlendFactor;
            int    backupMask;
            var    backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask);

            _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor);

            BeginBatch(F.GetFontSheetSRV());


            int length = text.Length;

            int posX = X;
            int posY = Y;

            Color4  color;
            Vector4 Vec = new Vector4(R > 0 ? (float)(R / 255.0f) : 0.0f, G > 0 ? (float)(G / 255.0f) : 0.0f, B > 0 ? (float)(B / 255.0f) : 0.0f, A > 0 ? (float)(A / 255.0f) : 0.0f);

            color = new Color4(Vec);

            for (int i = 0; i < length; ++i)
            {
                char character = text[i];

                if (character == ' ')
                {
                    posX += F.GetSpaceWidth();
                }
                else if (character == '\n')
                {
                    posX  = X;
                    posY += F.GetCharHeight();
                }
                else
                {
                    Rectangle charRect = F.GetCharRect(character);

                    int width  = charRect.Right - charRect.Left;
                    int height = charRect.Bottom - charRect.Top;

                    Draw(new Rectangle(posX, posY, posX + width, posY + height), charRect, color);

                    posX += width + 1;
                }
            }

            EndBatch();
            _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask);
        }