Skip to content

Commit

Permalink
add getFill()
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed Jul 29, 2023
1 parent 09880ba commit 7b17a0d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/micycle/pgs/PGS_Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public final class PGS_Conversion {

/** Approximate distance between successive sample points on bezier curves */
static final float BEZIER_SAMPLE_DISTANCE = 2;
private static Field MATRIX_FIELD;
private static Field MATRIX_FIELD, PSHAPE_FILL_FIELD;
/**
* A boolean flag that affects whether a PShape's style (fillColor, strokeColor,
* strokeWidth) is preserved during <code>PShape->Geometry->PShape</code>
Expand Down Expand Up @@ -130,6 +130,8 @@ public final class PGS_Conversion {
try {
MATRIX_FIELD = PShape.class.getDeclaredField("matrix");
MATRIX_FIELD.setAccessible(true);
PSHAPE_FILL_FIELD = PShape.class.getDeclaredField("fillColor");
PSHAPE_FILL_FIELD.setAccessible(true);
} catch (NoSuchFieldException e) {
System.err.println(e.getLocalizedMessage());
}
Expand Down Expand Up @@ -1513,6 +1515,22 @@ public static PShape fromChildren(Collection<PShape> children) {
return parent;
}

/**
* Retrieves the fill color of a PShape.
*
* @param shape The PShape object for which to retrieve the fill color.
* @return The integer representation of the fill color in ARGB format (32-bit).
* @since 1.4.0
*/
public static int getFillColor(PShape shape) {
try {
return PSHAPE_FILL_FIELD.getInt(shape);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
return 0;
}
}

/**
* Sets the fill color for the PShape and all of its children recursively (and
* disables stroke).
Expand Down

0 comments on commit 7b17a0d

Please sign in to comment.