mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-14 09:19:25 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
52 lines
1.3 KiB
C#
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()
|
|
{
|
|
|
|
}
|
|
}
|