using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace Barotrauma { /// /// GUIComponent that can be used to render custom content on the UI /// class GUICustomComponent : GUIComponent { public Action OnDraw; public Action OnUpdate; public bool HideElementsOutsideFrame; public GUICustomComponent(RectTransform rectT, Action onDraw = null, Action 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); } } }