mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
Added Ambilight-Example-Project
This commit is contained in:
1 parent
662085a346
commit
74824e3363
33 files changed
+1609
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Example_Ambilight_full.TakeAsIs.UI
|
||||
{
|
||||
public class ActionCommand : ICommand
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly Func<bool> _canExecute;
|
||||
private readonly Action _command;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ActionCommand(Action command, Func<bool> canExecute = null)
|
||||
{
|
||||
this._command = command;
|
||||
this._canExecute = canExecute;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return _canExecute?.Invoke() ?? true;
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_command?.Invoke();
|
||||
}
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<UserControl x:Class="Example_Ambilight_full.TakeAsIs.UI.ConfigView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:helper="clr-namespace:Example_Ambilight_full.TakeAsIs.Helper"
|
||||
xmlns:model="clr-namespace:Example_Ambilight_full.TakeAsIs.Model"
|
||||
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib"
|
||||
xmlns:ui="clr-namespace:Example_Ambilight_full.TakeAsIs.UI">
|
||||
|
||||
<!-- Quick'n'Dirty - you really shouldn't implement a View like this ... -->
|
||||
|
||||
<UserControl.Resources>
|
||||
<ui:EnumDescriptionConverter x:Key="HEnumDescriptionConverter" />
|
||||
|
||||
<ObjectDataProvider x:Key="SmoothModeEnumValues" ObjectType="{x:Type system:Enum}" MethodName="GetValues">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="model:SmoothMode" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
<ObjectDataProvider x:Key="AmbienceCreatorTypeValues" ObjectType="{x:Type system:Enum}" MethodName="GetValues">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="model:AmbienceCreatorType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={StaticResource HEnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin" Value="0,0,4,0" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="controls:NumericUpDown" BasedOn="{StaticResource {x:Type controls:NumericUpDown}}">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
|
||||
<Border Padding="16" Background="#CECECE" BorderBrush="#2E2E2E" BorderThickness="2">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="160" />
|
||||
<ColumnDefinition Width="32" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="160" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
<RowDefinition Height="32" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Update-Rate-->
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Update-Rate (FPS):" />
|
||||
<controls:NumericUpDown Grid.Row="0" Grid.Column="1"
|
||||
Minimum="1" Maximum="60"
|
||||
Value="{Binding Path=UpdateRate, Mode=TwoWay}" />
|
||||
|
||||
<!-- AmbienceCreatorType -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Ambilight-Mode:"/>
|
||||
<ComboBox Grid.Row="1" Grid.Column="1"
|
||||
ItemsSource="{Binding Source={StaticResource AmbienceCreatorTypeValues}}"
|
||||
SelectedItem="{Binding Path=Settings.AmbienceCreatorType}" />
|
||||
|
||||
<!-- MirrorAmount & Downsampling-->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="Mirrored Amount (%):" />
|
||||
<controls:NumericUpDown Grid.Row="2" Grid.Column="1"
|
||||
Minimum="0" Maximum="100"
|
||||
Value="{Binding Path=Settings.MirroredAmount, Mode=TwoWay}" />
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="3" Text="Downsampling:" />
|
||||
<controls:NumericUpDown Grid.Row="2" Grid.Column="4"
|
||||
Minimum="1" Maximum="20"
|
||||
Value="{Binding Path=Settings.Downsampling, Mode=TwoWay}" />
|
||||
|
||||
<!-- SmoothMode -->
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="Smoothing:" />
|
||||
<ComboBox Grid.Row="3" Grid.Column="1"
|
||||
ItemsSource="{Binding Source={StaticResource SmoothModeEnumValues}}"
|
||||
SelectedItem="{Binding Path=Settings.SmoothMode}" />
|
||||
|
||||
<!-- FlipMode -->
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" Text="Flip Horizontal:" />
|
||||
<CheckBox Grid.Row="4" Grid.Column="1"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:FlipMode.Horizontal}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.FlipMode}" />
|
||||
|
||||
<TextBlock Grid.Row="4" Grid.Column="3" Text="Flip Vertical:" />
|
||||
<CheckBox Grid.Row="4" Grid.Column="4"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:FlipMode.Vertical}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.FlipMode}" />
|
||||
|
||||
<!-- Horizontal offsets -->
|
||||
<TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="4" FontWeight="Black" Text="Offset" />
|
||||
|
||||
<TextBlock Grid.Row="6" Grid.Column="0" Text="Left:" />
|
||||
<controls:NumericUpDown Grid.Row="6" Grid.Column="1"
|
||||
Minimum="0"
|
||||
Value="{Binding Path=Settings.OffsetLeft, Mode=TwoWay}" />
|
||||
|
||||
<TextBlock Grid.Row="6" Grid.Column="3" Text="Right:" />
|
||||
<controls:NumericUpDown Grid.Row="6" Grid.Column="4"
|
||||
Minimum="0"
|
||||
Value="{Binding Path=Settings.OffsetRight, Mode=TwoWay}" />
|
||||
|
||||
<!-- Vertical offsets -->
|
||||
<TextBlock Grid.Row="7" Grid.Column="0" Text="Top:" />
|
||||
<controls:NumericUpDown Grid.Row="7" Grid.Column="1" Minimum="0"
|
||||
Value="{Binding Path=Settings.OffsetTop, Mode=TwoWay}" />
|
||||
|
||||
<TextBlock Grid.Row="7" Grid.Column="3" Text="Bottom:"/>
|
||||
<controls:NumericUpDown Grid.Row="7" Grid.Column="4" Minimum="0"
|
||||
Value="{Binding Path=Settings.OffsetBottom, Mode=TwoWay}" />
|
||||
|
||||
<!-- Horizontal BlackBar-detection -->
|
||||
<TextBlock Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="4" FontWeight="Black" Text="Black-Bar detection" />
|
||||
|
||||
<TextBlock Grid.Row="9" Grid.Column="0" Text="Left:" />
|
||||
<CheckBox Grid.Row="9" Grid.Column="1"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:BlackBarDetectionMode.Left}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.BlackBarDetectionMode}" />
|
||||
|
||||
<TextBlock Grid.Row="9" Grid.Column="3" Text="Right:" />
|
||||
<CheckBox Grid.Row="9" Grid.Column="4"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:BlackBarDetectionMode.Right}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.BlackBarDetectionMode}" />
|
||||
|
||||
<!-- Vertical BlackBar-detection -->
|
||||
<TextBlock Grid.Row="10" Grid.Column="0" Text="Top:" />
|
||||
<CheckBox Grid.Row="10" Grid.Column="1"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:BlackBarDetectionMode.Top}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.BlackBarDetectionMode}" />
|
||||
|
||||
<TextBlock Grid.Row="10" Grid.Column="3" Text="Bottom:" />
|
||||
<CheckBox Grid.Row="10" Grid.Column="4"
|
||||
helper:CheckboxEnumFlagHelper.Value="{x:Static model:BlackBarDetectionMode.Bottom}"
|
||||
helper:CheckboxEnumFlagHelper.Flags="{Binding Path=Settings.BlackBarDetectionMode}" />
|
||||
|
||||
<Button Grid.Row="12" Grid.Column="4" Command="{Binding ExitCommand}" Content="Exit" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Example_Ambilight_full.TakeAsIs.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ConfigView.xaml
|
||||
/// </summary>
|
||||
public partial class ConfigView : UserControl
|
||||
{
|
||||
public ConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using CUE.NET;
|
||||
|
||||
namespace Example_Ambilight_full.TakeAsIs.UI
|
||||
{
|
||||
public class ConfigViewModel
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public AmbilightSettings Settings { get; }
|
||||
|
||||
public int UpdateRate
|
||||
{
|
||||
get { return (int)Math.Round(1f / CueSDK.UpdateFrequency); }
|
||||
set { CueSDK.UpdateFrequency = 1f / value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
|
||||
private ActionCommand _exitCommand;
|
||||
public ActionCommand ExitCommand => _exitCommand ?? (_exitCommand = new ActionCommand(Exit));
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ConfigViewModel(AmbilightSettings settings)
|
||||
{
|
||||
this.Settings = settings;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void Exit()
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Example_Ambilight_full.TakeAsIs.UI
|
||||
{
|
||||
public class EnumDescriptionConverter : IValueConverter
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Enum myEnum = (Enum)value;
|
||||
string description = GetEnumDescription(myEnum);
|
||||
return description;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string GetEnumDescription(Enum enumObj)
|
||||
{
|
||||
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
||||
object[] attribArray = fieldInfo.GetCustomAttributes(false);
|
||||
|
||||
if (attribArray.Length == 0)
|
||||
return enumObj.ToString();
|
||||
|
||||
DescriptionAttribute attrib = attribArray[0] as DescriptionAttribute;
|
||||
return attrib?.Description;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:ui="clr-namespace:Example_Ambilight_full.TakeAsIs.UI">
|
||||
|
||||
<tb:TaskbarIcon x:Key="Taskbar"
|
||||
ToolTipText="Keyboard-Ambilight"
|
||||
IconSource="../../Resources/ambilight.ico"
|
||||
PopupActivation="All">
|
||||
|
||||
<tb:TaskbarIcon.TrayPopup>
|
||||
<ui:ConfigView />
|
||||
</tb:TaskbarIcon.TrayPopup>
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in new issue
Block a user