-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCM_Main.pas
1086 lines (1040 loc) · 44.3 KB
/
CCM_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 CCM_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DIB, MMSystem, clipbrd, Menus;
type
TTWTW = class(TForm)
Memo1: TMemo;
Button1: TButton;
pbp: TPanel;
pbx: TPaintBox;
IndexEdit: TEdit;
IndexList: TListBox;
NextPageTimer: TTimer;
Edit1: TEdit;
CancelButton: TButton;
ScrollBox: TScrollBox;
ImageScrolled: TImage;
PopupMenu1: TPopupMenu;
MenuSauveAnim: TMenuItem;
N1: TMenuItem;
MenuAPropos: TMenuItem;
MenuRestart: TMenuItem;
MenuRandomPage: TMenuItem;
ExportTimer: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure pbxPaint(Sender: TObject);
procedure pbxMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure pbxMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure IndexListDblClick(Sender: TObject);
procedure NextPageTimerTimer(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
procedure MenuSauveAnimClick(Sender: TObject);
procedure MenuAProposClick(Sender: TObject);
procedure MenuRestartClick(Sender: TObject);
procedure MenuRandomPageClick(Sender: TObject);
procedure ExportTimerTimer(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
TWTW: TTWTW;
implementation
uses CCM_Png, CCM_Ani, CCM_Zip, GIFImage;
type TLINK=record
linktype:smallint;
x1,y1,x2,y2:smallint;
fx1,fy1,fx2,fy2:smallint;
xoffset,yoffset:smallint;
cursor:IDPOINTER;
numactions:smallint;
actions:array[0..1] of TACTION;
anim:string;
anim_skip:IDPOINTER;
sound:string;
letter:smallint;
end;
type TDISPLAY=record
actualPage:IDPOINTER;
links:array[0..100] of TLINK;
numlinks:smallint;
actualItems:array[0..100] of TITEM;
actualNumitems:word;
actualBasedir:string;
xoff,yoff:smallint;
actualrelated_principles_popup:IDPOINTER;
actualmachines_page:IDPOINTER;
actualinventors_page:IDPOINTER;
actualtimeline_page:IDPOINTER;
x1,y1,x2,y2:smallint;
PageImage:TBitmap;
end;
type TEXPORT=record
pageexported,fullexported:boolean;
itemexported:array[0..100] of boolean;
end;
var nextpage_ani:IDPOINTER;
nextpage_load:IDPOINTER;
actualletter:smallint;
BufferImage:TBitmap;
actualPages:array[0..7] of TDISPLAY; // 0 = main frame, 1 to 7 = popups
actualPageLevel,predPageLevel:smallint; // Niveaux de pages
history:array[0..1000] of IDPOINTER; // Historique
numhistory:smallint;
debug,exportres,exportjs:boolean;
nextexportpage,nextexportitem:word;
exportstatus:array[0..2000] of TEXPORT;
jsexport,jstotal:string;
{$R *.dfm}
function revertandaddslashes(str:string;forceFirstSlash:boolean):string;
var i:word;
begin
i:=length(str);
while i > 0 do begin
if (str[i] = '\') then begin
str[i]:='/';
end;
if (str[i] = '''') or (str[i] = '"') then begin
insert('\',str,i);
end;
dec(i);
end;
if (forceFirstSlash) and (str[1] <> '/') then str:='/'+str;
result:=str;
end;
function replaceExt(filename,newext:string):string;
var i:word;
begin
i:=length(filename);
while (i>0) and (filename[i]<>'.') do dec(i);
if newext = '' then result:=copy(filename,1,i-1)
else result:=copy(filename,1,i)+newext;
end;
function SafeFileName(filename:string):string;
var i:word;
begin
i:=length(filename)-1;
while (i>0) do begin
if (filename[i] = '\') and (filename[i+1] = '\') then delete(filename,i,1);
dec(i);
end;
result:=filename;
end;
procedure writefile(filename,contenu:string);
var f:system.text;
fullname:string;
begin
fullname:=GetCurrentDir()+'\'+filename;
if (exportres) then fullname:=GetCurrentDir()+'\res\'+filename;
if (exportjs) then fullname:=GetCurrentDir()+'\js\'+filename;
ForceDirectories(SafeFileName(ExtractFileDir(fullname)));
assignfile(f,fullname);
rewrite(f);
write(f,contenu);
closefile(f);
end;
procedure writegif(filename:string;bmp:TBitmap);
var fullname:string;
GIF:TGIFImage;
begin
fullname:=GetCurrentDir()+'\res\'+filename;
fullname:=replaceExt(fullname,'gif');
ForceDirectories(SafeFileName(ExtractFileDir(fullname)));
GIF := TGIFImage.Create;
GIF.ColorReduction := rmNone; // rmQuantize rmNone
// GIF.DitherMode := dmNearest; // no dither, use nearest color in palette
GIF.DitherMode := dmNearest; // dmNearest dmFloydSteinberg
GIF.Add(bmp);
GIF.SaveToFile(fullname);
GIF.Free;
end;
procedure centerizeform(f:TForm);
begin
f.Top:=(Screen.WorkAreaHeight-f.Height) div 2;
if f.Top<0 then f.Top:=0;
f.Left:=(Screen.WorkAreaWidth-f.Width) div 2;
if f.Left<0 then f.Left:=0;
end;
function dec2hex(b:byte):string;
const hex:string[16]='0123456789ABCDEF';
begin
dec2hex:=hex[succ(b shr 4)]+hex[succ(b and 15)];
end;
procedure setCursor(idcursor:smallint);
var cursortype:string;
begin
if idcursor >= 0 then begin
cursortype:=strings.strings[idcursor];
if (cursortype = 'normal') then begin
TWTW.pbx.Cursor:=crDefault;
end;
if (cursortype = 'Hand') then begin
TWTW.pbx.Cursor:=crHandPoint;
end;
end else begin
if (idcursor = -1) then begin
TWTW.pbx.Cursor:=crDefault;
end;
if (idcursor = -2) then begin
TWTW.pbx.Cursor:=crHourGlass;
end;
end;
end;
procedure simulateMouseMove;
var pt : TPoint;
begin
if (exportres or exportjs) then exit;
GetCursorPos(pt);
SetCursorPos(pt.x+1, pt.y+1);
Application.ProcessMessages;
GetCursorPos(pt);
SetCursorPos(pt.x-1, pt.y-1);
Application.ProcessMessages;
end;
function displayPicture(filename:string;xoffset,yoffset:smallint):string;
var bmp:TBitmap;
bmpto:TRect;
bmpstream:TStream;
openbmp,i:smallint;
savename:string;
d:boolean;
begin
savename:=filename;
i:=1;d:=false;
while i <= length(filename) do begin
if filename[i] = '[' then begin
delete(filename,i,1);
d:=true;
end else if filename[i] = ']' then begin
delete(filename,i,1);
d:=false;
end else if (d) then delete(filename,i,1)
else inc(i);
end;
bmpstream:=OpenFile(filename);
if (bmpstream = nil) then begin
//raise Exception.Create('bmpstream for '+filename+' is nil');
exit;
end;
openbmp:=10;
bmp:=TBitmap.Create();
while openbmp>0 do begin
try
bmp.LoadFromStream(bmpstream);
openbmp:=-1;
except
on EInvalidGraphic do begin
bmp.Free;
bmp:=TBitmap.Create();
dec(openbmp);
end;
end;
end;
bmpstream.free;
if openbmp = 0 then begin
bmp.free;
//raise Exception.Create('bmpstream for '+filename+' cannot be opened');
exit;
end;
bmpto:=Rect(xoffset,yoffset,xoffset+bmp.Canvas.ClipRect.Right,yoffset+bmp.Canvas.ClipRect.Bottom);
with actualPages[actualPageLevel] do begin
x1:=xoffset;
y1:=yoffset;
x2:=xoffset+bmp.Canvas.ClipRect.Right;
if x2 > BufferImage.Canvas.ClipRect.Right then x2:=BufferImage.Canvas.ClipRect.Right;
y2:=yoffset+bmp.Canvas.ClipRect.Bottom;
if y2 > BufferImage.Canvas.ClipRect.Bottom then y2:=BufferImage.Canvas.ClipRect.Bottom;
// Limites d'affichage des animations dans l'image actuelle
AniRect:=Rect(x1,y1,x2,y2);
end;
// Insertion de l'image dans le buffer
BufferImage.Canvas.CopyRect(bmpto,bmp.Canvas,bmp.Canvas.ClipRect);
bmp.free;
if (exportres) then begin
i:=1;
while i <= length(savename) do begin
if (savename[i] = '[') or (savename[i] = ']') then delete(savename,i,1)
else inc(i);
end;
bmp:=TBitmap.Create();
bmp.Width:=AniRect.Right-AniRect.Left;
bmp.Height:=AniRect.Bottom-AniRect.Top;
bmp.Canvas.CopyRect(bmp.Canvas.ClipRect,BufferImage.Canvas,AniRect);
writegif(savename,bmp);
bmp.free;
end;
if (exportjs) then begin
filename:=replaceExt(filename,'gif');
result:=', src:''res'+revertandaddslashes(filename,true)+''', left:'+inttostr(AniRect.Left)+', top:'+inttostr(AniRect.Top);
end else result:='';
end;
procedure addItems(page:TPAGE;basedir:string;xoff_,yoff_:smallint);
var item,i:smallint;
filename,linkdata,actiondata:string;
bmp:TBitmap;
bmpto:TRect;
bmpstream:TStream;
begin
actualletter:=-1;
with actualPages[actualPageLevel] do begin
with page do
for item:=1 to numitems do with items[item-1] do begin
actualItems[actualNumitems]:=items[item];
inc(actualNumitems);
links[numlinks].x1:=xoff_+x1;
links[numlinks].y1:=yoff_+y1;
links[numlinks].x2:=xoff_+x2;
links[numlinks].y2:=yoff_+y2;
if (debug) then begin
BufferImage.Canvas.Brush.Style:=bsClear;
BufferImage.Canvas.Pen.Color:=$ee;
BufferImage.Canvas.Rectangle(links[numlinks].x1, links[numlinks].y1, links[numlinks].x2, links[numlinks].y2);
end;
links[numlinks].xoffset:=xoff_;
links[numlinks].yoffset:=yoff_;
links[numlinks].cursor:=cursor;
links[numlinks].linktype:=itemtype;
if (exportjs) then begin
linkdata:='x1:'+inttostr(links[numlinks].x1)+', y1:'+inttostr(links[numlinks].y1)+', x2:'+inttostr(links[numlinks].x2)+', y2:'+inttostr(links[numlinks].y2)+', type:'+inttostr(links[numlinks].linktype-600)+', id:'+inttostr(item_id);
end;
if (itemtype = 601) then begin
// Image de fond. C'est le premier item dans la liste
links[numlinks].x1:=0;
links[numlinks].y1:=0;
links[numlinks].x2:=0;
links[numlinks].y2:=0;
linkdata:='type:1';
filename:=basedir+strings.strings[image]+'.DIB';
if (debug) then twtw.memo1.lines.add('Background image '+filename+' '+inttostr(xoff_)+' '+inttostr(yoff_));
linkdata:=linkdata+displayPicture(filename,xoff_,yoff_);
inc(numlinks);
end;
links[numlinks].fx1:=actualPages[actualPageLevel].x1;
links[numlinks].fy1:=actualPages[actualPageLevel].y1;
links[numlinks].fx2:=actualPages[actualPageLevel].x2;
links[numlinks].fy2:=actualPages[actualPageLevel].y2;
if (itemtype = 602) then begin
// Animation avec barre de défilement
CCMBufferImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,CCMBufferImage.Canvas.ClipRect);
CCMaddControlbar(xoff_+x1,yoff_+y1);
BufferImage.Canvas.CopyRect(CCMBufferImage.Canvas.ClipRect,CCMBufferImage.Canvas,BufferImage.Canvas.ClipRect);
//TWTW.memo1.Lines.add('Animation with control bar');
filename:=basedir+strings.strings[anim]+'.ANI';
links[numlinks].anim:=filename;
links[numlinks].anim_skip:=actualPage;
if (exportjs) then linkdata:=linkdata+', src:''res'+revertandaddslashes(replaceExt(filename,'gif'),true)+''', audio:''res'+revertandaddslashes(replaceExt(filename,''),true)+''', left:'+inttostr(xoff_)+', top:'+inttostr(yoff_)+', time:'+inttostr(CCMAniLength(filename))+', controlbar:true, cbx:'+inttostr(xoff_+x1)+', cby:'+inttostr(yoff_+y1);
if (autostart = 0) then begin
AniRect:=Rect(links[numlinks].fx1,links[numlinks].fy1,links[numlinks].fx2,links[numlinks].fy2);
if (not exportjs) then CCMPlayAni(filename,xoff_,yoff_,true) else linkdata:=linkdata+', autostart:true';
setCursor(-2);
nextpage_ani:=-2;
links[numlinks].anim_skip:=-2;
dec(numhistory); // Doesn't count in the history
end;
inc(numlinks);
end;
if (itemtype = 603) then begin
// Objets cliquables, possédant une ou deux actions réalisables. Voir le mouseDown pour plus d'infos
// item_props : 4 (mainly) or 5 or 1
if (debug) then twtw.memo1.lines.add('Link: '+inttostr(links[numlinks].x1)+':'+inttostr(links[numlinks].y1)+'/'+inttostr(links[numlinks].x2)+':'+inttostr(links[numlinks].y2));
links[numlinks].numactions:=numactions;
links[numlinks].actions[0]:=actions[0];
links[numlinks].actions[1]:=actions[1];
if (exportjs) then begin
actiondata:='';
for i:=0 to numactions-1 do begin
if (actions[i].typeaction = 1) then begin
// Popup : aller au niveau suivant, et indiquer l'ID de la popup à afficher.
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:1,nextpage:'+inttostr(getIDPointer(actions[i].popup_id))+'}';
end;
if (actions[i].typeaction = 2) then begin
// Raccourci (lien secondaire) vers un item présent sur la page
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:2,linkId:'+inttostr(actions[i].item_id)+'}';
end;
if (actions[i].typeaction = 3) then begin
// Nouvelle page
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:3,nextpage:'+inttostr(getIDPointer(actions[i].linkto))+'}';
end;
if (actions[i].typeaction = 4) then begin
// Jouer un son
filename:=actualBaseDir+strings.strings[actions[i].soundtoplay];
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:4,audio:''res'+revertandaddslashes(filename,true)+'''}';
end;
if (actions[i].typeaction = 7) then begin
// Animation simple
filename:=actualBaseDir+strings.strings[actions[i].anim]+'.ANI';
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:7,src:''res'+revertandaddslashes(replaceExt(filename,'gif'),true)+''', audio:''res'+revertandaddslashes(replaceExt(filename,''),true)+''', left:'+inttostr(xoff_)+', top:'+inttostr(yoff_)+', time:'+inttostr(CCMAniLength(filename))+'}';
end;
if (actions[i].typeaction = 11) then begin
// Commandes spéciales (copier dans le presse papiers, imprimer, configurer impression)
actiondata:=actiondata+'{type:11}';
end;
if (actions[i].typeaction = 12) then begin
// Fermer la popup.
// In ciné-mamouth, this action item is followed by a popup action.
if (actiondata <> '') then actiondata:=actiondata+', ';
actiondata:=actiondata+'{type:12}';
end;
end;
if (actiondata <> '') then linkdata:=linkdata+', actions:['+actiondata+']';
end;
inc(numlinks);
end;
if (itemtype = 604) then begin
// Lettres utilisées dans la roue alphabétique
links[numlinks].numactions:=0;
links[numlinks].letter:=letter;
links[numlinks].anim_skip:=page_skip;
actualletter:=0;
if (exportjs) then begin
if (letter < 26) then linkdata:=linkdata+', src:''res'+revertandaddslashes(basedir+'AZAZ0M'+chr(ord('A')+letter)+'A.gif',true)+''', audio:''res'+revertandaddslashes(basedir+'AZAZ0MAA',true)+''', left:'+inttostr(xoff_)+', top:'+inttostr(yoff_)+', time:'+inttostr(CCMAniLength(basedir+'AZAZ0M'+chr(ord('A')+letter)+'A.ANI'))+', alt:''res'+revertandaddslashes(basedir+'AZAZ0M'+chr(ord('A')+letter)+'A-bg.gif',true)+''', letter:'+inttostr(letter)+', nextpage:'+inttostr(getIDPointer(page_skip))
else linkdata:=linkdata+', audio:''res'+revertandaddslashes(basedir+'DIAL',true)+''', letter:'+inttostr(letter);
end;
inc(numlinks);
end;
if (itemtype = 606) then begin
// Boutons de navigation à gauche (il y en a 9, dans la frame externe)
filename:=basedir+strings.strings[anim]+'.ANI';
//TWTW.memo1.Lines.add('NAV bar '+filename);
links[numlinks].anim:=filename;
//links[numlinks].anim_skip:=page_skip;
//TWTW.Memo1.lines.add('(Theorically) Link '+inttostr(item_id)+' to '+inttostr(page_skip));
// The order in the file is wrong!!
links[numlinks].anim_skip:=fixedNavBar(item_id, actualmachines_page, actualrelated_principles_popup, actualtimeline_page, actualinventors_page);
if (exportjs) then linkdata:=linkdata+', src:''res'+revertandaddslashes(replaceExt(filename,'gif'),true)+''', audio:''res'+revertandaddslashes(replaceExt(filename,''),true)+''', left:'+inttostr(xoff_)+', top:'+inttostr(yoff_)+', time:'+inttostr(CCMAniLength(filename))+', nextpage:'+inttostr(getIDPointer(fixedNavBar(item_id, -40, -41, -42, -43)));
inc(numlinks);
end;
if (itemtype = 607) then begin
// Animation
filename:=basedir+strings.strings[anim]+'.ANI';
if (debug) then twtw.memo1.lines.add('Animation ('+inttostr(item_props)+' '+filename+': '+inttostr(links[numlinks].x1)+':'+inttostr(links[numlinks].y1)+'/'+inttostr(links[numlinks].x2)+':'+inttostr(links[numlinks].y2));
if (exportjs) then linkdata:=linkdata+', src:''res'+revertandaddslashes(replaceExt(filename,'gif'),true)+''', audio:''res'+revertandaddslashes(replaceExt(filename,''),true)+''', left:'+inttostr(xoff_)+', top:'+inttostr(yoff_)+', time:'+inttostr(CCMAniLength(filename));
//setCursor(cursor);
if (item_props = 32) then begin
nextpage_ani:=nextpage;
if (not exportjs) then CCMPlayAni(filename,xoff_,yoff_,false) else linkdata:=linkdata+', autostart:true, nextpage:'+inttostr(getIDPointer(nextpage));
setCursor(-2);
dec(numhistory); // Doesn't count in the history
end;
if (item_props = 0) or (item_props = 16) then begin
links[numlinks].anim:=filename;
if (page_skip = 1) then begin
links[numlinks].anim_skip:=nextpage;
if (exportjs) then linkdata:=linkdata+', nextpage:'+inttostr(getIDPointer(nextpage));
end else begin
links[numlinks].anim_skip:=-1;
end;
end;
inc(numlinks);
end;
if (itemtype = 608) then begin
// Bouton d'annulation, utilisé dans la page d'options
TWTW.CancelButton.Left:=links[numlinks].x1;
TWTW.CancelButton.Top:=links[numlinks].y1;
TWTW.CancelButton.Width:=links[numlinks].x2-links[numlinks].x1;
TWTW.CancelButton.Height:=links[numlinks].y2-links[numlinks].y1;
TWTW.CancelButton.Visible:=true;
inc(numlinks);
end;
if (itemtype = 609) then begin
// Longue image scrollable utilisée dans l'aide
filename:=basedir+strings.strings[image]+'.DIB';
bmpstream:=OpenFile(filename);
bmp:=TBitmap.Create();
bmp.LoadFromStream(bmpstream);
bmpstream.free;
bmpto:=Rect(0,0,bmp.Canvas.ClipRect.Right,bmp.Canvas.ClipRect.Bottom);
TWTW.ImageScrolled.Width:=500;
TWTW.ImageScrolled.Height:=2000; // Get enough space for all the future images
TWTW.ScrollBox.Visible:=true;
TWTW.ScrollBox.VertScrollBar.Position:=0;
TWTW.ImageScrolled.Canvas.CopyRect(bmpto,bmp.Canvas,bmpto);
TWTW.ImageScrolled.Width:=bmp.Canvas.ClipRect.Right;
TWTW.ImageScrolled.Height:=bmp.Canvas.ClipRect.Bottom;
bmp.free;
end;
if ((exportjs) and (itemtype <> 605)) then begin
jsexport:=jsexport+'page.links['+inttostr(numlinks-1)+'] = {'+linkdata+'};'#13#10;
end;
end;
if (actualletter = 0) then begin
displayPicture(actualBaseDir+'AZAZ0MAA.DIB',255,105); // Lettre A affichée par défaut
end;
end;
end;
procedure displayFrame(idframe,typepage:smallint);
var i,j:smallint;
frame:TPAGE;
idpointer_frame_pointer:longint;
begin
with actualPages[actualPageLevel] do
for i:=0 to info.numframes-1 do with info.frames[i] do if (id_frame = idframe) then begin // On cherche la frame à afficher dans la liste des frames
for j:=0 to numinfos-1 do with infos[j] do begin // On parcours les infos disponibles
if (id_frame2 = 1) then begin
if (typepage = 102) then begin // Page pleine : on ajoute un offset (les popups ont leur propre offset)
xoff:=offset_x;
yoff:=offset_y;
end;
end else begin
idpointer_frame_pointer:=getIDPointer(idpointer_frame);
if (typeframe2 <> 202) then begin // On affiche le fond de la frame et ses items (exemple, les boutons de navigation).
if (exportres or exportjs) and (not exportstatus[idpointer_frame_pointer].pageexported) then begin
actualPages[actualPageLevel].numlinks:=0;
actualPages[actualPageLevel].actualNumitems:=0;
jsexport:='';
end;
if (not (exportres or exportjs)) or (not exportstatus[idpointer_frame_pointer].pageexported) then begin
frame:=ReadPagePNG(idpointer_frame_pointer);
addItems(frame,'',imageoffset_x,imageoffset_y);
end else if (exportjs) then begin
jsexport:=jsexport+'page.frames.push('+inttostr(idpointer_frame_pointer)+');'#13#10;
end;
if (exportres or exportjs) and (not exportstatus[idpointer_frame_pointer].pageexported) then begin
exportstatus[idpointer_frame_pointer].pageexported:=true;
nextexportpage:=idpointer_frame_pointer; // On prévoit d'exporter les liens, pour passer en fullexported
exit;
end;
end;
end;
end;
end;
end;
procedure displayPage(idpage:IDPOINTER);
var page:TPAGE;
basedir:string;
begin
// On arrête une éventuelle animation en cours
if CCMIsPlaying then CCMStopAni;
while CCMIsPlaying do;
// On met à jour et cache d'éventuels éléments d'interface
TWTW.Edit1.Text:=inttostr(idpage);
TWTW.IndexEdit.Visible:=(idpage = CCMIndex);
TWTW.IndexList.Visible:=(idpage = CCMIndex);
TWTW.CancelButton.Visible:=false;
TWTW.ScrollBox.Visible:=false;
// On met à jour le statut de la sauvegarde de l'animation (mise à zéro lorsque c'est fait).
TWTW.MenuSauveAnim.Checked:=AniSaveToDisk;
// Lecture des informations sur la page.
page:=ReadPagePNG(idpage);
if page.typepage=0 then exit; // On n'est pas sur une vraie page, on ignore.
if (page.typepage <> 102) then // S'il ne s'agit pas d'une pleine page (donc une popup à priori) et que le niveau est = 0 ou identique au précédent, alors on avance d'un niveau.
if (actualPageLevel = 0) and (actualPages[actualPageLevel].actualPage <> idpage) and (actualPageLevel = predPageLevel) then
inc(actualPageLevel) else
else actualPageLevel:=0; // Sinon, il s'agit d'une pleine page, on revient au début.
with actualPages[actualPageLevel] do begin // Ensuite, on donne les infos sur le niveau de page actuel
// Initialisation des infos
actualPage:=idpage;
nextpage_ani:=-1;
numlinks:=0;
actualNumitems:=0;
actualrelated_principles_popup:=-1;
actualmachines_page:=-1;
actualinventors_page:=-1;
actualtimeline_page:=-1;
x1:=-1;
y1:=-1;
x2:=-1;
y2:=-1;
if (debug) then twtw.memo1.lines.add('Reading page #'+inttostr(idpage));
with page do begin
if (debug) then twtw.memo1.lines.add('Page type: '+inttostr(typepage));
if (debug) then twtw.memo1.lines.add('Frame: '+inttostr(id_frame));
basedir:=strings.strings[basedirectory];
if (debug) then twtw.memo1.lines.add('Base directory: '+basedir);
actualBasedir:=basedir;
if ((actualBasedir <> '\HELP\') or (actualPageLevel <> predPageLevel)) then begin
// - Aide : problèmes avec quelques pages (gros souk des offsets). Résultat : les liens entre les pages "molécules" par ex changent
// la position de la fenêtre (même déplacée), mais pas les pages d'aide (si déplacement de la fenêtre, on reste)...
xoff:=actualPages[0].xoff;
yoff:=actualPages[0].yoff;
end;
if (exportjs) then jsexport:='page.type='+inttostr(typepage-100)+';'#13#10;
if (typepage=101) then begin // Popup
BufferImage.Canvas.CopyRect(actualPages[pred(actualPageLevel)].PageImage.Canvas.ClipRect,actualPages[pred(actualPageLevel)].PageImage.Canvas,BufferImage.Canvas.ClipRect);
end;
if (typepage=102) then begin // Page pleine
// On ajoute à l'historique
if (numhistory >= 1000) then numhistory:=999;
if (numhistory >= 0) then begin
if history[numhistory] <> idpage then begin
inc(numhistory);
if (numhistory >= 0) then history[numhistory]:=idpage;
end;
end else begin
inc(numhistory);
if (numhistory >= 0) then history[numhistory]:=idpage;
end;
if (more_infos = 1) and (links_infos = 0) then begin
// Si disponible, on renseigne les pages principes, inventions, inventeurs...
actualrelated_principles_popup:=related_principles_popup;
actualmachines_page:=machines_page;
actualinventors_page:=inventors_page;
actualtimeline_page:=timeline_page;
end;
if (exportjs) then jsexport:=jsexport+'page.menupages=['
+inttostr(getIDPointer(fixedNavBar(-47, actualmachines_page, actualrelated_principles_popup, actualtimeline_page, actualinventors_page)))+','
+inttostr(getIDPointer(fixedNavBar(-48, actualmachines_page, actualrelated_principles_popup, actualtimeline_page, actualinventors_page)))+','
+inttostr(getIDPointer(fixedNavBar(-49, actualmachines_page, actualrelated_principles_popup, actualtimeline_page, actualinventors_page)))+','
+inttostr(getIDPointer(fixedNavBar(-50, actualmachines_page, actualrelated_principles_popup, actualtimeline_page, actualinventors_page)))
+'];'#13#10;
end;
if (typepage = 103) then begin // Popup également ?
BufferImage.Canvas.CopyRect(actualPages[pred(actualPageLevel)].PageImage.Canvas.ClipRect,actualPages[pred(actualPageLevel)].PageImage.Canvas,BufferImage.Canvas.ClipRect);
end;
// Affichage de la frame extérieure
displayFrame(id_frame,typepage);
if ((actualBasedir <> '\HELP\') or (actualPageLevel <> predPageLevel)) then begin
// Si il ne s'agit pas d'une page d'aide ou si le niveau de page a changé, on décale la page dans la fenêtre.
inc(xoff,xoffset);
inc(yoff,yoffset);
end;
// On ajoute les différents items sur la page (image de fond, liens, animations...)
if (debug) then twtw.memo1.lines.add('Loading items: '+inttostr(numitems));
if (exportres or exportjs) then begin
if (nextexportpage = 0) or (nextexportpage = idpage) then begin
addItems(page,basedir,xoff,yoff);
exportstatus[idpage].pageexported:=true;
end;
end else addItems(page,basedir,xoff,yoff);
end;
// Une fois tous les items ajoutés, on affiche sur le buffer
CCMBufferImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,CCMBufferImage.Canvas.ClipRect);
// On sauvegarde l'image pour utilisation future (retour en arrière notamment, ou changement de popup)
actualPages[actualPageLevel].PageImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,actualPages[actualPageLevel].PageImage.Canvas.ClipRect);
// On rafraichit l'image à l'écran
TWTW.pbx.Refresh;
// Mettre à jour le curseur de la souris, si il y a un item ou pas en dessous
simulateMouseMove;
// On commence à compter l'historique à partir du workshop
if (numhistory < 0) and (idpage = CCMWorkshop) then numhistory:=0;
end;
// On garde le niveau actuel pour usage futur
predPageLevel:=actualPageLevel;
end;
procedure FinishedAnimation;
begin
// On écrase la valeur de nextpage_load par la valeur de nextpage_ani (ou la page actuelle pour rafficher la page à l'issue de l'animation)
nextpage_load:=-1;
if (nextpage_ani > -1) then nextpage_load:=nextpage_ani
else if (nextpage_ani = -1) then nextpage_load:=actualPages[actualPageLevel].actualPage;
// On lance le timer pour actualiser la page (petit truc pour éviter de s'embêter avec les threads)
if (exportres or exportjs) then begin
TWTW.ExportTimer.Enabled:=True;
end else begin
TWTW.NextPageTimer.Enabled:=true;
end;
end;
procedure TTWTW.Button1Click(Sender: TObject);
begin
displayPage(strtoint(Edit1.Text));
end;
procedure TTWTW.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if CCMIsPlaying then begin
CCMStopAni;
end;
if (debug) then memo1.lines.add('Closing...');
ClosePNG;
if (TWTWZip <> nil) then begin
TWTWZip.Close;
TWTWZip.Free;
end;
if (debug) then memo1.lines.add('Bye!');
end;
procedure TTWTW.FormShow(Sender: TObject);
var i,j:word;
s,param:string;
begin
memo1.Lines.Clear;
param:='TWTW';
debug:=false;exportres:=false;exportjs:=false;
if (paramstr(1) = '--debug') then debug:=true;
if (paramstr(1) = '--exportres') then exportres:=true;
if (paramstr(1) = '--exportjs') then exportjs:=true;
if (paramcount > 0) then param:=paramstr(paramcount);
TWTWZip:=nil;
if FileExists(param+'.ZIP') then begin
TWTWZip:=TZipFile.Create;
TWTWZip.OpenFromFile(param+'.ZIP');
TWTWZip.LoadZip;
end;
actualPageLevel:=0;
numhistory:=-10;history[0]:=CCMWorkshop;
if ((paramcount > 0) and (TWTWZip = nil)) then s:=param else s:='.';
while (s<>'') and (s[length(s)] = '\') do delete(s,length(s),1);
cdroot:=s;
if (debug) then memo1.lines.add('Loading...');
if not OpenPNG('DKCODE\TWTW.PNG') then begin
Application.MessageBox('Fichier TWTW.PNG non trouvé ou illisible, spécifiez le chemin en ligne de commande.','Erreur',mb_ICONSTOP);
Application.Terminate;
exit;
end;
if (debug) then memo1.lines.add('Loaded OK');
edit1.Text:=inttostr(info.page_start);
BufferImage:=TBitmap.Create;
BufferImage.Width:=info.screenwidth-2; // 638
BufferImage.Height:=info.screenheight-22; // 458
for i:=0 to 7 do begin
actualPages[i].PageImage:=TBitmap.Create;
actualPages[i].PageImage.Width:=info.screenwidth-2; // 638
actualPages[i].PageImage.Height:=info.screenheight-22; // 458
end;
for i:=0 to index.indexlen-1 do IndexList.Items.Add(strings.strings[index.indexitems[i].indexword]);
TWTW.Width:=info.screenwidth+4;
pbx.width:=info.screenwidth;
if (not debug) then TWTW.Height:=info.screenheight+3;
if (not debug) and (not exportres) and (not exportjs) then Button1.Click;
pbx.height:=info.screenheight-2;
IndexEdit.Visible:=false;
IndexList.Visible:=false;
ScrollBox.Left:=CCMScrollBoxPos[0];
ScrollBox.Top:=CCMScrollBoxPos[1];
ScrollBox.Width:=CCMScrollBoxPos[2];
ScrollBox.Height:=CCMScrollBoxPos[3];
centerizeform(TWTW);
if (exportres or exportjs) then begin
for i:=0 to 2000 do begin
exportstatus[i].pageexported:=false;
exportstatus[i].fullexported:=false;
for j:=0 to 100 do exportstatus[i].itemexported[j]:=false;
end;
nextexportpage:=0;
jstotal:='';
ExportTimer.Enabled:=True;
end;
end;
procedure TTWTW.FormCreate(Sender: TObject);
begin
CCMCanvas:=pbx.Canvas;
OnCCMFinished:=FinishedAnimation;
pbp.DoubleBuffered:=true;
end;
procedure TTWTW.pbxPaint(Sender: TObject);
begin
CCMRefresh;
end;
procedure TTWTW.pbxMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i:smallint;
linkFound:boolean;
begin
if (exportres or exportjs) then exit;
with actualPages[actualPageLevel] do begin
if not (CCMIsPlaying) then begin
linkFound:=false;
for i:=0 to numlinks-1 do with links[i] do begin
if (x >= x1) and (y >= y1) and (x <= x2) and (y <= y2) then begin
linkFound:=true;
{CCMCanvas.Brush.Color:=$cc0000; CCMCanvas.Pen.Color:=$cc0000; CCMCanvas.Rectangle(x1,y1,x2,y2);}
setCursor(cursor);
end;
end;
if not linkFound then setCursor(-1);
end;
end;
end;
procedure TTWTW.pbxMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var i,j,k:word;
filename:string;
nextpage:IDPOINTER;
nextlevel:smallint;
actionTaken:boolean;
begin
if (exportres or exportjs) and (Sender <> nil) then exit;
if Button <> mbLeft then exit;
if CCMIsPlaying then begin
CCMStopAni; // Stoppe simplement l'animation en cours avec un clic
end else with actualPages[actualPageLevel] do begin
nextpage:=-1;
nextpage_ani:=-1;
nextlevel:=actualPageLevel;
actionTaken:=false;
if (actualPageLevel > 0) and (not ((x >= x1) and (y >= y1) and (x <= x2) and (y <= y2))) then begin
dec(nextlevel);
nextpage:=actualPages[nextlevel].actualPage;
end else
for i:=1 to numlinks do if not actionTaken then with links[i-1] do begin
if (x >= x1) and (y >= y1) and (x <= x2) and (y <= y2) then begin
if (exportres) and (i-1 <> nextexportitem) then continue;
if (debug) then twtw.memo1.lines.add(inttostr(linktype));
// Item 601 ignoré, car c'est l'image de fond.
if (linktype = 602) then begin
// Animation avec barre de défilement
actionTaken:=true;
nextpage_ani:=anim_skip;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportjs) then CCMPlayAni(anim,xoff,yoff,true);
setCursor(-2);
end;
if (linktype = 603) then begin
// Objets avec actions
for j:=1 to numactions do with actions[j-1] do begin
if (typeaction = 1) then begin
// Popup : aller au niveau suivant, et indiquer l'ID de la popup à afficher.
inc(nextlevel);
nextpage:=popup_id;
actionTaken:=true;
break;
end;
if (typeaction = 2) then begin
// Raccourci (lien secondaire) vers un item présent sur la page
for k:=0 to actualNumitems-1 do if (actualItems[k].item_id = item_id) then begin
if (actualItems[k].itemtype = 602) then begin
if (debug) then twtw.memo1.lines.add('Animation with control bar');
filename:=actualBaseDir+strings.strings[actualItems[k].anim]+'.ANI';
actionTaken:=true;
if (actualItems[k].autostart = 0) then nextpage_ani:=-2;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportjs) then CCMPlayAni(filename,xoff,yoff,true);
setCursor(-2);
end;
end;
end;
if (typeaction = 3) then begin
// Nouvelle page
nextpage:=linkto;
actionTaken:=true;
break;
end;
if (typeaction = 4) then begin
// Jouer un son
filename:=actualBaseDir+strings.strings[soundtoplay]+'.WAV';
setCursor(-2);
if (not exportjs) then CCMPlayWav(filename);
end;
if (typeaction = 7) then begin
// Animation simple
filename:=actualBaseDir+strings.strings[anim]+'.ANI';
actionTaken:=true;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportjs) then CCMPlayAni(filename,xoff,yoff,false);
setCursor(-2);
end;
if (typeaction = 11) then begin
// Commandes spéciales
if (not (exportres or exportjs)) then begin
if (command = 1) then begin // Copier
clipboard.assign(actualPages[0].PageImage);
Application.MessageBox('Image copiée dans le presse-papiers !','CCM',mb_ICONINFORMATION);
//dec(nextlevel);
//nextpage:=actualPages[nextlevel].actualPage;
end;
if (command = 2) then begin // Imprimer
Application.MessageBox('Non supporté','Non supporté',mb_ICONSTOP);
end;
if (command = 3) then begin // Configurer impression
Application.MessageBox('Non supporté','Non supporté',mb_ICONSTOP);
end;
end;
end;
if (typeaction = 12) then begin
// Fermer la popup.
// In ciné-mamouth, this action item is followed by a popup action.
dec(nextlevel);
nextpage:=actualPages[nextlevel].actualPage;
end;
end;
end;
if (linktype = 604) then begin
// Utilisé dans la roue aplhabétique
actionTaken:=true;
if (letter >= 0) and (letter < 26) then begin
actualletter:=letter;
if (exportres) then begin
// On affiche l'image à la fois pour la sauvegarder (d'où le [-bg]) et à la fois pour préparer l'enregistrement de l'animation.
displayPicture(actualBaseDir+'AZAZ0M'+chr(ord('A')+actualletter)+'A[-bg].DIB',255,105);
CCMBufferImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,CCMBufferImage.Canvas.ClipRect);
actualPages[actualPageLevel].PageImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,actualPages[actualPageLevel].PageImage.Canvas.ClipRect);
AniRect:=Rect(fx1,fy1,fx2,fy2);
CCMPlayAni(actualBaseDir+'AZAZ0M'+chr(ord('A')+actualletter)+'A.ANI',xoff,yoff,false);
nextpage_ani:=-2; // On évite de jouer le son "DIAL.WAV" qui annule l'animation avant de l'avoir exportée. Le n° de page ne sera de toutes façons pas pris en compte.
end;
end else begin
if (letter = 26) then begin
dec(actualletter);
if (actualletter < 0) then actualletter:=25;
end;
if (letter = 27) then begin
inc(actualletter);
if (actualletter > 25) then actualletter:=0;
end;
if (letter = 28) then begin
if (debug) then twtw.memo1.lines.add('Other letter movement: OK');
for j:=1 to numlinks do if (links[j-1].letter = actualletter) then nextpage_ani:=links[j-1].anim_skip;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportres) and (not exportjs) then CCMPlayAni(actualBaseDir+'AZAZ0M'+chr(ord('A')+actualletter)+'A.ANI',xoff,yoff,false);
setCursor(-2);
end;
end;
if (nextpage_ani = -1) then begin
if (debug) then twtw.memo1.lines.add('Current letter: '+chr(ord('A')+actualletter));
nextpage_ani := -2;
CCMPlayWav(actualBaseDir+'DIAL.WAV');
displayPicture(actualBaseDir+'AZAZ0M'+chr(ord('A')+actualletter)+'A[-bg].DIB',255,105);
CCMBufferImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,CCMBufferImage.Canvas.ClipRect);
actualPages[actualPageLevel].PageImage.Canvas.CopyRect(BufferImage.Canvas.ClipRect,BufferImage.Canvas,actualPages[actualPageLevel].PageImage.Canvas.ClipRect);
TWTW.pbx.Refresh;
end;
end;
if (linktype = 606) then begin
// Boutons de navigation à gauche
nextpage_ani:=anim_skip;
if (anim_skip = -51) and (numhistory > 0) then begin
dec(numhistory);
nextpage_ani:=history[numhistory];
end;
actionTaken:=true;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportjs) then CCMPlayAni(anim,xoffset,yoffset,false);
setCursor(-2);
end;
if (linktype = 607) then begin
// Animations
nextpage_ani:=anim_skip;
actionTaken:=true;
AniRect:=Rect(fx1,fy1,fx2,fy2);
if (not exportjs) then CCMPlayAni(anim,xoffset,yoffset,false);
setCursor(-2);
end;
if (linktype = 608) then begin
// Utilisé à un seul endroit (page "Options")
// Bouton "Annuler"
// Pourrait également servir à fermer la popup, avec l'ID de popup qui suivrait.
dec(nextlevel);
nextpage:=actualPages[nextlevel].actualPage;
end;
end;
end;
if (nextpage > -1) and (not (exportres or exportjs)) then begin
// Si on est supposé changer de page, on le fait.
actualPageLevel:=nextlevel;
displayPage(nextpage);
end;
end;
end;
procedure TTWTW.IndexListDblClick(Sender: TObject);
var indexitem:TINDEXITEM;
i:smallint;
begin
indexitem:=index.indexitems[IndexList.ItemIndex];
displayPage(indexitem.idpage);
for i:=1 to indexitem.nbpopups do begin
inc(actualPageLevel);
displayPage(indexitem.popups[i-1]);
end;
end;
procedure TTWTW.NextPageTimerTimer(Sender: TObject);
var np:IDPOINTER;
begin
NextPageTimer.Enabled:=false;
np:=nextpage_load;
nextpage_load:=-1;
simulateMouseMove;
if (np > -1) then begin
if (debug) then memo1.lines.add('Skip to:'+inttostr(np));
displayPage(np);
end;
end;
procedure TTWTW.CancelButtonClick(Sender: TObject);
begin
dec(actualPageLevel);
displayPage(actualPages[actualPageLevel].actualPage);
end;
procedure TTWTW.MenuSauveAnimClick(Sender: TObject);
begin
AniSaveToDisk:=not AniSaveToDisk;