Profile editor - Only save profile on drag-edit when mouse is released

Profile editor - Format all numbers with 3 decimals 
Profile editor - Fixed drag-edit rounding errors with very small steps
Logging - Output logs to debug
Settings - Added logging level setting
Nuget - Updated Serilog and the used sinks
This commit is contained in:
Robert committed 2020-02-19 17:17:35 +01:00
1 parent 05cf1f0b53
commit 318a679744
26 files changed
+323 -161

No files matched your search

@@ -91,20 +91,12 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl1.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="ColorPicker.xaml.cs">
<DependentUpon>ColorPicker.xaml</DependentUpon>
</Compile>
<Compile Include="Converters\ColorToSKColorConverter.cs" />
<Compile Include="Converters\ColorToSolidColorConverter.cs" />
<Compile Include="Converters\ColorToStringConverter.cs" />
<Compile Include="UserControl1.xaml.cs">
<DependentUpon>UserControl1.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
+4 -3
View File
@@ -22,12 +22,13 @@
Height="17"
Padding="1 0"
Margin="0 4 0 0"
Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Text="{Binding Value, StringFormat=N3, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Cursor="/Resources/aero_drag_ew.cur"
Foreground="{DynamicResource SecondaryAccentBrush}"
MouseDown="InputMouseDown"
MouseUp="InputMouseUp"
MouseMove="InputMouseMove" />
MouseMove="InputMouseMove"
RequestBringIntoView="Input_OnRequestBringIntoView"/>
</Border>
<!-- Input -->
@@ -36,7 +37,7 @@
Height="20"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left"
Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Text="{Binding Value, StringFormat=N3, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
LostFocus="InputLostFocus"
KeyDown="InputKeyDown"
RequestBringIntoView="Input_OnRequestBringIntoView" />
+38 -8
View File
@@ -24,9 +24,13 @@ namespace Artemis.UI.Shared
typeof(RoutedPropertyChangedEventHandler<float>),
typeof(DraggableFloat));
public event EventHandler DragStarted;
public event EventHandler DragEnded;
private bool _inCallback;
private Point _mouseDragStartPoint;
private float _startValue;
private bool _calledDragStarted;
public DraggableFloat()
{
@@ -75,22 +79,33 @@ namespace Artemis.UI.Shared
var position = e.GetPosition((IInputElement) sender);
if (position == _mouseDragStartPoint)
DisplayInput();
else
{
OnDragEnded();
_calledDragStarted = false;
}
((IInputElement) sender).ReleaseMouseCapture();
}
private void InputMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
if (e.LeftButton != MouseButtonState.Pressed)
return;
if (!_calledDragStarted)
{
// Use decimals for everything to avoid floating point errors
var startValue = new decimal(_startValue);
var startX = new decimal(_mouseDragStartPoint.X);
var x = new decimal(e.GetPosition((IInputElement) sender).X);
var stepSize = new decimal(StepSize);
Value = (float) (Math.Round(startValue + stepSize * (x - startX) / stepSize) * stepSize);
OnDragStarted();
_calledDragStarted = true;
}
// Use decimals for everything to avoid floating point errors
var startValue = new decimal(_startValue);
var startX = new decimal(_mouseDragStartPoint.X);
var x = new decimal(e.GetPosition((IInputElement) sender).X);
var stepSize = new decimal(StepSize);
Value = (float) UltimateRoundingFunction(startValue + stepSize * (x - startX), stepSize, 0.5m);
}
private void InputLostFocus(object sender, RoutedEventArgs e)
@@ -127,5 +142,20 @@ namespace Artemis.UI.Shared
{
e.Handled = true;
}
private static decimal UltimateRoundingFunction(decimal amountToRound, decimal nearstOf, decimal fairness)
{
return Math.Floor(amountToRound / nearstOf + fairness) * nearstOf;
}
protected virtual void OnDragStarted()
{
DragStarted?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnDragEnded()
{
DragEnded?.Invoke(this, EventArgs.Empty);
}
}
}
-10
View File
@@ -1,10 +0,0 @@
<UserControl x:Class="Artemis.UI.Shared.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid />
</UserControl>
@@ -1,15 +0,0 @@
using System.Windows.Controls;
namespace Artemis.UI.Shared
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
}