-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleAnimeUnit2.pas
More file actions
3983 lines (3505 loc) · 90.6 KB
/
SimpleAnimeUnit2.pas
File metadata and controls
3983 lines (3505 loc) · 90.6 KB
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
{$M 100000000,0,100000000}
{$MODE OBJFPC}{$H+}
{$MODESWITCH ADVANCEDRECORDS}
//{$OPTIMIZATION ON,REGVAR,FASTMATH,LOOPUNROLL,CSE,DFA}
//{$R-,S-,Q-,I-,D-}
unit SimpleAnimeUnit2;
interface
uses math,Windows,Commdlg,SysUtils,Classes,ptc,gl,glu,FPImage,MMSystem,
FPReadJPEG,FPReadPNG,FPReadBMP,FPReadTGA,FPREADGIF,
FPWriteJPEG,FPWritePNG,FPWriteBMP,FPWriteTGA,
CommonTypeUnit;
const
GL_BGRA_EXT=$80e1;
var
Console:IPTCConsole;
Format:IPTCFormat;
Surface:IPTCSurface;
Event:IPTCEvent;
ConsoleHWND:HWND;
FreshLimit:Longint=0;
LastFresh:Int64;
UpdateFPS:Int64;
FPSCount,LastFPS:Longint;
ScrWidth,ScrHeight:Longint;
Type
EList=Specialize List<IPTCEvent>;
//Custom Type
type
shyGifReader=class;
const
oo=$3f3f3f3f;
const
tp_NULL=0;
tp_Line=1;
tp_Sqr=2;
tp_Sqrt=3;
tp_Pow=4;
tp_Sin=5;
tp_ArcSin=6;
tp_ArcTan=7;
tp_Luna=21;
tp_Luna2=22;
tpb_Line=51;
tpb_Sqr=52;
tpb_Sqr2=53;
tpb_Sin=54;
const
atp_normal=0;
atp_loop=1;
const
blend_alpha=1;
blend_lighten=2;
blend_darken=3;
blend_multiply=4;
blend_filter=5;
blend_deep=6;
blend_shallow=7;
blend_over=8;
blend_hard=9;
blend_soft=10;
blend_vivid=11;
type
Color=record b,g,r,a:byte end;
pColor=^Color;
FColor=record
case integer of
0:(c:Color);
1:(x:Longint);
2:(s:array[0..3]of char)
end;
function RGBA(_r,_g,_b,_a:byte):Color;
operator =(const a,b:Color)c:Boolean;
function Color_ALW(const a,b:Color):Longint;
function Color_Blend(const a,b:Color;BlendTp:Shortint):Color;
function tp_Count(const x:real;_tp:shortint):real;
const
Color_Alpha :Color=(b:0;g:0;r:0;a:0);
Color_Black :Color=(b:0;g:0;r:0;a:255);
Color_Red :Color=(b:0;g:0;r:255;a:255);
Color_Green :Color=(b:0;g:255;r:0;a:255);
Color_Blue :Color=(b:255;g:0;r:0;a:255);
Color_White :Color=(b:255;g:255;r:255;a:255);
Color_Gray :Color=(b:128;g:128;r:128;a:255);
Color_Yellow :Color=(b:0;g:255;r:255;a:255);
Color_Cyan :Color=(b:255;g:255;r:0;a:255);
Color_Purple :Color=(b:255;g:0;r:255;a:255);
Color_LYellow:Color=(b:128;g:255;r:255;a:255);
Color_LGreen :Color=(b:128;g:255;r:0;a:255);
Color_LRed :Color=(b:44;g:44;r:250;a:255);
Color_LBlue :Color=(b:255;g:128;r:0;a:255);
Color_LPurple:Color=(b:255;g:128;r:128;a:255);
Color_Pink :Color=(b:192;g:128;r:255;a:255);
Color_LGray :Color=(b:192;g:192;r:192;a:255);
Color_Forest :Color=(b:0;g:128;r:0;a:255);
Color_Tea :Color=(b:0;g:128;r:128;a:255);
Color_CRed :Color=(b:128;g:0;r:255;a:255);
Color_CGreen :Color=(b:128;g:255;r:128;a:255);
Color_CBlue :Color=(b:255;g:255;r:128;a:255);
const
cp_non=0;
cp_jpg=1;
cp_png=2;
cp_RLC=3;
const
rev_Horizontal=1;
rev_Vertical=2;
type
pBaseGraph=^BaseGraph;
pBaseAnime=^BaseAnime;
pGraph=^Graph;
pTextGraph=^TextGraph;
pGroupGraph=^GroupGraph;
pSimpleAnime=^SimpleAnime;
pTimeLineAnime=^TimeLineAnime;
pAnimeObj=^AnimeObj;
pAnimeTag=^AnimeTag;
pAnimeLog=^AnimeLog;
pElement=^Element;
pSAMACEvent=^SAMACEvent;
BaseGraph=Object
Width,Height:Longint;
Constructor Create;
Destructor Free;Virtual;Abstract;
Function Reproduce:pBaseGraph;Virtual;Abstract;
Function Recovery(Env:pSAMACEvent;Obj:pElement;Below:pGraph):pGraph;Virtual;Abstract;
end;
Graph=packed object(BaseGraph)
Canvas:pColor;
Constructor Create;
Constructor Create(_h,_w:longint);
Constructor Create(const g:TFPMemoryImage);
Constructor CreateText(const s:ansistring;fontsize:longint;const c:Color);
destructor Free;Virtual;
function toFPImage:TFPMemoryImage;
procedure LoadTGA(const path:ansistring);
procedure LoadBMP(const path:ansistring);
procedure LoadPNG(const path:ansistring);
procedure LoadJPG(const path:ansistring);
procedure LoadGIF(const path:ansistring);
procedure LoadSAG(const path:ansistring);
procedure Load(const path:ansistring);
procedure LoadTGA(data:TMemoryStream);
procedure LoadBMP(data:TMemoryStream);
procedure LoadPNG(data:TMemoryStream);
procedure LoadJPG(data:TMemoryStream);
procedure LoadGIF(data:TMemoryStream);
procedure LoadSAG(data:TMemoryStream);
procedure Load(data:TMemoryStream);
procedure SaveTGA(const path:ansistring);
procedure SaveBMP(const path:ansistring);
procedure SavePNG(const path:ansistring);
procedure SaveJPG(const path:ansistring);
function Bits:longint;
function getp(x,y:longint):Color;
procedure setp(x,y:longint;const c:Color);
procedure fill(x1,y1,x2,y2:longint;const c:Color);
procedure filla(x1,y1,x2,y2:longint;const c:Color);
procedure resize(newH,newW:Longint);
procedure reverse(_rv:Longint);
function cut(x1,y1,x2,y2:longint):Graph;
function cut:Graph;
Function Adapt(limitH,limitW:Longint):Graph;
Function Scale(limitH,limitW:Longint):Graph;
Function Scale2(LimitH,LimitW:Longint):Graph;
function LinearMapped(x1,y1,x2,y2,x3,y3,x4,y4:real):Graph;
function ColorBlend(const G:Graph;x,y:longint;blendtp:shortint):Graph;
procedure AddText(const s:ansistring;fontsize:longint;const c:Color;_x,_y:longint);
procedure Change(const csrc,cdst:Color);
procedure Change(const csrc,cdst:Color;Aw:Longint);
procedure ChangeNear(x,y:Longint;const cdst:Color);
procedure ChangeNear(x,y:Longint;const cdst:Color;Aw:Longint);
function inGraph(x,y:Longint):Boolean;
property Items[i,j:Longint]:Color read getp write setp;default;
Function Reproduce:pBaseGraph;Virtual;
Function Recovery(Env:pSAMACEvent;Obj:pElement;Below:pGraph):pGraph;Virtual;
end;
CompressGraph=packed object(BaseGraph)
CompressType:Shortint;
CompressStream:TStream;
Constructor Create;
Constructor Compress(Const A:Graph;_cp:Longint);
Destructor Free;Virtual;
function DeCompress:Graph;
function cut:CompressGraph;
Function Reproduce:pBaseGraph;Virtual;
Function Recovery(Env:pSAMACEvent;Obj:pElement;Below:pGraph):pGraph;Virtual;
end;
GroupGraph=packed object(BaseGraph)
Pic:Specialize List<pGraph>;
Res:Specialize List<Int64>;
Constructor Create;
Destructor Free;Virtual;
procedure LoadGif(const path:ansistring);
procedure LoadSAG(const path:ansistring);
procedure AddPic(const a:Graph);
procedure AddPic(const a:Graph;const b:Int64);
procedure Split(const a:Graph;n,m,sz:Longint);
procedure Operate(const c:Color);
procedure Operate;
function Size:Longint;
function TotTime:Int64;
procedure SetSpTime(const _t:Int64);
Function GetFrame(const Time:Int64):Graph;
function cut:GroupGraph;
Function Reproduce:pBaseGraph;Virtual;
Function Recovery(Env:pSAMACEvent;Obj:pElement;Below:pGraph):pGraph;Virtual;
end;
shyGifReader=class(TFPReaderGif)
public
function ReadFromStream(Stream:TStream):GroupGraph;
function ReadFromFile(const FileName:Ansistring):GroupGraph;
constructor Create;override;
destructor Destroy;override;
end;
TextGraph=Packed Object(BaseGraph)
Text,FontType:Ansistring;
FontSize:Longint;
FontAngle:Single;
FontColor,FontBackColor:Color;
Bold,Italic,UnderLine,StrikeOut:Boolean;
CharSet:DWord; //EASTEUROPE_CHARSET GB2312_CHARSET SHIFTJIS_CHARSET RUSSIAN_CHARSET
Constructor Create;
Constructor Create(Const Str:Ansistring);
Destructor Free;Virtual;
Procedure WriteTo(var A:Graph;_x,_y:Longint);
Procedure SetText(Const Str:Ansistring);
Procedure SetSize(_s:Longint);
Procedure SetType(Const tp:Ansistring);
Procedure Update;
Function Cut:TextGraph;
Function Reproduce:pBaseGraph;Virtual;
Function Recovery(Env:pSAMACEvent;Obj:pElement;Below:pGraph):pGraph;Virtual;
End;
BaseAnime=Object
AnimeType:ShortInt;
StdTime,TotTime:Int64;
Constructor Create;
Destructor Free;Virtual;Abstract;
procedure SetType(_atp:shortint);Virtual;
Procedure SetTime(Const _t:Int64);Virtual;
procedure Start;Virtual;
procedure Start(const _t:Int64);Virtual;
Function AnimeEnd:Boolean;Virtual;Abstract;
Function Apply(obj:pAnimeObj):Shortint;Virtual;Abstract;
Function Reproduce:pBaseAnime;Virtual;Abstract;
End;
AnimeTag=Packed Object
Enable:Boolean;
Source:pBaseAnime;
Constructor Create;
Constructor Create(Const a:BaseAnime);
Destructor Free;Virtual;
Procedure On;Virtual;
Procedure Off;Virtual;
Function StdTime:int64;
Function TotTime:Int64;
Function AnimeType:ShortInt;
Function Cut:AnimeTag;
Function AnimeEnd:Boolean;
Function Apply(obj:pAnimeObj):ShortInt;
End;
SimpleAnime=packed object(BaseAnime)
Reserve:Longint;
an_BiasX,an_BiasY,
an_ClipX1,an_ClipY1,an_ClipX2,an_ClipY2,
an_Rotate,an_Alpha,an_ScaleX,an_ScaleY:single;
tp_BiasX,tp_BiasY,
tp_ClipX1,tp_ClipY1,tp_ClipX2,tp_ClipY2,
tp_Rotate,tp_Alpha,tp_ScaleX,tp_ScaleY:shortint;
Constructor Create;
Destructor Free;Virtual;
procedure SetXY(_x,_y:single;_tp:shortint);
procedure SetClip(_x1,_y1,_x2,_y2:single;_tp:shortint);
procedure SetRotate(_r:single;_tp:shortint);
procedure SetAlpha(_a:single;_tp:shortint);
procedure SetScale(_s:single;_tp:shortint);
procedure SetXY(_x,_y:single);
procedure SetClip(_x1,_y1,_x2,_y2:single);
procedure SetRotate(_r:single);
procedure SetAlpha(_a:single);
procedure SetScale(_s:single);
Function AnimeEnd:Boolean;Virtual;
Function Apply(obj:pAnimeObj):Shortint;Virtual;
Function Reproduce:pBaseAnime;Virtual;
end;
AnimeObj=packed object
Visible:boolean;
Reverse:Longint;
BiasX,BiasY,ClipX1,ClipY1,ClipX2,ClipY2:Single;
Rotate,Alpha,ScaleX,ScaleY:single;
Source:pBaseGraph;
Constructor Create;
Constructor Create(const a:BaseGraph);
Constructor CreateLink(Const a:BaseGraph);
Destructor Free;
Function Width:Longint;
Function Height:Longint;
procedure SetXY(_x,_y:longint);
procedure SetClip(_x1,_y1,_x2,_y2:longint);
procedure SetRotate(_r:single);
procedure SetAlpha(_a:single);
procedure SetScale(_s:single);
procedure SetReverse(_rv:Longint);
procedure SetSource(const src:BaseGraph);
procedure SetParam(_x,_y:longint;_r,_a,_s:single);
procedure SetParam(_x,_y,_x1,_y1,_x2,_y2:longint;_r,_a,_s:single);
function Inner(x,y:longint):boolean;
Function Cut:AnimeObj;
end;
TLAnimeObj=Packed Record
BiasX,BiasY,ClipX1,ClipY1,ClipX2,ClipY2,Rotate,Alpha,ScaleX,ScaleY:single;
tp_BiasX,tp_BiasY,tp_ClipX1,tp_ClipY1,tp_ClipX2,tp_ClipY2,tp_Rotate,tp_Alpha,tp_ScaleX,tp_ScaleY:ShortInt;
Time:Int64;
Class Operator <(Const a,b:TLAnimeObj)c:Boolean;
Class Operator >(Const a,b:TLAnimeObj)c:Boolean;
Class Operator =(Const a,b:TLAnimeObj)c:Boolean;
Class Operator <=(Const a,b:TLAnimeObj)c:Boolean;
Class Operator >=(Const a,b:TLAnimeObj)c:Boolean;
Procedure Create;
Procedure SetTime(Const _t:Int64);
Procedure SetBiasX(Const _v:Single;_tp:ShortInt);
Procedure SetBiasY(Const _v:Single;_tp:ShortInt);
Procedure SetClipX1(Const _v:Single;_tp:ShortInt);
Procedure SetClipY1(Const _v:Single;_tp:ShortInt);
Procedure SetClipX2(Const _v:Single;_tp:ShortInt);
Procedure SetClipY2(Const _v:Single;_tp:ShortInt);
Procedure SetRotate(Const _v:Single;_tp:ShortInt);
Procedure SetAlpha (Const _v:Single;_tp:ShortInt);
Procedure SetScaleX(Const _v:Single;_tp:ShortInt);
Procedure SetScaleY(Const _v:Single;_tp:ShortInt);
End;
TimeLineAnime=Packed Object(BaseAnime)
TimeLine:Specialize Treap<TLAnimeObj>;
Constructor Create;
Destructor Free;Virtual;
Procedure SetFrame(Const _tl:TLAnimeObj);
Procedure SetFrame(Const _t:Int64;Const _tl:AnimeObj);
Function AnimeEnd:Boolean;Virtual;
Function Apply(obj:pAnimeObj):Shortint;Virtual;
Function Reproduce:pBaseAnime;Virtual;
End;
SAMouseEvent=Packed Record x,y,button:Longint; press,release:Boolean End;
SAKeyEvent=Packed Record key:Longint; press,release,alt,shift,ctrl:Boolean End;
SAMACEvent=Packed Record
MouseAccept,KeyAccept,MouseDown:Boolean;
MouseX,MouseY,MouseClickX,MouseClickY:Longint;
MouseClickT:Int64;
End;
MouseProc=procedure(Env:pSAMACEvent;Obj:pElement;Below:pGraph;Const E:SAMouseEvent;inner:ShortInt);
KeyProc=procedure(Env:pSAMACEvent;Obj:pElement;Below:pGraph;Const E:SAKeyEvent);
NonProc=procedure(Env:pSAMACEvent;Obj:pElement;Below:pGraph);
AnimeLog=packed object
Enable:Boolean;
LastInner:shortint;
MouseEvent:MouseProc;
KeyEvent:KeyProc;
NonEvent:NonProc;
Constructor Create;
procedure DealMouse(Env:pSAMACEvent;Obj:pElement;Below:pGraph;Const E:SAMouseEvent);
procedure DealKey(Env:pSAMACEvent;Obj:pElement;Below:pGraph;Const E:SAKeyEvent);
procedure DealNon(Env:pSAMACEvent;Obj:pElement;Below:pGraph);
end;
Element=Object
Role:AnimeObj;
Acts:AnimeTag;
Talk:AnimeLog;
Constructor Create;
Constructor Create(const A:AnimeObj);
Constructor Create(const A:AnimeObj;const B:AnimeTag;const C:AnimeLog);
Function Width:Longint;
Function Height:Longint;
Function Reproduce:pElement;Virtual;
Destructor Free;Virtual;
end;
Stage=object
Member:Specialize List<pElement>;
StageMAC:SAMACEvent;
StageBiasX,StageBiasY:Single;
constructor Create;
destructor Free;
Destructor FreeData;
function Size:longint;
function AddObj(const _role:Element):Longint;
function AddObj(const _role:AnimeObj):longint;
function AddObj(const _role:BaseGraph):Longint;
function LinkObj(const _role:Element):Longint;
//function LinkObj(const _role:AnimeObj):longint;
function LinkObj(const _role:BaseGraph):Longint;
function AnimeEnd(id:longint):boolean;
function AnimeAllEnd:boolean;
function IsInner(id,x,y:longint):boolean;
function Get(id:longint):pAnimeObj;
procedure ReplaceObj(id:longint;const _role:AnimeObj);
procedure DeleteObj(id:longint);
Procedure AttachAnime(Id:Longint;Const _act:BaseAnime);
procedure AttachAnime(id:longint;const _act:AnimeTag);
procedure AttachLogic(id:longint;const _log:AnimeLog);
Procedure AnimeBegin(id:Longint);
Procedure AnimeAllBegin;
procedure StopAnime(id:longint);
procedure DisplayObj(id:longint;Var Below:Graph);
procedure DisplayBlendObj(id:longint;tp:shortint;Var Below:Graph);
procedure Display(Var Below:Graph);
procedure DisplayBlend(tp:shortint;Var Below:Graph);
procedure DisplayObj(id:longint);
procedure DisplayBlendObj(id:longint;tp:shortint);
procedure Display;
procedure DisplayBlend(tp:shortint);
Procedure DisplayDirectObj(id:Longint;Var Below:Graph);
Procedure DisplayDirect(Var Below:Graph);
Procedure DisplayDirect;
procedure Communication;
Procedure Communication(Const L:EList);
procedure Communication(Below:pGraph);
procedure Communication(Below:pGraph;Const L:EList);
end;
var
Screen:Graph;
function NULLGraph:Graph;
function NULLAnimeObj:AnimeObj;
function NULLAnimeTag:AnimeTag;
function NULLAnimeLog:AnimeLog;
function NowFPS:Longint;
procedure Lock;
procedure UnLock;
procedure OpenGLScreenShot(var Scr:Graph);
procedure ScreenClear;
procedure ScreenClear(const c:Color);
procedure DrawTo(const pen:Graph;var goal:Graph;x,y:longint);
procedure BlendTo(const pen:Graph;var goal:Graph;x,y:longint);
procedure PureBlendColor(var a:Color;const b:Color);
procedure Opt_Mask(var g:Graph;_x1,_y1,_x2,_y2:Single);
procedure Opt_Scale(var g:Graph;x,y:single);
procedure Opt_Alpha(var g:Graph;a:single);
procedure Opt_Rotate(var g:Graph;r:single);
var
ProgramStart:int64;
MusicId:longint;
const
sf_Open=True;
sf_Save=False;
var
Main:Stage;
MAC:SAMACEvent;
function DeltaTime:Int64;
Function RootDirectory:Ansistring;
function GetFile(const regex:ansistring):SList;
Function SelectFile(Open:Boolean):Ansistring;
Function SelectFile(const Entry:SList;Open:Boolean):Ansistring;
Function SelectFile(const Entry:SList;Ext:Pchar;Open:Boolean):Ansistring;
Procedure ExeFile(Const S:Ansistring);
Procedure OpenFile(Const S:Ansistring);
function BeginThread(p:TProcedure):Dword;
procedure EndThread(tid:Dword);
function OpenMusic(const path:ansistring):longint;
procedure PlayMusicRepeat(mid:longint);
procedure PlayMusic(mid:longint);
procedure PlayMusicAt(mid,nowSchedule:Longint);
procedure PauseMusic(mid:longint);
procedure ResumeMusic(mid:longint);
procedure StopMusic(mid:longint);
Function ConsoleUsing:Boolean;
Function GetMouse(var x,y,button:longint):Boolean;
Function GetKey(var key:longint):Boolean;
Function GetMouse(Var E:SAMouseEvent):Boolean;
Function GetKey(Var E:SAKeyEvent):Boolean;
Function GetKeyPress:Boolean;
Function TestMouse(var x,y,button:longint):Boolean;
Function TestKey(var key:longint):Boolean;
Function TestMouse(Var E:SAMouseEvent):Boolean;
Function TestKey(Var E:SAKeyEvent):Boolean;
Function TestKeyPress:Boolean;
Function GetClose:Boolean;
Function GetClose(Const LimT:Int64):Boolean;
Function GetEvent:EList;
procedure ImageToSAGFormat(const g:Graph;const path:AnsiString);
procedure ImagesToSAGFormat(const gs:GroupGraph;const path:AnsiString);
procedure Init(const title:string;Width,Height:longint);
procedure Endit;
Procedure SetTitle(Const title:String);
Procedure SetPosition(X,Y:Longint);
implementation
procedure sw(var a,b:real);
var c:real; begin c:=a; a:=b; b:=c end;
procedure sw(var a,b:Longint);
var c:Longint; begin c:=a; a:=b; b:=c end;
procedure sw(var a,b:Color);
var c:Color; begin c:=a; a:=b; b:=c end;
operator =(const a,b:Color)c:Boolean;
begin exit((a.r=b.r)and(a.g=b.g)and(a.b=b.b)and(a.a=b.a)) end;
Operator =(Const a,b:Graph)c:Boolean;
Begin Exit((a.Width=b.Width)And(a.Height=b.Height)And(a.Canvas=b.Canvas)) End;
//CustomObject-shyGifReader-Begin
function shyGifReader.ReadFromStream(Stream:TStream):GroupGraph;
var
Introducer:byte;
ColorTableSize :Integer;
ContProgress: Boolean;
Img:TFPMemoryImage;
a,atmp:Graph;
DelayS:Int64=0;
begin
result.Create;
a.Create;
atmp.Create;
FPalette:=nil;
FScanLine:=nil;
try
ContProgress:=true;
Progress(psStarting, 0, False, Rect(0,0,0,0), '', ContProgress);
if not ContProgress then exit;
FPalette := TFPPalette.Create(0);
Stream.Position:=0;
// header
Stream.Read(FHeader,SizeOf(FHeader));
Progress(psRunning, trunc(100.0 * (Stream.position / Stream.size)), False, Rect(0,0,0,0), '', ContProgress);
if not ContProgress then exit;
// Endian Fix Mantis 8541. Gif is always little endian
{$IFDEF ENDIAN_BIG}
with FHeader do
begin
ScreenWidth := LEtoN(ScreenWidth);
ScreenHeight := LEtoN(ScreenHeight);
end;
{$ENDIF}
// global palette
if (FHeader.Packedbit and $80) <> 0 then
begin
ColorTableSize := FHeader.Packedbit and 7 + 1;
ReadPalette(stream, 1 shl ColorTableSize);
end;
a.Create(FHeader.ScreenHeight,FHeader.ScreenWidth);
a.Fill(1,1,a.Height,a.Width,Color_Black);
Repeat
// skip extensions
Repeat
Introducer:=SkipBlock(Stream);
until (Introducer = $2C) or (Introducer = $3B);
// descriptor
Stream.Read(FDescriptor, SizeOf(FDescriptor));
{$IFDEF ENDIAN_BIG}
with FDescriptor do
begin
Left := LEtoN(Left);
Top := LEtoN(Top);
Width := LEtoN(Width);
Height := LEtoN(Height);
end;
{$ENDIF}
// local palette
if (FDescriptor.Packedbit and $80) <> 0 then
begin
ColorTableSize := FDescriptor.Packedbit and 7 + 1;
ReadPalette(stream, 1 shl ColorTableSize);
end;
// parse header
if not AnalyzeHeader then exit;
// create image
Img:=TFPMemoryImage.Create(0,0);
if Assigned(OnCreateImage) then
OnCreateImage(Self,Img);
Img.SetSize(FWidth,FHeight);
// read pixels
if not ReadScanLine(Stream) then exit;
if not WriteScanLine(Img) then exit;
atmp.Create(Img);
BlendTo(atmp,a,FDescriptor.Top,FDescriptor.Left);
inc(DelayS,GraphicsCtrlExt.DelayTime);
Result.AddPic(a,DelayS*10);
ReAllocMem(FScanLine,0);
Img.Free;
Until Stream.Position>=Stream.Size-1;
finally
FreeAndNil(FPalette)
end;
a.Free;
atmp.Free;
Progress(FPimage.psEnding, 100, false, Rect(0,0,FWidth,FHeight), '', ContProgress);
end;
Function shyGifReader.ReadFromFile(const FileName:Ansistring):GroupGraph;
var
fs:TStream;
begin
result.Create;
if not FileExists(FileName) then exit;
fs:=TFileStream.Create(FIleName,fmOpenRead);
result:=ReadFromStream(Fs);
FreeAndNil(Fs)
end;
constructor shyGifReader.Create;
begin inherited Create end;
destructor shyGifReader.Destroy;
begin inherited Destroy end;
//CustomObject-shyGifReader-End
function DeltaTime:Int64;
begin
exit(GetTickCount64-ProgramStart)
end;
function RGBA(_r,_g,_b,_a:byte):Color;
begin
with RGBA do
begin
r:=_r;
g:=_g;
b:=_b;
a:=_a
end
end;
function Color_ALW(const a,b:Color):Longint;
var u,v,w:Longint;
begin
u:=a.R-b.R;
v:=a.G-b.G;
w:=a.B-b.B;
if u<v then sw(u,v);
if u<w then sw(u,w);
if v<w then sw(v,w);
if w>=0 then exit(u);
if u<=0 then exit(-w);
exit(u-w)
end;
function GetFile(const regex:ansistring):SList;
var
i:TSearchRec;
begin
GetFile.Clear;
if FindFirst(regex,faAnyFile,i)=0 then
repeat
GetFile.pushback(i.Name)
until FindNext(i)<>0;
FindClose(i)
end;
function BeginThread(p:TProcedure):Dword;
var tid:dword;
begin
CreateThread(nil,0,p,nil,0,tid);
end;
procedure EndThread(tid:Dword);
begin
TerminateThread(tid,0);
CloseHandle(tid)
end;
Function SelectFile(Open:Boolean):Ansistring;
Var Temp:SList;
Begin
Temp.Clear;
Temp.Pushback('All files (*.*)'#0'*.*'#0);
Result:=SelectFile(Temp,#0,Open);
Temp.Clear;
End;
Function SelectFile(const Entry:SList;Open:Boolean):Ansistring;
Begin
Exit(SelectFile(Entry,#0,Open))
End;
Function SelectFile(const Entry:SList;Ext:Pchar;Open:Boolean):Ansistring;
Var
NameRec:OpenFileName;
Filter:Ansistring='';
FName:Array[0..255]of Char;
i:Longint;
Begin
FillChar(NameRec,Sizeof(NameRec),0);
FName[0]:=#0;
For i:=1 to Entry.Size Do
Filter:=Filter+Entry.Items[i];
Filter:=Filter+#0;
With NameRec Do
Begin
LStructSize:=SizeOf(NameRec);
HWndOwner:=ConsoleHwnd;
LpStrFilter:=PChar(Filter);
LpStrFile:=@FName;
NMaxFile:=255;
Flags:=OFN_Explorer Or OFN_HideReadOnly;
If Open Then Flags:=Flags Or OFN_FileMustExist;
LpStrDefExt:=Ext
End;
If Open Then GetOpenFileName(@NameRec)
Else GetSaveFileName(@NameRec);
Result:=Ansistring(FName)
End;
Procedure ExeFile(Const S:Ansistring);
Begin
WinExec(Pchar(S),SW_SHOW)
End;
Function RootDirectory:Ansistring;
Var
Tmp:Array[0..500]of char;
Begin
GetCurrentDirectory(500,Tmp);
Exit(Ansistring(Tmp))
End;
Procedure OpenFile(Const S:Ansistring);
Var
Path:Ansistring;
PathFlag:Boolean=True;
i:Longint;
Begin
Path:=S;
For i:=Length(Path)Downto 1 Do
if (Path[i]='/')Or(Path[i]='\') Then
Begin
Delete(Path,i,Length(Path));
PathFlag:=False;
Break
End;
If PathFlag Then Path:=RootDirectory;
ShellExecute(0,'open',Pchar(S),nil,Pchar(Path),SW_SHOW)
End;
function OpenMusic(const path:ansistring):longint;
var MStr:ansistring;
begin
inc(MusicId);
str(MusicId,MStr);
mciSendString(pchar('open '+path+' alias '+MStr),nil,0,0);
exit(MusicId)
end;
procedure PlayMusicRepeat(mid:longint);
var MStr:ansistring;
begin
Str(mid,MStr);
mciSendString(pchar('play '+Mstr+' repeat'),nil,0,0);
end;
procedure PlayMusic(mid:longint);
var MStr:ansistring;
begin
Str(mid,MStr);
mciSendString(pchar('play '+MStr),nil,0,0)
end;
procedure PlayMusicAt(mid,nowSchedule:Longint);
var MStr,VStr:ansistring;
begin
Str(mid,MStr);
Str(nowSchedule,VStr);
mciSendString(pchar('play '+MStr+' from '+VStr),nil,0,0)
end;
procedure PauseMusic(mid:longint);
var MStr:ansistring;
begin
Str(mid,MStr);
mciSendString(pchar('pause '+MStr),nil,0,0)
end;
procedure ResumeMusic(mid:longint);
var MStr:ansistring;
begin
Str(mid,MStr);
mciSendString(pchar('resume '+MStr),nil,0,0)
end;
procedure StopMusic(mid:longint);
var MStr:ansistring;
begin
Str(mid,MStr);
mciSendString(pchar('stop '+MStr),nil,0,0)
end;
Function GetMouseCode(B:TPTCMouseButton):Longint;
Begin
if B=PTCMouseButton1 then Exit(1); //Left Mouse
if B=PTCMouseButton2 then Exit(2); //Right Mouse
if B=PTCMouseButton3 then Exit(4); //Middle Mouse
if B=PTCMouseButton4 then Exit(8); //Scroll Up
if B=PTCMouseButton5 then Exit(16); //Scroll Down
Exit(0)
End;
Function GetMouseCode(Const S:TPTCMouseButtonState):Longint;
Var I:TPTCMouseButton;
Begin
Result:=0;
For i in S Do Result:=Result Or GetMouseCode(i)
End;
Function ConsoleUsing:Boolean;
Begin
If (Not Assigned(Console))Or(Console=Nil) Then Exit(False);
if Console.PeekEvent(False,[PTCCloseEvent])is IPTCCloseEvent then
Begin EndIt; Exit(False) End;
Exit(True)
End;
Function NULLSAMACEvent:SAMACEvent;
Begin
With Result Do Begin
MouseAccept:=False;
KeyAccept:=False;
MouseDown:=False;
MouseX:=-1;
MouseY:=-1;
MouseClickX:=-1;
MouseClickY:=-1;
MouseClickT:=-1;
End
End;
Function GetMouse(Var MAC:SAMACEvent;Var x,y,button:Longint):Boolean;
Var
TmpB:IPTCMouseButtonEvent;
tmpM:IPTCMouseEvent;
Begin
With MAC Do Begin
X:=0; Y:=0; Button:=0;
If Not ConsoleUsing Then Exit(False);
Console.NextEvent(Event,True,[PTCMouseEvent,PTCCloseEvent]);
If Supports(Event,IPTCCloseEvent) Then Begin Endit; Exit(False) End;
If Supports(Event,IPTCMouseEvent) Then
Begin
If Supports(Event,IPTCMouseButtonEvent) Then
Begin
tmpB:=Event as IPTCMouseButtonEvent;
x:=tmpB.Y;
y:=tmpB.X;
button:=GetMouseCode(tmpB.button);
If tmpB.Press Then Begin MouseDown:=True; MouseClickX:=x; MouseClickY:=y; MouseClickT:=DeltaTime End;
If tmpB.Release Then Begin MouseDown:=False; MouseClickX:=-1; MouseClickY:=-1; MouseClickT:=-1 End;
MouseX:=x;
MouseY:=y
End
Else
Begin
tmpM:=Event as IPTCMouseEvent;
x:=tmpM.Y;
y:=tmpM.X;
button:=GetMouseCode(tmpM.ButtonState);
MouseX:=x;
MouseY:=y;
End
End;
Exit(True)
End
End;
Function GetMouse(Var x,y,button:Longint):Boolean;
Begin Exit(GetMouse(MAC,x,y,button)) End;
Function TestMouse(Var MAC:SAMACEvent;Var x,y,button:Longint):Boolean;
Var
TmpB:IPTCMouseButtonEvent;
tmpM:IPTCMouseEvent;
Begin
WIth MAC Do Begin
X:=0; Y:=0; Button:=0;
If Not ConsoleUsing Then Exit(False);
Console.NextEvent(Event,False,[PTCMouseEvent,PTCCloseEvent]);
If Supports(Event,IPTCCloseEvent) Then Begin Endit; Exit(False) End;
If Supports(Event,IPTCMouseEvent) Then