Search in sources :

Example 41 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project litiengine by gurkenlabs.

the class MapObjectsRenderer method renderName.

private static void renderName(Graphics2D g, IMapObject mapObject) {
    g.setFont(Style.getDefaultFont().deriveFont(Style.getDefaultFont().getSize() * 0.75f));
    FontMetrics fm = g.getFontMetrics();
    String objectName = mapObject.getName();
    if (objectName != null && !objectName.isEmpty()) {
        objectName = truncateName(objectName);
        final int PADDING = 2;
        double stringWidth = fm.stringWidth(objectName) / Game.world().camera().getRenderScale();
        double stringHeight = fm.getHeight() * .5 / Game.world().camera().getRenderScale();
        double x = mapObject.getX() + ((mapObject.getWidth() - stringWidth) / 2.0) - PADDING;
        double y = mapObject.getY() + mapObject.getHeight() + stringHeight;
        double width = stringWidth + PADDING * 2;
        double height = stringHeight + PADDING * 2;
        RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 2, 2);
        g.setColor(new Color(0, 0, 0, 200));
        Game.graphics().renderShape(g, rect, true);
        g.setColor(Color.WHITE);
        Game.graphics().renderText(g, objectName, x + PADDING, rect.getMaxY() - PADDING, true);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Color(java.awt.Color)

Example 42 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project Resource by lovelifeming.

the class MyProcessDiagramCanvas method drawHighLight.

/**
 * 高亮节点设置
 *
 * @param x
 * @param y
 * @param width
 * @param height
 */
public void drawHighLight(int x, int y, int width, int height) {
    Paint originalPaint = g.getPaint();
    Stroke originalStroke = g.getStroke();
    // 设置高亮节点的颜色
    g.setPaint(HIGHLIGHT_COLOR);
    g.setStroke(THICK_TASK_BORDER_STROKE);
    RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20);
    g.draw(rect);
    g.setPaint(originalPaint);
    g.setStroke(originalStroke);
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D)

Example 43 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project mage by magefree.

the class DialogContainer method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    if (!drawContainer) {
        return;
    }
    int x = X_OFFSET;
    int y = Y_OFFSET;
    int w = getWidth() - 2 * X_OFFSET;
    int h = getHeight() - 2 * Y_OFFSET;
    int arc = 30;
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (shadow != null) {
        int xOffset = (shadow.getWidth() - w) / 2;
        int yOffset = (shadow.getHeight() - h) / 2;
        g2.drawImage(shadow, x - xOffset, y - yOffset, null);
    }
    /**
     * Add white translucent substrate
     */
    if (alpha != 0) {
        g2.setColor(new Color(255, 255, 255, alpha));
        g2.fillRoundRect(x, y, w, h, arc, arc);
    }
    if (!isGradient) {
        g2.setColor(backgroundColor);
        g2.fillRoundRect(x, y, w, h, arc, arc);
    } else {
        RoundRectangle2D r = new RoundRectangle2D.Float(x, y, w, h, arc, arc);
        g2.setPaint(tp);
        g2.fill(r);
    }
    // ////////////////////////////////////////////////////////////////
    // ////////////////////////////////////////////////////////////////
    // draw border
    g2.setStroke(new BasicStroke(3f));
    g2.setColor(Color.BLACK);
    // g2.setColor(Color.GRAY);
    g2.drawRoundRect(x, y, w, h, arc, arc);
    // ////////////////////////////////////////////////////////////////
    g2.dispose();
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D)

Example 44 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project mage by magefree.

the class BackgroundPainter method doPaint.

@Override
protected void doPaint(Graphics2D g2, Object o, int i, int i1) {
    float alpha = BACKGROUND_ALPHA;
    Component c = (Component) o;
    Composite composite = g2.getComposite();
    if (composite instanceof AlphaComposite) {
        alpha *= ((AlphaComposite) composite).getAlpha();
    }
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    g2.setColor(bgColor);
    RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, c.getWidth() - 1, c.getHeight() - 1, 24, 24);
    g2.fill(rect);
    Ellipse2D ellipse = new Ellipse2D.Double(-c.getWidth(), c.getHeight() / 3.0, c.getWidth() * 3.0, c.getHeight() * 2.0);
    Area area = new Area(new Rectangle(0, 0, c.getWidth(), c.getHeight()));
    area.subtract(new Area(ellipse));
    area.intersect(new Area(rect));
    alpha = 0.1f;
    if (composite instanceof AlphaComposite) {
        alpha *= ((AlphaComposite) composite).getAlpha();
    }
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    g2.setColor(new Color(1.0f, 1.0f, 1.0f));
    g2.fill(area);
    g2.setComposite(composite);
}
Also used : Area(java.awt.geom.Area) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Ellipse2D(java.awt.geom.Ellipse2D)

Example 45 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project mage by magefree.

the class MageScrollbarUI method paintTrack.

@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
        int width = trackBounds.width - 4 + ANTI_WIDTH;
        int height = trackBounds.height;
        g2.translate(trackBounds.x + 2, trackBounds.y);
        Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
        g2.setColor(Color.BLACK);
        float alpha = 0.5f;
        Composite composite = g2.getComposite();
        if (composite instanceof AlphaComposite) {
            alpha *= ((AlphaComposite) composite).getAlpha();
        }
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(casing);
        g2.setComposite(composite);
        g2.drawLine(-1, 0, -1, height);
        g2.drawLine(-2, 0, -2, height);
        g2.drawLine(width, 0, width, height);
        g2.drawLine(width + 1, 0, width + 1, height);
        RoundRectangle2D roundCasing = new RoundRectangle2D.Double(0, 2, width, height - 4, width, width);
        Area area = new Area(casing);
        area.subtract(new Area(roundCasing));
        g2.fill(area);
        g2.translate(-trackBounds.x - 2, -trackBounds.y);
    } else {
        int width = trackBounds.width;
        int height = trackBounds.height - 4 + ANTI_WIDTH;
        g2.translate(trackBounds.x, trackBounds.y + 2);
        Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
        g2.setColor(Color.BLACK);
        float alpha = 0.5f;
        Composite composite = g2.getComposite();
        if (composite instanceof AlphaComposite) {
            alpha *= ((AlphaComposite) composite).getAlpha();
        }
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(casing);
        g2.setComposite(composite);
        g2.drawLine(0, -1, width, -1);
        g2.drawLine(0, -2, width, -2);
        g2.drawLine(0, height, width, height);
        g2.drawLine(0, height + 1, width, height + 1);
        RoundRectangle2D roundCasing = new RoundRectangle2D.Double(2, 0, width - 4, height, height, height);
        Area area = new Area(casing);
        area.subtract(new Area(roundCasing));
        g2.fill(area);
        g2.translate(-trackBounds.x, -trackBounds.y - 2);
    }
}
Also used : Area(java.awt.geom.Area) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Aggregations

RoundRectangle2D (java.awt.geom.RoundRectangle2D)45 Color (java.awt.Color)14 Graphics2D (java.awt.Graphics2D)13 Paint (java.awt.Paint)12 BasicStroke (java.awt.BasicStroke)11 Stroke (java.awt.Stroke)10 GradientPaint (java.awt.GradientPaint)8 Ellipse2D (java.awt.geom.Ellipse2D)8 Area (java.awt.geom.Area)7 Rectangle2D (java.awt.geom.Rectangle2D)7 Line2D (java.awt.geom.Line2D)6 RadialGradientPaint (java.awt.RadialGradientPaint)5 Rectangle (java.awt.Rectangle)5 Point (java.awt.Point)4 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)3 FontMetrics (java.awt.FontMetrics)3 Arc2D (java.awt.geom.Arc2D)3 Point2D (java.awt.geom.Point2D)3 MolecularType (org.vcell.model.rbm.MolecularType)3 Font (java.awt.Font)2