User Tools

Site Tools


script_animation_turn

====== 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_turn [2014/07/05 18:09]
lm13 link
script_animation_turn [2014/09/24 16:11] (current)
lm13 [About the script]
Line 2: Line 2:
   * Purpose : These scripts will give you a beautiful page transition animation and an optional horizontal page loop   * Purpose : These scripts will give you a beautiful page transition animation and an optional horizontal page loop
   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]
-  * Current Version : 1.0+  * Current Version : 2.1
   * Link: https://​plus.google.com/​115366157037831519359/​posts/​eUtogDspL2X   * Link: https://​plus.google.com/​115366157037831519359/​posts/​eUtogDspL2X
 +  * Download avialable! (Check repository)
  
 ====== Changelog ====== ====== Changelog ======
   * Version 1.0 (5/7/2014): initial release in wiki   * Version 1.0 (5/7/2014): initial release in wiki
 +  * Version 2.1 (12/​7/​2014):​ no second script needed anymore, added optional fade, improved speed for lot of pages & items 
  
  
  
 ====== How to use the script ====== ====== How to use the script ======
-  * Set the main script to the positionchanged event of your container; configure the main script, if you want another bounciness+  * Set the script to the positionchanged event of your container; configure the main script, if you want fading ​
   * 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 ​or a gesture ​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 21:
 //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;>//config  
-var cont= JSON.parse(d.getTag()||"​null"​);​ +var fade=false;​ 
-if(cont==null || !cont.setup || d.getPositionScale()!=1)return+//​endconfig 
-var dwidth=d.getWidth();​+ 
 + 
 +var e=LL.getEvent();​  
 +var d=e.getContainer(); 
 +var dwidth=d.getWidth(); ​
 var dheight=d.getHeight();​ var dheight=d.getHeight();​
 +var cont=JSON.parse(d.getTag()|| "​null"​);​
 +
 +if(e.getSource()!="​C_POSITION_CHANGED"​){
 +var items=d.getItems();​
 +var box=d.getBoundingBox();​
 +if(cont==null) cont=new Object(); cont.minx=box.getLeft();​ cont.maxx=box.getRight();​
 +var minpage=Math.floor(cont.minx/​dwidth);​
 +if(cont.setup!=true) ​
 +
 +cont.pages=[];​
 +var counters=[];​
 +for(x=0;​x<​Math.ceil(cont.maxx/​dwidth)-minpage;​x++)
 +{
 +cont.pages[x]=[];​
 +counters[x]=0;​
 +
 +for(x=0;​x<​items.length;​x++) ​
 +
 +var i=items.getAt(x); ​
 +var pinned=i.getProperties() .getString("​i.pinMode"​);​
 +if(pinned=="​NONE"​|| pinned=="​Y"​)
 +{
 +var data=new Object(); data.posx=i.getPositionX();​ data.posy=i.getPositionY();​
 +data.rot=i.getRotation();​ if(i.getProperties().getBoolean("​i.onGrid"​)) data.onGrid=true; ​
 +else data.onGrid=false;​ i.getProperties().edit().setBoolean("​i.onGrid",​false).commit();​
 +var p=Math.floor(data.posx/​dwidth)-minpage;​
 +cont.pages[p][counters[p]++]=i.getId();​
 +i.setTag(JSON.stringify(data)); ​
 +}
 +
 +for(x=0;​x<​Math.ceil(cont.maxx/​dwidth)-minpage;​x++)
 +{
 +cont.pages[x].length=counters[x];​
 +
 +cont.setup=true;​ Android.makeNewToast("​Animation enabled",​true).show();​
 +
 +else
 +
 +var cellw=d.getCellWidth(); ​
 +var cellh=d.getCellHeight();​
 +for(x=0;​x<​items.getLength();​x++) ​
 +
 +var i=items.getAt(x); ​
 +var data=JSON.parse(i.getTag());​
 +if(data!=null)
 +{
 +i.setRotation(data.rot);​
 +i.setPosition(data.posx,​data.posy);​
 +if(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 30: Line 98:
 var pagepos=current*dwidth;​ var pagepos=current*dwidth;​
 var percent=(dposx-pagepos)/​dwidth;​ var percent=(dposx-pagepos)/​dwidth;​
-var items=d.getItems(); +var maxpage=Math.ceil((cont.maxx-dwidth)/​dwidth); 
-var l=items.getLength(); +var minpage=Math.floor(cont.minx/dwidth);
-var maxpage=Math.floor((cont.maxx-dwidth)/dwidth);+
  
 if((percent>​0.005 && percent<​99.995) && dposx>​cont.minx-dwidth) if((percent>​0.005 && percent<​99.995) && dposx>​cont.minx-dwidth)
 { {
- 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);​
Line 42: Line 109:
 if(dposx<​cont.minx&&​scrollLimit) if(dposx<​cont.minx&&​scrollLimit)
 cont.state=true;​ cont.state=true;​
-for(i=0;i<l;i++)+var items=cont.pages[(cont.state?​maxpage:​current)-minpage]; 
 +if(items!=null)
 { {
-item=items.getAt(i); +for(z=0;z<items.length;z++) 
-var pinned=item.getProperties() .getString("​i.pinMode"​);+{ 
 +var item=LL.getItemById(items[z]);
 var data=JSON.parse(item.getTag());​ var data=JSON.parse(item.getTag());​
-if(pinned=="​NONE"​|| pinned=="​Y"​) 
-{ 
- var page=Math.floor(data.posx/​dwidth) 
-if(page==current||(cont.state && page==maxpage)) 
-{ 
 item.setRotation(90*percent+data.rot);​ item.setRotation(90*percent+data.rot);​
 var c0=center(item,​data.rot);​ var c0=center(item,​data.rot);​
Line 60: Line 124:
 var c=center(item,​item.getRotation());​ var c=center(item,​item.getRotation());​
 item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],​dposy+Math.sin(angle)*sqrt-c[1]);​ item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],​dposy+Math.sin(angle)*sqrt-c[1]);​
 +if(fade)
 +item.getProperties().edit().setInteger("​i.alpha",​255*(1-percent)).commit();​
 } }
-if(Math.floor(data.posx/​dwidth) ==current+1)+
 +var items=cont.pages[current+1-minpage];​ 
 +if(items!=null)
 { {
 +for(z=0;​z<​items.length;​z++)
 +{
 +var item=LL.getItemById(items[z]);​
 +var data=JSON.parse(item.getTag());​
 item.setRotation(90*percent-90+data.rot);​ item.setRotation(90*percent-90+data.rot);​
 var c0=center(item,​data.rot);​ var c0=center(item,​data.rot);​
Line 72: Line 144:
 var c=center(item,​item.getRotation());​ var c=center(item,​item.getRotation());​
 item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],​dposy+Math.sin(angle)*sqrt-c[1]);​ item.setPosition(dposx+Math.cos(angle)*sqrt-c[0],​dposy+Math.sin(angle)*sqrt-c[1]);​
-}+if(fade)item.getProperties().edit().setInteger("​i.alpha",​255*(percent)).commit();​
 } }
 } }
Line 81: Line 153:
 d.setPosition(dposx<​cont.minx?​cont.maxx-dwidth:​dposx,​dposy,​1,​false);​ d.setPosition(dposx<​cont.minx?​cont.maxx-dwidth:​dposx,​dposy,​1,​false);​
 cont.state=false;​ cont.state=false;​
-for(i=0;​i<​l;i++)+var items=d.getItems();​ 
 +for(i=0;​i<​items.length;i++)
 { {
 item=items.getAt(i);​ item=items.getAt(i);​
 var data=JSON.parse(item.getTag());​ var data=JSON.parse(item.getTag());​
 +if(data!=null)
 +{
 item.setRotation(data.rot);​ item.setRotation(data.rot);​
 item.setPosition(data.posx,​data.posy);​ item.setPosition(data.posx,​data.posy);​
 +}
 +if(fade)item.getProperties().edit().setInteger("​i.alpha",​255).commit();​
 } }
 } }
Line 100: Line 177:
 return [(w*cos+h*sin)*0.5,​(h*cos+w*sin)*0.5];​ return [(w*cos+h*sin)*0.5,​(h*cos+w*sin)*0.5];​
 } }
-</code> +</sxh>
  
script_animation_turn.1404583784.txt.gz · Last modified: 2014/07/05 18:09 by lm13