Search in sources :

Example 16 with AffineTransform

use of java.awt.geom.AffineTransform in project processing by processing.

the class Toolkit method getMonoFontList.

// Gets the plain (not bold, not italic) version of each
private static List<Font> getMonoFontList() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    List<Font> outgoing = new ArrayList<Font>();
    // Using AffineTransform.getScaleInstance(100, 100) doesn't change sizes
    FontRenderContext frc = new FontRenderContext(new AffineTransform(), Preferences.getBoolean("editor.antialias"), // use fractional metrics
    true);
    for (Font font : fonts) {
        if (font.getStyle() == Font.PLAIN && font.canDisplay('i') && font.canDisplay('M') && font.canDisplay(' ') && font.canDisplay('.')) {
            // The old method just returns 1 or 0, and using deriveFont(size)
            // is overkill. It also causes deprecation warnings
            //        @SuppressWarnings("deprecation")
            //        FontMetrics fm = awtToolkit.getFontMetrics(font);
            //FontMetrics fm = awtToolkit.getFontMetrics(font.deriveFont(24));
            //        System.out.println(fm.charWidth('i') + " " + fm.charWidth('M'));
            //        if (fm.charWidth('i') == fm.charWidth('M') &&
            //            fm.charWidth('M') == fm.charWidth(' ') &&
            //            fm.charWidth(' ') == fm.charWidth('.')) {
            double w = font.getStringBounds(" ", frc).getWidth();
            if (w == font.getStringBounds("i", frc).getWidth() && w == font.getStringBounds("M", frc).getWidth() && w == font.getStringBounds(".", frc).getWidth()) {
                //          //PApplet.printArray(font.getAvailableAttributes());
                //          Map<TextAttribute,?> attr = font.getAttributes();
                //          System.out.println(font.getFamily() + " > " + font.getName());
                //          System.out.println(font.getAttributes());
                //          System.out.println("  " + attr.get(TextAttribute.WEIGHT));
                //          System.out.println("  " + attr.get(TextAttribute.POSTURE));
                outgoing.add(font);
            //          System.out.println("  good " + w);
            }
        }
    }
    return outgoing;
}
Also used : ArrayList(java.util.ArrayList) AffineTransform(java.awt.geom.AffineTransform) FontRenderContext(java.awt.font.FontRenderContext) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font)

Example 17 with AffineTransform

use of java.awt.geom.AffineTransform in project processing by processing.

the class ColorControlBox method draw.

public void draw(Graphics2D g2d) {
    if (!visible) {
        return;
    }
    AffineTransform trans = g2d.getTransform();
    g2d.translate(x, y);
    // draw current color
    g2d.setColor(color);
    g2d.fillRoundRect(0, 0, width, height, 5, 5);
    // draw black outline
    g2d.setStroke(new BasicStroke(1));
    g2d.setColor(Color.BLACK);
    g2d.drawRoundRect(0, 0, width, height, 5, 5);
    if (ilegalColor) {
        g2d.setColor(Color.RED);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawLine(width - 3, 3, 3, height - 3);
    }
    g2d.setTransform(trans);
}
Also used : BasicStroke(java.awt.BasicStroke) AffineTransform(java.awt.geom.AffineTransform)

Example 18 with AffineTransform

use of java.awt.geom.AffineTransform in project processing by processing.

the class HandleComparator method draw.

public void draw(Graphics2D g2d, boolean hasFocus) {
    AffineTransform prevTrans = g2d.getTransform();
    g2d.translate(x, y);
    // draw underline on the number
    g2d.setColor(ColorScheme.getInstance().progressFillColor);
    g2d.drawLine(0, 0, width, 0);
    if (hasFocus) {
        if (progBar != null) {
            g2d.translate(width / 2, 2);
            progBar.draw(g2d);
        }
    }
    g2d.setTransform(prevTrans);
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 19 with AffineTransform

use of java.awt.geom.AffineTransform in project hid-serial by rayshobby.

the class GAbstractControl method calcTransformedOrigin.

/**
	 * This method takes a position px, py and calculates the equivalent
	 * position [ox,oy] as if no transformations have taken place and
	 * the origin is the top-left corner of the control.
	 * @param px
	 * @param py
	 */
protected void calcTransformedOrigin(float px, float py) {
    AffineTransform aff = new AffineTransform();
    aff = getTransform(aff);
    temp[0] = px;
    temp[1] = py;
    try {
        aff.inverseTransform(temp, 0, temp, 0, 1);
        ox = (float) temp[0] + halfWidth;
        oy = (float) temp[1] + halfHeight;
    } catch (NoninvertibleTransformException e) {
    }
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform)

Example 20 with AffineTransform

use of java.awt.geom.AffineTransform in project hid-serial by rayshobby.

the class GAbstractControl method addControl.

/**
	 * This will set the rotation of the control to angle overwriting
	 * any previous rotation set. Then it calculates the centre position
	 * so that the original top left corner of the control will be the 
	 * position indicated by x,y with respect to the top left corner of
	 * parent. <br>
	 * 
	 * The added control will have its position calculated relative to the 
	 * centre of the parent control. <br>
	 * 
	 * All overloaded methods call this one. <br>
	 * 
	 * @param c the control to add.
	 * @param x the leftmost or centre position depending on controlMode
	 * @param y the topmost or centre position depending on controlMode
	 * @param angle the rotation angle (replaces any the angle specified in control)
	 */
public void addControl(GAbstractControl c, float x, float y, float angle) {
    // Ignore if children are not allowed.
    if (children == null)
        return;
    c.rotAngle = angle;
    // In child control reset the control so it centred about the origin
    AffineTransform aff = new AffineTransform();
    aff.setToRotation(angle);
    /*
		 * The following code should result in the x,y and cx,cy coordinates of
		 * the added control (c) added being measured relative to the centre of  
		 * this control.
		 */
    switch(G4P.control_mode) {
        case CORNER:
        case CORNERS:
            // Rotate about top corner
            c.x = x;
            c.y = y;
            c.temp[0] = c.halfWidth;
            c.temp[1] = c.halfHeight;
            aff.transform(c.temp, 0, c.temp, 0, 1);
            c.cx = (float) c.temp[0] + x - halfWidth;
            c.cy = (float) c.temp[1] + y - halfHeight;
            c.x = c.cx - c.halfWidth;
            c.y = c.cy - c.halfHeight;
            break;
        case CENTER:
            // Rotate about centre
            c.cx = x;
            c.cy = y;
            c.temp[0] = -c.halfWidth;
            c.temp[1] = -c.halfHeight;
            aff.transform(c.temp, 0, c.temp, 0, 1);
            c.x = c.cx + (float) c.temp[0] - halfWidth;
            c.y = c.cy - (float) c.temp[1] - halfHeight;
            c.cx -= halfWidth;
            c.cy -= halfHeight;
            break;
    }
    c.rotAngle = angle;
    // Add to parent
    c.parent = this;
    c.setZ(z);
    // Parent will now be responsible for drawing
    c.registeredMethods &= (ALL_METHOD - DRAW_METHOD);
    if (children == null)
        children = new LinkedList<GAbstractControl>();
    children.addLast(c);
    Collections.sort(children, new Z_Order());
    // Does the control being added have to do anything extra
    c.addToParent(this);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) LinkedList(java.util.LinkedList)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)335 BufferedImage (java.awt.image.BufferedImage)55 Graphics2D (java.awt.Graphics2D)43 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)38 Point2D (java.awt.geom.Point2D)26 Paint (java.awt.Paint)22 Font (java.awt.Font)21 Shape (java.awt.Shape)21 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 PathIterator (java.awt.geom.PathIterator)16 ArrayList (java.util.ArrayList)16 FontRenderContext (java.awt.font.FontRenderContext)15 Color (java.awt.Color)14 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 Rectangle (java.awt.Rectangle)11 Path2D (java.awt.geom.Path2D)11 Test (org.junit.Test)11