Guest User

SmoothScroll

a guest
Jun 28th, 2016
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package svk.industrialTech.gui;
  2.  
  3. import org.lwjgl.input.Mouse;
  4.  
  5. import svk.industrialTech.utils.RenderHelper;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.util.ResourceLocation;
  8.  
  9. public class SmoothScroll
  10. {
  11.     public final ResourceLocation texture = new ResourceLocation("minecraft:textures/gui/container/creative_inventory/tabs.png");
  12.     int posX, posY, sizeY, step;
  13.     float percent, scrollPower;
  14.  
  15.     public SmoothScroll(int posX, int posY, int sizeY, int scrollPower)
  16.     {
  17.         this.posX = posX;
  18.         this.posY = posY;
  19.         this.sizeY = sizeY;
  20.         this.scrollPower = scrollPower;
  21.     }
  22.  
  23.     public void draw()
  24.     {
  25.         Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  26.  
  27.        
  28.         if(percent <= 0.1F) RenderHelper.drawTextureCustomSize(posX, posY, 232, 0, 12, 15, 256, 256);
  29.         else if(percent >= 0.9F) RenderHelper.drawTextureCustomSize(posX, posY + sizeY - 15, 232, 0, 12, 15, 256, 256);
  30.         else RenderHelper.drawTextureCustomSize(posX, posY + sizeY * percent - 7.5F, 232, 0, 12, 15, 256, 256);
  31.     }
  32.  
  33.     public void mouseClickMove(int x, int y, int key, long time)
  34.     {
  35.         if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
  36.         {
  37.             this.percent = (float) (y - posY)/sizeY;
  38.             if(percent <= 0.1F) percent = 0;
  39.             if(percent >= 0.9F) percent = 1;
  40.         }
  41.     }
  42.  
  43.     public void handleMouseInput(int x, int y)
  44.     {
  45.         if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
  46.         {
  47.             int scrollType = Mouse.getEventDWheel();
  48.             if(scrollType < 0) //Back
  49.             {      
  50.                 this.scrollDown();
  51.             }
  52.             else if(scrollType > 0)//Back to the future
  53.             {
  54.                 this.scrollUp();
  55.             }  
  56.         }
  57.     }
  58.    
  59.     public void scrollUp()
  60.     {
  61.         if(this.percent > 0) this.percent -= scrollPower;
  62.         }
  63.  
  64.     public void scrollDown()
  65.     {
  66.         if(this.percent < 1) this.percent += scrollPower;
  67.     }
  68. }
Add Comment
Please, Sign In to add comment