Client LuaCsForBarotrauma
GUICustomComponent.cs
1 using System;
2 using Microsoft.Xna.Framework;
3 using Microsoft.Xna.Framework.Graphics;
4 
5 namespace Barotrauma
6 {
11  {
12  public Action<SpriteBatch, GUICustomComponent> OnDraw;
13  public Action<float, GUICustomComponent> OnUpdate;
14 
16 
17  public GUICustomComponent(RectTransform rectT, Action<SpriteBatch, GUICustomComponent> onDraw = null, Action<float, GUICustomComponent> onUpdate = null) : base(null, rectT)
18  {
19  OnDraw = onDraw;
20  OnUpdate = onUpdate;
21  }
22 
23  protected override void Draw(SpriteBatch spriteBatch)
24  {
25  if (!Visible) return;
26 
27  Rectangle prevScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
29  {
30  spriteBatch.End();
31  spriteBatch.GraphicsDevice.ScissorRectangle = Rectangle.Intersect(prevScissorRect, Rect);
32  spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
33  }
34 
35  OnDraw?.Invoke(spriteBatch, this);
36 
38  {
39  spriteBatch.End();
40  spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
41  spriteBatch.Begin(SpriteSortMode.Deferred, samplerState: GUI.SamplerState, rasterizerState: GameMain.ScissorTestEnable);
42  }
43  }
44 
45  protected override void Update(float deltaTime)
46  {
47  if (Visible) OnUpdate?.Invoke(deltaTime, this);
48  }
49  }
50 }
virtual Rectangle Rect
GUIComponent that can be used to render custom content on the UI
Action< float, GUICustomComponent > OnUpdate
GUICustomComponent(RectTransform rectT, Action< SpriteBatch, GUICustomComponent > onDraw=null, Action< float, GUICustomComponent > onUpdate=null)
override void Update(float deltaTime)
Action< SpriteBatch, GUICustomComponent > OnDraw
override void Draw(SpriteBatch spriteBatch)
static RasterizerState ScissorTestEnable
Definition: GameMain.cs:195