colorpicker

This commit is contained in:
NaBian committed 2018-07-05 17:16:04 +08:00
1 parent 9356bbea2b
commit 89a8a51b80
3 files changed
+6 -28

No files matched your search

+1
View File
@@ -8,3 +8,4 @@
/HandyControlDemo/bin/Debug /HandyControlDemo/bin/Debug
/HandyControlDemo/obj/Debug /HandyControlDemo/obj/Debug
/HandyControl.sln.DotSettings.user /HandyControl.sln.DotSettings.user
.vs/HandyControl/DesignTimeBuild/.dtbcache
+1 -17
View File
@@ -24,22 +24,6 @@
<ImageBrush ImageSource="/HandyControl;component/Resources/colorPickerBack.png"/> <ImageBrush ImageSource="/HandyControl;component/Resources/colorPickerBack.png"/>
</Border.Background> </Border.Background>
</Border> </Border>
<!--<Border CornerRadius="2,2,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#00FFFFFF" Offset="1"/>
<GradientStop Color="#FFFFFFFF" Offset="0"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<Border CornerRadius="2,2,0,0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#00FFFFFF" Offset="0"/>
<GradientStop Color="#FF000000" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>-->
</Grid> </Grid>
<Border Name="BorderColor" Grid.Row="0" CornerRadius="2,2,0,0" ClipToBounds="True"> <Border Name="BorderColor" Grid.Row="0" CornerRadius="2,2,0,0" ClipToBounds="True">
<Canvas Margin="-6"> <Canvas Margin="-6">
@@ -67,7 +51,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border Width="60" Height="32" CornerRadius="2" Background="{StaticResource ColorPickerOpacityBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"></Border> <Border Width="60" Height="32" CornerRadius="2" Background="{StaticResource ColorPickerOpacityBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"></Border>
<Border Grid.Row="0" Grid.Column="0" Width="60" Height="32" CornerRadius="2" Background="{Binding SelectedBrush,ElementName=UserControlMain}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"></Border> <Border Grid.Row="0" Grid.Column="0" Width="60" Height="32" CornerRadius="2" Background="{Binding SelectedBrush,ElementName=UserControlMain}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"></Border>
<Slider Name="SliderColor" LargeChange="0.01" SmallChange="0.01" Grid.ColumnSpan="2" ValueChanged="SliderColor_OnValueChanged" Value="1" Maximum="1" Background="{StaticResource ColorPickerRainbowBrush}" Margin="10,1,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"></Slider> <Slider Name="SliderColor" LargeChange="0.01" SmallChange="0.01" Grid.ColumnSpan="2" ValueChanged="SliderColor_OnValueChanged" Value="6" Maximum="6" Background="{StaticResource ColorPickerRainbowBrush}" Margin="10,1,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"></Slider>
<Slider Grid.ColumnSpan="2" IsSnapToTickEnabled="True" Name="SliderOpacity" ValueChanged="SliderOpacity_OnValueChanged" Value="255" Maximum="255" SmallChange="1" Foreground="{Binding SelectedBrushWithoutOpacity,ElementName=UserControlMain}" Background="{StaticResource ColorPickerOpacityBrush}" Margin="10,0,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"></Slider> <Slider Grid.ColumnSpan="2" IsSnapToTickEnabled="True" Name="SliderOpacity" ValueChanged="SliderOpacity_OnValueChanged" Value="255" Maximum="255" SmallChange="1" Foreground="{Binding SelectedBrushWithoutOpacity,ElementName=UserControlMain}" Background="{StaticResource ColorPickerOpacityBrush}" Margin="10,0,0,0" Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"></Slider>
<StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,14,0,0" VerticalAlignment="Top" Visibility="{Binding ShowList[0],ElementName=UserControlMain,Converter={StaticResource Boolean2VisibilityConverter}}"> <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,14,0,0" VerticalAlignment="Top" Visibility="{Binding ShowList[0],ElementName=UserControlMain,Converter={StaticResource Boolean2VisibilityConverter}}">
<controls:InfoTextBox Text="{Binding SelectedBrush,ElementName=UserControlMain,Mode=TwoWay,Converter={StaticResource Color2HexStrConverter},UpdateSourceTrigger=LostFocus}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="10" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox> <controls:InfoTextBox Text="{Binding SelectedBrush,ElementName=UserControlMain,Mode=TwoWay,Converter={StaticResource Color2HexStrConverter},UpdateSourceTrigger=LostFocus}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="10" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox>
+4 -11
View File
@@ -40,11 +40,6 @@ namespace HandyControl.Controls
/// </summary> /// </summary>
private bool IsNeedUpdateInfo { get; set; } = true; private bool IsNeedUpdateInfo { get; set; } = true;
/// <summary>
/// 颜色分值
/// </summary>
private const double ColorInterval = 1 / 6.0;
/// <summary> /// <summary>
/// 颜色选取面板宽度 /// 颜色选取面板宽度
/// </summary> /// </summary>
@@ -416,11 +411,11 @@ namespace HandyControl.Controls
sub = 255 - common; sub = 255 - common;
} }
var scale = sub / 255.0; var scale = sub / 255.0;
var scaleTotal = ColorInterval * (cIndex - direc) + scale * ColorInterval; var scaleTotal = cIndex - direc + scale;
IsNeedUpdateInfo = false; IsNeedUpdateInfo = false;
if (!SliderColor.IsMouseOver && !SliderOpacity.IsMouseOver) if (!SliderColor.IsMouseOver && !SliderOpacity.IsMouseOver)
{ {
SliderColor.Value = SliderColor.Maximum * scaleTotal; SliderColor.Value = scaleTotal;
} }
IsNeedUpdateInfo = true; IsNeedUpdateInfo = true;
} }
@@ -438,10 +433,8 @@ namespace HandyControl.Controls
private void SliderColor_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) private void SliderColor_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{ {
if (!_isLoaded || !IsNeedUpdateInfo) return; if (!_isLoaded || !IsNeedUpdateInfo) return;
var newValue = e.NewValue; var index = Math.Min(5, (int)Math.Floor(e.NewValue));
var div = newValue / ColorInterval; var sub = e.NewValue - index;
var index = Math.Min(5, (int)Math.Floor(newValue / ColorInterval));
var sub = div - index;
var range = _colorRangeList[index]; var range = _colorRangeList[index];
var color = range.GetColor(sub); var color = range.GetColor(sub);