Ejemplo n.º 1
0
        internal RenderManager(GraphicsDevice device, SBX batch)
        {
            Skins       = new Dictionary <string, Skin>();
            SpriteFonts = new Dictionary <string, Font>();

            ApplyStencil = new DepthStencilState {
                StencilEnable     = true,
                StencilFunction   = CompareFunction.Always,
                StencilPass       = StencilOperation.Replace,
                ReferenceStencil  = 1,
                DepthBufferEnable = false,
            };

            SampleStencil = new DepthStencilState {
                StencilEnable     = true,
                StencilFunction   = CompareFunction.Equal,
                StencilPass       = StencilOperation.Keep,
                ReferenceStencil  = 1,
                DepthBufferEnable = false,
            };

            GraphicsDevice  = device;
            RasterizerState = new RasterizerState {
                ScissorTestEnable = true
            };
            SpriteBatch = batch;
        }
Ejemplo n.º 2
0
        /*####################################################################*/
        /*                           Initialization                           */
        /*####################################################################*/

        public Gui(Game game, Skin defaultSkin, Font defaultText,
                   IEnumerable <Tuple <string, Skin> > skins         = null,
                   IEnumerable <Tuple <string, Font> > textRenderers = null)
        {
            InitWidgets();

            NewState = OldState = new MouseState();

            InputManager = new InputManager(game, m_Widgets);
            Core.Graphics.SpriteBatchExtended SBX = (Core.Graphics.SpriteBatchExtended)game.Components[0];
            RenderManager = new RenderManager(game.GraphicsDevice, SBX);

            SetDefaultSettings(game, defaultSkin, defaultText);

            if (skins != null)
            {
                foreach (var skin in skins)
                {
                    AddSkin(skin.Item1, skin.Item2);
                }
            }

            if (textRenderers != null)
            {
                foreach (var textRenderer in textRenderers)
                {
                    AddText(textRenderer.Item1, textRenderer.Item2);
                }
            }
        }
Ejemplo n.º 3
0
        /*####################################################################*/
        /*                             Rendering                              */
        /*####################################################################*/

        public void RenderCursor(SBX batch, Rectangle renderArea)
        {
            //Top left corner of the text area
            int x = renderArea.X,
                y = renderArea.Y;

            if (TextCursor > 0)
            {
                if (_char[TextCursor - 1] == '\n' || _char[TextCursor - 1] == '\r')
                {
                    //Beginning of next line
                    y += _charY[TextCursor - 1] + Font.LineSpacing;
                }
                else if (TextCursor == Length)
                {
                    //After last character
                    x += _charX[TextCursor - 1] + _charWidth[TextCursor - 1];
                    y += _charY[TextCursor - 1];
                }
                else
                {
                    //Beginning of current character
                    x += _charX[TextCursor];
                    y += _charY[TextCursor];
                }
            }
            Cursor.Render(batch, new Rectangle(x - 1, y, Cursor.Size.X, Font.LineSpacing));
        }
Ejemplo n.º 4
0
        public override void Render(SBX batch, Rectangle destination)
        {
            var drawArea = new Rectangle(destination.Right - _edge.Width, destination.Top, _edge.Width, _edge.Height);

            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically);

            drawArea.Y = destination.Bottom - _edge.Height;
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White, SpriteEffects.FlipHorizontally);

            drawArea.Y      = destination.Top + _edge.Height;
            drawArea.Height = destination.Height - (2 * _edge.Height);
            batch.GUIDrawSprite(ImageMap, drawArea, _center, Color.White, SpriteEffects.FlipHorizontally);
        }
Ejemplo n.º 5
0
        public override void Render(SBX batch, Rectangle destination)
        {
            var drawArea = new Rectangle(destination.Left, destination.Top, _edge.Width, _edge.Height);

            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White, SpriteEffects.FlipHorizontally);

            drawArea.X = destination.Right - _edge.Width;
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White);

            drawArea.X     = destination.Left + _edge.Width;
            drawArea.Width = destination.Width - (2 * _edge.Width);
            batch.GUIDrawSprite(ImageMap, drawArea, _center, Color.White);
        }
Ejemplo n.º 6
0
        public EBThread()
        {
            Content.RootDirectory = "Content";

            m_Graphics = new GraphicsDeviceManager(this);
            m_Graphics.IsFullScreen              = false;
            m_Graphics.PreferredBackBufferWidth  = 256;
            m_Graphics.PreferredBackBufferHeight = 240;

            m_Input = new Core.InputState();
            m_Input.Initialize(this.Window.Handle);

            m_SBX = new Core.Graphics.SpriteBatchExtended(this);
            this.Components.Add(m_SBX);

            this.IsMouseVisible = true;
        }
Ejemplo n.º 7
0
        public void Render(SBX spriteBatch, string value, Rectangle renderArea, TextHorizontal h = TextHorizontal.LeftAligned, TextVertical v = TextVertical.TopAligned, Color?color = null)
        {
            if (value == null)
            {
                return;
            }

            if (color == null)
            {
                color = Color;
            }

            Vector2 location = new Vector2(renderArea.X, renderArea.Y);
            Vector2 size     = SpriteFont.MeasureString(value);

            switch (h)
            {
            case TextHorizontal.CenterAligned:
                location.X += (renderArea.Width - size.X) / 1.9f;
                break;

            case TextHorizontal.RightAligned:
                location.X += renderArea.Width - size.X;
                break;
            }

            switch (v)
            {
            case TextVertical.CenterAligned:
                location.Y += (renderArea.Height - size.Y) / 1.9f;
                break;

            case TextVertical.BottomAligned:
                location.Y += renderArea.Height - size.Y;
                break;
            }

            spriteBatch.GUIDrawString(SpriteFont, value, location, color);
        }
Ejemplo n.º 8
0
 abstract public void Render(SBX batch, Rectangle destination);
Ejemplo n.º 9
0
        public override void Render(SBX batch, Rectangle destination)
        {
            // ##### Draw Background ##### //

            var drawArea = new Rectangle(
                destination.Left + BorderWidth,
                destination.Top + BorderWidth,
                destination.Width - (2 * BorderWidth),
                destination.Height - (2 * BorderWidth));

            batch.GUIDrawSprite(ImageMap, drawArea, _background, Color.White);

            // ##### Draw Corners ##### //

            drawArea.Width  = BorderWidth;
            drawArea.Height = BorderWidth;

            //Top Left
            drawArea.X = destination.Left;
            drawArea.Y = destination.Top;
            batch.GUIDrawSprite(ImageMap, drawArea, _corner, Color.White);

            //Top Right
            drawArea.X = destination.Right - BorderWidth;
            drawArea.Y = destination.Top;
            _corner.Y += BorderWidth;
            batch.GUIDrawSprite(ImageMap, drawArea, _corner, Color.White);

            //Bottom Right
            drawArea.X = destination.Right - BorderWidth;
            drawArea.Y = destination.Bottom - BorderWidth;
            _corner.Y += BorderWidth;
            batch.GUIDrawSprite(ImageMap, drawArea, _corner, Color.White);

            //Bottom Left
            drawArea.X = destination.Left;
            drawArea.Y = destination.Bottom - BorderWidth;
            _corner.Y += BorderWidth;
            batch.GUIDrawSprite(ImageMap, drawArea, _corner, Color.White);

            _corner.Y -= (3 * BorderWidth);

            // ##### Draw Edges ##### //

            //Top Edge
            drawArea.X     = destination.Left + BorderWidth;
            drawArea.Y     = destination.Top;
            drawArea.Width = destination.Width - (2 * BorderWidth) + 1;
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White);

            //Bottom Edge
            drawArea.Y = destination.Bottom - BorderWidth;
            _edge.Y   += (2 * BorderWidth);
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White);

            //Left Edge
            drawArea.X      = destination.Left;
            drawArea.Y      = destination.Top + BorderWidth;
            drawArea.Width  = BorderWidth;
            drawArea.Height = destination.Height - (2 * BorderWidth) + 1;
            _edge.Y        += BorderWidth;
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White);

            //Right Edge
            drawArea.X = destination.Right - BorderWidth;
            _edge.Y   -= (2 * BorderWidth);
            batch.GUIDrawSprite(ImageMap, drawArea, _edge, Color.White);

            _edge.Y -= (1 * BorderWidth);
        }
Ejemplo n.º 10
0
 public override void Render(SBX batch, Rectangle destination)
 {
     batch.GUIDrawSprite(ImageMap, destination, _source, Color.White);
 }