Skip to content

Commit

Permalink
Added smoothness for dominant display color effect
Browse files Browse the repository at this point in the history
  • Loading branch information
benbense committed Dec 17, 2020
1 parent 7b58623 commit eb60146
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
10 changes: 9 additions & 1 deletion Common/DominantDisplayColorEffectMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Common
{
public class DominantDisplayColorEffectMetadata : EffectMetadata
public class DominantDisplayColorEffectMetadata : EffectMetadata<DominantDisplayColorEffectMetadataProperties>
{

public override string EffectName => "Dominant color sync";
Expand All @@ -20,5 +20,13 @@ public class DominantDisplayColorEffectMetadata : EffectMetadata
public override string IconGlyph => "\uE7F4";

public override EffectType Type => EffectType.DominantColor;

public DominantDisplayColorEffectMetadata()
{
EffectProperties = new DominantDisplayColorEffectMetadataProperties()
{
RelativeSmoothness = 0
};
}
}
}
24 changes: 24 additions & 0 deletions Common/DominantDisplayColorEffectMetadataProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.ComponentModel;
using Utils;

namespace Common
{
public class DominantDisplayColorEffectMetadataProperties : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

private int relativeSmoothness;
public int RelativeSmoothness
{
get
{
return relativeSmoothness;
}
set
{
relativeSmoothness = value;
NotifyPropertyChangedUtils.OnPropertyChanged(PropertyChanged, this);
}
}
}
}
18 changes: 15 additions & 3 deletions EffectsExecution/DominantDisplayColorEffectExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ private async Task DoWork(List<Device> devices)
{
while (!backgroundWorkCancellationTokenSource.IsCancellationRequested)
{
var c = GfxUtils.GetDominantColorFromThief();
var smoothness = ((DominantDisplayColorEffectMetadata)executedEffectMetadata).EffectProperties.RelativeSmoothness;

var color = GfxUtils.GetDominantColorFromThief();

List<Task> setColorTasks = new List<Task>();

foreach (var device in devices)
if (smoothness > 0)
{
foreach (var device in devices)
{
setColorTasks.Add(Task.Run(async () => await device.SetColorSmoothly(color, smoothness)));
}
}
else
{
setColorTasks.Add(Task.Run(async () => await device.SetColor(c)));
foreach (var device in devices)
{
setColorTasks.Add(Task.Run(async () => await device.SetColor(color)));
}
}

await Task.WhenAll(setColorTasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RGBMasterUWPApp.Pages.EffectsControls"
xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">

<Grid>
<StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock>Smoothness:&#160;</TextBlock>
<TextBlock Text="{x:Bind DominantDisplayColorEffectProps.RelativeSmoothness, Mode=OneWay}"/>
<TextBlock Text="ms"/>
</StackPanel>
<muxc:NumberBox x:Name="SmoothnessSlider" Value="{x:Bind DominantDisplayColorEffectProps.RelativeSmoothness, Mode=TwoWay}" Minimum="0" ToolTipService.ToolTip="Time between previous color to this color, in milliseconds" />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using AppExecutionManager.State;
using Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -22,6 +24,7 @@ namespace RGBMasterUWPApp.Pages.EffectsControls
/// </summary>
public sealed partial class DominantDisplayColorEffectControl : Page
{
public DominantDisplayColorEffectMetadataProperties DominantDisplayColorEffectProps => ((DominantDisplayColorEffectMetadata)AppState.Instance.Effects.First(effect => effect.Type == EffectType.DominantColor)).EffectProperties;
public DominantDisplayColorEffectControl()
{
this.InitializeComponent();
Expand Down

0 comments on commit eb60146

Please sign in to comment.