-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxterm_gui.pas
395 lines (329 loc) · 10.5 KB
/
xterm_gui.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
unit xterm_gui;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
StdCtrls, ExtCtrls, LCLType, Buttons, types, LMessages;
type
{ Tterm }
Tterm = class(TForm)
MainMenu1: TMainMenu;
MenuItem1: TMenuItem;
MenuItem10: TMenuItem;
MenuItem11: TMenuItem;
MenuItem12: TMenuItem;
MenuItem13: TMenuItem;
MenuItem14: TMenuItem;
MenuItem15: TMenuItem;
MenuItem16: TMenuItem;
MenuItem17: TMenuItem;
size0: TMenuItem;
size1: TMenuItem;
size2: TMenuItem;
size3: TMenuItem;
theme0: TMenuItem;
theme1: TMenuItem;
theme3: TMenuItem;
MenuItem2: TMenuItem;
theme2: TMenuItem;
MenuItem21: TMenuItem;
MenuItem22: TMenuItem;
kind_line: TMenuItem;
kind_tree: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
Scroll: TScrollBar;
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure MenuItem11Click(Sender: TObject);
procedure MSDOs(Sender: TObject);
procedure size0Click(Sender: TObject);
procedure theme0Click(Sender: TObject);
procedure MenuItem3Click(Sender: TObject);
procedure MenuItem4Click(Sender: TObject);
procedure MenuItem9Click(Sender: TObject);
procedure ScrollScroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure OptiRepaint;
private
procedure RedrawOnThemeChange;
end;
var
term: Tterm;
implementation
uses mik_VM, xterm_core, main;
{$R *.lfm}
{ Tterm }
procedure Tterm.FormCreate(Sender: TObject);
begin
enter_data_layer:=Tbitmap.Create;
{default values}
Frame_Font:=TFont.Create;
Frame_Font.Name:='Droid Sans Mono';
Frame_Font.size:=9;
readln_proc_lock:=none;
//sync conf
with main.app_config do
begin
//set size
case TERM_W_size of
1:size1.Click;
2:size2.Click;
3:size3.Click
else size0.Click; //default
end;
case TERM_theme of //внимание вызывает перерисовку!!!!
0:theme0.Click;
1:theme1.Click;
3:theme3.Click
else theme2.Click; //default
end;
MODIFY:=false;
end;
end;
procedure Tterm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
if (MikCpu<>nil) then
main_gui.stop_execClick(nil);
main_gui.save_config;
end;
procedure Tterm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
IF ((MikCpu<>nil) and (KEY=VK_C) and (Shift=[ssCtrl])) then begin
//Ctrl+C - kill terminal
xterm_writeln('---------------------------');
xterm_writeln('[!!] Ctrl + C; Выполение остановлено.');
main_gui.stop_execClick(nil);
end
ELSE
if readln_proc_lock=query then
if (key=VK_RETURN) and (shift=[]) then
if tryStrToint(input_buf,input_value) then
if (input_value>=-32768) and (input_value <=32767) then
begin
//пишем, что ввели то-то и предаем управление далее
readln_proc_lock:=none;
//lines.Add('<'+inttostr(input_value)); //защита от -1) DEPRECATED
AddData_toStrList('<'+inttostr(input_value));
input_buf:='';
scroll.Enabled:=true;
redraw(false); //new
Repaint; //full only
////передаем управление далее (возобновляем поток)
main_gui.Enabled:=true;
MikCpu.Resume;
end;
end;
procedure Tterm.FormKeyPress(Sender: TObject; var Key: char);
var
dr_x,dr_y:word;
begin
if readln_proc_lock=query then begin
if input_buf='' then begin
if not (key in ['-','0'..'9']) then key:=#0;
end
else if not (key in ['0'..'9',#8]) then key:=#0;
if key<>#0 then
case key of
#8:delete(input_buf,length(input_buf),1)
else input_buf:=input_buf+key;
end;
dr_x:=(enter_data_layer.Width-6 - input_width) div 2;
dr_y:=font_h*4-2;
//отрис буфер
enter_data_layer.Canvas.Font.Color:=Profile_perf.Back_cl;
enter_data_layer.Canvas.TextOut(dr_x,dr_y,'0000-32768');
enter_data_layer.Canvas.Font.Color:=Profile_perf.font_cl;
enter_data_layer.Canvas.TextOut(dr_x+input_width-enter_data_layer.Canvas.TextWidth(input_buf),dr_y,input_buf);
Repaint; //Fill only
end;
end;
procedure Tterm.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
begin
scroll.Position:=scroll.Position+6;
end;
procedure Tterm.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
begin
scroll.Position:=scroll.Position-6;
end;
procedure Tterm.OptiRepaint; //внутреннй вызов
var
dr_y_shift:word;
frame_id:byte;
begin
frame_id:=scroll.position div Profile_perf.v_height;
dr_y_shift:=scroll.position mod Profile_perf.v_height;
with ReDrawInfo do
if (frame=nil) or (need_to_cln_canvas)
then
begin
REPAINT; {область обновления НЕ ЗАДАНА, рисуем все. --> sys.redraw }
need_to_cln_canvas:=false;
end
ELSE
if (frames.FrameMap[frame_id]=frame) then
term.canvas.CopyRect(RECT(from_x,from_y+dr_y_shift,to_x,to_y+dr_y_shift), frame^.data.Canvas, RECT(from_x,from_y,to_x,to_y));
end;
procedure Tterm.FormPaint(Sender: TObject);
var
dr_y_shift:word;
frame_id:byte;
begin
//full repaint
frame_id:=scroll.position div Profile_perf.v_height;
dr_y_shift:=scroll.position mod Profile_perf.v_height;
Canvas.Draw(0,-dr_y_shift, frames.FrameMap[frame_id]^.data);
//отрисовали все? если был сдвиг то нет + если существует след кадр
if (dr_y_shift>0) and (frame_id<Frames.DataCount) then
begin
inc(frame_id);
Canvas.Draw(0,(Profile_perf.v_height-dr_y_shift),frames.FrameMap[frame_id]^.data);
end;
//отрисовка диалога запроса значения)
if (readln_proc_lock=QUERY) then
canvas.Draw((term.ClientWidth-enter_data_layer.Width) div 2,(term.ClientHeight - enter_data_layer.Height) div 2,enter_data_layer);
end;
procedure Tterm.FormResize(Sender: TObject);
{const
min_w=80;
min_h=24;
max_w=255;
max_h=255;
var
new_w,new_h:word; }
begin
{ В Win* живет своей жизнью режим bsSizable для формы
по этому стоит bsSingle, который запрещает измененеие размера пользователем
=> данный код бесполезен (пока вкл bsSingle)
//расчет изменений....
new_w:=clientWidth div font_w;
new_h:=clientHeight div font_h;
if (new_w<min_w) then new_w:=min_w
else
if (new_w>max_w) then new_w:=max_w;
if (new_h<min_h) then new_h:=min_h
else
if (new_h>max_h) then new_h:=max_h;
//перерисовка только если изменился размер...
resize_term(new_w,new_h,((x_term_w<>new_w) or (x_term_h<>new_h)) );
}
end;
procedure Tterm.MenuItem11Click(Sender: TObject);
begin
clean_term(false);
end;
procedure Tterm.MSDOs(Sender: TObject);
begin
with sender as TMenuitem do
app_config.TERM_W_theme:=tag;
RedrawOnThemeChange;
end;
procedure Tterm.size0Click(Sender: TObject);
begin
with sender as TMenuItem do
app_config.TERM_W_size:=tag;
case app_config.TERM_W_size of
1:resize_term(80,44,true);
2:resize_term(132,24,true);
3:resize_term(132,44,true)
else
resize_term(80,24,true); //default
end;
app_config.MODIFY:=true;
end;
procedure Tterm.RedrawOnThemeChange; //просто тот кусок повторялся n раз))
var
key:char;
begin
color:=Profile_perf.back_cl; //цвет формы
//пересоздай кно диалога под новую тему
create_DialogFrame;
//перерисовка.....
redraw(true);
if readln_proc_lock=query then
begin xterm_readln; key:=#0; term.KeyPress(key); end //в этом случае и так перерисует
else Repaint;
end;
procedure Tterm.theme0Click(Sender: TObject);
begin
with sender as TMenuItem do
app_config.TERM_theme:=tag;
case app_config.TERM_theme of
0:begin
Profile_perf.font_cl:=clLime;
Profile_perf.back_cl:=$0;
Profile_perf.cmd_cl:=$342ebe;
end;
1:begin
Profile_perf.font_cl:=clWhite;
Profile_perf.back_cl:=$0;
Profile_perf.cmd_cl:=$43fbf9
end;
3:begin
Profile_perf.font_cl:=$0;
Profile_perf.back_cl:=clWhite;
Profile_perf.cmd_cl:=$d02c37;
end
else
begin {DEFAULT}
Profile_perf.font_cl:=$0;
Profile_perf.back_cl:=$DDFFFF;
Profile_perf.cmd_cl:=$d02c37;
end;
end;
RedrawOnThemeChange;
app_config.MODIFY:=true;
end;
procedure Tterm.MenuItem3Click(Sender: TObject);
var
key:char;
begin
MenuItem4.Enabled:=true;
if Frame_Font.Size<14 then begin
Frame_Font.Size:=Frame_Font.Size+1;
resize_term(x_term_w,x_term_h,true);
end;
if Frame_Font.Size=14 then MenuItem3.Enabled:=false;
reSet_Font_prop;
create_DialogFrame;
if readln_proc_lock=query then begin key:=#0; term.KeyPress(key); end;
end;
procedure Tterm.MenuItem4Click(Sender: TObject);
var
key:char;
begin
MenuItem3.Enabled:=true;
if Frame_Font.Size>7 then begin
Frame_Font.Size:=Frame_Font.Size-1;
resize_term(x_term_w,x_term_h,true);
end;
if Frame_Font.Size=7 then MenuItem4.Enabled:=false;
reSet_Font_prop;
create_DialogFrame;
if readln_proc_lock=query then begin key:=#0; term.KeyPress(key); end;
end;
procedure Tterm.MenuItem9Click(Sender: TObject);
begin
close;
end;
procedure Tterm.ScrollScroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
Repaint; //full only!
end;
end.