(61d00a474) v0.9.7.1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user