Merge branch 'master' of kramm@git.swftools.org:/home/git/swftools
[swftools.git] / swfs / rfxview.sc
1 # rfxview.sc - a document viewer for pdf2swf converted files
2 #
3 # Copyright (c) 2008 Matthias Kramm 
4
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following condition:
11
12 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18 # THE SOFTWARE.
19
20
21 .flash filename=rfxview.swf fps=30 bbox=600x800 version=8 compress background=#CCCCCC export=0
22
23 .define width 600
24 .define height 800
25
26 #======================================== buttons ===========================================================
27
28 .gradient grad1 radial x=4 y=4 r=28:
29  0% white
30  50% #666666
31  100% #202020
32 .end
33 .gradient grad2 linear width=8 height=6 rotate=120:
34  0% white
35  70% #666666
36  100% #202020  
37 .end
38 .gradient grad4 linear width=8 height=6 rotate=120:
39  0% white
40  70% #999999
41  100% #404040
42 .end
43
44 .gradient grad2l linear width=8 height=6 rotate=120:
45  0% #e0e0e0
46  100% #000000  
47 .end
48 .gradient grad4l linear width=8 height=6 rotate=120:
49  0% #ffffff
50  100% #404040
51 .end
52
53 .gradient grad3 radial x=4 y=4 r=28:
54  0% white
55  70% #999999
56  100% #404040
57 .end
58
59 .gradient grad7 linear rotate=180:
60  0% #777777
61  100% #666666
62 .end
63
64 .gradient grad72 linear rotate=45:
65  0% #999999
66  100% #666666
67 .end
68
69 .outline arrowoutline:
70     moveTo -8,-8
71     lineTo -8, 8
72     lineTo  8, 0
73     lineTo -8,-8
74 .end
75
76 .outline larrowoutline:
77     moveTo 8,-8
78     lineTo 8, 8
79     lineTo -8, 0
80     lineTo 8,-8
81 .end
82
83 .font arialbold filename="../wx/ArialBold.ttf" glyphs="1:"
84 .font arial filename="../wx/Arial.ttf" glyphs="0123456789 /:"
85
86 .textshape oneoneoutline text="1:1" font=arialbold size=14pt
87
88 .outline plusoutline:
89     moveTo  2,-8
90     lineTo -2,-8
91     lineTo -2,-2
92     lineTo -8,-2
93     lineTo -8,2
94     lineTo -2,2
95     lineTo -2,8
96     lineTo  2,8
97     lineTo  2,2
98     lineTo  8,2
99     lineTo  8,-2
100     lineTo  2,-2
101     lineTo  2,-8
102 .end
103
104 .outline zoomoutline:
105     moveTo 8,0 lineTo 4,3 lineTo 4,-3 lineTo 8,0
106     moveTo -8,0 lineTo -4,3 lineTo -4,-3 lineTo -8,0
107     moveTo 0,8 lineTo 3,4 lineTo -3,4 lineTo 0,8
108     moveTo 0,-8 lineTo 3,-4 lineTo -3,-4 lineTo 0,-8
109 .end
110
111 .outline minusoutline:
112     moveTo -7,2
113     lineTo -7,-2
114     lineTo  7,-2
115     lineTo  7,2
116     lineTo -7,2
117 .end
118
119 .circle shadcircle line=0 fill=#00000033 r=11.5
120
121 .circle outcircle line=2 color=#00000060 fill=grad1 r=11
122 .circle outcircle_over line=2 color=#00000060 fill=grad3 r=11
123
124 .filled incircle outline=arrowoutline fill=grad2 line=1 color=#00000060
125 .filled incircle_over outline=arrowoutline fill=grad4 line=1 color=#00000060
126 .filled lincircle outline=larrowoutline fill=grad2l line=1 color=#00000060
127 .filled lincircle_over outline=larrowoutline fill=grad4l line=1 color=#00000060
128 .filled pincircle outline=plusoutline fill=grad2l line=1 color=#00000060
129 .filled pincircle_over outline=plusoutline fill=grad4l line=1 color=#00000060
130 .filled mincircle outline=minusoutline fill=grad2l line=1 color=#00000060
131 .filled mincircle_over outline=minusoutline fill=grad4l line=1 color=#00000060
132 .filled oincircle outline=oneoneoutline fill=grad2l line=1.2 color=#00000060
133 .filled oincircle_over outline=oneoneoutline fill=grad4l line=1.2 color=#00000060
134 .filled zincircle outline=zoomoutline fill=grad2l line=1 color=#00000060
135 .filled zincircle_over outline=zoomoutline fill=grad4l line=1 color=#00000060
136
137 .sprite plusface
138  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put pincircle 11 11 pin=center scale=90%
139 .end
140 .sprite plusfaceover 
141  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put pincircle_over 11 11 pin=center scale=90%
142 .end
143 .sprite plusfacedown 
144  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put pincircle_over 11 11 pin=center scale=79%
145 .end
146
147 .sprite minusface
148  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put mincircle 11 11 pin=center scale=90% luminance=60%
149 .end
150 .sprite minusfaceover 
151  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put mincircle_over 11 11 pin=center scale=90%
152 .end
153 .sprite minusfacedown 
154  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put mincircle_over 11 11 pin=center scale=79%
155 .end
156
157 .sprite rbface
158  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put incircle 13 11 pin=center scale=90%
159 .end
160 .sprite rbfaceover 
161  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put incircle_over 13 11 pin=center scale=90%
162 .end
163 .sprite rbfacedown 
164  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put incircle_over 13 11 pin=center scale=79%
165 .end
166
167 .sprite lbface
168  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put lincircle 9 11 pin=center scale=90%
169 .end
170 .sprite lbfaceover 
171  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put lincircle_over 9 11 pin=center scale=90%
172 .end
173 .sprite lbfacedown 
174  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put lincircle_over 9 11 pin=center scale=79%
175 .end
176
177 .sprite obface
178  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put oincircle 9 11 pin=center scale=90% luminance=50%
179 .end
180 .sprite obfaceover 
181  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put oincircle_over 9 11 pin=center scale=90%
182 .end
183 .sprite obfacedown 
184  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put oincircle_over 9 11 pin=center scale=79%
185 .end
186
187 .sprite zbface
188  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put zincircle 10 11 pin=center scale=90% luminance=50%
189 .end
190 .sprite zbfaceover 
191  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put zincircle_over 10 11 pin=center scale=90%
192 .end
193 .sprite zbfacedown 
194  .put shadcircle 11 13 pin=center scale=90% .put outcircle_over 11 11 pin=center scale=90% .put zincircle_over 10 11 pin=center scale=79%
195 .end
196
197 .button rightbutton
198   .show rbface as=idle
199   .show outcircle as=area
200   .show rbfacedown as=pressed
201   .show rbfaceover as=hover
202 .end
203
204 .button leftbutton
205   .show lbface as=idle
206   .show outcircle as=area
207   .show lbfacedown as=pressed
208   .show lbfaceover as=hover
209 .end
210
211 .button plusbutton
212   .show plusface as=idle
213   .show outcircle as=area
214   .show plusfacedown as=pressed
215   .show plusfaceover as=hover
216 .end
217
218 .button minusbutton
219   .show minusface as=idle
220   .show outcircle as=area
221   .show minusfacedown as=pressed
222   .show minusfaceover as=hover
223 .end
224
225 .button oneonebutton
226   .show obface as=idle
227   .show outcircle as=area
228   .show obfacedown as=pressed
229   .show obfaceover as=hover
230 .end
231
232 .button fullsizebutton
233   .show zbface as=idle
234   .show outcircle as=area
235   .show zbfacedown as=pressed
236   .show zbfaceover as=hover
237 .end
238
239 #======================================== frame ===========================================================
240   
241 .frame 1
242
243 .put p1=plusbutton x=width-25-20 y=20 pin=center
244 .put m1=minusbutton x=width-50-20 y=20 pin=center
245 .put o1=oneonebutton x=width-75-20 y=20 pin=center
246 .put z1=fullsizebutton x=width-100-20 y=20 pin=center
247
248 .put l1=leftbutton x=width/2-100 y=20 pin=center
249 .put r1=rightbutton x=width/2+100 y=20 pin=center
250
251 .sprite background
252 .end
253 .put background
254
255 .sprite vscrollbar
256     .box vscroll2_shadow line=0 fill=#00000033 width=14 height=100
257     .sprite vshadow
258     .put vscroll2_shadow x=0 y=0 luminance=1.8
259     .end
260     .put vshadow
261
262     .box vscroll2 width=14 height=100 line=1 color=#00000060 fill=grad7
263     .sprite vbox
264     .put vscroll2 x=0 y=0 luminance=1.5
265     .end
266     .put vbox
267
268     .box tick line=1 color=black width=8 height=0
269
270     .sprite t1 .put tt1=tick y=0 x=3 .end .put t1
271     .sprite t2 .put tt2=tick y=0 x=3 .end .put t2 y=50
272     .sprite t3 .put tt3=tick y=0 x=3 .end .put t3
273     
274     .button vscrollbutton
275         .show vscroll2 as=area
276         .on_press inside:
277             startDrag(false, _parent.fullwidth-22, 40, 
278                              _parent.fullwidth-22, 40+_parent.scrollbaryrange);
279             _parent.Dragging = "v";
280         .end
281         .on_release:
282             stopDrag();
283             _parent.refreshDrag();
284             _parent.Dragging = "";
285         .end
286     .end
287     .put vscrollbutton
288 .end
289
290 .sprite hscrollbar
291     .box hscroll2_shadow width=100 line=0 fill=#00000033 height=14
292     .sprite hshadow
293         .put hscroll2_shadow x=0 y=0 luminance=1.5
294     .end
295     .put hshadow
296
297     .box hscroll2 width=100 height=14 line=1 color=#00000060 fill=grad72
298     .sprite hbox
299     .put hscroll2 x=0 y=0 luminance=1.5
300     .end 
301     .put hbox
302
303     .box htick line=1 color=black width=0 height=8
304
305     .sprite th1 .put tht1=htick x=0 y=3 .end .put th1
306     .sprite th2 .put tht2=htick x=0 y=3 .end .put th2 x=50
307     .sprite th3 .put tht3=htick x=0 y=3 .end .put th3
308
309     .button hscrollbutton
310         .show hscroll2 as=area
311         .on_press inside:
312             startDrag(false, 10                        , _parent.fullheight-22, 
313                              10+_parent.scrollbarxrange, _parent.fullheight-22);
314             _parent.Dragging = "h";
315         .end
316         .on_release:
317             stopDrag();
318             _parent.refreshDrag();
319             _parent.Dragging = "";
320         .end
321     .end
322     .put hscrollbutton
323 .end
324
325 .put hscrollbar y=height-22 x=10
326 .put vscrollbar x=width-22 y=40
327
328 .edittext et width=50 height=20 font=arial size=18pt color=black variable=current_pagenumber maxlength=3 text="1" align=left
329 .edittext etmiddle text="/" width=10 height=25 font=arial color=black noselect size=18pt align=center
330 .edittext et_total_pages width=50 height=25 font=arial color=black noselect size=18pt align=right
331
332 #.font dbgarial filename="Courier.ttf"
333 #.edittext debugtxt width=width height=20 font=dbgarial size=18pt color=#004000 noselect
334 #.put debugtxt y=20
335
336 .put et x=width/2-55 y=8
337 .put etmiddle x=width/2-5 y=8
338 .put et_total_pages x=width/2+5 y=8
339
340 #.swf viewport filename=paper5.viewport
341 .sprite viewport
342 .end
343
344 .box f width=100 height=100 line=0 fill=black
345
346 .button areabutton
347     .show f as=area
348     .on_press inside:
349         viewport.startDrag(false, left-scrollxrange, top-scrollyrange, left,top);
350         Dragging = "xy";
351     .end
352     .on_release:
353         viewport.stopDrag();
354         Dragging = "";
355     .end
356 .end
357 .put areabutton x=10 y=40
358
359 .sprite cf
360     .put f
361 .end
362 .put cliparea=cf x=10 y=40
363 .put viewport x=10 y=40
364
365
366 .action:
367     et_total_pages.text=viewport._totalframes;
368     swfwidth = viewport._width;
369     swfheight = viewport._height;
370
371     Dragging = "";
372     
373     Stage.scaleMode="noScale";
374     Stage.align ="LT";
375     
376     //Stage.showMenu = false;
377
378     fullwidth = Stage.width;
379     fullheight = Stage.height;
380     contentwidth = fullwidth - 40;
381     contentheight = fullheight - 70;
382
383     // move all objects to their proper positions
384     vscrollbar._x = fullwidth-22;
385     hscrollbar._y = fullheight-22;
386     p1._x = fullwidth-25-20 - p1._width/2;
387     o1._x = fullwidth-50-20 - o1._width/2;
388     z1._x = fullwidth-75-20 - z1._width/2;
389     m1._x = fullwidth-100-20 - m1._width/2;
390
391     l1._x = fullwidth/2-100 - l1._width/2;
392     r1._x = fullwidth/2+100 - r1._width/2;
393
394     et._x = fullwidth/2 - (et._width+etmiddle._width+et_total_pages._width)/2;
395     etmiddle._x = fullwidth/2 - (et._width+etmiddle._width+et_total_pages._width)/2 + et._width;
396     et_total_pages._x = fullwidth/2 - (et._width+etmiddle._width+et_total_pages._width)/2 + et._width+etmiddle._width;
397
398     //.box f width=width-40 height=height-40-30 line=0 fill=black
399     //.box vscroll1 width=10 height=height-40-30 line=1 color=#00000060 fill=grad7
400     //.box hscroll1 height=10 width=width-40 line=1 color=#00000060 fill=grad72
401     //.put vscroll1 x=width-20 y=40
402     //.put hscroll1 x=10 y=height-20
403         
404     // horizontal scrollbar
405     background.lineStyle(1, 0, 0x60);
406     background.moveTo(10         ,fullheight-20);
407     background.lineTo(10         ,fullheight-10);
408     background.lineTo(10+fullwidth-40,fullheight-10);
409     background.lineTo(10+fullwidth-40,fullheight-20);
410     background.lineTo(10         ,fullheight-20);
411     
412     // vertical scrollbar
413     background.moveTo(fullwidth-20 ,40);
414     background.lineTo(fullwidth-20 ,fullheight-30);
415     background.lineTo(fullwidth-10 ,fullheight-30);
416     background.lineTo(fullwidth-10 ,40);
417     background.lineTo(fullwidth-20 ,40);
418
419     // content area
420     background.lineStyle(1, 0);
421     background.startFill(0x000000);
422     background.moveTo(9, 39);
423     background.lineTo(fullwidth-30+1, 39);
424     background.lineTo(fullwidth-30+1, fullheight-29);
425     background.lineTo(9, fullheight-29);
426     background.lineTo(9, 39);
427     background.endFill();
428     
429     areabutton._xscale = contentwidth;
430     areabutton._yscale = contentheight;
431     cliparea._xscale = contentwidth;
432     cliparea._yscale = contentheight;
433     viewport.setMask(cliparea);
434     
435
436     lastzoom = 1;
437
438     zoom = 1;
439         
440     //debugtxt.text = Stage.width+ " x " + Stage.height;
441     //debugtxt.text = zoomtype;
442
443     setPageNr = function() {
444         current_pagenumber = pagenr;
445         viewport.gotoAndStop(pagenr);
446     };
447    
448     setNoScrollZoomLevel = function() {
449         // determine initial zoom level
450         xscale = contentwidth / swfwidth;
451         yscale = contentheight / swfheight;
452         if(xscale < yscale) {
453             zoom = xscale;
454             setZoomLevel();
455         } else {
456             zoom = yscale;
457             setZoomLevel();
458         }
459     };
460     
461     setOneDirScrollZoomLevel = function() {
462         xscale = contentwidth / swfwidth;
463         yscale = contentheight / swfheight;
464         if(xscale > yscale) {
465             zoom = xscale;
466             setZoomLevel();
467         } else {
468             zoom = yscale;
469             setZoomLevel();
470         }
471     };
472    
473     set11ZoomLevel = function() {
474         zoom = 1.0;
475         setZoomLevel();
476     };
477
478     swfpos2scrollbars = function() {
479         if(scrollxrange) {
480             hscrollbar._x = 10 + (left-viewport._x)*scrollbarxrange/scrollxrange;
481         } else {
482             hscrollbar._x = 10;
483         }
484         if(scrollyrange) {
485             vscrollbar._y = 40 + (top-viewport._y)*scrollbaryrange/scrollyrange;
486         } else {
487             vscrollbar._y = 40;
488         }
489     };
490     setZoomLevel = function() {
491
492         width = contentwidth;
493         height = contentheight;
494         left = 10;
495         top = 40;
496
497         if(swfwidth * zoom < contentwidth) {
498             width = swfwidth*zoom;
499             left = 10+(contentwidth-width)/2;
500         }
501         if(swfheight * zoom < contentheight) {
502             height = swfheight*zoom;
503             top = 40+(contentheight-height)/2;
504         }
505             
506         scrollxrange = swfwidth*zoom-width;
507         scrollyrange = swfheight*zoom-height;
508    
509         hscrollbar._xscale = (contentwidth*width) / (swfwidth*zoom);
510         vscrollbar._yscale = (contentheight*height) / (swfheight*zoom);
511         scrollbarxrange = contentwidth - hscrollbar._xscale;
512         scrollbaryrange = contentheight - vscrollbar._yscale;
513         if(scrollbarxrange<0) {
514             scrollbarxrange = 0;
515         }
516         if(scrollbaryrange<0) {
517             scrollbaryrange = 0;
518         }
519
520         viewport._xscale = zoom*100;
521         viewport._yscale = zoom*100;
522    
523         focusx = contentwidth/2 - (viewport._x-10);
524         focusy = contentheight/2 - (viewport._y-40);
525
526         viewport._x = left - focusx * zoom / lastzoom + width/2;
527         viewport._y = top - focusy * zoom / lastzoom + height/2;
528
529         if(viewport._x > left) {
530             viewport._x = left;
531         } else if(viewport._x < left-scrollxrange) {
532             viewport._x = left-scrollxrange;
533         } 
534         if(viewport._y > top) {
535             viewport._y = top;
536         } else if(viewport._y < top-scrollyrange) {
537             viewport._y = top-scrollyrange;
538         }
539
540         swfpos2scrollbars();
541
542         if(scrollxrange) {
543             hscrollbar._visible = 1;
544         } else {
545             //hscrollbar._visible = 0;
546         }
547         if(scrollyrange) {
548             vscrollbar._visible = 1;
549         } else {
550             //vscrollbar._visible = 0;
551         }
552
553         lastzoom = zoom;
554
555         // update the ruler decorations
556
557         vscrollbar.t1._y = vscrollbar.t2._y - 600.0/vscrollbar._yscale;
558         vscrollbar.t3._y = vscrollbar.t2._y + 600.0/vscrollbar._yscale;
559         hscrollbar.th1._x = hscrollbar.th2._x - 600.0/hscrollbar._xscale;
560         hscrollbar.th3._x = hscrollbar.th2._x + 700.0/hscrollbar._xscale;
561
562         vscrollbar.vshadow._x = vscrollbar.vbox._x + 500/vscrollbar._xscale;
563         vscrollbar.vshadow._y = vscrollbar.vbox._y + 500/vscrollbar._yscale;
564         
565         hscrollbar.hshadow._x = hscrollbar.hbox._x + 500/hscrollbar._xscale;
566         hscrollbar.hshadow._y = hscrollbar.hbox._y + 500/hscrollbar._yscale;
567     };
568
569     pagenr = 1;
570     setPageNr();
571
572     if(zoomtype=="1") {
573         set11ZoomLevel();
574     } else if(zoomtype=="2") {
575         setNoScrollZoomLevel();
576     } else {
577         setOneDirScrollZoomLevel();
578     }
579         
580     et.onChanged = function(){
581         if(current_pagenumber <= viewport._totalframes) {
582             if (current_pagenumber > 0) {
583                 pagenr = int(current_pagenumber);
584                 setPageNr();
585             }
586         }
587     };
588     l1.onRelease = function(){ 
589         if(pagenr > 1) {
590             pagenr = pagenr - 1;
591             setPageNr();
592         }
593     };
594     r1.onRelease = function(){ 
595         if(pagenr < viewport._totalframes) {
596             pagenr = pagenr + 1;
597             setPageNr();
598         }
599     };
600     p1.onRelease = function(){ 
601         if(zoom < 4) {
602             zoom = zoom + 1;
603             setZoomLevel();
604         }
605     };
606     m1.onRelease = function(){ 
607         if(zoom > 1) {
608             zoom = zoom - 1;
609             if(zoom < 1)
610                 zoom = 1;
611             setZoomLevel();
612         }
613     };
614     o1.onRelease = function(){ 
615         setNoScrollZoomLevel();
616     };
617     z1.onRelease = function(){ 
618         setOneDirScrollZoomLevel();
619     };
620     refreshDrag = function(){
621         if(Dragging == "h") {
622             viewport._x = left + (10-hscrollbar._x)*scrollxrange/scrollbarxrange;
623         } else if(Dragging == "v") {
624             viewport._y = top + (40-vscrollbar._y)*scrollyrange/scrollbaryrange;
625         } else if(Dragging == "xy") {
626             swfpos2scrollbars();
627         }
628     };
629     dragrefresh = setInterval(refreshDrag, 20);
630 .end
631
632 .end