修改主页面右侧硬件栏目宽度,运动控制修改增加图标按钮切换。
This commit is contained in:
@@ -136,6 +136,27 @@ namespace XP.Common.Controls
|
||||
|
||||
#endregion
|
||||
|
||||
#region SwapMouseButtons 依赖属性 | SwapMouseButtons Dependency Property
|
||||
|
||||
public static readonly DependencyProperty SwapMouseButtonsProperty =
|
||||
DependencyProperty.Register(nameof(SwapMouseButtons), typeof(bool), typeof(VirtualJoystick),
|
||||
new PropertyMetadata(false, OnSwapMouseButtonsChanged));
|
||||
|
||||
/// <summary>是否交换左右键功能 | Whether to swap left and right button functions</summary>
|
||||
public bool SwapMouseButtons
|
||||
{
|
||||
get => (bool)GetValue(SwapMouseButtonsProperty);
|
||||
set => SetValue(SwapMouseButtonsProperty, value);
|
||||
}
|
||||
|
||||
private static void OnSwapMouseButtonsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is VirtualJoystick joystick)
|
||||
joystick.UpdateIconVisibility();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 四向图标依赖属性 | Directional Icon Dependency Properties
|
||||
|
||||
// 左键图标 | Left button icons
|
||||
@@ -185,7 +206,9 @@ namespace XP.Common.Controls
|
||||
{
|
||||
base.OnMouseLeftButtonDown(e);
|
||||
if (_isDragging || !IsEnabled) return;
|
||||
StartDrag(MouseButtonType.Left);
|
||||
// 如果启用了左右键交换,则左键触发右键逻辑,反之亦然
|
||||
var buttonType = SwapMouseButtons ? MouseButtonType.Right : MouseButtonType.Left;
|
||||
StartDrag(buttonType);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -193,7 +216,9 @@ namespace XP.Common.Controls
|
||||
{
|
||||
base.OnMouseRightButtonDown(e);
|
||||
if (_isDragging || !IsEnabled) return;
|
||||
StartDrag(MouseButtonType.Right);
|
||||
// 如果启用了左右键交换,则右键触发左键逻辑,反之亦然
|
||||
var buttonType = SwapMouseButtons ? MouseButtonType.Left : MouseButtonType.Right;
|
||||
StartDrag(buttonType);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -233,7 +258,10 @@ namespace XP.Common.Controls
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
if (!_isDragging || ActiveMouseButton != MouseButtonType.Left) return;
|
||||
if (!_isDragging) return;
|
||||
// 结束拖拽时,根据当前实际按下的按钮类型判断
|
||||
var expectedType = SwapMouseButtons ? MouseButtonType.Right : MouseButtonType.Left;
|
||||
if (ActiveMouseButton != expectedType) return;
|
||||
EndDrag();
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -241,7 +269,10 @@ namespace XP.Common.Controls
|
||||
protected override void OnMouseRightButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnMouseRightButtonUp(e);
|
||||
if (!_isDragging || ActiveMouseButton != MouseButtonType.Right) return;
|
||||
if (!_isDragging) return;
|
||||
// 结束拖拽时,根据当前实际按下的按钮类型判断
|
||||
var expectedType = SwapMouseButtons ? MouseButtonType.Left : MouseButtonType.Right;
|
||||
if (ActiveMouseButton != expectedType) return;
|
||||
EndDrag();
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -326,16 +357,21 @@ namespace XP.Common.Controls
|
||||
SetVisibility(Visibility.Visible, defaultTop, defaultBottom, defaultLeft, defaultRight);
|
||||
|
||||
// 根据 ActiveMouseButton 切换 | Switch based on ActiveMouseButton
|
||||
// 如果启用了左右键交换,则显示相反的图标组
|
||||
switch (ActiveMouseButton)
|
||||
{
|
||||
case MouseButtonType.Left:
|
||||
SetVisibility(Visibility.Collapsed, defaultTop, defaultBottom, defaultLeft, defaultRight);
|
||||
SetVisibility(Visibility.Visible, leftTop, leftBottom, leftLeft, leftRight);
|
||||
// 如果交换了左右键,这里显示的是右键图标组
|
||||
var leftIcons = SwapMouseButtons ? new[] { rightTop, rightBottom, rightLeft, rightRight } : new[] { leftTop, leftBottom, leftLeft, leftRight };
|
||||
SetVisibility(Visibility.Visible, leftIcons);
|
||||
if (_thumbElement != null) _thumbElement.Fill = new SolidColorBrush(Color.FromRgb(0x3A, 0x7B, 0xC8));
|
||||
break;
|
||||
case MouseButtonType.Right:
|
||||
SetVisibility(Visibility.Collapsed, defaultTop, defaultBottom, defaultLeft, defaultRight);
|
||||
SetVisibility(Visibility.Visible, rightTop, rightBottom, rightLeft, rightRight);
|
||||
// 如果交换了左右键,这里显示的是左键图标组
|
||||
var rightIcons = SwapMouseButtons ? new[] { leftTop, leftBottom, leftLeft, leftRight } : new[] { rightTop, rightBottom, rightLeft, rightRight };
|
||||
SetVisibility(Visibility.Visible, rightIcons);
|
||||
if (_thumbElement != null) _thumbElement.Fill = new SolidColorBrush(Color.FromRgb(0x5B, 0xA8, 0x5B));
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user