Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package svk.industrialTech.gui;
- import org.lwjgl.input.Mouse;
- import svk.industrialTech.utils.RenderHelper;
- import net.minecraft.client.Minecraft;
- import net.minecraft.util.ResourceLocation;
- public class SmoothScroll
- {
- public final ResourceLocation texture = new ResourceLocation("minecraft:textures/gui/container/creative_inventory/tabs.png");
- int posX, posY, sizeY, step;
- float percent, scrollPower;
- public SmoothScroll(int posX, int posY, int sizeY, int scrollPower)
- {
- this.posX = posX;
- this.posY = posY;
- this.sizeY = sizeY;
- this.scrollPower = scrollPower;
- }
- public void draw()
- {
- Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
- if(percent <= 0.1F) RenderHelper.drawTextureCustomSize(posX, posY, 232, 0, 12, 15, 256, 256);
- else if(percent >= 0.9F) RenderHelper.drawTextureCustomSize(posX, posY + sizeY - 15, 232, 0, 12, 15, 256, 256);
- else RenderHelper.drawTextureCustomSize(posX, posY + sizeY * percent - 7.5F, 232, 0, 12, 15, 256, 256);
- }
- public void mouseClickMove(int x, int y, int key, long time)
- {
- if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
- {
- this.percent = (float) (y - posY)/sizeY;
- if(percent <= 0.1F) percent = 0;
- if(percent >= 0.9F) percent = 1;
- }
- }
- public void handleMouseInput(int x, int y)
- {
- if(x >= posX && y >= posY && x <= posX+12 && y <= posY+sizeY)
- {
- int scrollType = Mouse.getEventDWheel();
- if(scrollType < 0) //Back
- {
- this.scrollDown();
- }
- else if(scrollType > 0)//Back to the future
- {
- this.scrollUp();
- }
- }
- }
- public void scrollUp()
- {
- if(this.percent > 0) this.percent -= scrollPower;
- }
- public void scrollDown()
- {
- if(this.percent < 1) this.percent += scrollPower;
- }
- }
Add Comment
Please, Sign In to add comment