-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
246 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
SightKeeper.Avalonia/DataSets/Compositions/CompositionViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using SightKeeper.Domain.Model.DataSets.Screenshots; | ||
|
||
namespace SightKeeper.Avalonia.DataSets.Compositions; | ||
|
||
internal abstract partial class CompositionViewModel : ViewModel | ||
{ | ||
public abstract string DisplayName { get; } | ||
|
||
public static CompositionViewModel? Create(Composition? composition) => composition switch | ||
{ | ||
null => null, | ||
FixedTransparentComposition fixedTransparent => new FixedTransparentCompositionViewModel(fixedTransparent), | ||
FloatingTransparentComposition floatingTransparent => new FloatingTransparentCompositionViewModel(floatingTransparent), | ||
_ => throw new ArgumentOutOfRangeException(nameof(composition)) | ||
}; | ||
|
||
public TimeSpan MaximumScreenshotsDelay => TimeSpan.FromMilliseconds(MaximumScreenshotsDelayInMilliseconds); | ||
|
||
public abstract Composition ToComposition(); | ||
|
||
protected CompositionViewModel() | ||
{ | ||
_maximumScreenshotsDelayInMilliseconds = 50; | ||
} | ||
|
||
protected CompositionViewModel(Composition composition) | ||
{ | ||
_maximumScreenshotsDelayInMilliseconds = (ushort)composition.MaximumScreenshotsDelay.TotalMilliseconds; | ||
} | ||
|
||
[ObservableProperty] private ushort _maximumScreenshotsDelayInMilliseconds; | ||
} |
42 changes: 42 additions & 0 deletions
42
SightKeeper.Avalonia/DataSets/Compositions/FixedTransparentCompositionViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using SightKeeper.Domain.Model.DataSets.Screenshots; | ||
|
||
namespace SightKeeper.Avalonia.DataSets.Compositions; | ||
|
||
internal sealed partial class FixedTransparentCompositionViewModel : CompositionViewModel | ||
{ | ||
public override string DisplayName => "Fixed transparent"; | ||
|
||
public byte ScreenshotsCount | ||
{ | ||
get => (byte)Opacities.Count; | ||
set | ||
{ | ||
var delta = value - Opacities.Count; | ||
OnPropertyChanging(); | ||
if (delta > 0) | ||
Opacities = Opacities.AddRange(Enumerable.Repeat(0.1m, delta)); | ||
else if (delta < 0) | ||
Opacities = Opacities.RemoveRange(Opacities.Count + delta, -delta); | ||
OnPropertyChanged(); | ||
} | ||
} | ||
|
||
public FixedTransparentCompositionViewModel() | ||
{ | ||
_opacities = [0.1m, 0.2m, 0.7m]; | ||
} | ||
|
||
public FixedTransparentCompositionViewModel(FixedTransparentComposition composition) : base(composition) | ||
{ | ||
_opacities = composition.Opacities.Select(opacity => (decimal)opacity).ToImmutableList(); | ||
} | ||
|
||
public override FixedTransparentComposition ToComposition() => | ||
new(MaximumScreenshotsDelay, | ||
Opacities.Select(opacity => (float)opacity).ToImmutableArray()); | ||
|
||
[ObservableProperty] private ImmutableList<decimal> _opacities; | ||
} |
30 changes: 30 additions & 0 deletions
30
SightKeeper.Avalonia/DataSets/Compositions/FloatingTransparentCompositionViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using SightKeeper.Domain.Model.DataSets.Screenshots; | ||
|
||
namespace SightKeeper.Avalonia.DataSets.Compositions; | ||
|
||
internal sealed partial class FloatingTransparentCompositionViewModel : CompositionViewModel | ||
{ | ||
public override string DisplayName => "Floating transparent"; | ||
|
||
public TimeSpan SeriesDuration => TimeSpan.FromMilliseconds(SeriesDurationInMilliseconds); | ||
|
||
public FloatingTransparentCompositionViewModel() | ||
{ | ||
_seriesDurationInMilliseconds = 500; | ||
} | ||
|
||
public FloatingTransparentCompositionViewModel(FloatingTransparentComposition composition) : base(composition) | ||
{ | ||
_seriesDurationInMilliseconds = (ushort)composition.SeriesDuration.TotalMilliseconds; | ||
} | ||
|
||
public override FloatingTransparentComposition ToComposition() | ||
{ | ||
return new FloatingTransparentComposition(MaximumScreenshotsDelay, SeriesDuration, MinimumOpacity); | ||
} | ||
|
||
[ObservableProperty] private ushort _seriesDurationInMilliseconds; | ||
[ObservableProperty] private float _minimumOpacity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
SightKeeper.Domain.Tests/DataSets/Screenshots/FixedTransparentCompositionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using SightKeeper.Domain.Model.DataSets.Screenshots; | ||
|
||
namespace SightKeeper.Domain.Tests.DataSets.Screenshots; | ||
|
||
public sealed class FixedTransparentCompositionTests | ||
{ | ||
[Fact] | ||
public void ShouldCreate() | ||
{ | ||
FixedTransparentComposition _ = new(TimeSpan.FromMilliseconds(50), [0.2f, 0.3f, 0.5f]); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotCreateWithNegativeDelay() | ||
{ | ||
Assert.ThrowsAny<Exception>(() => new FixedTransparentComposition(TimeSpan.FromMilliseconds(-1), [0.5f, 0.5f])); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotCreateWithOnlyOneOpacity() | ||
{ | ||
Assert.ThrowsAny<Exception>(() => new FixedTransparentComposition(TimeSpan.FromMilliseconds(50), [1])); | ||
} | ||
|
||
[Fact] | ||
public void ShouldNotCreateWithOpacitiesSumNotEqualToOne() | ||
{ | ||
Assert.ThrowsAny<Exception>(() => new FixedTransparentComposition(TimeSpan.FromMilliseconds(50), [0.1f, 0.3f, 0.5f])); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
SightKeeper.Domain.Tests/DataSets/Screenshots/TransparentCompositionTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
SightKeeper.Domain/Model/DataSets/Screenshots/FloatingTransparentComposition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using CommunityToolkit.Diagnostics; | ||
|
||
namespace SightKeeper.Domain.Model.DataSets.Screenshots; | ||
|
||
public sealed class FloatingTransparentComposition : Composition | ||
{ | ||
public TimeSpan SeriesDuration | ||
{ | ||
get => _seriesDuration; | ||
set | ||
{ | ||
Guard.IsGreaterThan(value, TimeSpan.Zero); | ||
_seriesDuration = value; | ||
} | ||
} | ||
|
||
public float MinimumOpacity | ||
{ | ||
get => _minimumOpacity; | ||
set | ||
{ | ||
Guard.IsInRange(value, 0, 1); | ||
_minimumOpacity = value; | ||
} | ||
} | ||
|
||
public FloatingTransparentComposition(TimeSpan maximumScreenshotsDelay, TimeSpan seriesDuration, float minimumOpacity) : base(maximumScreenshotsDelay) | ||
{ | ||
SeriesDuration = seriesDuration; | ||
MinimumOpacity = minimumOpacity; | ||
} | ||
|
||
private TimeSpan _seriesDuration; | ||
private float _minimumOpacity; | ||
} |
Oops, something went wrong.