From 331266b13685e16520ae5baa8a7aff50789c31df Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 13 Nov 2024 05:12:21 +0200 Subject: Inks Extension Support. --- .../TouchColorPickerCMYKControl.cs | 12 ++++++ .../TouchColorPickerControl.cs | 12 ++++++ .../TouchColorPickerControl.xaml | 1 + .../TouchColorPickerSlider.cs | 50 ++++++++++++++++++++++ 4 files changed, 75 insertions(+) (limited to 'Software/Visual_Studio/Tango.Touch') diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs index ba94ed30f..77fb82898 100644 --- a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs @@ -41,6 +41,18 @@ namespace Tango.Touch.Controls } } + + + public bool EnableViolet + { + get { return (bool)GetValue(EnableVioletProperty); } + set { SetValue(EnableVioletProperty, value); } + } + public static readonly DependencyProperty EnableVioletProperty = + DependencyProperty.Register("EnableViolet", typeof(bool), typeof(TouchColorPickerCMYKControl), new PropertyMetadata(false)); + + + public double ThumbHeight { get { return (double)GetValue(ThumbHeightProperty); } diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs index ae94cf9ac..e2e717183 100644 --- a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs @@ -41,6 +41,18 @@ namespace Tango.Touch.Controls } + + public bool AutoThumbColor + { + get { return (bool)GetValue(AutoThumbColorProperty); } + set { SetValue(AutoThumbColorProperty, value); } + } + public static readonly DependencyProperty AutoThumbColorProperty = + DependencyProperty.Register("AutoThumbColor", typeof(bool), typeof(TouchColorPickerControl), new PropertyMetadata(false)); + + + + public double MinValue { get { return (double)GetValue(MinValueProperty); } diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml index 503b9188a..0bdbf4009 100644 --- a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml @@ -26,6 +26,7 @@ /// The selected color property /// @@ -155,6 +164,11 @@ namespace Tango.Touch.Controls args.RoutedEvent = TouchColorPickerSlider.PickerSliderValueChangedEvent; RaiseEvent(args); } + + if (AutoThumbColor && SliderBackground is LinearGradientBrush background) + { + SelectedColor = GetRelativeColor(background.GradientStops, GetOffset(newValue, Minimum, Maximum)); + } } #endregion @@ -175,6 +189,7 @@ namespace Tango.Touch.Controls } #endregion + #region Methods public void SetValueAnotherControl(double newValue) @@ -187,6 +202,41 @@ namespace Tango.Touch.Controls } } + public static Color GetRelativeColor(GradientStopCollection gsc, double offset) + { + var point = gsc.SingleOrDefault(f => f.Offset == offset); + if (point != null) return point.Color; + + GradientStop before = gsc.Where(w => w.Offset == gsc.Min(m => m.Offset)).First(); + GradientStop after = gsc.Where(w => w.Offset == gsc.Max(m => m.Offset)).First(); + + foreach (var gs in gsc) + { + if (gs.Offset < offset && gs.Offset > before.Offset) + { + before = gs; + } + if (gs.Offset > offset && gs.Offset < after.Offset) + { + after = gs; + } + } + + var color = new Color(); + + color.ScA = (float)((offset - before.Offset) * (after.Color.ScA - before.Color.ScA) / (after.Offset - before.Offset) + before.Color.ScA); + color.ScR = (float)((offset - before.Offset) * (after.Color.ScR - before.Color.ScR) / (after.Offset - before.Offset) + before.Color.ScR); + color.ScG = (float)((offset - before.Offset) * (after.Color.ScG - before.Color.ScG) / (after.Offset - before.Offset) + before.Color.ScG); + color.ScB = (float)((offset - before.Offset) * (after.Color.ScB - before.Color.ScB) / (after.Offset - before.Offset) + before.Color.ScB); + + return color; + } + + public static double GetOffset(double value, double minValue, double maxValue) + { + return ((value - minValue) / (maxValue - minValue)); + } + #endregion //Methods } } -- cgit v1.3.1