User Tools

Site Tools


script_animation_bulldoze

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_animation_bulldoze [2014/05/19 08:29]
lm13 [How to use the script]
script_animation_bulldoze [2015/07/09 19:56] (current)
lm13
Line 1: Line 1:
 ====== About the script ====== ====== About the script ======
-  * Purpose : These scripts ​will give you a beautiful page transition animation and an optional horizontal and vertical page loop+  * Purpose : This script ​will give you a beautiful page transition animation and an optional horizontal and vertical page loop
   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]
-  * Current Version : 2.0+  * Current Version : 3.0.1
   * Link : https://​plus.google.com/​115366157037831519359/​posts/​GXVcfSaWVRi   * Link : https://​plus.google.com/​115366157037831519359/​posts/​GXVcfSaWVRi
 +  * Video : https://​plus.google.com/​115366157037831519359/​posts/​N4vKniRC4pe
 +  * Download avialable! (Check repository)
 +
  
 ====== Changelog ====== ​ ====== Changelog ====== ​
   * Version 1.0 (1/4/2014): initial release in wiki   * Version 1.0 (1/4/2014): initial release in wiki
   * Version 2.0 (19/​5/​2014):​ added vertical support, improved smoothness   * Version 2.0 (19/​5/​2014):​ added vertical support, improved smoothness
 +  * Version 2.1 (20/​6/​2014):​ added rotation check
 +  * Version 3.0.1 (20/​7/​2014):​ standalone, improved smoothness
  
 ====== How to use the script ====== ====== How to use the script ======
-  * Set the main script to the positionchanged event of your container+  * Set the script to the positionchanged event of your container
   * enable infinte scrolling if you want to have a screen loop   * enable infinte scrolling if you want to have a screen loop
-  * in this container: create a shortcut to the toggle ​script ​and set up toggle sripts configuration+  * in this container: create a shortcut to the script
   * one click on the shortcut will enable the animation, clicking again will disable the animation. ​   * 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!   * BE SURE TO DISABLE THE ANIMATION BEFORE YOU EDIT, MOVE OR ADD ITEMS!
Line 19: Line 24:
   * this will break any other script, which uses item or container tags, and will be broken by them      * this will break any other script, which uses item or container tags, and will be broken by them   
   * at some point it may flicker ​   * at some point it may flicker ​
-  * with many items it won't run smooth 
   * don't use dual position, this will do weird stuff   * don't use dual position, this will do weird stuff
 +  * make sure all of your items have exactly one of the following rotations: 0°,​90°,​180°,​270°
  
 //please report all bugs in the g+ community// //please report all bugs in the g+ community//
  
-====== ​Main Script code ====== +====== Script code ====== 
-<code>​var ​d=LL.getEvent().getContainer();​ +<sxh javascript;>​var ​e=LL.getEvent()
-var cont=JSON.parse(d.getTag()||"​null"​)+var d=e.getContainer();​ 
-if(cont==null || !cont.setup) +var cont= JSON.parse(d.getTag()||"​null"​); ​
-+
-return; +
-+
-var dwidth=d.getWidth();​ +
-var pos=d.getPositionX();​ +
-var current=Math.floor(pos/​dwidth);​ +
-var pagepos=current*dwidth;​ +
-var dposy=d.getPositionY();​ +
-var percent=(pos-pagepos)/​dwidth;+
 var items=d.getItems();​ var items=d.getItems();​
-var l=itemsgetLength(); +var dwidth=d.getWidth();  
-var tag=parseInt(LL.getScriptTag()); +var dheight=d.getHeight();
-var maxpage= Math.floor((cont.max-dwidth)/​dwidth);​ +
  
-if((percent>​0.005&&​percent<​99.995&& pos>​cont.min-dwidth)+if(e.getSource()!="​C_POSITION_CHANGED"​)
 { {
-if(pos>cont.max-dwidth)+if(cont==null) cont=new Object(); 
 +var box=d.getBoundingBox();​ 
 +cont.minx=box.getLeft();​ 
 +cont.maxx=box.getRight();​ 
 +cont.miny=box.getTop();​ 
 +cont.maxy=box.getBottom();​ 
 +var minpagex=Math.floor( cont.minx/dwidth);  
 +var minpagey=Math.floor( cont.miny/​dheight);​ 
 +if(cont.setup!=true)  
 +{  
 +cont.pages=[];​ 
 +for(x=0;​x<​Math.ceil(cont.maxx/​dwidth)-minpagex;​x++)
 { {
-d.setPosition(cont.min-dwidth ,​dposy,​1,​false);+cont.pages[x]=[];​ 
 +for(y=0;​y<​Math.ceil(cont.maxy/​dheight)-minpagey;​y++) 
 +
 +cont.pages[x][y]=[];
 } }
-if(pos<cont.min)+
 +for(x=0;x<items.length;x++)  
 +{  
 +var i=items.getAt(x);​ 
 +var pinned=i.getProperties() .getString("​i.pinMode"​);​ 
 +if(pinned!="​XY"​)
 { {
-cont.state=2;+var data=new Object(); 
 +data.posx=i.getPositionX();​ 
 +data.posy=i.getPositionY();​ 
 +data.rot=Math.abs(i.getRotation())==90;​ 
 +data.pin=pinned;​ 
 +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));​ 
 +if(pinned=="​X"​) 
 +
 +var ypages=cont.pages[Math.floor(data.posx/​dwidth)-minpagex][Math.floor(data.posy/​dheight)-minpagey];​ 
 +for(z=0;​z<​ypages.length;​z++) 
 +cont.pages[z][Math.floor(data.posy/​dheight)-minpagey].push(i.getId());
 } }
-for(i=0;​i<​l;​i++)+else if(pinned=="​Y"​)
 { {
-item=items.getAt(i); +var xpages=cont.pages[Math.floor(data.posx/​dwidth)-minpagex];​ 
-var pinneditem.getProperties().getString("i.pinMode"); +for(z=0;​z<​xpages.length;​z++) 
-if(pinned=="NONE"​|| ​pinned=="​Y"​)+xpages[z].push(i.getId());​ 
 +
 +else cont.pages[Math.floor(data.posx/​dwidth)-minpagex][Math.floor(data.posy/​dheight)-minpagey].push(i.getId());​ 
 +
 +}  
 +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());​ 
 +i.setScale(1,​1);​ 
 +if(data!=null&&​ data.onGrid==true)  
 +{  
 +iwidth=i.getWidth();​ 
 +iheight=i.getHeight();​  
 +i.getProperties().edit().setBoolean("i.onGrid",​true).commit();  
 +i.setCell(Math.round(data.posx/​cellw),​Math.round(data.posy/​cellh),​Math.round((data.posx+iwidth)/​cellw),​Math.round(( data.posy+iheight)/​cellh));​  
 +}   
 +}  
 +cont.setup=false; 
 +Android.makeNewToast("Animation disabled",​true).show();​  
 +}  
 +d.setTag(JSON.stringify(cont));​ 
 +
 + 
 +if(cont==null ​|| !cont.setup || d.getPositionScale()!=1)return; 
 +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 maxpagex=Math.floor( (cont.maxx-dwidth)/​dwidth);​ 
 +var maxpagey=Math.floor( (cont.maxy-dheight)/​dheight);​ 
 +var minpagex=Math.floor( cont.minx/​dwidth);​  
 +var minpagey=Math.floor( cont.miny/​dheight);​ 
 + 
 +if(((percentx>​0.005 && percentx<​99.995) ||(percenty>​0.005 && percenty<​99.995)) && dposx>​cont.minx-dwidth && dposy>​cont.miny-dheight)
 { {
-var data=JSON.parse(item.getTag()); + var scrollLimit=d.getProperties(.getBoolean("​noScrollLimit"​)
-if(data.page==current || (cont.state==&& ​data.page==maxpage))+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; 
 +var items=(cont.pages[(cont.statex?​maxpagex:​currentx)-minpagex]||[])[(cont.statey?​maxpagey:​currenty)-minpagey];​ 
 +if(items!=null)
 { {
-if(Math.abs(1-percent-item.getScaleX())>​0)+for(z=0;​z<​items.length;z++)
 { {
-item.setScale(1-percent,1); +var item=LL.getItemById(items[z]);​ 
-item.setPosition(pos+data.posx*(1-percent),​data.posy);​+var data=JSON.parse(item.getTag());​ 
 +item.setScale(data.pin=="​X"?​1:​1-(data.rot?​percenty:​percentx),data.pin=="​Y"?​1:​1-(data.rot?​percentx:​percenty)); 
 +item.setPosition(data.pin=="​X"?​data.posx:​dposx+((data.posx%dwidth+dwidth)%dwidth)*(1-percentx),data.pin=="​Y"?​data.posy:​dposy+((data.posy%dheight+dheight)%dheight)*(1-percenty));
 } }
 } }
-if(data.page==current+1)+var items=(cont.pages[currentx+1-minpagex]||[])[(cont.statey?​maxpagey:​currenty)-minpagey];​ 
 +if(items!=null)
 { {
-if(Math.abs(percent-item.getScaleX())>​0)+for(z=0;​z<​items.length;z++)
 { {
-item.setScale(percent,1); +var item=LL.getItemById(items[z]);​ 
-item.setPosition(pos+dwidth-(dwidth-data.posx)*percent,​data.posy);​+var data=JSON.parse(item.getTag());​ 
 +item.setScale(data.pin=="​X"?​1:​data.rot?​1-percenty:​percentx>​0.005?​percentx:​1,data.pin=="​Y"?​1:​data.rot?​(percentx>​0.005?​percentx:​1):​1-percenty); 
 +item.setPosition(data.pin=="​X"?​data.posx:​dposx+dwidth-(dwidth-(data.posx%dwidth+dwidth)%dwidth)*percentx,data.pin=="​Y"?​data.posy:​dposy+((data.posy%dheight+dheight)%dheight)*(1-percenty));
 } }
 } }
-} +var items=(cont.pages[(cont.statex?​maxpagex:​currentx)-minpagex]||[])[currenty+1-minpagey];​ 
-+if(items!=null)
-+
-else+
 { {
-if(pos<cont.min)+for(z=0;z<items.length;z++)
 { {
-d.setPosition(pos,​dposy);​ +var item=LL.getItemById(items[z]);
-d.setPosition(cont.max-dwidth,​dposy,​1,​false);​ +
-+
-cont.state=0;​ +
-for(i=0;​i<​l;​i++) +
-+
-item=items.getAt(i);+
 var data=JSON.parse(item.getTag());​ var data=JSON.parse(item.getTag());​
-item.setScale(1,​1);​ +item.setScale(data.pin=="​X"?​1:​data.rot?​(percenty>​0.005?​percenty:​1):​1-percentxdata.pin=="​Y"?​1:​data.rot?​1-percentx:​percenty>​0.005?​percenty:​1); 
-item.setPosition(data.page*dwidth+data.posx,​data.posy);​+item.setPosition(data.pin=="​X"?​data.posx:​dposx+((data.posx%dwidth+dwidth)%dwidth)*(1-percentx),data.pin=="​Y"?​data.posy:​dposy+dheight-(dheight-(data.posy%dheight+dheight)%dheight)*percenty);
 } }
 } }
-</​code>​ +var items=(cont.pages[currentx+1-minpagex]||[])[currenty+1-minpagey]
- +if(items!=null)
-====== Toggle Script code ====== +
-<​code>//​config +
-var main_scripts_name="​AnimationBulldoze";​ +
-//​endconfig +
- +
- +
-var d=LL.getEvent().getContainer();​ +
-var box=d.getBoundingBox();​ +
-var cont=JSON.parse(d.getTag()||"​null"​); +
-if(cont==null) cont=new Object(); +
-cont.min=box.getLeft();​ +
-cont.max= box.getRight();​ +
-var items=d.getItems();​ +
-LL.runScript(main_scripts_name,​null); +
-var dwidth=d.getWidth();​ +
-if(cont.setup!=true)+
 { {
-for(x=0;x<​items.length;​x++)+for(z=0;z<​items.length;​z++)
 { {
-var i=itemsgetAt(x); +var item=LL.getItemById(items[z]); 
-var posx=i.getPositionX(); +var data=JSON.parse(item.getTag()); 
-var data=new Object(); +item.setScale(data.pin=="​X"?​1:​data.rot?(percenty>​0.005?​percenty:​1):​percentx>​0.005?​percentx:​1,​data.pin=="​Y"?​1:​data.rot?​(percentx>​0.005?​percentx:​1):​percenty>​0.005?​percenty:​1); 
-data.page=Math.floor(posx/dwidth)+item.setPosition(data.pin=="X"?data.posx:​dposx+dwidth-(dwidth-(data.posx%dwidth+dwidth)%dwidth)*percentx,​data.pin=="​Y"?​data.posy:​dposy+dheight-(dheight-(data.posy%dheight+dheight)%dheight)*percenty);
-data.posx=posx-data.page*dwidth;​ +
-data.posy=i.getPositionY(); +
-if(i.getProperties().getBoolean("i.onGrid")) +
-+
-var cell=i.getCell(); +
-data.left=cell.getLeft()+
-data.right=cell.getRight(); +
-data.top=cell.getTop()+
-data.bottom=cell.getBottom();+
 } }
-else data.left=null;​ 
-i.setTag(JSON.stringify(data));​ 
-i.getProperties().edit().setBoolean("​i.onGrid",​false).commit();​ 
 } }
-cont.setup=true;​ 
-Android.makeNewToast("​Animation enabled",​true).show();​ 
 } }
 else else
 { {
-for(x=0;x<​items.length;​x++)+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<​items.length;​i++)
 { {
-var i=items. getAt(x); +item=items.getAt(i); 
-var data=JSON.parse(i.getTag());​ +var data=JSON.parse(item.getTag());​ 
-if(data!=null && data.left!=null) +item.setScale(1,1); 
-+item.setPosition(data.posx,data.posy);
-i.getProperties().edit().setBoolean("​i.onGrid"​,true).commit(); +
-i.setCell(parseInt(data.left)parseInt(data.top), parseInt(data.right),​ parseInt(data.bottom));+
 } }
 } }
-cont.setup=false;​ +</sxh>
-Android.makeNewToast("​Animation disabled",​true).show();​ +
-+
-d.setTag(JSON.stringify(cont));​ +
-</code>+
script_animation_bulldoze.1400488182.txt.gz · Last modified: 2014/05/19 08:29 by lm13