CollabVMDesktopClient/CollabVMClient/Views/CollabVMScreenView.axaml.cs
Elijah 08e5821df4 - add turns and vm control
- remove vlc since it doesnt work and takes up like 200mb
- enforce light mode temporarily since dark mode breaks everything
2023-08-29 13:39:51 -04:00

60 lines
2.3 KiB
C#

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();
}
}
}