Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion engine/Sandbox.Tools/ControlWidget/FloatControlWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class FloatControlWidget : StringControlWidget
public string Icon { get; set; }
public string Label { get; set; }
public Action<Rect, float> SliderPaint { get; set; }
public float SliderCurve
{
get => SliderWidget?.Curve ?? 1f;
set => SliderWidget?.Curve = value;
}

/// <summary>
/// If true we can draw a slider
Expand Down Expand Up @@ -277,6 +282,7 @@ public class FloatSlider : Widget
{
public float Minimum { get; set; }
public float Maximum { get; set; }
public float Curve { get; set; } = 1f;
public Action OnValueEdited { get; set; }
public Color HighlightColor { get; set; } = Theme.TextLight;
public Action<Rect, float> SliderPaint { get; set; }
Expand Down Expand Up @@ -304,12 +310,23 @@ public float DeltaValue
{
get
{
return MathX.LerpInverse( Value, Minimum, Maximum, true );
var v = Value;
if ( Curve != 1 )
{
var range = Maximum - Minimum;
v = MathF.Pow( v / range, 1f / Curve ) * range;
}
return MathX.LerpInverse( v, Minimum, Maximum, true );
}

set
{
var v = MathX.LerpTo( Minimum, Maximum, value, true );
if ( Curve != 1 )
{
var range = Maximum - Minimum;
v = MathF.Pow( v / range, Curve ) * range;
}
Value = v;
}

Expand Down
5 changes: 3 additions & 2 deletions game/addons/tools/Code/Widgets/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Color ValueWithoutRange

var hueSlider = new HsvFloatControlWidget( so.GetProperty( nameof( Hue ) ), HueSliderPaint );
AlphaSlider = new HsvFloatControlWidget( so.GetProperty( nameof( Alpha ) ), AlphaSliderPaint );
RangeSlider = new HsvFloatControlWidget( so.GetProperty( nameof( Range ) ), RangeSliderPaint );
RangeSlider = new HsvFloatControlWidget( so.GetProperty( nameof( Range ) ), RangeSliderPaint, 3 );

so.OnPropertyStartEdit += ( p ) => EditingStarted?.Invoke();
so.OnPropertyFinishEdit += ( p ) => EditingFinished?.Invoke();
Expand Down Expand Up @@ -382,10 +382,11 @@ class HsvFloatControlWidget : FloatControlWidget
public override bool IncludeLabel => false;
public override bool IsWideMode => true;

public HsvFloatControlWidget( SerializedProperty property, Action<Rect, float> sliderPaint ) : base( property )
public HsvFloatControlWidget( SerializedProperty property, Action<Rect, float> sliderPaint, float curve = 1f ) : base( property )
{
Label = null;
Icon = "multiple_stop";
SliderPaint = sliderPaint;
SliderCurve = curve;
}
}