This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuvncview.pas
154 lines (140 loc) · 3.69 KB
/
uvncview.pas
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
unit UVNCView;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, StdCtrls, ExtCtrls, Forms, Controls, Graphics, base64,
UCreateImageThread, UControlMachineThread;
type
TVNCView = class
private
id, row, col: integer;
name, ip, room: string;
scroll: TScrollBox;
box: TGroupBox;
viewport: TImage;
control: TButton;
timer: TTimer;
text: TLabel;
imageThread: TCreateImageThread;
controlThread: TControlMachineThread;
procedure updateImage(Sender: TObject);
procedure openRemoteControl(Sender: TObject);
public
constructor create(cid: integer; cname, cip, croom: string; cscroll: TScrollBox);
procedure setActive(mode: boolean);
procedure reposition;
procedure loadNewImage(data: string);
end;
implementation
uses
PCS;
constructor TVNCView.create(cid: integer; cname, cip, croom: string; cscroll: TScrollBox);
var
c: integer;
begin
id:=cid;
name:=cname;
room:=croom;
scroll:=cscroll;
ip:=cip;
c:=0;
col:=0;
row:=1;
while (c < id) do begin
col:=col+1;
if (col = 5) then begin
col:=1;
row:=row+1;
end;
c:=c+1;
end;
timer:=TTimer.create(Application);
timer.enabled:=false;
timer.interval:=5000;
timer.onTimer:=@updateImage;
box:=TGroupBox.create(Application);
box.width:=((window.width - 65) div 4);
box.height:=(round(0.8 * box.width) + 50);
box.left:=(5 + ((box.width + 5) * (col - 1)));
box.top:=(5 + ((box.height + 5) * (row - 1)));
box.parent:=scroll;
box.caption:=name;
viewport:=TImage.create(Application);
viewport.parent:=box;
viewport.left:=0;
viewport.top:=0;
viewport.width:=box.width;
viewport.height:=(box.height - 30);
viewport.Stretch:=true;
viewport.Proportional:=true;
viewport.visible:=false;
viewport.antialiasingMode:=amOn;
control:=TButton.create(Application);
control.parent:=box;
control.width:=107;
control.height:=25;
control.top:=(box.height - 20 - control.height);
control.left:=(box.width - 5 - control.width);
control.caption:='Rechner steuern';
control.onClick:=@openRemoteControl;
text:=TLabel.create(Application);
text.parent:=box;
text.left:=10;
text.top:=10;
text.caption:='Rechner ausgeschaltet.';
text.font.size:=15;
end;
procedure TVNCView.setActive(mode: boolean);
begin
if (mode = true) then begin
viewport.visible:=true;
text.visible:=false;
control.enabled:=true;
timer.enabled:=true;
end
else begin
viewport.visible:=false;
text.visible:=true;
control.enabled:=false;
timer.enabled:=false;
end;
end;
procedure TVNCView.reposition;
begin
box.width:=((window.width - 65) div 4);
box.height:=(round(0.8 * box.width) + 50);
box.left:=(5 + ((box.width + 5) * (col - 1)));
box.top:=(5 + ((box.height + 5) * (row - 1)));
viewport.width:=box.width;
viewport.height:=(box.height - 30);
control.top:=(box.height - 20 - control.height);
control.left:=(box.width - 5 - control.width);
end;
procedure TVNCView.updateImage(Sender: TObject);
begin
if (window.MainPageCtrl.activePage = window.vncSheet) then begin
imageThread:=TCreateImageThread.create(name, ip, room);
imageThread.OnShowStatus:=@loadNewImage;
imageThread.resume;
end;
end;
procedure TVNCView.openRemoteControl(Sender: TObject);
begin
controlThread:=TControlMachineThread.create(ip, room, name);
controlThread.resume;
end;
procedure TVNCView.loadNewImage(data: string);
var
Image: TJPEGImage;
MStream: TStringStream;
begin
MStream:=TStringStream.create('');
MStream.WriteString(DecodeStringBase64(data));
MStream.position:=0;
Image:=TJPEGImage.create;
Image.loadFromStream(MStream);
viewport.picture.jpeg:=Image;
Image.free;
MStream.free;
end;
end.