(61d00a474) v0.9.7.1

This commit is contained in:
Regalis
2020-03-04 13:04:10 +01:00
parent 3c50efa5c9
commit 3c09ebe02f
5086 changed files with 786063 additions and 295871 deletions
@@ -0,0 +1,50 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Barotrauma
{
/// <summary>
/// GUIComponent that can be used to render custom content on the UI
/// </summary>
class GUICustomComponent : GUIComponent
{
public Action<SpriteBatch, GUICustomComponent> OnDraw;
public Action<float, GUICustomComponent> OnUpdate;
public bool HideElementsOutsideFrame;
public GUICustomComponent(RectTransform rectT, Action<SpriteBatch, GUICustomComponent> onDraw = null, Action<float, GUICustomComponent> onUpdate = null) : base(null, rectT)
{
OnDraw = onDraw;
OnUpdate = onUpdate;
}
protected override void Draw(SpriteBatch spriteBatch)
{
if (!Visible) return;
Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
if (HideElementsOutsideFrame)
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, Rect);
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
OnDraw?.Invoke(spriteBatch, this);
if (HideElementsOutsideFrame)
{
spriteBatch.End();
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
}
}
protected override void Update(float deltaTime)
{
if (Visible) OnUpdate?.Invoke(deltaTime, this);
}
}
}