Files
LanMountainDesktop/LanMontainDesktop/Services/GlassEffectService.cs

69 lines
3.9 KiB
C#
Raw Normal View History

2026-02-27 19:27:38 +08:00
using Avalonia.Controls;
using Avalonia.Media;
2026-02-28 03:00:25 +08:00
using LanMontainDesktop.Theme;
2026-02-27 19:27:38 +08:00
namespace LanMontainDesktop.Services;
public static class GlassEffectService
{
2026-02-28 03:00:25 +08:00
private const double DayPanelBlurRadius = 40;
private const double DayStrongBlurRadius = 60;
private const double DayOverlayBlurRadius = 80;
private const double NightPanelBlurRadius = 45;
private const double NightStrongBlurRadius = 65;
private const double NightOverlayBlurRadius = 85;
public static void ApplyGlassResources(IResourceDictionary resources, ThemeColorContext context)
2026-02-27 19:27:38 +08:00
{
2026-02-28 04:23:28 +08:00
// Mica 材质:不透明,但混合壁纸颜色
// 提取壁纸颜色的透明度0-1用于控制 Mica 效果强度
var wallpaperTintOpacity = 0.15; // 壁纸颜色混合比例
var neutralBase = context.IsNightMode ? Color.Parse("#FF202020") : Color.Parse("#FFF3F3F3");
var neutralElevated = context.IsNightMode ? Color.Parse("#FF2C2C2C") : Color.Parse("#FFFAFAFA");
// Mica 效果:将壁纸颜色混合到中性基色中
var micaBackground = ColorMath.Blend(neutralBase, context.AccentColor, wallpaperTintOpacity);
var micaElevated = ColorMath.Blend(neutralElevated, context.AccentColor, wallpaperTintOpacity * 0.8);
// 按钮颜色
var buttonBackground = context.IsNightMode ?
Color.FromArgb(0x33, micaBackground.R, micaBackground.G, micaBackground.B) :
Color.FromArgb(0x4D, micaBackground.R, micaBackground.G, micaBackground.B);
resources["AdaptiveButtonBackgroundBrush"] = new SolidColorBrush(buttonBackground);
resources["AdaptiveButtonBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x1A, neutralElevated.R, neutralElevated.G, neutralElevated.B));
2026-02-28 03:00:25 +08:00
resources["AdaptiveButtonHoverBackgroundBrush"] = new SolidColorBrush(
2026-02-28 04:23:28 +08:00
ColorMath.WithAlpha(buttonBackground, context.IsNightMode ? (byte)0x4D : (byte)0x66));
2026-02-28 03:00:25 +08:00
resources["AdaptiveButtonPressedBackgroundBrush"] = new SolidColorBrush(
2026-02-28 04:23:28 +08:00
ColorMath.WithAlpha(buttonBackground, context.IsNightMode ? (byte)0x66 : (byte)0x80));
2026-02-28 03:00:25 +08:00
2026-02-28 04:23:28 +08:00
// 面板颜色 - 使用 Mica 材质
2026-02-28 03:00:25 +08:00
resources["AdaptiveGlassPanelBackgroundBrush"] = new SolidColorBrush(
2026-02-28 04:23:28 +08:00
Color.FromArgb(context.IsNightMode ? (byte)0xE6 : (byte)0xF2,
micaBackground.R, micaBackground.G, micaBackground.B));
resources["AdaptiveGlassPanelBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x1F, neutralElevated.R, neutralElevated.G, neutralElevated.B));
2026-02-28 03:00:25 +08:00
resources["AdaptiveGlassStrongBackgroundBrush"] = new SolidColorBrush(
2026-02-28 04:23:28 +08:00
Color.FromArgb(context.IsNightMode ? (byte)0xE6 : (byte)0xF5,
micaElevated.R, micaElevated.G, micaElevated.B));
resources["AdaptiveGlassStrongBorderBrush"] = new SolidColorBrush(
Color.FromArgb(0x29, neutralElevated.R, neutralElevated.G, neutralElevated.B));
2026-02-28 03:00:25 +08:00
resources["AdaptiveGlassOverlayBackgroundBrush"] = new SolidColorBrush(
2026-02-28 04:23:28 +08:00
Color.FromArgb(context.IsNightMode ? (byte)0xCC : (byte)0xE6,
micaBackground.R, micaBackground.G, micaBackground.B));
2026-02-27 19:27:38 +08:00
2026-02-28 04:23:28 +08:00
// 模糊半径Mica 不需要强模糊)
resources["AdaptiveGlassPanelBlurRadius"] = context.IsNightMode ? 20.0 : 30.0;
resources["AdaptiveGlassStrongBlurRadius"] = context.IsNightMode ? 25.0 : 35.0;
resources["AdaptiveGlassOverlayBlurRadius"] = context.IsNightMode ? 30.0 : 40.0;
// 不透明度Mica 材质接近不透明)
resources["AdaptiveGlassPanelOpacity"] = context.IsNightMode ? 0.95 : 0.98;
resources["AdaptiveGlassStrongOpacity"] = context.IsNightMode ? 0.97 : 0.99;
resources["AdaptiveGlassOverlayOpacity"] = context.IsNightMode ? 0.85 : 0.92;
resources["AdaptiveGlassNoiseOpacity"] = context.IsNightMode ? 0.01 : 0.008;
2026-02-27 19:27:38 +08:00
}
}