mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Added middle mouse button scroll to the Manifest
This commit is contained in:
parent
ff1ecf27a6
commit
ef7986db5c
@ -7,7 +7,8 @@
|
||||
xmlns:reactiveUi="http://reactiveui.net"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<ScrollViewer>
|
||||
<Grid>
|
||||
<ScrollViewer MouseDown="ScrollViewer_MouseDown" MouseUp="ScrollViewer_MouseUp" MouseMove="ScrollViewer_MouseMove">
|
||||
<ScrollViewer.Resources>
|
||||
<Style x:Key="HeaderStyle" TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Foreground" Value="#03DAC6"/>
|
||||
@ -19,7 +20,7 @@
|
||||
<Setter Property="Foreground" Value="#C7FC86"/>
|
||||
</Style>
|
||||
</ScrollViewer.Resources>
|
||||
<StackPanel Margin="8">
|
||||
<StackPanel Margin="8" x:Name="DynamicStackPanel">
|
||||
<TextBlock x:Name="Name" FontSize="32" HorizontalAlignment="Center" Style="{StaticResource HeaderStyle}"/>
|
||||
<TextBlock x:Name="Author" FontSize="14" Padding="0 3 0 3"/>
|
||||
<TextBlock x:Name="Description" FontSize="14" TextWrapping="Wrap"/>
|
||||
@ -57,4 +58,6 @@
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<Canvas x:Name="TopLayer" IsHitTestVisible="False"/>
|
||||
</Grid>
|
||||
</reactiveUi:ReactiveUserControl>
|
||||
|
@ -1,8 +1,13 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using ReactiveUI;
|
||||
using Wabbajack.Lib;
|
||||
|
||||
@ -55,5 +60,76 @@ namespace Wabbajack
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
//solution from https://stackoverflow.com/questions/5426232/how-can-i-make-wpf-scrollviewer-middle-click-scroll/5446307#5446307
|
||||
|
||||
private bool _isMoving; //False - ignore mouse movements and don't scroll
|
||||
private bool _isDeferredMovingStarted; //True - Mouse down -> Mouse up without moving -> Move; False - Mouse down -> Move
|
||||
private Point? _startPosition;
|
||||
private const double Slowdown = 10; //smaller = faster
|
||||
|
||||
private void ScrollViewer_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (_isMoving)
|
||||
CancelScrolling();
|
||||
else if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
|
||||
{
|
||||
if (_isMoving) return;
|
||||
|
||||
_isMoving = true;
|
||||
_startPosition = e.GetPosition(sender as IInputElement);
|
||||
_isDeferredMovingStarted = true;
|
||||
|
||||
AddScrollSign(e.GetPosition(TopLayer).X, e.GetPosition(TopLayer).Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void ScrollViewer_MouseUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Released && _isDeferredMovingStarted != true)
|
||||
CancelScrolling();
|
||||
}
|
||||
|
||||
private void ScrollViewer_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!_isMoving || !(sender is ScrollViewer sv))
|
||||
return;
|
||||
|
||||
_isDeferredMovingStarted = false;
|
||||
|
||||
var currentPosition = e.GetPosition(sv);
|
||||
if (_startPosition == null)
|
||||
return;
|
||||
|
||||
var offset = currentPosition - _startPosition.Value;
|
||||
offset.Y /= Slowdown;
|
||||
offset.X /= Slowdown;
|
||||
|
||||
sv.ScrollToVerticalOffset(sv.VerticalOffset + offset.Y);
|
||||
sv.ScrollToHorizontalOffset(sv.HorizontalOffset + offset.X);
|
||||
}
|
||||
|
||||
private void CancelScrolling()
|
||||
{
|
||||
_isMoving = false;
|
||||
_startPosition = null;
|
||||
_isDeferredMovingStarted = false;
|
||||
RemoveScrollSign();
|
||||
}
|
||||
|
||||
private void AddScrollSign(double x, double y)
|
||||
{
|
||||
const double size = 50.0;
|
||||
var icon = new Ellipse { Stroke = Brushes.Red, StrokeThickness = 2.0, Width = 20, Height = 20 };
|
||||
|
||||
TopLayer.Children.Add(icon);
|
||||
Canvas.SetLeft(icon, x - size / 2);
|
||||
Canvas.SetTop(icon, y - size / 2);
|
||||
}
|
||||
|
||||
private void RemoveScrollSign()
|
||||
{
|
||||
TopLayer.Children.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user