Beispiel #1
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            // moved from constructor to avoid texture loading on JIT thread
            if (_borderTexture == null)
            {
                _borderTexture = TextureManager.Load("Images/UI/PanelBorder");
            }
            if (_backgroundTexture == null)
            {
                _backgroundTexture = TextureManager.Load("Images/UI/PanelBackground");
            }


            var panelSpriteBatch = new SpriteBatch(Main.graphics.GraphicsDevice);

            panelSpriteBatch.Begin();

            this.DrawPanel(panelSpriteBatch, _backgroundTexture, BackgroundColor);
            this.DrawPanel(panelSpriteBatch, _borderTexture, BorderColor);

            CalculatedStyle space    = GetInnerDimensions();
            float           position = 0f;

            if (Scrollbar != null)
            {
                position = -Scrollbar.GetValue();
            }

            Scrollbar.Top.Pixels    = this.Top.Pixels;
            Scrollbar.Left.Pixels   = this.Left.Pixels + panelWidth + 0;
            Scrollbar.Height.Pixels = panelHeight;
            Scrollbar.Recalculate();
            Scrollbar.Draw(panelSpriteBatch);

            panelSpriteBatch.End();

            var innerSpriteBatch = new SpriteBatch(Main.graphics.GraphicsDevice);

            RasterizerState r = new RasterizerState();

            r.ScissorTestEnable = true;

            innerSpriteBatch.GraphicsDevice.RasterizerState = r;

            /*try
             * {*/
            int left   = (int)Math.Max(0, this.Left.Pixels);
            int top    = (int)Math.Max(0, this.Top.Pixels);
            int width  = Math.Min(panelWidth, innerSpriteBatch.GraphicsDevice.Viewport.Width - left);
            int height = Math.Min(panelHeight, innerSpriteBatch.GraphicsDevice.Viewport.Height - top);
            var rect   = new Rectangle(left, top, width, height);

            innerSpriteBatch.GraphicsDevice.ScissorRectangle = rect;

            //innerSpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, r, null, Matrix.CreateTranslation(0, -Scrollbar.ViewPosition, 0));
            innerSpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, r, null);

            int diff = ((int)-Scrollbar.ViewPosition) - lastOffset;

            lastOffset += diff;


            foreach (var child in this.Elements)
            {
                if (diff != 0)
                {
                    child.Top.Pixels += diff;
                    child.Recalculate();
                }

                child.Draw(innerSpriteBatch);
            }

            innerSpriteBatch.End();


            bool hoveringOverReforgeButton = this.Left.Pixels <= Main.mouseX && Main.mouseX <= this.Left.Pixels + this.panelWidth + 20 &&
                                             this.Top.Pixels <= Main.mouseY && Main.mouseY <= this.Top.Pixels + this.panelHeight + 20 && !PlayerInput.IgnoreMouseInterface;

            if (hoveringOverReforgeButton)
            {
                Main.LocalPlayer.mouseInterface = true;
            }
        }