From e9881dd540175642ed4e09acb0a35860f6637ee9 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 4 Feb 2019 09:50:39 +0000 Subject: [PATCH] Add ColorUtil#fromObject to generate color from object Add utility method that can generate color based on object hashCode. Signed-off-by: Tomas Slusny --- .../net/runelite/client/util/ColorUtil.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java b/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java index d37028f9dd..5445d55183 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java +++ b/runelite-client/src/main/java/net/runelite/client/util/ColorUtil.java @@ -27,6 +27,7 @@ package net.runelite.client.util; import com.google.common.primitives.Ints; import java.awt.Color; import java.util.regex.Pattern; +import javax.annotation.Nonnull; public class ColorUtil { @@ -226,4 +227,20 @@ public class ColorUtil return null; } } + + /** + * Creates color from passed object hash code + * @param object object with hashCode + * @param skipAlpha skips alpha + * @return color + */ + public static Color fromObject(@Nonnull final Object object, boolean skipAlpha) + { + int i = object.hashCode(); + int r = (i >> 24) & 0xFF; + int g = (i >> 16) & 0xFF; + int b = (i >> 8) & 0xFF; + int a = i & 0xFF; + return new Color(r, g, b, skipAlpha ? 255 : a); + } }