Files
sbox-public/engine/Sandbox.Tools/Editor/GameScenePicker.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

71 lines
1.3 KiB
C#

using System;
namespace Editor;
/// <summary>
/// Opens an invisible popup above the game screen which allows you to left click once on the scene.
/// This is great for things like selecting something from the game scene.
/// </summary>
public class GameScenePicker : Widget
{
public Action Destroyed { get; set; }
public GameScenePicker() : base( null )
{
NoSystemBackground = true;
TranslucentBackground = true;
MinimumSize = 32;
MouseTracking = true;
IsPopup = true;
Visible = true;
DeleteOnClose = true;
Cursor = CursorShape.None;
}
public override void OnDestroyed()
{
base.OnDestroyed();
Destroyed?.Invoke();
}
protected override void DoLayout()
{
base.DoLayout();
var activeSession = SceneEditorSession.Active;
var dock = activeSession.SceneDock;
Position = dock.ScreenPosition - 8;
Size = dock.ScreenRect.Size + 16;
}
Vector2 hoverPos;
protected override void OnMouseMove( MouseEvent e )
{
base.OnMouseMove( e );
hoverPos = e.LocalPosition;
Update();
}
protected override void OnPaint()
{
var r = LocalRect;
r.Size -= 2;
var color = Color.Parse( "#df9194" ) ?? Color.White;
Paint.SetPen( color, 8.0f, PenStyle.Dot );
Paint.DrawRect( LocalRect );
}
protected override void OnMouseReleased( MouseEvent e )
{
base.OnMouseReleased( e );
Destroy();
}
}