Debian Codegraph @

texmf-dist/source/latex/media9/players/SlideShow.mxml

raw
1 <?xml version="1.0"?>
2 <!-- -->
3 <!-- Apache Flex 4 source file of SlideShow.swf, -->
4 <!-- a FlashPlayer-10 compatible component for -->
5 <!-- JPEG/PNG/GIF slideshows. -->
6 <!-- -->
7 <!-- version 20150718 -->
8 <!-- -->
9 <!-- -->
10 <!-- The free Apache Flex 4 SDK is required to compile -->
11 <!-- this file. Get it from -->
12 <!-- -->
13 <!-- http://flex.apache.org/download-binaries.html -->
14 <!-- -->
15 <!-- and run -->
16 <!-- -->
17 <!-- mxmlc -static-link-runtime-shared-libraries SlideShow.mxml -->
18 <!-- -->
19 <!-- on the command line. -->
20 <!-- -->
21 <!-- -->
22 <!-- Copyright (C) 2015-today Alexander Grahn -->
23 <!-- -->
24 <!-- This work may be distributed and/or modified under the -->
25 <!-- conditions of the LaTeX Project Public License. -->
26 <!-- -->
27 <!-- The latest version of this license is in -->
28 <!-- http://www.latex-project.org/lppl.txt -->
29 <!-- -->
30 <!-- This work has the LPPL maintenance status `maintained'. -->
31 <!-- -->
32 <!-- The current maintainer of this work is A. Grahn. -->
33 <!-- -->
34 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
35 xmlns:s="library://ns.adobe.com/flex/spark"
36 xmlns:mx="library://ns.adobe.com/flex/mx"
37 preinitialize="initialise(this.parameters);"
38 applicationComplete="initApp();"
39 resize="if(dynResolution){dynResolution=false;forcedByUsr=true;setImgSrc();}"
40 backgroundAlpha="0"
41 >
42 <fx:Script>
43 <![CDATA[
44 import mx.managers.CursorManager;
45
46 private var slideshowXML:XML;
47 private var setXMLDone:Boolean;
48 private var isEnabled:Boolean=true;
49
50 private function setXML(s:String):void {
51 var loader:URLLoader = new URLLoader();
52 loader.addEventListener(Event.COMPLETE, onURLLoaderComplete);
53 loader.addEventListener(IOErrorEvent.IO_ERROR, onAnyError);
54 loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onAnyError);
55 isEnabled=false;
56 slideshowXML=null;
57 setXMLDone=false;
58 isIOError=true;
59 CursorManager.setBusyCursor();
60 timeoutTimer.start();
61 loader.load(new URLRequest(s));
62 }
63
64 private function onURLLoaderComplete(event:Event):void
65 {
66 CursorManager.removeBusyCursor();
67 isEnabled=true;
68 var loader:URLLoader = event.target as URLLoader;
69 if (loader != null)
70 {
71 slideshowXML = new XML(loader.data);
72 setXMLDone=true;
73 rotations=new Object();
74 seek(0);
75 if(autoPlay) play();
76 }
77 }
78
79 [Bindable] private var delay:Number=5;
80 [Bindable] private var autoPlay:Boolean=false;
81 private var xmlfile:String=null;
82
83 private function initialise(flashVars:Object):void {
84 xmlfile=flashVars.xml;
85 if(flashVars.delay){delay=flashVars.delay}
86 if(flashVars.autoPlay=='true'){autoPlay=true}
87 }
88
89 private var reloadTimer:Timer = null;
90 private var playTimer:Timer = null;
91 private var timeoutTimer:Timer;
92 private var curFile:String;
93
94 private var idx:Number=0;
95 private var urlIdx:Number=0;
96 [Bindable] private var src1:String;
97 [Bindable] private var src2:String;
98
99 private var rotations:Object;
100
101 private function rotate(n:Number=1):void {
102 if(Img1.visible){
103 n==0 ? Img1.rotation=0 : Img1.rotation+=90*Math.floor(n);
104 Img1.rotation%=360;
105 rotations[slideshowXML.Img[idx].URL[urlIdx].toString()]=
106 Img1.rotation/90;
107 } else {
108 n==0 ? Img2.rotation=0 : Img2.rotation+=90*Math.floor(n);
109 Img2.rotation%=360;
110 rotations[slideshowXML.Img[idx].URL[urlIdx].toString()]=
111 Img2.rotation/90;
112 }
113 }
114
115 import mx.collections.ArrayCollection;
116 import spark.collections.Sort;
117 import spark.collections.SortField;
118
119 private var forcedByUsr:Boolean;
120 private var dynResolution:Boolean;
121
122 private function setImgSrc():void {
123 if(reloadTimer && reloadTimer.hasEventListener(TimerEvent.TIMER)){
124 reloadTimer.removeEventListener(TimerEvent.TIMER, reloadImg);
125 reloadTimer=null;
126 }
127 if(setXMLDone && slideshowXML && (isEnabled||forcedByUsr)){
128 isEnabled=false;
129 forcedByUsr=false;
130 CursorManager.removeBusyCursor();
131 CursorManager.setBusyCursor();
132 timeoutTimer.start();
133 isIOError=true;
134
135 urlIdx=0;
136 if(slideshowXML.Img[idx].URL.length()>1){
137 var sizes:ArrayCollection = new ArrayCollection();
138 for(var i:Number=0; i<slideshowXML.Img[idx].URL.length(); i++){
139 var sizeStr:String=slideshowXML.Img[idx].URL[i].attribute("size");
140 if(sizeStr.match(/^\s*[0-9]+x[0-9]+\s*$/)){
141 var xsize:Number=Number(sizeStr.replace(/x[0-9]+/, ""));
142 var ysize:Number=Number(sizeStr.replace(/[0-9]+x/, ""));
143 sizes.addItem(
144 {size: xsize*ysize, index: i, x: xsize, y: ysize});
145 }
146 }
147 if(sizes.length>0){
148 dynResolution=true;
149 var sort:Sort = new Sort();
150 sort.fields=[new SortField("size",true,true)];
151 sizes.sort=sort;// ^--descending order
152 sizes.refresh();
153
154 urlIdx=sizes.getItemAt(0).index;
155 for(i=0; i<sizes.length; i++){
156 if(
157 sizes.getItemAt(i).x >= this.width ||
158 sizes.getItemAt(i).y >= this.height
159 ) urlIdx=sizes.getItemAt(i).index;
160 }
161 }
162 }
163
164 curFile=slideshowXML.Img[idx].URL[urlIdx].toString();
165
166 var pattern:RegExp;
167 if(slideshowXML.Img[idx].URL[urlIdx].attribute('height').length() > 0){
168 pattern = new RegExp(
169 slideshowXML.Img[idx].URL[urlIdx].attribute('height'), "g");
170 if(curFile.search(pattern)>-1){
171 dynResolution=true;
172 curFile=curFile.replace(pattern, this.height.toString());
173 }
174 }
175
176 if(slideshowXML.Img[idx].URL[urlIdx].attribute('width').length() > 0){
177 pattern = new RegExp(
178 slideshowXML.Img[idx].URL[urlIdx].attribute('width'), "g");
179 if(curFile.search(pattern)>-1){
180 dynResolution=true;
181 curFile=curFile.replace(pattern, this.width.toString());
182 }
183 }
184
185 if(Img1.visible) {
186 src2=null; src2=curFile;
187 } else {
188 src1=null; src1=curFile;
189 }
190 }
191 if(slideshowXML.Img[idx].attribute('live')>0){
192 reloadTimer=new Timer(slideshowXML.Img[idx].attribute('live')*1000,1);
193 reloadTimer.addEventListener(TimerEvent.TIMER, reloadImg);
194 reloadTimer.start();
195 }
196 }
197
198 private var isReload:Boolean;
199 private function reloadImg(e:TimerEvent):void {
200 isReload=true; setImgSrc();
201 }
202
203 private var isPlaying:Boolean=false;
204
205 private function playPause():void {
206 if(isPlaying) pause(); else play();
207 }
208
209 private function play():void {
210 if(!isPlaying && slideshowXML.Img.length()>1) {
211 if(!playTimer){
212 playTimer=new Timer(delay*1000, 0);
213 playTimer.addEventListener(TimerEvent.TIMER, nextSlide);
214 }
215 isPlaying=true;
216 playTimer.start();
217 }
218 }
219
220 private function pause():void {
221 if(isPlaying) {
222 isPlaying=false;
223 playTimer.stop();
224 }
225 }
226
227 private function nextSlide(e:Event=null):void {
228 if(!isEnabled && !forcedByUsr) return;
229 if(isPlaying) playTimer.stop();
230 var evnt:MouseEvent = e as MouseEvent;
231 if(evnt && evnt.type=="mouseUp" && evnt.shiftKey) {
232 prevSlide();
233 } else {
234 idx++;
235 if(idx==slideshowXML.Img.length()) idx=0;
236 isReload=false;
237 setImgSrc();
238 }
239 }
240
241 private function prevSlide(e:MouseEvent=null):void {
242 if(!isEnabled && !forcedByUsr) return;
243 if(isPlaying) playTimer.stop();
244 idx--;
245 if(idx<0) idx=slideshowXML.Img.length()-1;
246 isReload=false;
247 setImgSrc();
248 }
249
250 private function seek(i:Number):void {
251 if(!isEnabled && !forcedByUsr) return;
252 if(isPlaying) playTimer.stop();
253 if(i<0 || i>=slideshowXML.Img.length())
254 idx=slideshowXML.Img.length()-1;
255 else
256 idx=Math.floor(i);
257 isReload=false;
258 setImgSrc();
259 }
260
261 private function onKeyDown(e:KeyboardEvent):void {
262 forcedByUsr=true;
263 switch(e.keyCode) {
264 case 32: //space bar
265 playPause();
266 break;
267 case 36: //home
268 if(isPlaying) pause();
269 seek(0);
270 break;
271 case 35: //end
272 if(isPlaying) pause();
273 seek(-1);
274 break;
275 case 37: //<--
276 prevSlide();
277 break;
278 case 39: //-->
279 nextSlide();
280 break;
281 case 82: //`r'
282 e.shiftKey ? rotate(-1) : rotate();
283 break;
284 }
285 }
286
287 private function slideNum():Number {return idx;}
288
289 private function numSlides():Number {return slideshowXML.Img.length();}
290
291 private function playing():Boolean {return isPlaying;}
292
293 private function initApp():void {
294 this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
295 ExternalInterface.addCallback("setXML", setXML);
296 ExternalInterface.addCallback("play",
297 function():void{forcedByUsr=true;play();});
298 ExternalInterface.addCallback("pause",
299 function():void{forcedByUsr=true;pause();});
300 ExternalInterface.addCallback("playPause",
301 function():void{forcedByUsr=true;playPause();});
302 ExternalInterface.addCallback("seek",
303 function(i:Number):void{forcedByUsr=true;seek(i);});
304 ExternalInterface.addCallback("slideNum", slideNum);
305 ExternalInterface.addCallback("numSlides", numSlides);
306 ExternalInterface.addCallback("playing", playing);
307 ExternalInterface.addCallback("rotate", rotate);
308
309 var itemNextSlide:ContextMenuItem =
310 new ContextMenuItem("Next Slide, [\u2192]");
311 this.contextMenu.customItems.push(itemNextSlide);
312 itemNextSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
313 function(e:ContextMenuEvent):void{forcedByUsr=true;nextSlide();});
314
315 var itemPrevSlide:ContextMenuItem =
316 new ContextMenuItem("Previous Slide, [\u2190]");
317 this.contextMenu.customItems.push(itemPrevSlide);
318 itemPrevSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
319 function(e:ContextMenuEvent):void{forcedByUsr=true;prevSlide();});
320
321 var itemPlayPause:ContextMenuItem = new ContextMenuItem("N.N.");
322 this.contextMenu.customItems.push(itemPlayPause);
323 itemPlayPause.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
324 function(e:ContextMenuEvent):void{forcedByUsr=true;playPause();});
325
326 var itemFirstSlide:ContextMenuItem =
327 new ContextMenuItem("First Slide, [Home]");
328 this.contextMenu.customItems.push(itemFirstSlide);
329 itemFirstSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
330 function(e:ContextMenuEvent):void{
331 forcedByUsr=true;if(isPlaying) pause();seek(0);});
332
333 var itemLastSlide:ContextMenuItem =
334 new ContextMenuItem("Last Slide, [End]");
335 this.contextMenu.customItems.push(itemLastSlide);
336 itemLastSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
337 function(e:ContextMenuEvent):void{
338 forcedByUsr=true;if(isPlaying) pause();seek(-1);});
339
340 var itemRotRight:ContextMenuItem =
341 new ContextMenuItem("Rotate Right, [r]");
342 this.contextMenu.customItems.push(itemRotRight);
343 itemRotRight.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
344 function(e:ContextMenuEvent):void{forcedByUsr=true;rotate();});
345
346 var itemRotLeft:ContextMenuItem =
347 new ContextMenuItem("Rotate Left, [\u21e7]+[r]");
348 this.contextMenu.customItems.push(itemRotLeft);
349 itemRotLeft.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
350 function(e:ContextMenuEvent):void{forcedByUsr=true;rotate(-1);});
351
352 this.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,
353 function(e:ContextMenuEvent):void{
354 itemPlayPause.caption=(isPlaying ? "Pause" : "Play")+", [Space]";
355 itemPlayPause.visible=itemNextSlide.visible=itemPrevSlide.visible=
356 itemFirstSlide.visible=itemLastSlide.visible=false;
357 if(slideshowXML.Img.length()>1){
358 itemPlayPause.visible=itemNextSlide.visible=itemPrevSlide.visible=
359 itemFirstSlide.visible=itemLastSlide.visible=true;
360 }
361 });
362
363 timeoutTimer=new Timer(30000, 1);
364 timeoutTimer.addEventListener(TimerEvent.TIMER, onAnyError);
365 curFile=xmlfile; if(xmlfile) setXML(xmlfile);
366 CursorManager.hideCursor();
367 }
368
369 private var isIOError:Boolean;
370 private function onAnyError(e:Event):void {
371 if(e.type!=IOErrorEvent.IO_ERROR || setXMLDone==false){
372 isIOError=false;
373 setXMLDone=true;
374 if(Img1.visible){
375 src2=null; src2="/dev/null"
376 }else{
377 src1=null; src1="/dev/null"
378 }
379 caption.text=e.type+': '+curFile;
380 if(e.type==TimerEvent.TIMER)
381 caption.text="timeout after 30 s: "+curFile;
382 CursorManager.removeBusyCursor();
383 }else{
384 if(isIOError) caption.text=e.type+': '+curFile;
385 onImgDone(e);
386 }
387 caption.visible=true;
388 if(reloadTimer && reloadTimer.hasEventListener(TimerEvent.TIMER)){
389 reloadTimer.removeEventListener(TimerEvent.TIMER, reloadImg);
390 reloadTimer=null; isReload=false;
391 }
392 }
393
394 private function onImgDone(e:Event):void {
395 timeoutTimer.reset();
396 if(e.target==Img1){
397 Img1.visible=true;Img2.visible=false;
398 } else {
399 Img2.visible=true;Img1.visible=false;
400 }
401 if(slideshowXML.Img.length()>1){
402 slideNo.text=String(idx+1)+"/"+slideshowXML.Img.length().toString();
403 slideNo.visible=slideNo.includeInLayout=true;
404 } else {
405 slideNo.visible=slideNo.includeInLayout=false;
406 }
407 var curRot:Number=0;
408 if (rotations.hasOwnProperty(slideshowXML.Img[idx].URL[urlIdx].toString()))
409 curRot=rotations[slideshowXML.Img[idx].URL[urlIdx].toString()];
410 else
411 curRot=Number(slideshowXML.Img[idx].attribute('rot90'));
412 rotate(0);
413 if(e.type==FlexEvent.READY) {
414 rotate(curRot);
415 if(slideshowXML.Img[idx].caption.toString()!=""){
416 caption.text=slideshowXML.Img[idx].caption.toString();
417 caption.visible=true;
418 } else {
419 caption.text="";
420 caption.visible=false;
421 }
422 if(!isReload) anim.play();
423 if(slideshowXML.Img[idx].attribute('live')>0)
424 cache.removeCacheEntry(curFile);
425 }
426 CursorManager.removeBusyCursor();
427 isEnabled=true;
428 if(isPlaying && !playTimer.running) playTimer.start();
429 }
430 ]]>
431 </fx:Script>
432
433 <fx:Declarations>
434 <s:Animate id="anim" target="{grpCaption}">
435 <s:motionPaths>
436 <s:SimpleMotionPath property="bottom"
437 valueFrom="{-grpCaption.height}" valueTo="0"/>
438 </s:motionPaths>
439 </s:Animate>
440 <s:ContentCache id="cache"/>
441 </fx:Declarations>
442
443 <s:Image id="Img1" source="{src1}" visible="false"
444 width="100%" height="100%"
445 horizontalCenter="0" verticalCenter="0"
446 contentLoader="{cache}"
447 ready="onImgDone(event)"
448 ioError="onAnyError(event)"
449 securityError="onAnyError(event)"
450 smooth="true"
451 />
452
453 <s:Image id="Img2" source="{src2}" visible="true"
454 width="100%" height="100%"
455 horizontalCenter="0" verticalCenter="0"
456 contentLoader="{cache}"
457 ready="onImgDone(event)"
458 ioError="onAnyError(event)"
459 securityError="onAnyError(event)"
460 smooth="true"
461 />
462
463 <s:Group id="grpCaption" width="100%" bottom="{-grpCaption.height}">
464 <s:Label id="caption" left="0" bottom="0" visible="false"
465 paddingLeft="2" paddingBottom="2" paddingRight="2" paddingTop="4"
466 backgroundColor="0xdddddd" backgroundAlpha="0.7"
467 maxWidth="{grpCaption.width-slideNo.width}"
468 maxDisplayedLines="{-1}" lineBreak="toFit"
469 />
470 <s:Label id="slideNo" right="0" bottom="0" visible="false"
471 paddingLeft="2" paddingBottom="2" paddingRight="2" paddingTop="4"
472 backgroundColor="0xdddddd" backgroundAlpha="0.7"
473 />
474 </s:Group>
475
476 <s:Button alpha="0" width="100%" height="100%"
477 mouseUp="forcedByUsr=true;nextSlide(event);"
478 mouseOver="anim.play();CursorManager.showCursor();"
479 mouseOut="if(anim.isPlaying) anim.reverse(); else anim.play(null,true);
480 CursorManager.hideCursor();"
481 />
482 </s:Application>