1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 08:48:30 +00:00

Added Ambilight-Example-Project

This commit is contained in:
Darth Affe 2016-11-06 00:32:40 +01:00
parent 662085a346
commit 74824e3363
33 changed files with 1609 additions and 0 deletions

View File

@ -32,6 +32,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AudioAnalyzer", "AudioAnaly
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example_AudioAnalyzer_full", "Examples\AudioAnalyzer\Example_AudioAnalyzer_full\Example_AudioAnalyzer_full.csproj", "{E06B4E1D-9735-4CB4-BC11-9ECDF27A0972}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ambilight", "Ambilight", "{1ABADCA4-AC96-4E9F-91C5-232EB824D6DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example_Ambilight_full", "Examples\Ambilight\Example_Ambilight_full\Example_Ambilight_full.csproj", "{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -50,6 +54,10 @@ Global
{E06B4E1D-9735-4CB4-BC11-9ECDF27A0972}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E06B4E1D-9735-4CB4-BC11-9ECDF27A0972}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E06B4E1D-9735-4CB4-BC11-9ECDF27A0972}.Release|Any CPU.Build.0 = Release|Any CPU
{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -61,5 +69,7 @@ Global
{2F99124B-FAED-432D-B797-45566D373411} = {D69EF6D8-68FF-4C56-B5CB-253971B1DF91}
{BE16A0BF-6794-4718-AF27-F2A50078D880} = {1F52DDC9-E9D0-4A7B-8E78-930528203EE6}
{E06B4E1D-9735-4CB4-BC11-9ECDF27A0972} = {BE16A0BF-6794-4718-AF27-F2A50078D880}
{1ABADCA4-AC96-4E9F-91C5-232EB824D6DE} = {1F52DDC9-E9D0-4A7B-8E78-930528203EE6}
{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C} = {1ABADCA4-AC96-4E9F-91C5-232EB824D6DE}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using CUE.NET.Brushes;
using Example_Ambilight_full.TakeAsIs;
using Example_Ambilight_full.TakeAsIs.Model;
using Example_Ambilight_full.TakeAsIs.Model.Extensions;
using Example_Ambilight_full.TakeAsIs.ScreenCapturing;
namespace Example_Ambilight_full
{
public abstract class AbstractAmbilightBrush : AbstractBrush
{
#region Properties & Fields
protected readonly IScreenCapture ScreenCapture;
protected readonly AmbilightSettings Settings;
protected byte[] ScreenPixelData;
protected int SourceWidth;
protected int SourceHeight;
protected int OffsetLeft;
protected int OffsetRight;
protected int OffsetTop;
protected int OffsetBottom;
protected int EffectiveSourceWidth;
protected int EffectiveSourceHeight;
protected int Increment;
protected float KeyWidthProportion;
protected float KeyHeightProportion;
#endregion
#region Constructors
public AbstractAmbilightBrush(IScreenCapture screenCapture, AmbilightSettings settings)
{
this.ScreenCapture = screenCapture;
this.Settings = settings;
}
#endregion
#region Methods
public override void PerformRender(RectangleF rectangle, IEnumerable<BrushRenderTarget> renderTargets)
{
ScreenPixelData = ScreenCapture.CaptureScreen();
SourceWidth = ScreenCapture.Width;
SourceHeight = ScreenCapture.Height;
OffsetLeft = Settings.OffsetLeft + (Settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Left)
? ScreenPixelData.DetectBlackBarLeft(SourceWidth, SourceHeight, Settings.OffsetLeft, Settings.OffsetRight, Settings.OffsetTop, Settings.OffsetBottom)
: 0);
OffsetRight = Settings.OffsetRight + (Settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Right)
? ScreenPixelData.DetectBlackBarRight(SourceWidth, SourceHeight, Settings.OffsetLeft, Settings.OffsetRight, Settings.OffsetTop, Settings.OffsetBottom)
: 0);
OffsetTop = Settings.OffsetTop + (Settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Top)
? ScreenPixelData.DetectBlackBarTop(SourceWidth, SourceHeight, Settings.OffsetLeft, Settings.OffsetRight, Settings.OffsetTop, Settings.OffsetBottom)
: 0);
OffsetBottom = Settings.OffsetBottom + (Settings.BlackBarDetectionMode.HasFlag(BlackBarDetectionMode.Bottom)
? ScreenPixelData.DetectBlackBarBottom(SourceWidth, SourceHeight, Settings.OffsetLeft, Settings.OffsetRight, Settings.OffsetTop, Settings.OffsetBottom)
: 0);
EffectiveSourceWidth = SourceWidth - OffsetLeft - OffsetRight;
EffectiveSourceHeight = (int)Math.Round((SourceHeight - OffsetTop - OffsetBottom) * (Settings.MirroredAmount / 100.0));
Increment = Math.Max(1, Math.Min(20, Settings.Downsampling));
KeyWidthProportion = EffectiveSourceWidth / rectangle.Width;
KeyHeightProportion = EffectiveSourceHeight / rectangle.Height;
Opacity = Settings.SmoothMode == SmoothMode.Low ? 0.25f : (Settings.SmoothMode == SmoothMode.Medium ? 0.075f : (Settings.SmoothMode == SmoothMode.High ? 0.025f : 1f /*None*/));
base.PerformRender(rectangle, renderTargets);
}
#endregion
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Drawing;
using CUE.NET;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic.Enums;
using Example_Ambilight_full.TakeAsIs;
using Example_Ambilight_full.TakeAsIs.Model;
using Example_Ambilight_full.TakeAsIs.ScreenCapturing;
namespace Example_Ambilight_full
{
public class Ambilight
{
#region Properties & Fields
private readonly IScreenCapture _screenCapture;
private readonly AmbilightSettings _settings;
#endregion
#region Constructors
public Ambilight(IScreenCapture screenCapture, AmbilightSettings settings)
{
this._screenCapture = screenCapture;
this._settings = settings;
}
#endregion
#region Methods
public bool Initialize()
{
try
{
CueSDK.Initialize();
CueSDK.UpdateMode = UpdateMode.Continuous;
CueSDK.UpdateFrequency = 1 / 20f;
SetAmbilightBrush();
_settings.AmbienceCreatorTypeChanged += (sender, args) => SetAmbilightBrush();
}
catch { return false; }
return true;
}
private void SetAmbilightBrush()
{
IBrush ambilightBrush;
switch (_settings.AmbienceCreatorType)
{
case AmbienceCreatorType.Mirror:
ambilightBrush = new AmbilightMirrorBrush(_screenCapture, _settings);
break;
case AmbienceCreatorType.Extend:
ambilightBrush = new AmbilightExtendBrush(_screenCapture, _settings);
break;
default:
ambilightBrush = new SolidColorBrush(Color.Black);
break;
}
CueSDK.KeyboardSDK.Brush = ambilightBrush;
}
#endregion
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Drawing;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic;
using Example_Ambilight_full.TakeAsIs;
using Example_Ambilight_full.TakeAsIs.Model;
using Example_Ambilight_full.TakeAsIs.ScreenCapturing;
namespace Example_Ambilight_full
{
public class AmbilightExtendBrush : AbstractAmbilightBrush
{
#region Constructors
public AmbilightExtendBrush(IScreenCapture screenCapture, AmbilightSettings settings)
: base(screenCapture, settings)
{ }
#endregion
#region Methods
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{
//TODO DarthAffe 05.11.2016: The Key-Rectangle is missing in the render-target, I'll fix that with a future version of CUE.NET. Until then we consider the size of each key to be 10x10mm.
float keyWidth = 10;
int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth));
int r = 0;
int g = 0;
int b = 0;
int counter = 0;
int widthOffset = Settings.FlipMode.HasFlag(FlipMode.Horizontal)
? (int)((SourceWidth - OffsetRight) - (KeyWidthProportion * (renderTarget.Point.X + (keyWidth / 2f))))
: (int)(OffsetLeft + (KeyWidthProportion * (renderTarget.Point.X - (keyWidth / 2f))));
int heightOffset = SourceHeight - OffsetBottom - EffectiveSourceHeight; // DarthAffe 05.11.2016: Vertical flipping doesn't mather in Extend-Mode
// DarthAffe 06.11.2016: Validate offsets - rounding errors might cause problems (heightOffset is safe calculated -> no need to validate)
widthOffset = Math.Max(0, Math.Min(SourceWidth - widthPixels, widthOffset));
for (int y = 0; y < EffectiveSourceHeight; y += Increment)
for (int x = 0; x < widthPixels; x += Increment)
{
int offset = ((((heightOffset + y) * SourceWidth) + widthOffset + x) * 4);
b += ScreenPixelData[offset];
g += ScreenPixelData[offset + 1];
r += ScreenPixelData[offset + 2];
counter++;
}
return new CorsairColor((byte)(r / counter), (byte)(g / counter), (byte)(b / counter));
}
#endregion
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Drawing;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic;
using Example_Ambilight_full.TakeAsIs;
using Example_Ambilight_full.TakeAsIs.Model;
using Example_Ambilight_full.TakeAsIs.ScreenCapturing;
namespace Example_Ambilight_full
{
public class AmbilightMirrorBrush : AbstractAmbilightBrush
{
#region Constructors
public AmbilightMirrorBrush(IScreenCapture screenCapture, AmbilightSettings settings)
: base(screenCapture, settings)
{ }
#endregion
#region Methods
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{
//TODO DarthAffe 05.11.2016: The Key-Rectangle is missing in the render-target, I'll fix that with a future version of CUE.NET. Until then we consider the size of each key to be 10x10mm.
float keyWidth = 10;
float keyHeight = 10;
int widthPixels = Math.Max(1, (int)(KeyWidthProportion * keyWidth));
int heightPixels = Math.Max(1, (int)(KeyHeightProportion * keyHeight));
int r = 0;
int g = 0;
int b = 0;
int counter = 0;
int widthOffset = Settings.FlipMode.HasFlag(FlipMode.Horizontal)
? ((SourceWidth - OffsetRight) - (int)(KeyWidthProportion * (renderTarget.Point.X + (keyWidth / 2f))))
: (OffsetLeft + (int)(KeyWidthProportion * (renderTarget.Point.X - (keyWidth / 2f))));
int heightOffset = Settings.FlipMode.HasFlag(FlipMode.Vertical)
? ((SourceHeight - OffsetBottom) - (int)(KeyHeightProportion * (renderTarget.Point.Y + (keyHeight / 2f))))
: ((SourceHeight - OffsetBottom - EffectiveSourceHeight) + (int)(KeyHeightProportion * (renderTarget.Point.Y - (keyHeight / 2f))));
// DarthAffe 06.11.2016: Validate offsets - rounding errors might cause problems
widthOffset = Math.Max(0, Math.Min(SourceWidth - widthPixels, widthOffset));
heightOffset = Math.Max(0, Math.Min(EffectiveSourceHeight - heightPixels, heightOffset));
for (int y = 0; y < heightPixels; y += Increment)
for (int x = 0; x < widthPixels; x += Increment)
{
int offset = ((((heightOffset + y) * SourceWidth) + widthOffset + x) * 4);
b += ScreenPixelData[offset];
g += ScreenPixelData[offset + 1];
r += ScreenPixelData[offset + 2];
counter++;
}
return new CorsairColor((byte)(r / counter), (byte)(g / counter), (byte)(b / counter));
}
#endregion
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>

View File

@ -0,0 +1,17 @@
<Application x:Class="Example_Ambilight_full.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="TakeAsIs/UI/Taskbar.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -0,0 +1,67 @@
using System;
using System.Windows;
using Example_Ambilight_full.TakeAsIs;
using Example_Ambilight_full.TakeAsIs.Helper;
using Example_Ambilight_full.TakeAsIs.ScreenCapturing;
using Example_Ambilight_full.TakeAsIs.UI;
using Hardcodet.Wpf.TaskbarNotification;
namespace Example_Ambilight_full
{
public partial class App : Application
{
#region Constants
private const string PATH_SETTINGS = "Settings.xaml";
#endregion
#region Properties & Fields
private TaskbarIcon _taskBar;
private AmbilightSettings _settings;
private Ambilight _ambilight;
#endregion
#region Methods
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
try
{
_settings = SerializationHelper.LoadObjectFromFile<AmbilightSettings>(PATH_SETTINGS) ??
new AmbilightSettings();
IScreenCapture screenCapture = new DX9ScreenCapture();
// DarthAffe 05.11.2016: This could be done way cleaner ...
_taskBar = FindResource("Taskbar") as TaskbarIcon;
FrameworkElement configView = _taskBar?.TrayPopup as ConfigView;
if (configView == null)
Shutdown();
else
configView.DataContext = new ConfigViewModel(_settings);
_ambilight = new Ambilight(screenCapture, _settings);
if (!_ambilight.Initialize())
throw new ApplicationException();
}
catch
{
MessageBox.Show("An error occured while starting the Keyboard-Ambilight.\r\nPlease double check if CUE is running and 'Enable SDK' is checked.", "Can't start Keyboard-Ambilight");
Shutdown();
}
}
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
SerializationHelper.SaveObjectToFile(_settings, PATH_SETTINGS);
}
#endregion
}
}

View File

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6D7BAF89-A705-4FFA-A3A2-AF93EC3A909C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Example_Ambilight_full</RootNamespace>
<AssemblyName>Example_Ambilight_full</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\ambilight.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CUE.NET, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\CUE.NET.1.1.0.2\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MahApps.Metro.1.4.0-ALPHA026\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SharpDX, Version=3.1.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\SharpDX.3.1.1\lib\net45\SharpDX.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SharpDX.Direct3D9, Version=3.1.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\SharpDX.Direct3D9.3.1.1\lib\net45\SharpDX.Direct3D9.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MahApps.Metro.1.4.0-ALPHA026\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Ambilight.cs" />
<Compile Include="AbstractAmbilightBrush.cs" />
<Compile Include="AmbilightExtendBrush.cs" />
<Compile Include="AmbilightMirrorBrush.cs" />
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="TakeAsIs\AmbilightSettings.cs" />
<Compile Include="TakeAsIs\Helper\CheckboxEnumFlagHelper.cs" />
<Compile Include="TakeAsIs\Helper\SerializationHelper.cs" />
<Compile Include="TakeAsIs\Model\AmbienceCreatorType.cs" />
<Compile Include="TakeAsIs\Model\BlackBarDetectionMode.cs" />
<Compile Include="TakeAsIs\Model\Extensions\EnumExtension.cs" />
<Compile Include="TakeAsIs\Model\Extensions\PixelDataExtension.cs" />
<Compile Include="TakeAsIs\Model\FlipMode.cs" />
<Compile Include="TakeAsIs\Model\SmoothMode.cs" />
<Compile Include="TakeAsIs\ScreenCapturing\DX9ScreenCapture.cs" />
<Compile Include="TakeAsIs\ScreenCapturing\IScreenCapture.cs" />
<Compile Include="TakeAsIs\UI\ActionCommand.cs" />
<Compile Include="TakeAsIs\UI\ConfigViewModel.cs" />
<Compile Include="TakeAsIs\UI\ConfigView.xaml.cs">
<DependentUpon>ConfigView.xaml</DependentUpon>
</Compile>
<Compile Include="TakeAsIs\UI\EnumDescriptionConverter.cs" />
<Page Include="TakeAsIs\UI\ConfigView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="TakeAsIs\UI\Taskbar.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\ambilight.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets" Condition="Exists('..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\CUE.NET.1.1.0.2\build\net45\CUE.NET.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,53 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Example_Ambilight_full")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Example_Ambilight_full")]
[assembly: AssemblyCopyright("Copyright © Wyrez 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Example_Ambilight_full.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Example_Ambilight_full.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Example_Ambilight_full.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,45 @@
using System;
using Example_Ambilight_full.TakeAsIs.Model;
namespace Example_Ambilight_full.TakeAsIs
{
public class AmbilightSettings
{
private AmbienceCreatorType _ambienceCreatorType = AmbienceCreatorType.Mirror;
#region Properties & Fields
public AmbienceCreatorType AmbienceCreatorType
{
get { return _ambienceCreatorType; }
set
{
if (_ambienceCreatorType != value)
{
_ambienceCreatorType = value;
AmbienceCreatorTypeChanged?.Invoke(this, new EventArgs());
}
}
}
public int OffsetLeft { get; set; } = 0;
public int OffsetRight { get; set; } = 0;
public int OffsetTop { get; set; } = 0;
public int OffsetBottom { get; set; } = 0;
public int Downsampling { get; set; } = 2;
public double MirroredAmount { get; set; } = 10;
public SmoothMode SmoothMode { get; set; } = SmoothMode.Low;
public BlackBarDetectionMode BlackBarDetectionMode { get; set; } = BlackBarDetectionMode.Bottom;
public FlipMode FlipMode { get; set; } = FlipMode.Vertical;
#endregion
#region Events
public event EventHandler AmbienceCreatorTypeChanged;
#endregion
}
}

View File

@ -0,0 +1,93 @@
using System;
using System.Windows;
using System.Windows.Controls;
using Example_Ambilight_full.TakeAsIs.Model.Extensions;
namespace Example_Ambilight_full.TakeAsIs.Helper
{
public class CheckboxEnumFlagHelper
{
#region DependencyProperties
// ReSharper disable InconsistentNaming
public static readonly DependencyProperty FlagsProperty = DependencyProperty.RegisterAttached(
"Flags", typeof(Enum), typeof(CheckboxEnumFlagHelper), new FrameworkPropertyMetadata(default(Enum), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, FlagsChanged));
public static void SetFlags(DependencyObject element, Enum value)
{
element.SetValue(FlagsProperty, value);
}
public static Enum GetFlags(DependencyObject element)
{
return (Enum)element.GetValue(FlagsProperty);
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached(
"Value", typeof(Enum), typeof(CheckboxEnumFlagHelper), new PropertyMetadata(default(Enum), ValueChanged));
public static void SetValue(DependencyObject element, Enum value)
{
element.SetValue(ValueProperty, value);
}
public static Enum GetValue(DependencyObject element)
{
return (Enum)element.GetValue(ValueProperty);
}
// ReSharper restore InconsistentNaming
#endregion
#region Methods
private static void FlagsChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
UpdateTarget(dependencyObject as CheckBox, dependencyPropertyChangedEventArgs.NewValue as Enum);
}
private static void ValueChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
CheckBox checkbox = dependencyObject as CheckBox;
if (checkbox == null) return;
checkbox.Checked -= UpdateSource;
checkbox.Unchecked -= UpdateSource;
if (dependencyPropertyChangedEventArgs.NewValue != null)
{
checkbox.Checked += UpdateSource;
checkbox.Unchecked += UpdateSource;
}
UpdateTarget(checkbox, GetFlags(checkbox));
}
private static void UpdateTarget(CheckBox checkbox, Enum flags)
{
if (checkbox == null) return;
Enum value = GetValue(checkbox);
checkbox.IsChecked = value != null && (flags?.HasFlag(value) ?? false);
}
private static void UpdateSource(object sender, RoutedEventArgs routedEventArgs)
{
CheckBox checkbox = sender as CheckBox;
if (checkbox == null) return;
Enum flags = GetFlags(checkbox);
Enum value = GetValue(checkbox);
if (value == null) return;
if (checkbox.IsChecked ?? false)
SetFlags(checkbox, flags == null ? value : flags.SetFlag(value, true, flags.GetType()));
else
SetFlags(checkbox, flags?.SetFlag(value, false, flags.GetType()));
}
#endregion
}
}

View File

@ -0,0 +1,50 @@
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace Example_Ambilight_full.TakeAsIs.Helper
{
public static class SerializationHelper
{
public static void SaveObjectToFile<T>(T serializableObject, string path)
{
if (serializableObject == null) return;
try
{
XmlDocument xmlDocument = new XmlDocument();
XmlSerializer serializer = new XmlSerializer(serializableObject.GetType());
using (MemoryStream stream = new MemoryStream())
{
serializer.Serialize(stream, serializableObject);
stream.Seek(0, SeekOrigin.Begin);
xmlDocument.Load(stream);
xmlDocument.Save(path);
}
}
catch {/* Catch'em all */}
}
public static T LoadObjectFromFile<T>(string fileName)
{
if (string.IsNullOrEmpty(fileName)) return default(T);
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(fileName);
string xmlString = xmlDocument.OuterXml;
using (StringReader sr = new StringReader(xmlString))
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (XmlReader reader = new XmlTextReader(sr))
return (T)serializer.Deserialize(reader);
}
}
catch {/* Catch'em all */}
return default(T);
}
}
}

View File

@ -0,0 +1,13 @@
using System.ComponentModel;
namespace Example_Ambilight_full.TakeAsIs.Model
{
public enum AmbienceCreatorType
{
[Description("Mirror")]
Mirror,
[Description("Extend")]
Extend
}
}

View File

@ -0,0 +1,14 @@
using System;
namespace Example_Ambilight_full.TakeAsIs.Model
{
[Flags]
public enum BlackBarDetectionMode
{
None = 0,
Left = 1 << 0,
Right = 1 << 1,
Top = 1 << 2,
Bottom = 1 << 3,
}
}

View File

@ -0,0 +1,26 @@
using System;
namespace Example_Ambilight_full.TakeAsIs.Model.Extensions
{
public static class EnumExtension
{
#region Methods
public static Enum SetFlag(this Enum e, Enum value, bool set, Type t)
{
if (e == null || value == null || t == null) return e;
int eValue = Convert.ToInt32(e);
int valueValue = Convert.ToInt32(value);
if (set)
eValue |= valueValue;
else
eValue &= ~valueValue;
return (Enum)Enum.ToObject(t, eValue);
}
#endregion
}
}

View File

@ -0,0 +1,89 @@
namespace Example_Ambilight_full.TakeAsIs.Model.Extensions
{
public static class PixelDataExtension
{
#region Methods
public static int DetectBlackBarLeft(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
{
int bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight;
int blackBarWidth = 0;
for (int x = rightBorder - 1; x >= offsetLeft; x--)
{
for (int y = offsetTop; y < bottomBorder; y++)
{
int offset = ((y * width) + x) * 4;
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarWidth;
}
blackBarWidth++;
}
return width;
}
public static int DetectBlackBarRight(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
{
int bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight;
int blackBarWidth = 0;
for (int x = offsetLeft; x < rightBorder; x++)
{
for (int y = offsetTop; y < bottomBorder; y++)
{
int offset = ((y * width) + x) * 4;
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarWidth;
}
blackBarWidth++;
}
return width;
}
public static int DetectBlackBarTop(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
{
int bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight;
int blackBarHeight = 0;
for (int y = offsetTop; y < bottomBorder; y++)
{
for (int x = offsetLeft; x < rightBorder; x++)
{
int offset = ((y * width) + x) * 4;
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarHeight;
}
blackBarHeight++;
}
return height;
}
public static int DetectBlackBarBottom(this byte[] pixels, int width, int height, int offsetLeft, int offsetRight, int offsetTop, int offsetBottom)
{
int bottomBorder = height - offsetBottom;
int rightBorder = width - offsetRight;
int blackBarHeight = 0;
for (int y = bottomBorder - 1; y >= offsetTop; y--)
{
for (int x = offsetLeft; x < rightBorder; x++)
{
int offset = ((y * width) + x) * 4;
if (pixels[offset] > 15 || pixels[offset + 1] > 15 || pixels[offset + 2] > 15)
return blackBarHeight;
}
blackBarHeight++;
}
return height;
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace Example_Ambilight_full.TakeAsIs.Model
{
[Flags]
public enum FlipMode
{
None = 0,
Vertical = 1 << 0,
Horizontal = 1 << 1
}
}

View File

@ -0,0 +1,19 @@
using System.ComponentModel;
namespace Example_Ambilight_full.TakeAsIs.Model
{
public enum SmoothMode
{
[Description("None")]
None,
[Description("Low")]
Low,
[Description("Medium")]
Medium,
[Description("High")]
High
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Media;
using SharpDX;
using SharpDX.Direct3D9;
namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
{
public class DX9ScreenCapture : IScreenCapture
{
#region Properties & Fields
private Device _device;
private Surface _surface;
private byte[] _buffer;
public int Width { get; }
public int Height { get; }
public PixelFormat PixelFormat => PixelFormats.Bgr24;
#endregion
#region Constructors
public DX9ScreenCapture()
{
Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
PresentParameters presentParams = new PresentParameters(Width, Height)
{
Windowed = true,
SwapEffect = SwapEffect.Discard
};
_device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, presentParams);
_surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch);
_buffer = new byte[Width * Height * 4];
}
#endregion
#region Methods
public byte[] CaptureScreen()
{
_device.GetFrontBufferData(0, _surface);
DataRectangle dr = _surface.LockRectangle(LockFlags.None);
Marshal.Copy(dr.DataPointer, _buffer, 0, _buffer.Length);
_surface.UnlockRectangle();
return _buffer;
}
public void Dispose()
{
_device?.Dispose();
_surface?.Dispose();
}
#endregion
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Windows.Media;
namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing
{
public interface IScreenCapture : IDisposable
{
int Width { get; }
int Height { get; }
PixelFormat PixelFormat { get; }
/// <summary>
/// As Pixel-Data BGRA
/// </summary>
/// <returns>The Pixel-Data</returns>
byte[] CaptureScreen();
}
}

View File

@ -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
}
}

View File

@ -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>

View File

@ -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();
}
}
}

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CUE.NET" version="1.1.0.2" targetFramework="net45" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net45" />
<package id="MahApps.Metro" version="1.4.0-ALPHA026" targetFramework="net45" />
<package id="SharpDX" version="3.1.1" targetFramework="net45" />
<package id="SharpDX.Direct3D9" version="3.1.1" targetFramework="net45" />
</packages>