diff options
author | Bertrand Le Roy <beleroy@microsoft.com> | 2017-11-01 00:54:08 +0300 |
---|---|---|
committer | Bertrand Le Roy <beleroy@microsoft.com> | 2017-11-04 02:35:45 +0300 |
commit | ea9a0ae96bc7a3f6216849afe692b539f8f3bbfb (patch) | |
tree | 12d5b65708535e96e456d340f0a165596ae64f9a /Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs | |
parent | c60750205216c8b410f70da6a05207f7e639e6bb (diff) |
Move the solid brush editor to a tab, add a tab for no brush, and make the brush editor abstract enough to accommodate for any type of brush in the future
Diffstat (limited to 'Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs')
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs index 9c43c9d..c9c8b52 100644 --- a/Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/BrushPropertyViewModel.cs @@ -8,6 +8,90 @@ namespace Xamarin.PropertyEditing.ViewModels public BrushPropertyViewModel(IPropertyInfo property, IEnumerable<IObjectEditor> editors) : base(property, editors) { + if (property is IColorSpaced colorSpacedPropertyInfo) { + ColorSpaces = colorSpacedPropertyInfo.ColorSpaces; + } + } + + public IReadOnlyList<string> ColorSpaces { get; } + + public CommonSolidBrush PreviousSolidBrush { get; set; } + + string ColorSpace => Value is CommonSolidBrush solidBrush ? solidBrush.ColorSpace : null; + + CommonColor? hueColor; + public CommonColor HueColor { + get => (hueColor ?? (hueColor = LastColor.HueColor)).Value; + set { + if (!hueColor.Equals (value)) { + var saturation = Color.Saturation; + var brightness = Color.Brightness; + Color = CommonColor.FromHSB (value.Hue, saturation, brightness, Color.A); + OnPropertyChanged (nameof (Color)); + hueColor = value; + OnPropertyChanged (); + Value = new CommonSolidBrush (Color, ColorSpace, Value.Opacity); + } + } + } + + CommonColor? shade; + public CommonColor Shade { + get => (shade.HasValue ? shade : (shade = LastColor)).Value; + set { + if (!shade.Equals (value)) { + shade = value; + OnPropertyChanged (); + Value = new CommonSolidBrush (value, ColorSpace, Value.Opacity); + } + } + } + + public CommonColor Color { + get => Value is CommonSolidBrush solidBrush ? solidBrush.Color : new CommonColor(0, 0, 0); + set { + if (!Color.Equals (value)) { + CommonColor oldHue = HueColor; + CommonColor newHue = value.HueColor; + Value = new CommonSolidBrush (value, ColorSpace, Value.Opacity); + OnPropertyChanged (); + if (!newHue.Equals (oldHue)) { + hueColor = newHue; + OnPropertyChanged (nameof (HueColor)); + } + if (!value.Equals (shade)) { + shade = value; + OnPropertyChanged (nameof (Shade)); + } + if (!initialColor.HasValue) { + initialColor = value; + } + } + } + } + + CommonColor? initialColor; + public CommonColor InitialColor => initialColor ?? (initialColor = Color).Value; + + CommonColor? lastColor; + public CommonColor LastColor => lastColor ?? (lastColor = Color).Value; + + public void CommitLastColor () + { + lastColor = Color; + shade = Color; + hueColor = Color.HueColor; + OnPropertyChanged (nameof (LastColor)); + OnPropertyChanged (nameof (Shade)); + OnPropertyChanged (nameof (HueColor)); + Value = new CommonSolidBrush (Color, ColorSpace, Value.Opacity); + } + + public void CommitShade () + { + lastColor = Shade; + OnPropertyChanged (nameof (LastColor)); + Value = new CommonSolidBrush (Shade, ColorSpace, Value.Opacity); } } } |