mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Merge branch 'voltagex-nuget-targets' into Development
This commit is contained in:
commit
3cfa845482
@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Devices\Keyboard\Brushes\GradientStop.cs" />
|
<Compile Include="Devices\Keyboard\Brushes\GradientStop.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Brushes\IBrush.cs" />
|
<Compile Include="Devices\Keyboard\Brushes\IBrush.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Brushes\LinearGradientBrush.cs" />
|
<Compile Include="Devices\Keyboard\Brushes\LinearGradientBrush.cs" />
|
||||||
|
<Compile Include="Devices\Keyboard\Brushes\RainbowBrush.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Brushes\SolidColorBrush.cs" />
|
<Compile Include="Devices\Keyboard\Brushes\SolidColorBrush.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\CorsairLogicalKeyboardLayout.cs" />
|
<Compile Include="Devices\Keyboard\Enums\CorsairLogicalKeyboardLayout.cs" />
|
||||||
<Compile Include="Devices\Headset\Enums\CorsairHeadsetLedId.cs" />
|
<Compile Include="Devices\Headset\Enums\CorsairHeadsetLedId.cs" />
|
||||||
@ -91,6 +92,7 @@
|
|||||||
<Compile Include="Devices\Mouse\CorsairMouse.cs" />
|
<Compile Include="Devices\Mouse\CorsairMouse.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Extensions\KeyGroupExtension.cs" />
|
<Compile Include="Devices\Keyboard\Extensions\KeyGroupExtension.cs" />
|
||||||
<Compile Include="Helper\ColorHelper.cs" />
|
<Compile Include="Helper\ColorHelper.cs" />
|
||||||
|
<Compile Include="Helper\GradientHelper.cs" />
|
||||||
<Compile Include="Helper\RectangleHelper.cs" />
|
<Compile Include="Helper\RectangleHelper.cs" />
|
||||||
<Compile Include="Native\_CorsairDeviceInfo.cs" />
|
<Compile Include="Native\_CorsairDeviceInfo.cs" />
|
||||||
<Compile Include="Native\_CorsairLedColor.cs" />
|
<Compile Include="Native\_CorsairLedColor.cs" />
|
||||||
@ -113,15 +115,5 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<Import Project="$(MSBuildProjectDirectory)\CUE.NET.targets" />
|
||||||
<PostBuildEvent>if $(PlatformName) == x86 copy "$(SolutionDir)libs\CUESDK_2013.dll" "$(TargetDir)CUESDK_2013.dll"
|
|
||||||
if $(PlatformName) == x64 copy "$(SolutionDir)libs\CUESDK.x64_2013.dll" "$(TargetDir)CUESDK.x64_2013.dll"</PostBuildEvent>
|
|
||||||
</PropertyGroup>
|
|
||||||
<!-- 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>
|
</Project>
|
||||||
@ -18,5 +18,6 @@ I'm currently working on this library and it's far from being finished. Please b
|
|||||||
<files>
|
<files>
|
||||||
<file src="bin\x64\CUE.NET.dll" target="lib\net46\CUE.NET.dll" />
|
<file src="bin\x64\CUE.NET.dll" target="lib\net46\CUE.NET.dll" />
|
||||||
<file src="bin\x64\CUESDK.x64_2013.dll" target="build\net46\x64" />
|
<file src="bin\x64\CUESDK.x64_2013.dll" target="build\net46\x64" />
|
||||||
|
<file src="CUE.NET.targets" target="build\net46\x64\CUE.NET.targets" />
|
||||||
</files>
|
</files>
|
||||||
</package>
|
</package>
|
||||||
@ -9,6 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{1F
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDevTest", "Examples\SimpleDevTest\SimpleDevTest.csproj", "{7FD88256-5E14-4D7C-862B-7BC2CD04081A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDevTest", "Examples\SimpleDevTest\SimpleDevTest.csproj", "{7FD88256-5E14-4D7C-862B-7BC2CD04081A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FF50AF6A-D2AC-4772-B013-C10D127DBE29}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
CUE.NET.nuspec = CUE.NET.nuspec
|
||||||
|
CUE.NET.targets = CUE.NET.targets
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
|
|||||||
132
CUE.NET.targets
Normal file
132
CUE.NET.targets
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<!--
|
||||||
|
* Build targets hacked from SQLite (thanks!), please rename all of this when you're feeling brave
|
||||||
|
* System.Data.SQLite.Core.targets -
|
||||||
|
*
|
||||||
|
*
|
||||||
|
-->
|
||||||
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
** SQLite Interop Library Build Items **
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<SQLiteInteropFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
|
||||||
|
HasTrailingSlash('$(MSBuildThisFileDirectory)')"
|
||||||
|
Include="$(MSBuildThisFileDirectory)\libs\*.dll" />
|
||||||
|
<SQLiteInteropFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
|
||||||
|
HasTrailingSlash('$(MSBuildThisFileDirectory)')"
|
||||||
|
Include="$(MSBuildThisFileDirectory)\*.dll" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
** SQLite Interop Library Content Items **
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(ContentSQLiteInteropFiles)' != '' And
|
||||||
|
'$(ContentSQLiteInteropFiles)' != 'false' And
|
||||||
|
'@(SQLiteInteropFiles)' != ''">
|
||||||
|
<Content Include="@(SQLiteInteropFiles)">
|
||||||
|
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
** SQLite Interop Library Build Targets **
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Target Name="CopySQLiteInteropFiles"
|
||||||
|
Condition="'$(CopySQLiteInteropFiles)' != 'false' And
|
||||||
|
'$(OutDir)' != '' And
|
||||||
|
HasTrailingSlash('$(OutDir)') And
|
||||||
|
Exists('$(OutDir)')"
|
||||||
|
Inputs="@(SQLiteInteropFiles)"
|
||||||
|
Outputs="@(SQLiteInteropFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')">
|
||||||
|
<!--
|
||||||
|
NOTE: Copy "SQLite.Interop.dll" and all related files, for every
|
||||||
|
architecture that we support, to the build output directory.
|
||||||
|
-->
|
||||||
|
<Message Text="Copying Interop files..." Importance="high" />
|
||||||
|
<Copy SourceFiles="@(SQLiteInteropFiles)"
|
||||||
|
DestinationFiles="@(SQLiteInteropFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Target Name="CleanSQLiteInteropFiles"
|
||||||
|
Condition="'$(CleanSQLiteInteropFiles)' != 'false' And
|
||||||
|
'$(OutDir)' != '' And
|
||||||
|
HasTrailingSlash('$(OutDir)') And
|
||||||
|
Exists('$(OutDir)')">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
NOTE: Delete "SQLite.Interop.dll" and all related files, for every
|
||||||
|
architecture that we support, from the build output directory.
|
||||||
|
-->
|
||||||
|
<Message Text="this file $(MSBuildThisFileDirectory)" Importance="high"/>
|
||||||
|
<Message Text="Cleaning Interop files..." Importance="high" />
|
||||||
|
|
||||||
|
<Delete Files="@(SQLiteInteropFiles -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<Target Name="CollectSQLiteInteropFiles"
|
||||||
|
Condition="'$(CollectSQLiteInteropFiles)' != 'false'">
|
||||||
|
<Message Text="Collecting Interop files..." Importance="high" />
|
||||||
|
<ItemGroup>
|
||||||
|
<FilesForPackagingFromProject Include="@(SQLiteInteropFiles)">
|
||||||
|
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
|
||||||
|
</FilesForPackagingFromProject>
|
||||||
|
</ItemGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
** SQLite Interop Library Build Properties **
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEventDependsOn>
|
||||||
|
$(PostBuildEventDependsOn);
|
||||||
|
CopySQLiteInteropFiles;
|
||||||
|
</PostBuildEventDependsOn>
|
||||||
|
<BuildDependsOn>
|
||||||
|
$(BuildDependsOn);
|
||||||
|
CopySQLiteInteropFiles;
|
||||||
|
</BuildDependsOn>
|
||||||
|
<CleanDependsOn>
|
||||||
|
$(CleanDependsOn);
|
||||||
|
CleanSQLiteInteropFiles;
|
||||||
|
</CleanDependsOn>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
******************************************************************************
|
||||||
|
** SQLite Interop Library Publish Properties for Visual Studio 201x **
|
||||||
|
******************************************************************************
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' Or
|
||||||
|
'$(VisualStudioVersion)' == '10.0' Or
|
||||||
|
'$(VisualStudioVersion)' == '11.0' Or
|
||||||
|
'$(VisualStudioVersion)' == '12.0'">
|
||||||
|
<PipelineCollectFilesPhaseDependsOn>
|
||||||
|
CollectSQLiteInteropFiles;
|
||||||
|
$(PipelineCollectFilesPhaseDependsOn);
|
||||||
|
</PipelineCollectFilesPhaseDependsOn>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@ -4,7 +4,6 @@ namespace CUE.NET.Devices.Keyboard.Brushes
|
|||||||
{
|
{
|
||||||
public class GradientStop
|
public class GradientStop
|
||||||
{
|
{
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public float Offset { get; set; }
|
public float Offset { get; set; }
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
namespace CUE.NET.Devices.Keyboard.Brushes
|
namespace CUE.NET.Devices.Keyboard.Brushes
|
||||||
{
|
{
|
||||||
@ -42,91 +43,41 @@ namespace CUE.NET.Devices.Keyboard.Brushes
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
public Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
public Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
||||||
{
|
{
|
||||||
if (!GradientStops.Any()) return Color.Transparent;
|
if (!GradientStops.Any()) return Color.Transparent;
|
||||||
if (GradientStops.Count == 1) return GradientStops.First().Color;
|
if (GradientStops.Count == 1) return GradientStops.First().Color;
|
||||||
|
|
||||||
// Taken from https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
|
PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
|
||||||
|
PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
|
||||||
|
|
||||||
float x3 = point.X;
|
float offset = GradientHelper.CalculateGradientOffset(startPoint, endPoint, point);
|
||||||
float y3 = point.Y;
|
|
||||||
|
|
||||||
float x1 = StartPoint.X * rectangle.Width;
|
|
||||||
float y1 = StartPoint.Y * rectangle.Height;
|
|
||||||
PointF p1 = new PointF(x1, y1); // Starting point
|
|
||||||
|
|
||||||
float x2 = EndPoint.X * rectangle.Width;
|
|
||||||
float y2 = EndPoint.Y * rectangle.Height;
|
|
||||||
PointF p2 = new PointF(x2, y2); //End point
|
|
||||||
|
|
||||||
// Calculate intersecting points
|
|
||||||
PointF p4;
|
|
||||||
|
|
||||||
if (y1.Equals(y2)) // Horizontal case
|
|
||||||
p4 = new PointF(x3, y1);
|
|
||||||
|
|
||||||
else if (x1.Equals(x2)) // Vertical case
|
|
||||||
p4 = new PointF(x1, y3);
|
|
||||||
|
|
||||||
else // Diagnonal case
|
|
||||||
{
|
|
||||||
float m = (y2 - y1) / (x2 - x1);
|
|
||||||
float m2 = -1 / m;
|
|
||||||
float b = y1 - m * x1;
|
|
||||||
float c = y3 - m2 * x3;
|
|
||||||
|
|
||||||
float x4 = (c - b) / (m - m2);
|
|
||||||
float y4 = m * x4 + b;
|
|
||||||
p4 = new PointF(x4, y4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate distances relative to the vector start
|
|
||||||
float d4 = Dist(p4, p1, p2);
|
|
||||||
float d2 = Dist(p2, p1, p2);
|
|
||||||
|
|
||||||
float x = d4 / d2;
|
|
||||||
|
|
||||||
// Clip the input if before or after the max/min offset values
|
// Clip the input if before or after the max/min offset values
|
||||||
float max = GradientStops.Max(n => n.Offset);
|
float max = GradientStops.Max(n => n.Offset);
|
||||||
if (x > max)
|
if (offset > max)
|
||||||
x = max;
|
offset = max;
|
||||||
|
|
||||||
float min = GradientStops.Min(n => n.Offset);
|
float min = GradientStops.Min(n => n.Offset);
|
||||||
if (x < min)
|
if (offset < min)
|
||||||
x = min;
|
offset = min;
|
||||||
|
|
||||||
// Find gradient stops that surround the input value
|
// Find gradient stops that surround the input value
|
||||||
GradientStop gs0 = GradientStops.Where(n => n.Offset <= x).OrderBy(n => n.Offset).Last();
|
GradientStop gsBefore = GradientStops.Where(n => n.Offset <= offset).OrderBy(n => n.Offset).Last();
|
||||||
GradientStop gs1 = GradientStops.Where(n => n.Offset >= x).OrderBy(n => n.Offset).First();
|
GradientStop gsAfter = GradientStops.Where(n => n.Offset >= offset).OrderBy(n => n.Offset).First();
|
||||||
|
|
||||||
float y = 0f;
|
float blendFactor = 0f;
|
||||||
if (!gs0.Offset.Equals(gs1.Offset))
|
if (!gsBefore.Offset.Equals(gsAfter.Offset))
|
||||||
y = ((x - gs0.Offset) / (gs1.Offset - gs0.Offset));
|
blendFactor = ((offset - gsBefore.Offset) / (gsAfter.Offset - gsBefore.Offset));
|
||||||
|
|
||||||
byte colA = (byte)((gs1.Color.A - gs0.Color.A) * y + gs0.Color.A);
|
byte colA = (byte)((gsAfter.Color.A - gsBefore.Color.A) * blendFactor + gsBefore.Color.A);
|
||||||
byte colR = (byte)((gs1.Color.R - gs0.Color.R) * y + gs0.Color.R);
|
byte colR = (byte)((gsAfter.Color.R - gsBefore.Color.R) * blendFactor + gsBefore.Color.R);
|
||||||
byte colG = (byte)((gs1.Color.G - gs0.Color.G) * y + gs0.Color.G);
|
byte colG = (byte)((gsAfter.Color.G - gsBefore.Color.G) * blendFactor + gsBefore.Color.G);
|
||||||
byte colB = (byte)((gs1.Color.B - gs0.Color.B) * y + gs0.Color.B);
|
byte colB = (byte)((gsAfter.Color.B - gsBefore.Color.B) * blendFactor + gsBefore.Color.B);
|
||||||
return Color.FromArgb(colA, colR, colG, colB);
|
return Color.FromArgb(colA, colR, colG, colB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken from https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the signed magnitude of a point on a vector with origin po and pointing to pf
|
|
||||||
/// </summary>
|
|
||||||
private float Dist(PointF px, PointF po, PointF pf)
|
|
||||||
{
|
|
||||||
float d = (float)Math.Sqrt((px.Y - po.Y) * (px.Y - po.Y) + (px.X - po.X) * (px.X - po.X));
|
|
||||||
|
|
||||||
return (((px.Y < po.Y) && (pf.Y > po.Y)) ||
|
|
||||||
((px.Y > po.Y) && (pf.Y < po.Y)) ||
|
|
||||||
((px.Y.Equals(po.Y)) && (px.X < po.X) && (pf.X > po.X)) ||
|
|
||||||
((px.Y.Equals(po.Y)) && (px.X > po.X) && (pf.X < po.X)))
|
|
||||||
? -d : d;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
Devices/Keyboard/Brushes/RainbowBrush.cs
Normal file
71
Devices/Keyboard/Brushes/RainbowBrush.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using CUE.NET.Helper;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Keyboard.Brushes
|
||||||
|
{
|
||||||
|
public class RainbowBrush : IBrush
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public PointF StartPoint { get; set; } = new PointF(0f, 0.5f);
|
||||||
|
public PointF EndPoint { get; set; } = new PointF(1f, 0.5f);
|
||||||
|
public float StartHue { get; set; }
|
||||||
|
public float EndHue { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public RainbowBrush(float startHue = 0f, float endHue = 360f)
|
||||||
|
{
|
||||||
|
this.StartHue = startHue;
|
||||||
|
this.EndHue = endHue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RainbowBrush(PointF startPoint, PointF endPoint, float startHue = 0f, float endHue = 360f)
|
||||||
|
{
|
||||||
|
this.StartPoint = startPoint;
|
||||||
|
this.EndPoint = endPoint;
|
||||||
|
this.StartHue = startHue;
|
||||||
|
this.EndHue = endHue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
||||||
|
{
|
||||||
|
PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
|
||||||
|
PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
|
||||||
|
|
||||||
|
float offset = GradientHelper.CalculateGradientOffset(startPoint, endPoint, point);
|
||||||
|
float range = EndHue - StartHue;
|
||||||
|
float progress = (StartHue + (range * offset)) / 360f;
|
||||||
|
|
||||||
|
float div = (Math.Abs(progress % 1) * 6);
|
||||||
|
int value = (int)((div % 1) * 255);
|
||||||
|
|
||||||
|
switch ((int)div)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return Color.FromArgb(255, 255, value, 0);
|
||||||
|
case 1:
|
||||||
|
return Color.FromArgb(255, 255 - value, 255, 0);
|
||||||
|
case 2:
|
||||||
|
return Color.FromArgb(255, 0, 255, value);
|
||||||
|
case 3:
|
||||||
|
return Color.FromArgb(255, 0, 255 - value, 255);
|
||||||
|
case 4:
|
||||||
|
return Color.FromArgb(255, value, 0, 255);
|
||||||
|
case 5:
|
||||||
|
return Color.FromArgb(255, 255, 0, 255 - value);
|
||||||
|
default:
|
||||||
|
return Color.Transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -85,8 +85,8 @@ namespace SimpleDevTest
|
|||||||
// Create our gradient stop to play with
|
// Create our gradient stop to play with
|
||||||
GradientStop moveableStop = new GradientStop(0, Color.FromArgb(0, 255, 0));
|
GradientStop moveableStop = new GradientStop(0, Color.FromArgb(0, 255, 0));
|
||||||
|
|
||||||
//Create a basic (by default horizontal) brush ...
|
// Create a basic (by default horizontal) brush ...
|
||||||
LinearGradientBrush linearBrush = new LinearGradientBrush(new GradientStop(0, Color.Blue), moveableStop, new GradientStop(1f, Color.Red));
|
LinearGradientBrush linearBrush = new LinearGradientBrush(new GradientStop(0, Color.Blue), moveableStop, new GradientStop(1f, Color.White));
|
||||||
|
|
||||||
// ... and add it as the keyboard background
|
// ... and add it as the keyboard background
|
||||||
keyboard.Brush = linearBrush;
|
keyboard.Brush = linearBrush;
|
||||||
@ -122,6 +122,29 @@ namespace SimpleDevTest
|
|||||||
|
|
||||||
Wait(2);
|
Wait(2);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Time for an even better brush: rainbow
|
||||||
|
|
||||||
|
Console.WriteLine("rainbow-test");
|
||||||
|
|
||||||
|
// Create an simple horizontal rainbow containing two times the full spectrum
|
||||||
|
RainbowBrush rainbowBrush = new RainbowBrush(0, 720);
|
||||||
|
|
||||||
|
// Add the rainbow to the keyboard and perform an initial update
|
||||||
|
keyboard.Brush = rainbowBrush;
|
||||||
|
keyboard.UpdateLeds();
|
||||||
|
|
||||||
|
// Let the rainbow move around for 10 secs
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
rainbowBrush.StartHue += 10f;
|
||||||
|
rainbowBrush.EndHue += 10f;
|
||||||
|
keyboard.UpdateLeds();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
Wait(2);
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Now let us move some points random over the keyboard
|
// Now let us move some points random over the keyboard
|
||||||
|
|||||||
53
Helper/GradientHelper.cs
Normal file
53
Helper/GradientHelper.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace CUE.NET.Helper
|
||||||
|
{
|
||||||
|
public static class GradientHelper
|
||||||
|
{
|
||||||
|
// Based on https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
|
||||||
|
public static float CalculateGradientOffset(PointF startPoint, PointF endPoint, PointF point)
|
||||||
|
{
|
||||||
|
PointF intersectingPoint;
|
||||||
|
if (startPoint.Y.Equals(endPoint.Y)) // Horizontal case
|
||||||
|
intersectingPoint = new PointF(point.X, startPoint.Y);
|
||||||
|
|
||||||
|
else if (startPoint.X.Equals(endPoint.X)) // Vertical case
|
||||||
|
intersectingPoint = new PointF(startPoint.X, point.Y);
|
||||||
|
|
||||||
|
else // Diagnonal case
|
||||||
|
{
|
||||||
|
float slope = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);
|
||||||
|
float orthogonalSlope = -1 / slope;
|
||||||
|
|
||||||
|
float startYIntercept = startPoint.Y - slope * startPoint.X;
|
||||||
|
float pointYIntercept = point.Y - orthogonalSlope * point.X;
|
||||||
|
|
||||||
|
float intersectingPointX = (pointYIntercept - startYIntercept) / (slope - orthogonalSlope);
|
||||||
|
float intersectingPointY = slope * intersectingPointX + startYIntercept;
|
||||||
|
intersectingPoint = new PointF(intersectingPointX, intersectingPointY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate distances relative to the vector start
|
||||||
|
float intersectDistance = CalculateDistance(intersectingPoint, startPoint, endPoint);
|
||||||
|
float gradientLength = CalculateDistance(endPoint, startPoint, endPoint);
|
||||||
|
|
||||||
|
return intersectDistance / gradientLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Based on https://dotupdate.wordpress.com/2008/01/28/find-the-color-of-a-point-in-a-lineargradientbrush/
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the signed magnitude of a point on a vector
|
||||||
|
/// </summary>
|
||||||
|
private static float CalculateDistance(PointF point, PointF origin, PointF direction)
|
||||||
|
{
|
||||||
|
float distance = (float)Math.Sqrt((point.Y - origin.Y) * (point.Y - origin.Y) + (point.X - origin.X) * (point.X - origin.X));
|
||||||
|
|
||||||
|
return (((point.Y < origin.Y) && (direction.Y > origin.Y)) ||
|
||||||
|
((point.Y > origin.Y) && (direction.Y < origin.Y)) ||
|
||||||
|
((point.Y.Equals(origin.Y)) && (point.X < origin.X) && (direction.X > origin.X)) ||
|
||||||
|
((point.Y.Equals(origin.Y)) && (point.X > origin.X) && (direction.X < origin.X)))
|
||||||
|
? -distance : distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user