Add scroll wheel support for GuiScrollList (and empty super on GuiElement)

This commit is contained in:
Xander Victory committed 2017-04-27 14:04:03 +08:00
1 parent 78b468176b
commit a85d41b49a
3 files changed
+33

No files matched your search

@@ -21,6 +21,7 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
public abstract class GuiMekanism extends GuiContainer implements IGuiWrapper
{
@@ -258,6 +259,26 @@ public abstract class GuiMekanism extends GuiContainer implements IGuiWrapper
handleMouseClick(slot, slotIndex, button, modifier);
}
@Override
public void handleMouseInput() throws java.io.IOException
{
int xAxis = Mouse.getEventX() * this.width / this.mc.displayWidth - this.getXPos();
int yAxis = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1 - this.getYPos();
int delta = Mouse.getEventDWheel();
if (delta != 0) {
mouseWheel(xAxis, yAxis, delta);
}
super.handleMouseInput();
}
public void mouseWheel(int xAxis, int yAxis, int delta)
{
for(GuiElement element : guiElements)
{
element.mouseWheel(xAxis, yAxis, delta);
}
}
public int getXPos()
{
return (width - xSize) / 2;
@@ -126,6 +126,8 @@ public abstract class GuiElement
public void mouseReleased(int x, int y, int type) {}
public void mouseWheel(int x, int y, int delta) {}
public abstract Rectangle4i getBounds(int guiWidth, int guiHeight);
public abstract void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight);
@@ -244,4 +244,14 @@ public class GuiScrollList extends GuiElement
}
}
}
@Override
public void mouseWheel(int x, int y, int delta)
{
if (x > xPosition && x < xPosition+xSize && y > yPosition && y < yPosition+size*10){
scroll = Math.min(Math.max(scroll - (delta / 120F) * (1F / textEntries.size()), 0), 1); // 120 = DirectInput factor for one notch. Linux/OSX LWGL scale accordingly
drawScroll();
}
super.mouseWheel(x, y, delta);
}
}