更新整理

This commit is contained in:
GG Z
2025-04-24 20:56:44 +08:00
parent 155cef46f8
commit 5b6d67b571
813 changed files with 14437 additions and 12362 deletions

View File

@@ -1,26 +1,4 @@
// Copyright 2003-2024 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
using System;
using Color = System.Drawing.Color;
using Color = System.Drawing.Color;
namespace WPFluent.Controls;
@@ -149,7 +127,7 @@ public static class ColorFormatUtils
public static (double Cyan, double Magenta, double Yellow, double BlackKey) ConvertToCmykColor(Color color)
{
// special case for black (avoid division by zero)
if(color is { R: 0, G: 0, B: 0 })
if (color is { R: 0, G: 0, B: 0 })
{
return (0d, 0d, 0d, 1d);
}
@@ -161,7 +139,7 @@ public static class ColorFormatUtils
var blackKey = 1d - Math.Max(Math.Max(red, green), blue);
// special case for black (avoid division by zero)
if(1d - blackKey == 0d)
if (1d - blackKey == 0d)
{
return (0d, 0d, 0d, 1d);
}
@@ -192,7 +170,7 @@ public static class ColorFormatUtils
public static (double Hue, double Saturation, double Intensity) ConvertToHsiColor(Color color)
{
// special case for black
if(color.R == 0 && color.G == 0 && color.B == 0)
if (color.R == 0 && color.G == 0 && color.B == 0)
{
return (0d, 0d, 0d);
}
@@ -220,12 +198,12 @@ public static class ColorFormatUtils
var lightness = (max + min) / 2d;
if(lightness == 0d || Math.Abs(min - max) < 1e-9)
if (lightness == 0d || Math.Abs(min - max) < 1e-9)
{
return (color.GetHue(), 0d, lightness);
}
if(lightness is > 0d and <= 0.5d)
if (lightness is > 0d and <= 0.5d)
{
return (color.GetHue(), (max - min) / (max + min), lightness);
}

View File

@@ -1,13 +1,14 @@
using WPFluent.Extensions;
using WPFluent.Models;
using System;
using System.Windows.Controls;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using WPFluent.Extensions;
namespace WPFluent.Controls
{
@@ -148,9 +149,9 @@ namespace WPFluent.Controls
/// <returns></returns>
private static object OnCoerceHUEColorValue(DependencyObject d, object baseValue)
{
if(double.TryParse(baseValue.ToString(), out var value))
if (double.TryParse(baseValue.ToString(), out var value))
{
if(value > 360 || value < 0)
if (value > 360 || value < 0)
{
return 360;
}
@@ -160,9 +161,9 @@ namespace WPFluent.Controls
private static object OnCoerceRGBColorValue(DependencyObject d, object baseValue)
{
if(int.TryParse(baseValue.ToString(), out var value))
if (int.TryParse(baseValue.ToString(), out var value))
{
if(value > 255 || value < 0)
if (value > 255 || value < 0)
{
return 255;
}
@@ -173,9 +174,9 @@ namespace WPFluent.Controls
private static object OnCoerceSBAColorValue(DependencyObject d, object baseValue)
{
if(double.TryParse(baseValue.ToString(), out var value))
if (double.TryParse(baseValue.ToString(), out var value))
{
if(value < 0 || value > 1)
if (value < 0 || value > 1)
{
return 1.0;
}
@@ -191,7 +192,7 @@ namespace WPFluent.Controls
private static void OnHsbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker)d;
if(colorPicker.inCallback)
if (colorPicker.inCallback)
{
return;
}
@@ -199,7 +200,7 @@ namespace WPFluent.Controls
colorPicker.inCallback = true;
var color = default(Color);
if(e.NewValue is Hsb hsb)
if (e.NewValue is Hsb hsb)
{
color = hsb.ToColor();
}
@@ -223,19 +224,19 @@ namespace WPFluent.Controls
var colorPicker = (ColorPicker)d;
var propertyName = e.Property.Name;
if(int.TryParse(e.NewValue.ToString(), out var value))
if (int.TryParse(e.NewValue.ToString(), out var value))
{
Color color = default;
if(propertyName == nameof(Red))
if (propertyName == nameof(Red))
{
color = Color.FromRgb((byte)value, (byte)colorPicker.Green, (byte)colorPicker.Blue);
}
if(propertyName == nameof(Green))
if (propertyName == nameof(Green))
{
//color.G = (byte)value;
color = Color.FromRgb((byte)colorPicker.Red, (byte)value, (byte)colorPicker.Blue);
}
if(propertyName == nameof(Blue))
if (propertyName == nameof(Blue))
{
color = Color.FromRgb((byte)colorPicker.Red, (byte)colorPicker.Green, (byte)value);
}
@@ -274,7 +275,7 @@ namespace WPFluent.Controls
private static void OnSelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var colorPicker = (ColorPicker)d;
if(colorPicker.inCallback)
if (colorPicker.inCallback)
{
return;
}
@@ -318,24 +319,24 @@ namespace WPFluent.Controls
public override void OnApplyTemplate()
{
if(saturationBrightnessCanvas != null)
if (saturationBrightnessCanvas != null)
{
saturationBrightnessCanvas.MouseDown -= SaturationBrightnessCanvasMouseDown;
saturationBrightnessCanvas.MouseMove -= SaturationBrightnessCanvasMouseMove;
saturationBrightnessCanvas.MouseUp -= SaturationBrightnessCanvasMouseUp;
}
saturationBrightnessCanvas = GetTemplateChild(SaturationBrightnessPickerPartName) as Canvas;
if(saturationBrightnessCanvas != null)
if (saturationBrightnessCanvas != null)
{
saturationBrightnessCanvas.MouseDown += SaturationBrightnessCanvasMouseDown;
saturationBrightnessCanvas.MouseMove += SaturationBrightnessCanvasMouseMove;
saturationBrightnessCanvas.MouseUp += SaturationBrightnessCanvasMouseUp;
}
if(saturationBrightnessThumb != null)
if (saturationBrightnessThumb != null)
saturationBrightnessThumb.DragDelta -= SaturationBrightnessThumbDragDelta;
saturationBrightnessThumb = GetTemplateChild(SaturationBrightnessPickerThumbPartName) as Thumb;
if(saturationBrightnessThumb != null)
if (saturationBrightnessThumb != null)
saturationBrightnessThumb.DragDelta += SaturationBrightnessThumbDragDelta;
base.OnApplyTemplate();
}
@@ -408,10 +409,10 @@ namespace WPFluent.Controls
/// <param name="e"></param>
private void SaturationBrightnessCanvasMouseMove(object sender, MouseEventArgs e)
{
if(Mouse.Captured is null || Mouse.Captured != saturationBrightnessThumb)
if (Mouse.Captured is null || Mouse.Captured != saturationBrightnessThumb)
return;
//鼠标左键按下,拿到鼠标的位置,将滑块设置到鼠标指针的位置
if(e.LeftButton == MouseButtonState.Pressed)
if (e.LeftButton == MouseButtonState.Pressed)
{
var position = e.GetPosition(saturationBrightnessCanvas);
ApplyThumbPosition(position.X, position.Y);
@@ -452,16 +453,16 @@ namespace WPFluent.Controls
/// <param name="top"></param>
private void ApplyThumbPosition(double left, double top)
{
if(left < 0)
if (left < 0)
left = 0;
if(top < 0)
if (top < 0)
top = 0;
if(left > saturationBrightnessCanvas?.ActualWidth)
if (left > saturationBrightnessCanvas?.ActualWidth)
{
left = saturationBrightnessCanvas.ActualWidth;
}
if(top > saturationBrightnessCanvas?.ActualHeight)
if (top > saturationBrightnessCanvas?.ActualHeight)
{
top = saturationBrightnessCanvas.ActualHeight;
}
@@ -482,7 +483,7 @@ namespace WPFluent.Controls
private void SetThumbLeft()
{
if(saturationBrightnessCanvas is null)
if (saturationBrightnessCanvas is null)
return;
//var left = (saturationBrightnessCanvas.ActualWidth) / (1 / Saturation);
//因为饱和度是0~1=水平占比
@@ -492,7 +493,7 @@ namespace WPFluent.Controls
private void SetThumbTop()
{
if(saturationBrightnessCanvas is null)
if (saturationBrightnessCanvas is null)
return;
//轴反向所以1-比例
var top = (1 - Brightness) * saturationBrightnessCanvas.ActualHeight;

View File

@@ -0,0 +1,9 @@
namespace WPFluent.Controls
{
public enum ColorTypeEnum
{
RGB,
HSL,
HEX
}
}

View File

@@ -0,0 +1,74 @@
namespace WPFluent.Controls
{
public struct Hsb
{
public Hsb(double Hue, double Saturation, double Brightness, double opacity = 1)
{
this.Hue = Hue;
this.Saturation = Saturation;
this.Brightness = Brightness;
Opacity = opacity;
}
/// <summary>
/// 亮度0~1
/// </summary>
public double Brightness { get; set; }
/// <summary>
/// 色相0~359
/// </summary>
public double Hue { get; set; }
/// <summary>
/// 不透明度0~1
/// </summary>
public double Opacity { get; set; }
/// <summary>
/// 饱和度0~1
/// </summary>
public double Saturation { get; set; }
public static Hsb FromHSB(double hue, double saturation, double brightness, double opacity = 1)
{
return new Hsb(hue, saturation, brightness, opacity);
}
public static Hsb FromColor(Color color)
{
var hsb = new Hsb();
var max = Math.Max(color.R, Math.Max(color.G, color.B));
var min = Math.Min(color.R, Math.Min(color.G, color.B));
var delta = max - min;
hsb.Brightness = max / 255.0;
hsb.Saturation = max == 0 ? 0 : delta / max;
if (delta == 0)
{
hsb.Hue = 0;
}
else if (max == color.R)
{
hsb.Hue = (color.G - color.B) / delta;
}
else if (max == color.G)
{
hsb.Hue = 2 + (color.B - color.R) / delta;
}
else
{
hsb.Hue = 4 + (color.R - color.G) / delta;
}
hsb.Hue *= 60;
if (hsb.Hue < 0)
hsb.Hue += 360;
return hsb;
}
//public override string ToString()
//{
// return base.ToString();
//}
}
}