Layer properties - Added drag-editing for number-based properties

Layer properties - Added min and max values
Nuget - Updated Stylet to 1.3.1
This commit is contained in:
SpoinkyNL committed 2020-02-19 00:17:23 +01:00
1 parent ed26a9a5e5
commit 05cf1f0b53
37 files changed
+522 -235

No files matched your search

@@ -79,11 +79,18 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="DraggableFloat.xaml.cs">
<DependentUpon>DraggableFloat.xaml</DependentUpon>
</Compile>
<Compile Include="Utilities\EnumUtilities.cs" />
<Page Include="ColorPicker.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="DraggableFloat.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl1.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -18,7 +18,6 @@ namespace Artemis.UI.Shared
public static readonly DependencyProperty PopupOpenProperty = DependencyProperty.Register(nameof(PopupOpen), typeof(bool), typeof(ColorPicker),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, PopupOpenPropertyChangedCallback));
internal static readonly DependencyProperty ColorOpacityProperty = DependencyProperty.Register(nameof(ColorOpacity), typeof(byte), typeof(ColorPicker),
new FrameworkPropertyMetadata((byte) 255, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorOpacityPropertyChangedCallback));
+44
View File
@@ -0,0 +1,44 @@
<UserControl x:Class="Artemis.UI.Shared.DraggableFloat"
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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<StackPanel>
<!-- Drag handle -->
<Border x:Name="DragHandle" BorderThickness="0,0,0,1" Height="19">
<Border.BorderBrush>
<VisualBrush>
<VisualBrush.Visual>
<Rectangle StrokeDashArray="2 2" Stroke="{DynamicResource SecondaryAccentBrush}" StrokeThickness="1"
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}" />
</VisualBrush.Visual>
</VisualBrush>
</Border.BorderBrush>
<TextBlock Width="60"
Height="17"
Padding="1 0"
Margin="0 4 0 0"
Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
Cursor="/Resources/aero_drag_ew.cur"
Foreground="{DynamicResource SecondaryAccentBrush}"
MouseDown="InputMouseDown"
MouseUp="InputMouseUp"
MouseMove="InputMouseMove" />
</Border>
<!-- Input -->
<TextBox x:Name="Input"
Width="60"
Height="20"
materialDesign:ValidationAssist.UsePopup="True"
HorizontalAlignment="Left"
Text="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
LostFocus="InputLostFocus"
KeyDown="InputKeyDown"
RequestBringIntoView="Input_OnRequestBringIntoView" />
</StackPanel>
</UserControl>
@@ -0,0 +1,131 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Artemis.UI.Shared
{
/// <summary>
/// Interaction logic for DraggableFloat.xaml
/// </summary>
public partial class DraggableFloat : UserControl, INotifyPropertyChanged
{
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(float), typeof(DraggableFloat),
new FrameworkPropertyMetadata(default(float), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, FloatPropertyChangedCallback));
public static readonly DependencyProperty StepSizeProperty = DependencyProperty.Register(nameof(StepSize), typeof(float), typeof(DraggableFloat));
public static readonly RoutedEvent ValueChangedEvent =
EventManager.RegisterRoutedEvent(
nameof(Value),
RoutingStrategy.Bubble,
typeof(RoutedPropertyChangedEventHandler<float>),
typeof(DraggableFloat));
private bool _inCallback;
private Point _mouseDragStartPoint;
private float _startValue;
public DraggableFloat()
{
InitializeComponent();
}
public float Value
{
get => (float) GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
public float StepSize
{
get => (float) GetValue(StepSizeProperty);
set => SetValue(StepSizeProperty, value);
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private static void FloatPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var draggableFloat = (DraggableFloat) d;
if (draggableFloat._inCallback)
return;
draggableFloat._inCallback = true;
draggableFloat.OnPropertyChanged(nameof(Value));
draggableFloat._inCallback = false;
}
private void InputMouseDown(object sender, MouseButtonEventArgs e)
{
_startValue = Value;
((IInputElement) sender).CaptureMouse();
_mouseDragStartPoint = e.GetPosition((IInputElement) sender);
}
private void InputMouseUp(object sender, MouseButtonEventArgs e)
{
var position = e.GetPosition((IInputElement) sender);
if (position == _mouseDragStartPoint)
DisplayInput();
((IInputElement) sender).ReleaseMouseCapture();
}
private void InputMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
// 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);
}
}
private void InputLostFocus(object sender, RoutedEventArgs e)
{
DisplayDragHandle();
}
private void InputKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
DisplayDragHandle();
else if (e.Key == Key.Escape)
{
Input.Text = _startValue.ToString();
DisplayDragHandle();
}
}
private void DisplayInput()
{
DragHandle.Visibility = Visibility.Collapsed;
Input.Visibility = Visibility.Visible;
Input.Focus();
Input.SelectAll();
}
private void DisplayDragHandle()
{
Input.Visibility = Visibility.Collapsed;
DragHandle.Visibility = Visibility.Visible;
}
private void Input_OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
}
}
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Humanizer.Core" version="2.7.9" targetFramework="net472" />
<package id="MaterialDesignColors" version="1.2.0" targetFramework="net472" />