protected List<String> getTotalLines() { int w = xSize - border.w * 2 + 2; if(!slider.isHidden()) { w -= slider.width + 3; } w = (int) ((float) w / textScale); List<String> lines = Lists.newLinkedList(); tooltipLines.clear(); for(String line : text) { tooltipLines.add(lines.size()); // empty line if(line == null || line.isEmpty()) { lines.add(""); continue; } lines.addAll(fontRenderer.listFormattedStringToWidth(line, w)); } return lines; }
public void updateSlots() { // calculate displayed slots firstSlotId = slider.getValue() * columns; lastSlotId = Math.min(slotCount, firstSlotId + rows * columns); for(Slot slot : container.inventorySlots) { if(shouldDrawSlot(slot)) { // calc position of the slot int offset = slot.getSlotIndex() - firstSlotId; int x = (offset % columns) * GuiDynInventory.slot.w; int y = (offset / columns) * GuiDynInventory.slot.h; slot.xPos = xOffset + x + 1; slot.yPos = yOffset + y + 1; } else { slot.xPos = 0; slot.yPos = 0; } } }
protected void updateSlider() { int max = 0; if(sliderActive) { slider.show(); max = slotCount / columns - rows + 1; // the assumption here is that for an active slider this always is >0 } else { slider.hide(); } slider.setPosition(guiLeft + xSize - slider.width, guiTop); slider.setSize(ySize); slider.setSliderParameters(0, max, 1); }
protected void updateSliderParameters() { // we assume slider not shown slider.hide(); int h = ySize - 2 * 5; // we use 5 as border thickness // check if we can display all lines if(calcNeededHeight() <= h) // can display all, stay hidden { return; } // we need the slider slider.show(); // check how many lines we can show int neededHeight = calcNeededHeight(); // recalc because width changed due to slider int hiddenRows = (neededHeight - h) / fontRenderer.FONT_HEIGHT; if((neededHeight - h) % fontRenderer.FONT_HEIGHT > 0) { hiddenRows++; } slider.setSliderParameters(0, hiddenRows, 1); }
slider.enable(); this.xSize = columns * slot.w + slider.width + 2 * border.w; slider.disable(); this.xSize = columns * slot.w + border.w * 2; h -= textBackground.h; slider.setPosition(guiLeft + columns * slot.w + border.w, y); slider.setSize(h); slider.setSliderParameters(0, getTotalRows() - getDisplayedRows(), 1);
decrement(); return; increment(); return; float val = (float) (y - clickY) / (float) (getUsableSlidebarHeight() - slider.h); val *= d; setSliderValue(minValue); setSliderValue(maxValue); setSliderValue((int) (minValue + (float) increment * Math.round(val))); else if(x >= 0 && y >= getSliderTop() && x - sliderOffset <= slider.w && y <= getSliderTop() + slider.h) { isHighlighted = true; if(mouseDown) { isScrolling = true; clickX = x - sliderOffset; clickY = y - getSliderTop(); x >= 0 && y >= 0 && x <= slideBar.w && y <= height) { if(y < getSliderTop()) { decrement(); increment();
protected static final GuiElementScalable sliderBackground = GuiGeneric.sliderBackground; protected GuiWidgetSlider slider = new GuiWidgetSlider(sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground); protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { this.mc.getTextureManager().bindTexture(GuiGeneric.LOCATION); if(!slider.isHidden()) { slider.draw();
private GuiWidgetSlider slider = new GuiWidgetSlider(sliderNormal, sliderHover, sliderHover, sliderTop, sliderBot, sliderBar); ListIterator<String> iter = getTotalLines().listIterator(slider.getValue()); while(iter.hasNext()) { if(y + textHeight > lowerBound) { ListIterator<String> iter = getTotalLines().listIterator(slider.getValue()); while(iter.hasNext()) { if(y + textHeight - 0.5f > lowerBound) { slider.update(mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInModule(mouseX, mouseY)); slider.draw();
new GuiWidgetSlider(sliderNormal, sliderHigh, sliderLow, sliderTop, sliderBottom, sliderBackground); if(slider.isEnabled()) { slider.update(mouseX, mouseY, !isMouseOverFullSlot(mouseX, mouseY) && isMouseInModule(mouseX, mouseY)); slider.draw();
@Override public void draw() { if(hidden) { return; } // slidebar background slideBarTop.draw(xPos, yPos); slideBar.drawScaledY(xPos, yPos + slideBarTop.h, getUsableSlidebarHeight()); slideBarBottom.draw(xPos, yPos + height - slideBarBottom.h); int x = xPos + sliderOffset; int y = yPos + getSliderTop(); // the slider depending on state if(enabled) { if(isScrolling) { sliderDisabled.draw(x, y); } else if(isHighlighted) { sliderHighlighted.draw(x, y); } else { slider.draw(x, y); } } else { sliderDisabled.draw(x, y); } }
private void shiftSlider(int xd, int yd) { slider = new GuiWidgetSlider(sliderNormal.shift(xd, yd), sliderHover.shift(xd, yd), sliderHover.shift(xd, yd), sliderTop.shift(xd, yd), sliderBot.shift(xd, yd), sliderBar.shift(xd, yd)); }
private int getSliderTop() { float d = maxValue - minValue; d = (float) (currentValue - minValue) / d; d *= getUsableSlidebarHeight() - slider.h; return (int) d + slideBarTop.h; }
public int getValue() { if(isHidden()) { return 0; } return Math.min(maxValue, Math.max(minValue, currentValue)); }
protected void updateSlots() { firstSlotId = slider.getValue() * columns; lastSlotId = Math.min(slotCount, firstSlotId + getDisplayedRows() * columns); int xd = border.w + xOffset; int yd = border.h + yOffset; if(shouldDrawName()) { yd += textBackground.h; } for(Object o : inventorySlots.inventorySlots) { Slot slot = (Slot) o; if(shouldDrawSlot(slot)) { // calc position of the slot int offset = slot.getSlotIndex() - firstSlotId; int x = (offset % columns) * this.slot.w; int y = (offset / columns) * this.slot.h; slot.xPos = xd + x + 1; slot.yPos = yd + y + 1; if(this.right) { slot.xPos += parent.realWidth; } else { slot.xPos -= this.xSize; } } else { slot.xPos = 0; slot.yPos = 0; } } }