-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_narrative_v2.xml
2511 lines (2235 loc) · 119 KB
/
test_narrative_v2.xml
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
<PDFComposition>
<Metadata>
<Author>Robin</Author>
</Metadata>
<Javascript>
var animate = null;
var animationRunning = false;
// Colours for the UI components
var lightBlue = new Array("RGB", 0.815, 0.886, 0.949);
var darkBlue = new Array("RGB", 0.443, 0.662, 0.854);
var current_index = 0;
var firstRun = true;
var factor = null;
var dpi = 99;
var lastPageViewX = null;
var lastPageViewY = null;
var lastPageViewZoom = null;
var lastSliderButtonLocation = 0;
var currentNarrativeIndex = null;
// List of non-interactive layers
var nonInteractiveLayers = ['Nelson (non-interactive)', 'Collingwood (non-interactive)']
// Array of objects containing the name of the timestamp
// and a name of the OCG to turn on for that timestep.
// This is altered by the code in the MAIN section at the bottom
// which puts references to the actual OCG objects in the array
var narratives = [{
timestamp_str: "1995-12-12 05:00",
timestamp: 818744400000,
text: "COMEX SERIAL 16D"
},
{
timestamp_str: "1995-12-12 05:01",
timestamp: 818744460000,
text: "INTEND WIDE AREA SEARCH AS PREVIOUS SERIAL"
},
{
timestamp_str: "1995-12-12 05:02",
timestamp: 818744520000,
text: "BRIEFING HINTED THAT TARGET TO SE REALLY LONG TEXT HERE AND MORE AND MORE AND MORE AND MORE"
},
{
timestamp_str: "1995-12-12 05:22",
timestamp: 818745720000,
text: "NO CONTACTS YET, SWITCHING TO SCALE 7"
},
{
timestamp_str: "1995-12-12 06:12",
timestamp: 818748720000,
text: "INVESTIGATING TRACK 14"
},
{
timestamp_str: "1995-12-12 06:22",
timestamp: 818749320000,
text: "POSSUB TRACK 14"
},
{
timestamp_str: "1995-12-12 06:42",
timestamp: 818750520000,
text: "DROP TRACK 14 BIOLOGIC"
},
{
timestamp_str: "1995-12-12 09:53",
timestamp: 818761980000,
text: "HEADING TO RV"
},
{
timestamp_str: "1995-12-12 09:54",
timestamp: 818762040000,
text: "SUSPECT PLAYMATE NOT PRESENT"
},
{
timestamp_str: "1995-12-12 09:57",
timestamp: 818762220000,
text: "SUSPECTED DETECTION OF RED"
},
{
timestamp_str: "1995-12-12 10:03",
timestamp: 818762580000,
text: "CONFIRMED. OBTAIN SOLUTION"
},
{
timestamp_str: "1995-12-12 10:13",
timestamp: 818763180000,
text: "SUSPECT TARGET ZIG"
},
{
timestamp_str: "1995-12-12 10:14",
timestamp: 818763240000,
text: "PORT DETECTION, 16 HZ"
},
{
timestamp_str: "1995-12-12 10:29",
timestamp: 818764140000,
text: "ENTER TRAIL"
},
{
timestamp_str: "1995-12-12 10:37",
timestamp: 818764620000,
text: "TARGET ZIG DETECTED"
},
{
timestamp_str: "1995-12-12 11:19",
timestamp: 818767140000,
text: "FINEX CALLED, ENTER TRANSITION"
},
{
timestamp_str: "1995-12-12 11:20",
timestamp: 818767200000,
text: "ENTERING PLOT-LOCK TRANSITION"
},
{
timestamp_str: "1995-12-12 11:37",
timestamp: 818768220000,
text: "ACTIVE PLOT-LOCK SUCCESSFUL"
},
{
timestamp_str: "1995-12-12 11:41",
timestamp: 818768460000,
text: "RX CONGRATS ON UWT"
},
]
var timestamps = [
{
name: "1995-12-12 05:00",
timestamp: 818744400000,
ocg_name: "1995-12-12 05:00"
},
{
name: "1995-12-12 05:05",
timestamp: 818744700000,
ocg_name: "1995-12-12 05:05"
},
{
name: "1995-12-12 05:10",
timestamp: 818745000000,
ocg_name: "1995-12-12 05:10"
},
{
name: "1995-12-12 05:15",
timestamp: 818745300000,
ocg_name: "1995-12-12 05:15"
},
{
name: "1995-12-12 05:20",
timestamp: 818745600000,
ocg_name: "1995-12-12 05:20"
},
{
name: "1995-12-12 05:25",
timestamp: 818745900000,
ocg_name: "1995-12-12 05:25"
},
{
name: "1995-12-12 05:30",
timestamp: 818746200000,
ocg_name: "1995-12-12 05:30"
},
{
name: "1995-12-12 05:35",
timestamp: 818746500000,
ocg_name: "1995-12-12 05:35"
},
{
name: "1995-12-12 05:40",
timestamp: 818746800000,
ocg_name: "1995-12-12 05:40"
},
{
name: "1995-12-12 05:45",
timestamp: 818747100000,
ocg_name: "1995-12-12 05:45"
},
{
name: "1995-12-12 05:50",
timestamp: 818747400000,
ocg_name: "1995-12-12 05:50"
},
{
name: "1995-12-12 05:55",
timestamp: 818747700000,
ocg_name: "1995-12-12 05:55"
},
{
name: "1995-12-12 06:00",
timestamp: 818748000000,
ocg_name: "1995-12-12 06:00"
},
{
name: "1995-12-12 06:05",
timestamp: 818748300000,
ocg_name: "1995-12-12 06:05"
},
{
name: "1995-12-12 06:10",
timestamp: 818748600000,
ocg_name: "1995-12-12 06:10"
},
{
name: "1995-12-12 06:15",
timestamp: 818748900000,
ocg_name: "1995-12-12 06:15"
},
{
name: "1995-12-12 06:20",
timestamp: 818749200000,
ocg_name: "1995-12-12 06:20"
},
{
name: "1995-12-12 06:25",
timestamp: 818749500000,
ocg_name: "1995-12-12 06:25"
},
{
name: "1995-12-12 06:30",
timestamp: 818749800000,
ocg_name: "1995-12-12 06:30"
},
{
name: "1995-12-12 06:35",
timestamp: 818750100000,
ocg_name: "1995-12-12 06:35"
},
{
name: "1995-12-12 06:40",
timestamp: 818750400000,
ocg_name: "1995-12-12 06:40"
},
{
name: "1995-12-12 06:45",
timestamp: 818750700000,
ocg_name: "1995-12-12 06:45"
},
{
name: "1995-12-12 06:50",
timestamp: 818751000000,
ocg_name: "1995-12-12 06:50"
},
{
name: "1995-12-12 06:55",
timestamp: 818751300000,
ocg_name: "1995-12-12 06:55"
},
{
name: "1995-12-12 07:00",
timestamp: 818751600000,
ocg_name: "1995-12-12 07:00"
},
{
name: "1995-12-12 07:05",
timestamp: 818751900000,
ocg_name: "1995-12-12 07:05"
},
{
name: "1995-12-12 07:10",
timestamp: 818752200000,
ocg_name: "1995-12-12 07:10"
},
{
name: "1995-12-12 07:15",
timestamp: 818752500000,
ocg_name: "1995-12-12 07:15"
},
{
name: "1995-12-12 07:20",
timestamp: 818752800000,
ocg_name: "1995-12-12 07:20"
},
{
name: "1995-12-12 07:25",
timestamp: 818753100000,
ocg_name: "1995-12-12 07:25"
},
{
name: "1995-12-12 07:30",
timestamp: 818753400000,
ocg_name: "1995-12-12 07:30"
},
{
name: "1995-12-12 07:35",
timestamp: 818753700000,
ocg_name: "1995-12-12 07:35"
},
{
name: "1995-12-12 07:40",
timestamp: 818754000000,
ocg_name: "1995-12-12 07:40"
},
{
name: "1995-12-12 07:45",
timestamp: 818754300000,
ocg_name: "1995-12-12 07:45"
},
{
name: "1995-12-12 07:50",
timestamp: 818754600000,
ocg_name: "1995-12-12 07:50"
},
{
name: "1995-12-12 07:55",
timestamp: 818754900000,
ocg_name: "1995-12-12 07:55"
},
{
name: "1995-12-12 08:00",
timestamp: 818755200000,
ocg_name: "1995-12-12 08:00"
},
{
name: "1995-12-12 08:05",
timestamp: 818755500000,
ocg_name: "1995-12-12 08:05"
},
{
name: "1995-12-12 08:10",
timestamp: 818755800000,
ocg_name: "1995-12-12 08:10"
},
{
name: "1995-12-12 08:15",
timestamp: 818756100000,
ocg_name: "1995-12-12 08:15"
},
{
name: "1995-12-12 08:20",
timestamp: 818756400000,
ocg_name: "1995-12-12 08:20"
},
{
name: "1995-12-12 08:25",
timestamp: 818756700000,
ocg_name: "1995-12-12 08:25"
},
{
name: "1995-12-12 08:30",
timestamp: 818757000000,
ocg_name: "1995-12-12 08:30"
},
{
name: "1995-12-12 08:35",
timestamp: 818757300000,
ocg_name: "1995-12-12 08:35"
},
{
name: "1995-12-12 08:40",
timestamp: 818757600000,
ocg_name: "1995-12-12 08:40"
},
{
name: "1995-12-12 08:45",
timestamp: 818757900000,
ocg_name: "1995-12-12 08:45"
},
{
name: "1995-12-12 08:50",
timestamp: 818758200000,
ocg_name: "1995-12-12 08:50"
},
{
name: "1995-12-12 08:55",
timestamp: 818758500000,
ocg_name: "1995-12-12 08:55"
},
{
name: "1995-12-12 09:00",
timestamp: 818758800000,
ocg_name: "1995-12-12 09:00"
},
{
name: "1995-12-12 09:05",
timestamp: 818759100000,
ocg_name: "1995-12-12 09:05"
},
{
name: "1995-12-12 09:10",
timestamp: 818759400000,
ocg_name: "1995-12-12 09:10"
},
{
name: "1995-12-12 09:15",
timestamp: 818759700000,
ocg_name: "1995-12-12 09:15"
},
{
name: "1995-12-12 09:20",
timestamp: 818760000000,
ocg_name: "1995-12-12 09:20"
},
{
name: "1995-12-12 09:25",
timestamp: 818760300000,
ocg_name: "1995-12-12 09:25"
},
{
name: "1995-12-12 09:30",
timestamp: 818760600000,
ocg_name: "1995-12-12 09:30"
},
{
name: "1995-12-12 09:35",
timestamp: 818760900000,
ocg_name: "1995-12-12 09:35"
},
{
name: "1995-12-12 09:40",
timestamp: 818761200000,
ocg_name: "1995-12-12 09:40"
},
{
name: "1995-12-12 09:45",
timestamp: 818761500000,
ocg_name: "1995-12-12 09:45"
},
{
name: "1995-12-12 09:50",
timestamp: 818761800000,
ocg_name: "1995-12-12 09:50"
},
{
name: "1995-12-12 09:55",
timestamp: 818762100000,
ocg_name: "1995-12-12 09:55"
},
{
name: "1995-12-12 10:00",
timestamp: 818762400000,
ocg_name: "1995-12-12 10:00"
},
{
name: "1995-12-12 10:05",
timestamp: 818762700000,
ocg_name: "1995-12-12 10:05"
},
{
name: "1995-12-12 10:10",
timestamp: 818763000000,
ocg_name: "1995-12-12 10:10"
},
{
name: "1995-12-12 10:15",
timestamp: 818763300000,
ocg_name: "1995-12-12 10:15"
},
{
name: "1995-12-12 10:20",
timestamp: 818763600000,
ocg_name: "1995-12-12 10:20"
},
{
name: "1995-12-12 10:25",
timestamp: 818763900000,
ocg_name: "1995-12-12 10:25"
},
{
name: "1995-12-12 10:30",
timestamp: 818764200000,
ocg_name: "1995-12-12 10:30"
},
{
name: "1995-12-12 10:35",
timestamp: 818764500000,
ocg_name: "1995-12-12 10:35"
},
{
name: "1995-12-12 10:40",
timestamp: 818764800000,
ocg_name: "1995-12-12 10:40"
},
{
name: "1995-12-12 10:45",
timestamp: 818765100000,
ocg_name: "1995-12-12 10:45"
},
{
name: "1995-12-12 10:50",
timestamp: 818765400000,
ocg_name: "1995-12-12 10:50"
},
{
name: "1995-12-12 10:55",
timestamp: 818765700000,
ocg_name: "1995-12-12 10:55"
},
{
name: "1995-12-12 11:00",
timestamp: 818766000000,
ocg_name: "1995-12-12 11:00"
},
{
name: "1995-12-12 11:05",
timestamp: 818766300000,
ocg_name: "1995-12-12 11:05"
},
{
name: "1995-12-12 11:10",
timestamp: 818766600000,
ocg_name: "1995-12-12 11:10"
},
{
name: "1995-12-12 11:15",
timestamp: 818766900000,
ocg_name: "1995-12-12 11:15"
},
{
name: "1995-12-12 11:20",
timestamp: 818767200000,
ocg_name: "1995-12-12 11:20"
},
{
name: "1995-12-12 11:25",
timestamp: 818767500000,
ocg_name: "1995-12-12 11:25"
},
{
name: "1995-12-12 11:30",
timestamp: 818767800000,
ocg_name: "1995-12-12 11:30"
},
{
name: "1995-12-12 11:35",
timestamp: 818768100000,
ocg_name: "1995-12-12 11:35"
},
{
name: "1995-12-12 11:40",
timestamp: 818768400000,
ocg_name: "1995-12-12 11:40"
},
{
name: "1995-12-12 11:45",
timestamp: 818768700000,
ocg_name: "1995-12-12 11:45"
},
{
name: "1995-12-12 11:50",
timestamp: 818769000000,
ocg_name: "1995-12-12 11:50"
},
];
function goToFirstTimestep() {
goToTimestepIndex(0);
markSliderPart(0);
lastSliderButtonLocation = 0;
}
function goToTimestepIndex(idx) {
// We can make this efficient because we know that everything is in time
// order, and there will be blocks of timestamps that are on or off
// If the next timestamp to the right is on, then continue searching
// to the right turning timestamps off, until we get to one that is off
// Once we find one that is off we know that all the rest to the right
// of that one will also be off, so we can stop there.
var upwards_idx = idx + 1;
while ((upwards_idx < timestamps.length) && (timestamps[upwards_idx].ocg.state == true)) {
timestamps[upwards_idx].ocg.state = false;
upwards_idx = upwards_idx + 1;
}
// Same as above, but going to the left - if we know it is off then we need
// to turn it on, until we find a block of ones that are on
var downwards_idx = idx - 1;
while ((downwards_idx >= 0) && (timestamps[downwards_idx].ocg.state == false)) {
timestamps[downwards_idx].ocg.state = true;
downwards_idx = downwards_idx - 1;
}
current_index = idx;
// Update the displayed time
var txt = this.getField("txtTime");
txt.value = timestamps[current_index].name;
updateNarrative();
this.dirty = false;
}
function toggleObjectVisible(objName) {
// Takes an object name, gets the object, and toggles its visibility
var obj = this.getField(objName);
if (obj.display == display.visible) {
obj.display = display.hidden;
} else {
obj.display = display.visible;
}
}
function toggleDynamic() {
// Toggles the dynamic UI components by:
// - toggling the state of the toggle button
// - turning on/off the static/dynamic layers
// - making the other UI components visible/invisible
// We use the borderStyle of the button to tell us what
// state it is in
// If it is currently Inset (border.i) then it looks 'pressed' and we
// want to 'unpress' it
if (event.target.borderStyle == border.i) {
// Perform Pop Up Actions - ie. switch back to non-interactive
event.target.borderStyle = border.b; // Bevelled border - looks unpressed
// Restore Up Colors
event.target.fillColor = lightBlue;
unmarkSliderPart(lastSliderButtonLocation);
for (i = 0; i < nonInteractiveLayers.length; i += 1) {
getOCGByName(nonInteractiveLayers[i]).state = true;
}
getOCGByName("Interactive Layers").state = false;
} else {
// Perform Push Down Actions - ie. switch to interactive
event.target.borderStyle = border.i; // Inset border - looks pressed
// Darken Down Colors
event.target.fillColor = darkBlue;
for (i = 0; i < nonInteractiveLayers.length; i += 1) {
getOCGByName(nonInteractiveLayers[i]).state = false;
}
getOCGByName("Interactive Layers").state = true;
goToFirstTimestep();
}
toggleObjectVisible("btnPlayPause");
toggleObjectVisible("btnNext");
toggleObjectVisible("btnPrev");
toggleObjectVisible("txtTime");
toggleObjectVisible("txtNarrative");
for (i = 0; i < timestamps.length; i += 1) {
toggleObjectVisible("btnSlider_" + i);
}
this.dirty = false;
}
function nextTimestep() {
if (current_index >= 0) {
unmarkSliderPart(lastSliderButtonLocation);
}
current_index += 1;
if (current_index > timestamps.length - 1) {
// If we're trying to go past the end of the timestamps array then
// Reset back to the last element
current_index = timestamps.length - 1;
// Stop the animation
if (animate) {
app.clearInterval(animate);
animationRunning = false;
}
// Reset the Play/Pause button state
var btn = this.getField("btnPlayPause");
btn.borderStyle = border.b;
btn.buttonSetCaption(">");
btn.fillColor = lightBlue;
return;
}
// Get the next OCG (layer) and turn it on
timestamps[current_index].ocg.state = true;
// Update the displayed time
var txt = this.getField("txtTime");
txt.value = timestamps[current_index].name;
updateNarrative();
markSliderPart(current_index);
lastSliderButtonLocation = current_index;
this.dirty = false;
}
function prevTimestep() {
// Turn off the current OCG (layer)
timestamps[current_index].ocg.state = false;
unmarkSliderPart(lastSliderButtonLocation);
current_index -= 1;
if (current_index < 0) {
current_index = 0;
}
// Update the displayed time
var txt = this.getField("txtTime");
txt.value = timestamps[current_index].name;
updateNarrative();
markSliderPart(current_index);
lastSliderButtonLocation = current_index;
this.dirty = false;
}
function playPauseAnimation() {
// Plays/Pauses the animation - called from the main playPause function
if (animationRunning) {
app.clearInterval(animate);
animationRunning = false;
}
else {
animate = app.setInterval("nextTimestep()", 1000);
animationRunning = true;
}
}
function playPause() {
// Deals with changing the state of the Play/Pause button and
// then actually plays/pauses the animation
// Again, this uses the button border style to tell us whether we need to
// play or pause
if (event.target.borderStyle == border.i) {
// Perform Pop Up Actions
event.target.borderStyle = border.b; // Bevelled - ie. unpressed
event.target.buttonSetCaption(">");
// Restore Up Colors
event.target.fillColor = lightBlue;
playPauseAnimation();
} else {
// Perform Push Down Actions
event.target.borderStyle = border.i; // Inset - ie. pressed
event.target.buttonSetCaption("||");
// Darken Down Colors
event.target.fillColor = darkBlue;
playPauseAnimation();
}
}
function getOCGByName(name) {
// Gets an OCG (a layer) by name
var ocgs = this.getOCGs();
for (var i = 0; i < ocgs.length; i += 1) {
if (ocgs[i].name == name) {
return ocgs[i];
}
}
return false;
}
function markSliderPart(index) {
var btn = this.getField("btnSlider_" + index);
btn.fillColor = darkBlue;
}
function unmarkSliderPart(index) {
var btn = this.getField("btnSlider_" + index);
btn.fillColor = lightBlue;
}
function calcNewBasePosition() {
// Calculate the new base X and Y position for the UI components from the current
// scroll and zoom position
if (firstRun) {
// On the first run only
// Print these elements to the console. We have to do this to initialise
// the media component - rather strange, but it works.
console.println(app.media);
console.println(this.media);
// Get the DPI, if it's invalid then set to the default of 110
dpi = getDPI();
if (dpi == 0) {
dpi = 110;
}
// The factor of 0.732 here is established by trial and error
// and seems to be the conversion factor between the units of pageViewX/Y
// and actual page units
factor = 0.732 / (dpi / 99);
firstRun = false;
}
var pgRect = this.getPageBox("Crop", 0);
var curView = eval(this.viewState.toSource());
// If nothing has changed since last time, then return
if ((curView.pageViewX == lastPageViewX) & (curView.pageViewY == lastPageViewY) & (curView.pageViewZoom == lastPageViewZoom)) {
return null;
}
// Keep track of the last values
lastPageViewX = curView.pageViewX;
lastPageViewY = curView.pageViewY;
lastPageViewZoom = curView.pageViewZoom;
// Get a zoom factor which is either the current zoom, or 1 if the current zoom is less than 1
var zoomFactor = curView.pageViewZoom < 1 ? 1 : curView.pageViewZoom;
// Calculate the new X and Y base positions based on the factor, the zoom and the current X and Y coords
var yPos = curView.pageViewY >=0 ? (curView.pageViewY + 4) * factor / curView.pageViewZoom : 0;
var xPos = curView.pageViewX >=0 ? (curView.pageViewX + 4) * factor / curView.pageViewZoom : 0;
// the Y values for pageViewY count down from the top of the page, whereas the Y values for locating objects
// on the page count up from the bottom. Take away the co-ords of the top to switch between them.
yPos = pgRect[1] - yPos;
return [xPos, yPos, zoomFactor];
}
function moveField(fldName, xPos, yPos, zoomFactor) {
var fld = this.getField(fldName);
var rect = fld.rect;
// Calculate the new position, based on the stored offsets and sizes, the new position and the zoom scaling factor
rect[0] = xPos + (fld._xOffset / zoomFactor);
rect[1] = yPos + (fld._yOffset / zoomFactor);
rect[2] = xPos + (fld._xOffset / zoomFactor) + (fld._xSize / zoomFactor);
rect[3] = yPos + (fld._yOffset / zoomFactor) - (fld._ySize / zoomFactor);
fld.rect = rect;
if (fld._origTextSize == 0) {
if (zoomFactor >= 4) {
fld.textSize = 2;
} else if (zoomFactor >= 3) {
fld.textSize = 3;
}
else {
fld.textSize = 0;
fld.value = fld.value;
}
} else {
// Scale the text size by the zoom factor too
fld.textSize = fld._origTextSize / zoomFactor;
}
}
function moveAllFields() {
// Delays visually updating the fields while we move them all
this.delay = true;
newPos = calcNewBasePosition();
// If zoom/scroll position hasn't changed then do nothing
if (newPos == null) {
this.delay = false;
return;
}
[xPos, yPos, zoomFactor] = newPos;
// Move each of the main fields
moveField("btnPrev", xPos, yPos, zoomFactor);
moveField("btnDynamicToggle", xPos, yPos, zoomFactor);
moveField("btnNext", xPos, yPos, zoomFactor);
moveField("btnPlayPause", xPos, yPos, zoomFactor);
moveField("txtTime", xPos, yPos, zoomFactor);
moveField("txtNarrative", xPos, yPos, zoomFactor);
// Move the many buttons that make up the slider
for (i = 0; i < timestamps.length; i += 1) {
moveField("btnSlider_" + i, xPos, yPos, zoomFactor);
}
// Updates the display of all fields now we've finished moving them
this.delay = false;
this.dirty = false;
}
function createButton(cName, caption, nPage, xOffset, yOffset, xSize, ySize, hidden, jsCode) {
// Acquire the crop box (visible area) for the current page
var pgRect = this.getPageBox("Crop", nPage);
// Create array for size/location
var fldRect = [];
fldRect[0] = pgRect[0] + xOffset;
fldRect[1] = pgRect[0] + yOffset + ySize;
fldRect[2] = pgRect[0] + xOffset + xSize;
fldRect[3] = pgRect[0] + yOffset;
// Create the button
var oFld = this.addField( cName , "button", nPage, fldRect);
// Set the properties
if (oFld != null) {
oFld.buttonSetCaption(caption);
oFld.borderStyle == border.i;
oFld.strokeColor = color.black;
oFld.textColor = color.black;
oFld.textSize = 20;
oFld.fillColor = lightBlue;
oFld.lineWidth = 0;
if (hidden) {
oFld.display = display.hidden;
}
oFld.setAction("MouseUp", jsCode);
// Store offsets and size in attributes so we can use them later to reposition the button
oFld._xOffset = xOffset;
oFld._yOffset = yOffset;
oFld._xSize = xSize;
oFld._ySize = ySize;
oFld._origTextSize = oFld.textSize;
}
return oFld;
}
function createSliderButton(cName, caption, nPage, xOffset, yOffset, xSize, ySize, hidden, jsCode) {
// Acquire the crop box (visible area) for the current page
var pgRect = this.getPageBox("Crop", nPage);
// Create array for size/location
var fldRect = [];
fldRect[0] = pgRect[0] + xOffset;
fldRect[1] = pgRect[0] + yOffset + ySize;
fldRect[2] = pgRect[0] + xOffset + xSize;
fldRect[3] = pgRect[0] + yOffset;
// Create the button
var oFld = this.addField( cName , "button", nPage, fldRect);
// Set the properties
if (oFld != null) {
oFld.buttonSetCaption(caption);
oFld.borderStyle == border.s; // Solid border
oFld.strokeColor = color.transparent;
oFld.textColor = color.black;
oFld.fillColor = lightBlue;
oFld.lineWidth = 0;
if (hidden) {
oFld.display = display.hidden;
}
oFld.setAction("MouseEnter", jsCode);
// Store offsets and size in attributes so we can use them later to reposition the button
oFld._xOffset = xOffset;
oFld._yOffset = yOffset;
oFld._xSize = xSize;
oFld._ySize = ySize;
oFld._origTextSize = oFld.textSize;
}
return oFld;
}
function createTextbox(cName, contents, nPage, xOffset, yOffset, xSize, ySize, hidden, textSize) {
// Acquire the crop box (visible area) for the current page
var pgRect = this.getPageBox("Crop", nPage);
// Create array for size/location
var fldRect = [];
fldRect[0] = pgRect[0] + xOffset; // left x
fldRect[1] = pgRect[0] + yOffset + ySize; // top y
fldRect[2] = pgRect[0] + xOffset + xSize; // right x
fldRect[3] = pgRect[0] + yOffset; // bottom y
// Create Textbox on page
var oFld = this.addField( cName , "text", nPage, fldRect);
// Setup Textbox's Properties
if (oFld != null) {
oFld.value = contents;
oFld.readonly = true;
oFld.alignment = "center";
oFld.borderStyle == border.i;
oFld.textColor = color.green;
oFld.textSize = textSize;
oFld.fillColor = color.black;
oFld.lineWidth = 0;
if (hidden) {
oFld.display = display.hidden;
}
// Store offsets and size in attributes so we can use them later to reposition the button
oFld._xOffset = xOffset;
oFld._yOffset = yOffset;
oFld._xSize = xSize;
oFld._ySize = ySize;
oFld._origTextSize = oFld.textSize;
}
return oFld;
}
function getDPI(doc){
// Taken from https://community.adobe.com/t5/acrobat/is-there-a-way-to-read-the-user-s-page-display-resolution-preference-setting-from-javascript/td-p/9562886?page=1
if (doc == undefined) {
doc = this;
}
// get current view
var refView = eval(doc.viewState.toSource());
var pBox = doc.getPageBox("Crop", 0);
// Determine page width in inches
var pWidth = ((pBox[2] - pBox[0]) / 72);
// If pageViewZoomType 2 is "fit width" and that's all we need.
if (refView.pageViewZoomType != 2) {
// save current view to return to it so user won't notice pageViewZoomType change.
var curView = eval(doc.viewState.toSource());
// set control values to sample the zoom level at fitwidth on the target page. refView.pageViewPageNum= n;
refView.pageViewX = 0; //Ensure we don't somehow wind up on another page. Though I suspect a pageViewX of > 0 is impossible on fit width...