private void renderPoly(Graphics2D graphics, Color color, Polygon polygon) { if (polygon != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(polygon); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(polygon); } } }
public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { int ascent = unicodeFont.getAscent(); float height = (ascent) * scale; float top = -glyph.getYOffset() + unicodeFont.getDescent() + offset + ascent / 2 - height / 2; g.setPaint(new GradientPaint(0, top, topColor, 0, top + height, bottomColor, cyclic)); g.fill(glyph.getShape()); }
g2.setColor(Color.white); g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND)); translate.setToTranslation(offset, offset); shadow.transform(translate); g2.setColor(new Color(150,150,150)); g2.fill(shadow); new BasicStroke( strokeWeight, g2.setColor(shape.getFillColor()); g2.fill(path); g2.setStroke(dashStroke); g2.draw(path); g2.fill(path); g2.draw(path); g2.fill(path); g2.setColor(shape.getStrokeColor()); g2.draw(path);
final HtmlColor extended = fontConfiguration.getExtendedColor(); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Rectangle2D.Double area = new Rectangle2D.Double(x, y - dimBack.getHeight() + 1.5, dimBack.getWidth(), dimBack.getHeight()); if (extended instanceof HtmlColorGradient) { final GradientPaint paint = DriverRectangleG2d.getPaintGradient(x, y, mapper, dimBack.getWidth(), dimBack.getHeight(), extended); g2d.setPaint(paint); g2d.fill(area); } else { final Color backColor = mapper.getMappedColor(extended); if (backColor != null) { g2d.setColor(backColor); g2d.setBackground(backColor); g2d.fill(area); g2d.setColor(mapper.getMappedColor(fontConfiguration.getColor())); g2d.drawString(shape.getText(), (float) x, (float) y); g2d.setColor(mapper.getMappedColor(extended)); g2d.setStroke(new BasicStroke((float) 1)); g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); g2d.setStroke(new BasicStroke()); g2d.setColor(mapper.getMappedColor(extended));
public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); // This is what we want, but it only does hard-clipping, i.e. aliasing // g2.setClip(new RoundRectangle2D ...) // so instead fake soft-clipping by first drawing the desired clip shape // in fully opaque white with antialiasing enabled... g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); // ... then compositing the image on top, // using the white shape from above as alpha source g2.setComposite(AlphaComposite.SrcAtop); g2.drawImage(image, 0, 0, null); g2.dispose(); return output; }
imageTransform.translate(0, -1); Paint awtPaint = new TexturePaint(image, new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(), imageTransform.getScaleX(), imageTransform.getScaleY())); awtPaint = applySoftMaskToPaint(awtPaint, softMask); graphics.setPaint(awtPaint); Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1); if (isContentRendered()) graphics.fill(at.createTransformedShape(unitRect));
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); } }
protected void drawDecoration(Graphics2D graphics, Paint line, BasicStroke stroke) { if(line == null) { return; } graphics.setPaint(line); List<Outline> lst = new ArrayList<>(); LineDecoration deco = getShape().getLineDecoration(); Outline head = getHeadDecoration(graphics, deco, stroke); if (head != null) { lst.add(head); } Outline tail = getTailDecoration(graphics, deco, stroke); if (tail != null) { lst.add(tail); } for(Outline o : lst){ java.awt.Shape s = o.getOutline(); Path p = o.getPath(); graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s); if(p.isFilled()) { graphics.fill(s); } if(p.isStroked()) { graphics.draw(s); } } }
@Override public Dimension render(Graphics2D graphics) { //Construct the arc Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE); arc.setAngleStart(90); arc.setAngleExtent(progress * 360); arc.setFrame(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter); //Draw the inside of the arc graphics.setColor(fill); graphics.fill(arc); //Draw the outlines of the arc graphics.setStroke(stroke); graphics.setColor(borderColor); graphics.drawOval(position.getX() - diameter / 2, position.getY() - diameter / 2, diameter, diameter); return new Dimension(diameter, diameter); }
private void paintDragSelection(Graphics2D g) { if (isDragSelecting) { Rectangle r = dragSelectRect(); g.setColor(DRAG_SELECTION_COLOR); g.setStroke(DRAG_SELECTION_STROKE); g.fill(r); // To get a smooth line we need to subtract one from the width and height. g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth() - 1, (int) r.getHeight() - 1); } }
Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height); g2.setColor(Color.BLACK); g2.fill(casing); g2.setComposite(composite); Area area = new Area(casing); area.subtract(new Area(roundCasing)); g2.fill(area); Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height); g2.setColor(Color.BLACK); g2.fill(casing); g2.setComposite(composite); Area area = new Area(casing); area.subtract(new Area(roundCasing)); g2.fill(area);
public void clearPoints() { Graphics2D imageGraphics = (Graphics2D) pointImg.createGraphics(); imageGraphics.setColor(Color.WHITE); imageGraphics.setPaint(Color.WHITE); imageGraphics.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight())); ApplyToCanvas(pointImg); RedrawPointLayer(); }
@Override public void paint(Graphics2D g, double xOffset, double yOffset, int markerSize) { g.setStroke(stroke); double halfSize = (double) markerSize / 2; Shape square = new Rectangle2D.Double(xOffset - (halfSize / 2), yOffset - halfSize, halfSize, markerSize); g.fill(square); } }
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); p.addPoint((int) xx0, (int) previousHeightxx0); g2.setPaint(getItemPaint(row, column-1)); g2.setStroke(getItemStroke(row, column-1)); g2.fill(p); p.addPoint((int) xx1, (int) previousHeightxx1); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.fill(p);
/** * Draws a filled rectangle of the specified size, centered at (<em>x</em>, <em>y</em>). * * @param x the <em>x</em>-coordinate of the center of the rectangle * @param y the <em>y</em>-coordinate of the center of the rectangle * @param halfWidth one half the width of the rectangle * @param halfHeight one half the height of the rectangle * @throws IllegalArgumentException if either {@code halfWidth} or {@code halfHeight} is negative */ public static void filledRectangle(double x, double y, double halfWidth, double halfHeight) { if (!(halfWidth >= 0)) throw new IllegalArgumentException("half width must be nonnegative"); if (!(halfHeight >= 0)) throw new IllegalArgumentException("half height must be nonnegative"); double xs = scaleX(x); double ys = scaleY(y); double ws = factorX(2*halfWidth); double hs = factorY(2*halfHeight); if (ws <= 1 && hs <= 1) pixel(x, y); else offscreen.fill(new Rectangle2D.Double(xs - ws/2, ys - hs/2, ws, hs)); draw(); }
Rectangle2D rect = new Rectangle2D.Double(x, y, width, height); g2d.draw(rect); g2d.draw(line); for (Point2D p : ps) { if (p != null) { g2d.fill(new Ellipse2D.Double(p.getX() - 4, p.getY() - 4, 8, 8));
private void renderTargetOverlay(Graphics2D graphics, NPC actor, Color color) { Polygon objectClickbox = actor.getConvexHull(); if (objectClickbox != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(objectClickbox); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(objectClickbox); } } }