aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/Controls/RemoteDesktopControl.xaml.cs
blob: 617c3ec4479379d2b844508c45bc836ccf9234fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.FSE.PPCConsole.ViewModels;

namespace Tango.FSE.PPCConsole.Controls
{
    /// <summary>
    /// Interaction logic for RemoteDesktopControl.xaml
    /// </summary>
    public partial class RemoteDesktopControl : UserControl
    {
        private RemoteDesktopViewVM _vm;

        public RemoteDesktopControl()
        {
            InitializeComponent();

            Loaded += (_, __) => _vm = DataContext as RemoteDesktopViewVM;

            img.PreviewMouseDown += Img_PreviewMouseDown;
            img.PreviewMouseUp += Img_PreviewMouseUp;
            img.PreviewMouseMove += Img_PreviewMouseMove;
            img.PreviewKeyDown += Img_PreviewKeyDown;
            img.PreviewKeyUp += Img_PreviewKeyUp;
            img.PreviewMouseWheel += Img_PreviewMouseWheel;
        }

        private void Img_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            _vm.OnKeyboardDown(e.Key, Keyboard.IsKeyDown(Key.LeftCtrl), Keyboard.IsKeyDown(Key.LeftShift), Keyboard.IsKeyDown(Key.LeftAlt));
        }

        private void Img_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            _vm.OnKeyboardUp(e.Key, Keyboard.IsKeyDown(Key.LeftCtrl), Keyboard.IsKeyDown(Key.LeftShift), Keyboard.IsKeyDown(Key.LeftAlt));
        }

        private void Img_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Mouse.Capture(img);

            if (e.ClickCount == 2)
            {
                _vm.OnMouseDoubleClick(e.ChangedButton, e.GetPosition(img), new Size(img.ActualWidth, img.ActualHeight));
            }
            else
            {
                _vm.OnMouseDown(e.ChangedButton, e.GetPosition(img), new Size(img.ActualWidth, img.ActualHeight));
            }
        }

        private void Img_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            img.Focus();
            Keyboard.Focus(img);
            img.ReleaseMouseCapture();
            _vm.OnMouseUp(e.ChangedButton, e.GetPosition(img), new Size(img.ActualWidth, img.ActualHeight));
        }

        private void Img_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            _vm.OnMouseMove(e.GetPosition(img), new Size(img.ActualWidth, img.ActualHeight));
        }

        private void Img_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            _vm.OnMouseScroll(e.Delta, e.GetPosition(img), new Size(img.ActualWidth, img.ActualHeight));
        }

        private void BtnSnapshot_Click(object sender, RoutedEventArgs e)
        {
            rectSnapshot.StartDoubleAnimation(Rectangle.OpacityProperty, TimeSpan.FromSeconds(0.2), 1, 0, null, null, null, true);
        }
    }
}