142 lines
4.1 KiB
C#
142 lines
4.1 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Livia.ViewModels;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Livia.Views.Controls;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for ImageRotationViewerBorderlessControl.xaml
|
|
/// </summary>
|
|
public partial class ImageRotationViewerBorderlessControl
|
|
{
|
|
private readonly ILogger _logger;
|
|
private Point? _initialMousePosition;
|
|
private double _initialWindowCenterModifier;
|
|
private double _initialWindowWidthModifier;
|
|
|
|
public ImageRotationViewerBorderlessControl()
|
|
{
|
|
InitializeComponent();
|
|
_logger = ActivatorUtilities.GetServiceOrCreateInstance<ILogger>(ServiceProviderFactory.ServiceProvider);
|
|
}
|
|
|
|
private void OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
|
{
|
|
if (DataContext is not ImageRotationViewerControlViewModel viewModel)
|
|
return;
|
|
|
|
if (e.Delta < 0)
|
|
{
|
|
viewModel.PrevImage();
|
|
}
|
|
else
|
|
{
|
|
viewModel.NextImage();
|
|
}
|
|
e.Handled = true;
|
|
}
|
|
|
|
private void DefaultWindowLevelButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is not ImageRotationViewerControlViewModel viewModel)
|
|
return;
|
|
|
|
viewModel.SetDefaultWindowLevel();
|
|
}
|
|
|
|
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
//requires left ctrl
|
|
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
|
|
return;
|
|
|
|
if (DataContext is not ImageRotationViewerControlViewModel viewModel)
|
|
return;
|
|
|
|
if (!viewModel.StructureImageSeries.WindowCenterModifiable)
|
|
return;
|
|
|
|
//set cursor
|
|
Cursor = Cursors.Cross;
|
|
_initialMousePosition = e.GetPosition(this);
|
|
_initialWindowCenterModifier = viewModel.WindowCenterModifier;
|
|
_initialWindowWidthModifier = viewModel.WindowWidthModifier;
|
|
_logger.LogInformation("Mouse Down, WindowCenterModifier = {wc}, WindowWidthModifier = {ww}", _initialWindowCenterModifier, _initialWindowWidthModifier);
|
|
}
|
|
|
|
private void OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
|
{
|
|
_initialMousePosition = null;
|
|
//reset cursor
|
|
Cursor = Cursors.Arrow;
|
|
}
|
|
|
|
private void OnMouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
if (DataContext is not ImageRotationViewerControlViewModel viewModel)
|
|
return;
|
|
|
|
if (_initialMousePosition == null)
|
|
return;
|
|
|
|
Vector delta = _initialMousePosition.Value - e.GetPosition(this);
|
|
Size size = RenderSize;
|
|
|
|
double xDelta = delta.X / size.Width;
|
|
double yDelta = delta.Y / size.Height;
|
|
|
|
viewModel.WindowWidthModifier = _initialWindowWidthModifier - xDelta;
|
|
viewModel.WindowCenterModifier = _initialWindowCenterModifier + yDelta;
|
|
|
|
//_logger.LogInformation("Mouse move,dx = {x}, dy = {y}", xDelta, yDelta);
|
|
}
|
|
|
|
private void OnMouseLeave(object sender, MouseEventArgs e)
|
|
{
|
|
_initialMousePosition = null;
|
|
//reset cursor
|
|
Cursor = Cursors.Arrow;
|
|
}
|
|
|
|
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (DataContext is not ImageRotationViewerControlViewModel viewModel)
|
|
return;
|
|
|
|
// ReSharper disable once ConvertIfStatementToSwitchStatement
|
|
if (e.Key is Key.W or Key.Up)
|
|
{
|
|
viewModel.NextImage();
|
|
}
|
|
else if (e.Key is Key.S or Key.Down)
|
|
{
|
|
viewModel.PrevImage();
|
|
}
|
|
|
|
Focus();
|
|
}
|
|
|
|
private void OnMouseEnter(object sender, MouseEventArgs e)
|
|
{
|
|
if (Application.Current.Windows.OfType<SettingsWindow>().Any())
|
|
{
|
|
return;
|
|
}
|
|
|
|
Focus();
|
|
}
|
|
private void ImageRotationViewerBorderlessControl_OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
// Force initialization ToolTip
|
|
var toolTip = Button.ToolTip as ToolTip;
|
|
if (toolTip != null)
|
|
{
|
|
toolTip.IsOpen = true;
|
|
toolTip.IsOpen = false;
|
|
}
|
|
}
|
|
} |