Skip to content

Portable Tool for an Ideal Windows Setup

add new uc (ColorPickerWheel)

Greedeks020f004d4912
diff --git a/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml
new file mode 100644
index 00000000..64489caf
--- /dev/null
+++ b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml
@@ -0,0 +1,96 @@
+<UserControl x:Class="GTweak.Assets.UserControl.ColorWheelPicker.ColorPicker"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:local="clr-namespace:GTweak.Assets.UserControl.ColorWheelPicker"
+ mc:Ignorable="d"
+ d:DesignHeight="40" d:DesignWidth="140" UseLayoutRounding="True" SnapsToDevicePixels="True">
+ <Grid>
+ <ToggleButton x:Name="PART_ToggleButton" Checked="PART_ToggleButton_Checked" Unchecked="PART_ToggleButton_Unchecked">
+ <ToggleButton.Template>
+ <ControlTemplate TargetType="ToggleButton">
+ <Border x:Name="RootBorder" BorderBrush="{StaticResource Brush_Separator}" BorderThickness="1" Background="{StaticResource Brush_Background_ComboBox}" CornerRadius="4" Padding="5">
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*"/>
+ <ColumnDefinition Width="Auto"/>
+ </Grid.ColumnDefinitions>
+
+ <ContentPresenter Grid.Column="0" VerticalAlignment="Center"/>
+
+ <Path x:Name="Arrow" Grid.Column="1" Data="M 0,2 L 4,6 L 8,2" Stroke="{StaticResource Brush_Highlighted}" StrokeThickness="1.5" Margin="5,0,2,0" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
+ <Path.RenderTransform>
+ <RotateTransform x:Name="ArrowRotate" Angle="0"/>
+ </Path.RenderTransform>
+ </Path>
+ </Grid>
+ </Border>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsMouseOver" Value="True">
+ <Setter TargetName="RootBorder" Property="BorderBrush" Value="#AAA"/>
+ </Trigger>
+ <Trigger Property="IsChecked" Value="True">
+ <Trigger.EnterActions>
+ <BeginStoryboard>
+ <Storyboard Timeline.DesiredFrameRate="120">
+ <DoubleAnimation Storyboard.TargetName="ArrowRotate" Storyboard.TargetProperty="Angle" To="180" Duration="0:0:0.2">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </Trigger.EnterActions>
+ <Trigger.ExitActions>
+ <BeginStoryboard>
+ <Storyboard Timeline.DesiredFrameRate="120">
+ <DoubleAnimation Storyboard.TargetName="ArrowRotate" Storyboard.TargetProperty="Angle" To="0" Duration="0:0:0.2">
+ <DoubleAnimation.EasingFunction>
+ <CubicEase/>
+ </DoubleAnimation.EasingFunction>
+ </DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </Trigger.ExitActions>
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </ToggleButton.Template>
+
+ <StackPanel Orientation="Horizontal">
+ <Ellipse x:Name="PART_ColorPreview" Width="20" Height="20" Stroke="{StaticResource Brush_Separator}" StrokeThickness="2" Margin="0,0,8,0" Fill="White"/>
+ <TextBlock x:Name="PART_ColorTextBlock" VerticalAlignment="Center" FontSize="14px" FontFamily="{StaticResource Play}" Foreground="{StaticResource Brush_Highlighted}" Text="255 255 255" MinWidth="80"/>
+ </StackPanel>
+ </ToggleButton>
+
+ <Popup x:Name="ColorPopup" Placement="Bottom" StaysOpen="False" AllowsTransparency="True" Opened="ColorPopup_Opened" Closed="ColorPopup_Closed" VerticalOffset="4">
+ <Border x:Name="PopupBorder" Background="{StaticResource Brush_Background_ComboBox}" BorderBrush="{StaticResource Brush_Separator}" BorderThickness="1" CornerRadius="8" Padding="12" Margin="10">
+ <Border.CacheMode>
+ <BitmapCache RenderAtScale="2" />
+ </Border.CacheMode>
+ <Border.Effect>
+ <DropShadowEffect BlurRadius="10" Opacity="0.15" ShadowDepth="2"/>
+ </Border.Effect>
+ <Border.RenderTransform>
+ <TranslateTransform x:Name="PopupTransform"/>
+ </Border.RenderTransform>
+
+ <StackPanel>
+ <Canvas Width="150" Height="150">
+ <Rectangle x:Name="PART_Wheel" Width="150" Height="150" Fill="Transparent" MouseDown="Wheel_MouseDown" MouseMove="Wheel_MouseMove" MouseUp="Wheel_MouseUp">
+ <Rectangle.Effect>
+ <local:ColorWheelEffect />
+ </Rectangle.Effect>
+ <Rectangle.Clip>
+ <EllipseGeometry Center="75,75" RadiusX="75" RadiusY="75"/>
+ </Rectangle.Clip>
+ </Rectangle>
+ <Ellipse x:Name="PART_Marker" Width="14" Height="14" Stroke="Black" StrokeThickness="1" Fill="#FFFFFF" IsHitTestVisible="False"/>
+ </Canvas>
+ <Slider x:Name="PART_BrightnessSlider" Style="{StaticResource Slider_NoValue}" Minimum="0" Maximum="1" Value="1" Margin="0,15,0,0" Cursor="Hand" IsMoveToPointEnabled="True"/>
+ </StackPanel>
+ </Border>
+ </Popup>
+ </Grid>
+</UserControl>
diff --git a/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml.cs b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml.cs
new file mode 100644
index 00000000..16551668
--- /dev/null
+++ b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorPicker.xaml.cs
@@ -0,0 +1,243 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+using GTweak.Utilities.Animation;
+using GTweak.Utilities.Controls;
+
+namespace GTweak.Assets.UserControl.ColorWheelPicker
+{
+ public partial class ColorPicker
+ {
+ internal static readonly DependencyProperty SelectedColorProperty =
+ DependencyProperty.Register(nameof(SelectedColor), typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.White, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedColorChanged));
+
+ internal Color SelectedColor
+ {
+ get => (Color)GetValue(SelectedColorProperty);
+ set => SetValue(SelectedColorProperty, value);
+ }
+
+ internal string SelectedColorString
+ {
+ get => $"{SelectedColor.R} {SelectedColor.G} {SelectedColor.B}";
+
+ set
+ {
+ if (!string.IsNullOrWhiteSpace(value))
+ {
+ try
+ {
+ string[] parts = value.Split(new[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
+ if (parts.Length == 3)
+ {
+ byte r = byte.Parse(parts[0]);
+ byte g = byte.Parse(parts[1]);
+ byte b = byte.Parse(parts[2]);
+
+ SelectedColor = Color.FromRgb(r, g, b);
+ }
+ }
+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }
+ }
+ }
+ }
+
+ private const double WheelSize = 150.0;
+ private const double WheelRadius = WheelSize / 2.0;
+
+ private bool _isDragging, _isInitialized, _updatingFromProperty;
+ private double _selectedX, _selectedY, _brightness = 1.0;
+
+ public ColorPicker()
+ {
+ InitializeComponent();
+ PART_BrightnessSlider.ValueChanged += (s, e) => UpdateFromSlider();
+
+ Loaded += (s, e) =>
+ {
+ if (!_isInitialized)
+ {
+ SetColorFromColor(SelectedColor);
+ _isInitialized = true;
+ }
+
+ Window win = Window.GetWindow(this);
+ if (win != null)
+ {
+ win.LocationChanged += delegate { UpdatePopupPos(); };
+ win.SizeChanged += delegate { UpdatePopupPos(); };
+ }
+ };
+ }
+ private static void OnSelectedColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ ColorPicker ctrl = (ColorPicker)d;
+ if (ctrl._updatingFromProperty)
+ {
+ return;
+ }
+
+ ctrl.SetColorFromColor((Color)e.NewValue);
+ }
+
+ private void PART_ToggleButton_Checked(object sender, RoutedEventArgs e) => ColorPopup.IsOpen = true;
+
+ private void PART_ToggleButton_Unchecked(object sender, RoutedEventArgs e) => ColorPopup.IsOpen = false;
+
+ private void UpdatePopupPos()
+ {
+ if (ColorPopup.IsOpen)
+ {
+ var method = typeof(System.Windows.Controls.Primitives.Popup).GetMethod("UpdatePosition", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
+ method?.Invoke(ColorPopup, null);
+ }
+ }
+
+ private void UpdateFromSlider()
+ {
+ _brightness = PART_BrightnessSlider.Value;
+ UpdateColor(GetColorFromWheel(_selectedX, _selectedY, _brightness));
+ }
+
+ private void Wheel_MouseDown(object sender, MouseButtonEventArgs e)
+ {
+ PART_Wheel.CaptureMouse();
+ _isDragging = true;
+ UpdateColorByMouse(e.GetPosition(PART_Wheel));
+ }
+
+ private void Wheel_MouseMove(object sender, MouseEventArgs e)
+ {
+ if (_isDragging)
+ {
+ UpdateColorByMouse(e.GetPosition(PART_Wheel));
+ }
+ }
+
+ private void Wheel_MouseUp(object sender, MouseButtonEventArgs e)
+ {
+ _isDragging = false;
+ PART_Wheel.ReleaseMouseCapture();
+ }
+
+ private void UpdateColorByMouse(Point pos)
+ {
+ double dx = pos.X - WheelRadius, dy = pos.Y - WheelRadius;
+ double dist = Math.Sqrt(dx * dx + dy * dy);
+
+ if (dist > WheelRadius)
+ {
+ dx *= WheelRadius / dist;
+ dy *= WheelRadius / dist;
+ }
+
+ _selectedX = WheelRadius + dx;
+ _selectedY = WheelRadius + dy;
+ UpdateColor(GetColorFromWheel(_selectedX, _selectedY, _brightness));
+ }
+
+ private void ColorPopup_Closed(object sender, EventArgs e)
+ {
+ if (Mouse.LeftButton != MouseButtonState.Pressed)
+ {
+ PART_ToggleButton.IsChecked = false;
+ }
+ else if (!PART_ToggleButton.IsMouseOver)
+ {
+ PART_ToggleButton.IsChecked = false;
+ }
+ }
+
+ private void UpdateColor(Color color)
+ {
+ if (color.A >= 128)
+ {
+ Canvas.SetLeft(PART_Marker, _selectedX - PART_Marker.Width / 2);
+ Canvas.SetTop(PART_Marker, _selectedY - PART_Marker.Height / 2);
+
+ PART_ColorPreview.Fill = new SolidColorBrush(color);
+ PART_ColorTextBlock.Text = $"{color.R} {color.G} {color.B}";
+
+ _updatingFromProperty = true;
+ SelectedColor = color;
+ _updatingFromProperty = false;
+ }
+ }
+
+ private void SetColorFromColor(Color color)
+ {
+ double r = color.R / 255.0, g = color.G / 255.0, b = color.B / 255.0;
+ double max = Math.Max(r, Math.Max(g, b)), min = Math.Min(r, Math.Min(g, b));
+ double delta = max - min;
+
+ _brightness = max;
+ PART_BrightnessSlider.Value = _brightness;
+
+ double hueDeg = 0;
+
+ if (delta != 0)
+ {
+ if (max == r)
+ {
+ hueDeg = 60 * (((g - b) / delta) % 6);
+ }
+ else if (max == g)
+ {
+ hueDeg = 60 * (((b - r) / delta) + 2);
+ }
+ else
+ {
+ hueDeg = 60 * (((r - g) / delta) + 4);
+ }
+ }
+
+ if (hueDeg < 0)
+ {
+ hueDeg += 360;
+ }
+
+ double s = (max == 0) ? 0 : delta / max;
+ double angle = Math.PI - (Math.PI / 3.0) * (hueDeg / 60.0);
+
+ _selectedX = WheelRadius - (s * WheelRadius * Math.Cos(angle));
+ _selectedY = WheelRadius + (s * WheelRadius * Math.Sin(angle));
+
+ UpdateColor(color);
+ }
+
+ public static Color GetColorFromWheel(double x, double y, double v)
+ {
+ double nx = (x - WheelRadius) / WheelRadius;
+ double ny = (y - WheelRadius) / WheelRadius;
+ double sat = Math.Min(1.0, Math.Sqrt(nx * nx + ny * ny));
+
+ double hue = (Math.Atan2(ny, nx) + Math.PI) / (2 * Math.PI) * 6.0;
+
+ double c = v * sat;
+ double x_c = c * (1 - Math.Abs(hue % 2.0 - 1));
+ double m = v - c;
+
+ (double r, double g, double b) = hue switch
+ {
+ double h when h < 1 => (c, x_c, 0.0),
+ double h when h < 2 => (x_c, c, 0.0),
+ double h when h < 3 => (0.0, c, x_c),
+ double h when h < 4 => (0.0, x_c, c),
+ double h when h < 5 => (x_c, 0.0, c),
+ _ => (c, 0.0, x_c)
+ };
+
+ byte ToByte(double val) => (byte)((val + m) * 255);
+
+ return Color.FromRgb(ToByte(r), ToByte(g), ToByte(b));
+ }
+
+ private void ColorPopup_Opened(object sender, EventArgs e)
+ {
+ PopupTransform.BeginAnimation(TranslateTransform.YProperty, FactoryAnimation.CreateIn(-5, 0, 0.3, useCubicEase: true));
+ PopupBorder.BeginAnimation(OpacityProperty, FactoryAnimation.CreateIn(0, 1, 0.15));
+ }
+ }
+}
diff --git a/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.cs b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.cs
new file mode 100644
index 00000000..21dfdc7d
--- /dev/null
+++ b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Windows;
+using System.Windows.Media;
+using System.Windows.Media.Effects;
+
+namespace GTweak.Assets.UserControl.ColorWheelPicker
+{
+ public class ColorWheelEffect : ShaderEffect
+ {
+ private static readonly PixelShader _shader = new PixelShader()
+ {
+ UriSource = new Uri("pack://application:,,,/GTweak;component/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.ps")
+ };
+
+ public ColorWheelEffect()
+ {
+ PixelShader = _shader;
+ UpdateShaderValue(InputProperty);
+ }
+
+ public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input", typeof(ColorWheelEffect), 0);
+
+ public Brush Input
+ {
+ get => (Brush)GetValue(InputProperty);
+ set => SetValue(InputProperty, value);
+ }
+ }
+}
diff --git a/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.ps b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.ps
new file mode 100644
index 00000000..8569a77b
Binary files /dev/null and b/.Source/GTweak/Assets/UserControl/ColorWheelPicker/ColorWheelEffect.ps differ
diff --git a/.Source/GTweak/GTweak.csproj b/.Source/GTweak/GTweak.csproj
index 941e0cb0..7b595a78 100644
--- a/.Source/GTweak/GTweak.csproj
+++ b/.Source/GTweak/GTweak.csproj
@@ -131,6 +131,10 @@
<Compile Include="Assets\UserControl\Card.xaml.cs">
<DependentUpon>Card.xaml</DependentUpon>
</Compile>
+ <Compile Include="Assets\UserControl\ColorWheelPicker\ColorPicker.xaml.cs">
+ <DependentUpon>ColorPicker.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Assets\UserControl\ColorWheelPicker\ColorWheelEffect.cs" />
<Compile Include="Assets\UserControl\DescriptionBlock.xaml.cs">
<DependentUpon>DescriptionBlock.xaml</DependentUpon>
</Compile>
@@ -238,6 +242,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="Assets\UserControl\ColorWheelPicker\ColorPicker.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Assets\UserControl\DescriptionBlock.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -479,6 +487,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include=".editorconfig" />
+ <Resource Include="Assets\UserControl\ColorWheelPicker\ColorWheelEffect.ps" />
<None Include="Resources\Blank.gz" />
<None Include="Resources\DisablingWD.gz" />
<None Include="Resources\hosts.gz" />
diff --git a/.Source/GTweak/Styles/Inputs/Slider.xaml b/.Source/GTweak/Styles/Inputs/Slider.xaml
index 68dab11b..5fd79ac7 100644
--- a/.Source/GTweak/Styles/Inputs/Slider.xaml
+++ b/.Source/GTweak/Styles/Inputs/Slider.xaml
@@ -131,6 +131,24 @@
</Grid>
</ControlTemplate>
+ <ControlTemplate x:Key="SliderNoText" TargetType="{x:Type Slider}">
+ <Grid>
+ <Track x:Name="PART_Track" Cursor="Hand">
+ <Track.DecreaseRepeatButton>
+ <RepeatButton Style="{StaticResource SliderRepeatButton}" Command="Slider.DecreaseLarge"/>
+ </Track.DecreaseRepeatButton>
+
+ <Track.Thumb>
+ <Thumb Style="{StaticResource SliderThumb}"/>
+ </Track.Thumb>
+
+ <Track.IncreaseRepeatButton>
+ <RepeatButton Style="{StaticResource SliderRepeatButton_In}" Command="Slider.IncreaseLarge"/>
+ </Track.IncreaseRepeatButton>
+ </Track>
+ </Grid>
+ </ControlTemplate>
+
<Style x:Key="Numeric_Slider" TargetType="{x:Type Slider}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="SnapsToDevicePixels" Value="true" />
@@ -161,4 +179,14 @@
</Style.Triggers>
</Style>
+ <Style x:Key="Slider_NoValue" TargetType="{x:Type Slider}">
+ <Setter Property="Focusable" Value="False"/>
+ <Setter Property="SnapsToDevicePixels" Value="True"/>
+ <Setter Property="OverridesDefaultStyle" Value="True"/>
+ <Setter Property="IsTabStop" Value="False"/>
+ <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
+
+ <Setter Property="Template" Value="{StaticResource SliderNoText}"/>
+ </Style>
+
</ResourceDictionary>
\ No newline at end of file
diff --git a/Shaders/ColorWheelEffect.hlsl b/Shaders/ColorWheelEffect.hlsl
new file mode 100644
index 00000000..16f7e771
--- /dev/null
+++ b/Shaders/ColorWheelEffect.hlsl
@@ -0,0 +1,25 @@
+#define PI 3.141592653f
+#define value 1.0f
+
+float4 main(float2 uv : TEXCOORD) : COLOR {
+ uv = 2 * uv - 1;
+ float saturation = length(uv);
+ float hue = 3 * (PI - atan2(uv.y, -uv.x)) / PI;
+ float chroma = value * saturation;
+ float second = chroma * (1 - abs(hue % 2.0 - 1));
+ float m = value - chroma;
+ float3 rgb;
+ if (hue < 1)
+ rgb = float3(chroma, second, 0);
+ else if (hue < 2)
+ rgb = float3(second, chroma, 0);
+ else if (hue < 3)
+ rgb = float3(0, chroma, second);
+ else if (hue < 4)
+ rgb = float3(0, second, chroma);
+ else if (hue < 5)
+ rgb = float3(second, 0, chroma);
+ else
+ rgb = float3(chroma, 0, second);
+ return float4(rgb + m, saturation < 1);
+}
\ No newline at end of file