-
Notifications
You must be signed in to change notification settings - Fork 26
/
BigTV.Main.pas
1683 lines (1536 loc) · 44.1 KB
/
BigTV.Main.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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit BigTV.Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.ExtCtrls, Vcl.StdCtrls, PasLibVlcUnit, PasLibVlcClassUnit,
System.Generics.Collections, Vcl.Grids, HGM.Controls.VirtualTable,
System.Types, HGM.Controls.PanelExt, HGM.Button, System.ImageList, Vcl.ImgList,
Vcl.AppEvnts, HGM.Popup, HGM.Common.Settings, Vcl.OleCtrls, SHDocVw,
PasLibVlcPlayerUnit, IPPeerClient, Data.Bind.Components,
Data.Bind.ObjectScope, REST.Client, System.Net.HttpClient;
type
TChannelGuideItem = record
Date: TDateTime;
Text: string;
end;
TChannelGuideItems = TTableData<TChannelGuideItem>;
TChannel = record
URL: string;
Name: string;
TVGName: string;
Descriprion: string;
Guide: TChannelGuideItems;
Favorite: Boolean;
Icon: TBitmap;
private
FFavorite: Boolean;
function GetNowWatch: string;
function GetNowWatchID: Integer;
public
function LoadGuide(Path: string): Boolean;
function LoadIcon(Path: string): Boolean;
property NowWatch: string read GetNowWatch;
property NowWatchId: Integer read GetNowWatchID;
end;
TChannels = class(TTableData<TChannel>)
public
function GetIdByTVGName(TVGName: string): Integer;
procedure Clear; override;
end;
TFormMain = class(TForm)
PanelTV: TPanel;
PanelCtrl: TPanel;
PanelVolume: TPanel;
DrawPanelVolume: TDrawPanel;
ButtonFlatMute: TButtonFlat;
ImageList16: TImageList;
ButtonFlatVolume100: TButtonFlat;
TimerInfoHide: TTimer;
DrawPanelInfo: TDrawPanel;
PanelChannels: TPanel;
PanelGuide: TPanel;
TableExTvGuide: TTableEx;
Panel2: TPanel;
ButtonFlatCloseGuide: TButtonFlat;
PanelChannel: TPanel;
Panel3: TPanel;
ButtonFlatCloseChannels: TButtonFlat;
TableExChannels: TTableEx;
PanelPopup: TPanel;
ButtonFlat1: TButtonFlat;
ButtonFlatQuit: TButtonFlat;
Shape1: TShape;
Shape2: TShape;
TimerHideCursor: TTimer;
ApplicationEvents: TApplicationEvents;
CheckBoxStayOnTop: TCheckBoxFlat;
TimerShowVolume: TTimer;
TimerNumber: TTimer;
DrawPanelLeftTop: TDrawPanel;
TimerRefresh: TTimer;
DrawPanelTopRight: TDrawPanel;
ImageList32: TImageList;
ButtonFlatPrevChannel: TButtonFlat;
ButtonFlatNextChannel: TButtonFlat;
CheckBoxPanelCtrl: TCheckBoxFlat;
ButtonFlatClose: TButtonFlat;
ButtonFlatMin: TButtonFlat;
ButtonFlatMax: TButtonFlat;
ButtonFlatMin2: TButtonFlat;
TableExFavChannels: TTableEx;
ButtonFlatPause: TButtonFlat;
ButtonFlatPlay: TButtonFlat;
ButtonFlatTVGuide: TButtonFlat;
VlcPlayer: TPasLibVlcPlayer;
Panel1: TPanel;
ButtonFlatVDOWN: TButtonFlat;
ButtonFlatVUP: TButtonFlat;
procedure FormCreate(Sender: TObject);
procedure TableExChannelsDblClick(Sender: TObject);
procedure DrawPanelVolumePaint(Sender: TObject);
procedure DrawPanelVolumeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure DrawPanelVolumeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure DrawPanelVolumeMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TableExChannelsDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure ButtonFlatMuteClick(Sender: TObject);
procedure ButtonFlatVolume100Click(Sender: TObject);
procedure DrawPanelVolumeMouseEnter(Sender: TObject);
procedure DrawPanelVolumeMouseLeave(Sender: TObject);
procedure DrawPanelVolumeMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
procedure DrawPanelVolumeMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
procedure VlcPlayerDblClick(Sender: TObject);
procedure VlcPlayerMouseEnter(Sender: TObject);
procedure TimerInfoHideTimer(Sender: TObject);
procedure DrawPanelInfoPaint(Sender: TObject);
procedure TableExChannelsMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TableExTvGuideGetData(FCol, FRow: Integer; var Value: string);
procedure ButtonFlatCloseGuideClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure ButtonFlatCloseChannelsClick(Sender: TObject);
procedure VlcPlayerMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ButtonFlatQuitClick(Sender: TObject);
procedure ButtonFlat1Click(Sender: TObject);
procedure VlcPlayerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TimerHideCursorTimer(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure VlcPlayerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure TimerShowVolumeTimer(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure TimerNumberTimer(Sender: TObject);
procedure DrawPanelLeftTopPaint(Sender: TObject);
procedure TimerRefreshTimer(Sender: TObject);
procedure DrawPanelTopRightPaint(Sender: TObject);
procedure CheckBoxStayOnTopClick(Sender: TObject);
procedure ButtonFlatVUPClick(Sender: TObject);
procedure ButtonFlatVDOWNClick(Sender: TObject);
procedure ButtonFlatPrevChannelClick(Sender: TObject);
procedure ButtonFlatNextChannelClick(Sender: TObject);
procedure ApplicationEventsMessage(var Msg: tagMSG; var Handled: Boolean);
procedure CheckBoxPanelCtrlClick(Sender: TObject);
procedure PanelCtrlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ButtonFlatCloseClick(Sender: TObject);
procedure ButtonFlatMaxClick(Sender: TObject);
procedure ButtonFlatMinClick(Sender: TObject);
procedure TableExChannelsMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure TableExFavChannelsDrawCellData(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
procedure TableExFavChannelsItemClick(Sender: TObject; MouseButton: TMouseButton; const Index: Integer);
procedure ButtonFlatPauseClick(Sender: TObject);
procedure ButtonFlatPlayClick(Sender: TObject);
procedure TableExTvGuideChangeItem(Sender: TObject; const Old: Integer; var New: Integer);
procedure TableExChannelsChangeItem(Sender: TObject; const Old: Integer; var New: Integer);
procedure ButtonFlatTVGuideClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure VlcPlayerClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
protected
procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION;
procedure CreateParams(var Params: TCreateParams); override;
procedure WMNCHitTest(var message: TWMNCHitTest); message WM_NCHITTEST;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
private
FVolume: Integer;
FPlayer: TPasLibVlcPlayer;
FChannels: TChannels;
FFavChannels: TChannels;
FVolumeMD: Boolean;
FVolumeDrawNum: Boolean;
FVolumeMPos: TPoint;
FVolumeMActive: Boolean;
FFullScreen: Boolean;
FOldSize: TRect;
FMute: Boolean;
FCurrentChannel: Integer;
FShowGuide: Boolean;
FCurrentGuide: Integer;
FShowChannels: Boolean;
FGuideList: TChannelGuideItems;
FFormPopup: TFormPopup;
FFreezPos: TPoint;
FSettings: TSettingsIni;
FShowVolume: Boolean;
FIniting: Boolean;
FShowNum: Boolean;
FNum: string;
FShowPanelCtrl: Boolean;
FPlaylistURL: string;
FChannelsMouse: TPoint;
FChannelFavoriteIn: Boolean;
FTvGuideUrl: string;
procedure SetVolume(const Value: Integer);
procedure SetFullScreen(const Value: Boolean);
procedure ShowInfo;
procedure HideInfo;
procedure OpenGuide(Index: Integer);
procedure HideGuide;
procedure ShowGuide;
procedure HideChannels;
procedure ShowChannels;
procedure ShowPopup;
procedure Quit;
procedure Save;
procedure ClosePopup;
procedure ShowCursor(Value: Boolean);
procedure LoadSettings;
procedure SaveSettings;
procedure LoadTVGuide(Url: string);
procedure ShowVolume;
procedure NextChannel;
procedure PrevChannel;
procedure NumPress(Num: Char);
procedure HideNum;
procedure ShowNum;
procedure VolumeDown;
procedure VolumeUp;
procedure SetStayOnTop(Value: Boolean);
procedure SetShowPanelCtrl(Value: Boolean);
procedure LoadM3UPlayList(FileName: string; Dest: TChannels);
procedure LoadPlayListTo(FileName: string);
procedure LoadChannelsInfo;
procedure SaveChannelsInfo;
public
procedure Play(Index: Integer);
procedure SetMute(Value: Boolean);
property Volume: Integer read FVolume write SetVolume;
property FullScreen: Boolean read FFullScreen write SetFullScreen;
property Channels: TChannels read FChannels;
end;
var
FormMain: TFormMain;
function GetMins(Time: TTime): Integer;
implementation
uses
Math, HGM.Common.Utils, Zip, IniFiles, Registry, BigTV.SmartGuide;
{$R *.dfm}
function GetMins(Time: TTime): Integer;
var
H, M, S, MSec: Word;
begin
DecodeTime(Time, H, M, S, MSec);
Result := H * 60 + M;
end;
function GetSeconds(Time: TTime): Integer;
var
H, M, S, MSec: Word;
begin
DecodeTime(Time, H, M, S, MSec);
Result := (H * 60 + M) * 60 + S;
end;
function GetIniFileName: string;
begin
Result := ExtractFilePath(Application.ExeName) + 'config.ini';
end;
procedure TFormMain.ShowCursor(Value: Boolean);
begin
if Value then
VlcPlayer.Cursor := crDefault
else
begin
VlcPlayer.Cursor := crNone;
FFreezPos := Mouse.CursorPos;
end;
end;
procedure TFormMain.WMSize(var Message: TWMSize);
begin
inherited;
Invalidate;
end;
procedure TFormMain.LoadTVGuide(Url: string);
var
HTTP: THTTPClient;
Stream: TMemoryStream;
ZIP: TZipFile;
Ini: TIniFile;
i: Integer;
begin
if not FileExists(GetIniFileName) then
FileClose(FileCreate(GetIniFileName));
if Url.IsEmpty then
Exit;
Ini := TIniFile.Create(GetIniFileName);
if Ini.ReadDateTime('Info', 'LastTvGuideCheck', Now - 2) < Now - 1 / 24 * 12 then
begin
HTTP := THTTPClient.Create;
HTTP.HandleRedirects := True;
Stream := TMemoryStream.Create;
ZIP := TZipFile.Create;
try
HTTP.Get(Url, Stream);
if Stream.Size > 0 then
begin
Stream.SaveToFile(ExtractFilePath(Application.ExeName) + '\TvGuide\tv.zip');
ZIP.ExtractZipFile(ExtractFilePath(Application.ExeName) + '\TvGuide\tv.zip', ExtractFilePath(Application.ExeName) + '\TvGuide\', nil);
end;
finally
HTTP.Free;
Stream.Free;
ZIP.Free;
end;
Ini.WriteDateTime('Info', 'LastTvGuideCheck', Now);
end;
Ini.Free;
for i := 0 to FChannels.Count - 1 do
FChannels[i].LoadGuide(ExtractFilePath(Application.ExeName) + 'TvGuide\');
end;
function ReadTVGuide(FileNames, TVG: string; List: TChannelGuideItems): Boolean;
function ToInteger(Bytes: array of Byte): Integer;
begin
if Length(Bytes) = 2 then
Exit(PWORD(@Bytes[0])^)
else
Exit(PInteger(@Bytes[0])^);
end;
var
ft, bt: TFILETIME;
STime: SYSTEMTIME;
NDX, PDT: file of Byte;
i, BLen: integer;
Text: PAnsiChar;
Str: string;
Buf: array[1..12] of Byte;
Item: TChannelGuideItem;
LDate: TDate;
begin
Result := False;
List.Clear;
AssignFile(NDX, FileNames + TVG + '.ndx');
Reset(NDX);
AssignFile(PDT, FileNames + TVG + '.pdt');
Reset(PDT);
try
Read(NDX, Buf[1], Buf[2]);
for i := 1 to ToInteger([Buf[1], Buf[2]]) do
begin
BlockRead(NDX, Buf, 12);
ft.dwLowDateTime := ToInteger([Buf[3], Buf[4], Buf[5], Buf[6]]);
ft.dwHighDateTime := ToInteger([Buf[7], Buf[8], Buf[9], Buf[10]]);
FileTimeToLocalFileTime(ft, bt);
FileTimeToSystemTime(bt, STime);
Seek(PDT, ToInteger([Buf[11], Buf[12]]));
Read(PDT, Buf[1], Buf[2]);
BLen := ToInteger([Buf[1], Buf[2]]);
GetMem(Text, BLen);
BlockRead(PDT, Text^, BLen);
Str := Text;
SetLength(Str, BLen);
with STime do
begin
//GetTimeZoneInformation() 469
Item.Date := EncodeDate(wYear, wMonth, wDay) + EncodeTime(wHour, wMinute, 0, 0);
if TVG = '469' then
Item.Date := Item.Date - (1 / 24) * 11 //ÑÒÑ Love
else
Item.Date := Item.Date - (1 / 24) * 7;
Item.Text := Str;
List.Add(Item);
if (List.Count = 1) or (Trunc(LDate) <> Trunc(Item.Date)) then
begin
LDate := Item.Date;
Item.Date := 0;
Item.Text := '';
List.Insert(List.Count - 1, Item);
Item.Text := FormatDateTime('dd, mmm, ddd', LDate);
List.Insert(List.Count - 1, Item);
Item.Text := '';
List.Insert(List.Count - 1, Item);
end;
end;
FreeMem(Text);
Result := True;
end;
except
Result := False;
end;
CloseFile(NDX);
CloseFile(PDT);
end;
procedure TFormMain.LoadM3UPlayList(FileName: string; Dest: TChannels);
var
TMPstr: TStrings;
i: integer;
s: string;
Item: TChannel;
Fill: Boolean;
begin
Dest.Clear;
TMPstr := TStringList.Create;
TMPstr.LoadFromFile(FileName, TEncoding.UTF8);
TMPstr.NameValueSeparator := ',';
Fill := False;
FTvGuideUrl := '';
for i := 0 to TMPstr.Count - 1 do
begin
s := TMPstr.Strings[i];
if s = '' then
Continue;
if Pos('#extm3u', AnsiLowerCase(s)) > 0 then
begin
if Pos('url-tvg', AnsiLowerCase(s)) > 0 then
begin
FTvGuideUrl := Copy(s, Pos('"', s) + 1, Length(s) - (Pos('"', s) + 1));
FTvGuideUrl := Copy(FTvGuideUrl, 1, Pos('"', FTvGuideUrl) - 1);
end;
Continue;
end;
if Pos('#extinf', AnsiLowerCase(s)) > 0 then
begin
Item.Name := Trim(TMPstr.ValueFromIndex[i]);
Item.TVGName := Trim(TMPstr.KeyNames[i]);
if Pos('tvg-name', AnsiLowerCase(Item.TVGName)) > 0 then
Item.TVGName := Copy(Item.TVGName, Pos('"', Item.TVGName) + 1, Length(Item.TVGName) - (Pos('"', Item.TVGName) + 1))
else
Item.TVGName := Item.Name;
Fill := True;
Continue;
end;
if (Pos('#', s) = 0) and (Fill) then
begin
Item.URL := s;
Item.Guide := TChannelGuideItems.Create;
Item.Icon := TBitmap.Create;
Item.LoadIcon(ExtractFilePath(FileName) + '\Icons');
Item.Favorite := False;
Dest.Add(Item);
Fill := False;
end;
end;
TMPstr.Free;
end;
procedure TFormMain.LoadPlayListTo(FileName: string);
var HTTP: THTTPClient;
Stream: TMemoryStream;
begin
if not FPlaylistURL.IsEmpty then
begin
HTTP := THTTPClient.Create;
HTTP.HandleRedirects := True;
Stream := TMemoryStream.Create;
try
HTTP.Get(FPlaylistURL, Stream);
if Stream.Size > 0 then
begin
Stream.Position := 0;
Stream.SaveToFile(FileName);
end;
finally
Stream.Free;
HTTP.Free;
end;
end;
end;
procedure TFormMain.LoadChannelsInfo;
var
i: Integer;
Ch: TChannel;
begin
for i := 0 to FChannels.Count - 1 do
begin
if FSettings.GetBool(FChannels[i].TVGName, 'IsFavorite', False) then
begin
Ch := FChannels[i];
Ch.Favorite := True;
FChannels[i] := Ch;
FFavChannels.Add(Ch);
end;
end;
end;
procedure TFormMain.SaveChannelsInfo;
var
i: Integer;
begin
for i := 0 to FChannels.Count - 1 do
begin
FSettings.SetBool(FChannels[i].TVGName, 'IsFavorite', FChannels[i].Favorite);
end;
end;
procedure TFormMain.SetMute(Value: Boolean);
begin
if not Value then
ButtonFlatMute.ImageIndex := 20
else
ButtonFlatMute.ImageIndex := 6;
FMute := Value;
DrawPanelTopRight.Visible := FMute;
DrawPanelTopRight.Repaint;
FPlayer.SetAudioMute(FMute);
end;
procedure TFormMain.SetShowPanelCtrl(Value: Boolean);
begin
PanelCtrl.Visible := Value;
FormResize(nil);
end;
procedure TFormMain.CheckBoxPanelCtrlClick(Sender: TObject);
begin
ClosePopup;
FShowPanelCtrl := CheckBoxPanelCtrl.Checked;
if not FFullScreen then
SetShowPanelCtrl(FShowPanelCtrl);
end;
procedure TFormMain.CheckBoxStayOnTopClick(Sender: TObject);
begin
ClosePopup;
SetStayOnTop(CheckBoxStayOnTop.Checked);
end;
procedure TFormMain.ClosePopup;
begin
if Assigned(FFormPopup) then
FFormPopup.Close;
end;
procedure TFormMain.ApplicationEventsMessage(var Msg: tagMSG; var Handled: Boolean);
begin
if (Msg.Message = WM_SYSCOMMAND) and (Msg.wParam = SC_SCREENSAVE) then
Handled := True;
end;
procedure TFormMain.Button1Click(Sender: TObject);
begin
FPlayer.SetPlayRate(200);
end;
procedure TFormMain.ButtonFlat1Click(Sender: TObject);
begin
ClosePopup;
ShowChannels;
end;
procedure TFormMain.VolumeUp;
begin
Volume := Volume + 2;
end;
procedure TFormMain.VolumeDown;
begin
Volume := Volume - 2;
end;
procedure TFormMain.ButtonFlatPauseClick(Sender: TObject);
begin
FPlayer.Pause;
end;
procedure TFormMain.ButtonFlatPlayClick(Sender: TObject);
begin
FPlayer.Resume;
end;
procedure TFormMain.ButtonFlatPrevChannelClick(Sender: TObject);
begin
PrevChannel;
end;
procedure TFormMain.ButtonFlatVUPClick(Sender: TObject);
begin
VolumeUp;
end;
procedure TFormMain.ButtonFlatVDOWNClick(Sender: TObject);
begin
VolumeDown;
end;
procedure TFormMain.ButtonFlatNextChannelClick(Sender: TObject);
begin
NextChannel;
end;
procedure TFormMain.ButtonFlatCloseChannelsClick(Sender: TObject);
begin
HideChannels;
end;
procedure TFormMain.ButtonFlatCloseClick(Sender: TObject);
begin
Quit;
end;
procedure TFormMain.ButtonFlatCloseGuideClick(Sender: TObject);
begin
HideGuide;
end;
procedure TFormMain.ButtonFlatMaxClick(Sender: TObject);
begin
FullScreen := not FullScreen;
end;
procedure TFormMain.ButtonFlatMinClick(Sender: TObject);
begin
Application.Minimize;
end;
procedure TFormMain.ButtonFlatMuteClick(Sender: TObject);
begin
SetMute(not FMute);
end;
procedure TFormMain.Save;
begin
SaveSettings;
SaveChannelsInfo;
end;
procedure TFormMain.Quit;
begin
Hide;
FPlayer.Stop;
Save;
Application.Terminate;
end;
procedure TFormMain.ButtonFlatQuitClick(Sender: TObject);
begin
ClosePopup;
Quit;
end;
procedure TFormMain.ButtonFlatTVGuideClick(Sender: TObject);
begin
FormGuide.Show;
end;
procedure TFormMain.ButtonFlatVolume100Click(Sender: TObject);
begin
Volume := 100;
end;
procedure TFormMain.ShowInfo;
begin
DrawPanelInfo.Show;
DrawPanelInfo.BringToFront;
DrawPanelLeftTop.Show;
DrawPanelLeftTop.BringToFront;
TimerInfoHide.Interval := 5000;
TimerInfoHide.Enabled := False;
TimerInfoHide.Enabled := True;
end;
procedure TFormMain.HideInfo;
begin
DrawPanelInfo.Hide;
if not FShowNum then
DrawPanelLeftTop.Hide;
TimerInfoHide.Enabled := False;
end;
procedure TFormMain.VlcPlayerClick(Sender: TObject);
begin
VlcPlayer.SetFocus;
end;
procedure TFormMain.VlcPlayerDblClick(Sender: TObject);
begin
FullScreen := not FullScreen;
end;
procedure TFormMain.VlcPlayerMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
SC_DRAGMOVE = $F012;
begin
case Button of
TMouseButton.mbLeft:
if not DrawPanelInfo.Visible then
ShowInfo
else
HideInfo;
end;
if not FFullScreen then
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;
end;
procedure TFormMain.VlcPlayerMouseEnter(Sender: TObject);
begin
if Assigned(FFormPopup) then
if FFormPopup.Visible then
Exit;
VlcPlayer.SetFocus;
end;
procedure TFormMain.VlcPlayerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if FFreezPos.Distance(Mouse.CursorPos) > 5 then
begin
ShowCursor(True);
TimerHideCursor.Enabled := False;
TimerHideCursor.Enabled := True;
end;
if FFullScreen then
if (VlcPlayer.Height - Y) < 3 then
SetShowPanelCtrl(True)
else
SetShowPanelCtrl(False);
end;
procedure TFormMain.ShowPopup;
begin
FFormPopup := TFormPopup.CreatePopup(Self, PanelPopup, nil, Mouse.CursorPos.X, Mouse.CursorPos.Y, []);
end;
procedure TFormMain.VlcPlayerMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
case Button of
TMouseButton.mbRight:
ShowPopup;
TMouseButton.mbMiddle:
SetMute(not FMute);
end;
end;
procedure TFormMain.DrawPanelInfoPaint(Sender: TObject);
var
R: TRect;
S, S2: string;
G1, G2: TChannelGuideItem;
i, t1, t2: Integer;
function GetFontSize(Text: string): Integer;
var
Sz: TSize;
begin
with DrawPanelInfo.Canvas do
begin
Font.Size := 8;
repeat
Font.Size := Font.Size + 1;
Sz := TextExtent(S);
until (Sz.Height > R.Height) or (Sz.Width > R.Width - Round(R.Width * 15 / 100));
Result := Font.Size - 1;
end;
end;
begin
with DrawPanelInfo.Canvas do
begin
Pen.Color := $00202020;
Brush.Color := $00444444;
Rectangle(DrawPanelInfo.ClientRect);
Font.Color := clWhite;
if FShowVolume then
begin
Brush.Style := bsSolid;
Brush.Color := $00363636;
R := DrawPanelInfo.ClientRect;
R.Inflate(-1, -1);
R.Width := Round(R.Width * (FVolume / 100));
FillRect(R);
R := DrawPanelInfo.ClientRect;
R.Inflate(-1, -1);
S := 'Ãðîìêîñòü: ' + IntToStr(FVolume);
Font.Size := GetFontSize(S);
Brush.Style := bsClear;
TextRect(R, S, [tfSingleLine, tfCenter, tfVerticalCenter, tfWordEllipsis]);
Exit;
end;
R := DrawPanelInfo.ClientRect;
R.Inflate(-3, -3);
Brush.Style := bsSolid;
if IndexInList(FCurrentChannel, FChannels.Count) then
i := FChannels[FCurrentChannel].GetNowWatchID
else
i := -1;
if (i <> -1) and IndexInList(i, FChannels[FCurrentChannel].Guide.Count) then
begin
G1 := FChannels[FCurrentChannel].Guide[i];
S := FormatDateTime('HH:nn', G1.Date) + ' ' + G1.Text;
S2 := '';
Font.Size := GetFontSize(S);
if IndexInList(FChannels[FCurrentChannel].GetNowWatchID + 1, FChannels[FCurrentChannel].Guide.Count) then
begin
G2 := FChannels[FCurrentChannel].Guide[FChannels[FCurrentChannel].GetNowWatchID + 1];
t1 := GetSeconds(Now);
S2 := FormatDateTime('HH:nn', G2.Date);
t1 := Round(100 / (GetSeconds(G2.Date) - GetSeconds(G1.Date)) * (t1 - GetSeconds(G1.Date)));
Brush.Style := bsSolid;
Brush.Color := $00363636;
R := DrawPanelInfo.ClientRect;
R.Inflate(-1, -1);
R.Width := Round(R.Width * (t1 / 100));
FillRect(R);
R := DrawPanelInfo.ClientRect;
R.Inflate(-3, -3);
end;
Brush.Style := bsClear;
TextRect(R, S, [tfSingleLine, tfVerticalCenter, tfWordEllipsis]);
TextRect(R, S2, [tfSingleLine, tfRight, tfVerticalCenter]);
end
else
begin
S := 'Íåò èíôîðìàöèè';
Font.Size := GetFontSize(S);
TextRect(R, S, [tfSingleLine, tfVerticalCenter, tfWordEllipsis]);
end;
end;
end;
procedure TFormMain.DrawPanelLeftTopPaint(Sender: TObject);
var
R: TRect;
S: string;
i: Integer;
function GetFontSize(Text: string): Integer;
var
Sz: TSize;
begin
with DrawPanelLeftTop.Canvas do
begin
Font.Size := 8;
repeat
Font.Size := Font.Size + 1;
Sz := TextExtent(S);
until (Sz.Height > R.Height) or (Sz.Width > DrawPanelInfo.Width - Round(DrawPanelInfo.Width * 10 / 100));
Result := Font.Size - 1;
if DrawPanelLeftTop.Width <> Sz.Width then
DrawPanelLeftTop.Width := Sz.Width;
end;
end;
begin
with DrawPanelLeftTop.Canvas do
begin
Pen.Color := $00202020;
Brush.Color := $00444444;
Brush.Style := bsSolid;
Rectangle(DrawPanelLeftTop.ClientRect);
Font.Color := clWhite;
if FShowNum then
begin
R := DrawPanelLeftTop.ClientRect;
R.Inflate(-3, -3);
S := ' ' + FNum + ' ';
if S = '' then
S := ' - ';
Font.Style := [fsUnderline];
Font.Size := GetFontSize(S);
Brush.Style := bsClear;
TextRect(R, S, [tfSingleLine, tfCenter, tfVerticalCenter]);
Exit;
end;
Font.Style := [];
R := DrawPanelLeftTop.ClientRect;
R.Inflate(-3, -3);
Brush.Style := bsClear;
if IndexInList(FCurrentChannel, FChannels.Count) then
begin
S := ' ' + IntToStr(FCurrentChannel + 1) + ' ' + FChannels[FCurrentChannel].Name + ' | ' + FormatDateTime('HH:nn ', Now);
Font.Size := GetFontSize(S);
TextRect(R, S, [tfSingleLine, tfCenter, tfVerticalCenter]);
end
else
begin
S := ' ' + FormatDateTime('HH:nn ', Now);
Font.Size := GetFontSize(S);
TextRect(R, S, [tfSingleLine, tfCenter, tfVerticalCenter]);
end;
end;
end;
procedure TFormMain.DrawPanelTopRightPaint(Sender: TObject);
begin
with DrawPanelTopRight.Canvas do
begin
Pen.Color := $00202020;
Brush.Color := $00444444;
Brush.Style := bsSolid;
Rectangle(DrawPanelTopRight.ClientRect);
if FMute then
begin
ImageList32.Draw(DrawPanelTopRight.Canvas, DrawPanelTopRight.Width div 2 - 16, DrawPanelTopRight.Width div 2 - 16, 0, True);
end;
end;
end;
procedure TFormMain.DrawPanelVolumeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FVolumeMD := True;
FVolumeMPos := Point(X, Y);
if FVolumeMD then
begin
Volume := Max(0, Min(100, Round(100 / DrawPanelVolume.Width * FVolumeMPos.X)));
end;
DrawPanelVolume.Repaint;
end;
procedure TFormMain.DrawPanelVolumeMouseEnter(Sender: TObject);
begin
FVolumeMActive := True;
DrawPanelVolume.SetFocus;
DrawPanelVolume.Repaint;
end;
procedure TFormMain.DrawPanelVolumeMouseLeave(Sender: TObject);
begin
FVolumeMActive := False;
FVolumeDrawNum := False;
DrawPanelVolume.Repaint;
end;
procedure TFormMain.DrawPanelVolumeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
FVolumeMPos := Point(X, Y);
if FVolumeMD then
begin
Volume := Max(0, Min(100, Round(100 / DrawPanelVolume.Width * FVolumeMPos.X)));
end;
DrawPanelVolume.Repaint;
end;
procedure TFormMain.DrawPanelVolumeMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FVolumeMD := False;
DrawPanelVolume.Repaint;
end;
procedure TFormMain.DrawPanelVolumeMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
FVolumeDrawNum := True;
VolumeDown;
Handled := True;
end;
procedure TFormMain.DrawPanelVolumeMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
FVolumeDrawNum := True;
VolumeUp;
Handled := True;
end;
procedure TFormMain.WMNCHitTest(var message: TWMNCHitTest);
const
EDGEDETECT = 7;
var
deltaRect: TRect;
begin
inherited;
if BorderStyle = bsNone then
with message, deltaRect do
begin
Left := XPos - BoundsRect.Left;
Right := BoundsRect.Right - XPos;
Top := YPos - BoundsRect.Top;
Bottom := BoundsRect.Bottom - YPos;
if (Top < EDGEDETECT) and (Left < EDGEDETECT) then
Result := HTTOPLEFT
else if (Top < EDGEDETECT) and (Right < EDGEDETECT) then
Result := HTTOPRIGHT
else if (Bottom < EDGEDETECT) and (Left < EDGEDETECT) then
Result := HTBOTTOMLEFT
else if (Bottom < EDGEDETECT) and (Right < EDGEDETECT) then
Result := HTBOTTOMRIGHT
else if (Top < EDGEDETECT) then
Result := HTTOP
else if (Left < EDGEDETECT) then
Result := HTLEFT
else if (Bottom < EDGEDETECT) then
Result := HTBOTTOM
else if (Right < EDGEDETECT) then
Result := HTRIGHT;
end;
end;
procedure TFormMain.CreateParams(var Params: TCreateParams);
begin
inherited;