-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inspector: Add new AdvancedSlider control
Replace the old RangeEditor and TextBox numeric editors with the new advanced slider control. The user can use a combination of ALT, CTRL and SHIFT keys to adjust the rate of change. The user can also double click the value to edit the value numerically. Signed-off-by: Axel Gembe <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,160 additions
and
12 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Gemini.Modules.Inspector/Conventions/AdvancedSliderPropertyEditorBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using Gemini.Modules.Inspector.Inspectors; | ||
|
||
namespace Gemini.Modules.Inspector.Conventions | ||
{ | ||
public class AdvancedSliderPropertyEditorBuilder : PropertyEditorBuilder | ||
{ | ||
public override bool IsApplicable(PropertyDescriptor propertyDescriptor) | ||
{ | ||
var isNumberType = propertyDescriptor.PropertyType == typeof(int) | ||
|| propertyDescriptor.PropertyType == typeof(double) | ||
|| propertyDescriptor.PropertyType == typeof(float); | ||
|
||
return isNumberType; | ||
} | ||
|
||
public override IEditor BuildEditor(PropertyDescriptor propertyDescriptor) | ||
{ | ||
if (propertyDescriptor.PropertyType == typeof(int)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<int>() { | ||
Speed = 1 | ||
}; | ||
} | ||
|
||
if (propertyDescriptor.PropertyType == typeof(double)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<double>() { | ||
Speed = 0.1 | ||
}; | ||
} | ||
|
||
if (propertyDescriptor.PropertyType == typeof(float)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<float>() { | ||
Speed = 0.1f | ||
}; | ||
} | ||
|
||
throw new InvalidOperationException(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Gemini.Modules.Inspector/Conventions/AdvancedSliderRangePropertyEditorBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using Gemini.Modules.Inspector.Inspectors; | ||
|
||
namespace Gemini.Modules.Inspector.Conventions | ||
{ | ||
public class AdvancedSliderRangePropertyEditorBuilder : PropertyEditorBuilder | ||
{ | ||
public override bool IsApplicable(PropertyDescriptor propertyDescriptor) | ||
{ | ||
var isNumberType = propertyDescriptor.PropertyType == typeof(int) | ||
|| propertyDescriptor.PropertyType == typeof(double) | ||
|| propertyDescriptor.PropertyType == typeof(float); | ||
|
||
if (!isNumberType) | ||
return false; | ||
|
||
return propertyDescriptor.Attributes.Cast<Attribute>().Any(x => x is RangeAttribute); | ||
} | ||
|
||
public override IEditor BuildEditor(PropertyDescriptor propertyDescriptor) | ||
{ | ||
var rangeAttribute = propertyDescriptor.Attributes | ||
.Cast<Attribute>().OfType<RangeAttribute>() | ||
.First(); | ||
|
||
if (propertyDescriptor.PropertyType == typeof(int)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<int>((int) rangeAttribute.Minimum, (int) rangeAttribute.Maximum) { | ||
Speed = 1 | ||
}; | ||
} | ||
|
||
if (propertyDescriptor.PropertyType == typeof(double)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<double>((double) rangeAttribute.Minimum, (double) rangeAttribute.Maximum) { | ||
Speed = 0.1 | ||
}; | ||
} | ||
|
||
if (propertyDescriptor.PropertyType == typeof(float)) | ||
{ | ||
return new AdvancedSliderEditorViewModel<float>((float) rangeAttribute.Minimum, (float) rangeAttribute.Maximum) { | ||
Speed = 0.1f | ||
}; | ||
} | ||
|
||
throw new InvalidOperationException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Gemini.Modules.Inspector/Inspectors/AdvancedSliderEditorView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<UserControl | ||
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:cal="http://www.caliburnproject.org" | ||
xmlns:local="clr-namespace:Gemini.Modules.Inspector.Inspectors" | ||
xmlns:Controls="clr-namespace:Gemini.Framework.Controls;assembly=Gemini" | ||
x:Class="Gemini.Modules.Inspector.Inspectors.AdvancedSliderEditorView" | ||
mc:Ignorable="d" d:DesignWidth="300"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Controls:AdvancedSlider x:Name="slider" Grid.Column="0" Grid.RowSpan="2" | ||
BorderThickness="1" | ||
Value="{Binding Path=Value, Mode=TwoWay}" | ||
Type="{Binding Path=Type}" | ||
ValueType="{Binding Path=ValueType}" | ||
ValueMax="{Binding Path=Maximum}" | ||
ValueMin="{Binding Path=Minimum}" | ||
Speed="{Binding Path=Speed}" | ||
ValueFormat="{Binding Path=ValueFormat}" | ||
MouseCaptured="{Binding Path=MouseCaptured, Mode=OneWayToSource}" | ||
/> | ||
|
||
<Controls:RepeatingButton Grid.Column="1" Grid.Row="0" cal:Message.Attach="Up" BorderBrush="Transparent" Padding="0"> | ||
<Path Fill="{DynamicResource EnvironmentToolWindowText}" Data="M 0 6 L 12 6 L 6 0 Z"/> | ||
</Controls:RepeatingButton> | ||
<Controls:RepeatingButton Grid.Column="1" Grid.Row="1" cal:Message.Attach="Down" BorderBrush="Transparent" Padding="0"> | ||
<Path Fill="{DynamicResource EnvironmentToolWindowText}" Data="M 0 0 L 6 6 L 12 0 Z"/> | ||
</Controls:RepeatingButton> | ||
</Grid> | ||
</UserControl> |
15 changes: 15 additions & 0 deletions
15
src/Gemini.Modules.Inspector/Inspectors/AdvancedSliderEditorView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace Gemini.Modules.Inspector.Inspectors | ||
{ | ||
/// <summary> | ||
/// Interaction logic for AdvancedSliderEditorView.xaml | ||
/// </summary> | ||
public partial class AdvancedSliderEditorView : UserControl | ||
{ | ||
public AdvancedSliderEditorView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
src/Gemini.Modules.Inspector/Inspectors/AdvancedSliderEditorViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
|
||
using Caliburn.Micro; | ||
|
||
using Gemini.Framework.Controls; | ||
using Gemini.Framework.Util; | ||
|
||
namespace Gemini.Modules.Inspector.Inspectors | ||
{ | ||
public class AdvancedSliderEditorViewModel<TValue> : SelectiveUndoEditorBase<TValue>, ILabelledInspector, IViewAware where TValue : IComparable<TValue> | ||
{ | ||
private static readonly string _defaultValueFormat = "{0:0.#####}"; | ||
|
||
public AdvancedSliderEditorViewModel() | ||
{ | ||
_valueFormat = _defaultValueFormat; | ||
_valueType = typeof(TValue); | ||
_type = AdvancedSliderBase.DisplayType.Number; | ||
} | ||
|
||
public AdvancedSliderEditorViewModel(TValue min, TValue max) | ||
{ | ||
_minimum = min; | ||
_maximum = max; | ||
_valueFormat = _defaultValueFormat; | ||
_valueType = typeof(TValue); | ||
_type = AdvancedSliderBase.DisplayType.Bar; | ||
} | ||
|
||
private TValue _minimum; | ||
|
||
public TValue Minimum | ||
{ | ||
get { return _minimum; } | ||
set | ||
{ | ||
_minimum = value; | ||
NotifyOfPropertyChange(() => Minimum); | ||
} | ||
} | ||
|
||
private TValue _maximum; | ||
|
||
public TValue Maximum | ||
{ | ||
get { return _maximum; } | ||
set | ||
{ | ||
_maximum = value; | ||
NotifyOfPropertyChange(() => Maximum); | ||
} | ||
} | ||
|
||
private TValue _speed; | ||
|
||
public TValue Speed | ||
{ | ||
get { return _speed; } | ||
set | ||
{ | ||
_speed = value; | ||
NotifyOfPropertyChange(() => Speed); | ||
} | ||
} | ||
|
||
private bool _mouseCaptured; | ||
|
||
public bool MouseCaptured | ||
{ | ||
get { return _mouseCaptured; } | ||
set | ||
{ | ||
if (_mouseCaptured == value) | ||
return; | ||
|
||
_mouseCaptured = value; | ||
|
||
if (value) | ||
OnBeginEdit(); | ||
else | ||
OnEndEdit(); | ||
} | ||
} | ||
|
||
private string _valueFormat; | ||
|
||
public string ValueFormat | ||
{ | ||
get { return _valueFormat; } | ||
set | ||
{ | ||
_valueFormat = value; | ||
NotifyOfPropertyChange(() => ValueFormat); | ||
} | ||
} | ||
|
||
private Type _valueType; | ||
|
||
public Type ValueType | ||
{ | ||
get { return _valueType; } | ||
set | ||
{ | ||
_valueType = value; | ||
NotifyOfPropertyChange(() => ValueType); | ||
} | ||
} | ||
|
||
private AdvancedSliderBase.DisplayType _type; | ||
|
||
public AdvancedSliderBase.DisplayType Type | ||
{ | ||
get { return _type; } | ||
|
||
set | ||
{ | ||
if (Equals(_type, value)) | ||
return; | ||
|
||
_type = value; | ||
|
||
NotifyOfPropertyChange(() => Type); | ||
} | ||
} | ||
|
||
public void Up() | ||
{ | ||
_view.slider.ApplyValueChange(SpeedMultiplier.Get()); | ||
} | ||
|
||
public void Down() | ||
{ | ||
_view.slider.ApplyValueChange(-SpeedMultiplier.Get()); | ||
} | ||
|
||
private AdvancedSliderEditorView _view; | ||
|
||
public event EventHandler<ViewAttachedEventArgs> ViewAttached; | ||
|
||
public void AttachView(object view, object context = null) | ||
{ | ||
_view = (AdvancedSliderEditorView) view; | ||
ViewAttached?.Invoke(this, new ViewAttachedEventArgs() { View = view, Context = context }); | ||
} | ||
|
||
public object GetView(object context = null) | ||
{ | ||
return _view; | ||
} | ||
} | ||
} |
Oops, something went wrong.