Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Input/Selection.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

52 lines
1.3 KiB
C#

namespace Sandbox.UI;
internal class Selection
{
Panel SelectionStart;
Vector2 SelectionStartPos;
Vector2 SelectionEndPos;
public void UpdateSelection( Panel root, Panel hovered, bool dragging, bool started, bool ended, Vector2 pos )
{
if ( started )
{
SelectionStart = null;
if ( hovered == null )
return;
ClearSelection();
SelectionStart = hovered;
SelectionStartPos = SelectionStart.ScreenPositionToPanelPosition( pos );
SelectionEndPos = SelectionStartPos;
return;
}
if ( SelectionStart == null )
return;
if ( dragging || ended )
{
var hash = HashCode.Combine( SelectionStart, SelectionStartPos, SelectionEndPos );
SelectionEndPos = SelectionStart.ScreenPositionToPanelPosition( pos );
var newHash = HashCode.Combine( SelectionStart, SelectionStartPos, SelectionEndPos );
if ( newHash == hash ) return;
SelectionEvent e = new SelectionEvent( "ondragselect", SelectionStart );
e.StartPoint = SelectionStart.PanelPositionToScreenPosition( SelectionStartPos );
e.EndPoint = SelectionStart.PanelPositionToScreenPosition( SelectionEndPos );
e.SelectionRect = new Rect( e.StartPoint );
e.SelectionRect = e.SelectionRect.AddPoint( e.EndPoint );
SelectionStart.CreateEvent( e );
}
}
void ClearSelection()
{
}
}