- Fluent Design 风格 UI,深色/浅色主题切换 - 平滑过渡动画(页面切换、按钮交互、状态变化) - 五大核心功能:安装管理、墨迹管理、格式转换、触摸设置、激活管理 - 基于 dotnetCampus.EasiPlugin.Sdk v2.1.1-alpha.3 插件框架 - WPF 安装向导(欢迎页 -> 安装页 -> 完成页)
275 lines
10 KiB
C#
275 lines
10 KiB
C#
using System;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Media;
|
||
using System.Windows.Media.Animation;
|
||
|
||
namespace Better_Seewo.Manager.Pages
|
||
{
|
||
/// <summary>
|
||
/// TouchPage.xaml 的交互逻辑
|
||
/// 触摸设置页面 - 自定义触摸和笔输入行为
|
||
/// </summary>
|
||
public partial class TouchPage : Page
|
||
{
|
||
/// <summary>
|
||
/// 触摸设置数据模型
|
||
/// </summary>
|
||
public class TouchSettings
|
||
{
|
||
/// <summary>触摸输入是否启用</summary>
|
||
public bool TouchInputEnabled { get; set; } = true;
|
||
/// <summary>笔压灵敏度(0-100)</summary>
|
||
public int PenPressure { get; set; } = 50;
|
||
/// <summary>是否忽略误触</summary>
|
||
public bool IgnoreMistouch { get; set; } = true;
|
||
/// <summary>是否禁用掌心拒绝</summary>
|
||
public bool DisablePalmReject { get; set; } = false;
|
||
/// <summary>触摸延迟(0-500ms)</summary>
|
||
public int TouchDelay { get; set; } = 50;
|
||
/// <summary>双指缩放灵敏度(0-100)</summary>
|
||
public int PinchScaleSensitivity { get; set; } = 70;
|
||
}
|
||
|
||
// ===== 当前设置 =====
|
||
private TouchSettings _currentSettings = new TouchSettings();
|
||
|
||
public TouchPage()
|
||
{
|
||
InitializeComponent();
|
||
Loaded += TouchPage_Loaded;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 页面加载时播放入场动画
|
||
/// </summary>
|
||
private void TouchPage_Loaded(object sender, RoutedEventArgs e)
|
||
{
|
||
PlayStaggeredEntranceAnimation();
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置项交错入场动画
|
||
/// </summary>
|
||
private void PlayStaggeredEntranceAnimation()
|
||
{
|
||
var rows = new[] { Row1, Row2, Row3, Row4, Row5, Row6 };
|
||
for (int i = 0; i < rows.Length; i++)
|
||
{
|
||
var row = rows[i];
|
||
var transform = (TranslateTransform)row.RenderTransform;
|
||
int delay = i * 80; // 每项间隔80ms
|
||
|
||
var timer = new System.Windows.Threading.DispatcherTimer
|
||
{
|
||
Interval = TimeSpan.FromMilliseconds(delay)
|
||
};
|
||
timer.Tick += (s, e) =>
|
||
{
|
||
timer.Stop();
|
||
var slideIn = new DoubleAnimation
|
||
{
|
||
From = 20,
|
||
To = 0,
|
||
Duration = TimeSpan.FromMilliseconds(350),
|
||
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
|
||
};
|
||
var fadeIn = new DoubleAnimation
|
||
{
|
||
From = 0,
|
||
To = 1,
|
||
Duration = TimeSpan.FromMilliseconds(350),
|
||
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
|
||
};
|
||
transform.BeginAnimation(TranslateTransform.YProperty, slideIn);
|
||
transform.BeginAnimation(TranslateTransform.OpacityProperty, fadeIn);
|
||
};
|
||
timer.Start();
|
||
}
|
||
}
|
||
|
||
// ===== Toggle 事件处理 =====
|
||
|
||
/// <summary>
|
||
/// 触摸输入模式切换
|
||
/// </summary>
|
||
private void ToggleTouchInput_Changed(object sender, RoutedEventArgs e)
|
||
{
|
||
_currentSettings.TouchInputEnabled = ToggleTouchInput.IsChecked ?? false;
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
// ===== Slider 值改变事件(带实时预览) =====
|
||
|
||
/// <summary>
|
||
/// 笔压灵敏度滑块值改变
|
||
/// </summary>
|
||
private void SliderPenPressure_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||
{
|
||
if (PenPressureValue == null) return;
|
||
var value = (int)SliderPenPressure.Value;
|
||
PenPressureValue.Text = value.ToString();
|
||
_currentSettings.PenPressure = value;
|
||
|
||
// 实时更新预览条的缩放
|
||
var scaleX = value / 100.0;
|
||
var scaleAnimation = new DoubleAnimation
|
||
{
|
||
From = PressurePreviewBar.RenderTransform is ScaleTransform st ? st.ScaleX : scaleX,
|
||
To = scaleX,
|
||
Duration = TimeSpan.FromMilliseconds(150),
|
||
EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }
|
||
};
|
||
PressurePreviewBar.RenderTransform = new ScaleTransform(scaleX, 1);
|
||
PressurePreviewBar.RenderTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
|
||
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 触摸延迟滑块值改变
|
||
/// </summary>
|
||
private void SliderTouchDelay_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||
{
|
||
if (TouchDelayValue == null) return;
|
||
var value = (int)SliderTouchDelay.Value;
|
||
TouchDelayValue.Text = $"{value}ms";
|
||
_currentSettings.TouchDelay = value;
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 双指缩放灵敏度滑块值改变
|
||
/// </summary>
|
||
private void SliderPinchScale_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||
{
|
||
if (PinchScaleValue == null) return;
|
||
var value = (int)SliderPinchScale.Value;
|
||
PinchScaleValue.Text = value.ToString();
|
||
_currentSettings.PinchScaleSensitivity = value;
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新预览文本
|
||
/// </summary>
|
||
private void UpdatePreviewText()
|
||
{
|
||
if (PreviewText == null) return;
|
||
|
||
var touchStatus = _currentSettings.TouchInputEnabled ? "已启用" : "已禁用";
|
||
var mistouchStatus = _currentSettings.IgnoreMistouch ? "已启用" : "已禁用";
|
||
var palmStatus = _currentSettings.DisablePalmReject ? "已禁用" : "已启用";
|
||
|
||
PreviewText.Text = $"当前配置:触摸输入 {touchStatus} | 笔压灵敏度 {_currentSettings.PenPressure} | " +
|
||
$"误触过滤 {mistouchStatus} | 掌心拒绝 {palmStatus} | " +
|
||
$"触摸延迟 {_currentSettings.TouchDelay}ms | 缩放灵敏度 {_currentSettings.PinchScaleSensitivity}";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 收集当前UI设置到数据模型
|
||
/// </summary>
|
||
private void CollectSettingsFromUI()
|
||
{
|
||
_currentSettings.TouchInputEnabled = ToggleTouchInput.IsChecked ?? true;
|
||
_currentSettings.PenPressure = (int)SliderPenPressure.Value;
|
||
_currentSettings.IgnoreMistouch = ToggleIgnoreMistouch.IsChecked ?? true;
|
||
_currentSettings.DisablePalmReject = ToggleDisablePalmReject.IsChecked ?? false;
|
||
_currentSettings.TouchDelay = (int)SliderTouchDelay.Value;
|
||
_currentSettings.PinchScaleSensitivity = (int)SliderPinchScale.Value;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 恢复默认设置
|
||
/// </summary>
|
||
private async void BtnRestoreDefaults_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
var defaults = new TouchSettings();
|
||
|
||
// 带动画地恢复默认值
|
||
ToggleTouchInput.IsChecked = defaults.TouchInputEnabled;
|
||
ToggleIgnoreMistouch.IsChecked = defaults.IgnoreMistouch;
|
||
ToggleDisablePalmReject.IsChecked = defaults.DisablePalmReject;
|
||
|
||
// 动画滑块恢复
|
||
await AnimateSliderAsync(SliderPenPressure, defaults.PenPressure);
|
||
await AnimateSliderAsync(SliderTouchDelay, defaults.TouchDelay);
|
||
await AnimateSliderAsync(SliderPinchScale, defaults.PinchScaleSensitivity);
|
||
|
||
CollectSettingsFromUI();
|
||
UpdatePreviewText();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 滑块平滑动画
|
||
/// </summary>
|
||
private async Task AnimateSliderAsync(Slider slider, double targetValue)
|
||
{
|
||
var animation = new DoubleAnimation
|
||
{
|
||
From = slider.Value,
|
||
To = targetValue,
|
||
Duration = TimeSpan.FromMilliseconds(300),
|
||
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }
|
||
};
|
||
slider.BeginAnimation(Slider.ValueProperty, animation);
|
||
await Task.Delay(350);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 应用设置(异步保存)
|
||
/// </summary>
|
||
private async void BtnApplySettings_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
CollectSettingsFromUI();
|
||
|
||
BtnApplySettings.IsEnabled = false;
|
||
|
||
await Task.Run(() =>
|
||
{
|
||
// TODO: 实际保存逻辑 - 写入配置文件或注册表
|
||
// 当前为开发占位实现
|
||
System.Threading.Thread.Sleep(500);
|
||
});
|
||
|
||
BtnApplySettings.IsEnabled = true;
|
||
UpdatePreviewText();
|
||
|
||
// 显示已应用提示
|
||
MessageBox.Show("触摸设置已应用成功。", "提示",
|
||
MessageBoxButton.OK, MessageBoxImage.Information);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 供外部调用的公共方法:获取当前设置
|
||
/// </summary>
|
||
public TouchSettings GetCurrentSettings()
|
||
{
|
||
CollectSettingsFromUI();
|
||
return _currentSettings;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 供外部调用的公共方法:加载设置
|
||
/// </summary>
|
||
public void LoadSettings(TouchSettings settings)
|
||
{
|
||
if (settings == null) return;
|
||
|
||
_currentSettings = settings;
|
||
Dispatcher.Invoke(() =>
|
||
{
|
||
ToggleTouchInput.IsChecked = settings.TouchInputEnabled;
|
||
ToggleIgnoreMistouch.IsChecked = settings.IgnoreMistouch;
|
||
ToggleDisablePalmReject.IsChecked = settings.DisablePalmReject;
|
||
SliderPenPressure.Value = settings.PenPressure;
|
||
SliderTouchDelay.Value = settings.TouchDelay;
|
||
SliderPinchScale.Value = settings.PinchScaleSensitivity;
|
||
UpdatePreviewText();
|
||
});
|
||
}
|
||
}
|
||
}
|