/** * Draws the elements for this GUI. */ protected void drawElements(float partialTick, boolean foreground) { if (foreground) { for (ElementBase element : elements) { if (element.isVisible()) { element.drawForeground(mouseX, mouseY); } } } else { for (ElementBase element : elements) { if (element.isVisible()) { element.drawBackground(mouseX, mouseY, partialTick); } } } }
protected final void updateElements() { for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (c.isVisible() && c.isEnabled()) { c.update(mouseX, mouseY); } } }
@Override public void onMouseReleased(int mouseX, int mouseY) { mouseX -= this.posX(); mouseY -= this.posY; for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled()) { // no bounds checking on mouseUp events continue; } c.onMouseReleased(mouseX, mouseY); } }
@Override public boolean onKeyTyped(char characterTyped, int keyPressed) { for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled()) { continue; } if (c.onKeyTyped(characterTyped, keyPressed)) { return true; } } return super.onKeyTyped(characterTyped, keyPressed); }
@Override protected void keyTyped(char characterTyped, int keyPressed) throws IOException { for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled()) { continue; } if (c.onKeyTyped(characterTyped, keyPressed)) { return; } } super.keyTyped(characterTyped, keyPressed); }
@Override public void update(int mouseX, int mouseY) { super.update(mouseX, mouseY); mouseX -= this.posX(); mouseY -= this.posY; for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (c.isVisible() && c.isEnabled()) { c.update(mouseX, mouseY); } } }
@Override protected void mouseReleased(int mX, int mY, int mouseButton) { mX -= guiLeft; mY -= guiTop; if (mouseButton >= 0 && mouseButton <= 2) { // 0:left, 1:right, 2: middle for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled()) { // no bounds checking on mouseUp events continue; } c.onMouseReleased(mX, mY); } } mX += guiLeft; mY += guiTop; super.mouseReleased(mX, mY, mouseButton); }
@Override public void addTooltip(List<String> list) { for (int i = 0; i < this.elements.size(); i++) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(gui.getMouseX(), gui.getMouseY())) { continue; } c.addTooltip(list); } }
/** * @return Whether the tab should stay open or not. */ @Override public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) throws IOException { mouseX -= this.posX(); mouseY -= this.posY; boolean shouldStayOpen = false; for (int i = 0; i < this.elements.size(); i++) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) { continue; } shouldStayOpen = true; if (c.onMousePressed(mouseX, mouseY, mouseButton)) { return true; } } return shouldStayOpen; }
@Override public boolean onMouseWheel(int mouseX, int mouseY, int movement) { int wheelMovement = Mouse.getEventDWheel(); mouseX -= this.posX(); mouseY -= this.posY; if (wheelMovement != 0) { for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) { continue; } if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) { return true; } } } return true; }
public void addTooltips(List<String> tooltip) { TabBase tab = getTabAtPosition(mouseX, mouseY); if (tab != null) { tab.addTooltip(tooltip); } ElementBase element = getElementAtPosition(mouseX, mouseY); if (element != null && element.isVisible()) { element.addTooltip(tooltip); } }
if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mX, mY)) { continue;
@Override public void drawForeground(int mouseX, int mouseY) { mouseX -= this.posX(); mouseY -= this.posY; GlStateManager.pushMatrix(); GlStateManager.translate(this.posX(), this.posY, 0.0F); drawForeground(); for (ElementBase element : elements) { if (element.isVisible()) { element.drawForeground(mouseX, mouseY); } } GlStateManager.popMatrix(); }
@Override public void drawBackground(int mouseX, int mouseY, float gameTicks) { mouseX -= this.posX(); mouseY -= this.posY; GlStateManager.pushMatrix(); GlStateManager.translate(this.posX(), this.posY, 0.0F); drawBackground(); for (ElementBase element : elements) { if (element.isVisible()) { element.drawBackground(mouseX, mouseY, gameTicks); } } GlStateManager.popMatrix(); }
@Override public void handleMouseInput() throws IOException { int x = Mouse.getEventX() * width / mc.displayWidth; int y = height - Mouse.getEventY() * height / mc.displayHeight - 1; mouseX = x - guiLeft; mouseY = y - guiTop; int wheelMovement = Mouse.getEventDWheel(); if (wheelMovement != 0) { for (int i = elements.size(); i-- > 0; ) { ElementBase c = elements.get(i); if (!c.isVisible() || !c.isEnabled() || !c.intersectsWith(mouseX, mouseY)) { continue; } if (c.onMouseWheel(mouseX, mouseY, wheelMovement)) { return; } } TabBase tab = getTabAtPosition(mouseX, mouseY); if (tab != null && tab.onMouseWheel(mouseX, mouseY, wheelMovement)) { return; } if (onMouseWheel(mouseX, mouseY, wheelMovement)) { return; } } super.handleMouseInput(); }