User Tools

Site Tools


script_animation_flip

**This is an old revision of the document!** ----

A PCRE internal error occured. This might be caused by a faulty plugin

====== About the script ====== * Purpose : These scripts will give you a beautiful page transition animation and an optional horizontal & vertical page loop * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] * Current Version : 2.0 * Link: https://plus.google.com/115366157037831519359/posts/EAUStJNGa5o ====== Changelog ====== * Version 1.0 (30/4/2014): initial release in wiki * Version 2.0 (18/5/2014): Reworked parsing structure, added vertical support, improved smoothness ====== How to use the script ====== * Set the main script to the positionchanged event of your container * enable infinte scrolling if you want a page loop, disable it if you don't want to loop through pages * in this container: create a shortcut to the toggle script and set up toggle sripts configuration * one click on the shortcut will enable the animation, clicking again will disable the animation. * BE SURE TO DISABLE THE ANIMATION BEFORE YOU EDIT, MOVE OR ADD ITEMS! ====== Issues and hints ====== * this will break any other script, which uses item or container tags, and will be broken by them * with a lot of items it won't run smooth (for me 50+) * don't use dual position, this will do weird stuff //please report all bugs in the g+ community// ====== Main Script ====== <code>//var d=LL.getEvent().getContainer(); var d=LL.getCurrentDesktop(); var cont= JSON.parse(d.getTag()||"null"); if(cont==null || !cont.setup || d.getPositionScale()!=1)return; var dwidth=d.getWidth(); var dheight=d.getHeight(); var dposx=d.getPositionX(); var dposy=d.getPositionY(); var currentx=Math.floor(dposx/dwidth); var pageposx=currentx*dwidth; var percentx=(dposx-pageposx)/dwidth; var currenty=Math.floor(dposy/dheight); var pageposy=currenty*dheight; var percenty=(dposy-pageposy)/dheight; var items=d.getItems(); var l=items.getLength(); var maxpagex=Math.floor( (cont.maxx-dwidth)/dwidth); var maxpagey=Math.floor( (cont.maxy-dheight)/dheight); if(((percentx>0.005 && percentx<99.995) ||(percenty>0.005 && percenty<99.995)) && dposx>cont.minx-dwidth && dposy>cont.miny-dheight) { var scrollLimit=d.getProperties() .getBoolean("noScrollLimit"); if(dposx>cont.maxx-dwidth&&scrollLimit){ d.setPosition(cont.minx-dwidth,dposy,1,false); } else if(dposy>cont.maxy-dheight&&scrollLimit) d.setPosition(dposx,cont.miny-dheight,1,false); if(dposx<cont.minx&&scrollLimit) cont.statex=true; if(dposy<cont.miny&&scrollLimit) cont.statey=true; for(i=0;i<l;i++) { item=items.getAt(i); var pinned=item.getProperties() .getString("i.pinMode"); var data=JSON.parse(item.getTag()); var newposx=data.posx; var newposy=data.posy; var newscalex=1; var newscaley=1; var newvis=true; if(pinned=="NONE"|| pinned=="Y") { if(Math.floor(data.posx/dwidth)==currentx || (cont.statex && Math.floor(data.posx/dwidth)==maxpagex)) { if(percentx<0.5) { newscalex=1-percentx*2; newposx=dposx+((data.posx%dwidth+dwidth)%dwidth)+percentx*(dwidth- ((data.posx%dwidth+dwidth)%dwidth) *2); } else newvis=false; } if(Math.floor(data.posx/dwidth) ==currentx+1) { if(percentx>=0.5) { newscalex=percentx*2-1; newposx=dposx+dwidth/2*(2-percentx*2)+ ((data.posx%dwidth+dwidth)%dwidth) *(percentx*2-1); } else newvis=false; } } if(pinned=="NONE"|| pinned=="X") { if(Math.floor(data.posy/dheight)==currenty || (cont.statey && Math.floor(data.posy/dheight)==maxpagey)) { if(percenty<0.5) { newscaley=1-percenty*2; newposy=dposy+((data.posy%dheight+dheight)%dheight)+percenty*(dheight- ((data.posy%dheight+dheight)%dheight) *2); } else newvis=false; } if(Math.floor(data.posy/dheight) ==currenty+1) { if(percenty>=0.5) { newscaley=percenty*2-1; newposy=dposy+dheight/2*(2-percenty*2)+ ((data.posy%dheight+dheight)%dheight) *(percenty*2-1); } else newvis=false; } } item.setScale(newscalex,newscaley); item.setPosition(newposx,newposy); item.setVisibility(newvis); } } else { d.setPosition(dposx,dposy); d.setPosition(dposx<cont.minx?cont.maxx-dwidth:dposx,dposy<cont.miny?cont.maxy-dheight:dposy,1,false); cont.statex=false; cont.statey=false; for(i=0;i<l;i++) { item=items.getAt(i); var data=JSON.parse(item.getTag()); item.setScale(1,1); item.setPosition(data.posx,data.posy); item.setVisibility(true); } } </code> ====== Toggle Script code ====== <code>//config var mainScriptsName= "AnimationFlip"; //endconfig var d=LL.getEvent().getContainer(); var box=d.getBoundingBox(); var cont=JSON.parse(d.getTag()||"null"); if(cont==null) cont=new Object(); cont.minx=box.getLeft(); cont.maxx=box.getRight(); cont.miny=box.getTop(); cont.maxy=box.getBottom(); var items=d.getItems(); LL.runScript(mainScriptsName,null); var dwidth=d.getWidth(); var dheight=d.getHeight(); if(cont.setup!=true) { for(x=0;x<items.length;x++) { var i=items.getAt(x); var data=new Object(); data.posx=i.getPositionX(); data.posy=i.getPositionY(); if(i.getProperties().getBoolean("i.onGrid")) data.onGrid=true; else data.onGrid=false; i.getProperties().edit().setBoolean("i.onGrid",false).commit(); i.setTag(JSON.stringify(data)); } cont.setup=true; Android.makeNewToast("Animation enabled",true).show(); } else { var cellw=d.getCellWidth(); var cellh=d.getCellHeight(); for(x=0;x<items.length;x++) { var i=items.getAt(x); var data=JSON.parse(i.getTag()); if(data!=null && data.onGrid==true) { i.getProperties().edit().setBoolean("i.onGrid",true).commit(); i.setCell(Math.round(data.posx/cellw),Math.round(data.posy/cellh),Math.round((data.posx+i.getWidth())/cellw),Math.round(( data.posy+i.getHeight())/cellh)); } i.setVisibility(true); } cont.setup=false; Android.makeNewToast("Animation disabled",true).show(); } d.setTag(JSON.stringify(cont)); </code>

script_animation_flip.1400415695.txt.gz · Last modified: 2014/05/18 12:21 by lm13