using Avalonia.Controls; using CollabVMClient.ViewModels; using CollabVMSharp; 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(); } public void RefreshScreen() { screen.Source = ((CollabVMScreenViewModel)DataContext).Framebuffer; screen.InvalidateVisual(); } } }