forked from Ylianst/MeshCentralRouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKVMViewerExtra.cs
125 lines (108 loc) · 4.55 KB
/
KVMViewerExtra.cs
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
Copyright 2009-2022 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace MeshCentralRouter
{
public partial class KVMViewerExtra : Form
{
private MainForm parent = null;
private KVMViewer mainViewer = null;
private KVMControl kvmControl = null;
public KVMControl mainKvmControl = null;
private int displayId;
public string lang = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
public KVMViewerExtra(MainForm parent, KVMViewer mainViewer, NodeClass node, KVMControl mainKvmControl, int displayId)
{
this.parent = parent;
this.mainViewer = mainViewer;
this.mainKvmControl = mainKvmControl;
this.displayId = displayId;
InitializeComponent();
Translate.TranslateControl(this);
this.Text += " - " + node.name + " (" + displayId + ")";
kvmControl = resizeKvmControl.KVM;
kvmControl.desktop = mainKvmControl.desktop;
kvmControl.parentEx = this;
//kvmControl.Visible = true;
kvmControl.DesktopSizeChanged += KvmControl_DesktopSizeChanged;
kvmControl.cropDisplay(mainKvmControl.displayOrigin, mainKvmControl.displayInfo[displayId]);
resizeKvmControl.ZoomToFit = true;
this.MouseWheel += MainForm_MouseWheel;
}
public void UpdateScreenArea(Bitmap desktop, Rectangle r)
{
if (kvmControl.displayCrop.IntersectsWith(r) == false) return;
Rectangle r2 = new Rectangle(r.X, r.Y, r.Width, r.Height);
r2.Intersect(kvmControl.displayCrop);
kvmControl.desktop = desktop;
if (kvmControl.ScaleFactor == 1)
{
Rectangle r3 = new Rectangle(r2.X - kvmControl.displayCrop.X, r2.Y - kvmControl.displayCrop.Y, r2.Width, r2.Height);
kvmControl.Repaint(r3);
}
else
{
Rectangle r3 = new Rectangle((int)(((double)(r2.X - kvmControl.displayCrop.X)) / kvmControl.ScaleFactor) - 2, (int)(((double)(r2.Y - kvmControl.displayCrop.Y)) / kvmControl.ScaleFactor) - 2, (int)(((double)r2.Width) / kvmControl.ScaleFactor) + 4, (int)(((double)r2.Height) / kvmControl.ScaleFactor) + 4);
kvmControl.Repaint(r3);
}
}
private void KvmControl_DesktopSizeChanged(object sender, EventArgs e)
{
//kvmControl.Visible = true;
}
void MainForm_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta == 0) return;
Control c = this.GetChildAtPoint(e.Location);
if (c != null && c == resizeKvmControl) resizeKvmControl.MouseWheelEx(sender, e);
}
private void MainForm_Load(object sender, EventArgs e)
{
this.Size = new Size(820, 480);
resizeKvmControl.CenterKvmControl(false);
kvmControl.Repaint(null);
}
public void OnScreenChanged()
{
resizeKvmControl.CenterKvmControl(true);
}
private void resizeKvmControl_Enter(object sender, EventArgs e)
{
kvmControl.AttachKeyboard();
}
private void resizeKvmControl_Leave(object sender, EventArgs e)
{
kvmControl.DetacheKeyboard();
}
private void KVMViewer_Deactivate(object sender, EventArgs e)
{
kvmControl.DetacheKeyboard();
}
private void KVMViewer_Activated(object sender, EventArgs e)
{
kvmControl.AttachKeyboard();
}
bool isPointVisibleOnAScreen(Point p)
{
foreach (Screen s in Screen.AllScreens) { if ((p.X < s.Bounds.Right) && (p.X > s.Bounds.Left) && (p.Y > s.Bounds.Top) && (p.Y < s.Bounds.Bottom)) return true; }
return false;
}
private void KVMViewerExtra_FormClosed(object sender, FormClosedEventArgs e)
{
mainViewer.extraScreenClosed();
}
}
}