更新整理
This commit is contained in:
@@ -19,7 +19,7 @@ public static class ColorExtensions
|
||||
/// </summary>
|
||||
private static bool AlmostEquals(float numberOne, float numberTwo, float precision = 0)
|
||||
{
|
||||
if(precision <= 0)
|
||||
if (precision <= 0)
|
||||
{
|
||||
precision = float.Epsilon;
|
||||
}
|
||||
@@ -35,17 +35,17 @@ public static class ColorExtensions
|
||||
float num1,
|
||||
num2;
|
||||
|
||||
if(color > 1)
|
||||
if (color > 1)
|
||||
{
|
||||
color -= 1f;
|
||||
}
|
||||
|
||||
if(color < 0)
|
||||
if (color < 0)
|
||||
{
|
||||
color += 1f;
|
||||
}
|
||||
|
||||
if(lightness < 0.5f)
|
||||
if (lightness < 0.5f)
|
||||
{
|
||||
num1 = lightness * (1f + saturation);
|
||||
}
|
||||
@@ -56,17 +56,17 @@ public static class ColorExtensions
|
||||
|
||||
num2 = (2f * lightness) - num1;
|
||||
|
||||
if(color * 6f < 1)
|
||||
if (color * 6f < 1)
|
||||
{
|
||||
return (int)((num2 + ((num1 - num2) * 6f * color)) * _byteMax);
|
||||
}
|
||||
|
||||
if(color * 2f < 1)
|
||||
if (color * 2f < 1)
|
||||
{
|
||||
return (int)(num1 * _byteMax);
|
||||
}
|
||||
|
||||
if(color * 3f < 2)
|
||||
if (color * 3f < 2)
|
||||
{
|
||||
return (int)((num2 + ((num1 - num2) * (0.666666666f - color) * 6f)) * _byteMax);
|
||||
}
|
||||
@@ -79,11 +79,11 @@ public static class ColorExtensions
|
||||
/// </summary>
|
||||
private static byte ToColorByte(int value)
|
||||
{
|
||||
if(value > byte.MaxValue)
|
||||
if (value > byte.MaxValue)
|
||||
{
|
||||
value = byte.MaxValue;
|
||||
}
|
||||
else if(value < byte.MinValue)
|
||||
else if (value < byte.MinValue)
|
||||
{
|
||||
value = byte.MinValue;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public static class ColorExtensions
|
||||
/// </summary>
|
||||
public static (int R, int G, int B) FromHslToRgb(float hue, float saturation, float lightness)
|
||||
{
|
||||
if(AlmostEquals(saturation, 0, 0.01f))
|
||||
if (AlmostEquals(saturation, 0, 0.01f))
|
||||
{
|
||||
var color = (int)(lightness * _byteMax);
|
||||
|
||||
@@ -137,7 +137,7 @@ public static class ColorExtensions
|
||||
var green = 0;
|
||||
var blue = 0;
|
||||
|
||||
if(AlmostEquals(saturation, 0, 0.01f))
|
||||
if (AlmostEquals(saturation, 0, 0.01f))
|
||||
{
|
||||
red = green = blue = (int)(((brightness / 100f) * _byteMax) + 0.5f);
|
||||
|
||||
@@ -155,7 +155,7 @@ public static class ColorExtensions
|
||||
var q = brightness * (1.0f - (saturation * f));
|
||||
var t = brightness * (1.0f - (saturation * (1.0f - f)));
|
||||
|
||||
switch((int)hueAngle)
|
||||
switch ((int)hueAngle)
|
||||
{
|
||||
case 0:
|
||||
red = (int)((brightness * 255.0f) + 0.5f);
|
||||
@@ -279,7 +279,7 @@ public static class ColorExtensions
|
||||
float saturation;
|
||||
float lightness;
|
||||
|
||||
if(max <= 0)
|
||||
if (max <= 0)
|
||||
{
|
||||
return (0f, 0f, 0f);
|
||||
}
|
||||
@@ -287,18 +287,18 @@ public static class ColorExtensions
|
||||
saturation = 0.0f;
|
||||
lightness = ((max + min) / _byteMax) / 2.0f;
|
||||
|
||||
if(fDelta <= 0.0)
|
||||
if (fDelta <= 0.0)
|
||||
{
|
||||
return (0f, saturation * 100f, lightness * 100f);
|
||||
}
|
||||
|
||||
saturation = fDelta / (max / _byteMax);
|
||||
|
||||
if(max == red)
|
||||
if (max == red)
|
||||
{
|
||||
hue = ((green - blue) / _byteMax) / fDelta;
|
||||
}
|
||||
else if(max == green)
|
||||
else if (max == green)
|
||||
{
|
||||
hue = 2f + (((blue - red) / _byteMax) / fDelta);
|
||||
}
|
||||
@@ -307,7 +307,7 @@ public static class ColorExtensions
|
||||
hue = 4f + (((red - green) / _byteMax) / fDelta);
|
||||
}
|
||||
|
||||
if(hue < 0)
|
||||
if (hue < 0)
|
||||
{
|
||||
hue += 360;
|
||||
}
|
||||
@@ -334,7 +334,7 @@ public static class ColorExtensions
|
||||
float saturation;
|
||||
float value;
|
||||
|
||||
if(max <= 0)
|
||||
if (max <= 0)
|
||||
{
|
||||
return (0f, 0f, 0f);
|
||||
}
|
||||
@@ -342,16 +342,16 @@ public static class ColorExtensions
|
||||
saturation = fDelta / (max / _byteMax);
|
||||
value = max / _byteMax;
|
||||
|
||||
if(fDelta <= 0.0)
|
||||
if (fDelta <= 0.0)
|
||||
{
|
||||
return (0f, saturation * 100f, value * 100f);
|
||||
}
|
||||
|
||||
if(max == red)
|
||||
if (max == red)
|
||||
{
|
||||
hue = ((green - blue) / _byteMax) / fDelta;
|
||||
}
|
||||
else if(max == green)
|
||||
else if (max == green)
|
||||
{
|
||||
hue = 2f + (((blue - red) / _byteMax) / fDelta);
|
||||
}
|
||||
@@ -360,7 +360,7 @@ public static class ColorExtensions
|
||||
hue = 4f + (((red - green) / _byteMax) / fDelta);
|
||||
}
|
||||
|
||||
if(hue < 0)
|
||||
if (hue < 0)
|
||||
{
|
||||
hue += 360;
|
||||
}
|
||||
@@ -382,17 +382,17 @@ public static class ColorExtensions
|
||||
float saturationFactor = 0,
|
||||
float luminanceFactor = 0)
|
||||
{
|
||||
if(brightnessFactor is > 100f or < -100f)
|
||||
if (brightnessFactor is > 100f or < -100f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(brightnessFactor));
|
||||
}
|
||||
|
||||
if(saturationFactor is > 100f or < -100f)
|
||||
if (saturationFactor is > 100f or < -100f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(saturationFactor));
|
||||
}
|
||||
|
||||
if(luminanceFactor is > 100f or < -100f)
|
||||
if (luminanceFactor is > 100f or < -100f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(luminanceFactor));
|
||||
}
|
||||
@@ -404,7 +404,7 @@ public static class ColorExtensions
|
||||
ToPercentage(rawSaturation + saturationFactor),
|
||||
ToPercentage(rawBrightness + brightnessFactor));
|
||||
|
||||
if(luminanceFactor == 0)
|
||||
if (luminanceFactor == 0)
|
||||
{
|
||||
return Color.FromArgb(color.A, ToColorByte(red), ToColorByte(green), ToColorByte(blue));
|
||||
}
|
||||
@@ -426,7 +426,7 @@ public static class ColorExtensions
|
||||
/// <returns>Updated <see cref="System.Windows.Media.Color"/>.</returns>
|
||||
public static Color UpdateBrightness(this Color color, float factor)
|
||||
{
|
||||
if(factor is > 100f or < -100f)
|
||||
if (factor is > 100f or < -100f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(factor));
|
||||
}
|
||||
@@ -446,7 +446,7 @@ public static class ColorExtensions
|
||||
/// <returns>Updated <see cref="System.Windows.Media.Color"/>.</returns>
|
||||
public static Color UpdateLuminance(this Color color, float factor)
|
||||
{
|
||||
if(factor is > 100 or < -100)
|
||||
if (factor is > 100 or < -100)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(factor));
|
||||
}
|
||||
@@ -466,7 +466,7 @@ public static class ColorExtensions
|
||||
/// <returns>Updated <see cref="System.Windows.Media.Color"/>.</returns>
|
||||
public static Color UpdateSaturation(this Color color, float factor)
|
||||
{
|
||||
if(factor is > 100f or < -100f)
|
||||
if (factor is > 100f or < -100f)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(factor));
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Appearance;
|
||||
using WPFluent.Interop;
|
||||
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace WPFluent.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for the <see cref="ContextMenu"/>.
|
||||
/// </summary>
|
||||
internal static class ContextMenuExtensions
|
||||
{
|
||||
private static void ContextMenuOnOpened(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(sender is not ContextMenu contextMenu || PresentationSource.FromVisual(contextMenu) is not HwndSource source)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(ApplicationThemeManager.GetAppTheme() == ApplicationTheme.Dark)
|
||||
{
|
||||
_ = UnsafeNativeMethods.ApplyWindowDarkMode(source.Handle);
|
||||
}
|
||||
|
||||
// TODO: Needs more work with the Popup service
|
||||
|
||||
/*if (Background.Apply(source.Handle, BackgroundType.Mica))
|
||||
contextMenu.Background = Brushes.Transparent;*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to apply Mica effect to the <see cref="ContextMenu"/>.
|
||||
/// </summary>
|
||||
public static void ApplyMica(this ContextMenu contextMenu) { contextMenu.Opened += ContextMenuOnOpened; }
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class FrameExtensions
|
||||
{
|
||||
while(frame.CanGoBack)
|
||||
{
|
||||
_ = frame.RemoveBackEntry();
|
||||
frame.RemoveBackEntry();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using WPFluent.Models;
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
|
||||
namespace WPFluent.Extensions
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace WPFluent.Extensions
|
||||
/// <param name="hsb"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public static Color ToColor(this Hsb hsb)
|
||||
public static Color ToColor(this Controls.Hsb hsb)
|
||||
{
|
||||
//0~1
|
||||
var hue = hsb.Hue;
|
||||
@@ -27,15 +27,15 @@ namespace WPFluent.Extensions
|
||||
var opacity = hsb.Opacity;
|
||||
brightness *= 255;
|
||||
//饱和度为0,直接返回亮度值
|
||||
if(saturation.IsCloseTo(0))
|
||||
if (saturation.IsCloseTo(0))
|
||||
return Color.FromArgb((byte)brightness, (byte)brightness, (byte)brightness, (byte)brightness);
|
||||
opacity *= 255;
|
||||
//处理色相超出范围
|
||||
if(hue.IsCloseTo(360))
|
||||
if (hue.IsCloseTo(360))
|
||||
hue = 0;
|
||||
while(hue > 360)
|
||||
while (hue > 360)
|
||||
hue -= 360;
|
||||
while(hue < 0)
|
||||
while (hue < 0)
|
||||
hue += 360;
|
||||
|
||||
//通过色相返回颜色
|
||||
@@ -74,7 +74,7 @@ namespace WPFluent.Extensions
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static Hsb ToHsb(this Color color)
|
||||
public static Controls.Hsb ToHsb(this Color color)
|
||||
{
|
||||
double r = color.R;
|
||||
double g = color.G;
|
||||
@@ -95,21 +95,21 @@ namespace WPFluent.Extensions
|
||||
var delta = max - min;
|
||||
var saturation = max.IsCloseTo(0) ? 0 : delta / max;
|
||||
|
||||
if(max.IsCloseTo(min))
|
||||
if (max.IsCloseTo(min))
|
||||
{
|
||||
hue = 0; // 无色,未定义
|
||||
}
|
||||
else
|
||||
{
|
||||
if(max.IsCloseTo(r))
|
||||
if (max.IsCloseTo(r))
|
||||
{
|
||||
hue = (g - b) / delta + (g < b ? 6 : 0);
|
||||
}
|
||||
else if(max.IsCloseTo(g))
|
||||
else if (max.IsCloseTo(g))
|
||||
{
|
||||
hue = (b - r) / delta + 2;
|
||||
}
|
||||
else if(max.IsCloseTo(b))
|
||||
else if (max.IsCloseTo(b))
|
||||
{
|
||||
hue = (r - g) / delta + 4;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Diagnostics.Contracts;
|
||||
|
||||
namespace WPFluent.Extensions;
|
||||
|
||||
internal static class StringExtensions
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether a specified string occurs within this string, using the specified comparison
|
||||
|
||||
Reference in New Issue
Block a user