Files
sbox-public/game/addons/tools/Code/Scene/SceneView/SceneOverlayWidget.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

88 lines
1.8 KiB
C#

namespace Editor;
public class SceneOverlayWidget : Widget
{
public static SceneOverlayWidget Active { get; private set; }
public Layout Header { get; private set; }
internal SceneOverlayWidget( Widget parent ) : base( parent )
{
TranslucentBackground = true;
NoSystemBackground = true;
WindowFlags = WindowFlags.FramelessWindowHint | WindowFlags.Tool;
Active = this;
Layout = Layout.Column();
Layout.Margin = 8;
var header = Layout.AddRow();
header.AddStretchCell();
Header = header.AddRow();
Header.Spacing = 4;
Layout.AddStretchCell();
// doesn't handle floating windows, but there's no way to hook into dockwrapper events right now
EditorWindow.Moved += UpdateDimensions;
TransparentForMouseEvents = true;
}
public override void OnDestroyed()
{
base.OnDestroyed();
if ( EditorWindow.IsValid() )
{
EditorWindow.Moved -= UpdateDimensions;
}
}
int lastGeometryHash = -1;
[EditorEvent.Frame]
private void UpdateDimensions()
{
if ( !Parent.IsValid() )
return;
// this wasn't always being triggered properly when relying on widget events from the parent (causing HUGE jank)
int geometryHash = HashCode.Combine( Parent.ScreenPosition, Parent.Size );
if ( lastGeometryHash != geometryHash )
{
Position = Parent.ScreenPosition;
Size = Parent.Size;
}
lastGeometryHash = geometryHash;
}
internal RealTimeSince timeSinceNeededRedraw = 0.0f;
[EditorEvent.Frame]
public void Frame()
{
if ( timeSinceNeededRedraw > 0.1f )
{
Update();
timeSinceNeededRedraw = 0.0f;
}
}
protected override void OnPaint()
{
Active = this;
if ( Parent is SceneViewportWidget vw )
{
if ( vw.SceneView.CurrentView == SceneViewWidget.ViewMode.Game )
{
EditorEvent.Run( "sceneview.paintoverlay" );
}
}
}
}