public void drawText( String text, int x, int y ) { int height = gc.getFontMetrics().getHeight(); String[] lines = text.split( "\n" ); for ( String line : lines ) { gc.drawString( line, x + xOffset, y + height + yOffset ); y += height; } }
protected void paintComponent (Graphics graphics) { super.paintComponent(graphics); Graphics2D g = (Graphics2D)graphics; int width = getWidth(); int height = getHeight(); g.setColor(bgColor); g.fillRect(border, border, width - border * 2, height - border * 2); int maxKnobX = width - border - KNOB_WIDTH; int knobX = (int)((width - border * 2 - KNOB_WIDTH) * (value - sliderMin) / (sliderMax - sliderMin)) + border; g.setColor(knobColor); g.fillRect(Math.max(border, Math.min(maxKnobX, knobX)), 0, KNOB_WIDTH, height); float displayValue = (int)(value * 10) / 10f; String label = displayValue == (int)displayValue ? String.valueOf((int)displayValue) : String.valueOf(displayValue); FontMetrics metrics = g.getFontMetrics(); int labelWidth = metrics.stringWidth(label); g.setColor(Color.white); g.drawString(label, width / 2 - labelWidth / 2, height / 2 + metrics.getAscent() / 2); }
public int getAscent(Font font){ fakeGraphics.setFont(font); FontMetrics metrics = fakeGraphics.getFontMetrics(); if(DEBUG) System.out.println("Ascent: "+metrics.getAscent()); return metrics.getAscent(); }
private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int itemId, Color color) { if (itemId == -1) { return; } String text = itemId + ""; FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, graphics); int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(Color.BLACK); graphics.drawString(text, textX + 1, textY + 1); graphics.setColor(color); graphics.drawString(text, textX, textY); }
@Override public Dimension render(Graphics2D graphics) { graphics.translate(preferredLocation.x, preferredLocation.y); final FontMetrics metrics = graphics.getFontMetrics(); final TextComponent titleComponent = new TextComponent(); titleComponent.setText(text); titleComponent.setColor(color); titleComponent.setPosition(new Point((preferredSize.width - metrics.stringWidth(text)) / 2, metrics.getHeight())); final Dimension dimension = titleComponent.render(graphics); graphics.translate(-preferredLocation.x, -preferredLocation.y); return new Dimension(preferredSize.width, dimension.height); } }
final Color extended = mapper.getMappedColor(fontConfiguration.getExtendedColor()); if (extended != null) { g2d.setColor(extended); g2d.setBackground(extended); g2d.fill(new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, dimBack.getWidth(), dimBack visible.ensureVisible(x + dimBack.getWidth(), y + 1.5); g2d.setFont(font.getFont()); g2d.setColor(mapper.getMappedColor(fontConfiguration.getColor())); final TextLayout t = new TextLayout(shape.getText(), font.getFont(), fontRenderContext); g2d.translate(x, y); final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { g2d.setColor(mapper.getMappedColor(extended)); final FontMetrics fm = g2d.getFontMetrics(font.getFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); final HtmlColor extended = fontConfiguration.getExtendedColor();
private void renderIconsAndCounters(Graphics2D graphics, int x, int y, Image image, String counterText, int counterPadding) { final int widthOfCounter = graphics.getFontMetrics().stringWidth(counterText); final int centerText = (WIDTH - PADDING) / 2 - (widthOfCounter / 2); if (config.enableCounter()) { graphics.setFont(FontManager.getRunescapeSmallFont()); textComponent.setColor(Color.WHITE); textComponent.setText(counterText); textComponent.setPosition(new java.awt.Point(x + centerText + counterPadding, y + COUNTER_ICON_HEIGHT)); } else { textComponent.setText(""); } if (config.enableSkillIcon()) { graphics.drawImage(image, x + ICON_AND_COUNTER_OFFSET_X + PADDING, y + ICON_AND_COUNTER_OFFSET_Y - image.getWidth(null), null); textComponent.setPosition(new java.awt.Point(x + centerText + counterPadding, y + SKILL_ICON_HEIGHT)); } textComponent.render(graphics); } }
/** * Write the given text string in the current font, left-aligned at (<em>x</em>, <em>y</em>). * @param x the <em>x</em>-coordinate of the text * @param y the <em>y</em>-coordinate of the text * @param text the text */ public static void textLeft(double x, double y, String text) { if (text == null) throw new IllegalArgumentException(); offscreen.setFont(font); FontMetrics metrics = offscreen.getFontMetrics(); double xs = scaleX(x); double ys = scaleY(y); int hs = metrics.getDescent(); offscreen.drawString(text, (float) xs, (float) (ys + hs)); draw(); }
@Override public Dimension render(Graphics2D graphics) { if (!config.drawFps()) { return null; } final String text = client.getFPS() + FPS_STRING; final int textWidth = graphics.getFontMetrics().stringWidth(text); final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent(); final int width = (int) client.getRealDimensions().getWidth(); final Point point = new Point(width - textWidth - VALUE_X_OFFSET, textHeight + Y_OFFSET); OverlayUtil.renderTextLocation(graphics, point, text, getFpsValueColor()); return null; } }
g.draw(path); g.fillArc(startX, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360); g.drawString(label, startX + LABEL_OFFSET, y - LABEL_OFFSET); } else { int startX = x1; path.lineTo(endX + ARROW_WIDTH, y + ARROW_WIDTH); g.draw(path); int labelWidth = g.getFontMetrics().stringWidth(label); g.fillArc(startX - CIRCLE_WIDTH / 2, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360); g.drawString(label, startX - LABEL_OFFSET - labelWidth, y - LABEL_OFFSET);
int expeditiousCount = plugin.getExpeditiousChargeCount(); graphics.setFont(FontManager.getRunescapeSmallFont()); : graphics.getFontMetrics().getHeight()))); textComponent.render(graphics);
public Point textExtent( String text ) { String[] lines = text.split( Const.CR ); int maxWidth = 0; for ( String line : lines ) { Rectangle2D bounds = TextUtilities.getTextBounds( line, gc, gc.getFontMetrics() ); if ( bounds.getWidth() > maxWidth ) { maxWidth = (int) bounds.getWidth(); } } int height = gc.getFontMetrics().getHeight() * lines.length; return new Point( maxWidth, height ); }
protected void paintComponent (Graphics graphics) { super.paintComponent(graphics); Graphics2D g = (Graphics2D)graphics; int width = getWidth(); int height = getHeight(); g.setColor(bgColor); g.fillRect(border, border, width - border * 2, height - border * 2); int maxKnobX = width - border - KNOB_WIDTH; int knobX = (int)((width - border * 2 - KNOB_WIDTH) * (value - sliderMin) / (sliderMax - sliderMin)) + border; g.setColor(knobColor); g.fillRect(Math.max(border, Math.min(maxKnobX, knobX)), 0, KNOB_WIDTH, height); float displayValue = (int)(value * 10) / 10f; String label = displayValue == (int)displayValue ? String.valueOf((int)displayValue) : String.valueOf(displayValue); FontMetrics metrics = g.getFontMetrics(); int labelWidth = metrics.stringWidth(label); g.setColor(Color.white); g.drawString(label, width / 2 - labelWidth / 2, height / 2 + metrics.getAscent() / 2); }
private void renderInventory(Graphics2D graphics) { Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY); if (inventoryWidget == null || inventoryWidget.isHidden()) { return; } for (WidgetItem item : inventoryWidget.getWidgetItems()) { Rectangle slotBounds = item.getCanvasBounds(); String idText = "" + item.getId(); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(idText, graphics); int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2)); graphics.setColor(new Color(255, 255, 255, 65)); graphics.fill(slotBounds); graphics.setColor(Color.BLACK); graphics.drawString(idText, textX + 1, textY + 1); graphics.setColor(YELLOW); graphics.drawString(idText, textX, textY); } }
private void drawProgressLabel(Graphics2D graphics, XpGlobe globe, int startXp, int goalXp, int x, int y) { if (goalXp <= globe.getCurrentXp()) { return; } // Convert to int just to limit the decimal cases String progress = (int) (getSkillProgress(startXp, globe.getCurrentXp(), goalXp)) + "%"; final FontMetrics metrics = graphics.getFontMetrics(); int drawX = x + (config.xpOrbSize() / 2) - (metrics.stringWidth(progress) / 2); int drawY = y + (config.xpOrbSize() / 2) + (metrics.getHeight() / 2); OverlayUtil.renderTextLocation(graphics, new Point(drawX, drawY), progress, Color.WHITE); }
graphics.setFont(getSize() < DEFAULT_SIZE ? FontManager.getRunescapeSmallFont() : FontManager.getRunescapeFont()); graphics.translate(preferredLocation.x, preferredLocation.y); final FontMetrics metrics = graphics.getFontMetrics(); final int size = getSize(); final Rectangle bounds = new Rectangle(size, size); textComponent.setColor(color); textComponent.setText(text); textComponent.setPosition(new Point(((size - metrics.stringWidth(text)) / 2), size - SEPARATOR)); textComponent.render(graphics);
/** * Writes the given text string in the current font, left-aligned at (x, y). * * @param x the x-coordinate of the text * @param y the y-coordinate of the text * @param s the text */ public void textLeft(double x, double y, String s) { offscreen.setFont(font); FontMetrics metrics = offscreen.getFontMetrics(); double xs = scaleX(x); double ys = scaleY(y); // int ws = metrics.stringWidth(s); int hs = metrics.getDescent(); offscreen.drawString(s, (float) xs, (float) (ys + hs)); draw(); }
@Override public Dimension render(Graphics2D graphics) { panelComponent.getChildren().clear(); boolean warnedSkillSelected = plugin.isWarnedSkillSelected(); if (warnedSkillSelected || config.alwaysShowStyle()) { final String attackStyleString = plugin.getAttackStyle().getName(); panelComponent.getChildren().add(TitleComponent.builder() .text(attackStyleString) .color(warnedSkillSelected ? Color.RED : Color.WHITE) .build()); panelComponent.setPreferredSize(new Dimension( graphics.getFontMetrics().stringWidth(attackStyleString) + 10, 0)); return panelComponent.render(graphics); } return null; } }
public void drawText( String text, int x, int y ) { int height = gc.getFontMetrics().getHeight(); String[] lines = text.split( "\n" ); for ( String line : lines ) { gc.drawString( line, x + xOffset, y + height + yOffset ); y += height; } }
public Point textExtent( String text ) { String[] lines = text.split( Const.CR ); int maxWidth = 0; for ( String line : lines ) { Rectangle2D bounds = TextUtilities.getTextBounds( line, gc, gc.getFontMetrics() ); if ( bounds.getWidth() > maxWidth ) { maxWidth = (int) bounds.getWidth(); } } int height = gc.getFontMetrics().getHeight() * lines.length; return new Point( maxWidth, height ); }