diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch')
4 files changed, 75 insertions, 0 deletions
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 @@ <local:TouchNumericUpDownConrol x:Name="PART_ColorPickerNumericUpDown" HorizontalAlignment="Right" BorderThickness="0.8" BorderBrush="{TemplateBinding BorderBrush}" Margin="0 0 5 0" MaxValue="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=MaxValue, StringFormat='0.##'}" NumericPartWidth="68"/> </Grid> <local:TouchColorPickerSlider x:Name="PART_ColorPickerSlider" Grid.Row="1" Margin=" 0 10 0 0" Background="{TemplateBinding Background}" + AutoThumbColor="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=AutoThumbColor}" ThumbHeightInside ="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=ThumbHeightInside}" ThumbHeight="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=ThumbHeight}" ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}}" diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs index fb07ee976..7fa310927 100644 --- a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs @@ -26,6 +26,15 @@ namespace Tango.Touch.Controls #region Properties + public bool AutoThumbColor + { + get { return (bool)GetValue(AutoThumbColorProperty); } + set { SetValue(AutoThumbColorProperty, value); } + } + public static readonly DependencyProperty AutoThumbColorProperty = + DependencyProperty.Register("AutoThumbColor", typeof(bool), typeof(TouchColorPickerSlider), new PropertyMetadata(false)); + + /// <summary> /// The selected color property /// </summary> @@ -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 } } |
