====== Differences ====== This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
script_always_there_bar [2014/04/08 12:10] trianguloy [How to use the script] |
script_always_there_bar [2018/08/14 16:50] (current) f43nd1r fix link |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| * Purpose : This is a script that place an item (in the video a panel) always on top of the screen. Scroll down the desktop to show it. Scroll up to hide. | * Purpose : This is a script that place an item (in the video a panel) always on top of the screen. Scroll down the desktop to show it. Scroll up to hide. | ||
| * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] | * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] | ||
| - | * Link: https://plus.google.com/u/1/105066926163073195690/posts/DPufvGD2SjF | + | * Link: https://plus.google.com/+TrianguloY/posts/DPufvGD2SjF (With video) |
| ====== How to use the script ====== | ====== How to use the script ====== | ||
| Line 8: | Line 8: | ||
| Instructions: | Instructions: | ||
| * Copy paste this script as a new one. | * Copy paste this script as a new one. | ||
| - | * IMPORTANT: you need to write the ID of the item you want to move (id, because panels don't have label) | + | * IMPORTANT: you need to label "always-bar" the item you want to move |
| - | * Pin that item. | + | * Pin that item and detach it from the screen |
| - | * Set the script in the position change event of the desktop | + | * Set the script in the position change event of the desired container |
| + | |||
| + | Settings: | ||
| + | * you can change the velocity the item is scrolled. Just change the numbers of the first part of the script, nothing more. | ||
| + | * NEW : you can specify the direction of scrolling vertically and horizontally. Change the parameter in the config (you can have vertical and horizontal simultaneously) | ||
| ====== Script code ====== | ====== Script code ====== | ||
| - | <code> | + | <sxh javascript> |
| - | var desk = LL.getCurrentDesktop(); | + | |
| + | //this number means the velocity of showing/hidding respectively | ||
| + | //1 is the default ( like the desktop ) the bigger, the faster (avoid negative numbers, between (0,1) will be slower ) | ||
| + | var vs = 2;//show | ||
| + | var vh = 0.5;//hide | ||
| + | //this will set the direction | ||
| + | var vertical = 1;//-1,0,1 bottom,disable,top | ||
| + | var horizontal = 0; //-1,0,1 left,disable,right | ||
| - | /* Id of the item to move.*/ | ||
| - | var bar = desk.getItemById(524308); | ||
| + | var cont = LL.getEvent().getContainer(); | ||
| + | //item to move | ||
| + | var bar = cont.getItemByLabel("always-bar"); | ||
| + | |||
| + | if(bar==null){alert("Warning: no item with label 'always-bar' found.");return;} | ||
| /* current position | /* current position | ||
| Line 26: | Line 40: | ||
| //save | //save | ||
| */ | */ | ||
| - | var deskpos = desk.getPositionY(); | + | var contpos = [cont.getPositionX(),cont.getPositionY()]; |
| - | if(!("prev" in self )) self.prev = deskpos; | + | var prev = JSON.parse(bar.getTag())||[0,0]; |
| - | var d = deskpos-self.prev; | + | var d = [contpos[0]-prev[0],contpos[1]-prev[1]]; |
| - | self.prev = deskpos; | + | bar.setTag(JSON.stringify(contpos)); |
| - | var barpos = bar.getPositionY(); | + | var barpos = [bar.getPositionX(),bar.getPositionY()]; |
| - | var size=bar.getScaleY() * bar.getHeight(); | + | var size = [-bar.getScaleX()*bar.getWidth(),-bar.getScaleY()*bar.getHeight()]; |
| + | var sides = [horizontal,-vertical]; | ||
| + | var screen = [cont.getWidth(),cont.getHeight()]; | ||
| - | /*hide the bar */ | + | |
| - | if(d>0 && barpos>-size){ | + | for(var j=0;j<=1;++j){ |
| - | if(barpos-d<-size || barpos<-size){ | + | |
| - | bar.setPosition(0,-size); | + | if(sides[j]==0)continue; |
| - | }else{ | + | check=[0,size[j]]; |
| - | bar.setPosition(0,barpos-d); | + | if(sides[j]==1)check=[check[0]+screen[j],check[1]+screen[j]]; |
| - | } | + | |
| + | //up | ||
| + | if(d[j]>0 && barpos[j]>check[1]){ | ||
| + | if(barpos[j]-d[j]*vh<check[1]){ | ||
| + | barpos[j]=check[1];//bar.setPosition(posx,-size); | ||
| + | }else{ | ||
| + | barpos[j]=barpos[j]-d[j]*vh;//bar.setPosition(posx,barpos-d*vh); | ||
| + | } | ||
| } | } | ||
| - | /*show the bar */ | + | //down |
| - | if(d<0 && barpos<0){ | + | if(d[j]<0 && barpos[j]<check[0]){ |
| - | if(barpos-d*2>0 || barpos>0){ | + | if(barpos[j]-d[j]*vs>check[0]){ |
| - | bar.setPosition(0,0); | + | barpos[j]=check[0];//bar.setPosition(posx,0); |
| - | }else{ | + | }else{ |
| - | bar.setPosition(0,barpos-d*2); | + | barpos[j]=barpos[j]-d[j]*vs;//bar.setPosition(posx,barpos-d*vs); |
| - | } | + | |
| } | } | ||
| - | </code> | + | } |
| + | |||
| + | } | ||
| + | |||
| + | bar.setPosition(barpos[0],barpos[1]); | ||
| + | </sxh> | ||