-
Notifications
You must be signed in to change notification settings - Fork 0
/
pocket.pas
502 lines (430 loc) · 13.5 KB
/
pocket.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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
{*******************************************************}
{ }
{ Scenarium }
{ Copyright (c) 2024 Kirill Filippenok }
{ Apache License 2.0 }
{ }
{*******************************************************}
unit Pocket;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Buttons, Graphics, Dialogs, ExtCtrls, Controls, fgl;
type
TFileType = (ftAudio, ftVideo, ftImage, ftUnknown);
{ CStateNotify }
TStateNotifyKind = (snNone, snProcess, snFailed, snSuccess, snReload, snCancel);
CStateNotify = class(TCustomPanel)
private
FStateNotifyKind: TStateNotifyKind;
FTimer: TTimer;
FShowTime: Cardinal;
procedure SetStateNotifyKind(Value: TStateNotifyKind);
procedure PaintState(Sender: TObject);
procedure TimerTicker(Sender: TObject);
public
constructor Create(TheOwner: TComponent); override;
published
property State: TStateNotifyKind read FStateNotifyKind write SetStateNotifyKind default snNone;
property ShowTime: Cardinal read FShowTime write FShowTime default 1000;
end;
{ Связи }
(*
Provoking - вызывающий элемент
Invoking - вызываемый элемен
*)
{ CBonds }
CBonds = Class(TObject)
private
function GetCount: Integer;
public
arProvoking: array of Integer;
arInvoking: array of Integer;
procedure Add(Provoking, Invoking: Integer);
procedure DeleteWhereProvoking(Provoking: Integer);
procedure DeleteWhereInvoking(Invoking: Integer);
function GetInvokingWhereProvoking(Provoking: Integer): Integer;
function GetProvokingWhereInvoking(Invoking: Integer): Integer;
function IndexOfProvoking(Provoking: Integer): Integer;
function IndexOfInvoking(Invoking: Integer): Integer;
function IndexOfBond(Provoking, Invoking: Integer): Integer;
procedure UpdateWhereProvoking(oldProvoking, newProvoking: Integer);
procedure UpdateWhereInvoking(oldInvoking, newInvoking: Integer);
function InProvoking(Number: Integer): Boolean;
function InInvoking(Number: Integer): Boolean;
function InBonds(Number: Integer): Boolean; overload;
function InBonds(Provoking, Invoking: Integer): Boolean; overload;
procedure Clear;
property Count: Integer read GetCount;
end;
{ CScenario }
CScenario = Class(TObject)
public
Name: String;
FilePath: String;
AudioFileNames: TStringList;
AudioFilePaths: TStringList;
VideoFileNames: TStringList;
VideoFilePaths: TStringList;
MissingFiles: TStringList;
Bonds: CBonds;
constructor Create;
destructor Destroy; override;
end;
CScenarioList = specialize TFPGObjectList<CScenario>;
procedure setGlyphSpeedButton(SpeedButton: TSpeedButton; Path: String); overload;
procedure setGlyphSpeedButton(BitBtn: TBitBtn; Path: String); overload;
function isAudio(const FileName: String): Boolean;
function isVideo(const FileName: String): Boolean;
function isImage(const FileName: String): Boolean;
function identifyFileType(const FileName: String): TFileType;
var arrAudioExtensions: Array of string = ('.AAC', '.FLAC', '.MP3',
'.OGG', '.OPUS', '.VOC',
'.WAV', '.WFP');
arrVideoExtensions: Array of string = ('.AVI', '.AVC', '.BDMV',
'.H264', '.M2V', '.M4S',
'.MJPEG', '.MKV', '.MOV',
'.MP4', '.MP5', '.MPEG',
'.MPV', '.SRT', '.STR',
'.VID', '.WEBM', '.WLMP',
'.WMV', '.XVID');
arrImageExtensions: Array of string = ('.BMP', '.GIF', '.HDR',
'.HEIC', '.HEIF', '.ICO',
'.JPG', '.JPEG', '.PNG',
'.RAW', '.RPF', '.WEBP');
implementation
procedure setGlyphSpeedButton(SpeedButton: TSpeedButton; Path: String); overload;
var Picture: TPicture;
begin
try
Picture := TPicture.Create;
Picture.LoadFromFile(Path);
SpeedButton.Glyph.Assign(Picture.Bitmap);
finally
Picture.Destroy;
end;
end;
procedure setGlyphSpeedButton(BitBtn: TBitBtn; Path: String); overload;
var Picture: TPicture;
begin
try
Picture := TPicture.Create;
Picture.LoadFromFile(Path);
BitBtn.Glyph.Assign(Picture.Bitmap);
finally
Picture.Destroy;
end;
end;
function isAudio(const FileName: String): Boolean;
var i: Integer;
begin
Result := False;
for i := Low(arrAudioExtensions) to High(arrAudioExtensions) do
begin
if UpperCase(ExtractFileExt(FileName)) = arrAudioExtensions[i] then
begin
Exit(True);
end;
end;
end;
function isVideo(const FileName: String): Boolean;
var i: Integer;
begin
Result := False;
for i := Low(arrVideoExtensions) to High(arrVideoExtensions) do
begin
if UpperCase(ExtractFileExt(FileName)) = arrVideoExtensions[i] then
begin
Exit(True);
end;
end;
end;
function isImage(const FileName: String): Boolean;
var i: Integer;
begin
Result := False;
for i := Low(arrImageExtensions) to High(arrImageExtensions) do
begin
if UpperCase(ExtractFileExt(FileName)) = arrImageExtensions[i] then
begin
Exit(True);
end;
end;
end;
function identifyFileType(const FileName: String): TFileType;
begin
Result := ftUnknown;
if isAudio(FileName) then Exit(ftAudio);
if isVideo(FileName) then Exit(ftVideo);
if isImage(FileName) then Exit(ftImage);
end;
{ CScenario }
constructor CScenario.Create;
begin
inherited Create;
Name := '';
FilePath := '';
AudioFileNames := TStringList.Create;
AudioFilePaths := TStringList.Create;
VideoFileNames := TStringList.Create;
VideoFilePaths := TStringList.Create;
MissingFiles := TStringList.Create;
Bonds := CBonds.Create;
end;
destructor CScenario.Destroy;
begin
FreeAndNil(AudioFileNames);
FreeAndNil(AudioFilePaths);
FreeAndNil(VideoFileNames);
FreeAndNil(VideoFilePaths);
FreeAndNil(MissingFiles);
FreeAndNil(Bonds);
inherited Destroy;
end;
{ CStateNotify }
procedure CStateNotify.SetStateNotifyKind(Value: TStateNotifyKind);
begin
FStateNotifyKind := Value;
case FStateNotifyKind of
snNone:
begin
Self.Visible := False;
end;
snProcess: Self.Visible := True;
snFailed, snSuccess, snReload, snCancel:
begin
Self.Visible := True;
FTimer.Interval := ShowTime;
FTimer.Enabled := True;
end;
end;
Self.Repaint;
end;
procedure CStateNotify.PaintState(Sender: TObject);
var
text_width, text_height, text_x, text_y: Integer;
begin
Self.Canvas.Pen.Style := psSolid;
Self.Canvas.Brush.Style := bsSolid;
Self.Canvas.Pen.Color := clDefault;
Self.Canvas.Brush.Color := clDefault;
case FStateNotifyKind of
snNone:
begin
Self.Canvas.Clear;
end;
snProcess:
begin
Self.Canvas.Clear;
text_width := Self.Canvas.TextWidth('Сохранение...');
text_height := Self.Canvas.TextHeight('Сохранение...');
text_x := Round(Self.Width/2) - Round(text_width/2);
text_y := Round(Self.Height/2) - Round(text_height/2);
Self.Canvas.TextOut(text_x, text_y, 'Сохранение...');
end;
snFailed:
begin
Self.Canvas.Clear;
text_width := Self.Canvas.TextWidth('Ошибка при сохранении');
text_height := Self.Canvas.TextHeight('Ошибка при сохранении');
text_x := Round(Self.Width/2) - Round(text_width/2);
text_y := Round(Self.Height/2) - Round(text_height/2);
Self.Canvas.TextOut(text_x, text_y, 'Ошибка при сохранении');
end;
snReload:
begin
Self.Canvas.Clear;
text_width := Self.Canvas.TextWidth('Перезагрузка совершена');
text_height := Self.Canvas.TextHeight('Перезагрузка совершена');
text_x := Round(Self.Width/2) - Round(text_width/2);
text_y := Round(Self.Height/2) - Round(text_height/2);
Self.Canvas.TextOut(text_x, text_y, 'Перезагрузка совершена');
end;
snSuccess:
begin
Self.Canvas.Clear;
text_width := Self.Canvas.TextWidth('Успешно сохранено');
text_height := Self.Canvas.TextHeight('Успешно сохранено');
text_x := Round(Self.Width/2) - Round(text_width/2);
text_y := Round(Self.Height/2) - Round(text_height/2);
Self.Canvas.TextOut(text_x, text_y, 'Успешно сохранено');
Self.Canvas.Pen.Style := psSolid;
Self.Canvas.Brush.Style := bsSolid;
Self.Canvas.Pen.Color := clGreen;
Self.Canvas.Brush.Color := clGreen;
end;
snCancel:
begin
Self.Canvas.Clear;
text_width := Self.Canvas.TextWidth('Сохранение отменено');
text_height := Self.Canvas.TextHeight('Сохранение отменено');
text_x := Round(Self.Width/2) - Round(text_width/2);
text_y := Round(Self.Height/2) - Round(text_height/2);
Self.Canvas.TextOut(text_x, text_y, 'Сохранение отменено');
end;
end;
end;
procedure CStateNotify.TimerTicker(Sender: TObject);
begin
FTimer.Enabled := False;
State := snNone;
end;
constructor CStateNotify.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Self.OnPaint := @PaintState;
Self.Visible := False;
FTimer := TTimer.Create(Self);
FTimer.Enabled := False;
FTimer.OnTimer := @TimerTicker;
end;
{ CBonds }
function CBonds.GetCount: Integer;
begin
Result := Length(arProvoking);
end;
procedure CBonds.Add(Provoking, Invoking: Integer);
begin
SetLength(arProvoking, Count+1);
arProvoking[Count-1] := Provoking;
SetLength(arInvoking, Count);
arInvoking[Count-1] := Invoking;
end;
procedure CBonds.DeleteWhereProvoking(Provoking: Integer);
var i, t : Integer;
begin
for i := 0 to (Count - 1) do
begin
if arProvoking[i] = Provoking then
begin
if Count = 1 then
begin
SetLength(arProvoking, 0);
SetLength(arInvoking, 0);
Exit;
end;
for t := i to (Count-2) do
begin
arProvoking[t] := arProvoking[t+1];
arInvoking[t] := arInvoking[t+1];
end;
SetLength(arProvoking, Count-1);
SetLength(arInvoking, Count);
end;
end;
end;
procedure CBonds.DeleteWhereInvoking(Invoking: Integer);
var i, t : Integer;
begin
for i := 0 to (Count - 1) do
begin
if arInvoking[i] = Invoking then
begin
if Count = 1 then
begin
SetLength(arProvoking, 0);
SetLength(arInvoking, 0);
Exit;
end;
for t := i to (Count-2) do
begin
arProvoking[t] := arProvoking[t+1];
arInvoking[t] := arInvoking[t+1];
end;
SetLength(arProvoking, Count-1);
SetLength(arInvoking, Count);
end;
end;
end;
function CBonds.GetInvokingWhereProvoking(Provoking: Integer): Integer;
begin
if IndexOfProvoking(Provoking) = -1 then
Exit(-1);
Result := arInvoking[IndexOfProvoking(Provoking)];
end;
function CBonds.GetProvokingWhereInvoking(Invoking: Integer): Integer;
begin
if IndexOfInvoking(Invoking) = -1 then
Exit(-1);
Result := arProvoking[IndexOfInvoking(Invoking)];
end;
function CBonds.IndexOfProvoking(Provoking: Integer): Integer;
var i: Integer;
begin
Result := -1;
if Count = 0 then
Exit;
for i := 0 to Count-1 do
if Provoking = arProvoking[i] then
Exit(i);
end;
function CBonds.IndexOfInvoking(Invoking: Integer): Integer;
var i: Integer;
begin
Result := -1;
if Count = 0 then
Exit;
for i := 0 to Count-1 do
if Invoking = arInvoking[i] then
Exit(i);
end;
function CBonds.IndexOfBond(Provoking, Invoking: Integer): Integer;
var i: Integer;
begin
Result := -1;
for i := 0 to Count-1 do
if (arProvoking[i] = Provoking) and (arInvoking[i] = Invoking) then
Exit(i);
end;
procedure CBonds.UpdateWhereProvoking(oldProvoking, newProvoking: Integer);
var i: Integer;
begin
if Count = 0 then
Exit;
for i := 0 to Count-1 do
if arProvoking[i] = oldProvoking then
arProvoking[i] := newProvoking;
end;
procedure CBonds.UpdateWhereInvoking(oldInvoking, newInvoking: Integer);
var i: Integer;
begin
if Count = 0 then
Exit;
for i := 0 to Count-1 do
if arInvoking[i] = oldInvoking then
arInvoking[i] := newInvoking;
end;
function CBonds.InProvoking(Number: Integer): Boolean;
var i: Integer;
begin
Result := False;
for i in arProvoking do
if i = Number then
begin
Exit(True);
end;
end;
function CBonds.InInvoking(Number: Integer): Boolean;
var i: Integer;
begin
Result := False;
for i in arInvoking do
if i = Number then
begin
Exit(True);
end;
end;
function CBonds.InBonds(Number: Integer): Boolean; overload;
begin
Result := InProvoking(Number) or InInvoking(Number);
end;
function CBonds.InBonds(Provoking, Invoking: Integer): Boolean; overload;
begin
Result := InProvoking(Provoking) and InInvoking(Invoking);
end;
procedure CBonds.Clear;
begin
SetLength(arProvoking, 0);
SetLength(arInvoking, 0);
end;
end.