fixed paths
[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 minusoutline:
105     moveTo -7,2
106     lineTo -7,-2
107     lineTo  7,-2
108     lineTo  7,2
109     lineTo -7,2
110 .end
111
112 .circle shadcircle line=0 fill=#00000033 r=11.5
113
114 .circle outcircle line=2 color=#00000060 fill=grad1 r=11
115 .circle outcircle_over line=2 color=#00000060 fill=grad3 r=11
116
117 .filled incircle outline=arrowoutline fill=grad2 line=1 color=#00000060
118 .filled incircle_over outline=arrowoutline fill=grad4 line=1 color=#00000060
119 .filled lincircle outline=larrowoutline fill=grad2l line=1 color=#00000060
120 .filled lincircle_over outline=larrowoutline fill=grad4l line=1 color=#00000060
121 .filled pincircle outline=plusoutline fill=grad2l line=1 color=#00000060
122 .filled pincircle_over outline=plusoutline fill=grad4l line=1 color=#00000060
123 .filled mincircle outline=minusoutline fill=grad2l line=1 color=#00000060
124 .filled mincircle_over outline=minusoutline fill=grad4l line=1 color=#00000060
125 .filled oincircle outline=oneoneoutline fill=grad2l line=1.2 color=#00000060
126 .filled oincircle_over outline=oneoneoutline fill=grad4l line=1.2 color=#00000060
127
128 .sprite plusface
129  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put pincircle 11 11 pin=center scale=90%
130 .end
131 .sprite plusfaceover 
132  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put pincircle_over 11 11 pin=center scale=90%
133 .end
134 .sprite plusfacedown 
135  .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%
136 .end
137
138 .sprite minusface
139  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put mincircle 11 11 pin=center scale=90% luminance=60%
140 .end
141 .sprite minusfaceover 
142  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put mincircle_over 11 11 pin=center scale=90%
143 .end
144 .sprite minusfacedown 
145  .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%
146 .end
147
148 .sprite rbface
149  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put incircle 13 11 pin=center scale=90%
150 .end
151 .sprite rbfaceover 
152  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put incircle_over 13 11 pin=center scale=90%
153 .end
154 .sprite rbfacedown 
155  .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%
156 .end
157
158 .sprite lbface
159  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put lincircle 9 11 pin=center scale=90%
160 .end
161 .sprite lbfaceover 
162  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put lincircle_over 9 11 pin=center scale=90%
163 .end
164 .sprite lbfacedown 
165  .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%
166 .end
167
168 .sprite obface
169  .put shadcircle 11 13 pin=center .put outcircle 11 11 pin=center .put oincircle 9 11 pin=center scale=90% luminance=50%
170 .end
171 .sprite obfaceover 
172  .put shadcircle 11 13 pin=center .put outcircle_over 11 11 pin=center .put oincircle_over 9 11 pin=center scale=90%
173 .end
174 .sprite obfacedown 
175  .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%
176 .end
177
178 .button rightbutton
179   .show rbface as=idle
180   .show outcircle as=area
181   .show rbfacedown as=pressed
182   .show rbfaceover as=hover
183 .end
184
185 .button leftbutton
186   .show lbface as=idle
187   .show outcircle as=area
188   .show lbfacedown as=pressed
189   .show lbfaceover as=hover
190 .end
191
192 .button plusbutton
193   .show plusface as=idle
194   .show outcircle as=area
195   .show plusfacedown as=pressed
196   .show plusfaceover as=hover
197 .end
198
199 .button minusbutton
200   .show minusface as=idle
201   .show outcircle as=area
202   .show minusfacedown as=pressed
203   .show minusfaceover as=hover
204 .end
205
206 .button oneonebutton
207   .show obface as=idle
208   .show outcircle as=area
209   .show obfacedown as=pressed
210   .show obfaceover as=hover
211 .end
212
213 #======================================== frame ===========================================================
214   
215 .frame 1
216
217 .put p1=plusbutton x=width-25-20 y=20 pin=center
218 .put m1=minusbutton x=width-50-20 y=20 pin=center
219 .put l1=leftbutton x=width/2-100 y=20 pin=center
220 .put r1=rightbutton x=width/2+100 y=20 pin=center
221
222 .put o1=oneonebutton x=width-75-20 y=20 pin=center
223
224 .sprite background
225 .end
226 .put background
227
228 .sprite vscrollbar
229     .box vscroll2_shadow line=0 fill=#00000033 width=14 height=100
230     .sprite vshadow
231     .put vscroll2_shadow x=0 y=0 luminance=1.8
232     .end
233     .put vshadow
234
235     .box vscroll2 width=14 height=100 line=1 color=#00000060 fill=grad7
236     .sprite vbox
237     .put vscroll2 x=0 y=0 luminance=1.5
238     .end
239     .put vbox
240
241     .box tick line=1 color=black width=8 height=0
242
243     .sprite t1 .put tt1=tick y=0 x=3 .end .put t1
244     .sprite t2 .put tt2=tick y=0 x=3 .end .put t2 y=50
245     .sprite t3 .put tt3=tick y=0 x=3 .end .put t3
246     
247     .button vscrollbutton
248         .show vscroll2 as=area
249         .on_press inside:
250             startDrag(false, _parent.fullwidth-22, 40, 
251                              _parent.fullwidth-22, 40+_parent.scrollbaryrange);
252             _parent.Dragging = "v";
253         .end
254         .on_release:
255             stopDrag();
256             _parent.refreshDrag();
257             _parent.Dragging = "";
258         .end
259     .end
260     .put vscrollbutton
261 .end
262
263 .sprite hscrollbar
264     .box hscroll2_shadow width=100 line=0 fill=#00000033 height=14
265     .sprite hshadow
266         .put hscroll2_shadow x=0 y=0 luminance=1.5
267     .end
268     .put hshadow
269
270     .box hscroll2 width=100 height=14 line=1 color=#00000060 fill=grad72
271     .sprite hbox
272     .put hscroll2 x=0 y=0 luminance=1.5
273     .end 
274     .put hbox
275
276     .box htick line=1 color=black width=0 height=8
277
278     .sprite th1 .put tht1=htick x=0 y=3 .end .put th1
279     .sprite th2 .put tht2=htick x=0 y=3 .end .put th2 x=50
280     .sprite th3 .put tht3=htick x=0 y=3 .end .put th3
281
282     .button hscrollbutton
283         .show hscroll2 as=area
284         .on_press inside:
285             startDrag(false, 10                        , _parent.fullheight-22, 
286                              10+_parent.scrollbarxrange, _parent.fullheight-22);
287             _parent.Dragging = "h";
288         .end
289         .on_release:
290             stopDrag();
291             _parent.refreshDrag();
292             _parent.Dragging = "";
293         .end
294     .end
295     .put hscrollbutton
296 .end
297
298 .put hscrollbar y=height-22 x=10
299 .put vscrollbar x=width-22 y=40
300
301 .edittext et width=110 height=20 font=arial size=18pt color=black noselect align=center
302
303 .font dbgarial filename="../wx/Courier.ttf"
304 #.edittext debugtxt width=width height=20 font=dbgarial size=18pt color=#004000 noselect
305 #.put debugtxt y=20
306
307 .put et x=width/2-30 y=8
308
309 #.swf swf filename=paper5.swf
310 .sprite swf
311 .end
312
313 .box f width=100 height=100 line=0 fill=black
314
315 .button areabutton
316     .show f as=area
317     .on_press inside:
318         swf.startDrag(false, left-scrollxrange, top-scrollyrange, left,top);
319         Dragging = "xy";
320     .end
321     .on_release:
322         swf.stopDrag();
323         Dragging = "";
324     .end
325 .end
326 .put areabutton x=10 y=40
327
328 .sprite cf
329     .put f
330 .end
331 .put cliparea=cf x=10 y=40
332 .put swf x=10 y=40
333
334 .action:
335
336     swfwidth = swf._width;
337     swfheight = swf._height;
338
339     Dragging = "";
340     
341     Stage.scaleMode="noScale";
342     Stage.align ="LT";
343     
344     //Stage.showMenu = false;
345
346     fullwidth = Stage.width;
347     fullheight = Stage.height;
348     contentwidth = fullwidth - 40;
349     contentheight = fullheight - 70;
350
351     // move all objects to their proper positions
352     vscrollbar._x = fullwidth-22;
353     hscrollbar._y = fullheight-22;
354     p1._x = fullwidth-25-20 - p1._width/2;
355     o1._x = fullwidth-50-20 - o1._width/2;
356     m1._x = fullwidth-75-20 - m1._width/2;
357
358     l1._x = fullwidth/2-100 - l1._width/2;
359     r1._x = fullwidth/2+100 - r1._width/2;
360
361     et._x = fullwidth/2 - et._width/2;
362
363     //.box f width=width-40 height=height-40-30 line=0 fill=black
364     //.box vscroll1 width=10 height=height-40-30 line=1 color=#00000060 fill=grad7
365     //.box hscroll1 height=10 width=width-40 line=1 color=#00000060 fill=grad72
366     //.put vscroll1 x=width-20 y=40
367     //.put hscroll1 x=10 y=height-20
368         
369     // horizontal scrollbar
370     background.lineStyle(1, 0, 0x60);
371     background.moveTo(10         ,fullheight-20);
372     background.lineTo(10         ,fullheight-10);
373     background.lineTo(10+fullwidth-40,fullheight-10);
374     background.lineTo(10+fullwidth-40,fullheight-20);
375     background.lineTo(10         ,fullheight-20);
376     
377     // vertical scrollbar
378     background.moveTo(fullwidth-20 ,40);
379     background.lineTo(fullwidth-20 ,fullheight-30);
380     background.lineTo(fullwidth-10 ,fullheight-30);
381     background.lineTo(fullwidth-10 ,40);
382     background.lineTo(fullwidth-20 ,40);
383
384     // content area
385     background.lineStyle(1, 0);
386     background.startFill(0x000000);
387     background.moveTo(9, 39);
388     background.lineTo(fullwidth-30+1, 39);
389     background.lineTo(fullwidth-30+1, fullheight-29);
390     background.lineTo(9, fullheight-29);
391     background.lineTo(9, 39);
392     background.endFill();
393     
394     areabutton._xscale = contentwidth;
395     areabutton._yscale = contentheight;
396     cliparea._xscale = contentwidth;
397     cliparea._yscale = contentheight;
398     swf.setMask(cliparea);
399     
400
401     lastzoom = 1;
402
403     zoom = 1;
404         
405     //debugtxt.text = Stage.width+ " x " + Stage.height;
406
407     setPageNr = function() {
408         et.text = "  "+pagenr+" / "+swf._totalframes;
409         swf.gotoAndStop(pagenr);
410     };
411    
412     setNoScrollZoomLevel = function() {
413         // determine initial zoom level
414         xscale = contentwidth / swfwidth;
415         yscale = contentheight / swfheight;
416         if(xscale < yscale) {
417             zoom = xscale;
418             setZoomLevel();
419         } else {
420             zoom = yscale;
421             setZoomLevel();
422         }
423     };
424     
425     set11ZoomLevel = function() {
426         zoom = 1.0;
427         setZoomLevel();
428     };
429
430     swfpos2scrollbars = function() {
431         if(scrollxrange) {
432             hscrollbar._x = 10 + (left-swf._x)*scrollbarxrange/scrollxrange;
433         } else {
434             hscrollbar._x = 10;
435         }
436         if(scrollyrange) {
437             vscrollbar._y = 40 + (top-swf._y)*scrollbaryrange/scrollyrange;
438         } else {
439             vscrollbar._y = 40;
440         }
441     };
442     setZoomLevel = function() {
443
444         width = contentwidth;
445         height = contentheight;
446         left = 10;
447         top = 40;
448
449         if(swfwidth * zoom < contentwidth) {
450             width = swfwidth*zoom;
451             left = 10+(contentwidth-width)/2;
452         }
453         if(swfheight * zoom < contentheight) {
454             height = swfheight*zoom;
455             top = 40+(contentheight-height)/2;
456         }
457             
458         scrollxrange = swfwidth*zoom-width;
459         scrollyrange = swfheight*zoom-height;
460    
461         hscrollbar._xscale = (contentwidth*width) / (swfwidth*zoom);
462         vscrollbar._yscale = (contentheight*height) / (swfheight*zoom);
463         scrollbarxrange = contentwidth - hscrollbar._xscale;
464         scrollbaryrange = contentheight - vscrollbar._yscale;
465         if(scrollbarxrange<0) {
466             scrollbarxrange = 0;
467         }
468         if(scrollbaryrange<0) {
469             scrollbaryrange = 0;
470         }
471
472         swf._xscale = zoom*100;
473         swf._yscale = zoom*100;
474    
475         focusx = contentwidth/2 - (swf._x-10);
476         focusy = contentheight/2 - (swf._y-40);
477
478         swf._x = left - focusx * zoom / lastzoom + width/2;
479         swf._y = top - focusy * zoom / lastzoom + height/2;
480
481         if(swf._x > left) {
482             swf._x = left;
483         } else if(swf._x < left-scrollxrange) {
484             swf._x = left-scrollxrange;
485         } 
486         if(swf._y > top) {
487             swf._y = top;
488         } else if(swf._y < top-scrollyrange) {
489             swf._y = top-scrollyrange;
490         }
491
492         swfpos2scrollbars();
493
494         if(scrollxrange) {
495             hscrollbar._visible = 1;
496         } else {
497             //hscrollbar._visible = 0;
498         }
499         if(scrollyrange) {
500             vscrollbar._visible = 1;
501         } else {
502             //vscrollbar._visible = 0;
503         }
504
505         lastzoom = zoom;
506
507         // update the ruler decorations
508
509         vscrollbar.t1._y = vscrollbar.t2._y - 600.0/vscrollbar._yscale;
510         vscrollbar.t3._y = vscrollbar.t2._y + 600.0/vscrollbar._yscale;
511         hscrollbar.th1._x = hscrollbar.th2._x - 600.0/hscrollbar._xscale;
512         hscrollbar.th3._x = hscrollbar.th2._x + 700.0/hscrollbar._xscale;
513
514         vscrollbar.vshadow._x = vscrollbar.vbox._x + 500/vscrollbar._xscale;
515         vscrollbar.vshadow._y = vscrollbar.vbox._y + 500/vscrollbar._yscale;
516         
517         hscrollbar.hshadow._x = hscrollbar.hbox._x + 500/hscrollbar._xscale;
518         hscrollbar.hshadow._y = hscrollbar.hbox._y + 500/hscrollbar._yscale;
519     };
520
521     pagenr = 1;
522     setPageNr();
523     setNoScrollZoomLevel();
524     //set11ZoomLevel();
525         
526     l1.onRelease = function(){ 
527         if(pagenr > 1) {
528             pagenr = pagenr - 1;
529             setPageNr();
530         }
531     };
532     r1.onRelease = function(){ 
533         if(pagenr < swf._totalframes) {
534             pagenr = pagenr + 1;
535             setPageNr();
536         }
537     };
538     p1.onRelease = function(){ 
539         if(zoom < 4) {
540             zoom = zoom + 1;
541             setZoomLevel();
542         }
543     };
544     m1.onRelease = function(){ 
545         if(zoom > 1) {
546             zoom = zoom - 1;
547             if(zoom < 1)
548                 zoom = 1;
549             setZoomLevel();
550         }
551     };
552     o1.onRelease = function(){ 
553         setNoScrollZoomLevel();
554     };
555     refreshDrag = function(){
556         if(Dragging == "h") {
557             swf._x = left + (10-hscrollbar._x)*scrollxrange/scrollbarxrange;
558         } else if(Dragging == "v") {
559             swf._y = top + (40-vscrollbar._y)*scrollyrange/scrollbaryrange;
560         } else if(Dragging == "xy") {
561             swfpos2scrollbars();
562         }
563     };
564     dragrefresh = setInterval(refreshDrag, 20);
565 .end
566
567 .end