forked from dorkbox/SystemTray
Proper padding for checkmark icon now
This commit is contained in:
parent
6599989e82
commit
cf1606f321
@ -24,20 +24,33 @@ public class HeavyCheckMark {
|
|||||||
* This saves a scalable CheckMark to a correctly sized PNG file.
|
* This saves a scalable CheckMark to a correctly sized PNG file.
|
||||||
*
|
*
|
||||||
* @param color the color of the CheckMark
|
* @param color the color of the CheckMark
|
||||||
* @param iconSize the size of the icon (NOT the size of the image. The size of the image is iconSize + padding)
|
* @param checkMarkSize the size of the CheckMark inside the image. (does not include padding)
|
||||||
* @param padding the amount of padding to apply to all edges of the icon. 8 means that on all sides, there will be 8 pixels
|
*
|
||||||
* between the icon and the edge of the image. Image size = icon size + (padding * 2)
|
* @param paddingTop amount of padding to apply to the top edge of the icon.
|
||||||
|
* @param paddingLeft amount of padding to apply to the left edge of the icon.
|
||||||
|
* @param paddingBottom amount of padding to apply to the bottom edge of the icon.
|
||||||
|
* @param paddingRight amount of padding to apply to the right edge of the icon.
|
||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
String getFile(Color color, int iconSize, int padding) {
|
String getFile(Color color, int checkMarkSize, int paddingTop, int paddingLeft , int paddingBottom, int paddingRight) {
|
||||||
int imageSize = iconSize + padding;
|
|
||||||
|
|
||||||
String name = imageSize + "_checkMark_" + HeavyCheckMark.VERSION + "_" + color.getRGB() + ".png";
|
//noinspection StringBufferReplaceableByString
|
||||||
|
String name = new StringBuilder().append(checkMarkSize)
|
||||||
|
.append(paddingTop)
|
||||||
|
.append(paddingBottom)
|
||||||
|
.append(paddingLeft)
|
||||||
|
.append(paddingRight)
|
||||||
|
.append("_checkMark_")
|
||||||
|
.append(HeavyCheckMark.VERSION)
|
||||||
|
.append("_")
|
||||||
|
.append(color.getRGB())
|
||||||
|
.append(".png")
|
||||||
|
.toString();
|
||||||
|
|
||||||
final File newFile = CacheUtil.create(name);
|
final File newFile = CacheUtil.create(name);
|
||||||
if (newFile.canRead() || newFile.length() == 0) {
|
if (newFile.canRead() || newFile.length() == 0) {
|
||||||
try {
|
try {
|
||||||
BufferedImage img = HeavyCheckMark.draw(color, imageSize, padding);
|
BufferedImage img = HeavyCheckMark.draw(color, checkMarkSize, paddingTop, paddingLeft, paddingBottom, paddingRight);
|
||||||
ImageIO.write(img, "png", newFile);
|
ImageIO.write(img, "png", newFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SystemTray.logger.error("Error creating check-mark image.", e);
|
SystemTray.logger.error("Error creating check-mark image.", e);
|
||||||
@ -48,10 +61,14 @@ public class HeavyCheckMark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static
|
private static
|
||||||
BufferedImage draw(final Color color, int size, int padding) {
|
BufferedImage draw(final Color color, final int checkMarkSize, final int paddingTop, final int paddingLeft, int paddingBottom, int paddingRight) {
|
||||||
double scale = (size - padding) / SVG_ORIG_SIZE;
|
int sizeX = checkMarkSize + paddingLeft + paddingRight;
|
||||||
|
int sizeY = checkMarkSize + paddingTop + paddingBottom;
|
||||||
|
|
||||||
BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
|
double scaleX = checkMarkSize / SVG_ORIG_SIZE;
|
||||||
|
double scaleY = checkMarkSize / SVG_ORIG_SIZE;
|
||||||
|
|
||||||
|
BufferedImage img = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_ARGB);
|
||||||
Graphics2D g2d = img.createGraphics();
|
Graphics2D g2d = img.createGraphics();
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
||||||
@ -64,10 +81,8 @@ public class HeavyCheckMark {
|
|||||||
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
|
||||||
|
|
||||||
AffineTransform at = new AffineTransform();
|
AffineTransform at = new AffineTransform();
|
||||||
double midPoint = (size / 2.0) - ((size - padding) / 2.0);
|
at.translate(paddingLeft, paddingTop);
|
||||||
|
at.scale(scaleX, scaleY);
|
||||||
at.translate(midPoint, midPoint);
|
|
||||||
at.scale(scale, scale);
|
|
||||||
g2d.setTransform(at);
|
g2d.setTransform(at);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user