Refine search
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); }
int getGradientSteps(Shape gradientShape) { Rectangle rect = gradientShape.getBounds(); int lower = 1; int upper = (int)(Math.max(rect.getWidth(),rect.getHeight())/2.0); while (lower < upper-1) { int mid = lower + (upper - lower) / 2; BasicStroke bs = new BasicStroke(mid, capStyle, joinStyle); Area area = new Area(bs.createStrokedShape(gradientShape)); if (area.isSingular()) { upper = mid; } else { lower = mid; } } return upper; }
@Override public void setBounds(int x, int y, int width, int height) { if (containedInScreen) { Rectangle bounds = this.getGraphicsConfiguration().getBounds(); width = Math.min(width, width - (int)bounds.getX() + x); x = Math.max(x, (int)bounds.getX()); height = Math.min(height, height - (int)bounds.getY() + y); y = Math.max(y, (int)bounds.getY()); width = Math.min(width, (int)(bounds.getX() + bounds.getWidth()) - x); height = Math.min(height, (int)(bounds.getY() + bounds.getHeight()) - y); } super.setBounds(x, y, width, height); }
public ImageTransmitter(DatagramSocket socket, InetAddress remoteHost, int remotePort, Rectangle area) { try { robot = new Robot(); maxI = (int) Math.ceil(area.getWidth() / tileWidth); maxJ = (int) Math.ceil(area.getHeight() / tileWidth); tiles = new int[maxI][maxJ][tileWidth * tileWidth]; this.area = area; this.socket = socket; localHost = socket.getLocalAddress(); localPort = socket.getLocalPort(); this.remoteHost = remoteHost; this.remotePort = remotePort; this.encoder = new DefaultEncoder(); transmit = true; } catch (AWTException e) { LOGGER.log(Level.WARNING, "exception", e); } }
@Override public void setLocation(int x, int y) { if (containedInScreen) { Rectangle bounds = this.getGraphicsConfiguration().getBounds(); x = Math.max(x, (int)bounds.getX()); x = Math.min(x, (int)(bounds.getX() + bounds.getWidth() - this.getWidth())); y = Math.max(y, (int)bounds.getY()); y = Math.min(y, (int)(bounds.getY() + bounds.getHeight() - this.getHeight())); } super.setLocation(x, y); }
@NotNull private static List<EditorWindow> findWindowsInRow(@NotNull EditorWindow anchor, @NotNull List<EditorWindow> windows, final boolean vertical) { final Rectangle anchorRect = getEditorWindowRectangle(anchor); if (anchorRect != null) { final List<EditorWindow> result = new ArrayList<>(); final double coord = vertical ? anchorRect.getX() : anchorRect.getY(); for (EditorWindow window : windows) { final Rectangle rect = getEditorWindowRectangle(window); if (rect != null) { final double min = vertical ? rect.getX() : rect.getY(); final double max = min + (vertical ? rect.getWidth() : rect.getHeight()); if (coord >= min && coord <= max) { result.add(window); } } } result.sort((window1, window2) -> { final Rectangle rect1 = getEditorWindowRectangle(window1); final Rectangle rect2 = getEditorWindowRectangle(window2); if (rect1 != null && rect2 != null) { final double diff = vertical ? (rect1.getY() - rect2.getY()) : (rect1.getX() - rect2.getX()); return diff < 0 ? -1 : diff > 0 ? 1 : 0; } return 0; }); return result; } return Collections.singletonList(anchor); }
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 Point clipToRectangle(Point drawPoint, Rectangle mapDisplayRectangle) { int clippedX = drawPoint.getX(); if (drawPoint.getX() < mapDisplayRectangle.getX()) { clippedX = (int) mapDisplayRectangle.getX(); } if (drawPoint.getX() > mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth()) { clippedX = (int) (mapDisplayRectangle.getX() + mapDisplayRectangle.getWidth()); } int clippedY = drawPoint.getY(); if (drawPoint.getY() < mapDisplayRectangle.getY()) { clippedY = (int) mapDisplayRectangle.getY(); } if (drawPoint.getY() > mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight()) { clippedY = (int) (mapDisplayRectangle.getY() + mapDisplayRectangle.getHeight()); } return new Point(clippedX, clippedY); } }
private GeneralPath makeEllipsePath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); float xOff = (float) bounds.getWidth() * 0.5f * KAPPA; float yOff = (float) bounds.getHeight() * 0.5f * KAPPA; ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY()); ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY()); ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY()); ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY()); ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(top.x, top.y); path.curveTo(top.x + xOff, top.y, right.x, right.y - yOff, right.x, right.y); path.curveTo(right.x, right.y + yOff, bottom.x + xOff, bottom.y, bottom.x, bottom.y); path.curveTo(bottom.x - xOff, bottom.y, left.x, left.y + yOff, left.x, left.y); path.curveTo(left.x, left.y - yOff, top.x - xOff, top.y, top.x, top.y); path.closePath(); return path; }
private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint) { String tooltip = worldPoint.getTooltip(); Point drawPoint = mapWorldPointToGraphicsPoint(worldPoint.getWorldPoint()); if (tooltip == null || tooltip.length() <= 0 || drawPoint == null) { return; } drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT); graphics.setClip(client.getCanvas().getBounds()); graphics.setColor(JagexColors.TOOLTIP_BACKGROUND); graphics.setFont(FontManager.getRunescapeFont()); FontMetrics fm = graphics.getFontMetrics(); int width = fm.stringWidth(tooltip); int height = fm.getHeight(); Rectangle tooltipRect = new Rectangle(drawPoint.getX() - TOOLTIP_PADDING_WIDTH, drawPoint.getY() - TOOLTIP_PADDING_HEIGHT, width + TOOLTIP_PADDING_WIDTH * 2, height + TOOLTIP_PADDING_HEIGHT * 2); graphics.fillRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight()); graphics.setColor(JagexColors.TOOLTIP_BORDER); graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight()); graphics.setColor(JagexColors.TOOLTIP_TEXT); graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + height); }
void createRaster() { ColorModel cm = getColorModel(); raster = cm.createCompatibleWritableRaster((int)deviceBounds.getWidth(), (int)deviceBounds.getHeight()); BufferedImage img = new BufferedImage(cm, raster, false, null); Graphics2D graphics = img.createGraphics(); graphics.setRenderingHints(hints); graphics.translate(-deviceBounds.getX(), -deviceBounds.getY()); graphics.transform(xform); Raster img2 = pCtx.getRaster(0, 0, gradientSteps, 1); int[] rgb = new int[cm.getNumComponents()]; for (int i = gradientSteps-1; i>=0; i--) { img2.getPixel(i, 0, rgb); Color c = new Color(rgb[0],rgb[1],rgb[2]); if (rgb.length == 4) { // it doesn't work to use just a color with transparency ... graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, rgb[3]/255.0f)); } graphics.setStroke(new BasicStroke(i+1, capStyle, joinStyle)); graphics.setColor(c); graphics.draw(shape); } graphics.dispose(); } }
graphics.setClip(worldMapRect); int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile); int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile); int xTileOffset = x + widthInTiles / 2 - worldMapPosition.getX(); int xPos = ((int) (xTileOffset * pixelsPerTile)) + (int) worldMapRect.getX(); int yPos = (worldMapRect.height - (int) (yTileOffset * pixelsPerTile)) + (int) worldMapRect.getY();
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() call in * constructors"). */ private static MathTransform getMathTransform( final Rectangle gridRange, final Rectangle2D userRange) { final double scaleX = userRange.getWidth() / gridRange.getWidth(); final double scaleY = userRange.getHeight() / gridRange.getHeight(); final double transX = userRange.getMinX() - gridRange.x * scaleX; final double transY = userRange.getMaxY() + gridRange.y * scaleY; final AffineTransform tr = new AffineTransform(scaleX, 0, 0, -scaleY, transX, transY); tr.translate(0.5, 0.5); // Maps to pixel center return ProjectiveTransform.create(tr); }
private BufferedImage renderGlyph(GeneralPath path, Rectangle2D bounds2D, Rectangle cellRect) { BufferedImage bim = new BufferedImage((int) cellRect.getWidth(), (int) cellRect.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bim.getGraphics(); g.setBackground(Color.white); g.clearRect(0, 0, bim.getWidth(), bim.getHeight()); double scale = 1 / ((yBounds[1] - yBounds[0]) / cellRect.getHeight()); // flip g.scale(1, -1); g.translate(0, -bim.getHeight()); // horizontal center g.translate((cellRect.getWidth() - bounds2D.getWidth() * scale) / 2, 0); // scale from the glyph to the cell g.scale(scale, scale); // Adjust for negative y min bound g.translate(0, -yBounds[0]); g.setColor(Color.black); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.fill(path); g.dispose(); return bim; } }