public static void drawText( MenuItem item, String s, boolean centerH, boolean centerV, float x, float y, float width, float height) { try { Graphics2D g2 = (Graphics2D) item.menu.buff.g2; float descent = getTextDescent(item); float xOffset = 0, yOffset = 0; if (centerH) { float tWidth = getTextWidth(item, s); xOffset = (width - tWidth) / 2f; } if (centerV) { float tHeight = getTextHeight(item, s); yOffset = (height - tHeight) / 2f + descent; } else yOffset = height - descent; MenuStyle style = item.getStyle(); PFont font = style.getFont("font"); float fs = style.getF("f.fontSize"); g2.setFont(font.getFont().deriveFont(fs)); if (!item.isEnabled()) g2.setPaint(style.getC("c.foreground").brighter(120)); else g2.setPaint(style.getC("c.foreground")); g2.setStroke(new BasicStroke(style.getF("f.strokeWeight"))); g2.drawString(s, x + xOffset, y + yOffset); } catch (Exception e) { e.printStackTrace(); } }
public static float getTextDescent(MenuItem item) { MenuStyle style = item.getStyle(); return UIUtils.getTextAscent( item.menu.buff, style.getFont("font"), style.getF("f.fontSize"), true); }
public static float getTextHeight(MenuItem item, String s) { MenuStyle style = item.getStyle(); return UIUtils.getTextHeight( item.menu.buff, style.getFont("font"), style.getF("f.fontSize"), s, true); }