User Tools

Site Tools


script_animation_shrink

====== 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_shrink [2014/05/19 08:51]
lm13 [How to use the script]
script_animation_shrink [2014/09/24 16:10] (current)
lm13 [About the script]
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 & vertical page loop+  * Purpose : This script ​will give you a beautiful page transition animation and an optional horizontal & vertical page loop
   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]
-  * Current Version : 1.0 +  * Current Version : 2.0 
-  * Link: ...+  * Link: https://​plus.google.com/​115366157037831519359/​posts/​QHC7KRy8tVg 
 +  * Video : https://​plus.google.com/​115366157037831519359/​posts/​4Ktw58WRMji 
 +  * Download avialable! (Check repository)
  
 ====== Changelog ====== ====== Changelog ======
   * Version 1.0 (18/​5/​2014):​ initial release in wiki   * Version 1.0 (18/​5/​2014):​ initial release in wiki
 +  * Version 2.0 (24/​7/​2014):​ standalone, reworked structure, fix for pre-scaled items
  
 ====== 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 a page loop, disable it if you don't want to loop through pages   * 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 [[script_toggle_animation|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!
 +
 +====== Issues and Hints ======
 +  * 1-direction pinned items are not supported
  
 //please report all bugs in the g+ community!//​ //please report all bugs in the g+ community!//​
  
-====== ​Main Script ====== +====== Script ====== 
-<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 || d.getPositionScale()!=1)return;+var cont=JSON.parse(d.getTag()||"​null"​);​ 
 +var items=d.getItems();
 var dwidth=d.getWidth();​ var dwidth=d.getWidth();​
 var dheight=d.getHeight();​ var dheight=d.getHeight();​
 +
 +if(e.getSource()!="​C_POSITION_CHANGED"​)
 +{
 + 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++)
 + {
 + cont.pages[x]=[];​
 + for(y=0;​y<​Math.ceil(cont.maxy/​dheight)-minpagey;​y++)
 + {
 + cont.pages[x][y]=[];​
 + }
 + }
 + for(x=0;​x<​items.length;​x++)
 + {
 + var i=items.getAt(x);​
 + var pinned=i.getProperties().getString("​i.pinMode"​);​
 + if(pinned=="​NONE"​)
 + {
 + var data=new Object();
 + data.posx=i.getPositionX();​
 + data.posy=i.getPositionY();​
 + data.rot=Math.abs(i.getRotation())==90;​
 + data.sx=data.rot?​i.getScaleX():​i.getScaleY();​
 + data.sy=data.rot?​i.getScaleY():​i.getScaleX();​
 + if(i.getProperties().getBoolean("​i.onGrid"​))data.onGrid=true;​
 + else data.onGrid=false;​
 + i.getProperties().edit().setBoolean("​i.onGrid",​false).commit();​
 + cont.pages[Math.floor(data.posx/​dwidth)-minpagex][Math.floor(data.posy/​dheight)-minpagey].push(i.getId());​
 + i.setTag(JSON.stringify(data));​
 + }
 + }
 + cont.setup=true;​
 + Android.makeNewToast("​Animation enabled",​true).show();​
 + LL.writeToLogFile(JSON.stringify(cont.pages),​false);​
 + }
 + 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 dposx=d.getPositionX();​
 var dposy=d.getPositionY();​ var dposy=d.getPositionY();​
Line 31: Line 108:
 var pageposy=currenty*dheight;​ var pageposy=currenty*dheight;​
 var percenty=(dposy-pageposy)/​dheight;​ var percenty=(dposy-pageposy)/​dheight;​
-var items=d.getItems(); +var maxpagex=Math.floor((cont.maxx-dwidth)/​dwidth); 
-var l=items.getLength(); +var maxpagey=Math.floor((cont.maxy-dheight)/​dheight); 
-var maxpagex=Math.floor(cont.maxx-dwidth)/dwidth); +var minpagex=Math.floor(cont.minx/dwidth); 
-var maxpagey=Math.floor(cont.maxy-dheight)/​dheight);​ +var minpagey=Math.floor(cont.miny/​dheight);​ 
-var percent+var percent=(Math.abs(0.5-percentx)<​Math.abs(0.5-percenty))?percentx:percenty
-if(Math.abs(0.5-percentx)<​Math.abs(0.5-percenty)) + 
-percent=percentx; +if(percent>​0.005&&​percent<​99.995&&​dposx>​cont.minx-dwidth&&​dposy>​cont.miny-dheight)
-else percent=percenty;​ +
-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"​);​ + var scrollLimit=d.getProperties().getBoolean("​noScrollLimit"​);​ 
-if(dposx>​cont.maxx-dwidth&&​scrollLimit){ + if(dposx>​cont.maxx-dwidth&&​scrollLimit) 
-d.setPosition(cont.minx-dwidth,​dposy,​1,​false);​ + d.setPosition(cont.minx-dwidth,​dposy,​1,​false);​ 
-} + else if(dposy>​cont.maxy-dheight&&​scrollLimit)d.setPosition(dposx,​cont.miny-dheight,​1,​false);​ 
-else if(dposy>​cont.maxy-dheight&&​scrollLimit) d.setPosition(dposx,​cont.miny-dheight,​1,​false);​ + if(dposx<​cont.minx&&​scrollLimit) 
-if(dposx<​cont.minx&&​scrollLimit) + cont.statex=true;​ 
-cont.statex=true;​ + if(dposy<​cont.miny&&​scrollLimit) 
-if(dposy<​cont.miny&&​scrollLimit) + cont.statey=true;​
-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"​)&&​percentx==percent) +
-+
-if(Math.floor(data.posx/​dwidth)==currentx || (cont.statex && Math.floor(data.posx/​dwidth)==maxpagex)) +
-+
-if(percentx<​0.5) +
-+
-newscalex=1-percent*2;​ +
-newposx=dposx+((data.posx%dwidth+dwidth)%dwidth)+percent*(dwidth- ((data.posx%dwidth+dwidth)%dwidth) *2); +
-if(Math.floor(data.posy/​dheight)==currenty){ +
-newscaley=1-percent*2;​ +
-newposy=dposy+((data.posy%dheight+dheight)%dheight)+percent*(dheight- ((data.posy%dheight+dheight)%dheight)*2);​} +
-+
-else newvis=false;​ +
-+
-if(Math.floor(data.posx/​dwidth) ==currentx+1) +
-+
-if(percentx>​=0.5) +
-+
-newscalex=percent*2-1;​ +
-newposx=dposx+dwidth/​2*(2-percent*2)+ ((data.posx%dwidth+dwidth)%dwidth) *(percent*2-1);​ +
-if(Math.floor(data.posy/​dheight)==currenty){ +
-newscaley=percent*2-1;​ +
-newposy=dposy+dheight/​2*(2-percent*2)+ ((data.posy%dheight+dheight)%dheight)*(percent*2-1);​} +
-+
-else newvis=false;​ +
-+
-} if((pinned=="​NONE"​|| pinned=="​X"​)&&​percenty==percent) +
-+
-if(Math.floor(data.posy/​dheight)==currenty || (cont.statey && Math.floor(data.posy/​dheight)==maxpagey)) +
-+
-if(percenty<​0.5) +
-+
-newscaley=1-percent*2;​ +
-newposy=dposy+((data.posy%dheight+dheight)%dheight)+percent*(dheight- ((data.posy%dheight+dheight)%dheight) *2); +
-if(Math.floor(data.posx/​dwidth)==currentx){ +
-newscalex=1-percent*2;​ +
-newposx=dposx+((data.posx%dwidth+dwidth)%dwidth)+percent*(dwidth- ((data.posx%dwidth+dwidth)%dwidth) *2);} +
-+
-else newvis=false;​ +
-+
-if(Math.floor(data.posy/​dheight) ==currenty+1) +
-+
-if(percenty>​=0.5) +
-+
-newscaley=percent*2-1;​ +
-newposy=dposy+dheight/​2*(2-percent*2)+ ((data.posy%dheight+dheight)%dheight)*(percent*2-1);​ +
-if(Math.floor(data.posx/​dwidth)==currentx){ +
-newscalex=percent*2-1;​ +
-newposx=dposx+dwidth/​2*(2-percent*2)+ ((data.posx%dwidth+dwidth)%dwidth) *(percent*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>//​config +
-var mainScriptsName= "​AnimationShrink";​ +
-//endconfig+
  
- + var items0=(cont.pages[(cont.statex?​maxpagex:​currentx)-minpagex]||[])[(cont.statey?​maxpagey:​currenty)-minpagey];​ 
-var d=LL.getEvent().getContainer(); + if(items0!=null) 
-var box=d.getBoundingBox(); +
-var cont=JSON.parse(d.getTag()||"​null"​); + for(z=0;z<​items0.length;​z++) 
-if(cont==null) cont=new Object(); + { 
-cont.minx=box.getLeft()+ var item=LL.getItemById(items0[z]); 
-cont.maxx=box.getRight(); + var data=JSON.parse(item.getTag());​ 
-cont.miny=box.getTop()+ item.setScale((percent>=0.5?​1:​1-percent*2)*data.sx,​(percent>​=0.5?​1:​1-percent*2)*data.sy); 
-cont.maxy=box.getBottom(); + item.setPosition(dposx+((data.posx%dwidth+dwidth)%dwidth)+percent*(dwidth-((data.posx%dwidth+dwidth)%dwidth)*2),​dposy+((data.posy%dheight+dheight)%dheight)+percent*(dheight-((data.posy%dheight+dheight)%dheight)*2)); 
-var items=d.getItems(); + item.setVisibility(percent<​0.5); 
-LL.runScript(mainScriptsName,​null); +
-var dwidth=d.getWidth(); +
-var dheight=d.getHeight(); + if(percentx==percent
-if(cont.setup!=true+
-+ var items=(cont.pages[currentx+1-minpagex]||[])[(cont.statey?​maxpagey:​currenty)-minpagey]
-for(x=0;x<​items.length;​x++) +
-+ else 
-var i=items.getAt(x); +
-var data=new Object(); + var items=(cont.pages[(cont.statex?​maxpagex:​currentx)-minpagex]||[])[currenty+1-minpagey]; 
-data.posx=i.getPositionX(); + } 
-data.posy=i.getPositionY(); + if(items!=null
-if(i.getProperties().getBoolean("i.onGrid"​)) data.onGrid=true+
-else data.onGrid=false;​ + for(z=0;z<​items.length;​z++) 
-i.getProperties().edit().setBoolean("i.onGrid",​false).commit()+
-i.setTag(JSON.stringify(data)); + var item=LL.getItemById(items[z]); 
-+ var data=JSON.parse(item.getTag()); 
-cont.setup=true; + item.setScale((percent<​0.5?​1:​2*percent-1)*data.sx,(percent<​0.5?​1:​2*percent-1)*data.sy)
-Android.makeNewToast("​Animation enabled",​true).show();+ item.setPosition(dposx+dwidth/​2*(2-percent*2)+((data.posx%dwidth+dwidth)%dwidth)*(percent*2-1),​dposy+dheight/​2*(2-percent*2)+((data.posy%dheight+dheight)%dheight)*(percent*2-1)); 
 + item.setVisibility(percent>​=0.5); 
 +
 + }
 } }
 else else
 { {
-var cellw=d.getCellWidth(); + d.setPosition(dposx,dposy); 
-var cellh=d.getCellHeight(); + d.setPosition(dposx<​cont.minx?​cont.maxx-dwidth:​dposx,​dposy<​cont.miny?​cont.maxy-dheight:​dposy,​1,​false)
-for(x=0;x<​items.length;​x++) + cont.statex=false;​ 
-+ cont.statey=false
-var i=items.getAt(x); + for(i=0;i<​items.length;​i++) 
-var data=JSON.parse(i.getTag());​ +
-if(data!=null ​&& data.onGrid==true+ item=items.getAt(i); 
-+ var data=JSON.parse(item.getTag());​ 
-i.getProperties().edit().setBoolean("​i.onGrid"​,true).commit(); + if(data!=null) 
-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)); +
-+ item.setScale(data.sx,data.sy); 
-i.setVisibility(true);​ + item.setPosition(data.posx,​data.posy);​ 
-+ item.setVisibility(true);​ 
-cont.setup=false;​ +
-Android.makeNewToast("​Animation disabled",​true).show();​+ }
 } }
-d.setTag(JSON.stringify(cont));​ +</sxh>
-</code>+
script_animation_shrink.1400489519.txt.gz · Last modified: 2014/05/19 08:51 by lm13