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);
        }
    }
}
n class="p">.Application.Current.Dispatcher; System.Windows.Application.Current.MainWindow.RegisterForLoadedOrNow((_,__) => { Thread thread = new Thread(() => { main_dispatcher.ShutdownFinished += (x, y) => { if (_window != null) { _window.Invoke(() => { _window.Close(); }); } }; _window = new Window(); _window.WindowStyle = WindowStyle.None; _window.ResizeMode = ResizeMode.NoResize; _window.ShowInTaskbar = false; _window.AllowsTransparency = true; _window.Background = Brushes.Transparent; _window.WindowStartupLocation = WindowStartupLocation.Manual; SyncBounds(); if (v != Visibility.Visible) { _window.Opacity = 0; } new WindowInteropHelper(_window).Owner = handle; _window.ShowActivated = false; var cloned = FrameworkElementSerializer.Deserialize(xaml); cloned.DataContext = dc; _window.Content = cloned; _window.Show(); SyncBounds(); System.Windows.Threading.Dispatcher.Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(); }); } } /// <summary> /// Handles the LocationChanged event of the MainWindow control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void MainWindow_LocationChanged(object sender, EventArgs e) { SyncBounds(); } /// <summary> /// Synchronizes the bounds of the window with the bounds of the original control. /// </summary> public void SyncBounds() { if (_window != null) { this.BeginInvoke(() => { Point location = PointToScreen(new Point(0, 0)); Size size = new Size(ActualWidth, ActualHeight); _window.BeginInvoke(() => { _window.Top = location.Y; _window.Left = location.X; _window.Width = size.Width; _window.Height = size.Height; }); }); } } /// <summary> /// Hides the element window. /// </summary> private void HideWindow() { if (_window != null) { _window.BeginInvoke(() => { _window.Hide(); }); } } /// <summary> /// Shows the element window. /// </summary> private void ShowWindow() { if (_window != null) { _window.BeginInvoke(() => { _window.Opacity = 1; _window.Show(); }); } } } }