A UI RootPanel subclass that forces a fixed render target size and scale, and optionally forces the global mouse visibility while it exists. It overrides bounds and scale updates to use FixedBounds and FixedScale, and stores a MousePosition property for use by external code.
using Sandbox;
using Sandbox.UI;
namespace PanelRenderTarget;
public class TargetRootPanel : RootPanel
{
public Rect FixedBounds { get; set; } = new Rect( 0, 0, 1280, 720 );
public float FixedScale { get; set; } = 1f;
public new Vector2 MousePosition { get; set; }
public MouseVisibility MouseVisibility { get; set; } = MouseVisibility.Hidden;
public override void Tick()
{
base.Tick();
if( MouseVisibility == MouseVisibility.Visible && Mouse.Visibility != MouseVisibility.Visible )
{
Mouse.Visibility = MouseVisibility.Visible;
}
}
protected override void UpdateBounds( Rect rect )
{
PanelBounds = FixedBounds;
//this.Mouse
}
protected override void UpdateScale( Rect screenSize )
{
Scale = FixedScale;
}
public override void OnDeleted()
{
base.OnDeleted();
if( MouseVisibility == MouseVisibility.Visible )
{
Mouse.Visibility = MouseVisibility.Auto;
}
}
}