LapisSea

Untitled

Apr 12th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setUpButtons(){
  2.     buttons=$(".Button");
  3.     buttons.unbind();
  4.     buttons.each((i,button)=>{
  5.         if(!button.cricleAnim){
  6.             button.cricleAnim=new Animation(button);
  7.             button.updateSiz=()=>{
  8.                 var c=button.canv,w=button.clientWidth,h=button.clientHeight;
  9.                 if(c.width!=w||c.height!=h){
  10.                     $(c).css({
  11.                         width:(c.width=w)+"px",
  12.                         height:(c.height=h)+"px"
  13.                     });
  14.                     button.rad=Math.sqrt(w*w+h*h);
  15.                     button.lastTrans=-1;
  16.                 }
  17.             };
  18.             button.updateMouse=(e)=>{
  19.                 var off=$(button).offset();
  20.                 button.mousePos.x=e.pageX-off.left;
  21.                 button.mousePos.y=e.pageY-off.top;
  22.             }
  23.             button.mousePos={x:0,y:0};
  24.             button.lastTrans=0;
  25.             button.canv=button.children[0];
  26.            
  27.             button.canv.ctx=button.canv.getContext("2d");
  28.            
  29.             var col=$(button).attr("cricCol");
  30.            
  31.             var id=parseInt(col);
  32.             if((id+"")!="NaN"){
  33.                 var bodyStyles = window.getComputedStyle(document.body);
  34.                 var name;
  35.                 switch(id){
  36.                     case 0:name="main";break;
  37.                     case 1:name="seco";break;
  38.                 }
  39.                 col=bodyStyles.getPropertyValue("--"+name);
  40.             }
  41.             if(!col)col=$("body").css("background-color");
  42.             button.cricColor=col;
  43.         }
  44.     });
  45.     buttons.click((e1)=>{
  46.         var e=e1||window.event,that=e.currentTarget;
  47.        
  48.         that.cricleAnim.setDel(0);
  49.         that.updateMouse(e);
  50.        
  51.     });
  52.     buttons.mousedown((e1)=>{
  53.         var e=e1||window.event,that=e.currentTarget;
  54.         that.cricleAnim.set(1);
  55.         mouseDown=true;
  56.         that.updateMouse(e);
  57.     });
  58.     buttons.mouseup((e1)=>{
  59.         var e=e1||window.event,that=e.currentTarget;
  60.         mouseDown=false;
  61.         that.updateMouse(e);
  62.     });
  63.     buttons.mouseenter((e1)=>{
  64.         var e=e1||window.event,that=e.currentTarget;
  65.         if(mouseDown){
  66.             that.cricleAnim.set(1);
  67.             that.updateMouse(e);
  68.         }else{
  69.             that.cricleAnim.start=0
  70.             that.cricleAnim.end=0
  71.         }
  72.     });
  73.     buttons.mouseleave((e1)=>{
  74.         var e=e1||window.event,that=e.currentTarget;
  75.        
  76.         if(mouseDown){
  77.             that.cricleAnim.set(0);
  78.             that.updateMouse(e1||window.event);
  79.         }else if(that.cricleAnim.del==-1){
  80.             that.cricleAnim.set(0);
  81.         }
  82.        
  83.     });
  84.    
  85.     buttons.on("clsCh",(e1)=>{
  86.         var e=e1||window.event,that=e.currentTarget;
  87.         that.updateSiz();
  88.     });
  89.    
  90.     buttons.resize((e1)=>{
  91.         e.currentTarget.updateSiz();
  92.     });
  93. }
  94.  
  95.  
  96. function draw(){
  97.     var tim=time();
  98.     for(var i=0;i<buttons.length;i++){
  99.         var button=buttons[i];
  100.        
  101.         var clickTrans;
  102.         if($(button).hasClass("Disabled"))clickTrans=1;
  103.         else{
  104.             clickTrans=button.cricleAnim.get();
  105.             if(clickTrans<0)clickTrans=0;
  106.             if(clickTrans>1)clickTrans=1;
  107.         }
  108.  
  109.         if(button.lastTrans==clickTrans)continue;
  110.         button.lastTrans=clickTrans;
  111.         drawButtonCricle(button,clickTrans);
  112.     }
  113. }
  114. function drawButtonCricle(button,trans){
  115.     var can=button.canv,ctx=can.ctx,w=can.width,h=can.height;
  116.     ctx.fillStyle=button.cricColor;
  117.     ctx.clearRect(0,0,w,h);
  118.     var rad=trans*trans*1.3*button.rad;
  119.    
  120.     if(rad<button.rad){
  121.         var x=button.mousePos.x, y=button.mousePos.y;
  122.         x=x/w*2;
  123.         if(x>1)x=Math.sqrt(x-1)+1;
  124.         else x*=x;
  125.         x*=w/2;
  126.        
  127.         y=y/h*2;
  128.         if(y>1)y=Math.sqrt(y-1)+1;
  129.         else y*=y;
  130.         y*=h/2;
  131.        
  132.         ctx.beginPath();
  133.         ctx.arc(x,y, rad, 0, 2 * Math.PI, false);
  134.         ctx.fill();
  135.     }else ctx.fillRect(0,0,w,h);
  136. }
Add Comment
Please, Sign In to add comment