diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-09-30 13:53:08 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-09-30 13:53:08 +0300 |
| commit | 40711f4902e7e6e40ea809f521373e519354b204 (patch) | |
| tree | 8bc44c991c0b15c0915e7c4929b13dbb29a24522 /Software/Visual_Studio/Tango.Touch | |
| parent | d3c16022ce28a12ea879d4143b6712319bc93a04 (diff) | |
| download | Tango-40711f4902e7e6e40ea809f521373e519354b204.tar.gz Tango-40711f4902e7e6e40ea809f521373e519354b204.zip | |
Added Slider control with three thumbs.
Related Work Items: #3772
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch')
18 files changed, 1237 insertions, 33 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericUpDownConrol.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericUpDownConrol.xaml index 7df3900f2..8963c9c3e 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericUpDownConrol.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericUpDownConrol.xaml @@ -80,7 +80,7 @@ </StackPanel.Resources> <Border Background="Transparent" BorderBrush="{StaticResource TangoGrayBrush}" BorderThickness="0.8" CornerRadius="2" Width="54"> - <local:TouchNumericTextBox x:Name="Number_PART" Margin="0 4 0 0" FontSize="20" HorizontalContentAlignment="Center" VerticalAlignment="Center" BorderBrush="{TemplateBinding BorderBrush}" VerticalContentAlignment="Center" + <local:TouchNumericTextBox x:Name="Number_PART" Margin="0 4 0 0" FontSize="20" HorizontalContentAlignment="Center" VerticalAlignment="Center" BorderBrush="{TemplateBinding BorderBrush}" VerticalContentAlignment="Center" UpdateBindingOnlyWhenFocused="True" Value="{Binding Value,RelativeSource={RelativeSource AncestorType=local:TouchNumericUpDownConrol}}" Minimum="{Binding MinValue,RelativeSource={RelativeSource AncestorType=local:TouchNumericUpDownConrol}}" Maximum="{Binding MaxValue,RelativeSource={RelativeSource AncestorType=local:TouchNumericUpDownConrol}}"/> </Border> diff --git a/Software/Visual_Studio/Tango.Touch/Resources/Colors.xaml b/Software/Visual_Studio/Tango.Touch/Resources/Colors.xaml index 39a2fd502..2433ca077 100644 --- a/Software/Visual_Studio/Tango.Touch/Resources/Colors.xaml +++ b/Software/Visual_Studio/Tango.Touch/Resources/Colors.xaml @@ -20,7 +20,7 @@ <Color x:Key="TangoDisabledBackgroundColor">#d8d8d9</Color> <Color x:Key="TangoDisabledForegroundColor">#7c7c7d</Color> - <Color x:Key="RippleLightColor">#6EFFFFFF</Color> + <Color x:Key="RippleLightColor">#28BDBDBD</Color> <Color x:Key="RippleDarkColor">#28BDBDBD</Color> <Color x:Key="TangoColumnDividerColor">#464d67</Color> diff --git a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj index 94bad74b6..df8330cb0 100644 --- a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj +++ b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj @@ -71,16 +71,19 @@ <Compile Include="Controls\TouchCalendar.cs" /> <Compile Include="Controls\TouchCheckBox.cs" /> <Compile Include="Controls\TouchClickableControl.cs" /> - <Compile Include="Controls\TouchColorPickerControl.cs" /> - <Compile Include="Controls\TouchColorPickerRGBControl.cs" /> - <Compile Include="Controls\TouchColorPickerSlider.cs" /> + <Compile Include="TouchColorPickerControls\TouchSliderThreeThumbs.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerCMYKControl.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerControl.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerLABControl.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerRGBControl.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerSlider.cs" /> <Compile Include="Controls\TouchComboBox.cs" /> <Compile Include="Controls\TouchDatePicker.cs" /> <Compile Include="Controls\TouchDropShadowBorder.cs" /> <Compile Include="Controls\TouchExpander.cs" /> <Compile Include="Controls\TouchFlatListBox.cs" /> <Compile Include="Controls\TouchGifAnimation.cs" /> - <Compile Include="Controls\TouchColorPickerHSBControl.cs" /> + <Compile Include="TouchColorPickerControls\TouchColorPickerHSBControl.cs" /> <Compile Include="Controls\TouchIcon.cs" /> <Compile Include="Controls\TouchIconKind.cs" /> <Compile Include="Controls\TouchImageButton.cs" /> @@ -139,15 +142,27 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Controls\TouchColorPickerControl.xaml"> + <Page Include="TouchColorPickerControls\TouchSliderThreeThumbs.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + <Page Include="TouchColorPickerControls\TouchColorPickerCMYKControl.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="TouchColorPickerControls\TouchColorPickerControl.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="TouchColorPickerControls\TouchColorPickerLABControl.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Controls\TouchColorPickerRGBControl.xaml"> + <Page Include="TouchColorPickerControls\TouchColorPickerRGBControl.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Controls\TouchColorPickerSlider.xaml"> + <Page Include="TouchColorPickerControls\TouchColorPickerSlider.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> @@ -175,7 +190,7 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Controls\TouchColorPickerHSBControl.xaml"> + <Page Include="TouchColorPickerControls\TouchColorPickerHSBControl.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> @@ -456,7 +471,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml index 0952149c7..babf76d85 100644 --- a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml @@ -61,10 +61,13 @@ <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Styles/TouchListBox.xaml" /> <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchPanel.xaml" /> - <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchColorPickerSlider.xaml"/> - <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchColorPickerControl.xaml"/> - <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchColorPickerHSBControl.xaml"/> - <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/Controls/TouchColorPickerRGBControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerSlider.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerHSBControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerRGBControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerLABControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchColorPickerCMYKControl.xaml"/> + <ResourceDictionary Source="pack://application:,,,/Tango.Touch;component/TouchColorPickerControls/TouchSliderThreeThumbs.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs new file mode 100644 index 000000000..7e1bb1d96 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.cs @@ -0,0 +1,492 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using ColorMine.ColorSpaces; + +namespace Tango.Touch.Controls +{ + [TemplatePart(Name = PART_CTouchColorPickerControl, Type = typeof(TouchColorPickerCMYKControl))] + [TemplatePart(Name = PART_MTouchColorPickerControl, Type = typeof(TouchColorPickerCMYKControl))] + [TemplatePart(Name = PART_YTouchColorPickerControl, Type = typeof(TouchColorPickerCMYKControl))] + [TemplatePart(Name = PART_KTouchColorPickerControl, Type = typeof(TouchColorPickerCMYKControl))] + public class TouchColorPickerCMYKControl :Control + { + private const string PART_CTouchColorPickerControl = "PART_CTouchColorPickerControl"; + private const string PART_MTouchColorPickerControl = "PART_MTouchColorPickerControl"; + private const string PART_YTouchColorPickerControl = "PART_YTouchColorPickerControl"; + private const string PART_KTouchColorPickerControl = "PART_KTouchColorPickerControl"; + + #region Property + + private TouchColorPickerControl _cyanColorSlider; + private TouchColorPickerControl _magentaColorSlider; + private TouchColorPickerControl _yellowColorSlider; + private TouchColorPickerControl _keyColorSlider; + + public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata(Color.FromRgb(128, 0, 0), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedColorPropertyChanged))); + public Color SelectedColor + { + get + { + return (Color)GetValue(SelectedColorProperty); + } + set + { + SetValue(SelectedColorProperty, value); + } + } + + public double ThumbHeight + { + get { return (double)GetValue(ThumbHeightProperty); } + set { SetValue(ThumbHeightProperty, value); } + } + + /// <summary> + /// The thumb height property + /// </summary> + public static readonly DependencyProperty ThumbHeightProperty = + DependencyProperty.Register("ThumbHeight", typeof(double), typeof(TouchColorPickerCMYKControl), new PropertyMetadata((double)18)); + + public double ThumbHeightInside + { + get { return (double)GetValue(ThumbHeightInsideProperty); } + set { SetValue(ThumbHeightInsideProperty, value); } + } + + /// <summary> + /// The thumb height property + /// </summary> + public static readonly DependencyProperty ThumbHeightInsideProperty = + DependencyProperty.Register("ThumbHeightInside", typeof(double), typeof(TouchColorPickerCMYKControl), new PropertyMetadata((double)18)); + + + public Color ThumbColor + { + get { return (Color)GetValue(ThumbColorProperty); } + set { SetValue(ThumbColorProperty, value); } + } + + /// <summary> + /// The thumb color property + /// </summary> + public static readonly DependencyProperty ThumbColorProperty = + DependencyProperty.Register("ThumbColor", typeof(Color), typeof(TouchColorPickerCMYKControl), new PropertyMetadata(Color.FromRgb(0, 0, 0))); + + public double Cyan + { + get { return (double)GetValue(CyanProperty); } + set { SetValue(CyanProperty, value); } + } + + /// <summary> + /// The cyan property + /// </summary> + public static readonly DependencyProperty CyanProperty = + DependencyProperty.Register("Cyan", typeof(double), typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnCyanPropertyChanged))); + + + public double Magenta + { + get { return (double)GetValue(MagentaProperty); } + set { SetValue(MagentaProperty, value); } + } + + /// <summary> + /// The magenta property + /// </summary> + public static readonly DependencyProperty MagentaProperty = + DependencyProperty.Register("Magenta", typeof(double), typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnMagentaPropertyChanged))); + + public double Yellow + { + get { return (double)GetValue(YellowProperty); } + set { SetValue(YellowProperty, value); } + } + + /// <summary> + /// The yellow property + /// </summary> + public static readonly DependencyProperty YellowProperty = + DependencyProperty.Register("Yellow", typeof(double), typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnYellowPropertyChanged))); + + + public double Key + { + get { return (double)GetValue(KeyProperty); } + set { SetValue(KeyProperty, value); } + } + + /// <summary> + /// The key property + /// </summary> + public static readonly DependencyProperty KeyProperty = + DependencyProperty.Register("Key", typeof(double), typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnKeyPropertyChanged))); + + + #endregion + #region Constructors + + static TouchColorPickerCMYKControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchColorPickerCMYKControl), new FrameworkPropertyMetadata(typeof(TouchColorPickerCMYKControl))); + } + + #endregion + + #region Base Class Overrides + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + Cmyk cmyk = new Cmyk(Cyan, Magenta, Yellow, Key); + SelectedColor = ConvertCMYKToRGBColor(Cyan / 100, Magenta / 100, Yellow / 100, Key / 100); + + if (_cyanColorSlider != null) + { + _cyanColorSlider.PickerSliderValueChanged -= OnCyanChanged; + } + _cyanColorSlider = GetTemplateChild(PART_CTouchColorPickerControl) as TouchColorPickerControl; + if (_cyanColorSlider != null) + { + _cyanColorSlider.MinValue = 0; + _cyanColorSlider.MaxValue = 100; + CreateCyanBrush(cmyk.M / 100, cmyk.Y / 100, cmyk.K / 100); + _cyanColorSlider.ColorValue = cmyk.C; + _cyanColorSlider.ColorPickerText = "CYAN"; + _cyanColorSlider.PickerSliderValueChanged += OnCyanChanged; + } + + if (_magentaColorSlider != null) + { + _magentaColorSlider.PickerSliderValueChanged -= OnMagentaChanged; + } + _magentaColorSlider = GetTemplateChild(PART_MTouchColorPickerControl) as TouchColorPickerControl; + if (_magentaColorSlider != null) + { + _magentaColorSlider.MinValue = 0; + _magentaColorSlider.MaxValue = 100; + CreateMagentaBrush(cmyk.C / 100, cmyk.Y / 100, cmyk.K / 100); + _magentaColorSlider.ColorValue = cmyk.M; + _magentaColorSlider.ColorPickerText = "MAGENTA"; + _magentaColorSlider.PickerSliderValueChanged += OnMagentaChanged; + } + + if (_yellowColorSlider != null) + { + _yellowColorSlider.PickerSliderValueChanged -= OnYellowChanged; + } + _yellowColorSlider = GetTemplateChild(PART_YTouchColorPickerControl) as TouchColorPickerControl; + if (_yellowColorSlider != null) + { + _yellowColorSlider.MinValue = 0; + _yellowColorSlider.MaxValue = 100; + CreateYellowBrush(cmyk.C / 100, cmyk.M / 100, cmyk.K / 100); + _yellowColorSlider.ColorValue = cmyk.Y; + _yellowColorSlider.ColorPickerText = "YELLOW"; + _yellowColorSlider.PickerSliderValueChanged += OnYellowChanged; + } + + if (_keyColorSlider != null) + { + _keyColorSlider.PickerSliderValueChanged -= OnKeyChanged; + } + _keyColorSlider = GetTemplateChild(PART_KTouchColorPickerControl) as TouchColorPickerControl; + if (_keyColorSlider != null) + { + _keyColorSlider.MinValue = 0; + _keyColorSlider.MaxValue = 100; + CreateKeyBrush(cmyk.C / 100, cmyk.M / 100, cmyk.Y / 100); + _keyColorSlider.ColorValue = cmyk.K; + _keyColorSlider.ColorPickerText = "KEY"; + _keyColorSlider.PickerSliderValueChanged += OnKeyChanged; + } + } + + #endregion + + #region Methods + private static void OnSelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerCMYKControl TouchColorPickerCMYKControl = (TouchColorPickerCMYKControl)d; + if (TouchColorPickerCMYKControl != null) + TouchColorPickerCMYKControl.OnSelectedColorChanged((Color?)e.OldValue, (Color?)e.NewValue); + } + private void OnSelectedColorChanged(Color? oldValue, Color? newValue) + { + RoutedPropertyChangedEventArgs<Color?> args = new RoutedPropertyChangedEventArgs<Color?>(oldValue, newValue); + args.RoutedEvent = TouchColorPickerCMYKControl.SelectedColorChangedEvent; + RaiseEvent(args); + } + + private static void OnCyanPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerCMYKControl TouchColorPickerCMYKControl = (TouchColorPickerCMYKControl)d; + if (TouchColorPickerCMYKControl != null) + { + TouchColorPickerCMYKControl.OnCyanPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + + private void OnCyanPropertyChanged(double oldValue, double newValue) + { + if (_cyanColorSlider != null && oldValue != newValue) + { + _cyanColorSlider.ColorValue = newValue; + } + } + + private static void OnMagentaPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerCMYKControl TouchColorPickerCMYKControl = (TouchColorPickerCMYKControl)d; + if (TouchColorPickerCMYKControl != null) + { + TouchColorPickerCMYKControl.OnMagentaLabPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + + private void OnMagentaLabPropertyChanged(double oldValue, double newValue) + { + if (_magentaColorSlider != null && oldValue != newValue) + { + _magentaColorSlider.ColorValue = newValue; + } + } + + private static void OnYellowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerCMYKControl TouchColorPickerCMYKControl = (TouchColorPickerCMYKControl)d; + if (TouchColorPickerCMYKControl != null) + { + TouchColorPickerCMYKControl.OnYellowPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + private void OnYellowPropertyChanged(double oldValue, double newValue) + { + if (_yellowColorSlider != null && oldValue != newValue) + { + _yellowColorSlider.ColorValue = newValue; + } + } + + private static void OnKeyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerCMYKControl TouchColorPickerCMYKControl = (TouchColorPickerCMYKControl)d; + if (TouchColorPickerCMYKControl != null) + { + TouchColorPickerCMYKControl.OnKeyPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + private void OnKeyPropertyChanged(double oldValue, double newValue) + { + if (_keyColorSlider != null && oldValue != newValue) + { + _keyColorSlider.ColorValue = newValue; + } + } + + /// <summary> + /// Creates the cyan brush. + /// </summary> + private void CreateCyanBrush(double magenta, double yellow, double key) + { + LinearGradientBrush cyanBrush = new LinearGradientBrush(); + cyanBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + cyanBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(0, magenta, yellow, key), 0.0)); + cyanBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(1, magenta, yellow, key), 1)); + _cyanColorSlider.PickerBrush = cyanBrush; + } + + /// <summary> + /// Creates the magenta brush. + /// </summary> + private void CreateMagentaBrush(double cyan, double yellow, double key) + { + LinearGradientBrush magentaBrush = new LinearGradientBrush(); + magentaBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + magentaBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, 0, yellow, key), 0.0)); + magentaBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, 1, yellow, key), 1.0)); + _magentaColorSlider.PickerBrush = magentaBrush; + } + + /// <summary> + /// Creates the yellow brush. + /// </summary> + private void CreateYellowBrush(double cyan, double magenta, double key) + { + LinearGradientBrush yellowBrush = new LinearGradientBrush(); + yellowBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + yellowBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, magenta, 0, key), 0.0)); + yellowBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, magenta, 1, key), 1.0)); + _yellowColorSlider.PickerBrush = yellowBrush; + } + + /// <summary> + /// Creates the black brush. + /// </summary> + private void CreateKeyBrush(double cyan, double magenta, double yellow) + { + LinearGradientBrush keyBrush = new LinearGradientBrush(); + keyBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + keyBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, magenta, yellow, 0), 0.0)); + keyBrush.GradientStops.Add(new GradientStop(ConvertCMYKToRGBColor(cyan, magenta, yellow, 1), 1.0)); + _keyColorSlider.PickerBrush = keyBrush; + } + + /// <summary> + /// Called when [cyan slider value has changed]. + /// </summary> + private void OnCyanChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + if (e.OldValue != e.NewValue) + { + SelectedColor = ConvertCMYKToRGBColor(e.NewValue / 100, _magentaColorSlider.ColorValue / 100, _yellowColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _cyanColorSlider.SelectedColor = SelectedColor; + Cyan = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + + CreateMagentaBrush(e.NewValue / 100, _yellowColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _magentaColorSlider.SelectedColor = SelectedColor; + CreateYellowBrush(e.NewValue / 100, _magentaColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _yellowColorSlider.SelectedColor = SelectedColor; + CreateKeyBrush(e.NewValue / 100, _magentaColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _keyColorSlider.SelectedColor = SelectedColor; + } + } + + /// <summary> + /// Called when [magenta slider value changed]. + /// </summary> + private void OnMagentaChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + if (e.OldValue != e.NewValue) + { + SelectedColor = ConvertCMYKToRGBColor(_cyanColorSlider.ColorValue / 100, e.NewValue / 100, _yellowColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _magentaColorSlider.SelectedColor = SelectedColor; + Magenta = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + + CreateCyanBrush(e.NewValue / 100, _yellowColorSlider.ColorValue / 100, _keyColorSlider.ColorValue / 100); + _cyanColorSlider.SelectedColor = SelectedColor; + CreateYellowBrush(_cyanColorSlider.ColorValue / 100, e.NewValue / 100, _keyColorSlider.ColorValue / 100); + _yellowColorSlider.SelectedColor = SelectedColor; + CreateKeyBrush(_cyanColorSlider.ColorValue / 100, e.NewValue / 100, _yellowColorSlider.ColorValue / 100); + _keyColorSlider.SelectedColor = SelectedColor; + } + } + + /// <summary> + /// Called when [yellow slider value changed]. + /// </summary> + private void OnYellowChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + if (e.OldValue != e.NewValue) + { + SelectedColor = ConvertCMYKToRGBColor(_cyanColorSlider.ColorValue / 100, _magentaColorSlider.ColorValue / 100, e.NewValue / 100, _keyColorSlider.ColorValue / 100); + _yellowColorSlider.SelectedColor = SelectedColor; + Yellow = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + + CreateCyanBrush(_magentaColorSlider.ColorValue / 100, e.NewValue / 100, _keyColorSlider.ColorValue / 100); + _cyanColorSlider.SelectedColor = SelectedColor; + CreateMagentaBrush(_cyanColorSlider.ColorValue / 100, e.NewValue / 100, _keyColorSlider.ColorValue / 100); + _magentaColorSlider.SelectedColor = SelectedColor; + CreateKeyBrush(_cyanColorSlider.ColorValue / 100, _magentaColorSlider.ColorValue / 100, e.NewValue / 100); + _keyColorSlider.SelectedColor = SelectedColor; + } + } + + /// <summary> + /// Called when [yellow slider value changed]. + /// </summary> + private void OnKeyChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + if (e.OldValue != e.NewValue) + { + SelectedColor = ConvertCMYKToRGBColor(_cyanColorSlider.ColorValue / 100, _magentaColorSlider.ColorValue / 100, _yellowColorSlider.ColorValue / 100, e.NewValue / 100); + _keyColorSlider.SelectedColor = SelectedColor; + Key = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + + CreateCyanBrush(_magentaColorSlider.ColorValue / 100, _yellowColorSlider.ColorValue / 100, e.NewValue / 100); + _cyanColorSlider.SelectedColor = SelectedColor; + CreateMagentaBrush(_cyanColorSlider.ColorValue / 100, _yellowColorSlider.ColorValue / 100, e.NewValue / 100); + _magentaColorSlider.SelectedColor = SelectedColor; + CreateYellowBrush(_cyanColorSlider.ColorValue / 100, _magentaColorSlider.ColorValue / 100, e.NewValue / 100); + _yellowColorSlider.SelectedColor = SelectedColor; + } + } + + /// <summary> + /// Convert CMYYK to RGB color. + /// </summary> + public Color ConvertCMYKToRGBColor(double cyan, double magenta, double yellow, double key) + { + //var t = 255 * (1 - cyan) * (1 - black); + //var red = (int)(255 * (1 - cyan) * (1 - black)); + //var green = (int)(255 * (1 - magenta) * (1 - black)); + //var blue = (int)(255 * (1 - yellow) * (1 - black)); + //Cmyk cmyk = new Cmyk(cyan, magenta, yellow, black); + //Rgb rgb = new Rgb(cmyk.ToRgb()); + + //var test1 = Color.FromArgb(255, (byte)red, (byte)green, (byte)blue); + //var test2 = Color.FromArgb(255, (byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + //if(test1 != test2) + //{ + // int b = 0; + // b = 1; + //} + Cmyk cmyk = new Cmyk(cyan, magenta, yellow, key); + Rgb rgb = new Rgb(cmyk.ToRgb()); + return Color.FromArgb(255, (byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + } + + /// <summary> + /// Converts the RGB to CMYK color. + /// </summary> + public static Cmyk ConvertRgbToCmyk(int r, int g, int b) + { + //float c, m, y, k, rf, gf, bf; + //rf = r / 255F; + //gf = g / 255F; + //bf = b / 255F; + + //k = Convert.ToUInt32(ClampCmyk(1 - Math.Max(Math.Max(rf, gf), bf))); + //c = Convert.ToUInt32(ClampCmyk((1 - rf - k) / (1 - k))); + //m = Convert.ToUInt32(ClampCmyk((1 - gf - k) / (1 - k))); + //y = Convert.ToUInt32(ClampCmyk((1 - bf - k) / (1 - k))); + Rgb rgb = new Rgb(r, g, b); + var cmyk = rgb.To<Cmyk>(); + + return cmyk;// new CmykColor(c, m, y, k); + } + + /// <summary> + /// Clamps the cmyk. + /// </summary> + private static float ClampCmyk(float value) + { + return (value < 0 || float.IsNaN(value)) ? 0 : value; + } + #endregion + + #region Events + + public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<Color?>), typeof(TouchColorPickerCMYKControl)); + public event RoutedPropertyChangedEventHandler<Color?> SelectedColorChanged + { + add + { + AddHandler(SelectedColorChangedEvent, value); + } + remove + { + RemoveHandler(SelectedColorChangedEvent, value); + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.xaml new file mode 100644 index 000000000..513909c9e --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerCMYKControl.xaml @@ -0,0 +1,41 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:Tango.Touch.Controls"> + + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="../Resources/Colors.xaml" /> + </ResourceDictionary.MergedDictionaries> + + <Style TargetType="{x:Type local:TouchColorPickerCMYKControl}"> + <Setter Property="Background" Value="Transparent"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type local:TouchColorPickerCMYKControl}"> + <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" CornerRadius="16" Padding="0"> + <UniformGrid Margin="4" Columns="1" Rows="4"> + <local:TouchColorPickerControl x:Name="PART_CTouchColorPickerControl" Grid.Row="0" Margin=" 0 10 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="0" MaxValue="100" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}"/> + <local:TouchColorPickerControl x:Name="PART_MTouchColorPickerControl" Grid.Row="1" Margin=" 0 4 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="0" MaxValue="100" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}"/> + <local:TouchColorPickerControl x:Name="PART_YTouchColorPickerControl" Grid.Row="2" Margin=" 0 4 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="0" MaxValue="100" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}"/> + <local:TouchColorPickerControl x:Name="PART_KTouchColorPickerControl" Grid.Row="3" Margin=" 0 4 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="0" MaxValue="100" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerCMYKControl}}"/> + + + </UniformGrid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs index 945509445..945509445 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerControl.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.cs diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml index a1373054b..e129b5ce9 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerControl.xaml +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerControl.xaml @@ -22,7 +22,7 @@ </Grid.ColumnDefinitions> <Grid Grid.Row="0"> <TextBlock FontSize="{StaticResource TangoComboBoxItemFontSize}" TextBlock.Text="{Binding ColorPickerText, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}}" HorizontalAlignment="Left" Margin="6 0 0 0" FontWeight="SemiBold" VerticalAlignment="Center" /> - <local:TouchNumericUpDownConrol x:Name="PART_ColorPickerNumericUpDown" HorizontalAlignment="Right" BorderThickness="0.8" BorderBrush="{TemplateBinding BorderBrush}" Margin="0 0 5 0"/> + <local:TouchNumericUpDownConrol x:Name="PART_ColorPickerNumericUpDown" HorizontalAlignment="Right" BorderThickness="0.8" BorderBrush="{TemplateBinding BorderBrush}" Margin="0 0 5 0" /> </Grid> <local:TouchColorPickerSlider x:Name="PART_ColorPickerSlider" Grid.Row="1" Margin=" 0 10 0 0" Background="{TemplateBinding Background}" ThumbHeightInside ="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=ThumbHeightInside}" @@ -30,8 +30,8 @@ ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}}" SelectedColor="{Binding SelectedColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}}"/> <DockPanel Grid.Row="2" Margin=" 0 0 0 0"> - <TextBlock DockPanel.Dock="Left" FontSize="{StaticResource TangoSmallFontSize}" TextBlock.Text="0" HorizontalAlignment="Left" Margin="6 0 0 0" VerticalAlignment="Center" FontWeight="SemiBold"/> - <TextBlock DockPanel.Dock="Right" FontSize="{StaticResource TangoSmallFontSize}" TextBlock.Text="100%" HorizontalAlignment="Right" Margin="6 0 0 0" VerticalAlignment="Center" FontWeight="SemiBold" /> + <TextBlock DockPanel.Dock="Left" FontSize="{StaticResource TangoSmallFontSize}" TextBlock.Text="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=MinValue}" HorizontalAlignment="Left" Margin="6 0 0 0" VerticalAlignment="Center" FontWeight="SemiBold"/> + <TextBlock DockPanel.Dock="Right" FontSize="{StaticResource TangoSmallFontSize}" TextBlock.Text="{Binding RelativeSource={RelativeSource AncestorType=local:TouchColorPickerControl}, Path=MaxValue}" HorizontalAlignment="Right" Margin="6 0 0 0" VerticalAlignment="Center" FontWeight="SemiBold" /> </DockPanel> </Grid> </ControlTemplate> diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerHSBControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerHSBControl.cs index 2fd743b54..2fd743b54 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerHSBControl.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerHSBControl.cs diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerHSBControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerHSBControl.xaml index d2e28ca74..d2e28ca74 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerHSBControl.xaml +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerHSBControl.xaml diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.cs new file mode 100644 index 000000000..98fb01aea --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.cs @@ -0,0 +1,387 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows; +using ColorMine.ColorSpaces; + + +namespace Tango.Touch.Controls +{ + [TemplatePart(Name = PART_LTouchColorPickerControl, Type = typeof(TouchColorPickerControl))] + [TemplatePart(Name = PART_GRTouchColorPickerControl, Type = typeof(TouchColorPickerControl))] + [TemplatePart(Name = PART_BYTouchColorPickerControl, Type = typeof(TouchColorPickerControl))] + public class TouchColorPickerLABControl : Control + + { + private const string PART_LTouchColorPickerControl = "PART_LTouchColorPickerControl"; + private const string PART_GRTouchColorPickerControl = "PART_GRTouchColorPickerControl"; + private const string PART_BYTouchColorPickerControl = "PART_BYTouchColorPickerControl"; + + #region Property + + private TouchColorPickerControl _luminanceColorSlider; + + private TouchColorPickerControl _greenRedColorSlider; + + private TouchColorPickerControl _blueYellowColorSlider; + + /// <summary> + /// The selected color property + /// </summary> + public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(TouchColorPickerLABControl), new FrameworkPropertyMetadata(Color.FromRgb(128, 0, 0), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedColorPropertyChanged))); + public Color? SelectedColor + { + get + { + return (Color)GetValue(SelectedColorProperty); + } + set + { + SetValue(SelectedColorProperty, value); + } + } + + public double ThumbHeight + { + get { return (double)GetValue(ThumbHeightProperty); } + set { SetValue(ThumbHeightProperty, value); } + } + + /// <summary> + /// The thumb height property + /// </summary> + public static readonly DependencyProperty ThumbHeightProperty = + DependencyProperty.Register("ThumbHeight", typeof(double), typeof(TouchColorPickerLABControl), new PropertyMetadata((double)18)); + + public double ThumbHeightInside + { + get { return (double)GetValue(ThumbHeightInsideProperty); } + set { SetValue(ThumbHeightInsideProperty, value); } + } + + /// <summary> + /// The thumb height inside property + /// </summary> + public static readonly DependencyProperty ThumbHeightInsideProperty = + DependencyProperty.Register("ThumbHeightInside", typeof(double), typeof(TouchColorPickerLABControl), new PropertyMetadata((double)18)); + + public Color ThumbColor + { + get { return (Color)GetValue(ThumbColorProperty); } + set { SetValue(ThumbColorProperty, value); } + } + /// <summary> + /// The thumb color property + /// </summary> + public static readonly DependencyProperty ThumbColorProperty = + DependencyProperty.Register("ThumbColor", typeof(Color), typeof(TouchColorPickerLABControl), new PropertyMetadata(Color.FromRgb(0, 0, 0))); + + public double L + { + get { return (double)GetValue(LProperty); } + set { SetValue(LProperty, value); } + } + /// <summary> + /// The L property + /// </summary> + public static readonly DependencyProperty LProperty = + DependencyProperty.Register("L", typeof(double), typeof(TouchColorPickerLABControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnLPropertyChanged))); + + public double A + { + get { return (double)GetValue(AProperty); } + set { + var roundValue = Math.Round(value, 2, MidpointRounding.AwayFromZero); + SetValue(AProperty, roundValue); } + } + /// <summary> + /// The saturation property + /// </summary> + public static readonly DependencyProperty AProperty = + DependencyProperty.Register("A", typeof(double), typeof(TouchColorPickerLABControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnAPropertyChanged))); + + public double B + { + get { return (double)GetValue(BProperty); } + set { + var roundValue = Math.Round(value, 2, MidpointRounding.AwayFromZero); + SetValue(BProperty, roundValue); } + } + + /// <summary> + /// The brightness property + /// </summary> + public static readonly DependencyProperty BProperty = + DependencyProperty.Register("B", typeof(double), typeof(TouchColorPickerLABControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnBPropertyChanged))); + + #endregion + #region Constructors + + static TouchColorPickerLABControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchColorPickerLABControl), new FrameworkPropertyMetadata(typeof(TouchColorPickerLABControl))); + } + + #endregion + + #region Base Class Overrides + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + Lab labcolor = new Lab(L, A, B); + SelectedColor = ConvertLabToRgb(L, A, B); + + if (_luminanceColorSlider != null) + { + _luminanceColorSlider.PickerSliderValueChanged -= OnLuminanceChanged; + } + _luminanceColorSlider = GetTemplateChild(PART_LTouchColorPickerControl) as TouchColorPickerControl; + if (_luminanceColorSlider != null) + { + _luminanceColorSlider.MinValue = 0; + _luminanceColorSlider.MaxValue = 100; + CreateLuminanceBrush(labcolor.L, labcolor.A, labcolor.B); + _luminanceColorSlider.ColorValue = labcolor.L; + _luminanceColorSlider.ColorPickerText = "L"; + _luminanceColorSlider.PickerSliderValueChanged += OnLuminanceChanged; + } + if (_greenRedColorSlider != null) + { + _greenRedColorSlider.PickerSliderValueChanged -= OnGreenRedValueChanged; + } + _greenRedColorSlider = GetTemplateChild(PART_GRTouchColorPickerControl) as TouchColorPickerControl; + if (_greenRedColorSlider != null) + { + _greenRedColorSlider.MinValue = -128; + _greenRedColorSlider.MaxValue = 127; + CreateGreenRedBrush(labcolor.L, labcolor.A, labcolor.B); + _greenRedColorSlider.ColorValue = labcolor.A; + _greenRedColorSlider.ColorPickerText = "A"; + _greenRedColorSlider.PickerSliderValueChanged += OnGreenRedValueChanged; + } + if (_blueYellowColorSlider != null) + { + _blueYellowColorSlider.PickerSliderValueChanged -= OnBlueYellowColorChanged; + } + _blueYellowColorSlider = GetTemplateChild(PART_BYTouchColorPickerControl) as TouchColorPickerControl; + if (_blueYellowColorSlider != null) + { + _blueYellowColorSlider.MinValue = -128; + _blueYellowColorSlider.MaxValue = 127; + CreateBlueYellowBrush(labcolor.L, labcolor.A, labcolor.B); + _blueYellowColorSlider.ColorValue = labcolor.B; + _blueYellowColorSlider.ColorPickerText = "B"; + _blueYellowColorSlider.PickerSliderValueChanged += OnBlueYellowColorChanged; + } + } + + #endregion + + #region Methods + private static void OnSelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerLABControl TouchColorPickerLABControl = (TouchColorPickerLABControl)d; + if (TouchColorPickerLABControl != null) + TouchColorPickerLABControl.OnSelectedColorChanged((Color?)e.OldValue, (Color?)e.NewValue); + } + + private void OnSelectedColorChanged(Color? oldValue, Color? newValue) + { + RoutedPropertyChangedEventArgs<Color?> args = new RoutedPropertyChangedEventArgs<Color?>(oldValue, newValue); + args.RoutedEvent = TouchColorPickerLABControl.SelectedColorChangedEvent; + RaiseEvent(args); + } + + private static void OnLPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerLABControl TouchColorPickerLABControl = (TouchColorPickerLABControl)d; + if (TouchColorPickerLABControl != null) + { + TouchColorPickerLABControl.OnLLabPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + + private void OnLLabPropertyChanged(double oldValue, double newValue) + { + if (_luminanceColorSlider != null && oldValue != newValue) + { + _luminanceColorSlider.ColorValue = newValue; + } + } + + private static void OnAPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerLABControl TouchColorPickerLABControl = (TouchColorPickerLABControl)d; + if (TouchColorPickerLABControl != null) + { + TouchColorPickerLABControl.OnALabPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + + private void OnALabPropertyChanged(double oldValue, double newValue) + { + if (_greenRedColorSlider != null && oldValue != newValue) + { + _greenRedColorSlider.ColorValue = newValue; + } + } + + private static void OnBPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchColorPickerLABControl TouchColorPickerLABControl = (TouchColorPickerLABControl)d; + if (TouchColorPickerLABControl != null) + { + TouchColorPickerLABControl.OnBLabPropertyChanged((double)e.OldValue, (double)e.NewValue); + } + } + private void OnBLabPropertyChanged(double oldValue, double newValue) + { + if (_blueYellowColorSlider != null && oldValue != newValue) + { + _blueYellowColorSlider.ColorValue = newValue; + } + } + + /// <summary> + /// Creates the luminance slider brush. + /// </summary> + private void CreateLuminanceBrush(double luminance, double green_red, double blue_yellow) + { + LinearGradientBrush luminanceBrush = new LinearGradientBrush(); + luminanceBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + //luminanceBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(0, green_red, blue_yellow), 0.0)); + //luminanceBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(100, green_red, blue_yellow), 1)); + luminanceBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.0)); + luminanceBrush.GradientStops.Add(new GradientStop(Colors.White, 1)); + _luminanceColorSlider.PickerBrush = luminanceBrush; + _luminanceColorSlider.SelectedColor = ConvertLabToRgb(luminance, green_red, blue_yellow); + } + + /// <summary> + /// Creates the green-red slider brush. + /// </summary> + private void CreateGreenRedBrush(double luminance, double green_red, double blue_yellow) + { + LinearGradientBrush greenRedBrush = new LinearGradientBrush(); + greenRedBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + //greenRedBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(luminance, -128, blue_yellow), 0.0)); + // greenRedBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(luminance, 127, blue_yellow), 1.0)); + greenRedBrush.GradientStops.Add(new GradientStop(Colors.Green, 0.0)); + greenRedBrush.GradientStops.Add(new GradientStop(Colors.Red, 1.0)); + _greenRedColorSlider.PickerBrush = greenRedBrush; + _greenRedColorSlider.SelectedColor = ConvertLabToRgb(luminance, green_red, blue_yellow); + } + + /// <summary> + /// Creates the blue-yellow slider brush. + /// </summary> + private void CreateBlueYellowBrush(double luminance, double green_red, double blue_yellow) + { + LinearGradientBrush blueYellowBrush = new LinearGradientBrush(); + blueYellowBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; + //blueYellowBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(luminance, green_red, -128), 0.0)); + //blueYellowBrush.GradientStops.Add(new GradientStop(ConvertLabToRgb(luminance, green_red, 127), 1.0)); + blueYellowBrush.GradientStops.Add(new GradientStop(Colors.Blue, 0.0)); + blueYellowBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 1.0)); + _blueYellowColorSlider.PickerBrush = blueYellowBrush; + _blueYellowColorSlider.SelectedColor = ConvertLabToRgb(luminance, green_red, blue_yellow); + } + + /// <summary> + /// Called when [luminance slider value has changed]. + /// </summary> + private void OnLuminanceChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + //if (e.OldValue != e.NewValue) + { + _luminanceColorSlider.SelectedColor = ConvertLabToRgb(e.NewValue, _greenRedColorSlider.ColorValue, _blueYellowColorSlider.ColorValue); + SelectedColor = ConvertLabToRgb(e.NewValue, _greenRedColorSlider.ColorValue, _blueYellowColorSlider.ColorValue); + + L = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + _greenRedColorSlider.SelectedColor = SelectedColor; + _blueYellowColorSlider.SelectedColor = SelectedColor; + // CreateGreenRedBrush(e.NewValue, _greenRedColorSlider.ColorValue, _blueYellowColorSlider.ColorValue); + //CreateBlueYellowBrush(e.NewValue, _greenRedColorSlider.ColorValue, _blueYellowColorSlider.ColorValue); + } + } + + /// <summary> + /// Called when [ blue-yellow slider value changed]. + /// </summary> + private void OnGreenRedValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + //if (e.OldValue != e.NewValue) + { + SelectedColor = ConvertLabToRgb(_luminanceColorSlider.ColorValue, e.NewValue, _blueYellowColorSlider.ColorValue); + A = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + _greenRedColorSlider.SelectedColor = SelectedColor; + + _luminanceColorSlider.SelectedColor = SelectedColor; + _blueYellowColorSlider.SelectedColor = SelectedColor; + //CreateLuminanceBrush(_luminanceColorSlider.ColorValue, e.NewValue, _blueYellowColorSlider.ColorValue); + //CreateBlueYellowBrush(_luminanceColorSlider.ColorValue, e.NewValue, _blueYellowColorSlider.ColorValue); + } + } + + /// <summary> + /// Called when [yellow slider value changed]. + /// </summary> + private void OnBlueYellowColorChanged(object sender, RoutedPropertyChangedEventArgs<double> e) + { + // if (e.OldValue != e.NewValue) + { + + SelectedColor = ConvertLabToRgb(_luminanceColorSlider.ColorValue, _greenRedColorSlider.ColorValue, e.NewValue); + B = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); + _blueYellowColorSlider.SelectedColor = SelectedColor; + + _luminanceColorSlider.SelectedColor = SelectedColor; + _greenRedColorSlider.SelectedColor = SelectedColor; + //CreateLuminanceBrush(_luminanceColorSlider.ColorValue, _greenRedColorSlider.ColorValue, e.NewValue); + //CreateGreenRedBrush(_luminanceColorSlider.ColorValue, _greenRedColorSlider.ColorValue, e.NewValue); + } + } + #endregion + + #region Events + + public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<Color?>), typeof(TouchColorPickerLABControl)); + public event RoutedPropertyChangedEventHandler<Color?> SelectedColorChanged + { + add + { + AddHandler(SelectedColorChangedEvent, value); + } + remove + { + RemoveHandler(SelectedColorChangedEvent, value); + } + } + + #endregion + + #region LAB RGB Converters + + public static Color ConvertLabToRgb(double l, double a, double b) + { + Lab lab = new Lab(l, a, b); + Rgb rgb = new Rgb(lab.ToRgb()); + return Color.FromArgb(255, (byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + } + + public static Lab ConvertRgbToLab(int r, int g, int b) + { + Rgb rgb = new Rgb(r, g, b); + Lab lab = rgb.To<Lab>(); + return lab; + + } + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.xaml new file mode 100644 index 000000000..4ccf71295 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerLABControl.xaml @@ -0,0 +1,37 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:Tango.Touch.Controls"> + + + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="../Resources/Colors.xaml" /> + </ResourceDictionary.MergedDictionaries> + + <Style TargetType="{x:Type local:TouchColorPickerLABControl}"> + <Setter Property="Background" Value="Transparent"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type local:TouchColorPickerLABControl}"> + <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" CornerRadius="16" Padding="0"> + <UniformGrid Margin="4" Columns="1" Rows="3"> + <local:TouchColorPickerControl x:Name="PART_LTouchColorPickerControl" Grid.Row="0" Margin=" 0 10 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="0" MaxValue="360" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}"/> + <local:TouchColorPickerControl x:Name="PART_GRTouchColorPickerControl" Grid.Row="1" Margin=" 0 4 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="-128" MaxValue="127" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}"/> + <local:TouchColorPickerControl x:Name="PART_BYTouchColorPickerControl" Grid.Row="2" Margin=" 0 4 0 0" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="160" VerticalAlignment="Bottom" MinValue="-128" MaxValue="127" + ThumbHeight="{Binding ThumbHeight, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbHeightInside="{Binding ThumbHeightInside, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}" + ThumbColor="{Binding ThumbColor, RelativeSource={RelativeSource AncestorType=local:TouchColorPickerLABControl}}"/> + + </UniformGrid> + </Border> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerRGBControl.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerRGBControl.cs index 9b0514fcc..1d5b285ea 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerRGBControl.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerRGBControl.cs @@ -256,9 +256,10 @@ namespace Tango.Touch.Controls _RColorSlider.SelectedColor = color; R = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); SelectedColor = color; - - CreateGBrush(color); - CreateBBrush(color); + _GColorSlider.SelectedColor = SelectedColor; + _BColorSlider.SelectedColor = SelectedColor; + //CreateGBrush(color); + //CreateBBrush(color); } } @@ -273,9 +274,10 @@ namespace Tango.Touch.Controls _GColorSlider.SelectedColor = color; G = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); SelectedColor = color; - - CreateRBrush(color); - CreateBBrush(color); + _RColorSlider.SelectedColor = SelectedColor; + _BColorSlider.SelectedColor = SelectedColor; + //CreateRBrush(color); + //CreateBBrush(color); } } @@ -290,9 +292,10 @@ namespace Tango.Touch.Controls _BColorSlider.SelectedColor = color; B = Math.Round(e.NewValue, 2, MidpointRounding.AwayFromZero); SelectedColor = color; - - CreateRBrush(color); - CreateGBrush(color); + _RColorSlider.SelectedColor = SelectedColor; + _GColorSlider.SelectedColor = SelectedColor; + //CreateRBrush(color); + //CreateGBrush(color); } } @@ -303,8 +306,10 @@ namespace Tango.Touch.Controls { LinearGradientBrush rBrush = new LinearGradientBrush(); rBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; - rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, color.G, color.B), 0.0)); - rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(255, color.G, color.B), 1.0)); + //rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, color.G, color.B), 0.0)); + //rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(255, color.G, color.B), 1.0)); + rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0.0)); + rBrush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 1.0)); _RColorSlider.PickerBrush = rBrush; _RColorSlider.SelectedColor = Color.FromRgb((byte)_RColorSlider.ColorValue, color.G, color.B); } @@ -316,8 +321,10 @@ namespace Tango.Touch.Controls { LinearGradientBrush gBrush = new LinearGradientBrush(); gBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; - gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, 0, color.B), 0.0)); - gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, 255, color.B), 1.0)); + //gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, 0, color.B), 0.0)); + //gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, 255, color.B), 1.0)); + gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.0)); + gBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 1.0)); _GColorSlider.PickerBrush = gBrush; _GColorSlider.SelectedColor = Color.FromRgb(color.R, (byte) _GColorSlider.ColorValue, color.B); } @@ -329,8 +336,10 @@ namespace Tango.Touch.Controls { LinearGradientBrush bBrush = new LinearGradientBrush(); bBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; - bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, color.G, 0), 0.0)); - bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, color.G, 255), 1.0)); + //bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, color.G, 0), 0.0)); + //bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(color.R, color.G, 255), 1.0)); + bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 0.0)); + bBrush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 0, 255), 1.0)); _BColorSlider.PickerBrush = bBrush; _BColorSlider.SelectedColor = Color.FromRgb(color.R, color.G, (byte)_BColorSlider.ColorValue); } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerRGBControl.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerRGBControl.xaml index 86a3e35bb..86a3e35bb 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerRGBControl.xaml +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerRGBControl.xaml diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerSlider.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs index c92c52158..c92c52158 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerSlider.cs +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.cs diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerSlider.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.xaml index b5cebf60f..b5cebf60f 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchColorPickerSlider.xaml +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchColorPickerSlider.xaml diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.cs b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.cs new file mode 100644 index 000000000..52321a7a2 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Tango.Touch.Controls +{ + [TemplatePart(Name = PART_LowerSlider, Type = typeof(TouchSlider))] + [TemplatePart(Name = Part_MiddleSlider, Type = typeof(TouchSlider))] + [TemplatePart(Name = PART_UpperSlider, Type = typeof(TouchSlider))] + public class TouchSliderThreeThumbs : Control + { + private const string PART_LowerSlider = "PART_LowerSlider"; + private const string Part_MiddleSlider = "Part_MiddleSlider"; + private const string PART_UpperSlider = "PART_UpperSlider"; + + #region Members + + private TouchSlider _lowerSlider; + private TouchSlider _middleSlider; + private TouchSlider _upperSlider; + + #endregion + + + static TouchSliderThreeThumbs() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchSliderThreeThumbs), new FrameworkPropertyMetadata(typeof(TouchSliderThreeThumbs))); + } + + #region properties + + public double LowerValue + { + get { return (double)GetValue(LowerValueProperty); } + set { SetValue(LowerValueProperty, value); } + } + + public static readonly DependencyProperty LowerValueProperty = + DependencyProperty.Register("LowerValue", typeof(double), typeof(TouchSliderThreeThumbs), new UIPropertyMetadata(0d, null, LowerValueCoerceValueCallback)); + + public double UpperValue + { + get { return (double)GetValue(UpperValueProperty); } + set { SetValue(UpperValueProperty, value); } + } + public static readonly DependencyProperty UpperValueProperty = + DependencyProperty.Register("UpperValue", typeof(double), typeof(TouchSliderThreeThumbs), new UIPropertyMetadata(1d, null, UpperValueCoerceValueCallback)); + + public double MiddleValue + { + get { return (double)GetValue(MiddleValueProperty); } + set { SetValue(MiddleValueProperty, value); } + } + public static readonly DependencyProperty MiddleValueProperty = + DependencyProperty.Register("MiddleValue", typeof(double), typeof(TouchSliderThreeThumbs), new UIPropertyMetadata(0d, null, MiddleValueCoerceValueCallback)); + + public double MinimumMiddleRange + { + get { return (double)GetValue(MinimumMiddleRangeProperty); } + set { SetValue(MinimumMiddleRangeProperty, value); } + } + /// <summary> + /// The minimum middle range property in meters + /// </summary> + public static readonly DependencyProperty MinimumMiddleRangeProperty = + DependencyProperty.Register("MinimumMiddleRange", typeof(double), typeof(TouchSliderThreeThumbs), new UIPropertyMetadata(5d)); + + + public double Length + { + get { return (double)GetValue(LengthProperty); } + set { SetValue(LengthProperty, value); } + } + + /// <summary> + /// The length property in meters + /// </summary> + public static readonly DependencyProperty LengthProperty = + DependencyProperty.Register("Length", typeof(double), typeof(TouchSliderThreeThumbs), new FrameworkPropertyMetadata(5d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnLengthPropertyChanged))); + + public double MaxLowerValue { + get + { + double minrangeValue = (MinimumMiddleRange * 100) / Length; + return UpperValue - minrangeValue; + } + } + + public double MinUpperValue + { + get + { + double minrangeValue = (MinimumMiddleRange * 100) / Length; + return LowerValue + minrangeValue; + } + } + + + #endregion + + #region Base Class Overrides + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + //if (_lowerSlider != null) + // _lowerSlider.ValueChanged -= LowerSlider_ValueChanged; + + _lowerSlider = GetTemplateChild(PART_LowerSlider) as TouchSlider; + + _middleSlider = GetTemplateChild(Part_MiddleSlider) as TouchSlider; + + _upperSlider = GetTemplateChild(PART_UpperSlider) as TouchSlider; + } + + #endregion + + #region methods + + private static void OnLengthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TouchSliderThreeThumbs slider = (TouchSliderThreeThumbs)d; + if(slider != null) + { + slider.OnLengthChanged((double?)e.OldValue, (double?)e.NewValue); + } + } + + private void OnLengthChanged(double? oldValue, double? newValue) + { + + } + + private static object LowerValueCoerceValueCallback(DependencyObject target, object valueObject) + { + TouchSliderThreeThumbs targetSlider = (TouchSliderThreeThumbs)target; + double value = (double)valueObject; + + return Math.Min(Math.Min(value, targetSlider.MaxLowerValue), targetSlider.MiddleValue); + } + + private static object MiddleValueCoerceValueCallback(DependencyObject target, object valueObject) + { + TouchSliderThreeThumbs targetSlider = (TouchSliderThreeThumbs)target; + double value = (double)valueObject; + //var testValue = Math.Max(value, targetSlider.LowerValue); + return Math.Min(Math.Max(value, targetSlider.LowerValue), targetSlider.UpperValue); + } + private static object UpperValueCoerceValueCallback(DependencyObject target, object valueObject) + { + TouchSliderThreeThumbs targetSlider = (TouchSliderThreeThumbs)target; + double value = (double)valueObject; + + return Math.Max(Math.Max(value, targetSlider.MinUpperValue), targetSlider.MiddleValue); + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.xaml b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.xaml new file mode 100644 index 000000000..f4cbd46b6 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/TouchColorPickerControls/TouchSliderThreeThumbs.xaml @@ -0,0 +1,56 @@ +<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:Tango.Touch.Controls"> + + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="../Resources/Colors.xaml" /> + </ResourceDictionary.MergedDictionaries> + + <Style TargetType="{x:Type local:TouchSliderThreeThumbs}"> + <Setter Property="Background" Value="Transparent"/> + <Setter Property="MinHeight" Value="60"/> + <Setter Property="Template"> + <Setter.Value> + <ControlTemplate TargetType="{x:Type local:TouchSliderThreeThumbs}"> + <UniformGrid Rows="1" Columns="3"> + <local:TouchSlider x:Name="PART_LowerSlider" Style="{StaticResource TouchSliderHInvisibleTrack}" Height="60" Margin="10 0 0 0" Minimum="0" Foreground="{StaticResource TangoDarkForegroundBrush}" + Maximum="{Binding MiddleValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}" + Value="{Binding LowerValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}"> + <local:TouchSlider.ThumbTemplate> + <ControlTemplate> + <local:TouchDropShadowBorder CornerRadius="18" Width="31" Height="31"> + <local:TouchIcon Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:TouchSlider},Path=Foreground}" Width="11" Height="9" Icon="Triangle" Angle="0" VerticalAlignment="Center" /> + </local:TouchDropShadowBorder> + </ControlTemplate> + </local:TouchSlider.ThumbTemplate> + </local:TouchSlider> + <local:TouchSlider x:Name="Part_MiddleSlider" Style="{StaticResource TouchSliderHInvisibleTrack}" Height="60" Margin="10 0 0 0" Foreground="{StaticResource TangoDarkForegroundBrush}" + Minimum="{Binding LowerValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}" + Maximum="{Binding UpperValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}" + Value="{Binding MiddleValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}"> + <local:TouchSlider.ThumbTemplate> + <ControlTemplate> + <local:TouchDropShadowBorder CornerRadius="18" Width="31" Height="31"> + <local:TouchIcon Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:TouchSlider},Path=Foreground}" Width="11" Height="9" Icon="Triangle" Angle="0" /> + </local:TouchDropShadowBorder> + </ControlTemplate> + </local:TouchSlider.ThumbTemplate> + </local:TouchSlider> + <local:TouchSlider x:Name="PART_UpperSlider" Style="{StaticResource TouchSliderHInvisibleTrack}" Height="60" Margin="10 0 0 0" Maximum="100" Foreground="{StaticResource TangoDarkForegroundBrush}" + Minimum="{Binding MiddleValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}" + Value="{Binding UpperValue, RelativeSource={RelativeSource AncestorType=local:TouchSliderThreeThumbs}}"> + <local:TouchSlider.ThumbTemplate> + <ControlTemplate> + <local:TouchDropShadowBorder CornerRadius="18" Width="31" Height="31"> + <local:TouchIcon Foreground="{Binding RelativeSource={RelativeSource AncestorType=local:TouchSlider},Path=Foreground}" Width="11" Height="9" Icon="Triangle" Angle="0" /> + </local:TouchDropShadowBorder> + </ControlTemplate> + </local:TouchSlider.ThumbTemplate> + </local:TouchSlider> + </UniformGrid> + </ControlTemplate> + </Setter.Value> + </Setter> + </Style> + +</ResourceDictionary>
\ No newline at end of file |
