CollabVMDesktopClient/CollabVMClient/Views/CollabVMScreenView.axaml.cs

61 lines
2.3 KiB
C#
Raw Normal View History

2023-08-29 08:52:35 -04:00
using Avalonia.Controls;
using CollabVMClient.ViewModels;
using CollabVMSharp;
2023-08-29 08:52:35 -04:00
namespace CollabVMClient.Views
{
public partial class CollabVMScreenView : Window
{
public CollabVMScreenView()
{
InitializeComponent();
this.exit.Click += Exit_Click;
screen.PointerMoved += Screen_PointerMoved;
screen.PointerPressed += Screen_PointerPressed;
screen.PointerReleased += Screen_PointerReleased;
}
private void Screen_PointerReleased(object? sender, Avalonia.Input.PointerReleasedEventArgs e)
{
MouseButton btn = e.InitialPressMouseButton switch
{
Avalonia.Input.MouseButton.Left => MouseButton.Left,
Avalonia.Input.MouseButton.Right => MouseButton.Right,
Avalonia.Input.MouseButton.Middle => MouseButton.Middle,
_ => (MouseButton)(-1)
};
if (btn == (MouseButton)(-1)) return;
var dc = DataContext as CollabVMScreenViewModel;
dc.MouseBtn(btn, false);
}
private void Screen_PointerPressed(object? sender, Avalonia.Input.PointerPressedEventArgs e)
{
var dc = DataContext as CollabVMScreenViewModel;
// We can't see specifically which button was pressed, so just send every currently pressed button
var point = e.GetCurrentPoint(screen);
if (point.Properties.IsLeftButtonPressed) dc.MouseBtn(MouseButton.Left, true);
if (point.Properties.IsMiddleButtonPressed) dc.MouseBtn(MouseButton.Middle, true);
if (point.Properties.IsRightButtonPressed) dc.MouseBtn(MouseButton.Right, true);
}
private void Screen_PointerMoved(object? sender, Avalonia.Input.PointerEventArgs e)
{
var dc = DataContext as CollabVMScreenViewModel;
var point = e.GetCurrentPoint(screen);
dc.MoveMouse((int)point.Position.X, (int)point.Position.Y);
}
private void Exit_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Close();
2023-08-29 08:52:35 -04:00
}
public void RefreshScreen()
{
screen.Source = ((CollabVMScreenViewModel)DataContext).Framebuffer;
screen.InvalidateVisual();
}
}
}