Files
sbox-public/game/addons/tools/Code/Widgets/GradientEditor/GradientControlWidget.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

64 lines
1.4 KiB
C#

namespace Editor;
[CustomEditor( typeof( Gradient ) )]
public class GradientControlWidget : ControlWidget
{
public override bool SupportsMultiEdit => true;
public GradientControlWidget( SerializedProperty property ) : base( property )
{
SetSizeMode( SizeMode.Default, SizeMode.Default );
Layout = Layout.Column();
Layout.Spacing = 2;
Cursor = CursorShape.Finger;
}
protected override void PaintOver()
{
Gradient v = SerializedProperty.GetValue<Gradient>();
v.PaintBlock( LocalRect.Shrink( 2 ) );
}
protected override void OnMouseReleased( MouseEvent e )
{
base.OnMouseReleased( e );
if ( e.LeftMouseButton )
{
OpenPopup();
}
}
private void OpenPopup()
{
Gradient v = SerializedProperty.GetValue<Gradient>();
GradientEditorWidget.OpenPopup( this, v, x => { SerializedProperty.SetValue( x ); Update(); } );
}
protected override void OnContextMenu( ContextMenuEvent e )
{
var m = new ContextMenu();
m.AddOption( "Open in Editor", "edit", OpenPopup );
m.AddSeparator();
m.AddOption( "Copy", "content_copy", () =>
{
var json = JsonSerializer.Serialize( SerializedProperty.GetValue<Gradient>() );
EditorUtility.Clipboard.Copy( json );
} );
var clipboard = EditorUtility.Clipboard.Paste();
m.AddOption( "Paste", "content_paste", () =>
{
var value = JsonSerializer.Deserialize<Gradient>( clipboard );
SerializedProperty.SetValue( value );
} );
m.OpenAtCursor( false );
e.Accepted = true;
}
}