2020-09-01 03:20:26 +03:00
|
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
2020-10-13 20:21:17 +03:00
|
|
|
|
#nullable enable
|
2020-10-06 04:08:26 +03:00
|
|
|
|
|
2020-09-01 03:20:26 +03:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Windows.UI;
|
|
|
|
|
|
|
|
|
|
namespace LottieViewer
|
|
|
|
|
{
|
|
|
|
|
// An observable named color with the ability to change the color value.
|
|
|
|
|
public sealed class ColorPaletteEntry : INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
Color _initialColor;
|
|
|
|
|
Color _color;
|
|
|
|
|
|
|
|
|
|
internal ColorPaletteEntry(Color color, string name)
|
|
|
|
|
{
|
|
|
|
|
_initialColor = color;
|
|
|
|
|
_color = color;
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 20:21:17 +03:00
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
2020-09-01 03:20:26 +03:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If true, changing the Color will also change the InitialColor to keep it the
|
|
|
|
|
/// same as Color. This is used to special case the "Background" color, which does
|
|
|
|
|
/// not have an initial color.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsInitialColorSameAsColor { get; set; }
|
|
|
|
|
|
|
|
|
|
public Color Color
|
|
|
|
|
{
|
|
|
|
|
get => _color;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
// Check whether the color is actually changing, and ignore it if it isn't.
|
|
|
|
|
// This check ensures we can use two-way binding without infinite recursion.
|
|
|
|
|
if (value != _color)
|
|
|
|
|
{
|
|
|
|
|
_color = value;
|
|
|
|
|
if (IsInitialColorSameAsColor)
|
|
|
|
|
{
|
|
|
|
|
_initialColor = value;
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.InitialColor)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Color)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color InitialColor => _initialColor;
|
|
|
|
|
|
|
|
|
|
// A name that describes the palette entry.
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|