Exemplo n.º 1
0
        DXImage GetImageForImageElement(ImageElement element)
        {
            DXImage result = null;

            if (!_imageCache.TryGetValue(element, out result))
            {
                result = ToDispose(new DXImage(_device, _deviceContext));
                result.Initialise(element.Bitmap);
                _imageCache[element] = result;
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <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.º 3
0
        public void DrawImage(int x, int y, float scale, float angle, System.Drawing.Color?color, DXImage image)
        {
            Debug.Assert(_initialized);

            Color4 blendFactor = new Color4(1.0f);

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

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

                BeginBatch(image.GetSRV());

                Draw(new Rectangle(x, y, (int)(scale * image.Width), (int)(scale * image.Height)), new Rectangle(0, 0, image.Width, image.Height), color.HasValue ? ToColor4(color.Value) : Color4.White, 1.0f, angle);

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