-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple inputs support for plugins. Enums supported in plugin GUI. A…
…xis merger plugin implemented
- Loading branch information
Showing
21 changed files
with
224 additions
and
29 deletions.
There are no files selected for viewing
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,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HidWizards.UCR.Core.Models.Binding; | ||
|
||
namespace HidWizards.UCR.Core.Models | ||
{ | ||
public class CallbackMultiplexer | ||
{ | ||
private DeviceBinding.ValueChanged _mappingUpdate; | ||
private readonly int _index; | ||
private readonly List<long> _cache; | ||
|
||
public CallbackMultiplexer(List<long> cache, int index, DeviceBinding.ValueChanged mappingUpdate) | ||
{ | ||
_mappingUpdate = mappingUpdate; | ||
_index = index; | ||
_cache = cache; | ||
} | ||
|
||
public void Update(long value) | ||
{ | ||
_cache[_index] = value; | ||
_mappingUpdate(value); | ||
} | ||
|
||
~CallbackMultiplexer() | ||
{ | ||
_mappingUpdate = null; | ||
} | ||
} | ||
} |
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
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,71 @@ | ||
using System; | ||
using HidWizards.UCR.Core.Attributes; | ||
using HidWizards.UCR.Core.Models; | ||
using HidWizards.UCR.Core.Models.Binding; | ||
using HidWizards.UCR.Core.Utilities; | ||
|
||
namespace HidWizards.UCR.Plugins.Remapper | ||
{ | ||
[Plugin("Axis merger")] | ||
[PluginInput(DeviceBindingCategory.Range, "Axis high")] | ||
[PluginInput(DeviceBindingCategory.Range, "Axis low")] | ||
[PluginOutput(DeviceBindingCategory.Range, "Axis")] | ||
public class AxisMerger : Plugin | ||
{ | ||
[PluginGui("Dead zone", ColumnOrder = 1)] | ||
public int DeadZone { get; set; } | ||
|
||
[PluginGui("Mode", ColumnOrder = 0)] | ||
public AxisMergerMode Mode { get; set; } | ||
|
||
[PluginGui("Invert high", RowOrder = 1)] | ||
public bool InvertHigh { get; set; } | ||
|
||
[PluginGui("Invert low", RowOrder = 2)] | ||
public bool InvertLow { get; set; } | ||
|
||
public AxisMerger() | ||
{ | ||
DeadZone = 0; | ||
} | ||
|
||
public override void Update(params long[] values) | ||
{ | ||
var valueHigh = values[0]; | ||
var valueLow = values[1]; | ||
long valueOutput; | ||
|
||
if (InvertHigh) valueHigh *= -1; | ||
if (InvertLow) valueLow *= -1; | ||
|
||
switch (Mode) | ||
{ | ||
case AxisMergerMode.Average: | ||
valueOutput = (valueHigh + valueLow) / 2L; | ||
break; | ||
case AxisMergerMode.Greatest: | ||
valueOutput = Math.Abs(valueHigh) > Math.Abs(valueLow) ? valueHigh : valueLow; | ||
break; | ||
case AxisMergerMode.Sum: | ||
valueOutput = valueHigh + valueLow; | ||
break; | ||
default: | ||
valueOutput = 0L; | ||
break; | ||
} | ||
|
||
if (DeadZone != 0) | ||
{ | ||
valueOutput = Functions.ApplyRangeDeadZone(valueOutput, DeadZone); | ||
} | ||
WriteOutput(0, valueOutput); | ||
} | ||
|
||
public enum AxisMergerMode | ||
{ | ||
Average, | ||
Greatest, | ||
Sum | ||
} | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
UCR.Plugins/AxisToButton/AxisToButton.cs → UCR.Plugins/Remapper/AxisToButton.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
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
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
5 changes: 2 additions & 3 deletions
5
UCR.Plugins/MouseToAxis/MouseToAxis.cs → UCR.Plugins/Remapper/MouseToAxis.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
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
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
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
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,14 @@ | ||
<UserControl x:Class="HidWizards.UCR.Views.Controls.EnumControl" | ||
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:HidWizards.UCR.Views.Controls" | ||
mc:Ignorable="d" | ||
d:DesignHeight="100" d:DesignWidth="300"> | ||
<Grid> | ||
<GroupBox Header="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=PluginProperty.Name}" Width="Auto" Padding="5"> | ||
<ComboBox x:Name="EnumComboBox" Width="200" SelectionChanged="EnumComboBox_OnSelectionChanged" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Enums}"/> | ||
</GroupBox> | ||
</Grid> | ||
</UserControl> |
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,61 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using HidWizards.UCR.Core.Models; | ||
using HidWizards.UCR.ViewModels; | ||
|
||
namespace HidWizards.UCR.Views.Controls | ||
{ | ||
public partial class EnumControl : UserControl | ||
{ | ||
public static readonly DependencyProperty PluginPropertyProperty = DependencyProperty.Register("PluginProperty", typeof(PluginProperty), typeof(EnumControl), new PropertyMetadata(default(PluginProperty))); | ||
|
||
public PluginProperty PluginProperty | ||
{ | ||
get { return (PluginProperty)GetValue(PluginPropertyProperty); } | ||
set { SetValue(PluginPropertyProperty, value); } | ||
} | ||
|
||
public ObservableCollection<ComboBoxItemViewModel> Enums { get; set; } | ||
|
||
public EnumControl() | ||
{ | ||
InitializeComponent(); | ||
Loaded += UserControl_Loaded; | ||
} | ||
|
||
private void UserControl_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
if (PluginProperty == null) return; | ||
PopulateEnums(); | ||
} | ||
|
||
private void PopulateEnums() | ||
{ | ||
Enums = new ObservableCollection<ComboBoxItemViewModel>(); | ||
ComboBoxItemViewModel selectedEnum = null; | ||
foreach (var enumValue in Enum.GetValues(PluginProperty.Property.GetType())) | ||
{ | ||
var comboBoxItem = new ComboBoxItemViewModel(enumValue.ToString(), enumValue); | ||
Enums.Add(comboBoxItem); | ||
if (enumValue.Equals(PluginProperty.Property)) selectedEnum = comboBoxItem; | ||
} | ||
EnumComboBox.ItemsSource = Enums; | ||
if (selectedEnum != null) | ||
{ | ||
EnumComboBox.SelectedItem = selectedEnum; | ||
} | ||
else | ||
{ | ||
EnumComboBox.SelectedIndex = 0; | ||
} | ||
} | ||
|
||
|
||
private void EnumComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) | ||
{ | ||
PluginProperty.Property = ((ComboBoxItemViewModel) EnumComboBox.SelectedItem).Value; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.