@Override protected Rectangle[] getInteractableComponentRegions(Slider component) { return new Rectangle[] { new Rectangle( 0, theme.getFontRenderer().FONT_HEIGHT + 2, component.getWidth(), component.getHeight() - theme.getFontRenderer().FONT_HEIGHT) }; }
@Override protected void renderComponent(Slider component) { translateComponent(component, false); // GL settings glEnable(GL_BLEND); glDisable(GL_CULL_FACE); // area & font Rectangle area = component.getArea(); int fontSize = theme.getFontRenderer().FONT_HEIGHT; FontRenderer fontRenderer = theme.getFontRenderer(); // text fontRenderer.drawString( component.getText(), 0, 0, RenderUtil.toRGBA(component.getForegroundColor())); // value String content = null; switch (component.getValueDisplay()) { case DECIMAL: content = Double.toString( (double) (Math.round(component.getValue() / component.getIncrement()) * 1000000 * (long) (component.getIncrement() * 1000000)) / 1000000 / 1000000); break; case INTEGER: content = String.format("%,d", Long.valueOf(Math.round(component.getValue()))); break; case PERCENTAGE: int percent = (int) Math.round( (component.getValue() - component.getMinimumValue()) / (component.getMaximumValue() - component.getMinimumValue()) * 100D); content = String.format("%d%%", percent); default: } if (content != null) { String suffix = component.getContentSuffix(); if (suffix != null && !suffix.trim().isEmpty()) content = content.concat(" ").concat(suffix); fontRenderer.drawString( content, component.getWidth() - fontRenderer.getStringWidth(content), 0, RenderUtil.toRGBA(component.getForegroundColor())); } glDisable(GL_TEXTURE_2D); // line glColor4f(0.03125f, 0.03125f, 0.03125f, 0.25f); glBegin(GL_QUADS); { glVertex2d(1, fontSize + 4); glVertex2d(area.width - 1, fontSize + 4); glVertex2d(area.width - 1, area.height - 2); glVertex2d(1, area.height - 2); } glEnd(); // line shadow glLineWidth(1.0f); glColor4f(0.125f, 0.125f, 0.125f, 0.5f); glBegin(GL_LINE_LOOP); { glVertex2d(1, fontSize + 4); glVertex2d(area.width - 1, fontSize + 4); glVertex2d(area.width - 1, area.height - 2); glVertex2d(1, area.height - 2); } glEnd(); double sliderPercentage = (component.getValue() - component.getMinimumValue()) / (component.getMaximumValue() - component.getMinimumValue()); // slider glColor4f(0.0f + (float) sliderPercentage, 1.0f - (float) sliderPercentage, 0.0f, 0.5f); glBegin(GL_QUADS); { glVertex2d((area.width - 6) * sliderPercentage - 1, fontSize + 1); glVertex2d((area.width - 6) * sliderPercentage + 7, fontSize + 1); glVertex2d((area.width - 6) * sliderPercentage + 7, area.height + 1); glVertex2d((area.width - 6) * sliderPercentage - 1, area.height + 1); } glEnd(); // slider shadow RenderUtil.boxShadow( (area.width - 6) * sliderPercentage - 1, fontSize + 1, (area.width - 6) * sliderPercentage + 7, area.height + 1); // GL resets glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); translateComponent(component, true); }
@Override protected Dimension getDefaultComponentSize(Slider component) { return new Dimension(106, 8 + theme.getFontRenderer().FONT_HEIGHT); }